Пример #1
0
  private void deploy(ManagedApplication ma, List<Instance> instances) throws BulkActionException {

    BulkActionException bulkException = new BulkActionException(true);
    for (Instance instance : instances) {
      if (instance.getParent() == null) {
        try {
          IaasInterface iaasInterface = this.iaasResolver.findIaasInterface(ma, instance);
          String machineId =
              iaasInterface.createVM(
                  null, this.messageServerIp, instance.getName(), ma.getApplication().getName());

          // FIXME: the channel name is skipped here
          // As soon as we know what it is useful for, re-add it (it is in the instance)
          instance.getData().put(Instance.MACHINE_ID, machineId);

        } catch (IaasException e) {
          instance.setStatus(InstanceStatus.PROBLEM);
          bulkException.getInstancesToException().put(instance, e);

        } catch (CommunicationToIaasException e) {
          instance.setStatus(InstanceStatus.PROBLEM);
          bulkException.getInstancesToException().put(instance, e);
        }

      } else {
        try {
          // FIXME: we may have to add the instance on the agent too, just like for root instances
          Map<String, byte[]> instanceResources =
              ResourceUtils.storeInstanceResources(ma.getApplicationFilesDirectory(), instance);
          MsgCmdInstanceDeploy message =
              new MsgCmdInstanceDeploy(
                  InstanceHelpers.computeInstancePath(instance), instanceResources);
          ma.getMessagingClient()
              .publish(false, MessagingUtils.buildRoutingKeyToAgent(instance), message);

        } catch (IOException e) {
          // The instance does not have any problem, just keep trace of the exception
          bulkException.getInstancesToException().put(instance, e);
        }
      }
    }

    if (!bulkException.getInstancesToException().isEmpty()) {
      ma.getLogger().severe(bulkException.getLogMessage(false));
      ma.getLogger().finest(bulkException.getLogMessage(true));
      throw bulkException;
    }
  }
Пример #2
0
  private void remove(ManagedApplication ma, List<Instance> instances)
      throws UnauthorizedActionException, BulkActionException {

    for (Instance instance : instances) {
      if (instance.getStatus() != InstanceStatus.NOT_DEPLOYED)
        throw new UnauthorizedActionException(
            "Instances are still deployed or running. They cannot be removed.");
    }

    BulkActionException bulkException = new BulkActionException(false);
    for (Instance instance : instances) {

      if (instance.getParent() != null) {
        try {
          MsgCmdInstanceRemove message =
              new MsgCmdInstanceRemove(InstanceHelpers.computeInstancePath(instance));
          ma.getMessagingClient()
              .publish(false, MessagingUtils.buildRoutingKeyToAgent(instance), message);

          // The instance will be removed once the agent has indicated it was removed.
          // See DmMessageProcessor.

        } catch (IOException e) {
          // The instance does not have any problem, just keep trace of the exception
          bulkException.getInstancesToException().put(instance, e);
        }

      } else {
        ma.getApplication().getRootInstances().remove(instance);
      }
    }

    if (!bulkException.getInstancesToException().isEmpty()) {
      ma.getLogger().severe(bulkException.getLogMessage(false));
      ma.getLogger().finest(bulkException.getLogMessage(true));
      throw bulkException;
    }
  }
Пример #3
0
  private void undeploy(ManagedApplication ma, List<Instance> instances)
      throws BulkActionException {

    BulkActionException bulkException = new BulkActionException(false);
    for (Instance instance : instances) {
      try {
        MsgCmdInstanceUndeploy message =
            new MsgCmdInstanceUndeploy(InstanceHelpers.computeInstancePath(instance));
        ma.getMessagingClient()
            .publish(false, MessagingUtils.buildRoutingKeyToAgent(instance), message);

      } catch (IOException e) {
        // The instance does not have any problem, just keep trace of the exception
        bulkException.getInstancesToException().put(instance, e);
      }
    }

    if (!bulkException.getInstancesToException().isEmpty()) {
      ma.getLogger().severe(bulkException.getLogMessage(false));
      ma.getLogger().finest(bulkException.getLogMessage(true));
      throw bulkException;
    }
  }