Add new actor SDNC to support CCVPN Closed Loop 89/69689/5
authorXin Miao <xin.miao@huawei.com>
Mon, 1 Oct 2018 23:09:24 +0000 (18:09 -0500)
committerPamela Dragosh <pdragosh@research.att.com>
Fri, 5 Oct 2018 15:32:44 +0000 (11:32 -0400)
Issue-ID: POLICY-1183
Change-Id: I1b77b5b9cefca104382d9d84dd00bbd63b20e0f2
Signed-off-by: Xin Miao <xin.miao@huawei.com>
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
41 files changed:
controlloop/common/actors/actor.sdnc/pom.xml [new file with mode: 0644]
controlloop/common/actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java [new file with mode: 0644]
controlloop/common/actors/actor.sdnc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor [new file with mode: 0644]
controlloop/common/actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java [new file with mode: 0644]
controlloop/common/actors/pom.xml
controlloop/common/controller-casablanca/pom.xml
controlloop/common/eventmanager/pom.xml
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
controlloop/common/feature-controlloop-casablanca/pom.xml
controlloop/common/model-impl/pom.xml
controlloop/common/model-impl/sdnc/pom.xml [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealNetworkInfo.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequest.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestHeaderInfo.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestInfo.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealServiceInfo.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncRequest.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponse.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseNetworkInfo.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseOutput.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseServiceInfo.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestDemo.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncHealAdditionalParams.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncHealRequest.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncHealServiceInfo.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncManager.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncRequest.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncResponse.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncResponseDescriptor.java [new file with mode: 0644]
controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/TestSerialization.java [new file with mode: 0644]
controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MsbServiceFactory.java
controlloop/common/msb/src/main/java/org/onap/policy/msb/client/MsbServiceManager.java
controlloop/packages/basex-controlloop/src/files/config/controlloop.properties.environment
controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/pom.xml
controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/pom.xml
controlloop/templates/archetype-cl-casablanca/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
controlloop/templates/template.demo.clc/pom.xml
controlloop/templates/template.demo/pom.xml

diff --git a/controlloop/common/actors/actor.sdnc/pom.xml b/controlloop/common/actors/actor.sdnc/pom.xml
new file mode 100644 (file)
index 0000000..8aa1a7b
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version="1.0"?>
+<!--
+  ============LICENSE_START=======================================================
+  drools-pdp-apps
+  ================================================================================
+  Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
+  ================================================================================
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  ============LICENSE_END=========================================================
+  -->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
+    <artifactId>actors</artifactId>
+    <version>1.3.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>actor.sdnc</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
+      <artifactId>actorServiceProvider</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+      <artifactId>sdnc</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+      <artifactId>events</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+      <artifactId>aai</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.common</groupId>
+      <artifactId>policy-endpoints</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-pdp</groupId>
+      <artifactId>policy-management</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common</groupId>
+      <artifactId>simulators</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/controlloop/common/actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java b/controlloop/common/actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java
new file mode 100644 (file)
index 0000000..b9eaf7e
--- /dev/null
@@ -0,0 +1,134 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SdncActorServiceProvider
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.actor.sdnc;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+import org.onap.policy.aai.AaiGetVnfResponse;
+import org.onap.policy.controlloop.ControlLoopOperation;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
+import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.sdnc.SdncHealNetworkInfo;
+import org.onap.policy.sdnc.SdncHealRequest;
+import org.onap.policy.sdnc.SdncHealRequestHeaderInfo;
+import org.onap.policy.sdnc.SdncHealRequestInfo;
+import org.onap.policy.sdnc.SdncHealServiceInfo;
+import org.onap.policy.sdnc.SdncRequest;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class SdncActorServiceProvider implements Actor {
+    private static final Logger logger = LoggerFactory.getLogger(SdncActorServiceProvider.class);
+
+    // Strings for Sdnc Actor
+    private static final String SDNC_ACTOR = "SDNC";
+
+    // Strings for targets
+    private static final String TARGET_VM = "VM";
+
+    // Strings for recipes
+    private static final String RECIPE_REROUTE = "Reroute";
+
+    private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_REROUTE);
+    private static final ImmutableMap<String, List<String>> targets =
+            new ImmutableMap.Builder<String, List<String>>().put(RECIPE_REROUTE, ImmutableList.of(TARGET_VM)).build();
+
+    @Override
+    public String actor() {
+        return SDNC_ACTOR;
+    }
+
+    @Override
+    public List<String> recipes() {
+        return ImmutableList.copyOf(recipes);
+    }
+
+    @Override
+    public List<String> recipeTargets(String recipe) {
+        return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
+    }
+
+    @Override
+    public List<String> recipePayloads(String recipe) {
+        return Collections.emptyList();
+    }
+
+    /**
+     * Construct a request.
+     * 
+     * @param onset the onset event
+     * @param operation the control loop operation
+     * @param policy the policy
+     * @return the constructed request
+     */
+    public static SdncRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
+            Policy policy) {
+
+        if (!policy.getRecipe().equalsIgnoreCase(RECIPE_REROUTE)) {
+            return null;
+        }
+
+        // Construct an Sdnc request
+        String serviceInstance = onset.getAai().get("service-instance.service-instance-id");
+        if (serviceInstance == null || serviceInstance.isEmpty()) {
+            // This indicates that AAI Enrichment needs to be done by event producer. 
+            return null;
+        }
+        SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
+        serviceInfo.setServiceInstanceId(serviceInstance);
+        
+        String networkId = onset.getAai().get("network-information.network-id");
+        if (networkId == null || networkId.isEmpty()) {
+            // This indicates that AAI Enrichment needs to be done by event producer. 
+            return null;
+        }
+        SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo();        
+        networkInfo.setNetworkId(networkId);
+
+        SdncHealRequestInfo requestInfo = new SdncHealRequestInfo();
+        requestInfo.setRequestAction("ReoptimizeSOTNInstance");
+
+        SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
+        headerInfo.setSvcAction("reoptimize");
+        headerInfo.setSvcRequestId(UUID.randomUUID().toString());
+
+        SdncRequest request = new SdncRequest();
+        request.setNsInstanceId(serviceInstance);
+        request.setRequestId(onset.getRequestId());
+
+        SdncHealRequest healRequest = new SdncHealRequest();
+        healRequest.setRequestHeaderInfo(headerInfo);
+        healRequest.setNetworkInfo(networkInfo);
+        healRequest.setRequestInfo(requestInfo);
+        healRequest.setServiceInfo(serviceInfo);
+        request.setHealRequest(healRequest);
+
+        return request;
+    }
+}
\ No newline at end of file
diff --git a/controlloop/common/actors/actor.sdnc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor b/controlloop/common/actors/actor.sdnc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor
new file mode 100644 (file)
index 0000000..f4d1e97
--- /dev/null
@@ -0,0 +1 @@
+org.onap.policy.controlloop.actor.sdnc.SdncActorServiceProvider
\ No newline at end of file
diff --git a/controlloop/common/actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java b/controlloop/common/actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProviderTest.java
new file mode 100644 (file)
index 0000000..633234f
--- /dev/null
@@ -0,0 +1,114 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * TestSdncActorServiceProvider
+ * ================================================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Corp. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.actor.sdnc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.Objects;
+import java.util.UUID;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.aai.AaiGetVnfResponse;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.controlloop.ControlLoopOperation;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.sdnc.SdncRequest;
+import org.onap.policy.simulators.Util;
+
+public class SdncActorServiceProviderTest {
+
+    /**
+     * Set up for test class.
+     */
+    @BeforeClass
+    public static void setUpSimulator() {
+        try {
+            Util.buildAaiSim();
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @AfterClass
+    public static void tearDownSimulator() {
+        HttpServletServer.factory.destroy();
+    }
+
+    @Test
+    public void testConstructRequest() {
+        VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
+        ControlLoopOperation operation = new ControlLoopOperation();
+
+        Policy policy = new Policy();
+        policy.setRecipe("Reroute");
+
+        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+
+        onset.getAai().put("network-information.network-id", "network-5555");
+        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+
+        PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
+        PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
+        PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
+        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+
+        UUID requestId = UUID.randomUUID();
+        onset.setRequestId(requestId);
+        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+
+        PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
+        assertNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+
+        onset.getAai().put("service-instance.service-instance-id", "service-instance-01");
+        assertNotNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+
+        policy.setRecipe("Reroute");
+        assertNotNull(SdncActorServiceProvider.constructRequest(onset, operation, policy));
+
+        SdncRequest request =
+                SdncActorServiceProvider.constructRequest(onset, operation, policy);
+
+        assertEquals(requestId, Objects.requireNonNull(request).getRequestId());
+        assertEquals("reoptimize", request.getHealRequest().getRequestHeaderInfo().getSvcAction());
+        assertEquals("ReoptimizeSOTNInstance", request.getHealRequest().getRequestInfo().getRequestAction());
+        assertEquals("network-5555", request.getHealRequest().getNetworkInfo().getNetworkId());
+        assertEquals("service-instance-01", request.getHealRequest().getServiceInfo().getServiceInstanceId());
+    }
+
+    @Test
+    public void testMethods() {
+        SdncActorServiceProvider sp = new SdncActorServiceProvider();
+
+        assertEquals("SDNC", sp.actor());
+        assertEquals(1, sp.recipes().size());
+        assertEquals("Reroute", sp.recipes().get(0));
+        assertEquals("VM", sp.recipeTargets("Reroute").get(0));
+        assertEquals(0, sp.recipePayloads("Reroute").size());
+    }
+}
index 3c2162b..9c6c056 100644 (file)
@@ -35,6 +35,7 @@
     <module>actorServiceProvider</module>
     <module>actor.appc</module>
     <module>actor.vfc</module>
+    <module>actor.sdnc</module>
     <module>actor.appclcm</module>
     <module>actor.sdnr</module>
     <module>actor.so</module>
index f606d69..5514e9e 100644 (file)
             <artifactId>vfc</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+            <artifactId>sdnc</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
             <artifactId>so</artifactId>
             <artifactId>actor.vfc</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
+            <artifactId>actor.sdnc</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.onap.policy.drools-applications.controlloop.common</groupId>
             <artifactId>policy-yaml</artifactId>
index 846a69f..c26f604 100644 (file)
       <version>${project.version}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
+      <artifactId>actor.sdnc</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
     <dependency>
       <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
       <artifactId>actor.appclcm</artifactId>
       <version>${project.version}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+      <artifactId>sdnc</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
     <dependency>
       <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
       <artifactId>appclcm</artifactId>
index 0b2c14e..9807991 100644 (file)
@@ -43,6 +43,7 @@ import org.onap.policy.controlloop.ControlLoopOperation;
 import org.onap.policy.controlloop.VirtualControlLoopEvent;
 import org.onap.policy.controlloop.actor.appc.AppcActorServiceProvider;
 import org.onap.policy.controlloop.actor.appclcm.AppcLcmActorServiceProvider;
+import org.onap.policy.controlloop.actor.sdnc.SdncActorServiceProvider;
 import org.onap.policy.controlloop.actor.sdnr.SdnrActorServiceProvider;
 import org.onap.policy.controlloop.actor.so.SoActorServiceProvider;
 import org.onap.policy.controlloop.actor.vfc.VfcActorServiceProvider;
@@ -50,6 +51,7 @@ import org.onap.policy.controlloop.policy.Policy;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.drools.system.PolicyEngine;
 import org.onap.policy.guard.Util;
+import org.onap.policy.sdnc.SdncResponse;
 import org.onap.policy.sdnr.PciResponseWrapper;
 import org.onap.policy.so.SOResponseWrapper;
 import org.onap.policy.vfc.VFCResponse;
@@ -121,6 +123,8 @@ public class ControlLoopOperationManager implements Serializable {
                 break;
             case "VFC":
                 break;
+            case "SDNC":
+                break;
             default:
                 throw new ControlLoopException("ControlLoopEventManager: policy has an unknown actor.");
         }
@@ -304,6 +308,14 @@ public class ControlLoopOperationManager implements Serializable {
                 }
 
                 return operationRequest;
+            case "SDNC":
+                this.operationRequest = SdncActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset,
+                        operation.clOperation, this.policy);
+                this.currentOperation = operation;
+                if (this.operationRequest == null) {
+                    this.policyResult = PolicyResult.FAILURE;
+                }
+                return operationRequest;                
             default:
                 throw new ControlLoopException("invalid actor " + policy.getActor() + " on policy");
         }
index ccdda5e..1715b1a 100644 (file)
             <artifactId>vfc</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+            <artifactId>sdnc</artifactId>
+            <version>${project.version}</version>
+        </dependency>        
         <dependency>
             <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
             <artifactId>so</artifactId>
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
+            <artifactId>actor.sdnc</artifactId>
+            <version>${project.version}</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>guava</artifactId>
+                    <groupId>com.google.guava</groupId>
+                </exclusion>
+            </exclusions>
+        </dependency>        
         <dependency>
             <groupId>org.onap.policy.drools-applications.controlloop.common</groupId>
             <artifactId>policy-yaml</artifactId>
index ebf35b8..89fd251 100644 (file)
@@ -43,6 +43,7 @@
     <module>sdc</module>
     <module>trafficgenerator</module>
     <module>vfc</module>
+    <module>sdnc</module>
   </modules>
 
 
diff --git a/controlloop/common/model-impl/sdnc/pom.xml b/controlloop/common/model-impl/sdnc/pom.xml
new file mode 100644 (file)
index 0000000..ea48753
--- /dev/null
@@ -0,0 +1,72 @@
+<!--
+  ============LICENSE_START=======================================================
+  Copyright (C) 2018 Huawei. All rights reserved.
+  Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+  ================================================================================
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+  
+       http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  ============LICENSE_END=========================================================
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+    <artifactId>model-impl</artifactId>
+    <version>1.3.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>sdnc</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <version>2.13.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.code.gson</groupId>
+      <artifactId>gson</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+      <artifactId>rest</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.drools</groupId>
+      <artifactId>drools-core</artifactId>
+      <version>6.5.0.Final</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.common</groupId>
+      <artifactId>policy-endpoints</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-pdp</groupId>
+      <artifactId>policy-management</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealNetworkInfo.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealNetworkInfo.java
new file mode 100644 (file)
index 0000000..4039d94
--- /dev/null
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncHealNetworkInfo implements Serializable {
+
+    private static final long serialVersionUID = 3208673205100673119L;
+
+    @SerializedName("network-id")
+    private String networkId;
+
+    public SdncHealNetworkInfo() {
+        // Default constructor for SdncHealActionVmInfo
+    }
+
+    public String getNetworkId() {
+        return networkId;
+    }
+
+    public void setNetworkId(String networkId) {
+        this.networkId = networkId;
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequest.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequest.java
new file mode 100644 (file)
index 0000000..74122b8
--- /dev/null
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncHealRequest implements Serializable {
+
+    private static final long serialVersionUID = -7341931593089709247L;
+
+    @SerializedName("sdnc-request-header")
+    private SdncHealRequestHeaderInfo requestHeaderInfo;
+
+    @SerializedName("request-information")
+    private SdncHealRequestInfo requestInfo;
+
+    @SerializedName("service-information")
+    private SdncHealServiceInfo serviceInfo;
+
+    @SerializedName("network-information")
+    private SdncHealNetworkInfo networkInfo;
+
+    public SdncHealRequest() {
+        // Default constructor for SdncHealRequest
+    }
+
+    public SdncHealRequestHeaderInfo getRequestHeaderInfo() {
+        return requestHeaderInfo;
+    }
+
+    public void setRequestHeaderInfo(SdncHealRequestHeaderInfo requestHeaderInfo) {
+        this.requestHeaderInfo = requestHeaderInfo;
+    }
+
+    public SdncHealRequestInfo getRequestInfo() {
+        return requestInfo;
+    }
+
+    public void setRequestInfo(SdncHealRequestInfo requestInfo) {
+        this.requestInfo = requestInfo;
+    }
+
+    public SdncHealServiceInfo getServiceInfo() {
+        return serviceInfo;
+    }
+
+    public void setServiceInfo(SdncHealServiceInfo serviceInfo) {
+        this.serviceInfo = serviceInfo;
+    }
+
+    public SdncHealNetworkInfo getNetworkInfo() {
+        return networkInfo;
+    }
+
+    public void setNetworkInfo(SdncHealNetworkInfo networkInfo) {
+        this.networkInfo = networkInfo;
+    }
+
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestHeaderInfo.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestHeaderInfo.java
new file mode 100644 (file)
index 0000000..97426b4
--- /dev/null
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncHealRequestHeaderInfo implements Serializable {
+
+    private static final long serialVersionUID = 3208673205100673119L;
+
+    @SerializedName("svc-request-id")
+    private String svcRequestId;
+
+    @SerializedName("svc-action")
+    private String svcAction;
+
+    public SdncHealRequestHeaderInfo() {
+        // Default constructor for SdncHealActionVmInfo
+    }
+
+    public String getSvcRequestId() {
+        return svcRequestId;
+    }
+
+    public void setSvcRequestId(String svcRequestId) {
+        this.svcRequestId = svcRequestId;
+    }
+
+    public String getSvcAction() {
+        return svcAction;
+    }
+
+    public void setSvcAction(String svcAction) {
+        this.svcAction = svcAction;
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestInfo.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealRequestInfo.java
new file mode 100644 (file)
index 0000000..91de4b2
--- /dev/null
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncHealRequestInfo implements Serializable {
+
+    private static final long serialVersionUID = 3208673205100673119L;
+
+    @SerializedName("request-action")
+    private String requestAction;
+
+    public SdncHealRequestInfo() {
+        // Default constructor for SdncHealActionVmInfo
+    }
+
+    public String getRequestAction() {
+        return requestAction;
+    }
+
+    public void setRequestAction(String requestAction) {
+        this.requestAction = requestAction;
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealServiceInfo.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncHealServiceInfo.java
new file mode 100644 (file)
index 0000000..d86d32f
--- /dev/null
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncHealServiceInfo implements Serializable {
+
+    private static final long serialVersionUID = 3208673205100673119L;
+
+    @SerializedName("service-instance-id")
+    private String serviceInstanceId;
+
+    public SdncHealServiceInfo() {
+        // Default constructor for SdncHealActionVmInfo
+    }
+
+    public String getServiceInstanceId() {
+        return serviceInstanceId;
+    }
+
+    public void setServiceInstanceId(String serviceInstanceId) {
+        this.serviceInstanceId = serviceInstanceId;
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncManager.java
new file mode 100644 (file)
index 0000000..61665f6
--- /dev/null
@@ -0,0 +1,164 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+
+import com.google.gson.JsonSyntaxException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.drools.core.WorkingMemory;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.rest.RESTManager;
+import org.onap.policy.rest.RESTManager.Pair;
+import org.onap.policy.sdnc.util.Serialization;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+   
+public final class SdncManager implements Runnable {
+    private static final String SYSTEM_LS = System.lineSeparator();
+
+    private String sdncUrlBase;
+    private String username;
+    private String password;
+    private SdncRequest sdncRequest;
+    private WorkingMemory workingMem;
+    private static final Logger logger = LoggerFactory.getLogger(SdncManager.class);
+    private static final Logger netLogger = 
+            LoggerFactory.getLogger(org.onap.policy.common.endpoints.event.comm.Topic.NETWORK_LOGGER);
+
+    // The REST manager used for processing REST calls for this Sdnc manager
+    private RESTManager restManager;
+    
+    /**
+     * Constructor.
+     * 
+     * @param wm Drools working memory
+     * @param request request
+     */
+    public SdncManager(WorkingMemory wm, SdncRequest request) {
+        if (wm == null || request == null) {
+            throw new IllegalArgumentException(
+                  "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null"
+            );
+        }
+        workingMem = wm;
+        sdncRequest = request;
+
+        restManager = new RESTManager();
+
+        setSdncParams(getPeManagerEnvProperty("sdnc.url"), getPeManagerEnvProperty("sdnc.username"), 
+            getPeManagerEnvProperty("sdnc.password"));
+    }
+
+    /**
+     * Set the parameters.
+     * 
+     * @param baseUrl base URL
+     * @param name username
+     * @param pwd password
+     */
+    public void setSdncParams(String baseUrl, String name, String pwd) {
+        sdncUrlBase = baseUrl;
+        username = name;
+        password = pwd;
+    }
+
+    @Override
+    public void run() {
+        Map<String, String> headers = new HashMap<>();
+        Pair<Integer, String> httpDetails;
+
+        SdncResponse responseError = new SdncResponse();
+        SdncResponseOutput responseOutput = new SdncResponseOutput();
+        responseOutput.setResponseCode("404");
+        responseError.setResponseOutput(responseOutput);
+
+        headers.put("Accept", "application/json");
+        String sdncUrl = sdncUrlBase + "/GENERIC-RESOURCE-API:network-topology-operation";
+
+        try {
+            String sdncRequestJson = Serialization.gsonPretty.toJson(sdncRequest);
+            netLogger.info("[OUT|{}|{}|]{}{}", "Sdnc", sdncUrl, SYSTEM_LS, sdncRequestJson);
+            logger.info("[OUT|{}|{}|]{}{}", "Sdnc", sdncUrl, SYSTEM_LS, sdncRequestJson);
+
+            httpDetails = restManager.post(sdncUrl, username, password, headers, "application/json",
+                                           sdncRequestJson);
+        } catch (Exception e) {
+            logger.info(e.getMessage(), e);
+            workingMem.insert(responseError);
+            return;
+        }
+
+        if (httpDetails == null) {
+            workingMem.insert(responseError);
+            return;
+        }
+
+        try {
+            SdncResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SdncResponse.class);
+            netLogger.info("[IN|{}|{}|]{}{}", "Sdnc", sdncUrl, SYSTEM_LS, httpDetails.second);
+            logger.info("[IN|{}|{}|]{}{}", "Sdnc", sdncUrl, SYSTEM_LS, httpDetails.second);
+            String body = Serialization.gsonPretty.toJson(response);
+            logger.info("Response to Sdnc Heal post:");
+            logger.info(body);
+            response.setRequestId(sdncRequest.getRequestId().toString());
+
+            if (!response.getResponseOutput().getResponseCode().equals("200")) {
+                logger.info(
+                    "Sdnc Heal Restcall failed with http error code {} {}", httpDetails.first, httpDetails.second
+                );
+            }
+
+            workingMem.insert(response);
+        } catch (JsonSyntaxException e) {
+            logger.info("Failed to deserialize into SdncResponse {}", e.getLocalizedMessage(), e);
+        } catch (Exception e) {
+            logger.info("Unknown error deserializing into SdncResponse {}", e.getLocalizedMessage(), e);
+        }
+    }
+
+    /**
+     * Protected setter for rest manager to allow mocked rest manager to be used for testing.
+     * @param restManager the test REST manager
+     */
+    protected void setRestManager(final RESTManager restManager) {
+        this.restManager = restManager;
+    }
+
+    /**
+     * This method reads and validates environmental properties coming from the policy engine. Null properties cause
+     * an {@link IllegalArgumentException} runtime exception to be thrown
+     * @param  enginePropertyName name of the parameter to retrieve
+     * @return the property value
+     */
+
+    private String getPeManagerEnvProperty(String enginePropertyName) {
+        String enginePropertyValue = PolicyEngine.manager.getEnvironmentProperty(enginePropertyName);
+        if (enginePropertyValue == null) {
+            throw new IllegalArgumentException(
+                "The value of policy engine manager environment property \"" 
+                   + enginePropertyName + "\" may not be null"
+            );
+        }
+        return enginePropertyValue;
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncRequest.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncRequest.java
new file mode 100644 (file)
index 0000000..ad824f6
--- /dev/null
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+public class SdncRequest implements Serializable {
+
+    private static final long serialVersionUID = 3736300970326332512L;
+    // These fields are not serialized and not part of JSON
+    private transient String nsInstanceId;
+    private transient UUID requestId;
+
+    @SerializedName("input")
+    private SdncHealRequest healRequest;
+
+    public SdncRequest() {
+            // Default constructor for SdncRequest
+    }
+
+    public String getNsInstanceId() {
+        return nsInstanceId;
+    }
+
+    public void setNsInstanceId(String nsInstanceId) {
+        this.nsInstanceId = nsInstanceId;
+    }
+
+    public UUID getRequestId() {
+        return requestId;
+    }
+
+    public void setRequestId(UUID requestId) {
+        this.requestId = requestId;
+    }
+
+    public SdncHealRequest getHealRequest() {
+        return healRequest;
+    }
+
+    public void setHealRequest(SdncHealRequest healRequest) {
+        this.healRequest = healRequest;
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponse.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponse.java
new file mode 100644 (file)
index 0000000..c0f2444
--- /dev/null
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncResponse implements Serializable {
+
+    private static final long serialVersionUID = 9151443891238218455L;
+
+    @SerializedName("output")
+    private SdncResponseOutput responseOutput;
+
+    private transient String requestId;
+
+    public SdncResponse() {
+        // Default constructor for SdncResponse
+    }
+
+    public String getRequestId() {
+        return requestId;
+    }
+
+    public void setRequestId(String requestId) {
+        this.requestId = requestId;
+    }
+
+    public SdncResponseOutput getResponseOutput() {
+        return responseOutput;
+    }
+
+    public void setResponseOutput(SdncResponseOutput responseOutput) {
+        this.responseOutput = responseOutput;
+    }
+
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseNetworkInfo.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseNetworkInfo.java
new file mode 100644 (file)
index 0000000..75582ff
--- /dev/null
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncResponseNetworkInfo implements Serializable {
+
+    private static final long serialVersionUID = 6827782899144150158L;
+
+    @SerializedName("instance-id")
+    private String instanceId;
+
+    @SerializedName("object-path")
+    private String objectPath;
+
+    public SdncResponseNetworkInfo() {
+        // Default constructor for SdncResponseNetworkInfo
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+
+    public void setInstanceId(String instanceId) {
+        this.instanceId = instanceId;
+    }
+
+    public String getObjectPath() {
+        return objectPath;
+    }
+
+    public void setObjectPath(String objectPath) {
+        this.objectPath = objectPath;
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseOutput.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseOutput.java
new file mode 100644 (file)
index 0000000..48acc5e
--- /dev/null
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class SdncResponseOutput implements Serializable {
+
+    private static final long serialVersionUID = 6827782899144150158L;
+
+    @SerializedName("svc-request-id")
+    private String svcRequestId;
+
+    @SerializedName("response-code")
+    private String responseCode;
+
+    @SerializedName("ack-final-indicator")
+    private String ackFinalIndicator;
+
+    public SdncResponseOutput() {
+        // Default constructor for SdncResponseDescriptor
+    }
+
+    public String getSvcRequestId() {
+        return svcRequestId;
+    }
+
+    public void setSvcRequestId(String svcRequestId) {
+        this.svcRequestId = svcRequestId;
+    }
+
+    public String getResponseCode() {
+        return responseCode;
+    }
+
+    public void setResponseCode(String responseCode) {
+        this.responseCode = responseCode;
+    }
+
+    public String getAckFinalIndicator() {
+        return ackFinalIndicator;
+    }
+
+    public void setAckFinalIndicator(String ackFinalIndicator) {
+        this.ackFinalIndicator = ackFinalIndicator;
+    }
+
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseServiceInfo.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/SdncResponseServiceInfo.java
new file mode 100644 (file)
index 0000000..745ba24
--- /dev/null
@@ -0,0 +1,44 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
+
+public class SdncResponseServiceInfo implements Serializable {
+
+    private static final long serialVersionUID = 6827782899144150158L;
+
+    @SerializedName("instance-id")
+    private String instanceId;
+
+    public SdncResponseServiceInfo() {
+        // Default constructor for SdncResponseServiceInfo
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+
+    public void setInstanceId(String instanceId) {
+        this.instanceId = instanceId;
+    }
+
+}
diff --git a/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java b/controlloop/common/model-impl/sdnc/src/main/java/org/onap/policy/sdnc/util/Serialization.java
new file mode 100644 (file)
index 0000000..260407a
--- /dev/null
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei Corp. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc.util;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public final class Serialization {
+    private Serialization() {
+    }
+    
+    public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping()
+            .setPrettyPrinting()
+            .create();
+
+}
diff --git a/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestDemo.java b/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestDemo.java
new file mode 100644 (file)
index 0000000..b002b7c
--- /dev/null
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import java.util.LinkedList;
+
+import org.junit.Test;
+import org.onap.policy.sdnc.util.Serialization;
+
+public class TestDemo {
+
+    @Test
+    public void test() {
+        SdncRequest request = new SdncRequest();
+
+        request.setNsInstanceId("100");
+        request.setHealRequest(new SdncHealRequest());
+
+        request.getHealRequest().setRequestHeaderInfo(new SdncHealRequestHeaderInfo());
+        request.getHealRequest().getRequestHeaderInfo().setSvcRequestId("service-req-01");
+        request.getHealRequest().getRequestHeaderInfo().setSvcAction("servive-action");
+
+        request.getHealRequest().setRequestInfo(new SdncHealRequestInfo());
+        request.getHealRequest().getRequestInfo().setRequestAction("request-action");
+        
+        request.getHealRequest().setServiceInfo(new SdncHealServiceInfo());
+        request.getHealRequest().getServiceInfo().setServiceInstanceId("service-instance-01");
+        
+        request.getHealRequest().setNetworkInfo(new SdncHealNetworkInfo());
+        request.getHealRequest().getNetworkInfo().setNetworkId("network-5555");
+        
+
+        String body = Serialization.gsonPretty.toJson(request);
+        System.out.println(body);
+
+        SdncResponse response = new SdncResponse();
+
+        body = Serialization.gsonPretty.toJson(response);
+        System.out.println(body);
+
+        response.setRequestId("request-01");
+        response.setResponseOutput(new SdncResponseOutput());
+        response.getResponseOutput().setSvcRequestId("service-req-01");
+        response.getResponseOutput().setResponseCode("200");
+        response.getResponseOutput().setAckFinalIndicator("final-indicator-00");
+        
+        body = Serialization.gsonPretty.toJson(response);
+        System.out.println(body);
+
+        response = Serialization.gsonPretty.fromJson(body, SdncResponse.class);
+        body = Serialization.gsonPretty.toJson(response);
+        System.out.println(body);
+
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncHealAdditionalParams.java b/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncHealAdditionalParams.java
new file mode 100644 (file)
index 0000000..a282ddc
--- /dev/null
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * vfc
+ * ================================================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class TestSdncHealAdditionalParams {
+
+    @Test
+    public void testSdncHealAdditionalParameters() {
+        SdncHealRequestHeaderInfo additionalParams = new SdncHealRequestHeaderInfo();
+        assertNotNull(additionalParams);
+        assertNotEquals(0, additionalParams.hashCode());
+        
+        String action = "Go Home";
+        additionalParams.setSvcAction(action);
+        assertEquals(action, additionalParams.getSvcAction());
+        
+        String requestId = "My Request";
+        additionalParams.setSvcRequestId(requestId);
+        assertEquals(requestId, additionalParams.getSvcRequestId());
+        
+        assertNotEquals(0, additionalParams.hashCode());
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncHealRequest.java b/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncHealRequest.java
new file mode 100644 (file)
index 0000000..96d19b7
--- /dev/null
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * vfc
+ * ================================================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class TestSdncHealRequest {
+
+    @Test
+    public void testSdncHealRequest() {
+        SdncHealRequest request = new SdncHealRequest();
+        assertNotNull(request);
+        assertNotEquals(0, request.hashCode());
+        
+        SdncHealRequestInfo requestInfo = new SdncHealRequestInfo();
+        request.setRequestInfo(requestInfo);
+        assertEquals(requestInfo, request.getRequestInfo());
+        
+        assertNotEquals(0, request.hashCode());
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncHealServiceInfo.java b/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncHealServiceInfo.java
new file mode 100644 (file)
index 0000000..92bb4a7
--- /dev/null
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdnc
+ * ================================================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class TestSdncHealServiceInfo {
+
+    @Test
+    public void testSdncHealServiceInfo() {
+        SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
+        assertNotNull(serviceInfo);
+        assertNotEquals(0, serviceInfo.hashCode());
+        
+        String svrid = "ECity";
+        serviceInfo.setServiceInstanceId(svrid);
+        assertEquals(svrid, serviceInfo.getServiceInstanceId());
+        
+        assertNotEquals(0, serviceInfo.hashCode());
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncManager.java b/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncManager.java
new file mode 100644 (file)
index 0000000..ec6c0a5
--- /dev/null
@@ -0,0 +1,281 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdnc
+ * ================================================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.endsWith;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.startsWith;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.drools.core.WorkingMemory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.rest.RESTManager;
+import org.onap.policy.rest.RESTManager.Pair;
+import org.onap.policy.sdnc.util.Serialization;
+
+public class TestSdncManager {
+    private static WorkingMemory mockedWorkingMemory;
+
+    private RESTManager   mockedRestManager;
+
+    private Pair<Integer, String> httpResponsePutOk;
+    private Pair<Integer, String> httpResponseGetOk;
+    private Pair<Integer, String> httpResponseBadResponse;
+    private Pair<Integer, String> httpResponseErr;
+
+    private SdncRequest  request;
+    private SdncResponse response;
+
+    @BeforeClass
+    public static void beforeTestSdncManager() {
+        mockedWorkingMemory = mock(WorkingMemory.class);
+    }
+
+    /**
+     * Set up the mocked REST manager.
+     */
+    @Before
+    public void setupMockedRest() {
+        mockedRestManager   = mock(RESTManager.class);
+        
+        httpResponsePutOk       = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
+        httpResponseGetOk       = mockedRestManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
+        httpResponseBadResponse = mockedRestManager.new Pair<>(202, Serialization.gsonPretty.toJson(null));
+        httpResponseErr         = mockedRestManager.new Pair<>(200, null);
+    }
+    
+    /**
+     * Create the request and response before.
+     */
+    @Before
+    public void createRequestAndResponse() {
+        SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
+        serviceInfo.setServiceInstanceId("E-City");
+
+        SdncHealRequestHeaderInfo additionalParams = new SdncHealRequestHeaderInfo();
+        additionalParams.setSvcAction("Go Home");
+        additionalParams.setSvcRequestId("My Request");
+    
+        SdncHealRequest healRequest = new SdncHealRequest();
+        healRequest.setRequestHeaderInfo(additionalParams);
+        healRequest.setServiceInfo(serviceInfo);
+
+        UUID requestId = UUID.randomUUID();
+        request = new SdncRequest();
+        request.setRequestId(requestId);
+        request.setHealRequest(healRequest);
+        request.setNsInstanceId("Dorothy");
+
+        SdncResponseOutput responseDescriptor = new SdncResponseOutput();
+        responseDescriptor.setSvcRequestId("1234");
+        responseDescriptor.setResponseCode("200");
+        responseDescriptor.setAckFinalIndicator("final-indicator-00");
+
+        response = new SdncResponse();
+        response.setRequestId(request.getRequestId().toString());
+        response.setResponseOutput(responseDescriptor);
+    }
+    
+    /**
+     * After Test clean up.
+     */
+    @After
+    public void afterTestSdncManager() throws InterruptedException {
+        PolicyEngine.manager.getEnvironment().remove("sdnc.password");
+        PolicyEngine.manager.getEnvironment().remove("sdnc.username");
+        PolicyEngine.manager.getEnvironment().remove("sdnc.url");
+    }
+
+    @Test
+    public void testSdncInitiation() throws InterruptedException {
+        try {
+            new SdncManager(null, null);
+            fail("test should throw an exception here");
+        }
+        catch (IllegalArgumentException e) {
+            assertEquals(
+                "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null", 
+                e.getMessage()
+            );
+        }
+    
+        try {
+            new SdncManager(mockedWorkingMemory, null);
+            fail("test should throw an exception here");
+        }
+        catch (IllegalArgumentException e) {
+            assertEquals(
+                "the parameters \"wm\" and \"request\" on the SdncManager constructor may not be null", 
+                e.getMessage()
+            );
+        }
+        
+        try {
+            new SdncManager(mockedWorkingMemory, request);
+            fail("test should throw an exception here");
+        }
+        catch (IllegalArgumentException e) {
+            assertEquals(
+                "The value of policy engine manager environment property \"sdnc.url\" may not be null", 
+                e.getMessage()
+            );
+        }
+        
+        PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
+        try {
+            new SdncManager(mockedWorkingMemory, request);
+            fail("test should throw an exception here");
+        }
+        catch (IllegalArgumentException e) {
+            assertEquals(
+                "The value of policy engine manager environment property \"sdnc.username\" may not be null", 
+                e.getMessage()
+            );
+        }
+        
+        PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
+        try {
+            new SdncManager(mockedWorkingMemory, request);
+            fail("test should throw an exception here");
+        }
+        catch (IllegalArgumentException e) {
+            assertEquals(
+                "The value of policy engine manager environment property \"sdnc.password\" may not be null", 
+                e.getMessage()
+            );
+        }
+        
+        PolicyEngine.manager.getEnvironment().put("sdnc.password", "Toto");
+        new SdncManager(mockedWorkingMemory, request);
+    }
+
+    @Test
+    public void testSdncExecutionException() throws InterruptedException {
+        PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
+        PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
+        PolicyEngine.manager.getEnvironment().put("sdnc.password", "Exception");
+
+        SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+        manager.setRestManager(mockedRestManager);
+
+        Thread managerThread = new Thread(manager);
+        managerThread.start();
+
+        when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Exception"), anyMap(), anyString(), anyString()))
+            .thenThrow(new RuntimeException("OzException"));
+        
+
+        managerThread.join(100);
+    }
+    
+    @Test
+    public void testSdncExecutionNull() throws InterruptedException {
+        PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
+        PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
+        PolicyEngine.manager.getEnvironment().put("sdnc.password", "Null");
+
+        SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+        manager.setRestManager(mockedRestManager);
+
+        Thread managerThread = new Thread(manager);
+        managerThread.start();
+        
+        when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
+            .thenReturn(null);
+        
+        managerThread.join(100);
+    }
+
+
+    @Test
+    public void testSdncExecutionError0() throws InterruptedException {
+        PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
+        PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
+        PolicyEngine.manager.getEnvironment().put("sdnc.password", "Error0");
+
+        SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+        manager.setRestManager(mockedRestManager);
+        
+        Thread managerThread = new Thread(manager);
+        managerThread.start();
+        
+        when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Error0"), anyMap(), anyString(), anyString()))
+            .thenReturn(httpResponseErr);
+        
+        managerThread.join(100);
+    }
+
+    @Test
+    public void testSdncExecutionBadResponse() throws InterruptedException {
+        PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
+        PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
+        PolicyEngine.manager.getEnvironment().put("sdnc.password", "BadResponse");
+
+        SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+        manager.setRestManager(mockedRestManager);
+        
+        Thread managerThread = new Thread(manager);
+        managerThread.start();
+        
+        when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
+            .thenReturn(httpResponseBadResponse);
+        
+        managerThread.join(100);
+    }
+    
+    @Test
+    public void testSdncExecutionOk() throws InterruptedException {
+        PolicyEngine.manager.getEnvironment().put("sdnc.url", "http://somewhere.over.the.rainbow");
+        PolicyEngine.manager.getEnvironment().put("sdnc.username", "Dorothy");
+        PolicyEngine.manager.getEnvironment().put("sdnc.password", "OK");
+        
+        SdncManager manager = new SdncManager(mockedWorkingMemory, request);
+        manager.setRestManager(mockedRestManager);
+        
+        Thread managerThread = new Thread(manager);
+        managerThread.start();
+
+        when(mockedRestManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("OK"), anyMap(), anyString(), anyString()))
+            .thenReturn(httpResponsePutOk);
+        
+        when(mockedRestManager.get(endsWith("1234"), eq("Dorothy"), eq("OK"), anyMap()))
+            .thenReturn(httpResponseGetOk);
+        
+
+        managerThread.join(100);
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncRequest.java b/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncRequest.java
new file mode 100644 (file)
index 0000000..adb07b9
--- /dev/null
@@ -0,0 +1,53 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdnc
+ * ================================================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.UUID;
+
+import org.junit.Test;
+
+public class TestSdncRequest {
+
+    @Test
+    public void testSdncRequest() {
+        SdncRequest request = new SdncRequest();
+        assertNotNull(request);
+        assertNotEquals(0, request.hashCode());
+        
+        String nsInstanceId = "Dorothy";
+        request.setNsInstanceId(nsInstanceId);
+        assertEquals(nsInstanceId, request.getNsInstanceId());
+        
+        UUID requestId = UUID.randomUUID();
+        request.setRequestId(requestId);
+        assertEquals(requestId, request.getRequestId());
+        
+        SdncHealRequest healRequest = new SdncHealRequest();
+        request.setHealRequest(healRequest);
+        assertEquals(healRequest, request.getHealRequest());
+        
+        assertNotEquals(0, request.hashCode());
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncResponse.java b/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncResponse.java
new file mode 100644 (file)
index 0000000..5daa12a
--- /dev/null
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdnc
+ * ================================================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+import org.junit.Test;
+
+public class TestSdncResponse {
+
+    @Test
+    public void testSdncResponse() {
+        SdncResponse response = new SdncResponse();
+        assertNotNull(response);
+        assertNotEquals(0, response.hashCode());
+        
+        String requestId = "Get Home";
+        response.setRequestId(requestId);
+        assertEquals(requestId, response.getRequestId());
+        
+        SdncResponseOutput responseDescriptor = new SdncResponseOutput();
+        response.setResponseOutput(responseDescriptor);
+        assertEquals(responseDescriptor, response.getResponseOutput());
+        
+        assertNotEquals(0, response.hashCode());
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncResponseDescriptor.java b/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/TestSdncResponseDescriptor.java
new file mode 100644 (file)
index 0000000..5c88228
--- /dev/null
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdnc
+ * ================================================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+public class TestSdncResponseDescriptor {
+
+    @Test
+    public void testSdncResponseDescriptor() {
+        SdncResponseOutput output = new SdncResponseOutput();
+        assertNotNull(output);
+        assertNotEquals(0, output.hashCode());
+        
+        String responseCode = "200";
+        output.setResponseCode(responseCode);
+        assertEquals(responseCode, output.getResponseCode());
+        
+        String svcRequest = "svc-request-01";
+        output.setSvcRequestId(svcRequest);
+        assertEquals(svcRequest, output.getSvcRequestId());
+        
+        String indicator = "final-indicator-00";
+        output.setAckFinalIndicator(indicator);
+        assertEquals(indicator, output.getAckFinalIndicator());
+        
+        assertNotEquals(0, output.hashCode());
+    }
+}
diff --git a/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/TestSerialization.java b/controlloop/common/model-impl/sdnc/src/test/java/org/onap/policy/sdnc/util/TestSerialization.java
new file mode 100644 (file)
index 0000000..9d02d4f
--- /dev/null
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * vfc
+ * ================================================================================
+ * Copyright (C) 2018 Huawei. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.sdnc.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class TestSerialization {
+
+    @Test
+    public void test() {
+        assertNotNull(Serialization.gsonPretty);
+    }
+}
index 91e36c0..c2868a2 100644 (file)
@@ -99,6 +99,9 @@ public class MsbServiceFactory implements Serializable {
             case "VFC":
                 node = this.build("nfvo-nslcm", "v1");
                 return node;
+            case "SDNC":
+                node = this.build("sdnc-nslcm", "v10");      //... ???
+                return node;                
             default:
                 logger.info("MSBServiceManager: policy has an unknown actor.");
         }
index aca3ff2..b94992c 100644 (file)
@@ -37,7 +37,7 @@ public class MsbServiceManager implements Serializable {
     /**
      * Get the IP and port of the components registered in the MSB.
      * 
-     * @param actor AAI or SO or VFC
+     * @param actor AAI or SO or VFC or SNDC
      * @return the node
      */
     public Node getNode(String actor) {
index 86fe1ed..5f813c2 100644 (file)
@@ -48,3 +48,7 @@ pdpx.client.password=${{PDP_CLIENT_PASSWORD}}
 guard.url=http://${{PDP_HOST}}:8081/pdp/api/getDecision
 guard.jdbc.url=mariadb://${{SQL_HOST}}:3306/operationshistory10
 guard.disabled=true
+
+sdnc.url=${{SDNC_URL}}
+sdnc.username=${{SDNC_USERNAME}}
+sdnc.password=${{SDNC_PASSWORD}}
\ No newline at end of file
index ecbf903..f39acc1 100644 (file)
       <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
       <artifactId>so</artifactId>
       <version>${dependenciesVersion}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+      <artifactId>sdnc</artifactId>
+      <version>${dependenciesVersion}</version>
     </dependency>      
     <dependency>
       <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
       <artifactId>actor.vfc</artifactId>
       <version>${dependenciesVersion}</version>
     </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
+      <artifactId>actor.sdnc</artifactId>
+      <version>${dependenciesVersion}</version>
+    </dependency>    
     <dependency>
       <groupId>org.onap.policy.drools-applications.controlloop.common</groupId>
       <artifactId>policy-yaml</artifactId>
index 9a1a292..5e49010 100644 (file)
@@ -56,6 +56,9 @@ import org.onap.policy.so.SORelatedInstanceListElement;
 import org.onap.policy.so.SORelatedInstance;
 import org.onap.policy.so.SOResponse;
 import org.onap.policy.so.SOResponseWrapper;
+import org.onap.policy.sdnc.SdncRequest;
+import org.onap.policy.sdnc.SdncManager;
+import org.onap.policy.sdnc.SdncResponse;
 import org.onap.policy.guard.PolicyGuard;
 import org.onap.policy.guard.PolicyGuard.LockResult;
 import org.onap.policy.guard.TargetLock;
@@ -580,6 +583,14 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
                       t.start();
                   }          
                   break;
+                
+              case "SDNC":
+                  if (request instanceof SdncRequest) {
+                     // Start SDNC thread
+                     Thread t = new Thread(new SdncManager(drools.getWorkingMemory(), (SdncRequest)request));
+                     t.start();
+                  }
+                  break;                       
           }
         } else {
           //
@@ -1164,6 +1175,83 @@ rule "${policyName}.VFC.RESPONSE"
 
 end
 
+/*
+*
+* This rule responds to SDNC Response Events
+*
+*/
+
+rule "${policyName}.SDNC.RESPONSE"
+    when
+        $params : Params( getClosedLoopControlName() == "${closedLoopControlName}" )
+        $event : VirtualControlLoopEvent( closedLoopControlName == $params.getClosedLoopControlName(), 
+            closedLoopEventStatus == ControlLoopEventStatus.ONSET )
+        $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), 
+            requestID == $event.getRequestId() )
+        $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), 
+            onset.getRequestId() == $event.getRequestId() )
+        $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), 
+            requestID == $event.getRequestId().toString(), timerType == "Operation", !expired )
+        $lock : TargetLock (requestID == $event.getRequestId())
+        $response : SdncResponse( requestId.toString() == $event.getRequestId().toString() )    
+    then
+        Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
+        logger.info("{}: {}", $params.getClosedLoopControlName(), drools.getRule().getName());
+        logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}", 
+                    $params.getClosedLoopControlName(), drools.getRule().getName(),
+                    $event, $manager, $operation, $lock, $operation, $opTimer, $response);
+
+        // Get the result of the operation
+        //
+        PolicyResult policyResult = $operation.onResponse($response);
+        if (policyResult != null) {
+            //
+            // This Operation has completed, construct a notification showing our results
+            //
+            VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
+            notification.setFrom("policy");
+            notification.setPolicyName(drools.getRule().getName());
+            notification.setPolicyScope("${policyScope}");
+            notification.setPolicyVersion("${policyVersion}");
+            notification.setMessage($operation.getOperationHistory());
+            notification.setHistory($operation.getHistory());
+            //
+            // Ensure the operation is complete
+            //
+            if ($operation.isOperationComplete()) {
+                //
+                // It is complete, remove it from memory
+                //
+                retract($operation);
+                //
+                // We must also retract the timer object
+                // NOTE: We could write a Rule to do this
+                //
+                retract($opTimer);
+                //
+                // Complete the operation
+                //
+                modify($manager) {finishOperation($operation)};
+            } else {
+                //
+                // Just doing this will kick off the LOCKED rule again
+                //
+                modify($operation) {};
+            }
+        } else {
+            //
+            // Its not finished yet (i.e. expecting more Response objects)
+            //
+            // Or possibly it is a leftover response that we timed the request out previously
+            //
+        }
+        //
+        // We are going to retract these objects from memory
+        //
+        retract($response);
+
+end
+
 /*
 *
 * This manages a single timer.
index aa56082..e44ebb2 100644 (file)
       <artifactId>sdnr</artifactId>
       <version>${dependenciesVersion}</version>
     </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+      <artifactId>sdnc</artifactId>
+      <version>${dependenciesVersion}</version>
+    </dependency>
     <dependency>
       <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
       <artifactId>trafficgenerator</artifactId>
       <artifactId>actor.vfc</artifactId>
       <version>${dependenciesVersion}</version>
     </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
+      <artifactId>actor.sdnc</artifactId>
+      <version>${dependenciesVersion}</version>
+    </dependency>    
     <dependency>
       <groupId>org.onap.policy.drools-applications.controlloop.common</groupId>
       <artifactId>policy-yaml</artifactId>
index f2fe231..11855d4 100644 (file)
@@ -61,6 +61,9 @@ import org.onap.policy.so.SORelatedInstanceListElement;
 import org.onap.policy.so.SORelatedInstance;
 import org.onap.policy.so.SOResponse;
 import org.onap.policy.so.SOResponseWrapper;
+import org.onap.policy.sdnc.SdncRequest;
+import org.onap.policy.sdnc.SdncManager;
+import org.onap.policy.sdnc.SdncResponse;
 import org.onap.policy.guard.PolicyGuard;
 import org.onap.policy.guard.PolicyGuard.LockResult;
 import org.onap.policy.guard.TargetLock;
@@ -550,6 +553,14 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
                       PolicyEngine.manager.deliver("SDNR-CL", request);
                   }
                   break;
+              
+              case "SDNC":
+                  if (request instanceof SdncRequest) {
+                     // Start SDNC thread
+                     Thread t = new Thread(new SdncManager(drools.getWorkingMemory(), (SdncRequest)request));
+                     t.start();
+                  }
+                  break;                 
           }
         } else {
           //
@@ -1135,6 +1146,79 @@ rule "VFC.RESPONSE"
 
 end
 
+/*
+*
+* This rule responds to SDNC Response Events
+*
+*/
+rule "SDNC.RESPONSE"
+    when
+        $params : ControlLoopParams( $clName : getClosedLoopControlName() )
+        $event : VirtualControlLoopEvent( closedLoopControlName == $clName, closedLoopEventStatus == ControlLoopEventStatus.ONSET )
+        $manager : ControlLoopEventManager( closedLoopControlName == $event.getClosedLoopControlName(), requestID == $event.getRequestId() )
+        $operation : ControlLoopOperationManager( onset.closedLoopControlName == $event.getClosedLoopControlName(), onset.getRequestId() == $event.getRequestId() )
+        $opTimer : ControlLoopTimer( closedLoopControlName == $event.getClosedLoopControlName(), 
+            requestID == $event.getRequestId().toString(), timerType == "Operation", !expired )
+        $lock : TargetLock (requestID == $event.getRequestId())
+        $response : SdncResponse( requestId.toString() == $event.getRequestId().toString() )
+    then
+        Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
+        logger.info("{}: {}", $clName, $params.getPolicyName() + "." + drools.getRule().getName());
+        logger.debug("{}: {}: event={} manager={} operation={} lock={} opTimer={} response={}",
+                       $clName, $params.getPolicyName() + "." + drools.getRule().getName(),
+                       $event, $manager, $operation, $lock, $operation, $opTimer, $response);
+
+        // Get the result of the operation
+        //
+        PolicyResult policyResult = $operation.onResponse($response);
+        if (policyResult != null) {
+            //
+            // This Operation has completed, construct a notification showing our results
+            //
+            VirtualControlLoopNotification notification = new VirtualControlLoopNotification($event);
+            notification.setFrom("policy");
+            notification.setPolicyName($params.getPolicyName() + "." + drools.getRule().getName());
+            notification.setPolicyScope($params.getPolicyScope());
+            notification.setPolicyVersion($params.getPolicyVersion());
+            notification.setMessage($operation.getOperationHistory());
+            notification.setHistory($operation.getHistory());
+            //
+            // Ensure the operation is complete
+            //
+            if ($operation.isOperationComplete()) {
+                //
+                // It is complete, remove it from memory
+                //
+                retract($operation);
+                //
+                // We must also retract the timer object
+                // NOTE: We could write a Rule to do this
+                //
+                retract($opTimer);
+                //
+                // Complete the operation
+                //
+                modify($manager) {finishOperation($operation)};
+            } else {
+                //
+                // Just doing this will kick off the LOCKED rule again
+                //
+                modify($operation) {};
+            }
+        } else {
+            //
+            // Its not finished yet (i.e. expecting more Response objects)
+            //
+            // Or possibly it is a leftover response that we timed the request out previously
+            //
+        }
+        //
+        // We are going to retract these objects from memory
+        //
+        retract($response);
+
+end
+
 /*
 *
 * This manages a single timer.
index 9295d78..574d1ce 100644 (file)
       <version>${project.version}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+      <artifactId>sdnc</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>    
     <dependency>
       <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
       <artifactId>events</artifactId>
       <version>${project.version}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
+      <artifactId>actor.sdnc</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>   
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
index 6b13022..138bfc7 100644 (file)
       <version>${project.version}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
+      <artifactId>sdnc</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>    
     <dependency>
       <groupId>org.onap.policy.drools-applications.controlloop.common.model-impl</groupId>
       <artifactId>events</artifactId>
       <version>${project.version}</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.onap.policy.drools-applications.controlloop.common.actors</groupId>
+      <artifactId>actor.sdnc</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+    </dependency>    
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>