Search in sources :

Example 6 with RestError

use of alien4cloud.rest.model.RestError in project alien4cloud by alien4cloud.

the class PluginController method upload.

@ApiOperation(value = "Upload a plugin archive.", notes = "Content of the zip file must be compliant with the expected alien 4 cloud plugin structure.", authorizations = { @Authorization("ADMIN") })
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('ADMIN')")
@Audit
public RestResponse<Void> upload(@ApiParam(value = "Zip file that contains the plugin.", required = true) @RequestParam("file") MultipartFile pluginArchive) {
    Path pluginPath = null;
    try {
        // save the plugin archive in the temp directory
        pluginPath = Files.createTempFile(tempDirPath, null, ".zip");
        FileUploadUtil.safeTransferTo(pluginPath, pluginArchive);
        // upload the plugin archive
        Plugin plugin = pluginManager.uploadPlugin(pluginPath);
        // TODO as we do not manage many version of a same plugin, is this still relevant ?
        if (plugin.isConfigurable()) {
            tryReusePreviousVersionConf(plugin);
        }
    } catch (MissingPlugingDescriptorFileException e) {
        log.error("Your plugin don't have the META-INF/plugin.yml file.", e);
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.MISSING_PLUGIN_DESCRIPTOR_FILE_EXCEPTION.getCode(), "Your plugin don't have the META-INF/plugin.yml file.")).build();
    } catch (IOException e) {
        log.error("Unexpected IO error on plugin upload.", e);
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.INDEXING_SERVICE_ERROR.getCode(), "A technical issue occurred during the plugin upload <" + e.getMessage() + ">.")).build();
    } catch (PluginLoadingException e) {
        log.error("Fail to enable and load the plugin. The plugin will remain disabled", e);
        return RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.ENABLE_PLUGIN_ERROR.getCode(), e.getMessage())).build();
    } finally {
        if (pluginPath != null) {
            try {
                FileUtil.delete(pluginPath);
            } catch (IOException e) {
                log.error("Failed to cleanup temporary file <" + pluginPath.toString() + ">", e);
            }
        }
    }
    return RestResponseBuilder.<Void>builder().build();
}
Also used : Path(java.nio.file.Path) PluginLoadingException(alien4cloud.plugin.exception.PluginLoadingException) RestError(alien4cloud.rest.model.RestError) IOException(java.io.IOException) Plugin(alien4cloud.plugin.Plugin) MissingPlugingDescriptorFileException(alien4cloud.plugin.exception.MissingPlugingDescriptorFileException) 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 7 with RestError

use of alien4cloud.rest.model.RestError in project alien4cloud by alien4cloud.

the class DeploymentController method getDeploymentStatus.

@ApiOperation(value = "Get deployment status from its id.", authorizations = { @Authorization("ADMIN"), @Authorization("APPLICATION_MANAGER") })
@RequestMapping(value = "/{deploymentId}/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<DeploymentStatus> getDeploymentStatus(@ApiParam(value = "Deployment id.", required = true) @Valid @NotBlank @PathVariable String deploymentId) {
    Deployment deployment = alienDAO.findById(Deployment.class, deploymentId);
    if (deployment != null) {
        try {
            return deploymentLockService.doWithDeploymentReadLock(deployment.getOrchestratorDeploymentId(), () -> {
                final SettableFuture<DeploymentStatus> statusSettableFuture = SettableFuture.create();
                deploymentRuntimeStateService.getDeploymentStatus(deployment, new IPaaSCallback<DeploymentStatus>() {

                    @Override
                    public void onSuccess(DeploymentStatus result) {
                        statusSettableFuture.set(result);
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        statusSettableFuture.setException(t);
                    }
                });
                try {
                    DeploymentStatus currentStatus = statusSettableFuture.get();
                    if (DeploymentStatus.UNDEPLOYED.equals(currentStatus)) {
                        deploymentService.markUndeployed(deployment);
                    }
                    return RestResponseBuilder.<DeploymentStatus>builder().data(currentStatus).build();
                } catch (Exception e) {
                    throw new PaaSTechnicalException("Could not retrieve status from PaaS", e);
                }
            });
        } catch (OrchestratorDisabledException e) {
            return RestResponseBuilder.<DeploymentStatus>builder().data(null).error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build();
        }
    } else {
        return RestResponseBuilder.<DeploymentStatus>builder().data(null).error(new RestError(RestErrorCode.NOT_FOUND_ERROR.getCode(), "Deployment with id <" + deploymentId + "> was not found.")).build();
    }
}
Also used : OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) PaaSTechnicalException(alien4cloud.paas.exception.PaaSTechnicalException) RestError(alien4cloud.rest.model.RestError) Deployment(alien4cloud.model.deployment.Deployment) DeploymentStatus(alien4cloud.paas.model.DeploymentStatus) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) PaaSTechnicalException(alien4cloud.paas.exception.PaaSTechnicalException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with RestError

use of alien4cloud.rest.model.RestError in project alien4cloud by alien4cloud.

the class ComponentController method deleteTag.

@ApiOperation(value = "Delete a tag for a component (tosca element).")
@RequestMapping(value = "/{componentId:.+}/tags/{tagId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAnyAuthority('ADMIN', 'COMPONENTS_MANAGER')")
@Audit
public RestResponse<Void> deleteTag(@PathVariable String componentId, @PathVariable String tagId) {
    RestError deleteComponentTagError = null;
    NodeType component = dao.findById(NodeType.class, componentId);
    if (component != null) {
        tagService.removeTag(component, tagId);
    } else {
        deleteComponentTagError = RestErrorBuilder.builder(RestErrorCode.COMPONENT_MISSING_ERROR).message("Tag delete operation failed. Could not find component with id <" + componentId + ">.").build();
    }
    return RestResponseBuilder.<Void>builder().error(deleteComponentTagError).build();
}
Also used : RestError(alien4cloud.rest.model.RestError) NodeType(org.alien4cloud.tosca.model.types.NodeType) 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 9 with RestError

use of alien4cloud.rest.model.RestError in project alien4cloud by alien4cloud.

the class ComponentController method upsertTag.

/**
 * Update or insert one tag for a given component
 *
 * @param componentId The if of the component for which to insert a tag.
 * @param updateTagRequest The request that contains the key and value for the tag to update.
 * @return a void rest response that contains no data if successful and an error if something goes wrong.
 */
@ApiOperation(value = "Update or insert a tag for a component (tosca element).")
@RequestMapping(value = "/{componentId:.+}/tags", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAnyAuthority('ADMIN', 'COMPONENTS_MANAGER')")
@Audit
public RestResponse<Void> upsertTag(@PathVariable String componentId, @RequestBody UpdateTagRequest updateTagRequest) {
    RestError updateComponantTagError = null;
    NodeType component = dao.findById(NodeType.class, componentId);
    if (component != null) {
        tagService.upsertTag(component, updateTagRequest.getTagKey(), updateTagRequest.getTagValue());
    } else {
        updateComponantTagError = RestErrorBuilder.builder(RestErrorCode.COMPONENT_MISSING_ERROR).message("Tag update operation failed. Could not find component with id <" + componentId + ">.").build();
    }
    return RestResponseBuilder.<Void>builder().error(updateComponantTagError).build();
}
Also used : RestError(alien4cloud.rest.model.RestError) NodeType(org.alien4cloud.tosca.model.types.NodeType) 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 10 with RestError

use of alien4cloud.rest.model.RestError in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method doDeploy.

private RestResponse<?> doDeploy(DeployApplicationRequest deployApplicationRequest, Application application, ApplicationEnvironment environment, Topology topology) {
    DeploymentTopologyDTO deploymentTopologyDTO = deploymentTopologyDTOBuilder.prepareDeployment(topology, application, environment);
    TopologyValidationResult validation = deploymentTopologyDTO.getValidation();
    // if not valid, then return validation errors
    if (!validation.isValid()) {
        return RestResponseBuilder.<TopologyValidationResult>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.")).data(validation).build();
    }
    User deployer = AuthorizationUtil.getCurrentUser();
    // commit and push the deployment configuration data
    GitLocation location = gitLocationDao.findDeploymentSetupLocation(application.getId(), environment.getId());
    localGitManager.commitAndPush(location, deployer.getUsername(), deployer.getEmail(), "Deployment " + DateTime.now(DateTimeZone.UTC));
    // the request contains secret provider credentials?
    SecretProviderCredentials secretProviderCredentials = null;
    if (deployApplicationRequest.getSecretProviderCredentials() != null && deployApplicationRequest.getSecretProviderPluginName() != null) {
        secretProviderCredentials = new SecretProviderCredentials();
        secretProviderCredentials.setCredentials(deployApplicationRequest.getSecretProviderCredentials());
        secretProviderCredentials.setPluginName(deployApplicationRequest.getSecretProviderPluginName());
    }
    // process with the deployment
    deployService.deploy(deployer, secretProviderCredentials, deploymentTopologyDTO.getTopology(), application);
    return RestResponseBuilder.<Void>builder().build();
}
Also used : TopologyValidationResult(alien4cloud.topology.TopologyValidationResult) SecretProviderCredentials(alien4cloud.deployment.model.SecretProviderCredentials) User(alien4cloud.security.model.User) RestError(alien4cloud.rest.model.RestError) DeploymentTopologyDTO(alien4cloud.deployment.DeploymentTopologyDTO) GitLocation(org.alien4cloud.git.model.GitLocation)

Aggregations

RestError (alien4cloud.rest.model.RestError)12 ApiOperation (io.swagger.annotations.ApiOperation)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 Audit (alien4cloud.audit.annotation.Audit)7 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)5 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)5 RestResponse (alien4cloud.rest.model.RestResponse)4 DeferredResult (org.springframework.web.context.request.async.DeferredResult)4 Application (alien4cloud.model.application.Application)3 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 Deployment (alien4cloud.model.deployment.Deployment)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 PaaSDeploymentException (alien4cloud.paas.exception.PaaSDeploymentException)2 TopologyValidationResult (alien4cloud.topology.TopologyValidationResult)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Topology (org.alien4cloud.tosca.model.templates.Topology)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 CSARUsedInActiveDeployment (alien4cloud.component.repository.exception.CSARUsedInActiveDeployment)1