Add VFC integration code 17/8517/3
authorRitu Sood <ritu.sood@intel.com>
Wed, 23 Aug 2017 14:52:20 +0000 (07:52 -0700)
committerRitu Sood <ritu.sood@intel.com>
Thu, 24 Aug 2017 13:33:57 +0000 (06:33 -0700)
This patch adds VFC Actor code and updates drool template for VFC.
This is WIP patch. There are two opens for this patch that are
still in discussion

1) AA&I fields in onset event
2) VFC URL, username and password

Issue-ID: POLICY-57
Change-Id: Idc1d1fada295fa1c2e563ba37dd359f7b5c59f87
Signed-off-by: Ritu Sood <ritu.sood@intel.com>
20 files changed:
controlloop/common/actors/actor.vfc/pom.xml [new file with mode: 0644]
controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java [new file with mode: 0644]
controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor [new file with mode: 0644]
controlloop/common/actors/pom.xml
controlloop/common/eventmanager/pom.xml
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
controlloop/common/model-impl/pom.xml
controlloop/common/model-impl/vfc/pom.xml [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealActionVmInfo.java [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealAdditionalParams.java [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealRequest.java [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCRequest.java [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponse.java [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseDescriptor.java [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseHistoryList.java [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java [new file with mode: 0644]
controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestDemo.java [new file with mode: 0644]
controlloop/packages/artifacts/pom.xml
controlloop/templates/template.demo/src/main/resources/ControlLoop_Template_xacml_guard.drl

diff --git a/controlloop/common/actors/actor.vfc/pom.xml b/controlloop/common/actors/actor.vfc/pom.xml
new file mode 100644 (file)
index 0000000..de6f058
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<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</groupId>
+            <artifactId>actors</artifactId>
+            <version>1.1.0-SNAPSHOT</version>
+       </parent>
+       <artifactId>actor.vfc</artifactId>
+       <dependencies>
+               <dependency>
+               <groupId>org.onap.policy.drools-applications</groupId>
+                       <artifactId>actorServiceProvider</artifactId>
+                       <version>1.1.0-SNAPSHOT</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.onap.policy.drools-applications</groupId>
+                       <artifactId>vfc</artifactId>
+                       <version>1.1.0-SNAPSHOT</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.onap.policy.drools-applications</groupId>
+                       <artifactId>events</artifactId>
+                       <version>1.1.0-SNAPSHOT</version>
+                       <scope>provided</scope>
+               </dependency>
+       </dependencies>
+</project>
diff --git a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java
new file mode 100644 (file)
index 0000000..ffada0a
--- /dev/null
@@ -0,0 +1,94 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2017 Intel 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.vfc;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.vfc.VFCRequest;
+import org.onap.policy.vfc.VFCHealRequest;
+import org.onap.policy.vfc.VFCHealAdditionalParams;
+import org.onap.policy.vfc.VFCHealActionVmInfo;
+import org.onap.policy.controlloop.ControlLoopOperation;
+import org.onap.policy.controlloop.policy.Policy;
+
+import org.onap.policy.controlloop.actorServiceProvider.spi.Actor;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+
+public class VFCActorServiceProvider implements Actor {
+
+    private static final ImmutableList<String> recipes = ImmutableList.of("Restart");
+    private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
+            .put("Restart", ImmutableList.of("VM"))
+            .build();
+
+    @Override
+    public String actor() {
+        return "VFC";
+    }
+
+    @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();
+    }
+
+    public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) {
+
+        // Construct an VFC request
+        VFCRequest request = new VFCRequest();
+        // TODO: Verify service-instance-id is part of onset event
+        request.nsInstanceId = onset.AAI.get("service-instance.service-instance-id");
+        request.healRequest = new VFCHealRequest();
+        request.healRequest.vnfInstanceId = onset.AAI.get("generic-vnf.vnf-id");
+        request.healRequest.cause = operation.message;
+
+        request.healRequest.additionalParams = new VFCHealAdditionalParams();
+        switch (policy.getRecipe()) {
+            case "Restart":
+                // TODO: check target??
+                request.healRequest.additionalParams.action = "restartvm";
+                request.healRequest.additionalParams.actionInfo = new VFCHealActionVmInfo();
+                // TODO: Verify vserver-id and vserver-name is part of onset event
+                request.healRequest.additionalParams.actionInfo.vmid = onset.AAI.get("vserver.vserver-id");
+                request.healRequest.additionalParams.actionInfo.vmname = onset.AAI.get("vserver.vserver-name");
+                break;
+            default:
+                //TODO: default
+                break;
+        }
+        return request;
+    }
+
+
+}
diff --git a/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor b/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor
new file mode 100644 (file)
index 0000000..3ccac99
--- /dev/null
@@ -0,0 +1 @@
+org.onap.policy.controlloop.actor.vfc.APPCActorServiceProvider
index a00a3af..e99fbb0 100644 (file)
@@ -14,6 +14,7 @@
        <modules>
                <module>actorServiceProvider</module>
                <module>actor.appc</module>
+               <module>actor.vfc</module>
            <module>actor.mso</module>
                <module>actor.test</module>
     </modules>
index efe7b34..b33763b 100644 (file)
                        <version>1.1.0-SNAPSHOT</version>
                        <scope>provided</scope>
                </dependency>
+                <dependency>
+                        <groupId>org.onap.policy.drools-applications</groupId>
+                        <artifactId>actor.vfc</artifactId>
+                        <version>1.1.0-SNAPSHOT</version>
+                        <scope>provided</scope>
+                </dependency>
                <dependency>
                        <groupId>org.onap.policy.drools-applications</groupId>
                        <artifactId>guard</artifactId>
                        <version>1.1.0-SNAPSHOT</version>
                        <scope>provided</scope>
                </dependency>
+                <dependency>
+                        <groupId>org.onap.policy.drools-applications</groupId>
+                        <artifactId>vfc</artifactId>
+                        <version>1.1.0-SNAPSHOT</version>
+                        <scope>provided</scope>
+                </dependency>
                <dependency>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
index f552cc5..0df58be 100644 (file)
@@ -37,6 +37,7 @@ import org.onap.policy.controlloop.ControlLoopException;
 import org.onap.policy.controlloop.policy.Policy;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.controlloop.actor.appc.APPCActorServiceProvider;
+import org.onap.policy.controlloop.actor.vfc.VFCActorServiceProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -132,7 +133,7 @@ public class ControlLoopOperationManager implements Serializable {
                        break;
                case "SDNO":
                        break;
-               case "SDNR":
+               case "VFC":
                        break;
                default:
                        throw new ControlLoopException("ControlLoopEventManager: policy has an unknown actor.");
@@ -212,6 +213,11 @@ public class ControlLoopOperationManager implements Serializable {
                        //
                        System.out.println("We are not supporting MSO actor in the latest release.");
                        return null;
+               case "VFC":
+                        this.operationRequest = VFCActorServiceProvider.constructRequest((VirtualControlLoopEvent) onset, operation.operation, this.policy);
+                        this.currentOperation = operation;
+                        return operationRequest;
+
                }
                return null;
        }
index 94c3f34..5d18e49 100644 (file)
@@ -40,6 +40,7 @@
        <module>rest</module>
        <module>sdc</module>
        <module>trafficgenerator</module>
+        <module>vfc</module>
     </modules>
 
 
diff --git a/controlloop/common/model-impl/vfc/pom.xml b/controlloop/common/model-impl/vfc/pom.xml
new file mode 100644 (file)
index 0000000..db86345
--- /dev/null
@@ -0,0 +1,49 @@
+<!--
+  ============LICENSE_START=======================================================
+  Copyright (C) 2017 Intel 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=========================================================
+  -->
+
+<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>
+
+  <artifactId>vfc</artifactId>
+
+       <parent>
+               <groupId>org.onap.policy.drools-applications</groupId>
+               <artifactId>model-impl</artifactId>
+               <version>1.1.0-SNAPSHOT</version>
+       </parent>
+
+  <dependencies>
+       <dependency>
+               <groupId>junit</groupId>
+               <artifactId>junit</artifactId>
+               <version>4.12</version>
+               <scope>provided</scope>
+       </dependency>
+       <dependency>
+               <groupId>com.google.code.gson</groupId>
+               <artifactId>gson</artifactId>
+               <version>2.5</version>
+               <scope>provided</scope>
+       </dependency>
+       <dependency>
+               <groupId>org.onap.policy.drools-applications</groupId>
+               <artifactId>rest</artifactId>
+               <version>${project.version}</version>
+       </dependency>
+  </dependencies>
+</project>
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealActionVmInfo.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealActionVmInfo.java
new file mode 100644 (file)
index 0000000..b2535e3
--- /dev/null
@@ -0,0 +1,40 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * Copyright (C) 2017 Intel Corp. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.policy.vfc;\r
+\r
+import java.io.Serializable;\r
+import java.time.LocalDateTime;\r
+\r
+import com.google.gson.annotations.SerializedName;\r
+\r
+public class VFCHealActionVmInfo implements Serializable {\r
+\r
+       private static final long serialVersionUID = 3208673205100673119L;
+\r
+       @SerializedName("vmid")\r
+       public String vmid;\r
+\r
+       @SerializedName("vmname")\r
+       public String vmname;\r
+\r
+\r
+       public VFCHealActionVmInfo() {\r
+       }\r
+\r
+}\r
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealAdditionalParams.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealAdditionalParams.java
new file mode 100644 (file)
index 0000000..a65ad8a
--- /dev/null
@@ -0,0 +1,39 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * Copyright (C) 2017 Intel Corp. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.policy.vfc;\r
+\r
+import java.io.Serializable;\r
+import java.time.LocalDateTime;\r
+\r
+import com.google.gson.annotations.SerializedName;\r
+\r
+public class VFCHealAdditionalParams implements Serializable {\r
+\r
+       private static final long serialVersionUID = 2656694137285096191L;
+\r
+       @SerializedName("action")\r
+       public String action;\r
+\r
+       @SerializedName("actionvminfo")\r
+       public VFCHealActionVmInfo actionInfo;\r
+\r
+       public VFCHealAdditionalParams() {\r
+       }\r
+\r
+}\r
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealRequest.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealRequest.java
new file mode 100644 (file)
index 0000000..f7fc891
--- /dev/null
@@ -0,0 +1,42 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * Copyright (C) 2017 Intel Corp. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.policy.vfc;\r
+\r
+import java.io.Serializable;\r
+import java.time.LocalDateTime;\r
+\r
+import com.google.gson.annotations.SerializedName;\r
+\r
+public class VFCHealRequest implements Serializable {\r
+\r
+       private static final long serialVersionUID = -7341931593089709247L;
+\r
+       @SerializedName("vnfInstanceId")\r
+       public String vnfInstanceId;\r
+\r
+       @SerializedName("cause")\r
+       public String cause;\r
+\r
+       @SerializedName("additionalParams")\r
+       public VFCHealAdditionalParams additionalParams;\r
+\r
+       public VFCHealRequest() {\r
+       }\r
+\r
+}\r
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java
new file mode 100644 (file)
index 0000000..44f9905
--- /dev/null
@@ -0,0 +1,107 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2017 Intel 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.vfc;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.onap.policy.vfc.util.Serialization;
+import org.onap.policy.rest.RESTManager;
+import org.onap.policy.rest.RESTManager.Pair;
+
+import com.google.gson.JsonSyntaxException;
+
+public final class VFCManager implements Runnable {
+
+    private String vfcUrlBase;
+    private String username;
+    private String password;
+    private VFCRequest vfcRequest;
+
+    public VFCManager(VFCRequest request) {
+        vfcRequest = request;
+        // TODO: Get base URL, username and password from MSB?
+        // TODO: Following code is a placeholder, needs to be updated
+        setVFCParams("https://", "vfc", "vfc");
+
+    }
+
+    public void setVFCParams(String baseUrl, String name, String pwd) {
+        vfcUrlBase = baseUrl + "/api/nslcm/v1";
+        username = name;
+        password = pwd;
+    }
+
+    @Override
+    public void run() {
+
+        Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Accept", "application/json");
+
+        String vfcUrl = vfcUrlBase + "/ns/" + vfcRequest.nsInstanceId + "/heal";
+        Pair<Integer, String> httpDetails = RESTManager.post(vfcUrl, username, password, headers,
+                "application/json", Serialization.gsonPretty.toJson(vfcRequest));
+
+        if (httpDetails == null) {
+            return;
+        }
+
+        if (httpDetails.a == 202) {
+            try {
+                VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, VFCResponse.class);
+
+                String body = Serialization.gsonPretty.toJson(response);
+                System.out.println("Response to VFC Heal post:");
+                System.out.println(body);
+
+                String jobId = response.jobId;
+                int attemptsLeft = 20;
+
+                String urlGet = vfcUrlBase + "/jobs/" + jobId;
+                VFCResponse responseGet = null;
+
+                while (attemptsLeft-- > 0) {
+
+                    Pair<Integer, String> httpDetailsGet = RESTManager.get(urlGet, username, password, headers);
+                    responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, VFCResponse.class);
+                    body = Serialization.gsonPretty.toJson(responseGet);
+                    System.out.println("Response to VFC Heal get:");
+                    System.out.println(body);
+
+                    if (httpDetailsGet.a == 200) {
+                        if (responseGet.responseDescriptor.status.equalsIgnoreCase("finished") ||
+                                responseGet.responseDescriptor.status.equalsIgnoreCase("error")) {
+                            System.out.println("VFC Heal Status " + responseGet.responseDescriptor.status);
+                            break;
+                        }
+                    }
+                    Thread.sleep(20000);
+                }
+                if (attemptsLeft <= 0)
+                    System.out.println("VFC timeout. Status: (" + responseGet.responseDescriptor.status + ")");
+            } catch (JsonSyntaxException e) {
+                System.err.println("Failed to deserialize into VFCResponse" + e.getLocalizedMessage());
+            } catch (InterruptedException e) {
+                System.err.println("Interrupted exception: " + e.getLocalizedMessage());
+            }
+        } else {
+            System.out.println("VFC Heal Restcall failed");
+        }
+    }
+}
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCRequest.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCRequest.java
new file mode 100644 (file)
index 0000000..a45a62d
--- /dev/null
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2017 Intel 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.vfc;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+import com.google.gson.annotations.SerializedName;
+
+public class VFCRequest implements Serializable {
+
+    private static final long serialVersionUID = 3736300970326332512L;
+    // This field is not serialized and not part of JSON
+    public transient String nsInstanceId;
+
+    @SerializedName("healVnfData")
+    public VFCHealRequest healRequest;
+
+    public VFCRequest() {
+    }
+
+}
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponse.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponse.java
new file mode 100644 (file)
index 0000000..775d78f
--- /dev/null
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2017 Intel 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.vfc;
+
+import java.io.Serializable;
+
+import com.google.gson.annotations.SerializedName;
+
+public class VFCResponse implements Serializable {
+
+    private static final long serialVersionUID = 9151443891238218455L;
+
+    @SerializedName("jobId")
+    public String jobId;
+
+    @SerializedName("responseDescriptor")
+    VFCResponseDescriptor responseDescriptor;
+
+    public VFCResponse() {
+    }
+
+}
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseDescriptor.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseDescriptor.java
new file mode 100644 (file)
index 0000000..f156fa0
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2017 Intel 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.vfc;
+
+import java.io.Serializable;
+
+import com.google.gson.annotations.SerializedName;
+
+public class VFCResponseDescriptor implements Serializable {
+
+    private static final long serialVersionUID = 6827782899144150158L;
+
+    @SerializedName("progress")
+    public String progress;
+
+    @SerializedName("status")
+    String status;
+
+    @SerializedName("statusDescription")
+    String statusDescription;
+
+    @SerializedName("errorCode")
+    String errorCode;
+
+    @SerializedName("responseId")
+    String responseId;
+
+    @SerializedName("responseHistoryList")
+    VFCResponseHistoryList responseHistoryList;
+
+    public VFCResponseDescriptor() {
+    }
+
+}
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseHistoryList.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseHistoryList.java
new file mode 100644 (file)
index 0000000..3fe62ea
--- /dev/null
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2017 Intel 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.vfc;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+import com.google.gson.annotations.SerializedName;
+
+public class VFCResponseHistoryList implements Serializable {
+
+    private static final long serialVersionUID = 3340914325806649762L;
+
+    public List<VFCResponseDescriptor> responseDescriptorList= new LinkedList<>();
+
+    public VFCResponseHistoryList() {
+    }
+
+}
diff --git a/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java
new file mode 100644 (file)
index 0000000..6550852
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2017 Intel 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.vfc.util;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public final class Serialization {
+       
+       final static public Gson gsonPretty = new GsonBuilder().disableHtmlEscaping()
+                       .setPrettyPrinting()
+                       .create();
+
+}
diff --git a/controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestDemo.java b/controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestDemo.java
new file mode 100644 (file)
index 0000000..7e8c212
--- /dev/null
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2017 Intel 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.vfc;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.onap.policy.vfc.VFCRequest;
+import org.onap.policy.vfc.VFCHealRequest;
+import org.onap.policy.vfc.VFCHealAdditionalParams;
+import org.onap.policy.vfc.VFCHealActionVmInfo;
+import org.onap.policy.vfc.VFCResponse;
+import org.onap.policy.vfc.VFCResponseDescriptor;
+import org.onap.policy.vfc.VFCResponseHistoryList;
+import org.junit.Test;
+import org.onap.policy.vfc.util.Serialization;
+
+public class TestDemo {
+
+    @Test
+    public void test() {
+        VFCRequest request = new VFCRequest();
+
+        request.nsInstanceId = "100";
+        request.healRequest = new VFCHealRequest();
+        request.healRequest.vnfInstanceId = "1";
+        request.healRequest.cause = "vm is down";
+
+        request.healRequest.additionalParams = new VFCHealAdditionalParams();
+        request.healRequest.additionalParams.action = "restartvm";
+
+        request.healRequest.additionalParams.actionInfo = new VFCHealActionVmInfo();
+        request.healRequest.additionalParams.actionInfo.vmid = "33";
+        request.healRequest.additionalParams.actionInfo.vmname = "xgw-smp11";
+
+        String body = Serialization.gsonPretty.toJson(request);
+        System.out.println(body);
+
+        VFCResponse response = new VFCResponse();
+        response.jobId = "1";
+
+        body = Serialization.gsonPretty.toJson(response);
+        System.out.println(body);
+
+        response.responseDescriptor = new VFCResponseDescriptor();
+        response.responseDescriptor.progress = "40";
+        response.responseDescriptor.status = "processing";
+        response.responseDescriptor.statusDescription = "OMC VMs are decommissioned in VIM";
+        response.responseDescriptor.errorCode = null;
+        response.responseDescriptor.responseId = "42";
+        body = Serialization.gsonPretty.toJson(response);
+        System.out.println(body);
+
+        VFCResponseDescriptor responseDescriptor = new VFCResponseDescriptor();
+        responseDescriptor.progress = "20";
+        responseDescriptor.status = "processing";
+        responseDescriptor.statusDescription = "OMC VMs are decommissioned in VIM";
+        responseDescriptor.errorCode = null;
+        responseDescriptor.responseId = "11";
+
+        response.responseDescriptor.responseHistoryList = new VFCResponseHistoryList();
+        response.responseDescriptor.responseHistoryList.responseDescriptorList.add(responseDescriptor);
+
+        body = Serialization.gsonPretty.toJson(response);
+        System.out.println(body);
+
+    }
+}
index 27ec28a..f47f2b7 100644 (file)
                        <version>${project.version}</version>
                        <type>jar</type>
                </dependency>
+                <dependency>
+                        <groupId>org.onap.policy.drools-applications</groupId>
+                        <artifactId>vfc</artifactId>
+                        <version>${project.version}</version>
+                        <type>jar</type>
+                </dependency>
                <dependency>
                        <groupId>org.onap.policy.drools-applications</groupId>
                        <artifactId>aai</artifactId>
index a141f49..8eab478 100644 (file)
@@ -32,6 +32,8 @@ import org.onap.policy.controlloop.eventmanager.ControlLoopOperationManager;
 import org.onap.policy.appc.Request;
 import org.onap.policy.appc.Response;
 import org.onap.policy.appc.CommonHeader;
+import org.onap.policy.vfc.VFCRequest;
+import org.onap.policy.vfc.VFCManager;
 import org.onap.policy.guard.PolicyGuard;
 import org.onap.policy.guard.PolicyGuard.LockResult;
 import org.onap.policy.guard.TargetLock;
@@ -491,11 +493,15 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
                                        if (request instanceof Request) {
                                                Engine.deliver("UEB", "APPC-CL", request);
                                        }
-                               case "SDNR":
-                               default:
+                                       break;
+                               case "VFC":
+                                       if (request instanceof VFCRequest) {
+                                               // Start VFC thread
+                                               Thread t = new Thread(new VFCManager(request));
+                                               t.start();
+                                       }                       
+                                       break;
                        }
-                       
-                       
                } else {
                        //
                        // What happens if its null?