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>
--- /dev/null
+<?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>
--- /dev/null
+/*-
+ * ============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;
+ }
+
+
+}
--- /dev/null
+org.onap.policy.controlloop.actor.vfc.APPCActorServiceProvider
<modules>
<module>actorServiceProvider</module>
<module>actor.appc</module>
+ <module>actor.vfc</module>
<module>actor.mso</module>
<module>actor.test</module>
</modules>
<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>
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;
break;
case "SDNO":
break;
- case "SDNR":
+ case "VFC":
break;
default:
throw new ControlLoopException("ControlLoopEventManager: policy has an unknown actor.");
//
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;
}
<module>rest</module>
<module>sdc</module>
<module>trafficgenerator</module>
+ <module>vfc</module>
</modules>
--- /dev/null
+<!--
+ ============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>
--- /dev/null
+/*-\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
--- /dev/null
+/*-\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
--- /dev/null
+/*-\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
--- /dev/null
+/*-
+ * ============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");
+ }
+ }
+}
--- /dev/null
+/*-
+ * ============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() {
+ }
+
+}
--- /dev/null
+/*-
+ * ============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() {
+ }
+
+}
--- /dev/null
+/*-
+ * ============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() {
+ }
+
+}
--- /dev/null
+/*-
+ * ============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() {
+ }
+
+}
--- /dev/null
+/*-
+ * ============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();
+
+}
--- /dev/null
+/*-
+ * ============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);
+
+ }
+}
<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>
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;
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?