Exemplo n.º 1
0
  /**
   * Return kind of hypervisor API the remote machine through the {@link
   * NodeCollectorPremiumRESTClient} client.
   *
   * @param nodecollector object nodecollector used in the datacenter.
   * @param hypervisorIp ip address of the hypervisor.
   * @return hypType kind of hypervisor API of remote machine.
   */
  public HypervisorType getRemoteHypervisorType(
      final RemoteService nodecollector, final String hypervisorIp) {
    NodeCollectorRESTClient restCli = initializeRESTClient(nodecollector);

    try {
      return restCli.getRemoteHypervisorType(hypervisorIp);
    } catch (BadRequestException e) {
      // InternalServerError -> A Bad Request NEVER should be thrown from here.
      logger.error(e.getMessage());
      addUnexpectedErrors(APIError.NC_UNEXPECTED_EXCEPTION);
    } catch (ConnectionException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_CONNECTION_EXCEPTION);
    } catch (UnprovisionedException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_NOT_FOUND_EXCEPTION);
    } catch (CollectorException e) {
      logger.error(e.getMessage());
      addUnexpectedErrors(APIError.NC_UNEXPECTED_EXCEPTION);
    } catch (ServiceUnavailableException e) {
      logger.error(e.getMessage());
      addServiceUnavailableErrors(APIError.NC_UNAVAILABLE_EXCEPTION);
    } catch (CannotExecuteException e) {
      addConflictErrors(new CommonError(APIError.STATUS_CONFLICT.getCode(), e.getMessage()));
      flushErrors();
    }

    flushErrors();

    return null;
  }
Exemplo n.º 2
0
  /**
   * Return the remote machine using its hypervisor APIs through the {@link
   * NodeCollectorPremiumRESTClient} client.
   *
   * @param nodecollector object nodecollector used in the datacenter we want to add the machine.
   * @param hypervisorIp ip address of the hypervisor.
   * @param hypType kind of hypervisor API we want to use.
   * @param user use to log-in
   * @param password password
   * @param port (optional) AIM port we connect to if we use KVM or XEN.
   * @return the remote {@link Machine} entity, null if we don't find anything.
   */
  public Machine getRemoteHypervisor(
      final RemoteService nodecollector,
      final IPAddress hypervisorIp,
      final HypervisorType hypType,
      final String user,
      final String password,
      final Integer port) {
    NodeCollectorRESTClient restCli = initializeRESTClient(nodecollector);
    HostDto host = new HostDto();
    try {
      host = restCli.getRemoteHostInfo(hypervisorIp.toString(), hypType, user, password, port);
    } catch (BadRequestException e) {
      // InternalServerError -> A Bad Request NEVER should be thrown from here.
      logger.error(e.getMessage());
      addUnexpectedErrors(APIError.NC_UNEXPECTED_EXCEPTION);
    } catch (LoginException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_BAD_CREDENTIALS_TO_MACHINE);
    } catch (ConnectionException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_CONNECTION_EXCEPTION);
    } catch (UnprovisionedException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_NOT_FOUND_EXCEPTION);
    } catch (CollectorException e) {
      logger.error(e.getMessage());
      addUnexpectedErrors(APIError.NC_UNEXPECTED_EXCEPTION);
    } catch (ServiceUnavailableException e) {
      logger.error(e.getMessage());
      addServiceUnavailableErrors(APIError.NC_UNAVAILABLE_EXCEPTION);
    } catch (CannotExecuteException e) {
      addConflictErrors(new CommonError(APIError.STATUS_CONFLICT.getCode(), e.getMessage()));
      flushErrors();
    }

    flushErrors();

    Machine machine = hostToMachine(nodecollector.getDatacenter(), host);
    Hypervisor hypervisor =
        machine.createHypervisor(
            hypType, hypervisorIp.toString(), hypervisorIp.toString(), port, user, password);
    machine.setHypervisor(hypervisor);

    return machine;
  }
Exemplo n.º 3
0
  /**
   * Return kind of hypervisor API the remote machine through the {@link
   * NodeCollectorPremiumRESTClient} client.
   *
   * @param nodecollector object nodecollector used in the datacenter.
   * @param hypervisorIp ip address of the hypervisor.
   * @return hypType kind of hypervisor API of remote machine.
   * @throws LoginException
   */
  public List<VirtualMachine> getRemoteVirtualMachines(
      final RemoteService nodecollector,
      final String hypervisorIp,
      final HypervisorType hypervisorType,
      final String user,
      final String password,
      final Integer aimport) {
    NodeCollectorRESTClient restCli = initializeRESTClient(nodecollector);

    try {
      VirtualSystemCollectionDto vsc =
          restCli.getRemoteVirtualSystemCollection(
              hypervisorIp, hypervisorType, user, password, aimport);

      List<VirtualMachine> vms = transportVSCollectionToVMs(vsc);

      return vms;
    } catch (BadRequestException e) {
      // InternalServerError -> A Bad Request NEVER should be thrown from here.
      logger.error(e.getMessage());
      addUnexpectedErrors(APIError.NC_UNEXPECTED_EXCEPTION);
    } catch (LoginException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_BAD_CREDENTIALS_TO_MACHINE);
    } catch (ConnectionException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_CONNECTION_EXCEPTION);
    } catch (UnprovisionedException e) {
      logger.debug(e.getMessage());
      addConflictErrors(APIError.NC_NOT_FOUND_EXCEPTION);
    } catch (CollectorException e) {
      logger.error(e.getMessage());
      addUnexpectedErrors(APIError.NC_UNEXPECTED_EXCEPTION);
    } catch (CannotExecuteException e) {
      addConflictErrors(new CommonError(APIError.STATUS_CONFLICT.getCode(), e.getMessage()));
      flushErrors();
    }

    flushErrors();

    return null;
  }