Search in sources :

Example 36 with Deployment

use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.

the class DeploymentController method search.

/**
 * Search for deployments
 *
 * @return A rest response that contains a {@link FacetedSearchResult} containing deployments, including if asked some details of the related applications..
 */
@ApiOperation(value = "Search for deployments", notes = "Returns a search result with that contains deployments matching the request.")
@RequestMapping(value = "/search", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('ADMIN')")
public RestResponse<FacetedSearchResult> search(@ApiParam(value = "Query text.") @RequestParam(required = false) String query, @ApiParam(value = "Query from the given index.") @RequestParam(required = false, defaultValue = "0") int from, @ApiParam(value = "Maximum number of results to retrieve.") @RequestParam(required = false, defaultValue = "50") int size, @ApiParam(value = "Id of the orchestrator for which to get deployments. If not provided, get deployments for all orchestrators") @RequestParam(required = false) String orchestratorId, @ApiParam(value = "Id of the application for which to get deployments. if not provided, get deployments for all applications") @RequestParam(required = false) String sourceId, @ApiParam(value = "Id of the environment for which to get deployments. if not provided, get deployments without filtering by environment") @RequestParam(required = false) String environmentId, @ApiParam(value = "include or not the source (application or csar) summary in the results") @RequestParam(required = false, defaultValue = "false") boolean includeSourceSummary) {
    FacetedSearchResult searchResult = deploymentService.searchDeployments(query, orchestratorId, environmentId, sourceId, from, size);
    List<DeploymentDTO> deploymentsDTOS = buildDeploymentsDTOS(includeSourceSummary, (Deployment[]) searchResult.getData());
    searchResult.setData(deploymentsDTOS.toArray());
    return RestResponseBuilder.<FacetedSearchResult>builder().data(searchResult).build();
}
Also used : Deployment(alien4cloud.model.deployment.Deployment) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with Deployment

use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.

the class DeploymentEventHandler method send.

protected void send(AbstractMonitorEvent event) {
    String eventType = MappingBuilder.indexTypeFromClass(event.getClass());
    String topicName = TOPIC_PREFIX + '/' + event.getDeploymentId() + '/' + eventType;
    dispatchEvent(event, topicName);
    if (event instanceof PaaSDeploymentStatusMonitorEvent) {
        Deployment deployment = alienDAO.findById(Deployment.class, event.getDeploymentId());
        if (deployment != null && deployment.getEnvironmentId() != null) {
            // dispatch an event on the environment topic
            topicName = ENV_TOPIC_PREFIX + "/" + deployment.getEnvironmentId();
            dispatchEvent(event, topicName);
        }
    }
}
Also used : PaaSDeploymentStatusMonitorEvent(alien4cloud.paas.model.PaaSDeploymentStatusMonitorEvent) Deployment(alien4cloud.model.deployment.Deployment)

Example 38 with Deployment

use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.

the class DeploymentEventHandler method checkDeploymentAuthorization.

private void checkDeploymentAuthorization(Authentication authentication, User a4cUser, String deploymentId) {
    Deployment deployment = alienDAO.findById(Deployment.class, deploymentId);
    switch(deployment.getSourceType()) {
        case APPLICATION:
            // check if the user has right for the environment associated with the deployment.
            ApplicationEnvironment environment = alienDAO.findById(ApplicationEnvironment.class, deployment.getEnvironmentId());
            if (environment == null) {
                log.error("Environment with id [{}] do not exist any more for deployment [{}]", deployment.getEnvironmentId(), deployment.getId());
                throw new NotFoundException("Environment with id [" + deployment.getEnvironmentId() + "] do not exist any more for deployment [" + deployment.getId() + "]");
            }
            AuthorizationUtil.checkAuthorization(a4cUser, environment, ApplicationRole.APPLICATION_MANAGER, ApplicationEnvironmentRole.values());
            break;
        case CSAR:
            AuthorizationUtil.checkHasOneRoleIn(authentication, Role.COMPONENTS_MANAGER);
    }
}
Also used : Deployment(alien4cloud.model.deployment.Deployment) NotFoundException(alien4cloud.exception.NotFoundException) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment)

Example 39 with Deployment

use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.

the class WorkflowEventHandler method send.

protected void send(AbstractMonitorEvent event) {
    String eventType = MappingBuilder.indexTypeFromClass(event.getClass());
    String topicName = TOPIC_PREFIX + '/' + event.getDeploymentId() + '/' + eventType;
    if (log.isDebugEnabled()) {
        log.debug("Send [" + event.getClass().getSimpleName() + "] to [" + topicName + "]: " + event);
    }
    template.convertAndSend(topicName, event);
    if (event instanceof PaaSWorkflowMonitorEvent) {
        Deployment deployment = alienDAO.findById(Deployment.class, event.getDeploymentId());
        if (deployment != null) {
            PaaSWorkflowMonitorEvent pwme = (PaaSWorkflowMonitorEvent) event;
            if (log.isDebugEnabled()) {
                log.debug("Workflow {} started with executionId {} (subkworkflow: {})", pwme.getWorkflowId(), pwme.getExecutionId(), pwme.getSubworkflow());
            }
            String workflowId = pwme.getWorkflowId();
            if (pwme.getSubworkflow() != null) {
                workflowId = pwme.getSubworkflow();
            }
            updateDeploymentExecutionId(deployment, workflowId, pwme.getExecutionId());
        }
    }
}
Also used : AbstractPaaSWorkflowMonitorEvent(alien4cloud.paas.model.AbstractPaaSWorkflowMonitorEvent) PaaSWorkflowMonitorEvent(alien4cloud.paas.model.PaaSWorkflowMonitorEvent) Deployment(alien4cloud.model.deployment.Deployment)

Example 40 with Deployment

use of alien4cloud.model.deployment.Deployment in project alien4cloud by alien4cloud.

the class BlockStorageEventHandler method updateApplicationTopology.

private void updateApplicationTopology(PaaSInstancePersistentResourceMonitorEvent persistentResourceEvent, final Map<String, Object> persistentProperties) {
    Deployment deployment = deploymentService.get(persistentResourceEvent.getDeploymentId());
    String topologyId = deployment.getSourceId() + ":" + deployment.getVersionId();
    Topology topology = topoServiceCore.getOrFail(topologyId);
    // The deployment topology may have changed and the node removed, in such situations there is nothing to update as the block won't be reused.
    NodeTemplate nodeTemplate;
    try {
        nodeTemplate = TopologyUtils.getNodeTemplate(topology, persistentResourceEvent.getNodeTemplateId());
    } catch (NotFoundException e) {
        log.warn("Fail to update persistent resource for node {}", persistentResourceEvent.getNodeTemplateId(), e);
        return;
    }
    for (String propertyName : persistentProperties.keySet()) {
        Object propertyValue = persistentProperties.get(propertyName);
        AbstractPropertyValue abstractPropertyValue = nodeTemplate.getProperties().get(propertyName);
        if (abstractPropertyValue != null && abstractPropertyValue instanceof FunctionPropertyValue) {
            // the value is set in the topology
            FunctionPropertyValue function = (FunctionPropertyValue) abstractPropertyValue;
            if (function.getFunction().equals(ToscaFunctionConstants.GET_INPUT) && propertyValue instanceof String) {
                DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(deployment.getVersionId(), deployment.getEnvironmentId()));
                // the value is set in the input (deployment setup)
                log.info("Updating deploymentsetup [ {} ] input properties [ {} ] to add a new VolumeId", deploymentInputs.getId(), function.getTemplateName());
                log.debug("Property [ {} ] to update: [ {} ]. New value is [ {} ]", propertyName, persistentResourceEvent.getPersistentProperties().get(propertyName), propertyValue);
                deploymentInputs.getInputs().put(function.getTemplateName(), new ScalarPropertyValue((String) propertyValue));
                deploymentConfigurationDao.save(deploymentInputs);
            } else {
                // this is not supported / print a warning
                log.warn("Failed to store the id of the created block storage [ {} ] for deployment [ {} ] application [ {} ] environment [ {} ]");
                return;
            }
        } else {
            DeploymentMatchingConfiguration matchingConfiguration = deploymentConfigurationDao.findById(DeploymentMatchingConfiguration.class, AbstractDeploymentConfig.generateId(deployment.getVersionId(), deployment.getEnvironmentId()));
            log.info("Updating deployment topology: Persistent resource property [ {} ] for node template <{}.{}> to add a value", propertyName, matchingConfiguration.getId(), persistentResourceEvent.getNodeTemplateId());
            log.debug("Value to add: [ {} ]. New value is [ {} ]", persistentResourceEvent.getPersistentProperties().get(propertyName), propertyValue);
            matchingConfiguration.getMatchedNodesConfiguration().get(persistentResourceEvent.getNodeTemplateId()).getProperties().put(propertyName, getPropertyValue(propertyValue));
            deploymentConfigurationDao.save(matchingConfiguration);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) DeploymentMatchingConfiguration(org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration) Deployment(alien4cloud.model.deployment.Deployment) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Topology(org.alien4cloud.tosca.model.templates.Topology)

Aggregations

Deployment (alien4cloud.model.deployment.Deployment)43 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)13 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)11 ApiOperation (io.swagger.annotations.ApiOperation)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 NotFoundException (alien4cloud.exception.NotFoundException)6 Application (alien4cloud.model.application.Application)6 Location (alien4cloud.model.orchestrators.locations.Location)6 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)5 ApplicationVersion (alien4cloud.model.application.ApplicationVersion)3 Usage (alien4cloud.model.common.Usage)3 PaaSDeploymentContext (alien4cloud.paas.model.PaaSDeploymentContext)3 Date (java.util.Date)3 DeploymentTopologyDTO (alien4cloud.deployment.DeploymentTopologyDTO)2 SecretProviderConfigurationAndCredentials (alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2 ServiceResource (alien4cloud.model.service.ServiceResource)2 OrchestratorDisabledException (alien4cloud.paas.exception.OrchestratorDisabledException)2 DeploymentStatus (alien4cloud.paas.model.DeploymentStatus)2