public DeployClient(String host, int port, String userName, String password) {
    String url = "http://" + host + ":" + port + "/hmtp";

    _url = url;

    HmtpClient client = new HmtpClient(url);
    try {
      client.setVirtualHost("admin.resin");

      client.connect(userName, password);

      _bamClient = client;
      _bamManager = new SimpleBamManager(_bamClient.getBroker());

      _deployAddress = DeployActor.ADDRESS;

      /*
            BamManager bamManager = server.getAdminBrokerManager();
            return BamProxyFactory.createProxy(api, to, sender);
      */
      _deployProxy = _bamManager.createProxy(DeployActorProxy.class, _deployAddress, _bamClient);
    } catch (RemoteConnectionFailedException e) {
      throw new RemoteConnectionFailedException(
          L.l(
              "Connection to '{0}' failed for remote administration.\n  Ensure the local server has started, or include --server and --port parameters to connect to a remote server.\n  {1}",
              url, e.getMessage()),
          e);
    } catch (RemoteListenerUnavailableException e) {
      throw new RemoteListenerUnavailableException(
          L.l(
              "Connection to '{0}' failed for remote administration because RemoteAdminService (HMTP) is not enabled.\n  Ensure <resin:RemoteAdminService> is enabled in resin.xml.\n  {1}",
              url, e.getMessage()),
          e);
    }
  }
Exemple #2
0
  public void killWatchdog(String serverId) throws IOException {
    ActorSender conn = getConnection();

    try {
      ResultStatus status =
          (ResultStatus) conn.query(WATCHDOG_ADDRESS, new WatchdogKillQuery(serverId), BAM_TIMEOUT);

      if (!status.isSuccess())
        throw new RuntimeException(
            L.l("{0}: watchdog kill failed because of '{1}'", this, status.getMessage()));
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      log.log(Level.FINE, e.toString(), e);
    }
  }
Exemple #3
0
  public boolean shutdown() throws IOException {
    ActorSender conn = getConnection();

    try {
      ResultStatus status =
          (ResultStatus) conn.query(WATCHDOG_ADDRESS, new WatchdogShutdownQuery(), BAM_TIMEOUT);

      if (!status.isSuccess())
        throw new RuntimeException(
            L.l("{0}: watchdog shutdown failed because of '{1}'", this, status.getMessage()));
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      log.log(Level.FINE, e.toString(), e);
    }

    return true;
  }
Exemple #4
0
  public void restartWatchdog(String id, String[] argv) throws IOException {
    // cloud/1295
    ActorSender conn = getConnection();

    try {
      ResultStatus status =
          (ResultStatus)
              conn.query(WATCHDOG_ADDRESS, new WatchdogRestartQuery(id, argv), BAM_TIMEOUT);

      if (!status.isSuccess())
        throw new RuntimeException(
            L.l("{0}: watchdog restartfailed because of '{1}'", this, status.getMessage()));
    } catch (RuntimeException e) {
      throw e;
    } catch (Exception e) {
      log.log(Level.FINE, e.toString(), e);
    }
  }
Exemple #5
0
  public Process startWatchdog(String[] argv) throws ConfigException, IOException {
    if (getUserName() != null && !hasBoot()) {
      String message = getTroubleshootMessage();

      if (message == null)
        message =
            "Check the $RESIN_HOME/libexec or $RESIN_HOME/libexec64 directory for libresin_os.so.";

      throw new ConfigException(L.l("<user-name> requires compiled JNI.\n{0}", message));
    }

    if (getGroupName() != null && !hasBoot()) {
      String message = getTroubleshootMessage();

      if (message == null)
        message =
            "Check the $RESIN_HOME/libexec or $RESIN_HOME/libexec64 directory for libresin_os.so.";

      throw new ConfigException(L.l("<group-name> requires compiled JNI.\n{0}", message));
    }

    ActorSender conn = null;

    try {
      conn = getConnection();

      ResultStatus status =
          (ResultStatus) conn.query(WATCHDOG_ADDRESS, new WatchdogStartQuery(argv), BAM_TIMEOUT);

      if (status.isSuccess()) return null;

      throw new ConfigException(
          L.l("{0}: watchdog start failed because of '{1}'", this, status.getMessage()));
    } catch (RemoteConnectionFailedException e) {
      log.log(Level.FINE, e.toString(), e);
    } catch (RuntimeException e) {
      throw e;
    } finally {
      if (conn != null) conn.close();
    }

    return launchManager(argv);
  }
  public DeployClient(String url, ActorSender client) {
    _bamClient = client;
    _bamManager = new SimpleBamManager(client.getBroker());

    _url = url;

    _deployAddress = DeployActor.ADDRESS;

    _deployProxy = _bamManager.createProxy(DeployActorProxy.class, _deployAddress, _bamClient);
  }
Exemple #7
0
  public String statusWatchdog() throws IOException {
    ActorSender conn = getConnection();

    try {
      ResultStatus status = (ResultStatus) conn.query(WATCHDOG_ADDRESS, new WatchdogStatusQuery());

      if (status.isSuccess()) return status.getMessage();

      throw new RuntimeException(
          L.l("{0}: watchdog status failed because of '{1}'", this, status.getMessage()));
    } catch (Exception e) {
      Throwable e1 = e;

      while (e1.getCause() != null) e1 = e1.getCause();

      log.log(Level.FINE, e.toString(), e);

      return e1.toString();
    }
  }
 public void close() {
   _bamClient.close();
 }
 public String getUrl() {
   if (_url != null) return _url;
   else if (_bamClient != null) return _bamClient.getAddress();
   else return null;
 }