Esempio n. 1
0
  /**
   * Finds the right IaaS interface for a given instance.
   *
   * @param ma the managed application
   * @param instance the (root) instance associated with a IaaS
   * @return a IaaS interface
   * @throws IaasException if no IaaS interface was found
   */
  public IaasInterface findIaasInterface(ManagedApplication ma, Instance instance)
      throws IaasException {

    // FIXME: Not very "plug-in-like"
    IaasInterface iaasInterface;
    try {
      String installerName = instance.getComponent().getInstallerName();
      if (!"iaas".equalsIgnoreCase(installerName))
        throw new IaasException("Unsupported installer name: " + installerName);

      Map<String, String> props =
          IaasHelpers.loadIaasProperties(ma.getApplicationFilesDirectory(), instance);
      iaasInterface = findIaasHandler(props);
      if (iaasInterface == null)
        throw new IaasException("No IaaS handler was found for " + instance.getName() + ".");

      iaasInterface.setIaasProperties(props);

    } catch (IOException e) {
      throw new IaasException(e);

    } catch (InvalidIaasPropertiesException e) {
      throw new IaasException(e);
    }

    return iaasInterface;
  }
Esempio n. 2
0
  /**
   * Terminates a VM.
   *
   * @param applicationName the application name
   * @param rootInstance the root instance associated with a machine
   */
  public void terminateMachine(String applicationName, Instance rootInstance) {

    try {
      ManagedApplication ma = this.appNameToManagedApplication.get(applicationName);
      if (ma == null) {
        this.logger.severe(
            "Machine "
                + rootInstance.getName()
                + " failed to be resolved for application "
                + applicationName
                + ".");

      } else {
        this.logger.fine("Machine " + rootInstance.getName() + " is about to be deleted.");
        IaasInterface iaasInterface = this.iaasResolver.findIaasInterface(ma, rootInstance);
        String machineId = rootInstance.getData().get(Instance.MACHINE_ID);
        iaasInterface.terminateVM(machineId);

        this.logger.fine("Machine " + rootInstance.getName() + " was successfully deleted.");
        rootInstance.setStatus(InstanceStatus.NOT_DEPLOYED);
      }

    } catch (IaasException e) {
      rootInstance.setStatus(InstanceStatus.PROBLEM);
      this.logger.severe(
          "Machine " + rootInstance.getName() + " could not be deleted. " + e.getMessage());
      this.logger.finest(Utils.writeException(e));

    } catch (CommunicationToIaasException e) {
      rootInstance.setStatus(InstanceStatus.PROBLEM);
      this.logger.severe(
          "Machine " + rootInstance.getName() + " could not be deleted. " + e.getMessage());
      this.logger.finest(Utils.writeException(e));
    }
  }
Esempio n. 3
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;
    }
  }