use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class MsoHeatUtils method queryStackForOutputs.
// TODO enhancement - just have this return the stack then we dont have to query again in deleteStack
public Map<String, Object> queryStackForOutputs(String cloudSiteId, String cloudOwner, String tenantId, String stackName) throws MsoException {
logger.debug("MsoHeatUtils.queryStackForOutputs)");
StackInfo heatStack = this.queryStack(cloudSiteId, cloudOwner, tenantId, stackName);
if (heatStack == null || heatStack.getStatus() == HeatStatus.NOTFOUND) {
return null;
}
return heatStack.getOutputs();
}
use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class MsoHeatUtils method deleteVdu.
/**
* VduPlugin interface for delete function.
*/
@Override
public VduInstance deleteVdu(CloudInfo cloudInfo, String instanceId, int timeoutMinutes) throws VduException {
String cloudSiteId = cloudInfo.getCloudSiteId();
String cloudOwner = cloudInfo.getCloudOwner();
String tenantId = cloudInfo.getTenantId();
try {
// Delete the Heat stack
StackInfo stackInfo = deleteStack(tenantId, cloudOwner, cloudSiteId, instanceId, true, timeoutMinutes);
// Populate a VduInstance based on the deleted Cloudify Deployment object
VduInstance vduInstance = stackInfoToVduInstance(stackInfo);
// Override return state to DELETED (HeatUtils sets to NOTFOUND)
vduInstance.getStatus().setState(VduStateType.DELETED);
return vduInstance;
} catch (Exception e) {
throw new VduException("Delete VDU Exception", e);
}
}
use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class MsoHeatUtils method queryStack.
/**
* Query for a single stack (by Name) in a tenant. This call will always return a StackInfo object. If the stack
* does not exist, an "empty" StackInfo will be returned - containing only the stack name and a status of NOTFOUND.
*
* @param tenantId The Openstack ID of the tenant in which to query
* @param cloudSiteId The cloud identifier (may be a region) in which to query
* @param cloudOwner the cloud owner of the cloud site in which to query
* @param stackName The name of the stack to query (may be simple or canonical)
* @return A StackInfo object
* @throws MsoOpenstackException Thrown if the Openstack API call returns an exception.
*/
public StackInfo queryStack(String cloudSiteId, String cloudOwner, String tenantId, String stackName) throws MsoException {
logger.debug("Query HEAT stack: {} in tenant {}", stackName, tenantId);
Heat heatClient = null;
try {
heatClient = getHeatClient(cloudSiteId, tenantId);
} 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);
} catch (MsoException me) {
// Got an Openstack error. Propagate it
logger.error("{} {} Openstack Exception on Token request: ", MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.AvailabilityError.getValue(), me);
me.addContext("QueryStack");
throw me;
}
// Query the Stack.
// An MsoException will propagate transparently to the caller.
Stack heatStack = queryHeatStack(heatClient, stackName);
if (heatStack == null) {
// Stack does not exist. Return a StackInfo with status NOTFOUND
return new StackInfo(stackName, HeatStatus.NOTFOUND);
}
return new StackInfoMapper(heatStack).map();
}
use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class MsoHeatUtils method deleteStack.
/**
* Delete a stack (by Name/ID) in a tenant. If the stack is not found, it will be considered a successful deletion.
* The return value is a StackInfo object which contains the current stack status.
*
* The client may choose to let the adapter poll Openstack for completion of the stack deletion, or may handle
* polling itself via separate query calls. In either case, a StackInfo object will be returned. When polling is
* enabled, a final status of NOTFOUND is expected. When not polling, a status of DELETING is expected.
*
* There is no rollback from a successful stack deletion. A deletion failure will also result in an undefined stack
* state - the components may or may not have been all or partially deleted, so the resulting stack must be
* considered invalid.
*
* @param tenantId The Openstack ID of the tenant in which to perform the delete
* @param cloudOwner the cloud owner of the cloud site in which to delete the stack
* @param cloudSiteId The cloud identifier (may be a region) from which to delete the stack.
* @param stackName The name/id of the stack to delete. May be simple or canonical
* @param pollForCompletion Indicator that polling should be handled in Java vs. in the client
* @return A StackInfo object
* @throws MsoOpenstackException Thrown if the Openstack API call returns an exception.
* @throws MsoCloudSiteNotFound
*/
public StackInfo deleteStack(String tenantId, String cloudOwner, String cloudSiteId, String stackName, boolean pollForCompletion, int timeoutMinutes) throws MsoException {
Stack currentStack = queryHeatStack(stackName, cloudSiteId, tenantId);
StackInfo stackInfo = null;
if (currentStack == null || DELETE_COMPLETE.equals(currentStack.getStackStatus())) {
stackInfo = new StackInfo(stackName, HeatStatus.NOTFOUND);
stackInfo.setOperationPerformed(false);
} else {
currentStack = deleteStack(currentStack, timeoutMinutes, cloudSiteId, tenantId, pollForCompletion);
stackInfo = new StackInfoMapper(currentStack).map();
stackInfo.setName(stackName);
stackInfo.setOperationPerformed(true);
if (currentStack != null) {
stackInfo.setCanonicalName(currentStack.getStackName() + "/" + currentStack.getId());
}
}
return stackInfo;
}
use of org.onap.so.openstack.beans.StackInfo in project so by onap.
the class StackInfoMapperTest method checkOutputToMap.
@Test
public void checkOutputToMap() throws JsonParseException, JsonMappingException, IOException {
ObjectMapper jacksonMapper = new ObjectMapper();
Stack sample = jacksonMapper.readValue(this.getJson("stack-example.json"), Stack.class);
StackInfoMapper mapper = new StackInfoMapper(sample);
StackInfo result = mapper.map();
Map<String, Object> map = result.getOutputs();
assertEquals(true, map.containsKey("key2"));
assertEquals("value1", map.get("key1"));
}
Aggregations