Search in sources :

Example 1 with ApplicationTopologyVersion

use of alien4cloud.model.application.ApplicationTopologyVersion in project alien4cloud by alien4cloud.

the class ApplicationVersionServiceTest method createApplicationVersion.

private ApplicationVersion createApplicationVersion() {
    String version = "1.0.0-SNAPSHOT";
    ApplicationVersion applicationVersion = new ApplicationVersion();
    applicationVersion.setApplicationId("application");
    applicationVersion.setVersion(version);
    Map<String, ApplicationTopologyVersion> topologyVersionMap = Maps.newHashMap();
    ApplicationTopologyVersion applicationTopologyVersion = new ApplicationTopologyVersion();
    applicationTopologyVersion.setArchiveId(version);
    topologyVersionMap.put(version, applicationTopologyVersion);
    applicationTopologyVersion = new ApplicationTopologyVersion();
    String devVersion = version + "-DEV";
    applicationTopologyVersion.setArchiveId(devVersion);
    topologyVersionMap.put(devVersion, applicationTopologyVersion);
    applicationVersion.setTopologyVersions(topologyVersionMap);
    dao.save(applicationVersion);
    return applicationVersion;
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 2 with ApplicationTopologyVersion

use of alien4cloud.model.application.ApplicationTopologyVersion in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method updateDeployment.

@ApiOperation(value = "Update the active deployment for the given application on the given cloud.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/update-deployment", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public DeferredResult<RestResponse<Void>> updateDeployment(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId, @ApiParam(value = "The secret provider configuration and credentials.") @RequestBody SecretProviderCredentials secretProviderCredentials) {
    final DeferredResult<RestResponse<Void>> result = new DeferredResult<>(15L * 60L * 1000L);
    Application application = applicationService.checkAndGetApplication(applicationId);
    // get the topology from the version and the cloud from the environment
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(application.getId(), applicationEnvironmentId);
    if (!environment.getApplicationId().equals(applicationId)) {
        throw new NotFoundException("Unable to find environment with id <" + applicationEnvironmentId + "> for application <" + applicationId + ">");
    }
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.APPLICATION_USER);
    // check that the environment is not already deployed
    boolean isEnvironmentDeployed = applicationEnvironmentService.isDeployed(environment.getId());
    if (!isEnvironmentDeployed) {
        // the topology must be deployed in order to update it
        throw new NotFoundException("Application <" + applicationId + "> is not deployed for environment with id <" + applicationEnvironmentId + ">, can't update it");
    }
    Deployment deployment = deploymentService.getActiveDeployment(environment.getId());
    if (deployment == null) {
        throw new NotFoundException("Unable to find deployment for environment with id <" + applicationEnvironmentId + "> application <" + applicationId + ">, can't update it");
    }
    ApplicationTopologyVersion topologyVersion = applicationVersionService.getOrFail(Csar.createId(environment.getApplicationId(), environment.getVersion()), environment.getTopologyVersion());
    Topology topology = topologyServiceCore.getOrFail(topologyVersion.getArchiveId());
    DeploymentTopologyDTO deploymentTopologyDTO = deploymentTopologyDTOBuilder.prepareDeployment(topology, application, environment);
    TopologyValidationResult validation = deploymentTopologyDTO.getValidation();
    deploymentService.checkDeploymentUpdateFeasibility(deployment, deploymentTopologyDTO.getTopology());
    // if not valid, then return validation errors
    if (!validation.isValid()) {
        result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.INVALID_DEPLOYMENT_TOPOLOGY.getCode(), "The deployment topology for the application <" + application.getName() + "> on the environment <" + environment.getName() + "> is not valid.")).build());
    }
    // process with the deployment
    deployService.update(secretProviderCredentials, deploymentTopologyDTO.getTopology(), application, deployment, new IPaaSCallback<Object>() {

        @Override
        public void onSuccess(Object data) {
            result.setResult(RestResponseBuilder.<Void>builder().build());
        }

        @Override
        public void onFailure(Throwable e) {
            result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.UNCATEGORIZED_ERROR.getCode(), e.getMessage())).build());
        }
    });
    return result;
}
Also used : RestResponse(alien4cloud.rest.model.RestResponse) NotFoundException(alien4cloud.exception.NotFoundException) Deployment(alien4cloud.model.deployment.Deployment) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion) TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) RestError(alien4cloud.rest.model.RestError) Application(alien4cloud.model.application.Application) DeferredResult(org.springframework.web.context.request.async.DeferredResult) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ApplicationTopologyVersion

use of alien4cloud.model.application.ApplicationTopologyVersion in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method updateSubstitutionProperty.

@ApiOperation(value = "Update node substitution's property.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(value = "/substitutions/{nodeId}/properties", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updateSubstitutionProperty(@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, () -> matchedNodePropertiesConfigService.updateProperty(application, environment, topology, nodeId, Optional.empty(), 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 4 with ApplicationTopologyVersion

use of alien4cloud.model.application.ApplicationTopologyVersion in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method updateSubstitution.

/**
 * Update node substitution.
 *
 * @param appId id of the application.
 * @param environmentId id of the environment.
 * @return response containing the available substitutions.
 */
@ApiOperation(value = "Substitute a specific node by the location 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 = "/substitutions/{nodeId}", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<DeploymentTopologyDTO> updateSubstitution(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @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, () -> nodeMatchingSubstitutionService.updateSubstitution(application, environment, topology, nodeId, 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 5 with ApplicationTopologyVersion

use of alien4cloud.model.application.ApplicationTopologyVersion in project alien4cloud by alien4cloud.

the class DeploymentTopologyController method updateSubstitutionCapabilityProperty.

@ApiOperation(value = "Update substitution's capability property.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(value = "/substitutions/{nodeId}/capabilities/{capabilityName}/properties", method = RequestMethod.POST)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<?> updateSubstitutionCapabilityProperty(@PathVariable String appId, @PathVariable String environmentId, @PathVariable String nodeId, @PathVariable String capabilityName, @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, () -> matchedNodePropertiesConfigService.updateProperty(application, environment, topology, nodeId, Optional.of(capabilityName), 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)

Aggregations

ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)18 Topology (org.alien4cloud.tosca.model.templates.Topology)12 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)11 Application (alien4cloud.model.application.Application)9 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)9 ApiOperation (io.swagger.annotations.ApiOperation)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)7 Audit (alien4cloud.audit.annotation.Audit)6 ApplicationVersion (alien4cloud.model.application.ApplicationVersion)5 ConstraintFunctionalException (org.alien4cloud.tosca.exceptions.ConstraintFunctionalException)3 ConstraintTechnicalException (org.alien4cloud.tosca.exceptions.ConstraintTechnicalException)3 NotFoundException (alien4cloud.exception.NotFoundException)2 AfterApplicationTopologyVersionDeleted (org.alien4cloud.alm.events.AfterApplicationTopologyVersionDeleted)2 BeforeApplicationTopologyVersionDeleted (org.alien4cloud.alm.events.BeforeApplicationTopologyVersionDeleted)2 AuthorizationServiceException (org.springframework.security.access.AuthorizationServiceException)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 Deployment (alien4cloud.model.deployment.Deployment)1 RestError (alien4cloud.rest.model.RestError)1