diff options
13 files changed, 284 insertions, 400 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/StackInfo.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/StackInfo.java index 83e1484257..600985e310 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/StackInfo.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/StackInfo.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,136 +20,89 @@ package org.openecomp.mso.openstack.beans; - -import java.util.Map; -import java.util.HashMap; - import com.woorea.openstack.heat.model.Stack; +import java.util.HashMap; +import java.util.Map; /* * This Java bean class relays Heat stack status information to ActiveVOS processes. - * + * * This bean is returned by all Heat-specific adapter operations (create, query, delete) */ - public class StackInfo { - // Set defaults for everything private String name = ""; private String canonicalName = ""; - private HeatStatus status = HeatStatus.UNKNOWN; - private String statusMessage = ""; - private Map<String,Object> outputs = new HashMap<String,Object>(); - private Map<String,Object> parameters = new HashMap<String,Object>(); - - static Map<String,HeatStatus> HeatStatusMap; - static { - HeatStatusMap = new HashMap<String,HeatStatus>(); - HeatStatusMap.put("CREATE_IN_PROGRESS", HeatStatus.BUILDING); - HeatStatusMap.put("CREATE_COMPLETE", HeatStatus.CREATED); - HeatStatusMap.put("CREATE_FAILED", HeatStatus.FAILED); - HeatStatusMap.put("DELETE_IN_PROGRESS", HeatStatus.DELETING); - HeatStatusMap.put("DELETE_COMPLETE", HeatStatus.NOTFOUND); - HeatStatusMap.put("DELETE_FAILED", HeatStatus.FAILED); - HeatStatusMap.put("UPDATE_IN_PROGRESS", HeatStatus.UPDATING); - HeatStatusMap.put("UPDATE_FAILED", HeatStatus.FAILED); - HeatStatusMap.put("UPDATE_COMPLETE", HeatStatus.UPDATED); - } + private HeatStatus status; + private Map<String, Object> outputs = new HashMap<>(); + private Map<String,Object> parameters = new HashMap<>(); + static private Map<String, HeatStatus> heatStatusMap; - public StackInfo () { + static { + heatStatusMap = new HashMap<>(); + heatStatusMap.put("CREATE_IN_PROGRESS", HeatStatus.BUILDING); + heatStatusMap.put("CREATE_COMPLETE", HeatStatus.CREATED); + heatStatusMap.put("CREATE_FAILED", HeatStatus.FAILED); + heatStatusMap.put("DELETE_IN_PROGRESS", HeatStatus.DELETING); + heatStatusMap.put("DELETE_COMPLETE", HeatStatus.NOTFOUND); + heatStatusMap.put("DELETE_FAILED", HeatStatus.FAILED); + heatStatusMap.put("UPDATE_IN_PROGRESS", HeatStatus.UPDATING); + heatStatusMap.put("UPDATE_FAILED", HeatStatus.FAILED); + heatStatusMap.put("UPDATE_COMPLETE", HeatStatus.UPDATED); } - - public StackInfo (String name, HeatStatus status, String statusMessage, Map<String,Object> outputs) { - this.name = name; - this.canonicalName = name; // Don't have an ID, so just use name - this.status = status; - if (statusMessage != null) this.statusMessage = statusMessage; - if (outputs != null) this.outputs = outputs; - } - public StackInfo (String name, HeatStatus status) { this.name = name; this.canonicalName = name; // Don't have an ID, so just use name this.status = status; } - + public StackInfo (Stack stack) { if (stack == null) { this.status = HeatStatus.NOTFOUND; return; } - this.name = stack.getStackName(); this.canonicalName = stack.getStackName() + "/" + stack.getId(); if (stack.getStackStatus() == null) { this.status = HeatStatus.INIT; - } else if (HeatStatusMap.containsKey(stack.getStackStatus())) { - this.status = HeatStatusMap.get(stack.getStackStatus()); + } else if (heatStatusMap.containsKey(stack.getStackStatus())) { + this.status = heatStatusMap.get(stack.getStackStatus()); } else { this.status = HeatStatus.UNKNOWN; } - - this.statusMessage = stack.getStackStatusReason(); - if (stack.getOutputs() != null) { - this.outputs = new HashMap<String,Object>(); - for (Stack.Output output : stack.getOutputs()) { - this.outputs.put(output.getOutputKey(), output.getOutputValue()); - } + this.outputs = new HashMap<>(); + stack.getOutputs().forEach(output -> outputs.put(output.getOutputKey(), output.getOutputValue())); } - + this.parameters = stack.getParameters(); } - + public String getName() { return name; } - + public void setName (String name) { this.name = name; } - + public String getCanonicalName() { return canonicalName; } - - public void setCanonicalName (String name) { - this.canonicalName = name; - } - + public HeatStatus getStatus() { return status; } - - public void setStatus (HeatStatus status) { - this.status = status; - } - - public String getStatusMessage() { - return statusMessage; - } - - public void setStatusMessage (String statusMessage) { - this.statusMessage = statusMessage; - } - - public Map<String,Object> getOutputs () { + + public Map<String, Object> getOutputs() { return outputs; } - - public void setOutputs (Map<String,Object> outputs) { - this.outputs = outputs; - } - + public Map<String,Object> getParameters () { return parameters; } - - public void setParameters (Map<String,Object> parameters) { - this.parameters = parameters; - } - + } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java index 08ea84d85d..8f21cfb2a3 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java @@ -648,7 +648,7 @@ public class MsoHeatUtils extends MsoCommonUtils { } catch (MsoTenantNotFound e) { // Tenant doesn't exist, so stack doesn't either LOGGER.debug ("Tenant with id " + tenantId + "not found.", e); - return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + return new StackInfo (stackName, HeatStatus.NOTFOUND); } catch (MsoException me) { // Got an Openstack error. Propagate it LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "Openstack Exception on Token request: " + me, "Openstack", "", MsoLogger.ErrorCode.AvailabilityError, "Connection Exception"); @@ -662,7 +662,7 @@ public class MsoHeatUtils extends MsoCommonUtils { if (heatStack == null) { // Stack does not exist. Return a StackInfo with status NOTFOUND - StackInfo stackInfo = new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + StackInfo stackInfo = new StackInfo (stackName, HeatStatus.NOTFOUND); return stackInfo; } @@ -712,7 +712,7 @@ public class MsoHeatUtils extends MsoCommonUtils { } catch (MsoTenantNotFound e) { // Tenant doesn't exist, so stack doesn't either LOGGER.debug ("Tenant with id " + tenantId + "not found.", e); - return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + return new StackInfo (stackName, HeatStatus.NOTFOUND); } catch (MsoException me) { // Got an Openstack error. Propagate it LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "Openstack", "Openstack Exception on Token request: " + me, "Openstack", "", MsoLogger.ErrorCode.AvailabilityError, "Connection Exception"); @@ -724,7 +724,7 @@ public class MsoHeatUtils extends MsoCommonUtils { Stack heatStack = queryHeatStack (heatClient, stackName); if (heatStack == null || "DELETE_COMPLETE".equals (heatStack.getStackStatus ())) { // Not found. Return a StackInfo with status NOTFOUND - return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + return new StackInfo (stackName, HeatStatus.NOTFOUND); } // Delete the stack. @@ -747,7 +747,7 @@ public class MsoHeatUtils extends MsoCommonUtils { } catch (OpenStackResponseException e) { if (e.getStatus () == 404) { // Not found. We are OK with this. Return a StackInfo with status NOTFOUND - return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + return new StackInfo (stackName, HeatStatus.NOTFOUND); } else { // Convert the OpenStackResponseException to an MsoOpenstackException throw heatExceptionToMsoException (e, DELETE_STACK); @@ -813,7 +813,7 @@ public class MsoHeatUtils extends MsoCommonUtils { } // The stack is gone when this point is reached - return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + return new StackInfo (stackName, HeatStatus.NOTFOUND); } // Return the current status (if not polling, the delete may still be in progress) diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java index 6bd78153b6..250211845f 100644 --- a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/AdapterBeansTest.java @@ -22,18 +22,15 @@ package org.openecomp.mso.adapter_utils.tests; import static org.junit.Assert.assertTrue;
-import com.woorea.openstack.heat.model.Stack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.openecomp.mso.entity.MsoRequest;
-import org.openecomp.mso.openstack.beans.HeatStatus;
import org.openecomp.mso.openstack.beans.MsoTenant;
import org.openecomp.mso.openstack.beans.NetworkRollback;
import org.openecomp.mso.openstack.beans.Pool;
-import org.openecomp.mso.openstack.beans.StackInfo;
import org.openecomp.mso.openstack.beans.Subnet;
import org.openecomp.mso.openstack.beans.VnfRollback;
@@ -99,26 +96,6 @@ public class AdapterBeansTest { }
@Test
- public final void stackInfoTest() {
- StackInfo stackInfo = new StackInfo();
- new StackInfo(new Stack());
- new StackInfo("name", HeatStatus.CREATED, "statusmessage", new HashMap<>());
- new StackInfo("name", HeatStatus.CREATED);
- stackInfo.setCanonicalName("Canonicalname");
- stackInfo.getCanonicalName();
- stackInfo.setName("name");
- stackInfo.getName();
- stackInfo.setOutputs(new HashMap<>());
- stackInfo.getOutputs();
- stackInfo.setParameters(new HashMap<>());
- stackInfo.getParameters();
- stackInfo.setStatus(HeatStatus.CREATED);
- stackInfo.getStatus();
- stackInfo.setStatusMessage("statusMessage");
- stackInfo.getStatusMessage();
- }
-
- @Test
public final void subnetTest() {
Subnet subnet = new Subnet();
subnet.setAllocationPools(new ArrayList<>());
diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/StackInfoTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/StackInfoTest.java new file mode 100644 index 0000000000..9c7911ef89 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/StackInfoTest.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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.openecomp.mso.openstack.beans; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.woorea.openstack.heat.model.Stack; +import java.io.IOException; +import org.codehaus.jackson.JsonNode; +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.Test; + +public class StackInfoTest { + + private static final String STACK_NAME = "stackNameTest"; + private static final String STACK_STATUS = "CREATE_COMPLETE"; + private static final String STACK_OUTPUT_KEY = "outputKeyTest"; + private static final String STACK_OUTPUT_VALUE = "outputValueTest"; + private static final String STACK_PARAM_KEY = "paramKeyTest"; + private static final String STACK_PARAM_VALUE = "paramValueTest"; + + @Test + public void setStatusNotFoundWhenStackIsNull() { + StackInfo stackInfo = new StackInfo(null); + assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.NOTFOUND); + assertThat(stackInfo.getOutputs()).isEmpty(); + assertThat(stackInfo.getParameters()).isEmpty(); + } + + @Test + public void createObjectWhenStackStatusIsNull() { + StackInfo stackInfo = new StackInfo(createStackWithStatus(null)); + assertThat(stackInfo.getName()).isEqualTo(STACK_NAME); + assertThat(stackInfo.getOutputs()).isEmpty(); + assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.INIT); + assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE); + } + + @Test + public void createObjectWhenStackStatusIsFound() { + StackInfo stackInfo = new StackInfo(createStackWithStatus(STACK_STATUS)); + assertThat(stackInfo.getName()).isEqualTo(STACK_NAME); + assertThat(stackInfo.getOutputs()).isEmpty(); + assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.CREATED); + assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE); + } + + @Test + public void createObjectWhenStackStatusIsUnknown() { + StackInfo stackInfo = new StackInfo(createStackWithStatus("unknownStatus")); + assertThat(stackInfo.getName()).isEqualTo(STACK_NAME); + assertThat(stackInfo.getOutputs()).isEmpty(); + assertThat(stackInfo.getStatus()).isEqualTo(HeatStatus.UNKNOWN); + assertThat(stackInfo.getParameters()).hasSize(1).containsEntry(STACK_PARAM_KEY, STACK_PARAM_VALUE); + } + + @Test + public void createStackWhenOutputsListIsNotNull() throws IOException { + StackInfo stackInfo = new StackInfo(createStackWithOutputs()); + assertThat(stackInfo.getOutputs()).isNotEmpty().hasSize(1); + assertThat(stackInfo.getOutputs()).hasSize(1).containsEntry(STACK_OUTPUT_KEY, STACK_OUTPUT_VALUE); + } + + private Stack createStackWithStatus(String stackStatus) { + Stack stack = new Stack(); + stack.setStackName(STACK_NAME); + stack.setStackStatus(stackStatus); + stack.getParameters().put(STACK_PARAM_KEY, STACK_PARAM_VALUE); + return stack; + } + + private Stack createStackWithOutputs() throws IOException { + String json = "{\"outputs\":[{\"output_key\" : \"" + STACK_OUTPUT_KEY + "\", \"output_value\" : \"" + + STACK_OUTPUT_VALUE + "\" }]}"; + JsonNode node = new ObjectMapper().readTree(json); + Stack stack = new ObjectMapper().readValue(node, Stack.class); + return stack; + } + +} diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/MsoVnfAdapterAsyncImplTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/MsoVnfAdapterAsyncImplTest.java index b680170abe..a045b00699 100644 --- a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/MsoVnfAdapterAsyncImplTest.java +++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/MsoVnfAdapterAsyncImplTest.java @@ -22,18 +22,10 @@ package org.openecomp.mso.adapters.vnf.test; import java.util.HashMap;
import java.util.Map;
-
import org.junit.Test;
import org.openecomp.mso.adapters.vnf.MsoVnfAdapterAsyncImpl;
import org.openecomp.mso.entity.MsoRequest;
-import org.openecomp.mso.openstack.beans.HeatStatus;
-import org.openecomp.mso.openstack.beans.StackInfo;
import org.openecomp.mso.openstack.beans.VnfRollback;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-import org.openecomp.mso.openstack.utils.MsoHeatUtils;
-
-import mockit.Mock;
-import mockit.MockUp;
public class MsoVnfAdapterAsyncImplTest {
@@ -45,15 +37,6 @@ public class MsoVnfAdapterAsyncImplTest { @Test
public void createVNFTest() {
- new MockUp<MsoHeatUtils>() {
- @Mock
- public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {
- StackInfo info = new StackInfo();
- info.setStatus(HeatStatus.CREATED);
- return info;
- }
- };
-
MsoVnfAdapterAsyncImpl instance = new MsoVnfAdapterAsyncImpl();
MsoRequest msoRequest = new MsoRequest();
msoRequest.setRequestId("12345");
diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/MsoVnfAdapterImplTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/MsoVnfAdapterImplTest.java index 77879089e9..6f01954db3 100644 --- a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/MsoVnfAdapterImplTest.java +++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/MsoVnfAdapterImplTest.java @@ -22,24 +22,11 @@ package org.openecomp.mso.adapters.vnf.test; import java.util.HashMap;
import java.util.Map;
-
import javax.xml.ws.Holder;
-
import org.junit.Test;
import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl;
-import org.openecomp.mso.db.catalog.CatalogDatabase;
-import org.openecomp.mso.db.catalog.beans.VfModule;
-import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
-import org.openecomp.mso.db.catalog.beans.VnfResource;
import org.openecomp.mso.entity.MsoRequest;
-import org.openecomp.mso.openstack.beans.HeatStatus;
-import org.openecomp.mso.openstack.beans.StackInfo;
import org.openecomp.mso.openstack.beans.VnfRollback;
-import org.openecomp.mso.openstack.exceptions.MsoException;
-import org.openecomp.mso.openstack.utils.MsoHeatUtils;
-
-import mockit.Mock;
-import mockit.MockUp;
public class MsoVnfAdapterImplTest {
@@ -51,16 +38,6 @@ public class MsoVnfAdapterImplTest { @Test
public void createVnfTest() {
-
- new MockUp<MsoHeatUtils>() {
- @Mock
- public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {
- StackInfo info = new StackInfo();
- info.setStatus(HeatStatus.CREATED);
- return info;
- }
- };
-
MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();
MsoRequest msoRequest = new MsoRequest();
msoRequest.setRequestId("12345");
@@ -80,37 +57,6 @@ public class MsoVnfAdapterImplTest { @Test
public void updateVnfTest() {
-
- new MockUp<MsoHeatUtils>() {
- @Mock
- public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {
- StackInfo info = new StackInfo();
- info.setStatus(HeatStatus.CREATED);
- return info;
- }
- };
-
- new MockUp<CatalogDatabase>() {
- @Mock
- public VfModuleCustomization getVfModuleCustomizationByModelCustomizationId(String modelCustomizationUuid) {
- VfModuleCustomization vfcModule = new VfModuleCustomization();
- VfModule vfm = new VfModule();
- vfm.setVnfResourceModelUUId("88a6ca3ee0394ade9403f075db23167e");
- vfcModule.setVfModule(vfm);
- return vfcModule;
- }
- };
-
- new MockUp<CatalogDatabase>() {
- @Mock
- public VnfResource getVnfResourceByModelUuid(String modelUuid) {
- VnfResource vnfResource = new VnfResource();
- vnfResource.setAicVersionMin("1");
- vnfResource.setAicVersionMax("2");
- return vnfResource;
- }
- };
-
MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();
MsoRequest msoRequest = new MsoRequest();
msoRequest.setRequestId("12345");
@@ -130,17 +76,6 @@ public class MsoVnfAdapterImplTest { @Test
public void deleteVnfTest() {
- new MockUp<MsoHeatUtils>() {
- @Mock
- public Map<String, Object> queryStackForOutputs(String cloudSiteId, String tenantId, String stackName)
- throws MsoException {
-
- Map<String, Object> outputs = new HashMap<>();
- outputs.put("Key1", "value1");
- return outputs;
- }
- };
-
MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();
MsoRequest msoRequest = new MsoRequest();
msoRequest.setRequestId("12345");
diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java index 315db2eb83..f6e79e12a0 100644 --- a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java +++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/test/QueryTest.java @@ -21,26 +21,23 @@ package org.openecomp.mso.adapters.vnf.test; -import java.util.Map; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.util.Map; import javax.xml.ws.Holder; - import mockit.Mock; import mockit.MockUp; import org.junit.Test; import org.openecomp.mso.adapters.vnf.MsoVnfAdapter; import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl; +import org.openecomp.mso.adapters.vnf.exceptions.VnfException; import org.openecomp.mso.openstack.beans.HeatStatus; import org.openecomp.mso.openstack.beans.StackInfo; import org.openecomp.mso.openstack.beans.VnfStatus; -import org.openecomp.mso.adapters.vnf.exceptions.VnfException; -import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; import org.openecomp.mso.openstack.exceptions.MsoException; import org.openecomp.mso.openstack.utils.MsoHeatUtils; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - public class QueryTest { @Test @@ -49,8 +46,7 @@ public class QueryTest { new MockUp<MsoHeatUtils>() { @Mock public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException { - StackInfo info = new StackInfo(); - info.setStatus(HeatStatus.CREATED); + StackInfo info = new StackInfo("stackName", HeatStatus.CREATED); return info; } }; @@ -77,8 +73,7 @@ public class QueryTest { new MockUp<MsoHeatUtils>() { @Mock public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException { - StackInfo info = new StackInfo(); - info.setStatus(HeatStatus.NOTFOUND); + StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND); return info; } }; @@ -102,13 +97,6 @@ public class QueryTest { @Test(expected = VnfException.class) public void testQueryVnfWithException() throws VnfException { { - new MockUp<MsoHeatUtils>() { - @Mock - public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException { - throw new MsoCloudSiteNotFound(cloudSiteId); - } - }; - MsoVnfAdapter vnfAdapter = new MsoVnfAdapterImpl(); String cloudId = "MT"; String tenantId = "MSO_Test"; diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DecomposeService.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DecomposeService.groovy index 06cc284620..2645ea3c02 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DecomposeService.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/DecomposeService.groovy @@ -17,7 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.openecomp.mso.bpmn.common.scripts; +package org.openecomp.mso.bpmn.common.scripts + +import org.openecomp.mso.bpmn.core.json.DecomposeJsonUtil; import static org.apache.commons.lang3.StringUtils.*; @@ -96,12 +98,12 @@ public class DecomposeService extends AbstractServiceTaskProcessor { // check for input String serviceModelInvariantId = execution.getVariable("DDS_serviceModelInvariantId") String modelVersion = execution.getVariable("DDS_modelVersion") - + utils.log("DEBUG", "serviceModelInvariantId: " + serviceModelInvariantId, isDebugEnabled) - utils.log("DEBUG", "modelVersion: " + modelVersion, isDebugEnabled) - + utils.log("DEBUG", "modelVersion: " + modelVersion, isDebugEnabled) + JSONObject catalogDbResponse = null - + if (modelVersion != null && modelVersion.length() > 0) catalogDbResponse = catalogDbUtils.getServiceResourcesByServiceModelInvariantUuidAndServiceModelVersion(execution, serviceModelInvariantId, modelVersion, "v2") else @@ -140,7 +142,7 @@ public class DecomposeService extends AbstractServiceTaskProcessor { utils.log("DEBUG", "getting service decomposition", isDebugEnabled) String catalogDbResponse = execution.getVariable("DDS_catalogDbResponse") - ServiceDecomposition serviceDecomposition = new ServiceDecomposition(catalogDbResponse, serviceInstanceId) + ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.jsonToServiceDecomposition(catalogDbResponse, serviceInstanceId) execution.setVariable("serviceDecomposition", serviceDecomposition) execution.setVariable("serviceDecompositionString", serviceDecomposition.toJsonString()) diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java index 1e68c84878..0e985cc8f1 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/domain/ServiceDecomposition.java @@ -31,9 +31,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
-import org.json.JSONObject;
import org.openecomp.mso.bpmn.core.json.DecomposeJsonUtil;
-
+import org.openecomp.mso.bpmn.core.json.JsonDecomposingException;
/**
@@ -50,7 +49,6 @@ import org.openecomp.mso.bpmn.core.json.DecomposeJsonUtil; public class ServiceDecomposition extends JsonWrapper implements Serializable {
private static final long serialVersionUID = 1L;
- DecomposeJsonUtil jsonUtils = new DecomposeJsonUtil();
@JsonProperty("modelInfo")
private ModelInfo modelInfo;
@@ -67,48 +65,6 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { private List <AllottedResource> allottedResources;
public ServiceDecomposition () {
- super();
- }
-
- public ServiceDecomposition (String catalogRestOutput) {
-
- ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.JsonToServiceDecomposition(catalogRestOutput);
- this.modelInfo = serviceDecomposition.getModelInfo();
- this.vnfResources = serviceDecomposition.getServiceVnfs();
- this.allottedResources = serviceDecomposition.getServiceAllottedResources();
- this.networkResources = serviceDecomposition.getServiceNetworks();
- this.serviceRole = serviceDecomposition.getServiceRole();
- this.serviceType = serviceDecomposition.getServiceType();
- }
-
- /**
- * Constructor taking Catalog DB Adapter REST output (serviceResources model) + service Instance ID
- * @param catalogRestOutput
- * @param serviceInstanceId
- */
- public ServiceDecomposition (String catalogRestOutput, String serviceInstanceId) {
-
- ServiceDecomposition serviceDecomposition = DecomposeJsonUtil.JsonToServiceDecomposition(catalogRestOutput);
- this.modelInfo = serviceDecomposition.getModelInfo();
- this.vnfResources = serviceDecomposition.getServiceVnfs();
- this.allottedResources = serviceDecomposition.getServiceAllottedResources();
- this.networkResources = serviceDecomposition.getServiceNetworks();
-
- this.serviceRole = serviceDecomposition.getServiceRole();
- this.serviceType = serviceDecomposition.getServiceType();
-
- this.serviceInstance = new ServiceInstance();
- this.serviceInstance.setInstanceId(serviceInstanceId);
- }
-
- /**
- * Constructor taking a Service Decomposition JSON serialization
- * @param catalogRestOutput
- * @param serviceInstanceId
- */
- public ServiceDecomposition (JSONObject jsonServiceDecomposition, String serviceInstanceId) {
- //TODO provide constructor implementation
-
}
//*****
@@ -278,7 +234,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { * Add resource to the list
* Given a ResourceDecomposition (subclass) object, add it to the Service Decomposition (in the appropriate category, e.g. as a VNF, Network, or Allotted Resource).
* As dependencies are not currently supported, add it to the end of any ordered lists.
- * @param Resource
+ * @param resource
*/
public void addResource(Resource resource) {
//create resource based upon type
@@ -299,36 +255,36 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /**
* Add resource to the list
- * @param Resource
+ * @param jsonResource
*/
- public void addVnfResource(String jsonResource) {
+ public void addVnfResource(String jsonResource) throws JsonDecomposingException {
VnfResource vnfResource = null;
- vnfResource = DecomposeJsonUtil.JsonToVnfResource(jsonResource);
+ vnfResource = DecomposeJsonUtil.jsonToVnfResource(jsonResource);
this.addVnfResource(vnfResource);
}
/**
* Add resource to the list
- * @param Resource
+ * @param jsonResource
*/
- public void addNetworkResource(String jsonResource) {
+ public void addNetworkResource(String jsonResource) throws JsonDecomposingException {
NetworkResource networkResource = null;
- networkResource = DecomposeJsonUtil.JsonToNetworkResource(jsonResource);
+ networkResource = DecomposeJsonUtil.jsonToNetworkResource(jsonResource);
this.addVnfResource(networkResource);
}
/**
* Add resource to the list
- * @param Resource
+ * @param jsonResource
*/
- public void addAllottedResource(String jsonResource) {
+ public void addAllottedResource(String jsonResource) throws JsonDecomposingException {
AllottedResource allottedResource = null;
- allottedResource = DecomposeJsonUtil.JsonToAllottedResource(jsonResource);
+ allottedResource = DecomposeJsonUtil.jsonToAllottedResource(jsonResource);
this.addVnfResource(allottedResource);
}
/**
* Given a ResourceDecomposition (subclass) object, locate it in the Service Decomposition by its unique ID, and replace the current version with the new one.
* This method should support concurrency control via an auto-incrementing field in the ResourceDecomposition class.
- * @param Resource
+ * @param newResource
* @return TRUE if replacement was a success
*/
public boolean replaceResource(Resource newResource){
@@ -365,7 +321,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /**
* Given a resource object ID, locate it in the Service Decomposition by its unique ID, and delete it.
- * @param Resource
+ * @param resource
* @return TRUE if delete was a success
*/
public boolean deleteResource(Resource resource){
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java index 71ef09ce33..dcd9e3b39a 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/DecomposeJsonUtil.java @@ -20,139 +20,102 @@ package org.openecomp.mso.bpmn.core.json;
-import java.io.Serializable;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
-
-
import org.openecomp.mso.bpmn.core.domain.AllottedResource;
import org.openecomp.mso.bpmn.core.domain.NetworkResource;
import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;
+import org.openecomp.mso.bpmn.core.domain.ServiceInstance;
import org.openecomp.mso.bpmn.core.domain.VnfResource;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+public class DecomposeJsonUtil {
-import org.openecomp.mso.logger.MsoLogger;
+ private static final ObjectMapper OBJECT_MAPPER = createObjectMapper();
-public class DecomposeJsonUtil implements Serializable {
- private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
- /**
- *
- */
- private static final long serialVersionUID = 1L;
+ private DecomposeJsonUtil() {
+ }
- /**
- * Method to construct Service Decomposition object converting
- * JSON structure
- *
- * @param jsonString - input in JSON format confirming ServiceDecomposition
- * @return - ServiceDecomposition object
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
- */
- public static ServiceDecomposition JsonToServiceDecomposition(String jsonString) {
-
- ServiceDecomposition serviceDecomposition = new ServiceDecomposition();
- ObjectMapper om = new ObjectMapper();
- om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
-
- try {
- serviceDecomposition = om.readValue(jsonString, ServiceDecomposition.class);
- } catch (JsonParseException e) {
- LOGGER.debug("JsonParseException :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("JsonMappingException :",e);
- } catch (IOException e) {
- LOGGER.debug("IOException :",e);
- }
-
- return serviceDecomposition;
- }
-
- /**
- * Method to construct Resource Decomposition object converting
- * JSON structure
- *
- * @param jsonString - input in JSON format confirming ResourceDecomposition
- * @return - ServiceDecomposition object
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
- */
- public static VnfResource JsonToVnfResource(String jsonString) {
-
- VnfResource vnfResource = new VnfResource();
+ private static ObjectMapper createObjectMapper() {
ObjectMapper om = new ObjectMapper();
om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
-
- try {
- vnfResource = om.readValue(jsonString, VnfResource.class);
- } catch (JsonParseException e) {
- LOGGER.debug("JsonParseException :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("JsonMappingException :",e);
- } catch (IOException e) {
- LOGGER.debug("IOException :",e);
- }
- return vnfResource;
- }
-
- /**
- * Method to construct Resource Decomposition object converting
- * JSON structure
- *
- * @param jsonString - input in JSON format confirming ResourceDecomposition
- * @return - ServiceDecomposition object
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
- */
- public static NetworkResource JsonToNetworkResource(String jsonString) {
-
- NetworkResource networkResource = new NetworkResource();
- ObjectMapper om = new ObjectMapper();
- om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
-
- try {
- networkResource = om.readValue(jsonString, NetworkResource.class);
- } catch (JsonParseException e) {
- LOGGER.debug("Exception :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("Exception :",e);
- } catch (IOException e) {
- LOGGER.debug("Exception :",e);
- }
- return networkResource;
- }
-
- /**
- * Method to construct Resource Decomposition object converting
- * JSON structure
- *
- * @param jsonString - input in JSON format confirming ResourceDecomposition
- * @return - ServiceDecomposition object
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
- */
- public static AllottedResource JsonToAllottedResource(String jsonString) {
-
- AllottedResource allottedResource = new AllottedResource();
- ObjectMapper om = new ObjectMapper();
- om.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
-
- try {
- allottedResource = om.readValue(jsonString, AllottedResource.class);
- } catch (JsonParseException e) {
- LOGGER.debug("Exception :",e);
- } catch (JsonMappingException e) {
- LOGGER.debug("Exception :",e);
- } catch (IOException e) {
- LOGGER.debug("Exception :",e);
- }
- return allottedResource;
- }
+ return om;
+ }
+
+ /**
+ * Method to construct Service Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ServiceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static ServiceDecomposition jsonToServiceDecomposition(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, ServiceDecomposition.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to service decomposition", e);
+ }
+ }
+
+ /**
+ * Method to construct Service Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ServiceDecomposition
+ * @param serviceInstanceId service instance id to be put in decoded ServiceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static ServiceDecomposition jsonToServiceDecomposition(String jsonString, String serviceInstanceId)
+ throws JsonDecomposingException {
+ ServiceDecomposition serviceDecomposition = jsonToServiceDecomposition(jsonString);
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setInstanceId(serviceInstanceId);
+ serviceDecomposition.setServiceInstance(serviceInstance);
+ return serviceDecomposition;
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ResourceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static VnfResource jsonToVnfResource(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, VnfResource.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to vnf resource", e);
+ }
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting JSON structure
+ *
+ * @param jsonString input in JSON format confirming ResourceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static NetworkResource jsonToNetworkResource(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, NetworkResource.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to network resource", e);
+ }
+ }
+
+ /**
+ * Method to construct Resource Decomposition object converting JSON structure
+ *
+ * @param jsonString - input in JSON format confirming ResourceDecomposition
+ * @return decoded object
+ * @throws JsonDecomposingException thrown when decoding json fails
+ */
+ public static AllottedResource jsonToAllottedResource(String jsonString) throws JsonDecomposingException {
+ try {
+ return OBJECT_MAPPER.readValue(jsonString, AllottedResource.class);
+ } catch (IOException e) {
+ throw new JsonDecomposingException("Exception while converting json to allotted resource", e);
+ }
+ }
}
\ No newline at end of file diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java new file mode 100644 index 0000000000..352979e7dd --- /dev/null +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/json/JsonDecomposingException.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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.openecomp.mso.bpmn.core.json; + +import java.io.IOException; + +public class JsonDecomposingException extends IOException { + + public JsonDecomposingException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy index 862c46ad19..308834038e 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy +++ b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/DoCreateVnfAndModules.groovy @@ -54,7 +54,6 @@ class DoCreateVnfAndModules extends AbstractServiceTaskProcessor { JsonUtils jsonUtil = new JsonUtils() VidUtils vidUtils = new VidUtils(this) CatalogDbUtils cutils = new CatalogDbUtils() - DecomposeJsonUtil decomposeJsonUtil = new DecomposeJsonUtil() /** * This method gets and validates the incoming @@ -185,7 +184,7 @@ class DoCreateVnfAndModules extends AbstractServiceTaskProcessor { utils.log("DEBUG", "obtained VNF list") // Only one match here JSONObject vnfObject = vnfs[0] - vnf = decomposeJsonUtil.JsonToVnfResource(vnfObject.toString()) + vnf = DecomposeJsonUtil.jsonToVnfResource(vnfObject.toString()) } utils.log("DEBUG", "Read vnfResource", isDebugLogEnabled) if (vnf == null) { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java index 2f32e80dc1..d60915bf43 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/OrchestrationRequests.java @@ -160,7 +160,7 @@ public class OrchestrationRequests { orchestrationList = new GetOrchestrationListResponse(); - List<RequestList> requestLists = new ArrayList<RequestList>(); + List<RequestList> requestLists = new ArrayList<>(); for (InfraActiveRequests infraActive : activeRequests) { |