aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-actors/actor.so')
-rw-r--r--models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java55
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java25
2 files changed, 39 insertions, 41 deletions
diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java
index 2da0a95af..8aad5feb3 100644
--- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java
+++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoActorServiceProvider.java
@@ -57,6 +57,9 @@ import org.slf4j.LoggerFactory;
public class SoActorServiceProvider implements Actor {
private static final Logger logger = LoggerFactory.getLogger(SoActorServiceProvider.class);
+ private static final String TENANT_NOT_FOUND = "Tenant Item not found in AAI response {}";
+ private static final String CONSTRUCTED_SO_MSG = "Constructed SO request: {}";
+
// Strings for SO Actor
private static final String SO_ACTOR = "SO";
@@ -160,7 +163,7 @@ public class SoActorServiceProvider implements Actor {
tenantItem = aaiResponseWrapper.getAaiNqResponse().getInventoryResponseItems().get(0).getItems()
.getInventoryResponseItems().get(1);
} catch (Exception e) {
- logger.error("Tenant Item not found in AAI response {}",
+ logger.error(TENANT_NOT_FOUND,
Serialization.gsonPretty.toJson(aaiResponseWrapper), e);
return null;
}
@@ -180,7 +183,7 @@ public class SoActorServiceProvider implements Actor {
if (RECIPE_VF_MODULE_CREATE.equals(policy.getRecipe())) {
return constructCreateRequest(aaiResponseWrapper, policy, tenantItem, vnfItem, vnfServiceItem, soModelInfo);
} else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) {
- return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, soModelInfo, policy);
+ return constructDeleteRequest(tenantItem, vnfItem, vnfServiceItem, policy);
} else {
return null;
}
@@ -188,21 +191,23 @@ public class SoActorServiceProvider implements Actor {
private SoModelInfo prepareSoModelInfo(Policy policy) {
- SoModelInfo soModelInfo = new SoModelInfo();
- if ((policy.getTarget() != null && (policy.getTarget().getModelCustomizationId() != null))
- && (policy.getTarget().getModelInvariantId() != null) && (policy.getTarget().getModelName() != null)
- && (policy.getTarget().getModelVersion() != null) && (policy.getTarget().getModelVersionId() != null)) {
-
- soModelInfo.setModelCustomizationId(policy.getTarget().getModelCustomizationId());
- soModelInfo.setModelInvariantId(policy.getTarget().getModelInvariantId());
- soModelInfo.setModelName(policy.getTarget().getModelName());
- soModelInfo.setModelVersion(policy.getTarget().getModelVersion());
- soModelInfo.setModelVersionId(policy.getTarget().getModelVersionId());
- soModelInfo.setModelType("vfModule");
- return soModelInfo;
- } else {
+ if (policy.getTarget() == null || policy.getTarget().getModelCustomizationId() == null
+ || policy.getTarget().getModelInvariantId() == null) {
return null;
}
+
+ if (policy.getTarget().getModelName() == null || policy.getTarget().getModelVersion() == null
+ || policy.getTarget().getModelVersionId() == null) {
+ return null;
+ }
+
+ SoModelInfo soModelInfo = new SoModelInfo();
+ soModelInfo.setModelCustomizationId(policy.getTarget().getModelCustomizationId());
+ soModelInfo.setModelInvariantId(policy.getTarget().getModelInvariantId());
+ soModelInfo.setModelName(policy.getTarget().getModelName());
+ soModelInfo.setModelVersion(policy.getTarget().getModelVersion());
+ soModelInfo.setModelVersionId(policy.getTarget().getModelVersionId());
+ return soModelInfo;
}
/**
@@ -301,7 +306,7 @@ public class SoActorServiceProvider implements Actor {
preserveInstanceIds(vnfItem.getGenericVnf().getVnfId(),
vnfServiceItem.getServiceInstance().getServiceInstanceId(), null);
if (logger.isDebugEnabled()) {
- logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
+ logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request));
}
return request;
}
@@ -312,11 +317,10 @@ public class SoActorServiceProvider implements Actor {
* @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
- * @param vfModuleItem vf module item from A&AI named-query response
* @return SO delete vf-module request
*/
private SoRequest constructDeleteRequest(AaiNqInventoryResponseItem tenantItem, AaiNqInventoryResponseItem vnfItem,
- AaiNqInventoryResponseItem vnfServiceItem, SoModelInfo vfModuleItem, Policy policy) {
+ AaiNqInventoryResponseItem vnfServiceItem, Policy policy) {
SoRequest request = new SoRequest();
request.setOperationType(SoOperationType.DELETE_VF_MODULE);
request.setRequestDetails(new SoRequestDetails());
@@ -334,7 +338,7 @@ public class SoActorServiceProvider implements Actor {
vnfServiceItem.getServiceInstance().getServiceInstanceId(), null);
if (logger.isDebugEnabled()) {
- logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
+ logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request));
}
return request;
}
@@ -513,14 +517,14 @@ public class SoActorServiceProvider implements Actor {
try {
tenantItem = aaiCqResponse.getDefaultTenant();
} catch (Exception e) {
- logger.error("Tenant Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiCqResponse), e);
+ logger.error(TENANT_NOT_FOUND, Serialization.gsonPretty.toJson(aaiCqResponse), e);
return null;
}
try {
cloudRegionItem = aaiCqResponse.getDefaultCloudRegion();
} catch (Exception e) {
- logger.error("Tenant Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiCqResponse), e);
+ logger.error(TENANT_NOT_FOUND, Serialization.gsonPretty.toJson(aaiCqResponse), e);
return null;
}
@@ -531,7 +535,7 @@ public class SoActorServiceProvider implements Actor {
return constructCreateRequestCq(aaiCqResponse, policy, tenantItem, vnfItem, vnfServiceItem, soModelInfo,
cloudRegionItem);
} else if (RECIPE_VF_MODULE_DELETE.equals(policy.getRecipe())) {
- return constructDeleteRequestCq(tenantItem, vnfItem, vnfServiceItem, soModelInfo, policy, cloudRegionItem);
+ return constructDeleteRequestCq(tenantItem, vnfItem, vnfServiceItem, policy, cloudRegionItem);
} else {
return null;
}
@@ -622,7 +626,7 @@ public class SoActorServiceProvider implements Actor {
// vfModuleId is not required for the create vf-module
preserveInstanceIds(vnfItem.getVnfId(), vnfServiceItem.getServiceInstanceId(), null);
if (logger.isDebugEnabled()) {
- logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
+ logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request));
}
return request;
}
@@ -633,13 +637,12 @@ public class SoActorServiceProvider implements Actor {
* @param tenantItem Tenant from A&AI CQ request
* @param vnfItem Generic VNF from A&AI CQ request
* @param vnfServiceItem ServiceInstance from A&AI CQ request
- * @param vfModuleItem VFModule from A&AI CQ request
* @param policy policy information
* @param cloudRegionItem CloudRegion from A&AI CQ request
* @return SoRequest deleted
*/
private SoRequest constructDeleteRequestCq(Tenant tenantItem, GenericVnf vnfItem, ServiceInstance vnfServiceItem,
- SoModelInfo vfModuleItem, Policy policy, CloudRegion cloudRegionItem) {
+ Policy policy, CloudRegion cloudRegionItem) {
SoRequest request = new SoRequest();
request.setOperationType(SoOperationType.DELETE_VF_MODULE);
request.setRequestDetails(new SoRequestDetails());
@@ -656,7 +659,7 @@ public class SoActorServiceProvider implements Actor {
preserveInstanceIds(vnfItem.getVnfId(), vnfServiceItem.getServiceInstanceId(), null);
if (logger.isDebugEnabled()) {
- logger.debug("Constructed SO request: {}", Serialization.gsonPretty.toJson(request));
+ logger.debug(CONSTRUCTED_SO_MSG, Serialization.gsonPretty.toJson(request));
}
return request;
}
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
index 9c26a4cd1..175d2fe0c 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorServiceProviderTest.java
@@ -26,7 +26,6 @@ package org.onap.policy.controlloop.actor.so;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -36,7 +35,6 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
-import org.eclipse.persistence.exceptions.JAXBException;
import org.junit.Test;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.aai.AaiNqResponse;
@@ -52,6 +50,8 @@ import org.onap.policy.so.util.Serialization;
public class SoActorServiceProviderTest {
+ private static final String C_VALUE = "cvalue";
+ private static final String A_VALUE = "avalue";
private static final String VF_MODULE_CREATE = "VF Module Create";
private static final String VF_MODULE_DELETE = "VF Module Delete";
@@ -90,9 +90,9 @@ public class SoActorServiceProviderTest {
request = new SoActorServiceProvider().constructRequest(onset, operation, policy, aaiNqResp);
assertNotNull(request);
assertEquals(true, request.getRequestDetails().getRequestParameters().isUsePreload());
- assertEquals("avalue", request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey"));
+ assertEquals(A_VALUE, request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey"));
assertEquals(1, request.getRequestDetails().getConfigurationParameters().size());
- assertEquals("cvalue", request.getRequestDetails().getConfigurationParameters().get(0).get("ckey"));
+ assertEquals(C_VALUE, request.getRequestDetails().getConfigurationParameters().get(0).get("ckey"));
// payload with config, but no request params
policy.setPayload(makePayload());
@@ -176,11 +176,7 @@ public class SoActorServiceProviderTest {
@Test
public void testSendRequest() {
- try {
- SoActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null, null, null, null);
- } catch (Exception e) {
- fail("Test should not throw an exception");
- }
+ SoActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null, null, null, null);
}
@Test
@@ -232,9 +228,9 @@ public class SoActorServiceProviderTest {
request = new SoActorServiceProvider().constructRequestCq(onset, operation, policy, aaiCqResp);
assertNotNull(request);
assertEquals(true, request.getRequestDetails().getRequestParameters().isUsePreload());
- assertEquals("avalue", request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey"));
+ assertEquals(A_VALUE, request.getRequestDetails().getRequestParameters().getUserParams().get(0).get("akey"));
assertEquals(1, request.getRequestDetails().getConfigurationParameters().size());
- assertEquals("cvalue", request.getRequestDetails().getConfigurationParameters().get(0).get("ckey"));
+ assertEquals(C_VALUE, request.getRequestDetails().getConfigurationParameters().get(0).get("ckey"));
// payload with config, but no request params
policy.setPayload(makePayload());
@@ -282,9 +278,8 @@ public class SoActorServiceProviderTest {
* @param fileName name of the file containing the JSON response
* @return output from the AAI vserver named-query
* @throws IOException if the file cannot be read
- * @throws JAXBException throws JAXBException
*/
- private AaiCqResponse loadAaiResponseCq(String fileName) throws IOException, JAXBException {
+ private AaiCqResponse loadAaiResponseCq(String fileName) throws IOException {
String resp = IOUtils.toString(getClass().getResource(fileName), StandardCharsets.UTF_8);
return new AaiCqResponse(resp);
}
@@ -316,7 +311,7 @@ public class SoActorServiceProviderTest {
params.setUsePreload(true);
Map<String, String> map = new TreeMap<>();
- map.put("akey", "avalue");
+ map.put("akey", A_VALUE);
List<Map<String, String>> lst = new LinkedList<>();
lst.add(map);
@@ -333,7 +328,7 @@ public class SoActorServiceProviderTest {
*/
private String makeConfigParams() {
Map<String, String> map = new TreeMap<>();
- map.put("ckey", "cvalue");
+ map.put("ckey", C_VALUE);
List<Map<String, String>> lst = new LinkedList<>();
lst.add(map);