Search in sources :

Example 26 with Deployment

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

the class ApplicationVersionService method failIfAnyEnvironmentDeployed.

private void failIfAnyEnvironmentDeployed(ApplicationEnvironment[] relatedEnvironments) {
    Usage[] usages = Arrays.stream(relatedEnvironments).map(environment -> {
        Usage usage = null;
        Deployment deployment = applicationEnvironmentService.getActiveDeployment(environment.getId());
        if (deployment != null) {
            String usageName = " App (" + deployment.getSourceName() + "), Env (" + environment.getName() + ")";
            usage = new Usage(usageName, "Deployment", deployment.getId(), null);
        }
        return usage;
    }).filter(Objects::nonNull).toArray(Usage[]::new);
    if (ArrayUtils.isNotEmpty(usages)) {
        throw new ReferencedResourceException("Application versions deployed cannot be updated", usages);
    }
}
Also used : Usage(alien4cloud.model.common.Usage) Deployment(alien4cloud.model.deployment.Deployment)

Example 27 with Deployment

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

the class DeploymentRuntimeStateService method getDeploymentEvents.

/**
 * Get events for a specific deployment from an environment
 *
 * @param applicationEnvironmentId The environment we want to get events from
 * @param from The initial position of the events to get (based on time desc sorting)
 * @param size The number of events to get.
 * @return A result that contains all events.
 */
public GetMultipleDataResult<?> getDeploymentEvents(String applicationEnvironmentId, int from, int size) {
    Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
    String index = alienMonitorDao.getIndexForType(AbstractMonitorEvent.class);
    QueryHelper.ISearchQueryBuilderHelper searchQueryHelperBuilder = queryHelper.buildQuery().types(PaaSDeploymentStatusMonitorEvent.class, PaaSInstanceStateMonitorEvent.class, PaaSMessageMonitorEvent.class, PaaSInstancePersistentResourceMonitorEvent.class).filters(MapUtil.newHashMap(new String[] { "deploymentId" }, new String[][] { new String[] { deployment.getId() } })).prepareSearch(index).fieldSort("_timestamp", true);
    return alienMonitorDao.search(searchQueryHelperBuilder, from, size);
}
Also used : QueryHelper(org.elasticsearch.mapping.QueryHelper) Deployment(alien4cloud.model.deployment.Deployment)

Example 28 with Deployment

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

the class DeploymentService method getCloudActiveDeploymentContexts.

public Map<String, PaaSTopologyDeploymentContext> getCloudActiveDeploymentContexts(String orchestratorId) {
    Deployment[] deployments = getOrchestratorActiveDeployments(orchestratorId);
    Map<String, PaaSTopologyDeploymentContext> activeDeploymentContexts = Maps.newHashMap();
    for (Deployment deployment : deployments) {
        DeploymentTopology topology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
        activeDeploymentContexts.put(deployment.getOrchestratorDeploymentId(), deploymentContextService.buildTopologyDeploymentContext(null, deployment, deploymentTopologyService.getLocations(topology), topology));
    }
    return activeDeploymentContexts;
}
Also used : PaaSTopologyDeploymentContext(alien4cloud.paas.model.PaaSTopologyDeploymentContext) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Deployment(alien4cloud.model.deployment.Deployment)

Example 29 with Deployment

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

the class DeploymentService method getDeployments.

/**
 * Get all deployments for a given orchestrator an application
 *
 * @param orchestratorId Id of the cloud for which to get deployments (can be null to get deployments for all clouds).
 * @param sourceId Id of the application for which to get deployments (can be null to get deployments for all applications).
 * @param environmentId Id of the environment for which to get deployments (can be null to get deployments for all environments).
 * @return An array of deployments.
 */
public Deployment[] getDeployments(String orchestratorId, String sourceId, String environmentId, int from, int size) {
    FilterBuilder filterBuilder = buildDeploymentFilters(orchestratorId, sourceId, environmentId);
    IESQueryBuilderHelper<Deployment> queryBuilderHelper = alienDao.buildQuery(Deployment.class);
    return queryBuilderHelper.setFilters(filterBuilder).prepareSearch().setFieldSort("startDate", true).search(from, size).getData();
}
Also used : FilterBuilder(org.elasticsearch.index.query.FilterBuilder) Deployment(alien4cloud.model.deployment.Deployment)

Example 30 with Deployment

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

the class ApplicationService method delete.

/**
 * Delete an existing application from it's id. This method ensures first that there is no running deployment of the application.
 *
 * @param applicationId The id of the application to remove.
 * @return True if the application has been removed, false if not.
 */
public boolean delete(String applicationId) {
    // Removal of a deployed application is not authorized
    if (alienDAO.count(Deployment.class, null, fromKeyValueCouples("sourceId", applicationId, "endDate", null)) > 0) {
        return false;
    }
    // Ensure that application related resources can be removed.
    Application application = getOrFail(applicationId);
    DeleteApplicationVersions deleteApplicationVersions = applicationVersionService.prepareDeleteByApplication(applicationId);
    DeleteApplicationEnvironments deleteApplicationEnvironments = applicationEnvironmentService.prepareDeleteByApplication(applicationId);
    // Delete the application.
    deleteApplicationVersions.delete();
    deleteApplicationEnvironments.delete();
    publisher.publishEvent(new BeforeApplicationDeleted(this, applicationId));
    alienDAO.delete(Application.class, applicationId);
    if (application != null && StringUtils.isNotBlank(application.getImageId())) {
        imageDAO.deleteAll(application.getImageId());
    }
    publisher.publishEvent(new AfterApplicationDeleted(this, applicationId));
    return true;
}
Also used : DeleteApplicationEnvironments(alien4cloud.application.ApplicationEnvironmentService.DeleteApplicationEnvironments) BeforeApplicationDeleted(org.alien4cloud.alm.events.BeforeApplicationDeleted) DeleteApplicationVersions(alien4cloud.application.ApplicationVersionService.DeleteApplicationVersions) Deployment(alien4cloud.model.deployment.Deployment) AfterApplicationDeleted(org.alien4cloud.alm.events.AfterApplicationDeleted) Application(alien4cloud.model.application.Application)

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