Configurable update-strategy for clusteredAppConfig 86/44386/6
authorVishal Thapar <vishal.thapar@ericsson.com>
Fri, 19 Aug 2016 10:00:43 +0000 (15:30 +0530)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 7 Oct 2016 03:14:06 +0000 (03:14 +0000)
Any change to application's config data results in restart of the
blueprint container. This change adds an attribute that allows different
applications to disable this restart.

Attribute added: update-strategy
Values: reload, none.
Default: reload

Change-Id: Ie0c7501f8b5c84970a46ca8f02d7f77caf913a0a
Signed-off-by: Vishal Thapar <vishal.thapar@ericsson.com>
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/DataStoreAppConfigMetadata.java
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/OpendaylightNamespaceHandler.java
opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/UpdateStrategy.java [new file with mode: 0644]
opendaylight/blueprint/src/main/resources/opendaylight-blueprint-ext-1.0.0.xsd

index c83e4e8..7361497 100644 (file)
@@ -93,6 +93,7 @@ public class DataStoreAppConfigMetadata extends AbstractDependentComponentFactor
     private final String defaultAppConfigFileName;
     private final String appConfigBindingClassName;
     private final String appConfigListKeyValue;
+    private final UpdateStrategy appConfigUpdateStrategy;
     private final AtomicBoolean readingInitialAppConfig = new AtomicBoolean(true);
 
     private volatile BindingContext bindingContext;
@@ -106,12 +107,13 @@ public class DataStoreAppConfigMetadata extends AbstractDependentComponentFactor
 
     public DataStoreAppConfigMetadata(@Nonnull String id, @Nonnull String appConfigBindingClassName,
             @Nullable String appConfigListKeyValue, @Nullable String defaultAppConfigFileName,
-            @Nullable Element defaultAppConfigElement) {
+            @Nonnull UpdateStrategy updateStrategyValue, @Nullable Element defaultAppConfigElement) {
         super(id);
         this.defaultAppConfigElement = defaultAppConfigElement;
         this.defaultAppConfigFileName = defaultAppConfigFileName;
         this.appConfigBindingClassName = appConfigBindingClassName;
         this.appConfigListKeyValue = appConfigListKeyValue;
+        this.appConfigUpdateStrategy = updateStrategyValue;
     }
 
     @Override
@@ -250,14 +252,18 @@ public class DataStoreAppConfigMetadata extends AbstractDependentComponentFactor
 
                 if(!setInitialAppConfig(Optional.of(newAppConfig)) &&
                         !Objects.equals(currentAppConfig, newAppConfig)) {
-                    LOG.debug("App config was updated - scheduling container for restart");
+                    LOG.debug("App config was updated");
 
-                    restartContainer();
+                    if(appConfigUpdateStrategy == UpdateStrategy.RELOAD) {
+                        restartContainer();
+                    }
                 }
             } else if(type == ModificationType.DELETE) {
-                LOG.debug("App config was deleted - scheduling container for restart");
+                LOG.debug("App config was deleted");
 
-                restartContainer();
+                if(appConfigUpdateStrategy == UpdateStrategy.RELOAD) {
+                    restartContainer();
+                }
             }
         }
     }
index e6ddd48..47b2c2b 100644 (file)
@@ -54,6 +54,7 @@ public class OpendaylightNamespaceHandler implements NamespaceHandler {
     static final String RPC_REGISTRY_NAME = "org.opendaylight.blueprint.RpcRegistry";
     static final String NOTIFICATION_SERVICE_NAME = "org.opendaylight.blueprint.NotificationService";
     static final String TYPE_ATTR = "type";
+    static final String UPDATE_STRATEGY_ATTR = "update-strategy";
 
     private static final Logger LOG = LoggerFactory.getLogger(OpendaylightNamespaceHandler.class);
     private static final String COMPONENT_PROCESSOR_NAME = ComponentProcessor.class.getName();
@@ -350,7 +351,20 @@ public class OpendaylightNamespaceHandler implements NamespaceHandler {
         return new DataStoreAppConfigMetadata(getId(context, element), element.getAttribute(
                 DataStoreAppConfigMetadata.BINDING_CLASS), element.getAttribute(
                         DataStoreAppConfigMetadata.LIST_KEY_VALUE), element.getAttribute(
-                                DataStoreAppConfigMetadata.DEFAULT_CONFIG_FILE_NAME), defaultAppConfigElement);
+                        DataStoreAppConfigMetadata.DEFAULT_CONFIG_FILE_NAME), parseUpdateStrategy(
+                        element.getAttribute(UPDATE_STRATEGY_ATTR)), defaultAppConfigElement);
+    }
+
+    private UpdateStrategy parseUpdateStrategy(String updateStrategyValue) {
+        if (Strings.isNullOrEmpty(updateStrategyValue) ||
+                updateStrategyValue.equalsIgnoreCase(UpdateStrategy.RELOAD.name())) {
+            return UpdateStrategy.RELOAD;
+        } else if(updateStrategyValue.equalsIgnoreCase(UpdateStrategy.NONE.name())){
+            return UpdateStrategy.NONE;
+        } else {
+            LOG.warn("update-strategy {} not supported, using reload", updateStrategyValue);
+            return UpdateStrategy.RELOAD;
+        }
     }
 
     private Metadata parseSpecificReferenceList(Element element, ParserContext context) {
diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/UpdateStrategy.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/UpdateStrategy.java
new file mode 100644 (file)
index 0000000..1b5d128
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.blueprint.ext;
+
+/**
+ * Enumerates possible strategies when a component is updated
+ *
+ * @author Vishal Thapar
+ */
+public enum UpdateStrategy {
+    /*
+     * Restart container
+     */
+    RELOAD,
+    /*
+     * Don't do anything
+     */
+    NONE
+}
index c451e48..3c0e227 100644 (file)
     <xsd:attribute name="list-key-value" type="xsd:string" use="optional"/>
     <xsd:attribute name="default-config-file-name" type="xsd:string" use="optional"/>
     <xsd:attribute name="id" type="xsd:ID" use="required"/>
+    <xsd:attribute name="update-strategy" type="TupdateStrategy" use="optional" default="reload"/>
   </xsd:complexType>
   <xsd:element name="clustered-app-config" type="TclusteredAppConfig"/>
-
+ <xsd:simpleType name="TupdateStrategy">
+  <xsd:restriction base="xsd:NMTOKEN">
+    <xsd:enumeration value="none"/>
+    <xsd:enumeration value="reload"/>
+  </xsd:restriction>
+ </xsd:simpleType>
   <xsd:complexType name="TspecificReferenceList">
     <xsd:attribute name="interface" type="bp:Tclass" use="required"/>
     <xsd:attribute name="id" type="xsd:ID"/>

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.