Search in sources :

Example 1 with OrchestratorDisabledException

use of alien4cloud.paas.exception.OrchestratorDisabledException 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;
}
Also used : RestResponse(alien4cloud.rest.model.RestResponse) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) PaaSDeploymentException(alien4cloud.paas.exception.PaaSDeploymentException) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) RestError(alien4cloud.rest.model.RestError) DeferredResult(org.springframework.web.context.request.async.DeferredResult) 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 2 with OrchestratorDisabledException

use of alien4cloud.paas.exception.OrchestratorDisabledException in project alien4cloud by alien4cloud.

the class ApplicationDeploymentController method getInstanceInformation.

/**
 * Get detailed information for every instances of every node of the application on the PaaS.
 *
 * @param applicationId The id of the application to be deployed.
 * @return A {@link RestResponse} that contains detailed informations (See {@link InstanceInformation}) of the application on the PaaS it is deployed.
 */
@ApiOperation(value = "Get detailed informations for every instances of every node of the application on the PaaS.", notes = "Application role required [ APPLICATION_MANAGER | APPLICATION_DEVOPS ] and Application environment role required [ APPLICATION_USER | DEPLOYMENT_MANAGER ]")
@RequestMapping(value = "/{applicationId:.+}/environments/{applicationEnvironmentId}/deployment/informations", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public DeferredResult<RestResponse<Map<String, Map<String, InstanceInformation>>>> getInstanceInformation(@PathVariable String applicationId, @PathVariable String applicationEnvironmentId) {
    Application application = applicationService.checkAndGetApplication(applicationId);
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(application.getId(), applicationEnvironmentId);
    AuthorizationUtil.checkAuthorizationForEnvironment(application, environment, ApplicationEnvironmentRole.values());
    Deployment deployment = applicationEnvironmentService.getActiveDeployment(environment.getId());
    final DeferredResult<RestResponse<Map<String, Map<String, InstanceInformation>>>> instancesDeferredResult = new DeferredResult<>(5L * 60L * 1000L);
    if (deployment == null) {
        // if there is no topology associated with the version it could not have been deployed.
        instancesDeferredResult.setResult(RestResponseBuilder.<Map<String, Map<String, InstanceInformation>>>builder().build());
    } else {
        try {
            deploymentRuntimeStateService.getInstancesInformation(deployment, new IPaaSCallback<Map<String, Map<String, InstanceInformation>>>() {

                @Override
                public void onSuccess(Map<String, Map<String, InstanceInformation>> data) {
                    instancesDeferredResult.setResult(RestResponseBuilder.<Map<String, Map<String, InstanceInformation>>>builder().data(data).build());
                }

                @Override
                public void onFailure(Throwable throwable) {
                    instancesDeferredResult.setErrorResult(throwable);
                }
            });
        } catch (OrchestratorDisabledException e) {
            log.error("Cannot get instance informations as topology plugin cannot be found.", e);
            instancesDeferredResult.setResult(RestResponseBuilder.<Map<String, Map<String, InstanceInformation>>>builder().build());
        }
    }
    return instancesDeferredResult;
}
Also used : RestResponse(alien4cloud.rest.model.RestResponse) Deployment(alien4cloud.model.deployment.Deployment) InstanceInformation(alien4cloud.paas.model.InstanceInformation) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) Application(alien4cloud.model.application.Application) Map(java.util.Map) 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 OrchestratorDisabledException

use of alien4cloud.paas.exception.OrchestratorDisabledException 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;
}
Also used : OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) RestResponse(alien4cloud.rest.model.RestResponse) RestError(alien4cloud.rest.model.RestError) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) PaaSDeploymentException(alien4cloud.paas.exception.PaaSDeploymentException) DeferredResult(org.springframework.web.context.request.async.DeferredResult) 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 OrchestratorDisabledException

use of alien4cloud.paas.exception.OrchestratorDisabledException in project alien4cloud by alien4cloud.

the class PluginArchiveIndexer method getConfiguratorPlugin.

private ILocationConfiguratorPlugin getConfiguratorPlugin(Location location) {
    ILocationConfiguratorPlugin configuratorPlugin;
    try {
        IOrchestratorPlugin<Object> orchestratorInstance = orchestratorPluginService.getOrFail(location.getOrchestratorId());
        configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    } catch (OrchestratorDisabledException e) {
        IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestratorService.getOrFail(location.getOrchestratorId()));
        IOrchestratorPlugin<Object> orchestratorInstance = orchestratorFactory.newInstance();
        configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
        orchestratorFactory.destroy(orchestratorInstance);
    }
    return configuratorPlugin;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 5 with OrchestratorDisabledException

use of alien4cloud.paas.exception.OrchestratorDisabledException 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;
}
Also used : ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) RestResponse(alien4cloud.rest.model.RestResponse) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ConstraintFunctionalException(org.alien4cloud.tosca.exceptions.ConstraintFunctionalException) OrchestratorDisabledException(alien4cloud.paas.exception.OrchestratorDisabledException) RestError(alien4cloud.rest.model.RestError) OperationExecutionException(alien4cloud.paas.exception.OperationExecutionException) ConstraintViolationException(org.alien4cloud.tosca.exceptions.ConstraintViolationException) Application(alien4cloud.model.application.Application) Map(java.util.Map) ConstraintRequiredParameterException(org.alien4cloud.tosca.exceptions.ConstraintRequiredParameterException) DeferredResult(org.springframework.web.context.request.async.DeferredResult) Audit(alien4cloud.audit.annotation.Audit) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)7 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)5 RestError (alien4cloud.rest.model.RestError)5 ApiOperation (io.swagger.annotations.ApiOperation)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 RestResponse (alien4cloud.rest.model.RestResponse)4 DeferredResult (org.springframework.web.context.request.async.DeferredResult)4 Audit (alien4cloud.audit.annotation.Audit)3 Application (alien4cloud.model.application.Application)3 Deployment (alien4cloud.model.deployment.Deployment)2 PaaSDeploymentException (alien4cloud.paas.exception.PaaSDeploymentException)2 Map (java.util.Map)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)1 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)1 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)1 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)1 OperationExecutionException (alien4cloud.paas.exception.OperationExecutionException)1 PaaSTechnicalException (alien4cloud.paas.exception.PaaSTechnicalException)1 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)1