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;
}
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);
}
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;
}
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;
}
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();
}
Aggregations