Search in sources :

Example 6 with Deployment

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

the class ApplicationEnvironmentDTOBuilder method getApplicationEnvironmentDTO.

/**
 * Creates an ApplicationEnvironmentDTO from an ApplicationEnvironment adding the deployment status informations.
 *
 * @param env The environment for which to create DTO
 * @return The application environement DTO matching the given application environement.
 */
public ApplicationEnvironmentDTO getApplicationEnvironmentDTO(ApplicationEnvironment env) {
    ApplicationEnvironmentDTO tempEnvDTO = new ApplicationEnvironmentDTO();
    tempEnvDTO.setApplicationId(env.getApplicationId());
    tempEnvDTO.setDescription(env.getDescription());
    tempEnvDTO.setEnvironmentType(env.getEnvironmentType());
    tempEnvDTO.setId(env.getId());
    tempEnvDTO.setName(env.getName());
    tempEnvDTO.setUserRoles(env.getUserRoles());
    tempEnvDTO.setGroupRoles(env.getGroupRoles());
    tempEnvDTO.setCurrentVersionName(env.getTopologyVersion());
    try {
        Deployment deployment = applicationEnvironmentService.getActiveDeployment(env.getId());
        tempEnvDTO.setStatus(applicationEnvironmentService.getStatus(deployment));
        if (!DeploymentStatus.UNDEPLOYED.equals(tempEnvDTO.getStatus())) {
            tempEnvDTO.setDeployedVersion(deployment.getVersionId());
        }
    } catch (Exception e) {
        log.debug("Getting status for the environment <" + env.getId() + "> failed because the associated orchestrator cannot be reached. Returned status is UNKNOWN.", e);
        tempEnvDTO.setStatus(DeploymentStatus.UNKNOWN);
    }
    return tempEnvDTO;
}
Also used : ApplicationEnvironmentDTO(alien4cloud.rest.application.model.ApplicationEnvironmentDTO) Deployment(alien4cloud.model.deployment.Deployment)

Example 7 with Deployment

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

the class MockPaaSProvider method notifyInstanceStateChanged.

private void notifyInstanceStateChanged(final String deploymentPaaSId, final String nodeId, final String instanceId, final InstanceInformation information, long delay) {
    final InstanceInformation cloned = new InstanceInformation();
    cloned.setAttributes(information.getAttributes());
    cloned.setInstanceStatus(information.getInstanceStatus());
    cloned.setRuntimeProperties(information.getRuntimeProperties());
    cloned.setState(information.getState());
    executorService.schedule(new Runnable() {

        @Override
        public void run() {
            final MockRuntimeDeploymentInfo deploymentInfo = runtimeDeploymentInfos.get(deploymentPaaSId);
            Deployment deployment = deploymentInfo.getDeploymentContext().getDeployment();
            PaaSInstanceStateMonitorEvent event;
            event = new PaaSInstanceStateMonitorEvent();
            event.setInstanceId(instanceId.toString());
            event.setInstanceState(cloned.getState());
            event.setInstanceStatus(cloned.getInstanceStatus());
            event.setNodeTemplateId(nodeId);
            event.setDate((new Date()).getTime());
            event.setDeploymentId(paaSDeploymentIdToAlienDeploymentIdMap.get(deploymentPaaSId));
            event.setRuntimeProperties(cloned.getRuntimeProperties());
            event.setAttributes(cloned.getAttributes());
            toBeDeliveredEvents.add(event);
            if (deployment.getSourceName().equals(BLOCKSTORAGE_APPLICATION) && cloned.getState().equalsIgnoreCase("created")) {
                PaaSInstancePersistentResourceMonitorEvent prme = new PaaSInstancePersistentResourceMonitorEvent(nodeId, instanceId.toString(), MapUtil.newHashMap(new String[] { NormativeBlockStorageConstants.VOLUME_ID }, new Object[] { UUID.randomUUID().toString() }));
                prme.setDeploymentId(deployment.getId());
                toBeDeliveredEvents.add(prme);
            }
            PaaSMessageMonitorEvent messageMonitorEvent = new PaaSMessageMonitorEvent();
            messageMonitorEvent.setDate((new Date()).getTime());
            messageMonitorEvent.setDeploymentId(paaSDeploymentIdToAlienDeploymentIdMap.get(deploymentPaaSId));
            messageMonitorEvent.setMessage("APPLICATIONS.RUNTIME.EVENTS.MESSAGE_EVENT.INSTANCE_STATE_CHANGED");
            toBeDeliveredEvents.add(messageMonitorEvent);
        }
    }, delay, TimeUnit.SECONDS);
}
Also used : PaaSInstanceStateMonitorEvent(alien4cloud.paas.model.PaaSInstanceStateMonitorEvent) PaaSInstancePersistentResourceMonitorEvent(alien4cloud.paas.model.PaaSInstancePersistentResourceMonitorEvent) InstanceInformation(alien4cloud.paas.model.InstanceInformation) Deployment(alien4cloud.model.deployment.Deployment) PaaSMessageMonitorEvent(alien4cloud.paas.model.PaaSMessageMonitorEvent) Date(java.util.Date)

Example 8 with Deployment

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

the class OrchestratorStateService method disable.

/**
 * Disable an orchestrator.
 *
 * @param orchestrator The orchestrator to disable.
 * @param force If true the orchestrator is disabled even if some deployments are currently running.
 */
public synchronized List<Usage> disable(Orchestrator orchestrator, boolean force) {
    if (!force) {
        // If there is at least one active deployment.
        GetMultipleDataResult<Deployment> result = alienDAO.buildQuery(Deployment.class).setFilters(MapUtil.newHashMap(new String[] { "orchestratorId", "endDate" }, new String[][] { new String[] { orchestrator.getId() }, new String[] { null } })).prepareSearch().setFieldSort("_timestamp", true).search(0, 1);
        // TODO place a lock to avoid deployments during the disabling of the orchestrator.
        if (result.getData().length > 0) {
            List<Usage> usages = generateDeploymentUsages(result.getData());
            return usages;
        }
    }
    try {
        // unregister the orchestrator.
        IOrchestratorPlugin orchestratorInstance = orchestratorPluginService.unregister(orchestrator.getId());
        if (orchestratorInstance != null) {
            IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
            orchestratorFactory.destroy(orchestratorInstance);
        }
    } catch (Exception e) {
        log.info("Unable to destroy orchestrator, it may not be created yet", e);
    } finally {
        // Mark the orchestrator as disabled
        orchestrator.setState(OrchestratorState.DISABLED);
        alienDAO.save(orchestrator);
    }
    return null;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) Usage(alien4cloud.model.common.Usage) Deployment(alien4cloud.model.deployment.Deployment) AlreadyExistException(alien4cloud.exception.AlreadyExistException) IOException(java.io.IOException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 9 with Deployment

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

the class PaaSProviderPollingMonitor method getActiveDeployment.

private Deployment getActiveDeployment() {
    Deployment deployment = null;
    GetMultipleDataResult<Deployment> dataResult = dao.search(Deployment.class, null, MapUtil.newHashMap(new String[] { "orchestratorId", "endDate" }, new String[][] { new String[] { orchestratorId }, new String[] { null } }), 1);
    if (dataResult.getData() != null && dataResult.getData().length > 0) {
        deployment = dataResult.getData()[0];
    }
    return deployment;
}
Also used : Deployment(alien4cloud.model.deployment.Deployment)

Example 10 with Deployment

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

the class RuntimeController method getDeployedTopology.

/**
 * Get runtime (deployed) topology of an application on a specific environment
 *
 * @param applicationId application id for which to get the topology
 * @param applicationEnvironmentId application environment for which to get the topology through the version
 * @return {@link RestResponse}<{@link TopologyDTO}> containing the requested runtime {@link Topology} and the
 *         {@link NodeType} related to his {@link NodeTemplate}s
 */
@ApiOperation(value = "Get runtime (deployed) topology of an application on a specific cloud.")
@RequestMapping(value = "/{applicationId:.+?}/environment/{applicationEnvironmentId:.+?}/topology", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<TopologyDTO> getDeployedTopology(@ApiParam(value = "Id of the application for which to get deployed topology.", required = true) @PathVariable String applicationId, @ApiParam(value = "Id of the environment for which to get deployed topology.", required = true) @PathVariable String applicationEnvironmentId) {
    ApplicationEnvironment environment = applicationEnvironmentService.getEnvironmentByIdOrDefault(applicationId, applicationEnvironmentId);
    if (!environment.getApplicationId().equals(applicationId)) {
        throw new NotFoundException("Unable to find environment with id <" + applicationEnvironmentId + "> for application <" + applicationId + ">");
    }
    // Security check user must be authorized to deploy the environment (or be application manager)
    AuthorizationUtil.checkAuthorizationForEnvironment(applicationService.getOrFail(applicationId), environment);
    Deployment deployment = deploymentService.getActiveDeploymentOrFail(environment.getId());
    DeploymentTopology deploymentTopology = deploymentRuntimeStateService.getRuntimeTopology(deployment.getId());
    return RestResponseBuilder.<TopologyDTO>builder().data(topologyDTOBuilder.initTopologyDTO(deploymentTopology, new TopologyDTO())).build();
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) NotFoundException(alien4cloud.exception.NotFoundException) Deployment(alien4cloud.model.deployment.Deployment) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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