Search in sources :

Example 1 with DeploymentStatus

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);
}
Also used : DeploymentStatus(alien4cloud.paas.model.DeploymentStatus)

Example 2 with DeploymentStatus

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);
    }
}
Also used : Map(java.util.Map) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) MaintenanceModeException(alien4cloud.paas.exception.MaintenanceModeException) OperationExecutionException(alien4cloud.paas.exception.OperationExecutionException) YorcRestException(org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException)

Example 3 with DeploymentStatus

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;
}
Also used : DeployInfosResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.DeployInfosResponse) InstanceInformation(alien4cloud.paas.model.InstanceInformation) NodeInfosResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.NodeInfosResponse) AttributeResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.AttributeResponse) InstanceInfosResponse(org.ystia.yorc.alien4cloud.plugin.rest.Response.InstanceInfosResponse) Map(java.util.Map) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) Link(org.ystia.yorc.alien4cloud.plugin.rest.Response.Link)

Example 4 with DeploymentStatus

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();
    }
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) PaaSAlreadyDeployedException(alien4cloud.paas.exception.PaaSAlreadyDeployedException) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) IllegalDeploymentStateException(alien4cloud.paas.exception.IllegalDeploymentStateException) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus)

Example 5 with DeploymentStatus

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();
    }
}
Also used : PaaSNotYetDeployedException(alien4cloud.paas.exception.PaaSNotYetDeployedException) IllegalDeploymentStateException(alien4cloud.paas.exception.IllegalDeploymentStateException) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus)

Aggregations

DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)14 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 MaintenanceModeException (alien4cloud.paas.exception.MaintenanceModeException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Map (java.util.Map)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2 Application (alien4cloud.model.application.Application)2 Deployment (alien4cloud.model.deployment.Deployment)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 IllegalDeploymentStateException (alien4cloud.paas.exception.IllegalDeploymentStateException)2 OperationExecutionException (alien4cloud.paas.exception.OperationExecutionException)2 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)2 PluginConfigurationException (alien4cloud.paas.exception.PluginConfigurationException)2 PaaSDeploymentStatusMonitorEvent (alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 YorcRestException (org.ystia.yorc.alien4cloud.plugin.rest.YorcRestException)2 NotFoundException (alien4cloud.exception.NotFoundException)1 ITException (alien4cloud.it.exception.ITException)1 ServiceResource (alien4cloud.model.service.ServiceResource)1