use of alien4cloud.rest.model.RestError in project alien4cloud by alien4cloud.
the class ApplicationDeploymentController method launchWorkflow.
@ApiOperation(value = "Launch a given workflow.", authorizations = { @Authorization("ADMIN"), @Authorization("APPLICATION_MANAGER") })
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/workflows/{workflowName}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit(bodyHiddenFields = { "credentials" })
public DeferredResult<RestResponse<Void>> launchWorkflow(@ApiParam(value = "Application id.", required = true) @Valid @NotBlank @PathVariable String applicationId, @ApiParam(value = "Deployment id.", required = true) @Valid @NotBlank @PathVariable String applicationEnvironmentId, @ApiParam(value = "Workflow name.", required = true) @Valid @NotBlank @PathVariable String workflowName, @ApiParam(value = "The secret provider configuration and credentials.") @RequestBody(required = false) SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
final DeferredResult<RestResponse<Void>> result = new DeferredResult<>(15L * 60L * 1000L);
ApplicationEnvironment environment = getAppEnvironmentAndCheckAuthorization(applicationId, applicationEnvironmentId);
// TODO merge with incoming params
Map<String, Object> params = Maps.newHashMap();
try {
workflowExecutionService.launchWorkflow(secretProviderConfigurationAndCredentials, environment.getId(), workflowName, params, 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.RUNTIME_WORKFLOW_ERROR.getCode(), e.getMessage())).build());
}
});
} catch (OrchestratorDisabledException e) {
result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build());
} catch (PaaSDeploymentException e) {
result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.SCALING_ERROR.getCode(), e.getMessage())).build());
}
return result;
}
use of alien4cloud.rest.model.RestError 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;
}
use of alien4cloud.rest.model.RestError in project alien4cloud by alien4cloud.
the class ApplicationDeploymentController method scale.
/**
* Scale an application on a particular node.
*
* @param applicationId The id of the application to be scaled.
* @param nodeTemplateId The id of the node template to be scaled.
* @param instances The instances number to be scaled up (if > 0)/ down (if < 0)
* @return A {@link RestResponse} that contains the application's current {@link DeploymentStatus}.
*/
@ApiOperation(value = "Scale the application on a particular node.", notes = "Returns the detailed informations of the application on the PaaS it is deployed." + " Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/scale/{nodeTemplateId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit(bodyHiddenFields = { "credentials" })
public DeferredResult<RestResponse<Void>> scale(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId, @PathVariable String nodeTemplateId, @RequestParam int instances, @ApiParam(value = "The secret provider configuration ans credentials.") @RequestBody SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
final DeferredResult<RestResponse<Void>> result = new DeferredResult<>(15L * 60L * 1000L);
ApplicationEnvironment environment = getAppEnvironmentAndCheckAuthorization(applicationId, applicationEnvironmentId);
try {
deploymentRuntimeService.scale(secretProviderConfigurationAndCredentials, environment.getId(), nodeTemplateId, instances, 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.SCALING_ERROR.getCode(), e.getMessage())).build());
}
});
} catch (OrchestratorDisabledException e) {
result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build());
} catch (PaaSDeploymentException e) {
result.setErrorResult(RestResponseBuilder.<Void>builder().error(new RestError(RestErrorCode.SCALING_ERROR.getCode(), e.getMessage())).build());
}
return result;
}
use of alien4cloud.rest.model.RestError in project alien4cloud by alien4cloud.
the class RuntimeController method executeOperation.
@ApiOperation(value = "Trigger a custom command on a specific node template of a topology .", authorizations = { @Authorization("APPLICATION_MANAGER") }, notes = "Returns a response with no errors and the command response as data in success case. Application role required [ APPLICATION_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+?}/operations", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@PreAuthorize("isAuthenticated()")
@Audit(bodyHiddenFields = { "secretProviderCredentials" })
public DeferredResult<RestResponse<Object>> executeOperation(@PathVariable String applicationId, @RequestBody @Valid OperationExecRequest operationRequest) {
final DeferredResult<RestResponse<Object>> result = new DeferredResult<>(15L * 60L * 1000L);
Application application = applicationService.getOrFail(applicationId);
ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, operationRequest.getApplicationEnvironmentId());
AuthorizationUtil.checkAuthorizationForEnvironment(application, environment);
Topology topology = deploymentRuntimeStateService.getRuntimeTopologyFromEnvironment(operationRequest.getApplicationEnvironmentId());
// validate the operation request
try {
validateCommand(operationRequest, topology);
} catch (ConstraintViolationException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_CONSTRAINT_VIOLATION_ERROR.getCode(), e.getMessage())).build());
return result;
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_TYPE_VIOLATION_ERROR.getCode(), e.getMessage())).build());
return result;
} catch (ConstraintRequiredParameterException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_REQUIRED_VIOLATION_ERROR.getCode(), e.getMessage())).build());
return result;
} catch (ConstraintFunctionalException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().data(e.getConstraintInformation()).error(new RestError(RestErrorCode.PROPERTY_UNKNOWN_VIOLATION_ERROR.getCode(), e.getMessage())).build());
return result;
}
// try to trigger the execution of the operation
try {
deploymentRuntimeService.triggerOperationExecution(operationRequest, new IPaaSCallback<Map<String, String>>() {
@Override
public void onSuccess(Map<String, String> data) {
result.setResult(RestResponseBuilder.<Object>builder().data(data).build());
}
@Override
public void onFailure(Throwable throwable) {
result.setErrorResult(RestResponseBuilder.<Object>builder().error(new RestError(RestErrorCode.NODE_OPERATION_EXECUTION_ERROR.getCode(), throwable.getMessage())).build());
}
});
} catch (OperationExecutionException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().error(new RestError(RestErrorCode.NODE_OPERATION_EXECUTION_ERROR.getCode(), e.getMessage())).build());
} catch (OrchestratorDisabledException e) {
result.setErrorResult(RestResponseBuilder.<Object>builder().error(new RestError(RestErrorCode.CLOUD_DISABLED_ERROR.getCode(), e.getMessage())).build());
}
return result;
}
use of alien4cloud.rest.model.RestError in project alien4cloud by alien4cloud.
the class CloudServiceArchiveController method uploadCSAR.
@ApiOperation(value = "Upload a csar zip file.")
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<CsarUploadResult> uploadCSAR(@RequestParam(required = false) String workspace, @RequestParam("file") MultipartFile csar) throws IOException {
Path csarPath = null;
try {
if (workspace == null) {
workspace = AlienConstants.GLOBAL_WORKSPACE_ID;
}
// Perform check that the user has one of ARCHITECT, COMPONENT_MANAGER or ADMIN role
archiveIndexerAuthorizationFilter.preCheckAuthorization(workspace);
log.info("Serving file upload with name [" + csar.getOriginalFilename() + "]");
csarPath = Files.createTempFile(tempDirPath, null, '.' + CsarFileRepository.CSAR_EXTENSION);
// save the archive in the temp directory
FileUploadUtil.safeTransferTo(csarPath, csar);
// load, parse the archive definitions and save on disk
ParsingResult<Csar> result = csarUploadService.upload(csarPath, CSARSource.UPLOAD, workspace);
RestError error = null;
if (result.hasError(ParsingErrorLevel.ERROR)) {
error = RestErrorBuilder.builder(RestErrorCode.CSAR_PARSING_ERROR).build();
}
return RestResponseBuilder.<CsarUploadResult>builder().error(error).data(CsarUploadUtil.toUploadResult(result)).build();
} catch (ParsingException e) {
log.error("Error happened while parsing csar file <" + e.getFileName() + ">", e);
String fileName = e.getFileName() == null ? csar.getOriginalFilename() : e.getFileName();
CsarUploadResult uploadResult = new CsarUploadResult();
uploadResult.getErrors().put(fileName, e.getParsingErrors());
return RestResponseBuilder.<CsarUploadResult>builder().error(RestErrorBuilder.builder(RestErrorCode.CSAR_INVALID_ERROR).build()).data(uploadResult).build();
} catch (AlreadyExistException | CSARUsedInActiveDeployment | ToscaTypeAlreadyDefinedInOtherCSAR e) {
CsarUploadResult uploadResult = new CsarUploadResult();
uploadResult.getErrors().put(csar.getOriginalFilename(), Lists.newArrayList(UploadExceptionUtil.parsingErrorFromException(e)));
return RestResponseBuilder.<CsarUploadResult>builder().error(RestErrorBuilder.builder(RestErrorCode.ALREADY_EXIST_ERROR).build()).data(uploadResult).build();
} finally {
if (csarPath != null) {
// Clean up
try {
FileUtil.delete(csarPath);
} catch (IOException e) {
// The repository might just move the file instead of copying to save IO disk access
}
}
}
}
Aggregations