/**
   * Get the current deployment status for a topology.
   *
   * @param deployment deployment for which we want the status
   * @param callback that will be called when status is available*
   * @return The status of the topology.
   * @throws alien4cloud.paas.exception.OrchestratorDisabledException In case the cloud selected for
   *     the topology is disabled.
   */
  public void getDeploymentStatus(
      final Deployment deployment, final IPaaSCallback<DeploymentStatus> callback)
      throws OrchestratorDisabledException {
    if (deployment == null) {
      callback.onSuccess(DeploymentStatus.UNDEPLOYED);
      return;
    }
    IOrchestratorPlugin orchestratorPlugin =
        orchestratorPluginService.getOrFail(deployment.getOrchestratorId());

    PaaSDeploymentContext deploymentContext =
        new PaaSDeploymentContext(deployment, getRuntimeTopology(deployment.getId()));
    IPaaSCallback<DeploymentStatus> esCallback =
        new IPaaSCallback<DeploymentStatus>() {
          @Override
          public void onSuccess(DeploymentStatus data) {
            if (data == DeploymentStatus.UNDEPLOYED) {
              deployment.setEndDate(new Date());
              alienDao.save(deployment);
            }
            callback.onSuccess(data);
          }

          @Override
          public void onFailure(Throwable throwable) {
            callback.onFailure(throwable);
          }
        };
    orchestratorPlugin.getStatus(deploymentContext, esCallback);
  }
 /**
  * Get the detailed status for each instance of each node template.
  *
  * @param deployment The deployment for witch to get the instance informations.
  * @param callback callback on witch to send the map of node template's id to map of instance's id
  *     to instance information.
  * @throws alien4cloud.paas.exception.OrchestratorDisabledException In case the cloud selected for
  *     the topology is disabled.
  */
 public void getInstancesInformation(
     final Deployment deployment,
     IPaaSCallback<Map<String, Map<String, InstanceInformation>>> callback)
     throws OrchestratorDisabledException {
   Map<String, Map<String, InstanceInformation>> instancesInformation = Maps.newHashMap();
   if (deployment == null) {
     callback.onSuccess(instancesInformation);
     return;
   }
   DeploymentTopology runtimeTopology =
       alienMonitorDao.findById(DeploymentTopology.class, deployment.getId());
   PaaSTopologyDeploymentContext deploymentContext =
       deploymentContextService.buildTopologyDeploymentContext(
           deployment, deploymentTopologyService.getLocations(runtimeTopology), runtimeTopology);
   IOrchestratorPlugin orchestratorPlugin =
       orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
   orchestratorPlugin.getInstancesInformation(deploymentContext, callback);
 }
 /**
  * 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.SearchQueryHelperBuilder searchQueryHelperBuilder =
       queryHelper
           .buildSearchQuery(index)
           .types(
               PaaSDeploymentStatusMonitorEvent.class,
               PaaSInstanceStateMonitorEvent.class,
               PaaSMessageMonitorEvent.class,
               PaaSInstancePersistentResourceMonitorEvent.class)
           .filters(
               MapUtil.newHashMap(
                   new String[] {"deploymentId"},
                   new String[][] {new String[] {deployment.getId()}}))
           .fieldSort("_timestamp", true);
   return alienMonitorDao.search(searchQueryHelperBuilder, from, size);
 }
 /**
  * Get the deployed (runtime) topology of an application on a cloud
  *
  * @param topologyId id of the topology for which to get deployed topology.
  * @param orchestratorId targeted cloud id
  * @return the DeploymentTopology requested if found
  */
 public DeploymentTopology getRuntimeTopologyFromEnvironment(
     String topologyId, String orchestratorId) {
   Deployment deployment = deploymentService.getActiveDeploymentOrFail(topologyId, orchestratorId);
   return alienMonitorDao.findById(DeploymentTopology.class, deployment.getId());
 }
 /**
  * Get the deployed (runtime) topology of an application from the environment id
  *
  * @param applicationEnvironmentId id of the environment
  * @return the DeploymentTopology requested if found
  */
 public DeploymentTopology getRuntimeTopologyFromEnvironment(String applicationEnvironmentId) {
   Deployment deployment = deploymentService.getActiveDeploymentOrFail(applicationEnvironmentId);
   return alienMonitorDao.findById(DeploymentTopology.class, deployment.getId());
 }