Пример #1
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;
    }
  }
Пример #2
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;
    }
  }
Пример #3
0
  /**
   * Shutdowns an application.
   *
   * <p>It means Roboconf deletes every machine it created for this application.
   *
   * @param applicationName the application name
   * @throws InexistingException if the application or the parent instance does not exist
   * @throws BulkActionException if an error occurred while terminating machines
   */
  public void shutdownApplication(String applicationName)
      throws InexistingException, BulkActionException {

    ManagedApplication ma = this.appNameToManagedApplication.get(applicationName);
    if (ma == null) throw new InexistingException(applicationName);

    // Undeploy everything correctly so that we keep the message server clean.
    // Also, this is useful for deployments on machines (not just on VM).
    BulkActionException bulkException = new BulkActionException(false);
    for (Instance instance : ma.getApplication().getRootInstances()) {
      if (instance.getStatus() != InstanceStatus.NOT_DEPLOYED)
        undeploy(ma, Arrays.asList(instance));
    }

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

    cleanMessagingServer(ma);
    ma.getLogger().fine("Application " + applicationName + " was successfully shutdown.");
  }
Пример #4
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;
    }
  }