use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class MsoMulticloudUtils method instantiateVdu.
/**
* VduPlugin interface for instantiate function.
*
* Translate the VduPlugin parameters to the corresponding 'createStack' parameters, and then invoke the existing
* function.
*/
@Override
public VduInstance instantiateVdu(CloudInfo cloudInfo, String instanceName, Map<String, Object> inputs, VduModelInfo vduModel, boolean rollbackOnFailure) throws VduException {
String cloudSiteId = cloudInfo.getCloudSiteId();
String cloudOwner = cloudInfo.getCloudOwner();
String tenantId = cloudInfo.getTenantId();
// Translate the VDU ModelInformation structure to that which is needed for
// creating the Heat stack. Loop through the artifacts, looking specifically
// for MAIN_TEMPLATE and ENVIRONMENT. Any other artifact will
// be attached as a FILE.
String heatTemplate = null;
Map<String, Object> nestedTemplates = new HashMap<>();
Map<String, Object> files = new HashMap<>();
String heatEnvironment = null;
for (VduArtifact vduArtifact : vduModel.getArtifacts()) {
if (vduArtifact.getType() == ArtifactType.MAIN_TEMPLATE) {
heatTemplate = new String(vduArtifact.getContent());
} else if (vduArtifact.getType() == ArtifactType.NESTED_TEMPLATE) {
nestedTemplates.put(vduArtifact.getName(), new String(vduArtifact.getContent()));
} else if (vduArtifact.getType() == ArtifactType.ENVIRONMENT) {
heatEnvironment = new String(vduArtifact.getContent());
}
}
try {
StackInfo stackInfo = createStack(cloudSiteId, cloudOwner, tenantId, instanceName, vduModel, heatTemplate, // poll
inputs, // poll
true, // completion
vduModel.getTimeoutMinutes(), heatEnvironment, nestedTemplates, files, rollbackOnFailure, false);
// Populate a vduInstance from the StackInfo
return stackInfoToVduInstance(stackInfo);
} catch (Exception e) {
throw new VduException("MsoMulticloudUtils (instantiateVDU): createStack Exception", e);
}
}
use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class MsoMulticloudUtils method queryVdu.
/**
* VduPlugin interface for query function.
*/
@Override
public VduInstance queryVdu(CloudInfo cloudInfo, String instanceId) throws VduException {
String cloudSiteId = cloudInfo.getCloudSiteId();
String cloudOwner = cloudInfo.getCloudOwner();
String tenantId = cloudInfo.getTenantId();
try {
// Query the Cloudify Deployment object and populate a VduInstance
StackInfo stackInfo = queryStack(cloudSiteId, cloudOwner, tenantId, instanceId);
return stackInfoToVduInstance(stackInfo);
} catch (Exception e) {
throw new VduException("MsoMulticloudUtils (queryVdu): queryStack Exception ", e);
}
}
use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class MsoMulticloudUtils method deleteStack.
public StackInfo deleteStack(String cloudSiteId, String cloudOwner, String tenantId, String instanceId) throws MsoException {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Delete multicloud HEAT stack: %s in tenant %s", instanceId, tenantId));
}
String stackName = null;
String stackId = null;
int offset = instanceId.indexOf('/');
if (offset > 0 && offset < (instanceId.length() - 1)) {
stackName = instanceId.substring(0, offset);
stackId = instanceId.substring(offset + 1);
} else {
stackName = instanceId;
stackId = instanceId;
}
StackInfo returnInfo = new StackInfo();
returnInfo.setName(stackName);
Response response = null;
String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId, false);
RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId);
if (multicloudClient != null) {
response = multicloudClient.delete();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Multicloud Delete response is: %s", response.getEntity().toString()));
}
if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
returnInfo.setStatus(HeatStatus.NOTFOUND);
returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase());
} else if (response.getStatus() == Response.Status.NO_CONTENT.getStatusCode()) {
return getStackStatus(cloudSiteId, cloudOwner, tenantId, instanceId);
} else {
returnInfo.setStatus(HeatStatus.FAILED);
returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase());
}
}
returnInfo.setStatus(mapResponseToHeatStatus(response));
return returnInfo;
}
use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class StackInfoMapperTest method mapRemainingFields.
@Test
public void mapRemainingFields() {
Stack stack = new Stack();
stack.setStackName("name");
stack.setId("id");
stack.setStackStatusReason("message");
stack.setParameters(new HashMap<String, Object>());
StackInfoMapper mapper = new StackInfoMapper(stack);
StackInfo info = mapper.map();
assertEquals("name", info.getName());
assertEquals("name/id", info.getCanonicalName());
assertEquals("message", info.getStatusMessage());
assertEquals(stack.getParameters(), info.getParameters());
}
use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class MsoHeatUtilsWithUpdateTest method updateStackWithEnvironmentTest.
@Test
public void updateStackWithEnvironmentTest() throws JsonParseException, JsonMappingException, IOException, MsoException {
String environmentString = "environmentString";
CloudSite cloudSite = new CloudSite();
Heat heatClient = new Heat("endpoint");
Stack heatStack = mapper.readValue(new File(RESOURCE_PATH + "HeatStack.json"), Stack.class);
Stack updateStack = mapper.readValue(new File(RESOURCE_PATH + "UpdateStack.json"), Stack.class);
StackInfo expectedStackInfo = new StackInfo("stackName", HeatStatus.UPDATED, "stackStatusReason", null);
expectedStackInfo.setCanonicalName("stackName/id");
doReturn(heatClient).when(heatUtils).getHeatClient(isA(String.class), isA(String.class));
doReturn(null).when(heatUtils).executeAndRecordOpenstackRequest(isA(OpenStackRequest.class));
doReturn("0").when(environment).getProperty(isA(String.class), isA(String.class));
doReturn(updateStack).when(heatUtils).queryHeatStack(isA(Heat.class), isA(String.class));
StackInfo actualStackInfo = heatUtils.updateStack(cloudSiteId, cloudOwner, tenantId, stackName, heatTemplate, stackInputs, pollForCompletion, timeoutMinutes, environmentString);
assertThat(actualStackInfo, sameBeanAs(expectedStackInfo));
}
Aggregations