Search in sources :

Example 61 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method updatePolicySubstitution.

/**
 * Update policy substitution.
 *
 * @param appId id of the application.
 * @param environmentId id of the environment.
 * @return response containing the deployment topology dto {@link DeploymentTopologyDTO}.
 */
@ApiOperation(value = "Substitute a specific policy by a location policy resource template in the topology of an application, given an environment.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/policies/{policyId}/substitution", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<DeploymentTopologyDTO> updatePolicySubstitution(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String policyId, @RequestParam String locationResourceTemplateId) {
    Application application = applicationService.getOrFail(appId);
    ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
    ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
    Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
    DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> policyMatchingSubstitutionService.updateSubstitution(application, environment, topology, policyId, locationResourceTemplateId));
    return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
}
Also used : DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 62 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method updatePolicySubstitutionProperty.

@ApiOperation(value = "Update policy substitution's property.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(value = "/policies/{nodeId}/substitution/properties", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updatePolicySubstitutionProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @RequestBody UpdatePropertyRequest updateRequest) {
    try {
        Application application = applicationService.getOrFail(appId);
        ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
        AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
        ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
        Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
        DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, () -> matchedPolicyPropertiesConfigService.updateProperty(application, environment, topology, nodeId, updateRequest.getPropertyName(), updateRequest.getPropertyValue()));
        return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
    } catch (ConstraintTechnicalException e) {
        if (e.getCause() instanceof ConstraintFunctionalException) {
            return RestConstraintValidator.fromException((ConstraintFunctionalException) e.getCause(), updateRequest.getPropertyName(), updateRequest.getPropertyValue());
        }
        throw e;
    }
}
Also used : ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ConstraintTechnicalException(org.alien4cloud.tosca.exceptions.ConstraintTechnicalException) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 63 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method execute.

private DeploymentTopologyDTO execute(String applicationId, String environmentId, IDeploymentConfigAction action) {
    Application application = applicationService.getOrFail(applicationId);
    ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
    ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
    Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
    // This method prepares the deployment and create a Deployment Topology DTO object.
    return deploymentTopologyDTOBuilder.prepareDeployment(topology, application, environment, topologyVersion, action);
}
Also used : DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 64 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method getDeploymentTopology.

/**
 * Get the deployment topology of an application given an environment
 *
 * @param appId application Id
 * @param environmentId environment Id
 * @return the deployment topology DTO
 */
@ApiOperation(value = "Get the deployment topology of an application given an environment.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "", method = RequestMethod.GET)
@PreAuthorize("isAuthenticated()")
public RestResponse<DeploymentTopologyDTO> getDeploymentTopology(@PathVariable String appId, @PathVariable String environmentId) {
    Application application = applicationService.getOrFail(appId);
    ApplicationEnvironment environment = appEnvironmentService.getOrFail(environmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
    ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
    Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
    // This method prepares the deployment and create a Deployment Topology DTO object.
    DeploymentTopologyDTO dto = deploymentTopologyDTOBuilder.prepareDeployment(topology, application, environment);
    return RestResponseBuilder.<DeploymentTopologyDTO>builder().data(dto).build();
}
Also used : DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) Application(alien4cloud.model.application.Application) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 65 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class MockPaaSProvider method doDeploy.

@Override
protected synchronized void doDeploy(final PaaSTopologyDeploymentContext deploymentContext) {
    log.info("Deploying deployment [" + deploymentContext.getDeploymentPaaSId() + "]");
    paaSDeploymentIdToAlienDeploymentIdMap.put(deploymentContext.getDeploymentPaaSId(), deploymentContext.getDeploymentId());
    Topology topology = deploymentContext.getDeploymentTopology();
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    if (nodeTemplates == null) {
        nodeTemplates = Maps.newHashMap();
    }
    Map<String, Map<String, InstanceInformation>> currentInformations = Maps.newHashMap();
    for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplates.entrySet()) {
        Map<String, InstanceInformation> instanceInformations = Maps.newHashMap();
        currentInformations.put(nodeTemplateEntry.getKey(), instanceInformations);
        ScalingPolicy policy = getScalingPolicy(nodeTemplateEntry.getKey(), nodeTemplates, topology);
        int initialInstances = policy != null ? policy.getInitialInstances() : 1;
        for (int i = 1; i <= initialInstances; i++) {
            InstanceInformation newInstanceInformation = newInstance(i);
            instanceInformations.put(String.valueOf(i), newInstanceInformation);
            notifyInstanceStateChanged(deploymentContext.getDeploymentPaaSId(), nodeTemplateEntry.getKey(), String.valueOf(i), newInstanceInformation, 1);
        }
    }
    runtimeDeploymentInfos.put(deploymentContext.getDeploymentPaaSId(), new MockRuntimeDeploymentInfo(deploymentContext, DeploymentStatus.DEPLOYMENT_IN_PROGRESS, currentInformations));
    changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.DEPLOYMENT_IN_PROGRESS);
    executorService.schedule(new Runnable() {

        @Override
        public void run() {
            switch(deploymentContext.getDeployment().getSourceName()) {
                case BAD_APPLICATION_THAT_NEVER_WORKS:
                    changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.FAILURE);
                    break;
                case WARN_APPLICATION_THAT_NEVER_WORKS:
                    changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.WARNING);
                    break;
                default:
                    changeStatus(deploymentContext.getDeploymentPaaSId(), DeploymentStatus.DEPLOYED);
            }
        }
    }, 5, TimeUnit.SECONDS);
}
Also used : ScalingPolicy(org.alien4cloud.tosca.model.templates.ScalingPolicy) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Topology(org.alien4cloud.tosca.model.templates.Topology) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Map(java.util.Map)

Aggregations

Topology (org.alien4cloud.tosca.model.templates.Topology)79 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)22 Map (java.util.Map)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)17 Csar (org.alien4cloud.tosca.model.Csar)16 Application (alien4cloud.model.application.Application)15 NotFoundException (alien4cloud.exception.NotFoundException)14 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)9 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)9 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 IOException (java.io.IOException)8 List (java.util.List)8 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)8 Component (org.springframework.stereotype.Component)8 Audit (alien4cloud.audit.annotation.Audit)7