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();
}
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();
}
}
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();
}
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();
}
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();
}
Aggregations