* 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.
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;
- }
-
+
}
} 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");
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;
}
} 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");
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.
} 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);
}
// 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)
\r
import static org.junit.Assert.assertTrue;\r
\r
-import com.woorea.openstack.heat.model.Stack;\r
import java.util.ArrayList;\r
import java.util.HashMap;\r
import java.util.List;\r
import java.util.Map;\r
import org.junit.Test;\r
import org.openecomp.mso.entity.MsoRequest;\r
-import org.openecomp.mso.openstack.beans.HeatStatus;\r
import org.openecomp.mso.openstack.beans.MsoTenant;\r
import org.openecomp.mso.openstack.beans.NetworkRollback;\r
import org.openecomp.mso.openstack.beans.Pool;\r
-import org.openecomp.mso.openstack.beans.StackInfo;\r
import org.openecomp.mso.openstack.beans.Subnet;\r
import org.openecomp.mso.openstack.beans.VnfRollback;\r
\r
p.toString();\r
}\r
\r
- @Test\r
- public final void stackInfoTest() {\r
- StackInfo stackInfo = new StackInfo();\r
- new StackInfo(new Stack());\r
- new StackInfo("name", HeatStatus.CREATED, "statusmessage", new HashMap<>());\r
- new StackInfo("name", HeatStatus.CREATED);\r
- stackInfo.setCanonicalName("Canonicalname");\r
- stackInfo.getCanonicalName();\r
- stackInfo.setName("name");\r
- stackInfo.getName();\r
- stackInfo.setOutputs(new HashMap<>());\r
- stackInfo.getOutputs();\r
- stackInfo.setParameters(new HashMap<>());\r
- stackInfo.getParameters();\r
- stackInfo.setStatus(HeatStatus.CREATED);\r
- stackInfo.getStatus();\r
- stackInfo.setStatusMessage("statusMessage");\r
- stackInfo.getStatusMessage();\r
- }\r
-\r
@Test\r
public final void subnetTest() {\r
Subnet subnet = new Subnet();\r
--- /dev/null
+/*-
+ * ============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;
+ }
+
+}
\r
import java.util.HashMap;\r
import java.util.Map;\r
-\r
import org.junit.Test;\r
import org.openecomp.mso.adapters.vnf.MsoVnfAdapterAsyncImpl;\r
import org.openecomp.mso.entity.MsoRequest;\r
-import org.openecomp.mso.openstack.beans.HeatStatus;\r
-import org.openecomp.mso.openstack.beans.StackInfo;\r
import org.openecomp.mso.openstack.beans.VnfRollback;\r
-import org.openecomp.mso.openstack.exceptions.MsoException;\r
-import org.openecomp.mso.openstack.utils.MsoHeatUtils;\r
-\r
-import mockit.Mock;\r
-import mockit.MockUp;\r
\r
public class MsoVnfAdapterAsyncImplTest {\r
\r
\r
@Test\r
public void createVNFTest() {\r
- new MockUp<MsoHeatUtils>() {\r
- @Mock\r
- public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {\r
- StackInfo info = new StackInfo();\r
- info.setStatus(HeatStatus.CREATED);\r
- return info;\r
- }\r
- };\r
-\r
MsoVnfAdapterAsyncImpl instance = new MsoVnfAdapterAsyncImpl();\r
MsoRequest msoRequest = new MsoRequest();\r
msoRequest.setRequestId("12345");\r
\r
import java.util.HashMap;\r
import java.util.Map;\r
-\r
import javax.xml.ws.Holder;\r
-\r
import org.junit.Test;\r
import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl;\r
-import org.openecomp.mso.db.catalog.CatalogDatabase;\r
-import org.openecomp.mso.db.catalog.beans.VfModule;\r
-import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;\r
-import org.openecomp.mso.db.catalog.beans.VnfResource;\r
import org.openecomp.mso.entity.MsoRequest;\r
-import org.openecomp.mso.openstack.beans.HeatStatus;\r
-import org.openecomp.mso.openstack.beans.StackInfo;\r
import org.openecomp.mso.openstack.beans.VnfRollback;\r
-import org.openecomp.mso.openstack.exceptions.MsoException;\r
-import org.openecomp.mso.openstack.utils.MsoHeatUtils;\r
-\r
-import mockit.Mock;\r
-import mockit.MockUp;\r
\r
public class MsoVnfAdapterImplTest {\r
\r
\r
@Test\r
public void createVnfTest() {\r
-\r
- new MockUp<MsoHeatUtils>() {\r
- @Mock\r
- public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {\r
- StackInfo info = new StackInfo();\r
- info.setStatus(HeatStatus.CREATED);\r
- return info;\r
- }\r
- };\r
-\r
MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();\r
MsoRequest msoRequest = new MsoRequest();\r
msoRequest.setRequestId("12345");\r
\r
@Test\r
public void updateVnfTest() {\r
-\r
- new MockUp<MsoHeatUtils>() {\r
- @Mock\r
- public StackInfo queryStack(String cloudSiteId, String tenantId, String stackName) throws MsoException {\r
- StackInfo info = new StackInfo();\r
- info.setStatus(HeatStatus.CREATED);\r
- return info;\r
- }\r
- };\r
-\r
- new MockUp<CatalogDatabase>() {\r
- @Mock\r
- public VfModuleCustomization getVfModuleCustomizationByModelCustomizationId(String modelCustomizationUuid) {\r
- VfModuleCustomization vfcModule = new VfModuleCustomization();\r
- VfModule vfm = new VfModule();\r
- vfm.setVnfResourceModelUUId("88a6ca3ee0394ade9403f075db23167e");\r
- vfcModule.setVfModule(vfm);\r
- return vfcModule;\r
- }\r
- };\r
-\r
- new MockUp<CatalogDatabase>() {\r
- @Mock\r
- public VnfResource getVnfResourceByModelUuid(String modelUuid) {\r
- VnfResource vnfResource = new VnfResource();\r
- vnfResource.setAicVersionMin("1");\r
- vnfResource.setAicVersionMax("2");\r
- return vnfResource;\r
- }\r
- };\r
-\r
MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();\r
MsoRequest msoRequest = new MsoRequest();\r
msoRequest.setRequestId("12345");\r
\r
@Test\r
public void deleteVnfTest() {\r
- new MockUp<MsoHeatUtils>() {\r
- @Mock\r
- public Map<String, Object> queryStackForOutputs(String cloudSiteId, String tenantId, String stackName)\r
- throws MsoException {\r
- \r
- Map<String, Object> outputs = new HashMap<>();\r
- outputs.put("Key1", "value1");\r
- return outputs;\r
- }\r
- };\r
-\r
MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();\r
MsoRequest msoRequest = new MsoRequest();\r
msoRequest.setRequestId("12345");\r
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
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;
}
};
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;
}
};
@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";