use of alien4cloud.paas.model.DeploymentStatus in project yorc-a4c-plugin by ystia.
the class YorcPaaSProvider method getStatus.
/**
* Get status of a deployment
*
* @param ctx the deployment context
* @param callback callback when the status is available
*/
@Override
public void getStatus(PaaSDeploymentContext ctx, IPaaSCallback<DeploymentStatus> callback) {
DeploymentStatus status;
String paasId = ctx.getDeploymentPaaSId();
YorcRuntimeDeploymentInfo jrdi = runtimeDeploymentInfos.get(paasId);
if (jrdi == null) {
status = DeploymentStatus.UNDEPLOYED;
} else {
status = jrdi.getStatus();
}
callback.onSuccess(status);
}
use of alien4cloud.paas.model.DeploymentStatus in project yorc-a4c-plugin by ystia.
the class YorcPaaSProvider method doUpdateDeploymentInfo.
/**
* Update Deployment Info from Yorc information
* Called at init, for each active deployment.
* @param ctx
*/
protected void doUpdateDeploymentInfo(PaaSTopologyDeploymentContext ctx) {
String paasId = ctx.getDeploymentPaaSId();
a4cDeploymentIds.put(paasId, ctx.getDeploymentId());
String deploymentUrl = "/deployments/" + paasId;
log.debug("update deployment info " + paasId);
// Create the YorcRuntimeDeploymentInfo for this deployment
Map<String, Map<String, InstanceInformation>> nodemap = Maps.newHashMap();
YorcRuntimeDeploymentInfo jrdi = new YorcRuntimeDeploymentInfo(ctx, DeploymentStatus.UNKNOWN, nodemap, deploymentUrl);
runtimeDeploymentInfos.put(paasId, jrdi);
DeploymentStatus ds = null;
try {
ds = updateNodeInfo(ctx);
} catch (Exception e) {
log.error(paasId + " : Cannot update DeploymentInfo ", e);
}
}
use of alien4cloud.paas.model.DeploymentStatus in project yorc-a4c-plugin by ystia.
the class YorcPaaSProvider method updateNodeInfo.
/**
* Update nodeInformation in the YorcRuntimeDeploymentInfo
* This is needed to let a4c know all about the nodes and their instances
* Information is got from Yorc using the REST API
*
* @param ctx PaaSDeploymentContext to be updated
* @return deployment status
*
* @throws
*/
private DeploymentStatus updateNodeInfo(PaaSDeploymentContext ctx) throws Exception {
String paasId = ctx.getDeploymentPaaSId();
String deploymentUrl = "/deployments/" + paasId;
log.debug("updateNodeInfo " + paasId);
// Assumes YorcRuntimeDeploymentInfo already created.
YorcRuntimeDeploymentInfo jrdi = runtimeDeploymentInfos.get(paasId);
if (jrdi == null) {
log.error("No YorcRuntimeDeploymentInfo");
return DeploymentStatus.FAILURE;
}
// Find the deployment info from Yorc
DeployInfosResponse deployRes = restClient.getDeploymentInfosFromYorc(deploymentUrl);
DeploymentStatus ds = getDeploymentStatusFromString(deployRes.getStatus());
jrdi.setStatus(ds);
Map<String, Map<String, InstanceInformation>> nodemap = jrdi.getInstanceInformations();
// Look every node we want to update.
for (Link nodeLink : deployRes.getLinks()) {
if (nodeLink.getRel().equals("node")) {
// Find the node info from Yorc
NodeInfosResponse nodeRes = restClient.getNodesInfosFromYorc(nodeLink.getHref());
String node = nodeRes.getName();
Map<String, InstanceInformation> instanceMap = nodemap.get(node);
if (instanceMap == null) {
// This node was unknown. Create it.
instanceMap = Maps.newHashMap();
nodemap.put(node, instanceMap);
}
// Find information about all the node instances from Yorc
for (Link instanceLink : nodeRes.getLinks()) {
if (instanceLink.getRel().equals("instance")) {
// Find the instance info from Yorc
InstanceInfosResponse instRes = restClient.getInstanceInfosFromYorc(instanceLink.getHref());
String inb = instRes.getId();
InstanceInformation iinfo = instanceMap.get(inb);
if (iinfo == null) {
// This instance was unknown. create it.
iinfo = newInstance(new Integer(inb));
instanceMap.put(inb, iinfo);
}
for (Link link : instRes.getLinks()) {
if (link.getRel().equals("attribute")) {
// Get the attribute from Yorc
AttributeResponse attrRes = restClient.getAttributeFromYorc(link.getHref());
iinfo.getAttributes().put(attrRes.getName(), attrRes.getValue());
log.debug("Attribute: " + attrRes.getName() + "=" + attrRes.getValue());
}
}
// Let a4c know the instance state
updateInstanceState(paasId, node, inb, iinfo, instRes.getStatus());
}
}
}
}
return ds;
}
use of alien4cloud.paas.model.DeploymentStatus in project alien4cloud by alien4cloud.
the class AbstractPaaSProvider method deploy.
@Override
public void deploy(PaaSTopologyDeploymentContext deploymentContext, IPaaSCallback<?> callback) {
String deploymentId = deploymentContext.getDeploymentPaaSId();
DeploymentTopology deploymentTopology = deploymentContext.getDeploymentTopology();
String yaml = archiveExportService.getYaml(new Csar(deploymentTopology.getArchiveName(), deploymentTopology.getArchiveVersion()), deploymentTopology, false, ToscaParser.LATEST_DSL);
log.info("Attempting to deploy the following topology: " + yaml);
try {
providerLock.writeLock().lock();
if (deploymentTopology.getProviderDeploymentProperties() != null) {
// i.e : use / handle plugin deployment properties
log.info("Topology deployment [" + deploymentTopology.getId() + "] for application [" + deploymentContext.getDeployment().getSourceName() + "]" + " and [" + deploymentTopology.getProviderDeploymentProperties().size() + "]Â deployment properties");
log.info(deploymentTopology.getProviderDeploymentProperties().keySet().toString());
for (String property : deploymentTopology.getProviderDeploymentProperties().keySet()) {
log.info(property);
if (deploymentTopology.getProviderDeploymentProperties().get(property) != null) {
log.info("[Â " + property + " : " + deploymentTopology.getProviderDeploymentProperties().get(property) + "]");
}
}
}
DeploymentStatus deploymentStatus = getStatus(deploymentId, false);
switch(deploymentStatus) {
case DEPLOYED:
case DEPLOYMENT_IN_PROGRESS:
case UNDEPLOYMENT_IN_PROGRESS:
case WARNING:
case FAILURE:
throw new PaaSAlreadyDeployedException("Topology [" + deploymentId + "] is in status [" + deploymentStatus + "] and cannot be deployed");
case UNKNOWN:
throw new IllegalDeploymentStateException("Topology [" + deploymentId + "] is in status [" + deploymentStatus + "] and cannot be deployed");
case UNDEPLOYED:
doDeploy(deploymentContext);
break;
default:
throw new IllegalDeploymentStateException("Topology [" + deploymentId + "] is in illegal status [" + deploymentStatus + "] and cannot be deployed");
}
} finally {
providerLock.writeLock().unlock();
}
}
use of alien4cloud.paas.model.DeploymentStatus in project alien4cloud by alien4cloud.
the class AbstractPaaSProvider method undeploy.
@Override
public void undeploy(PaaSDeploymentContext deploymentContext, IPaaSCallback<?> callback) {
String deploymentId = deploymentContext.getDeploymentPaaSId();
try {
providerLock.writeLock().lock();
DeploymentStatus deploymentStatus = getStatus(deploymentId, true);
switch(deploymentStatus) {
case UNDEPLOYMENT_IN_PROGRESS:
case UNDEPLOYED:
throw new PaaSNotYetDeployedException("Application [" + deploymentId + "] is in status [" + deploymentStatus + "] and cannot be undeployed");
case UNKNOWN:
throw new IllegalDeploymentStateException("Application [" + deploymentId + "] is in status [" + deploymentStatus + "] and cannot be undeployed");
case DEPLOYMENT_IN_PROGRESS:
case FAILURE:
case DEPLOYED:
case WARNING:
doUndeploy(deploymentContext);
callback.onSuccess(null);
break;
default:
throw new IllegalDeploymentStateException("Application [" + deploymentId + "] is in illegal status [" + deploymentStatus + "] and cannot be undeployed");
}
} finally {
providerLock.writeLock().unlock();
}
}
Aggregations