From 1c4fcf40b4cd33454bb57bde1e82a3819cb6ccff Mon Sep 17 00:00:00 2001 From: Ritu Sood Date: Wed, 23 Aug 2017 07:52:20 -0700 Subject: Add VFC integration code 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 --- controlloop/common/actors/actor.vfc/pom.xml | 32 ++++++ .../actor/vfc/VFCActorServiceProvider.java | 94 ++++++++++++++++++ ...licy.controlloop.actorServiceProvider.spi.Actor | 1 + controlloop/common/actors/pom.xml | 1 + controlloop/common/eventmanager/pom.xml | 12 +++ .../eventmanager/ControlLoopOperationManager.java | 8 +- controlloop/common/model-impl/pom.xml | 1 + controlloop/common/model-impl/vfc/pom.xml | 49 ++++++++++ .../org/onap/policy/vfc/VFCHealActionVmInfo.java | 40 ++++++++ .../onap/policy/vfc/VFCHealAdditionalParams.java | 39 ++++++++ .../java/org/onap/policy/vfc/VFCHealRequest.java | 42 ++++++++ .../main/java/org/onap/policy/vfc/VFCManager.java | 107 +++++++++++++++++++++ .../main/java/org/onap/policy/vfc/VFCRequest.java | 38 ++++++++ .../main/java/org/onap/policy/vfc/VFCResponse.java | 38 ++++++++ .../org/onap/policy/vfc/VFCResponseDescriptor.java | 50 ++++++++++ .../onap/policy/vfc/VFCResponseHistoryList.java | 36 +++++++ .../org/onap/policy/vfc/util/Serialization.java | 30 ++++++ .../test/java/org/onap/policy/vfc/TestDemo.java | 84 ++++++++++++++++ 18 files changed, 701 insertions(+), 1 deletion(-) create mode 100644 controlloop/common/actors/actor.vfc/pom.xml create mode 100644 controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java create mode 100644 controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor create mode 100644 controlloop/common/model-impl/vfc/pom.xml create mode 100644 controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealActionVmInfo.java create mode 100644 controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealAdditionalParams.java create mode 100644 controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealRequest.java create mode 100644 controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java create mode 100644 controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCRequest.java create mode 100644 controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponse.java create mode 100644 controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseDescriptor.java create mode 100644 controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseHistoryList.java create mode 100644 controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java create mode 100644 controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestDemo.java (limited to 'controlloop/common') diff --git a/controlloop/common/actors/actor.vfc/pom.xml b/controlloop/common/actors/actor.vfc/pom.xml new file mode 100644 index 000000000..de6f05841 --- /dev/null +++ b/controlloop/common/actors/actor.vfc/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + org.onap.policy.drools-applications + actors + 1.1.0-SNAPSHOT + + actor.vfc + + + org.onap.policy.drools-applications + actorServiceProvider + 1.1.0-SNAPSHOT + provided + + + org.onap.policy.drools-applications + vfc + 1.1.0-SNAPSHOT + provided + + + org.onap.policy.drools-applications + events + 1.1.0-SNAPSHOT + provided + + + 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 index 000000000..ffada0a81 --- /dev/null +++ b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java @@ -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 recipes = ImmutableList.of("Restart"); + private static final ImmutableMap> targets = new ImmutableMap.Builder>() + .put("Restart", ImmutableList.of("VM")) + .build(); + + @Override + public String actor() { + return "VFC"; + } + + @Override + public List recipes() { + return ImmutableList.copyOf(recipes); + } + + @Override + public List recipeTargets(String recipe) { + return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList())); + } + + @Override + public List 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 index 000000000..3ccac9949 --- /dev/null +++ b/controlloop/common/actors/actor.vfc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorServiceProvider.spi.Actor @@ -0,0 +1 @@ +org.onap.policy.controlloop.actor.vfc.APPCActorServiceProvider diff --git a/controlloop/common/actors/pom.xml b/controlloop/common/actors/pom.xml index a00a3af52..e99fbb09f 100644 --- a/controlloop/common/actors/pom.xml +++ b/controlloop/common/actors/pom.xml @@ -14,6 +14,7 @@ actorServiceProvider actor.appc + actor.vfc actor.mso actor.test diff --git a/controlloop/common/eventmanager/pom.xml b/controlloop/common/eventmanager/pom.xml index efe7b3487..b33763b12 100644 --- a/controlloop/common/eventmanager/pom.xml +++ b/controlloop/common/eventmanager/pom.xml @@ -40,6 +40,12 @@ 1.1.0-SNAPSHOT provided + + org.onap.policy.drools-applications + actor.vfc + 1.1.0-SNAPSHOT + provided + org.onap.policy.drools-applications guard @@ -58,6 +64,12 @@ 1.1.0-SNAPSHOT provided + + org.onap.policy.drools-applications + vfc + 1.1.0-SNAPSHOT + provided + junit junit diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java index f552cc549..0df58be06 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java @@ -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; } diff --git a/controlloop/common/model-impl/pom.xml b/controlloop/common/model-impl/pom.xml index 94c3f345a..5d18e4916 100644 --- a/controlloop/common/model-impl/pom.xml +++ b/controlloop/common/model-impl/pom.xml @@ -40,6 +40,7 @@ rest sdc trafficgenerator + vfc diff --git a/controlloop/common/model-impl/vfc/pom.xml b/controlloop/common/model-impl/vfc/pom.xml new file mode 100644 index 000000000..db86345e8 --- /dev/null +++ b/controlloop/common/model-impl/vfc/pom.xml @@ -0,0 +1,49 @@ + + + + 4.0.0 + + vfc + + + org.onap.policy.drools-applications + model-impl + 1.1.0-SNAPSHOT + + + + + junit + junit + 4.12 + provided + + + com.google.code.gson + gson + 2.5 + provided + + + org.onap.policy.drools-applications + rest + ${project.version} + + + 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 index 000000000..b2535e3af --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealActionVmInfo.java @@ -0,0 +1,40 @@ +/*- + * ============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 VFCHealActionVmInfo implements Serializable { + + private static final long serialVersionUID = 3208673205100673119L; + + @SerializedName("vmid") + public String vmid; + + @SerializedName("vmname") + public String vmname; + + + public VFCHealActionVmInfo() { + } + +} 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 index 000000000..a65ad8aac --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealAdditionalParams.java @@ -0,0 +1,39 @@ +/*- + * ============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 VFCHealAdditionalParams implements Serializable { + + private static final long serialVersionUID = 2656694137285096191L; + + @SerializedName("action") + public String action; + + @SerializedName("actionvminfo") + public VFCHealActionVmInfo actionInfo; + + public VFCHealAdditionalParams() { + } + +} 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 index 000000000..f7fc891c0 --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCHealRequest.java @@ -0,0 +1,42 @@ +/*- + * ============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 VFCHealRequest implements Serializable { + + private static final long serialVersionUID = -7341931593089709247L; + + @SerializedName("vnfInstanceId") + public String vnfInstanceId; + + @SerializedName("cause") + public String cause; + + @SerializedName("additionalParams") + public VFCHealAdditionalParams additionalParams; + + public VFCHealRequest() { + } + +} 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 index 000000000..44f9905b2 --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java @@ -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 headers = new HashMap(); + headers.put("Accept", "application/json"); + + String vfcUrl = vfcUrlBase + "/ns/" + vfcRequest.nsInstanceId + "/heal"; + Pair 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 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 index 000000000..a45a62dfa --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCRequest.java @@ -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 index 000000000..775d78f1d --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponse.java @@ -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 index 000000000..f156fa0d0 --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseDescriptor.java @@ -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 index 000000000..3fe62ea25 --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCResponseHistoryList.java @@ -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 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 index 000000000..655085288 --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java @@ -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 index 000000000..7e8c212e1 --- /dev/null +++ b/controlloop/common/model-impl/vfc/src/test/java/org/onap/policy/vfc/TestDemo.java @@ -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); + + } +} -- cgit 1.2.3-korg