aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-09-06 00:27:03 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-06 00:27:03 +0000
commit1edf5cb1278f8c920599196e5722c1237face1da (patch)
tree4c191155b8a5c5c246fb5322ff080c6e3d6c5250 /controlloop
parent6e3c351251ae1e578b3f28019de41fe03a69f1e0 (diff)
parent0b6288e180c1d33bba88b3df5e03442c57058db9 (diff)
Merge "Added support for VF Module Delete recipe"
Diffstat (limited to 'controlloop')
-rw-r--r--controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java240
-rw-r--r--controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java9
-rw-r--r--controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java14
-rw-r--r--controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java52
-rw-r--r--controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java196
-rw-r--r--controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java36
-rwxr-xr-xcontrolloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestGet.java18
-rwxr-xr-xcontrolloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPair.java8
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java89
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java9
-rw-r--r--controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java40
-rw-r--r--controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoDummyServer.java191
-rw-r--r--controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoManager.java156
-rwxr-xr-xcontrolloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequest.java3
-rw-r--r--controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java12
-rw-r--r--controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java12
-rw-r--r--controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java2
-rw-r--r--controlloop/common/simulators/src/test/java/org/onap/policy/simulators/VfcSimulatorTest.java6
18 files changed, 728 insertions, 365 deletions
diff --git a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
index 602bc284b..ce49dda46 100644
--- a/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
+++ b/controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
@@ -36,15 +36,7 @@ import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.so.SOCloudConfiguration;
-import org.onap.policy.so.SOManager;
-import org.onap.policy.so.SOModelInfo;
-import org.onap.policy.so.SORelatedInstance;
-import org.onap.policy.so.SORelatedInstanceListElement;
-import org.onap.policy.so.SORequest;
-import org.onap.policy.so.SORequestDetails;
-import org.onap.policy.so.SORequestInfo;
-import org.onap.policy.so.SORequestParameters;
+import org.onap.policy.so.*;
import org.onap.policy.so.util.Serialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,10 +52,13 @@ public class SOActorServiceProvider implements Actor {
// Strings for recipes
private static final String RECIPE_VF_MODULE_CREATE = "VF Module Create";
+ private static final String RECIPE_VF_MODULE_DELETE = "VF Module Delete";
- private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_VF_MODULE_CREATE);
+ private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_VF_MODULE_CREATE,
+ RECIPE_VF_MODULE_DELETE);
private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
- .put(RECIPE_VF_MODULE_CREATE, ImmutableList.of(TARGET_VFC)).build();
+ .put(RECIPE_VF_MODULE_CREATE, ImmutableList.of(TARGET_VFC))
+ .put(RECIPE_VF_MODULE_DELETE, ImmutableList.of(TARGET_VFC)).build();
// name of request parameters within policy payload
public static final String REQ_PARAM_NM = "requestParameters";
@@ -71,14 +66,19 @@ public class SOActorServiceProvider implements Actor {
// name of configuration parameters within policy payload
public static final String CONFIG_PARAM_NM = "configurationParameters";
+ private static final String MODEL_NAME_PROPERTY_KEY = "model-ver.model-name";
+ private static final String MODEL_VERSION_PROPERTY_KEY = "model-ver.model-version";
+ private static final String MODEL_VERSION_ID_PROPERTY_KEY = "model-ver.model-version-id";
+
// used to decode configuration parameters via gson
- public static Type CONFIG_TYPE = new TypeToken<List<Map<String, String>>>() {}.getType();
+ private static final Type CONFIG_TYPE = new TypeToken<List<Map<String, String>>>() {}.getType();
- // Static variables required to hold the IDs of the last service item and VNF item.
+ // Static variables required to hold the IDs of the last service item, VNF item and VF Module.
// Note that in
// a multithreaded deployment this WILL break
private static String lastVNFItemVnfId;
private static String lastServiceItemServiceInstanceId;
+ private static String lastVfModuleItemVfModuleInstanceId;
@Override
public String actor() {
@@ -114,17 +114,11 @@ public class SOActorServiceProvider implements Actor {
*/
public SORequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy,
AaiNqResponseWrapper aaiResponseWrapper) {
- String modelNamePropertyKey = "model-ver.model-name";
- String modelVersionPropertyKey = "model-ver.model-version";
- String modelVersionIdPropertyKey = "model-ver.model-version-id";
-
-
- if (!SO_ACTOR.equals(policy.getActor()) || !RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) {
- // for future extension
+ if (!SO_ACTOR.equals(policy.getActor()) || !recipes().contains(policy.getRecipe())) {
return null;
}
- // Perform named query request and handle response
+ // A&AI named query should have been performed by now. If not, return null
if (aaiResponseWrapper == null) {
return null;
}
@@ -170,56 +164,51 @@ public class SOActorServiceProvider implements Actor {
return null;
}
+ // Construct SO Request for a policy's recipe
+ if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) {
+ return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem);
+ } else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) {
+ return constructDeleteRequest(aaiResponseWrapper, tenantItem, vnfItem, vnfServiceItem);
+ } else {
+ return null;
+ }
+ }
- // Construct SO Request
+ /**
+ * Construct SO request to create vf-module
+ *
+ * @param aaiResponseWrapper the AAI response containing the VF modules
+ * @param policy the policy
+ * @param tenantItem tenant item from A&AI named-query response
+ * @param vnfItem vnf item from A&AI named-query response
+ * @param vnfServiceItem vnf service item from A&AI named-query response
+ * @return SO create vf-module request
+ */
+ private SORequest constructCreateRequest(AaiNqResponseWrapper aaiResponseWrapper, Policy policy, AaiNqInventoryResponseItem
+ tenantItem, AaiNqInventoryResponseItem vnfItem, AaiNqInventoryResponseItem vnfServiceItem) {
+ AaiNqInventoryResponseItem vfModuleItem = findVfModule(aaiResponseWrapper, false);
SORequest request = new SORequest();
+ request.setOperationType(SoOperationType.SCALE_OUT);
+ //
//
// Do NOT send So the requestId, they do not support this field
//
request.setRequestDetails(new SORequestDetails());
- request.getRequestDetails().setModelInfo(new SOModelInfo());
- request.getRequestDetails().setCloudConfiguration(new SOCloudConfiguration());
- request.getRequestDetails().setRequestInfo(new SORequestInfo());
request.getRequestDetails().setRequestParameters(new SORequestParameters());
request.getRequestDetails().getRequestParameters().setUserParams(null);
- //
// cloudConfiguration
- //
- request.getRequestDetails().getCloudConfiguration().setTenantId(tenantItem.getTenant().getTenantId());
- request.getRequestDetails().getCloudConfiguration().setLcpCloudRegionId(
- tenantItem.getItems().getInventoryResponseItems().get(0).getCloudRegion().getCloudRegionId());
-
- //
+ request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem));
// modelInfo
- //
- request.getRequestDetails().getModelInfo().setModelType("vfModule");
- request.getRequestDetails().getModelInfo()
- .setModelInvariantId(vfModuleItem.getVfModule().getModelInvariantId());
+ request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem));
request.getRequestDetails().getModelInfo().setModelVersionId(vfModuleItem.getVfModule().getModelVersionId());
- request.getRequestDetails().getModelInfo()
- .setModelCustomizationId(vfModuleItem.getVfModule().getModelCustomizationId());
- for (AaiNqExtraProperty prop : vfModuleItem.getExtraProperties().getExtraProperty()) {
- if (prop.getPropertyName().equals(modelNamePropertyKey)) {
- request.getRequestDetails().getModelInfo().setModelName(prop.getPropertyValue());
- } else if (prop.getPropertyName().equals(modelVersionPropertyKey)) {
- request.getRequestDetails().getModelInfo().setModelVersion(prop.getPropertyValue());
- }
- }
-
- //
// requestInfo
- //
+ request.getRequestDetails().setRequestInfo(constructRequestInfo());
String vfModuleName = aaiResponseWrapper.genVfModuleName();
request.getRequestDetails().getRequestInfo().setInstanceName(vfModuleName);
- request.getRequestDetails().getRequestInfo().setSource("POLICY");
- request.getRequestDetails().getRequestInfo().setSuppressRollback(false);
- request.getRequestDetails().getRequestInfo().setRequestorId("policy");
- //
// relatedInstanceList
- //
SORelatedInstanceListElement relatedInstanceListElement0 = new SORelatedInstanceListElement();
SORelatedInstanceListElement relatedInstanceListElement1 = new SORelatedInstanceListElement();
SORelatedInstanceListElement relatedInstanceListElement2 = new SORelatedInstanceListElement();
@@ -235,20 +224,20 @@ public class SOActorServiceProvider implements Actor {
// Service Item
relatedInstanceListElement1.getRelatedInstance()
- .setInstanceId(vnfServiceItem.getServiceInstance().getServiceInstanceId());
+ .setInstanceId(vnfServiceItem.getServiceInstance().getServiceInstanceId());
relatedInstanceListElement1.getRelatedInstance().setModelInfo(new SOModelInfo());
relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelType("service");
relatedInstanceListElement1.getRelatedInstance().getModelInfo()
- .setModelInvariantId(vnfServiceItem.getServiceInstance().getModelInvariantId());
+ .setModelInvariantId(vnfServiceItem.getServiceInstance().getModelInvariantId());
for (AaiNqExtraProperty prop : vnfServiceItem.getExtraProperties().getExtraProperty()) {
- if (prop.getPropertyName().equals(modelNamePropertyKey)) {
+ if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) {
relatedInstanceListElement1.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue());
- } else if (prop.getPropertyName().equals(modelVersionPropertyKey)) {
+ } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) {
relatedInstanceListElement1.getRelatedInstance().getModelInfo()
- .setModelVersion(prop.getPropertyValue());
- } else if (prop.getPropertyName().equals(modelVersionIdPropertyKey)) {
+ .setModelVersion(prop.getPropertyValue());
+ } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) {
relatedInstanceListElement1.getRelatedInstance().getModelInfo()
- .setModelVersionId(prop.getPropertyValue());
+ .setModelVersionId(prop.getPropertyValue());
}
}
@@ -257,23 +246,23 @@ public class SOActorServiceProvider implements Actor {
relatedInstanceListElement2.getRelatedInstance().setModelInfo(new SOModelInfo());
relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelType("vnf");
relatedInstanceListElement2.getRelatedInstance().getModelInfo()
- .setModelInvariantId(vnfItem.getGenericVnf().getModelInvariantId());
+ .setModelInvariantId(vnfItem.getGenericVnf().getModelInvariantId());
for (AaiNqExtraProperty prop : vnfItem.getExtraProperties().getExtraProperty()) {
- if (prop.getPropertyName().equals(modelNamePropertyKey)) {
+ if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) {
relatedInstanceListElement2.getRelatedInstance().getModelInfo().setModelName(prop.getPropertyValue());
- } else if (prop.getPropertyName().equals(modelVersionPropertyKey)) {
+ } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) {
relatedInstanceListElement2.getRelatedInstance().getModelInfo()
- .setModelVersion(prop.getPropertyValue());
- } else if (prop.getPropertyName().equals(modelVersionIdPropertyKey)) {
+ .setModelVersion(prop.getPropertyValue());
+ } else if (prop.getPropertyName().equals(MODEL_VERSION_ID_PROPERTY_KEY)) {
relatedInstanceListElement2.getRelatedInstance().getModelInfo()
- .setModelVersionId(prop.getPropertyValue());
+ .setModelVersionId(prop.getPropertyValue());
}
}
relatedInstanceListElement2.getRelatedInstance().getModelInfo()
- .setModelCustomizationName(vnfItem.getGenericVnf().getVnfType()
- .substring(vnfItem.getGenericVnf().getVnfType().lastIndexOf('/') + 1));
+ .setModelCustomizationName(vnfItem.getGenericVnf().getVnfType()
+ .substring(vnfItem.getGenericVnf().getVnfType().lastIndexOf('/') + 1));
relatedInstanceListElement2.getRelatedInstance().getModelInfo()
- .setModelCustomizationId(vnfItem.getGenericVnf().getModelCustomizationId());
+ .setModelCustomizationId(vnfItem.getGenericVnf().getModelCustomizationId());
// Insert the Service Item and VNF Item
request.getRequestDetails().getRelatedInstanceList().add(relatedInstanceListElement0);
@@ -285,19 +274,102 @@ public class SOActorServiceProvider implements Actor {
// Configuration Parameters
request.getRequestDetails().setConfigurationParameters(buildConfigurationParameters(policy));
-
// Save the instance IDs for the VNF and service to static fields
- preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(),
- vnfServiceItem.getServiceInstance().getServiceInstanceId());
-
+ // vfModuleId is not required for the create vf-module
+ preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance()
+ .getServiceInstanceId(), null);
if (logger.isDebugEnabled()) {
- logger.debug("SO request sent: {}", Serialization.gsonPretty.toJson(request));
+ logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
}
+ return request;
+ }
+
+ /**
+ * Construct SO request to delete vf-module
+ *
+ * @param aaiResponseWrapper the AAI response containing the VF modules
+ * @param tenantItem tenant item from A&AI named-query response
+ * @param vnfItem vnf item from A&AI named-query response
+ * @param vnfServiceItem vnf service item from A&AI named-query response
+ * @return SO delete vf-module request
+ */
+ private SORequest constructDeleteRequest(AaiNqResponseWrapper aaiResponseWrapper, AaiNqInventoryResponseItem
+ tenantItem, AaiNqInventoryResponseItem vnfItem, AaiNqInventoryResponseItem vnfServiceItem) {
+ // find the last non-base vf-module to delete
+ AaiNqInventoryResponseItem vfModuleItem = findVfModuleToDelete(aaiResponseWrapper);
+ SORequest request = new SORequest();
+ request.setOperationType(SoOperationType.DELETE_VF_MODULE);
+ request.setRequestDetails(new SORequestDetails());
+ request.getRequestDetails().setRelatedInstanceList(null);
+ request.getRequestDetails().setConfigurationParameters(null);
+
+ // cloudConfiguration
+ request.getRequestDetails().setCloudConfiguration(constructCloudConfiguration(tenantItem));
+ // modelInfo
+ request.getRequestDetails().setModelInfo(constructVfModuleModelInfo(vfModuleItem));
+ // requestInfo
+ request.getRequestDetails().setRequestInfo(constructRequestInfo());
+ // Save the instance IDs for the VNF, service and vfModule to static fields
+ preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(), vnfServiceItem.getServiceInstance()
+ .getServiceInstanceId(), vfModuleItem.getVfModule().getVfModuleId());
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
+ }
return request;
}
/**
+ * construct requestInfo for the SO requestDetails
+ *
+ * @return SO request information
+ */
+ private SORequestInfo constructRequestInfo() {
+ SORequestInfo soRequestInfo = new SORequestInfo();
+ soRequestInfo.setSource("POLICY");
+ soRequestInfo.setSuppressRollback(false);
+ soRequestInfo.setRequestorId("policy");
+ return soRequestInfo;
+ }
+
+ /**
+ * construct modelInfo of the vfModule for the SO requestDetails
+ *
+ * @param vfModuleItem vf module item from A&AI named-query response
+ * @return SO Model info for the vfModule
+ */
+ private SOModelInfo constructVfModuleModelInfo(AaiNqInventoryResponseItem vfModuleItem) {
+ SOModelInfo soModelInfo = new SOModelInfo();
+ soModelInfo.setModelType("vfModule");
+ soModelInfo.setModelInvariantId(vfModuleItem.getVfModule().getModelInvariantId());
+ soModelInfo.setModelCustomizationId(vfModuleItem.getVfModule().getModelCustomizationId());
+
+ for (AaiNqExtraProperty prop : vfModuleItem.getExtraProperties().getExtraProperty()) {
+ if (prop.getPropertyName().equals(MODEL_NAME_PROPERTY_KEY)) {
+ soModelInfo.setModelName(prop.getPropertyValue());
+ } else if (prop.getPropertyName().equals(MODEL_VERSION_PROPERTY_KEY)) {
+ soModelInfo.setModelVersion(prop.getPropertyValue());
+ }
+ }
+ return soModelInfo;
+ }
+
+ /**
+ * construct cloudConfiguration for the SO requestDetails
+ *
+ * @param tenantItem tenant item from A&AI named-query response
+ * @return SO cloud configuration
+ */
+ private SOCloudConfiguration constructCloudConfiguration(AaiNqInventoryResponseItem tenantItem) {
+ SOCloudConfiguration cloudConfiguration = new SOCloudConfiguration();
+ cloudConfiguration.setTenantId(tenantItem.getTenant().getTenantId());
+ cloudConfiguration.setLcpCloudRegionId(tenantItem.getItems().getInventoryResponseItems().get(0)
+ .getCloudRegion().getCloudRegionId());
+ return cloudConfiguration;
+ }
+
+ /**
* This method is needed to get the serviceInstanceId and vnfInstanceId which is used
* in the asyncSORestCall.
*
@@ -308,7 +380,7 @@ public class SOActorServiceProvider implements Actor {
public static void sendRequest(String requestId, WorkingMemory wm, Object request) {
SOManager soManager = new SOManager();
soManager.asyncSORestCall(requestId, wm, lastServiceItemServiceInstanceId, lastVNFItemVnfId,
- (SORequest) request);
+ lastVfModuleItemVfModuleInstanceId, (SORequest) request);
}
/**
@@ -325,6 +397,18 @@ public class SOActorServiceProvider implements Actor {
}
/**
+ * Find the VF module item to delete from AAI response.
+ *
+ * @param aaiResponseWrapper the AAI response containing the VF modules
+ * @return VF module item to delete or null if the non-base vfModule was not found
+ */
+ private AaiNqInventoryResponseItem findVfModuleToDelete(AaiNqResponseWrapper aaiResponseWrapper) {
+ List<AaiNqInventoryResponseItem> lst = aaiResponseWrapper.getVfModuleItems(false);
+ return (lst == null || lst.isEmpty() ? null : lst.get(lst.size() - 1));
+ }
+
+
+ /**
* Builds the request parameters from the policy payload.
*
* @param policy the policy
@@ -364,14 +448,16 @@ public class SOActorServiceProvider implements Actor {
}
/**
- * This method is called to remember the last service instance ID and VNF Item VNF ID.
+ * This method is called to remember the last service instance ID, VNF Item VNF ID and vf module ID.
* Note these fields are static, beware for multithreaded deployments
*
* @param vnfInstanceId update the last VNF instance ID to this value
* @param serviceInstanceId update the last service instance ID to this value
+ * @param vfModuleId update the vfModule instance ID to this value
*/
- private static void preserveInstanceIds(final String vnfInstanceId, final String serviceInstanceId) {
+ private static void preserveInstanceIds(final String vnfInstanceId, final String serviceInstanceId, final String vfModuleId) {
lastVNFItemVnfId = vnfInstanceId;
lastServiceItemServiceInstanceId = serviceInstanceId;
+ lastVfModuleItemVfModuleInstanceId = vfModuleId;
}
}
diff --git a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
index fcc55ead3..6de451d0c 100644
--- a/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
+++ b/controlloop/common/actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
@@ -42,6 +42,7 @@ import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.so.SORequest;
import org.onap.policy.so.SORequestParameters;
+import org.onap.policy.so.SoOperationType;
import org.onap.policy.so.util.Serialization;
public class SoActorServiceProviderTest {
@@ -92,6 +93,11 @@ public class SoActorServiceProviderTest {
// response has no non-base VF modules (other than the "dummy")
assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy,
loadAaiResponse(onset, "aai/AaiNqResponse-NoNonBase.json")));
+
+ policy.setRecipe("VF Module Delete");
+ SORequest deleteRequest = new SOActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp);
+ assertNotNull(deleteRequest);
+ assertEquals(SoOperationType.DELETE_VF_MODULE, deleteRequest.getOperationType());
}
@Test
@@ -108,8 +114,9 @@ public class SoActorServiceProviderTest {
SOActorServiceProvider sp = new SOActorServiceProvider();
assertEquals("SO", sp.actor());
- assertEquals(1, sp.recipes().size());
+ assertEquals(2, sp.recipes().size());
assertEquals("VF Module Create", sp.recipes().get(0));
+ assertEquals("VF Module Delete", sp.recipes().get(1));
assertEquals(0, sp.recipePayloads("VF Module Create").size());
}
diff --git a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java
index 56f79d378..b54981d22 100644
--- a/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java
+++ b/controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java
@@ -88,13 +88,13 @@ public final class AaiManager {
return null;
}
- int httpResponseCode = httpDetails.a;
+ int httpResponseCode = httpDetails.first;
logger.info(url);
logger.info("{}", httpResponseCode);
- logger.info(httpDetails.b);
+ logger.info(httpDetails.second);
- if (httpDetails.b != null) {
+ if (httpDetails.second != null) {
return composeResponse(httpDetails, url, AaiNqResponse.class);
}
return null;
@@ -174,11 +174,11 @@ public final class AaiManager {
return null;
}
- int httpResponseCode = httpDetailsGet.a;
+ int httpResponseCode = httpDetailsGet.first;
logger.info(urlGet);
logger.info("{}", httpResponseCode);
- logger.info(httpDetailsGet.b);
+ logger.info(httpDetailsGet.second);
if (httpResponseCode == 200) {
T responseGet = composeResponse(httpDetailsGet, urlGet, classOfResponse);
@@ -226,8 +226,8 @@ public final class AaiManager {
private <T> T composeResponse(final Pair<Integer, String> httpDetails, final String url,
final Class<T> classOfResponse) {
try {
- T response = Serialization.gsonPretty.fromJson(httpDetails.b, classOfResponse);
- netLogger.info("[IN|{}|{}|]{}{}", "AAI", url, LINE_SEPARATOR, httpDetails.b);
+ T response = Serialization.gsonPretty.fromJson(httpDetails.second, classOfResponse);
+ netLogger.info("[IN|{}|{}|]{}{}", "AAI", url, LINE_SEPARATOR, httpDetails.second);
return response;
} catch (JsonSyntaxException e) {
logger.error("postQuery threw: ", e);
diff --git a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java
new file mode 100644
index 000000000..262872262
--- /dev/null
+++ b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================
+ * rest
+ * ================================================================================
+ * Copyright (C) 2018 Amdocs. 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.rest;
+
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+
+import java.net.URI;
+
+
+/**
+ * Allows for HTTP DELETE requests to contain a body, which the HttpDelete
+ * class does not support.
+ */
+public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
+ public static final String METHOD_NAME = "DELETE";
+
+ public String getMethod() {
+ return METHOD_NAME;
+ }
+
+ public HttpDeleteWithBody(final String uri) {
+ super();
+ setURI(URI.create(uri));
+ }
+
+ public HttpDeleteWithBody(final URI uri) {
+ super();
+ setURI(uri);
+ }
+
+ public HttpDeleteWithBody() {
+ super();
+ }
+}
diff --git a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
index 39e0d8a7f..a7e373b5f 100644
--- a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
+++ b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,15 +20,16 @@
package org.onap.policy.rest;
-import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.bind.DatatypeConverter;
+
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -42,126 +43,141 @@ public class RESTManager {
private static final Logger logger = LoggerFactory.getLogger(RESTManager.class);
public class Pair<A, B> {
- public final A a;
- public final B b;
+ public final A first;
+ public final B second;
- public Pair(A a, B b) {
- this.a = a;
- this.b = b;
+ public Pair(A first, B second) {
+ this.first = first;
+ this.second = second;
}
}
/**
* Perform REST Post.
- *
- * @param url the url
- * @param username the user name
- * @param password the password
- * @param headers any headers
+ *
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
* @param contentType what the content type is
- * @param body body to send
+ * @param body body to send
* @return the response status code and the body
*/
public Pair<Integer, String> post(String url, String username, String password,
- Map<String, String> headers, String contentType, String body) {
-
- String authHeader = makeAuthHeader(username, password);
-
- logger.debug("HTTP REQUEST: {} -> {} {} -> {}", url, username,
- ((password != null) ? password.length() : "-"), contentType);
- if (headers != null) {
- logger.debug("Headers: ");
- headers.forEach((name, value) -> logger.debug("{} -> {}", name, value));
+ Map<String, String> headers, String contentType, String body) {
+ HttpPost post = new HttpPost(url);
+ addHeaders(post, username, password, headers);
+ post.addHeader("Content-Type", contentType);
+ try {
+ StringEntity input = new StringEntity(body);
+ input.setContentType(contentType);
+ post.setEntity(input);
+ } catch (Exception e) {
+ logger.error("post threw: ", e);
+ return null;
}
- logger.debug(body);
+ return sendRequest(post);
+ }
- try (CloseableHttpClient client =
- HttpClientBuilder
- .create()
- .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
- .build()) {
-
- HttpPost post = new HttpPost(url);
- if (headers != null) {
- for (Entry<String, String> entry : headers.entrySet()) {
- post.addHeader(entry.getKey(), headers.get(entry.getKey()));
- }
- }
- post.addHeader("Content-Type", contentType);
- if (authHeader != null) {
- post.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
+ /**
+ * Do a REST get.
+ *
+ * @param url URL
+ * @param username user name
+ * @param password password
+ * @param headers any headers to add
+ * @return a Pair for the response status and the body
+ */
+ public Pair<Integer, String> get(String url, String username, String password,
+ Map<String, String> headers) {
+ HttpGet get = new HttpGet(url);
+ addHeaders(get, username, password, headers);
+ return sendRequest(get);
+ }
+
+ /**
+ * Perform REST Delete.
+ *
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
+ * @param contentType what the content type is
+ * @param body body (optional) to send
+ * @return the response status code and the body
+ */
+ public Pair<Integer, String> delete(String url, String username, String password, Map<String, String> headers,
+ String contentType, String body) {
+ HttpDeleteWithBody delete = new HttpDeleteWithBody(url);
+ addHeaders(delete, username, password, headers);
+ delete.addHeader("Content-Type", contentType);
+ if (body != null && !body.isEmpty()) {
+ try {
+ StringEntity input = new StringEntity(body);
+ input.setContentType(contentType);
+ delete.setEntity(input);
+ } catch (Exception e) {
+ logger.error("delete threw: ", e);
+ return null;
}
+ }
+ return sendRequest(delete);
+ }
- StringEntity input = new StringEntity(body);
- input.setContentType(contentType);
- post.setEntity(input);
+ /**
+ * Send REST request.
+ *
+ * @param request http request to send
+ * @return the response status code and the body
+ */
+ private Pair<Integer, String> sendRequest(HttpRequestBase request) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("***** sendRequest to url {}:", request.getURI());
+ }
- HttpResponse response = client.execute(post);
+ try (CloseableHttpClient client =
+ HttpClientBuilder
+ .create()
+ .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
+ .build()) {
+ HttpResponse response = client.execute(request);
if (response != null) {
String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
- logger.debug("HTTP POST Response Status Code: {}",
+ logger.debug("HTTP Response Status Code: {}",
response.getStatusLine().getStatusCode());
- logger.debug("HTTP POST Response Body:");
+ logger.debug("HTTP Response Body:");
logger.debug(returnBody);
return new Pair<>(response.getStatusLine().getStatusCode(),
returnBody);
- }
- else {
- logger.error("Response from {} is null", url);
+ } else {
+ logger.error("Response from {} is null", request.getURI());
return null;
}
- }
- catch (Exception e) {
- logger.error("Failed to POST to {}", url, e);
+ } catch (Exception e) {
+ logger.error("Request failed to {}", request.getURI(), e);
return null;
}
}
/**
- * Do a REST get.
- *
- * @param url URL
- * @param username user name
- * @param password password
- * @param headers any headers to add
- * @return a Pair for the response status and the body
+ * Add header to the request.
+ *
+ * @param request http request to send
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
*/
- public Pair<Integer, String> get(String url, String username, String password,
- Map<String, String> headers) {
-
+ private void addHeaders(HttpRequestBase request, String username, String password, Map<String,
+ String> headers) {
String authHeader = makeAuthHeader(username, password);
-
- try (CloseableHttpClient client =
- HttpClientBuilder
- .create()
- .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
- .build()) {
-
- HttpGet get = new HttpGet(url);
- if (headers != null) {
- for (Entry<String, String> entry : headers.entrySet()) {
- get.addHeader(entry.getKey(), headers.get(entry.getKey()));
- }
- }
- if (authHeader != null) {
- get.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
+ if (headers != null) {
+ for (Entry<String, String> entry : headers.entrySet()) {
+ request.addHeader(entry.getKey(), headers.get(entry.getKey()));
}
-
- HttpResponse response = client.execute(get);
-
- String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
-
- logger.debug("HTTP GET Response Status Code: {}",
- response.getStatusLine().getStatusCode());
- logger.debug("HTTP GET Response Body:");
- logger.debug(returnBody);
-
- return new Pair<>(response.getStatusLine().getStatusCode(), returnBody);
}
- catch (IOException e) {
- logger.error("Failed to GET to {}", url, e);
- return null;
+ if (authHeader != null) {
+ request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
}
}
diff --git a/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java
new file mode 100644
index 000000000..0cb5f3aef
--- /dev/null
+++ b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================
+ * rest
+ * ================================================================================
+ * Copyright (C) 2018 Amdocs. 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.rest;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class HttpDeleteWithBodyTest {
+
+ @Test
+ public void getMethod() {
+ String url = "http://www.example.org";
+ HttpDeleteWithBody deleteWithBody = new HttpDeleteWithBody(url);
+ assertEquals("DELETE", deleteWithBody.getMethod());
+ assertEquals(url, deleteWithBody.getURI().toString());
+ }
+} \ No newline at end of file
diff --git a/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestGet.java b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestGet.java
index a8301810c..7e881df51 100755
--- a/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestGet.java
+++ b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestGet.java
@@ -39,9 +39,9 @@ public class TestGet {
RESTManager mgr = new RESTManager();
Pair<Integer, String> result = mgr.get("http://www.example.org", null, null, null);
- assertEquals((Integer)200, result.a);
- assertTrue(result.b != null);
- assertTrue(result.b.length() > 0);
+ assertEquals((Integer)200, result.first);
+ assertTrue(result.second != null);
+ assertTrue(result.second.length() > 0);
}
@Test
@@ -49,9 +49,9 @@ public class TestGet {
RESTManager mgr = new RESTManager();
Pair<Integer, String> result = mgr.get("http://www.example.org", "", null, null);
- assertEquals((Integer)200, result.a);
- assertTrue(result.b != null);
- assertTrue(result.b.length() > 0);
+ assertEquals((Integer)200, result.first);
+ assertTrue(result.second != null);
+ assertTrue(result.second.length() > 0);
}
@Test
@@ -59,8 +59,8 @@ public class TestGet {
RESTManager mgr = new RESTManager();
Pair<Integer, String> result = mgr.get("http://www.example.org", "user", null, null);
- assertEquals((Integer)200, result.a);
- assertTrue(result.b != null);
- assertTrue(result.b.length() > 0);
+ assertEquals((Integer)200, result.first);
+ assertTrue(result.second != null);
+ assertTrue(result.second.length() > 0);
}
} \ No newline at end of file
diff --git a/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPair.java b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPair.java
index aea5a7387..28e9934d1 100755
--- a/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPair.java
+++ b/controlloop/common/model-impl/rest/src/test/java/org/onap/policy/rest/TestPair.java
@@ -32,11 +32,11 @@ public class TestPair {
RESTManager mgr = new RESTManager();
Pair<Integer, Integer> pii = mgr.new Pair<>(1, 2);
- assertEquals((Integer) 1, (Integer) pii.a);
- assertEquals((Integer) 2, (Integer) pii.b);
+ assertEquals((Integer) 1, (Integer) pii.first);
+ assertEquals((Integer) 2, (Integer) pii.second);
Pair<Integer, String> pis = mgr.new Pair<>(1, "test");
- assertEquals((Integer) 1, (Integer) pis.a);
- assertEquals("test", pis.b);
+ assertEquals((Integer) 1, (Integer) pis.first);
+ assertEquals("test", pis.second);
}
}
diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java
index a3f2be30b..5acd973ef 100644
--- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java
+++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java
@@ -98,19 +98,35 @@ public final class SOManager {
}
/**
+ * Works just like {@link SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest)
+ * except the vfModuleInstanceId is always null
+ *
+ * @see SOManager#asyncSORestCall(String, WorkingMemory, String, String, String, SORequest)
+ */
+ public Future<SOResponse> asyncSORestCall(final String requestID, final WorkingMemory wm,
+ final String serviceInstanceId, final String vnfInstanceId,
+ final SORequest request) {
+ return asyncSORestCall(requestID, wm, serviceInstanceId, vnfInstanceId, null, request);
+ }
+
+ /**
* This method makes an asynchronous Rest call to MSO and inserts the response into
* Drools working memory.
- *
- * @param requestID request id
- * @param wm the Drools working memory
- * @param serviceInstanceId service instance id
- * @param vnfInstanceId vnf instance id
- * @param request the SO request
+ *
+ * @param requestID
+ * @param wm the Drools working memory
+ * @param serviceInstanceId service instance id to construct the request url
+ * @param vnfInstanceId vnf instance id to construct the request url
+ * @param vfModuleInstanceId vfModule instance id to construct the request url (required in case of delete vf
+ * module)
+ * @param request the SO request
* @return a concurrent Future for the thread that handles the request
*/
public Future<SOResponse> asyncSORestCall(final String requestID, final WorkingMemory wm,
- final String serviceInstanceId, final String vnfInstanceId, final SORequest request) {
- return executors.submit(new AsyncSORestCallThread(requestID, wm, serviceInstanceId, vnfInstanceId, request));
+ final String serviceInstanceId, final String vnfInstanceId, final String vfModuleInstanceId, final
+ SORequest request) {
+ return executors.submit(new AsyncSORestCallThread(requestID, wm, serviceInstanceId, vnfInstanceId,
+ vfModuleInstanceId, request));
}
/**
@@ -121,23 +137,26 @@ public final class SOManager {
final WorkingMemory wm;
final String serviceInstanceId;
final String vnfInstanceId;
+ final String vfModuleInstanceId;
final SORequest request;
/**
* Constructor, sets the context of the request.
*
- * @param requestID The request ID
- * @param wm reference to the Drools working memory
- * @param serviceInstanceId the service instance in SO to use
- * @param vnfInstanceId the VNF instance that is the subject of the request
- * @param request the request itself
+ * @param requestID The request ID
+ * @param wm reference to the Drools working memory
+ * @param serviceInstanceId the service instance in SO to use
+ * @param vnfInstanceId the VNF instance that is the subject of the request
+ * @param vfModuleInstanceId the vf module instance id (not null in case of delete vf module request)
+ * @param request the request itself
*/
private AsyncSORestCallThread(final String requestID, final WorkingMemory wm, final String serviceInstanceId,
- final String vnfInstanceId, final SORequest request) {
+ final String vnfInstanceId, final String vfModuleInstanceId, final SORequest request) {
this.requestID = requestID;
this.wm = wm;
this.serviceInstanceId = serviceInstanceId;
this.vnfInstanceId = vnfInstanceId;
+ this.vfModuleInstanceId = vfModuleInstanceId;
this.request = request;
}
@@ -150,16 +169,26 @@ public final class SOManager {
String username = PolicyEngine.manager.getEnvironmentProperty("so.username");
String password = PolicyEngine.manager.getEnvironmentProperty("so.password");
- // The URL of the request we will POST
- String url = urlBase + "/serviceInstantiation/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId
- + "/vfModules/scaleOut";
-
// Create a JSON representation of the request
String soJson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create().toJson(request);
-
- netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson);
- Pair<Integer, String> httpResponse =
- restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson);
+ String url = null;
+ Pair<Integer, String> httpResponse = null;
+
+ if (request.getOperationType() != null && request.getOperationType()
+ .equals(SoOperationType.SCALE_OUT)) {
+ url = urlBase + "/serviceInstantiation/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId
+ + "/vfModules/scaleOut";
+ netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson);
+ httpResponse = restManager.post(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson);
+ } else if (request.getOperationType() != null && request.getOperationType()
+ .equals(SoOperationType.DELETE_VF_MODULE)) {
+ url = urlBase + "/serviceInstances/v7/" + serviceInstanceId + "/vnfs/" + vnfInstanceId
+ + "/vfModules/" + vfModuleInstanceId;
+ netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson);
+ httpResponse = restManager.delete(url, username, password, createSimpleHeaders(), MEDIA_TYPE, soJson);
+ } else {
+ return null;
+ }
// Process the response from SO
SOResponse response = waitForSOOperationCompletion(urlBase, username, password, url, httpResponse);
@@ -241,7 +270,7 @@ public final class SOManager {
* Parse the response message from SO into a SOResponse object.
*
* @param requestURL The URL of the HTTP request
- * @param httpDetails The HTTP message returned from SO
+ * @param httpResponse The HTTP message returned from SO
* @return The parsed response
*/
private SOResponse processSOResponse(final String requestURL, final Pair<Integer, String> httpResponse) {
@@ -250,7 +279,7 @@ public final class SOManager {
// A null httpDetails indicates a HTTP problem, a valid response from SO must be
// either 200
// or 202
- if (!httpResultIsNullFree(httpResponse) || (httpResponse.a != 200 && httpResponse.a != 202)) {
+ if (!httpResultIsNullFree(httpResponse) || (httpResponse.first != 200 && httpResponse.first != 202)) {
logger.error("Invalid HTTP response received from SO");
response.setHttpResponseCode(SO_RESPONSE_ERROR);
return response;
@@ -258,7 +287,7 @@ public final class SOManager {
// Parse the JSON of the response into our POJO
try {
- response = Serialization.gsonPretty.fromJson(httpResponse.b, SOResponse.class);
+ response = Serialization.gsonPretty.fromJson(httpResponse.second, SOResponse.class);
} catch (JsonSyntaxException e) {
logger.error("Failed to deserialize HTTP response into SOResponse: ", e);
response.setHttpResponseCode(SO_RESPONSE_ERROR);
@@ -267,14 +296,14 @@ public final class SOManager {
// Set the HTTP response code of the response if needed
if (response.getHttpResponseCode() == 0) {
- response.setHttpResponseCode(httpResponse.a);
+ response.setHttpResponseCode(httpResponse.first);
}
- netLogger.info("[IN|{}|{}|]{}{}", "SO", requestURL, LINE_SEPARATOR, httpResponse.b);
+ netLogger.info("[IN|{}|{}|]{}{}", "SO", requestURL, LINE_SEPARATOR, httpResponse.second);
if (logger.isDebugEnabled()) {
logger.debug("***** Response to SO Request to URL {}:", requestURL);
- logger.debug(httpResponse.b);
+ logger.debug(httpResponse.second);
}
return response;
@@ -308,7 +337,7 @@ public final class SOManager {
* @return true if the request for the response is finished
*/
private boolean isRequestStateFinished(final Pair<Integer, String> latestHTTPDetails, final SOResponse response) {
- if (latestHTTPDetails != null && 200 == latestHTTPDetails.a && isRequestStateDefined(response)) {
+ if (latestHTTPDetails != null && 200 == latestHTTPDetails.first && isRequestStateDefined(response)) {
String requestState = response.getRequest().getRequestStatus().getRequestState();
return "COMPLETE".equalsIgnoreCase(requestState) || "FAILED".equalsIgnoreCase(requestState);
} else {
@@ -323,7 +352,7 @@ public final class SOManager {
* @return true if no nulls are found
*/
private boolean httpResultIsNullFree(Pair<Integer, String> httpOperationResult) {
- return httpOperationResult != null && httpOperationResult.a != null && httpOperationResult.b != null;
+ return httpOperationResult != null && httpOperationResult.first != null && httpOperationResult.second != null;
}
/**
diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java
index 4a2f405e7..8bcbacf73 100644
--- a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java
+++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequest.java
@@ -51,6 +51,8 @@ public class SORequest implements Serializable {
@SerializedName("requestStatus")
private SORequestStatus requestStatus;
+ private transient SoOperationType operationType;
+
public SORequest() {
// required by author
}
@@ -111,4 +113,11 @@ public class SORequest implements Serializable {
this.startTime = startTime;
}
+ public SoOperationType getOperationType() {
+ return operationType;
+ }
+
+ public void setOperationType(SoOperationType operationType) {
+ this.operationType = operationType;
+ }
}
diff --git a/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java
new file mode 100644
index 000000000..7619e3a84
--- /dev/null
+++ b/controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SoOperationType.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * so
+ * ================================================================================
+ * Copyright (C) 2018 Amdocs. 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.so;
+
+/**
+ * Enumeration of SO Operations type that can be performed by a policy
+ */
+public enum SoOperationType {
+ SCALE_OUT("Create Vf Module"),
+ DELETE_VF_MODULE("Delete Vf Module");
+
+ private String operationType;
+
+ SoOperationType(String operationType) {
+ this.operationType = operationType;
+ }
+
+ @Override
+ public String toString() {
+ return this.operationType;
+ }
+}
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoDummyServer.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoDummyServer.java
index 5eb0a01ee..0d719e50d 100644
--- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoDummyServer.java
+++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoDummyServer.java
@@ -25,6 +25,7 @@ package org.onap.policy.so;
import com.google.gson.Gson;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -38,6 +39,7 @@ public class TestSoDummyServer {
private static int putMessagesReceived = 0;
private static int statMessagesReceived = 0;
private static int getMessagesReceived = 0;
+ private static int deleteMessagesReceived = 0;
private static Map<String, SOResponse> ongoingRequestMap = new ConcurrentHashMap<>();
@@ -51,7 +53,9 @@ public class TestSoDummyServer {
public Response serviceGetStats() {
statMessagesReceived++;
return Response.status(200).entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived
- + ",\"POST\": " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build();
+ + ",\"POST\": " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived
+ + ",\"DELETE\": " + deleteMessagesReceived + "}").build();
+
}
/**
@@ -77,98 +81,78 @@ public class TestSoDummyServer {
@Path("/serviceInstantiation/v7")
public Response servicePostRequest(final String jsonString) {
postMessagesReceived++;
+ return buildResponse(jsonString);
+ }
- if (jsonString == null) {
- return Response.status(400).build();
- }
-
- SORequest request = null;
- try {
- request = new Gson().fromJson(jsonString, SORequest.class);
- } catch (Exception e) {
- return Response.status(400).build();
- }
-
- if (request == null) {
- return Response.status(400).build();
- }
-
- if (request.getRequestType() == null) {
- return Response.status(400).build();
- }
-
- if ("ReturnBadJson".equals(request.getRequestType())) {
- return Response.status(200)
- .entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived
- + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": "
- + putMessagesReceived + "}")
- .build();
- }
-
- SOResponse response = new SOResponse();
- response.setRequest(request);
- response.setRequestReferences(new SORequestReferences());
- response.getRequestReferences().setRequestId(request.getRequestId().toString());
-
- if ("ReturnCompleted".equals(request.getRequestType())) {
- response.getRequest().getRequestStatus().setRequestState("COMPLETE");
- response.setHttpResponseCode(200);
- String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
- }
-
- if ("ReturnFailed".equals(request.getRequestType())) {
- response.getRequest().getRequestStatus().setRequestState("FAILED");
- response.setHttpResponseCode(200);
- String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
- }
-
- if ("ReturnOnging202".equals(request.getRequestType())) {
- ongoingRequestMap.put(request.getRequestId().toString(), response);
+ /**
+ * Post.
+ *
+ * @param serviceInstanceId service instance id
+ * @param vnfInstanceId vnf instance id
+ * @param jsonString json body
+ * @return http response
+ */
+ @POST
+ @Path("/serviceInstantiation/v7/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut")
+ public Response servicePostRequestVfModules(@PathParam("serviceInstanceId") final String serviceInstanceId,
+ @PathParam("vnfInstanceId") final String vnfInstanceId, final String jsonString) {
+ postMessagesReceived++;
+ return buildResponse(jsonString);
+ }
- response.getRequest().getRequestStatus().setRequestState("ONGOING");
- response.setHttpResponseCode(202);
- String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
- }
+ /**
+ * Get instance ID.
+ *
+ * @param nsInstanceId node instance id
+ * @return http response
+ */
+ @GET
+ @Path("/orchestrationRequests/v5/{nsInstanceId}")
+ public Response soRequestStatus(@PathParam("nsInstanceId") final String nsInstanceId) {
- if ("ReturnOnging200".equals(request.getRequestType())) {
- ongoingRequestMap.put(request.getRequestId().toString(), response);
+ SOResponse response = ongoingRequestMap.get(nsInstanceId);
- response.getRequest().getRequestStatus().setRequestState("ONGOING");
- response.setHttpResponseCode(200);
+ int iterationsLeft = Integer.valueOf(response.getRequest().getRequestScope());
+ if (--iterationsLeft > 0) {
+ response.getRequest().setRequestScope(new Integer(iterationsLeft).toString());
String responseString = new Gson().toJson(response, SOResponse.class);
return Response.status(response.getHttpResponseCode()).entity(responseString).build();
}
+ ongoingRequestMap.remove(nsInstanceId);
- if ("ReturnBadAfterWait".equals(request.getRequestType())) {
- ongoingRequestMap.put(request.getRequestId().toString(), response);
-
- response.getRequest().getRequestStatus().setRequestState("ONGOING");
- response.setHttpResponseCode(200);
- String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
+ if ("ReturnBadAfterWait".equals(response.getRequest().getRequestType())) {
+ return Response.status(400).build();
}
- return null;
+ response.getRequest().getRequestStatus().setRequestState("COMPLETE");
+ response.getRequest().setRequestScope("0");
+ response.setHttpResponseCode(200);
+ String responseString = new Gson().toJson(response, SOResponse.class);
+ return Response.status(response.getHttpResponseCode()).entity(responseString).build();
}
/**
- * Post.
- *
+ * Delete.
+ *
* @param serviceInstanceId service instance id
* @param vnfInstanceId vnf instance id
+ * @param vfModuleInstanceId vf module instance id
* @param jsonString json body
* @return http response
*/
- @POST
- @Path("/serviceInstantiation/v7/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/scaleOut")
- public Response servicePostRequestVfModules(@PathParam("serviceInstanceId") final String serviceInstanceId,
- @PathParam("vnfInstanceId") final String vnfInstanceId, final String jsonString) {
- postMessagesReceived++;
+ @DELETE
+ @Path("/serviceInstances/v7/{serviceInstanceId}/vnfs/{vnfInstanceId}/vfModules/{vfModuleInstanceId}")
+ public Response serviceDeleteRequestVfModules(
+ @PathParam("serviceInstanceId") final String serviceInstanceId,
+ @PathParam("vnfInstanceId") final String vnfInstanceId,
+ @PathParam("vfModuleInstanceId") final String vfModuleInstanceId,
+ final String jsonString) {
+ deleteMessagesReceived++;
+ return buildResponse(jsonString);
+ }
+ private Response buildResponse(String jsonString) {
if (jsonString == null) {
return Response.status(400).build();
}
@@ -190,10 +174,9 @@ public class TestSoDummyServer {
if ("ReturnBadJson".equals(request.getRequestType())) {
return Response.status(200)
- .entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived
- + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": "
- + putMessagesReceived + "}")
- .build();
+ .entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived
+ + ",\"POST\":" + " , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived
+ + ",\"DELETE\": " + deleteMessagesReceived + "}").build();
}
SOResponse response = new SOResponse();
@@ -205,14 +188,18 @@ public class TestSoDummyServer {
response.getRequest().getRequestStatus().setRequestState("COMPLETE");
response.setHttpResponseCode(200);
String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
+ return Response.status(response.getHttpResponseCode())
+ .entity(responseString)
+ .build();
}
if ("ReturnFailed".equals(request.getRequestType())) {
response.getRequest().getRequestStatus().setRequestState("FAILED");
response.setHttpResponseCode(200);
String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
+ return Response.status(response.getHttpResponseCode())
+ .entity(responseString)
+ .build();
}
if ("ReturnOnging202".equals(request.getRequestType())) {
@@ -221,7 +208,9 @@ public class TestSoDummyServer {
response.getRequest().getRequestStatus().setRequestState("ONGOING");
response.setHttpResponseCode(202);
String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
+ return Response.status(response.getHttpResponseCode())
+ .entity(responseString)
+ .build();
}
if ("ReturnOnging200".equals(request.getRequestType())) {
@@ -230,51 +219,21 @@ public class TestSoDummyServer {
response.getRequest().getRequestStatus().setRequestState("ONGOING");
response.setHttpResponseCode(200);
String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
+ return Response.status(response.getHttpResponseCode())
+ .entity(responseString)
+ .build();
}
-
if ("ReturnBadAfterWait".equals(request.getRequestType())) {
ongoingRequestMap.put(request.getRequestId().toString(), response);
response.getRequest().getRequestStatus().setRequestState("ONGOING");
response.setHttpResponseCode(200);
String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
+ return Response.status(response.getHttpResponseCode())
+ .entity(responseString)
+ .build();
}
-
return null;
}
-
- /**
- * Get instance ID.
- *
- * @param nsInstanceId node instance id
- * @return http response
- */
- @GET
- @Path("/orchestrationRequests/v5/{nsInstanceId}")
- public Response soRequestStatus(@PathParam("nsInstanceId") final String nsInstanceId) {
-
- SOResponse response = ongoingRequestMap.get(nsInstanceId);
-
- int iterationsLeft = Integer.valueOf(response.getRequest().getRequestScope());
- if (--iterationsLeft > 0) {
- response.getRequest().setRequestScope(new Integer(iterationsLeft).toString());
- String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
- }
-
- ongoingRequestMap.remove(nsInstanceId);
-
- if ("ReturnBadAfterWait".equals(response.getRequest().getRequestType())) {
- return Response.status(400).build();
- }
-
- response.getRequest().getRequestStatus().setRequestState("COMPLETE");
- response.getRequest().setRequestScope("0");
- response.setHttpResponseCode(200);
- String responseString = new Gson().toJson(response, SOResponse.class);
- return Response.status(response.getHttpResponseCode()).entity(responseString).build();
- }
}
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoManager.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoManager.java
index 38bfcd398..20cb54fca 100644
--- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoManager.java
+++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoManager.java
@@ -51,10 +51,18 @@ public class TestSoManager {
private static final String BASE_SO_URI = BASE_URI + "/SO";
private static HttpServer server;
+ /**
+ * Set up test class.
+ */
@BeforeClass
- public static void setUp() {
+ public static void setUp() throws IOException {
final ResourceConfig rc = new ResourceConfig(TestSoDummyServer.class);
- server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
+ //Grizzly by default doesn't allow payload for HTTP methods (ex: DELETE), for which HTTP spec doesn't
+ // explicitly state that.
+ //allow it before starting the server
+ server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc, false);
+ server.getServerConfiguration().setAllowPayloadForUndefinedHttpMethods(true);
+ server.start();
}
@AfterClass
@@ -69,7 +77,8 @@ public class TestSoManager {
CloseableHttpResponse response = httpclient.execute(httpGet);
String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
- assertTrue(returnBody.matches("^\\{\"GET\": [0-9]*,\"STAT\": [0-9]*,\"POST\": [0-9]*,\"PUT\": [0-9]*\\}$"));
+ assertTrue(returnBody.matches("^\\{\"GET\": [0-9]*,\"STAT\": [0-9]*,\"POST\": [0-9]*,\"PUT\": [0-9]*,"
+ + "\"DELETE\": [0-9]*\\}$"));
}
@Test
@@ -78,8 +87,8 @@ public class TestSoManager {
assertNotNull(manager);
manager.setRestGetTimeout(100);
- SOResponse response =
- manager.createModuleInstance("http:/localhost:99999999", BASE_SO_URI, "sean", "citizen", null);
+ SOResponse response = manager.createModuleInstance("http:/localhost:99999999", BASE_SO_URI, "sean",
+ "citizen", null);
assertNull(response);
response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
@@ -158,9 +167,11 @@ public class TestSoManager {
WorkingMemory wm = new DummyWorkingMemory();
+ SORequest soRequest = new SORequest();
+ soRequest.setOperationType(SoOperationType.SCALE_OUT);
PolicyEngine.manager.setEnvironmentProperty("so.url", "http:/localhost:99999999");
Future<SOResponse> asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm,
- UUID.randomUUID().toString(), UUID.randomUUID().toString(), null);
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest);
try {
SOResponse response = asyncRestCallFuture.get();
assertEquals(999, response.getHttpResponseCode());
@@ -170,7 +181,7 @@ public class TestSoManager {
PolicyEngine.manager.setEnvironmentProperty("so.url", BASE_SO_URI);
asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
- UUID.randomUUID().toString(), null);
+ UUID.randomUUID().toString(), soRequest);
try {
SOResponse response = asyncRestCallFuture.get();
assertEquals(999, response.getHttpResponseCode());
@@ -178,8 +189,122 @@ public class TestSoManager {
fail("test should not throw an exception");
}
+ SORequest request = new SORequest();
+ request.setRequestId(UUID.randomUUID());
+ request.setRequestScope("Test");
+ request.setRequestType("ReturnBadJson");
+ request.setStartTime("2018-03-23 16:31");
+ request.setRequestStatus(new SORequestStatus());
+ request.getRequestStatus().setRequestState("ONGOING");
+ request.setOperationType(SoOperationType.SCALE_OUT);
+
+ asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(), request);
+ try {
+ SOResponse response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
+ } catch (Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ request.setRequestType("ReturnCompleted");
+
+ asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(), request);
+ try {
+ SOResponse response = asyncRestCallFuture.get();
+ assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ } catch (Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ request.setRequestType("ReturnFailed");
+ asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(), request);
+ try {
+ SOResponse response = asyncRestCallFuture.get();
+ assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
+ } catch (Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ // Use scope to set the number of iterations we'll wait for
+
+ request.setRequestType("ReturnOnging200");
+ request.setRequestScope(new Integer(10).toString());
+ asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(), request);
+ try {
+ SOResponse response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ } catch (Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ request.setRequestType("ReturnOnging202");
+ request.setRequestScope(new Integer(20).toString());
+ asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(), request);
+ try {
+ SOResponse response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ } catch (Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ // Test timeout after 20 attempts for a response
+ request.setRequestType("ReturnOnging202");
+ request.setRequestScope(new Integer(21).toString());
+ asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(), request);
+ try {
+ SOResponse response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
+ } catch (Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ // Test bad response after 3 attempts for a response
+ request.setRequestType("ReturnBadAfterWait");
+ request.setRequestScope(new Integer(3).toString());
+ asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
+ UUID.randomUUID().toString(), request);
+ try {
+ SOResponse response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
+ } catch (Exception e) {
+ fail("test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testVfModuleDeletion() {
+ SOManager manager = new SOManager();
+ assertNotNull(manager);
+ manager.setRestGetTimeout(100);
+
+ PolicyEngine.manager.setEnvironmentProperty("so.username", "sean");
+ PolicyEngine.manager.setEnvironmentProperty("so.password", "citizen");
+
+ WorkingMemory wm = new DummyWorkingMemory();
+
+ SORequest soRequest = new SORequest();
+ soRequest.setOperationType(SoOperationType.DELETE_VF_MODULE);
+ PolicyEngine.manager.setEnvironmentProperty("so.url", "http:/localhost:99999999");
+ Future<SOResponse> asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm,
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest);
+ try {
+ SOResponse response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
+ } catch (Exception e) {
+ fail("test should not throw an exception");
+ }
+
+ PolicyEngine.manager.setEnvironmentProperty("so.url", BASE_SO_URI);
asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
- UUID.randomUUID().toString(), new SORequest());
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest);
try {
SOResponse response = asyncRestCallFuture.get();
assertEquals(999, response.getHttpResponseCode());
@@ -194,9 +319,10 @@ public class TestSoManager {
request.setStartTime("2018-03-23 16:31");
request.setRequestStatus(new SORequestStatus());
request.getRequestStatus().setRequestState("ONGOING");
+ request.setOperationType(SoOperationType.DELETE_VF_MODULE);
asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
- UUID.randomUUID().toString(), request);
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
try {
SOResponse response = asyncRestCallFuture.get();
assertEquals(999, response.getHttpResponseCode());
@@ -207,7 +333,7 @@ public class TestSoManager {
request.setRequestType("ReturnCompleted");
asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
- UUID.randomUUID().toString(), request);
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
try {
SOResponse response = asyncRestCallFuture.get();
assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
@@ -217,7 +343,7 @@ public class TestSoManager {
request.setRequestType("ReturnFailed");
asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
- UUID.randomUUID().toString(), request);
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
try {
SOResponse response = asyncRestCallFuture.get();
assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
@@ -230,7 +356,7 @@ public class TestSoManager {
request.setRequestType("ReturnOnging200");
request.setRequestScope(new Integer(10).toString());
asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
- UUID.randomUUID().toString(), request);
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
try {
SOResponse response = asyncRestCallFuture.get();
assertNotNull(response.getRequest());
@@ -242,7 +368,7 @@ public class TestSoManager {
request.setRequestType("ReturnOnging202");
request.setRequestScope(new Integer(20).toString());
asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
- UUID.randomUUID().toString(), request);
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
try {
SOResponse response = asyncRestCallFuture.get();
assertNotNull(response.getRequest());
@@ -255,7 +381,7 @@ public class TestSoManager {
request.setRequestType("ReturnOnging202");
request.setRequestScope(new Integer(21).toString());
asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
- UUID.randomUUID().toString(), request);
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
try {
SOResponse response = asyncRestCallFuture.get();
assertEquals(999, response.getHttpResponseCode());
@@ -267,7 +393,7 @@ public class TestSoManager {
request.setRequestType("ReturnBadAfterWait");
request.setRequestScope(new Integer(3).toString());
asyncRestCallFuture = manager.asyncSORestCall(UUID.randomUUID().toString(), wm, UUID.randomUUID().toString(),
- UUID.randomUUID().toString(), request);
+ UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
try {
SOResponse response = asyncRestCallFuture.get();
assertEquals(999, response.getHttpResponseCode());
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequest.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequest.java
index f58254184..2f9bf68bb 100755
--- a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequest.java
+++ b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequest.java
@@ -65,6 +65,9 @@ public class TestSoRequest {
obj.setRequestType("requestType");
assertEquals("requestType", obj.getRequestType());
+ obj.setOperationType(SoOperationType.DELETE_VF_MODULE);
+ assertEquals(SoOperationType.DELETE_VF_MODULE, obj.getOperationType());
+
LocalDateTime startTime = LocalDateTime.now();
obj.setStartTime(startTime.toString());
assertEquals(startTime.toString(), obj.getStartTime());
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
index 1a8d603b5..d84d0403f 100644
--- 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
@@ -108,14 +108,14 @@ public final class VFCManager implements Runnable {
return;
}
- if (httpDetails.a != 202) {
+ if (httpDetails.first != 202) {
logger.warn("VFC Heal Restcall failed");
return;
}
try {
- VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, VFCResponse.class);
- netLogger.info("[IN|{}|{}|]{}{}", "VFC", vfcUrl, SYSTEM_LS, httpDetails.b);
+ VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, VFCResponse.class);
+ netLogger.info("[IN|{}|{}|]{}{}", "VFC", vfcUrl, SYSTEM_LS, httpDetails.second);
String body = Serialization.gsonPretty.toJson(response);
logger.debug("Response to VFC Heal post:");
logger.debug(body);
@@ -129,15 +129,15 @@ public final class VFCManager implements Runnable {
while (attemptsLeft-- > 0) {
netLogger.info("[OUT|{}|{}|]", "VFC", urlGet);
Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers);
- responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, VFCResponse.class);
- netLogger.info("[IN|{}|{}|]{}{}", "VFC", urlGet, SYSTEM_LS, httpDetailsGet.b);
+ responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.second, VFCResponse.class);
+ netLogger.info("[IN|{}|{}|]{}{}", "VFC", urlGet, SYSTEM_LS, httpDetailsGet.second);
responseGet.setRequestId(vfcRequest.getRequestId().toString());
body = Serialization.gsonPretty.toJson(responseGet);
logger.debug("Response to VFC Heal get:");
logger.debug(body);
String responseStatus = responseGet.getResponseDescriptor().getStatus();
- if (httpDetailsGet.a == 200
+ if (httpDetailsGet.first == 200
&& ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) {
logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus());
workingMem.insert(responseGet);
diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java
index cebf5f7fe..3768b1b32 100644
--- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java
+++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java
@@ -60,16 +60,16 @@ public class GuardSimulatorTest {
Pair<Integer, String> response =
new RESTManager().post(url, "testUname", "testPass", null, "application/json", request);
assertNotNull(response);
- assertNotNull(response.a);
- assertNotNull(response.b);
- assertEquals("{\"decision\": \"PERMIT\", \"details\": \"Decision Permit. OK!\"}", response.b);
+ assertNotNull(response.first);
+ assertNotNull(response.second);
+ assertEquals("{\"decision\": \"PERMIT\", \"details\": \"Decision Permit. OK!\"}", response.second);
request = makeRequest("test_actor_id", "test_op_id", "test_target", "denyGuard");
response = new RESTManager().post(url, "testUname", "testPass", null, "application/json", request);
assertNotNull(response);
- assertNotNull(response.a);
- assertNotNull(response.b);
- assertEquals("{\"decision\": \"DENY\", \"details\": \"Decision Deny. You asked for it\"}", response.b);
+ assertNotNull(response.first);
+ assertNotNull(response.second);
+ assertEquals("{\"decision\": \"DENY\", \"details\": \"Decision Deny. You asked for it\"}", response.second);
}
private static String makeRequest(String actor, String recipe, String target, String clName) {
diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java
index 4fce837b9..772dd7f2c 100644
--- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java
+++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/SoSimulatorTest.java
@@ -142,7 +142,7 @@ public class SoSimulatorTest {
"http://localhost:6667/serviceInstantiation/v7/12345/vnfs/12345/vfModules/scaleOut", "username",
"password", new HashMap<>(), "application/json", request);
assertNotNull(httpDetails);
- final SOResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, SOResponse.class);
+ final SOResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, SOResponse.class);
assertNotNull(response);
}
}
diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/VfcSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/VfcSimulatorTest.java
index 8a7afb959..0e083bb6c 100644
--- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/VfcSimulatorTest.java
+++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/VfcSimulatorTest.java
@@ -63,8 +63,8 @@ public class VfcSimulatorTest {
new RESTManager().post("http://localhost:6668/api/nslcm/v1/ns/1234567890/heal", "username", "password",
new HashMap<String, String>(), "application/json", "Some Request Here");
assertNotNull(httpDetails);
- assertTrue(httpDetails.a == 202);
- final VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, VFCResponse.class);
+ assertTrue(httpDetails.first == 202);
+ final VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, VFCResponse.class);
assertNotNull(response);
}
@@ -73,7 +73,7 @@ public class VfcSimulatorTest {
final Pair<Integer, String> httpDetails = new RESTManager().get("http://localhost:6668/api/nslcm/v1/jobs/1234",
"username", "password", new HashMap<String, String>());
assertNotNull(httpDetails);
- final VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, VFCResponse.class);
+ final VFCResponse response = Serialization.gsonPretty.fromJson(httpDetails.second, VFCResponse.class);
assertNotNull(response);
}
}