Search in sources :

Example 1 with OrchestratorDeploymentIdConflictException

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

the class DeployService method generateOrchestratorDeploymentId.

/**
 * Generate the human readable deployment id for the orchestrator.
 *
 * @param envId Id of the deployed environment.
 * @param orchestratorId Id of the orchestrator on which the deployment is performed.
 * @return The orchestrator deployment id.
 * @throws alien4cloud.paas.exception.OrchestratorDeploymentIdConflictException
 */
private String generateOrchestratorDeploymentId(String envId, String orchestratorId) throws OrchestratorDeploymentIdConflictException {
    log.debug("Generating deployment paaS Id...");
    log.debug("All spaces will be replaced by an \"_\" charactr. You might consider it while naming your applications.");
    ApplicationEnvironment env = applicationEnvironmentService.getOrFail(envId);
    Orchestrator orchestrator = orchestratorService.getOrFail(orchestratorId);
    String namePattern = orchestrator.getDeploymentNamePattern();
    ExpressionParser parser = new SpelExpressionParser();
    Expression exp = parser.parseExpression(namePattern);
    String orchestratorDeploymentId = (String) exp.getValue(new OrchestratorIdContext(env, applicationService.getOrFail(env.getApplicationId()), namePattern.contains("metaProperties[")));
    // ensure that the id is not used by another deployment.
    if (deploymentService.isActiveDeployment(orchestratorId, orchestratorDeploymentId)) {
        throw new OrchestratorDeploymentIdConflictException("Conflict detected with the generated paasId <" + orchestratorDeploymentId + ">.");
    }
    return orchestratorDeploymentId;
}
Also used : SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) OrchestratorDeploymentIdConflictException(alien4cloud.paas.exception.OrchestratorDeploymentIdConflictException) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) Orchestrator(alien4cloud.model.orchestrators.Orchestrator)

Aggregations

ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)1 Orchestrator (alien4cloud.model.orchestrators.Orchestrator)1 OrchestratorDeploymentIdConflictException (alien4cloud.paas.exception.OrchestratorDeploymentIdConflictException)1 Expression (org.springframework.expression.Expression)1 ExpressionParser (org.springframework.expression.ExpressionParser)1 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)1