Some changes and bug fixes for PdpMessage handling 46/84746/1
authora.sreekumar <ajith.sreekumar@est.tech>
Tue, 9 Apr 2019 20:48:32 +0000 (20:48 +0000)
committera.sreekumar <ajith.sreekumar@est.tech>
Tue, 9 Apr 2019 20:48:32 +0000 (20:48 +0000)
1) Updating pom file of services-onappf to fix dependency related
issues.
2) Some changes to accomodate recent updates.
3) Fix for some issues identified during testing.

Change-Id: I8150ed9858902ebbe12321a793770df3fdc7e773
Issue-ID: POLICY-1453
Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
services/services-onappf/pom.xml
services/services-onappf/src/main/java/org/onap/policy/apex/starter/ApexStarterActivator.java
services/services-onappf/src/main/java/org/onap/policy/apex/starter/engine/ApexEngineHandler.java
services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpMessageHandler.java
services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpStateChangeMessageHandler.java
services/services-onappf/src/main/java/org/onap/policy/apex/starter/handler/PdpUpdateMessageHandler.java
services/services-onappf/src/test/java/org/onap/policy/apex/starter/comm/TestPdpStateChangeListener.java

index af3dab0..ef23ae7 100644 (file)
             <artifactId>services-engine</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <!-- Plugins for Context Distribution -->
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution</groupId>
+            <artifactId>plugins-context-distribution-hazelcast</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-distribution</groupId>
+            <artifactId>plugins-context-distribution-infinispan</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <!-- Plugins for Context Locking -->
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking</groupId>
+            <artifactId>plugins-context-locking-hazelcast</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-locking</groupId>
+            <artifactId>plugins-context-locking-curator</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <!-- Plugins for Context Schemas -->
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-schema</groupId>
+            <artifactId>plugins-context-schema-avro</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <!-- Plugins for Executors -->
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId>
+            <artifactId>plugins-executor-java</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId>
+            <artifactId>plugins-executor-javascript</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId>
+            <artifactId>plugins-executor-jruby</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId>
+            <artifactId>plugins-executor-jython</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-executor</groupId>
+            <artifactId>plugins-executor-mvel</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <!-- Plugins for Persistence of Models over JPA -->
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-persistence.plugins-persistence-jpa</groupId>
+            <artifactId>plugins-persistence-jpa-eclipselink</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-persistence.plugins-persistence-jpa</groupId>
+            <artifactId>plugins-persistence-jpa-hibernate</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <!-- Plugins for event carrier technologies -->
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId>
+            <artifactId>plugins-event-carrier-kafka</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId>
+            <artifactId>plugins-event-carrier-websocket</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId>
+            <artifactId>plugins-event-carrier-jms</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId>
+            <artifactId>plugins-event-carrier-restclient</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId>
+            <artifactId>plugins-event-carrier-restserver</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId>
+            <artifactId>plugins-event-carrier-restrequestor</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        
+        <!-- Plugins for event protocols -->
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId>
+            <artifactId>plugins-event-protocol-xml</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId>
+            <artifactId>plugins-event-protocol-jms</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+
         <dependency>
             <groupId>org.onap.policy.common</groupId>
             <artifactId>policy-endpoints</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.glassfish.jersey.containers</groupId>
+                    <artifactId>jersey-container-servlet-core</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.glassfish.jersey.core</groupId>
+                    <artifactId>jersey-common</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.glassfish.jersey.containers</groupId>
+                    <artifactId>jersey-container-jetty-http</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.glassfish.jersey.core</groupId>
+                    <artifactId>jersey-server</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>javax.ws.rs</groupId>
+                    <artifactId>javax.ws.rs-api</artifactId>
+                </exclusion>
+            </exclusions>
             <version>${version.policy.common}</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.glassfish.jersey.inject</groupId>
+            <artifactId>jersey-hk2</artifactId>
+            <version>${version.jersey}</version>
+        </dependency>
+
         <dependency>
             <groupId>org.onap.policy.common</groupId>
             <artifactId>utils-test</artifactId>
         <dependency>
             <groupId>org.onap.policy.models</groupId>
             <artifactId>policy-models-pdp</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>javax.ws.rs</groupId>
+                    <artifactId>javax.ws.rs-api</artifactId>
+                </exclusion>
+            </exclusions>
             <version>${version.policy.models}</version>
         </dependency>
         <dependency>
index a6bd702..b33d792 100644 (file)
@@ -40,6 +40,7 @@ import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
 import org.onap.policy.common.utils.services.Registry;
 import org.onap.policy.common.utils.services.ServiceManager;
 import org.onap.policy.common.utils.services.ServiceManagerException;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -78,7 +79,7 @@ public class ApexStarterActivator {
         // TODO: instanceId currently set as a random string, could be fetched from actual deployment
         final int random = (int) (Math.random() * 100);
         final String instanceId = "apex_" + random;
-
+        LOGGER.debug("ApexStarterActivator initializing with instance id:" + instanceId);
         try {
             this.apexStarterParameterGroup = apexStarterParameterGroup;
             this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES);
@@ -110,11 +111,11 @@ public class ApexStarterActivator {
                                         apexStarterParameterGroup.getPdpStatusParameters().getTimeIntervalMs())),
                         () -> stopAndRemovePdpStatusPublisher())
                 .addAction("Register pdp update listener",
-                    () -> msgDispatcher.register("PDP_UPDATE", pdpUpdateListener),
-                    () -> msgDispatcher.unregister("PDP_UPDATE"))
+                    () -> msgDispatcher.register(PdpMessageType.PDP_UPDATE.name(), pdpUpdateListener),
+                    () -> msgDispatcher.unregister(PdpMessageType.PDP_UPDATE.name()))
                 .addAction("Register pdp state change request dispatcher",
-                        () -> msgDispatcher.register("PDP_STATE_CHANGE", pdpStateChangeListener),
-                        () -> msgDispatcher.unregister("PDP_STATE_CHANGE"))
+                        () -> msgDispatcher.register(PdpMessageType.PDP_STATE_CHANGE.name(), pdpStateChangeListener),
+                        () -> msgDispatcher.unregister(PdpMessageType.PDP_STATE_CHANGE.name()))
                 .addAction("Message Dispatcher",
                     () -> registerMsgDispatcher(),
                     () -> unregisterMsgDispatcher());
index 4682a3b..e58b0db 100644 (file)
 
 package org.onap.policy.apex.starter.engine;
 
+import com.google.gson.JsonObject;
+
 import java.io.IOException;
 import java.io.StringReader;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.util.Map;
 
 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
 import org.onap.policy.apex.service.engine.main.ApexMain;
@@ -53,16 +54,15 @@ public class ApexEngineHandler {
      * @throws ApexStarterException
      */
 
-    @SuppressWarnings("unchecked")
     public ApexEngineHandler(final String properties) throws ApexStarterException {
         final StandardCoder standardCoder = new StandardCoder();
-        Map<String, Map<String, String>> body;
+        JsonObject body;
         try {
-            body = standardCoder.decode(new StringReader(properties), Map.class);
+            body = standardCoder.decode(new StringReader(properties), JsonObject.class);
         } catch (final CoderException e) {
             throw new ApexStarterException(e);
         }
-        final Map<String, String> engineServiceParameters = body.get("engineServiceParameters");
+        final JsonObject engineServiceParameters = body.get("engineServiceParameters").getAsJsonObject();
         final String policyModel = engineServiceParameters.get("policy_type_impl").toString();
         engineServiceParameters.remove("policy_type_impl");
         final String apexConfig = body.toString();
@@ -70,8 +70,8 @@ public class ApexEngineHandler {
         final String modelFilePath = createFile(policyModel, "modelFile");
 
         final String apexConfigFilePath = createFile(apexConfig, "apexConfigFile");
-
         final String[] apexArgs = { "-rfr", "target/classes", "-c", apexConfigFilePath, "-m", modelFilePath };
+        LOGGER.debug("Starting apex engine.");
         apexMain = new ApexMain(apexArgs);
     }
 
@@ -100,6 +100,7 @@ public class ApexEngineHandler {
 
     public void shutdown() throws ApexStarterException {
         try {
+            LOGGER.debug("Shutting down apex engine.");
             apexMain.shutdown();
             apexMain = null;
         } catch (final ApexException e) {
index a022a8a..be76938 100644 (file)
@@ -96,12 +96,8 @@ public class PdpMessageHandler {
         pdpStatus.setDescription(pdpStatusContext.getDescription());
         pdpStatus.setSupportedPolicyTypes(pdpStatusContext.getSupportedPolicyTypes());
         pdpStatus.setPolicies(pdpStatusContext.getPolicies());
-        if (null != pdpStatusContext.getPdpGroup()) {
-            pdpStatus.setPdpGroup(pdpStatusContext.getPdpGroup());
-        }
-        if (null != pdpStatusContext.getPdpSubgroup()) {
-            pdpStatus.setPdpSubgroup(pdpStatusContext.getPdpSubgroup());
-        }
+        pdpStatus.setPdpGroup(pdpStatusContext.getPdpGroup());
+        pdpStatus.setPdpSubgroup(pdpStatusContext.getPdpSubgroup());
         return pdpStatus;
     }
 
index c0ec690..9f97fb2 100644 (file)
@@ -51,11 +51,9 @@ public class PdpStateChangeMessageHandler {
         final PdpStatusPublisher pdpStatusPublisher = Registry.get(ApexStarterConstants.REG_PDP_STATUS_PUBLISHER);
         final PdpMessageHandler pdpMessageHandler = new PdpMessageHandler();
         PdpResponseDetails pdpResponseDetails = null;
-        if (isMessageRelevant(pdpStateChangeMsg, pdpStatusContext)) {
+        if (pdpStateChangeMsg.appliesTo(pdpStatusContext.getName(), pdpStatusContext.getPdpGroup(),
+                pdpStatusContext.getPdpSubgroup())) {
             switch (pdpStateChangeMsg.getState()) {
-                case TERMINATED:
-                    pdpResponseDetails = handleTerminatedState(pdpStateChangeMsg, pdpStatusContext, pdpMessageHandler);
-                    break;
                 case PASSIVE:
                     pdpResponseDetails = handlePassiveState(pdpStateChangeMsg, pdpStatusContext, pdpMessageHandler);
                     break;
@@ -67,23 +65,11 @@ public class PdpStateChangeMessageHandler {
             }
             final PdpStatus pdpStatus = pdpMessageHandler.createPdpStatusFromContext();
             pdpStatus.setResponse(pdpResponseDetails);
+            pdpStatus.setDescription("Pdp status response message for PdpStateChange");
             pdpStatusPublisher.send(pdpStatus);
         }
     }
 
-    /**
-     * Check if the pdp state change message is meant for this pdp.
-     *
-     * @param pdpStateChangeMsg
-     * @param pdpStatusContext
-     * @return boolean value if relevant or not
-     */
-    private boolean isMessageRelevant(final PdpStateChange pdpStateChangeMsg, final PdpStatus pdpStatusContext) {
-        return pdpStatusContext.getName().equals(pdpStateChangeMsg.getName()) || (null == pdpStateChangeMsg.getName()
-                && pdpStateChangeMsg.getPdpGroup().equals(pdpStatusContext.getPdpGroup())
-                && pdpStateChangeMsg.getPdpSubgroup().equals(pdpStatusContext.getPdpSubgroup()));
-    }
-
     /**
      * Method to handle when the new state from pap is active.
      *
@@ -108,7 +94,7 @@ public class PdpStateChangeMessageHandler {
                     // assumed that the apex policies list contains only one entry.
                     final ApexEngineHandler apexEngineHandler =
                             new ApexEngineHandler((String) policies.get(0).getProperties().get("content"));
-                    Registry.register(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, apexEngineHandler);
+                    Registry.registerOrReplace(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, apexEngineHandler);
                     pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
                             PdpResponseStatus.SUCCESS, "Apex engine started. State changed to active.");
                     pdpStatusContext.setState(PdpState.ACTIVE);
@@ -150,36 +136,4 @@ public class PdpStateChangeMessageHandler {
         }
         return pdpResponseDetails;
     }
-
-    /**
-     * Method to handle when the new state from pap is terminated.
-     *
-     * @param pdpStateChangeMsg
-     * @param pdpStatusPublisher
-     * @param pdpMessageHandler
-     * @return pdpResponseDetails
-     */
-    private PdpResponseDetails handleTerminatedState(final PdpStateChange pdpStateChangeMsg,
-            final PdpStatus pdpStatusContext, final PdpMessageHandler pdpMessageHandler) {
-
-        PdpResponseDetails pdpResponseDetails;
-        if (pdpStatusContext.getState().equals(PdpState.ACTIVE)) {
-            final ApexEngineHandler apexEngineHandler = Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER);
-            try {
-                apexEngineHandler.shutdown();
-                pdpStatusContext.setState(PdpState.PASSIVE);
-                pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
-                        PdpResponseStatus.SUCCESS, "Apex Engine stopped. State changed to passive.");
-            } catch (final Exception e) {
-                pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
-                        PdpResponseStatus.FAIL,
-                        "Stopping apex engine failed. State cannot be changed." + e.getMessage());
-            }
-        } else {
-            pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
-                    PdpResponseStatus.SUCCESS, "Pdp already in passive state");
-        }
-        return pdpResponseDetails;
-
-    }
 }
index 835c299..5198c22 100644 (file)
@@ -32,6 +32,7 @@ import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.models.pdp.concepts.PdpUpdate;
 import org.onap.policy.models.pdp.enums.PdpResponseStatus;
+import org.onap.policy.models.pdp.enums.PdpState;
 
 /**
  * This class supports the handling of pdp update messages.
@@ -40,7 +41,6 @@ import org.onap.policy.models.pdp.enums.PdpResponseStatus;
  */
 public class PdpUpdateMessageHandler {
 
-
     /**
      * Method which handles a pdp update event from PAP.
      *
@@ -49,8 +49,9 @@ public class PdpUpdateMessageHandler {
     public void handlePdpUpdateEvent(final PdpUpdate pdpUpdateMsg) {
         final PdpMessageHandler pdpMessageHandler = new PdpMessageHandler();
         final PdpStatus pdpStatusContext = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT, PdpStatus.class);
-        PdpResponseDetails pdpResponseDetails;
-        if (pdpStatusContext.getName().equals(pdpUpdateMsg.getName())) {
+        PdpResponseDetails pdpResponseDetails = null;
+        if (pdpUpdateMsg.appliesTo(pdpStatusContext.getName(), pdpStatusContext.getPdpGroup(),
+                pdpStatusContext.getPdpSubgroup())) {
             final PdpStatusPublisher pdpStatusPublisher = Registry.get(ApexStarterConstants.REG_PDP_STATUS_PUBLISHER);
             if (checkIfAlreadyHandled(pdpUpdateMsg, pdpStatusContext, pdpStatusPublisher.getInterval())) {
                 pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
@@ -64,31 +65,67 @@ public class PdpUpdateMessageHandler {
                 pdpStatusContext.setPdpSubgroup(pdpUpdateMsg.getPdpSubgroup());
                 pdpStatusContext
                         .setPolicies(new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
-                if (pdpUpdateMsg.getPolicies().isEmpty()) {
-                    final ApexEngineHandler apexEngineHandler =
-                            Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER);
-                    if (apexEngineHandler.isApexEngineRunning()) {
-                        try {
-                            apexEngineHandler.shutdown();
-                        } catch (final ApexStarterException e) {
-                            pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
-                                    PdpResponseStatus.FAIL,
-                                    "Pdp update failed as the policies couldn't be undeployed.");
-                        }
-                    }
+                if (pdpStatusContext.getState().equals(PdpState.ACTIVE)) {
+                    pdpResponseDetails =
+                            startOrStopApexEngineBasedOnPolicies(pdpUpdateMsg, pdpMessageHandler, pdpStatusContext);
                 }
                 Registry.registerOrReplace(ApexStarterConstants.REG_APEX_TOSCA_POLICY_LIST, pdpUpdateMsg.getPolicies());
-                pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
-                        PdpResponseStatus.SUCCESS, "Pdp update successful.");
+                if (null == pdpResponseDetails) {
+                    pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+                            PdpResponseStatus.SUCCESS, "Pdp update successful.");
+                }
             }
             final PdpStatusPublisher pdpStatusPublisherTemp =
                     Registry.get(ApexStarterConstants.REG_PDP_STATUS_PUBLISHER);
             final PdpStatus pdpStatus = pdpMessageHandler.createPdpStatusFromContext();
             pdpStatus.setResponse(pdpResponseDetails);
+            pdpStatus.setDescription("Pdp status response message for PdpUpdate");
             pdpStatusPublisherTemp.send(pdpStatus);
         }
     }
 
+    /**
+     * Method to start or stop apex engine based on the list of policies received from pap. When current state is
+     * active, if PAP sends PdpUpdate with empty policies list, stop apex engine, or, if there is a change in policies,
+     * stop the current running policies and the deploy the new ones.
+     *
+     * @param pdpUpdateMsg
+     * @param pdpMessageHandler
+     * @param pdpStatusContext
+     * @return pdpResponseDetails
+     */
+    private PdpResponseDetails startOrStopApexEngineBasedOnPolicies(final PdpUpdate pdpUpdateMsg,
+            final PdpMessageHandler pdpMessageHandler, final PdpStatus pdpStatusContext) {
+        PdpResponseDetails pdpResponseDetails = null;
+        if (pdpUpdateMsg.getPolicies().isEmpty()) {
+            final ApexEngineHandler apexEngineHandler = Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER);
+            if (apexEngineHandler.isApexEngineRunning()) {
+                try {
+                    apexEngineHandler.shutdown();
+                } catch (final ApexStarterException e) {
+                    pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+                            PdpResponseStatus.FAIL, "Pdp update failed as the policies couldn't be undeployed.");
+                }
+            }
+        } else {
+            try {
+                ApexEngineHandler apexEngineHandler = Registry.get(ApexStarterConstants.REG_APEX_ENGINE_HANDLER);
+                if (apexEngineHandler.isApexEngineRunning()) {
+                    apexEngineHandler.shutdown();
+                }
+                apexEngineHandler = new ApexEngineHandler(
+                        (String) pdpUpdateMsg.getPolicies().get(0).getProperties().get("content"));
+                Registry.registerOrReplace(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, apexEngineHandler);
+                pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+                        PdpResponseStatus.SUCCESS, "Apex engine started and policies are running.");
+            } catch (final ApexStarterException e) {
+                pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+                        PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
+            }
+        }
+        return pdpResponseDetails;
+    }
+
     /**
      * Method checks of the Pdp update message is already handled by checking the values in the context.
      *
@@ -104,10 +141,12 @@ public class PdpUpdateMessageHandler {
                 && null != pdpStatusContext.getPdpSubgroup()
                 && pdpStatusContext.getPdpSubgroup().equals(pdpUpdateMsg.getPdpSubgroup())
                 && null != pdpStatusContext.getPolicies()
-                && pdpStatusContext.getPolicies()
-                        .containsAll(new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()))
-                && null != pdpUpdateMsg.getPdpHeartbeatIntervalMs() && pdpUpdateMsg.getPdpHeartbeatIntervalMs() > 0
-                && interval == pdpUpdateMsg.getPdpHeartbeatIntervalMs();
+                && new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies())
+                        .equals(pdpStatusContext.getPolicies())
+                && (null == pdpUpdateMsg.getPdpHeartbeatIntervalMs()
+                        || (null != pdpUpdateMsg.getPdpHeartbeatIntervalMs()
+                                && pdpUpdateMsg.getPdpHeartbeatIntervalMs() > 0
+                                && interval == pdpUpdateMsg.getPdpHeartbeatIntervalMs()));
     }
 
     /**
index b25d473..d0a85f9 100644 (file)
@@ -168,18 +168,4 @@ public class TestPdpStateChangeListener {
 
         assertEquals(pdpStatus.getState(), pdpStateChangeMsg.getState());
     }
-
-    @Test
-    public void testPdpStateChangeMessageListener_passivetoterminated() {
-        final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
-        pdpStatus.setState(PdpState.PASSIVE);
-        performPdpUpdate(pdpStatus.getName());
-        final PdpStateChange pdpStateChangeMsg = new PdpStateChange();
-        pdpStateChangeMsg.setState(PdpState.TERMINATED);
-        pdpStateChangeMsg.setPdpGroup("pdpGroup");
-        pdpStateChangeMsg.setPdpSubgroup("pdpSubgroup");
-        pdpStateChangeMsg.setName(pdpStatus.getName());
-        pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
-        assertEquals(pdpStatus.getState(), PdpState.PASSIVE);
-    }
 }