示例#1
0
    @Override
    protected void doActivity(AgentContext ctx) throws Exception {
      String version = ctx.getVersion();
      String host = ctx.getHost();

      ctx.println("[INFO] Deployed phoenix kernel(%s) to host(%s) successfully.", version, host);
    }
示例#2
0
    @Override
    protected void doProlog(AgentContext ctx) throws Exception {
      String version = ctx.getVersion();
      String host = ctx.getHost();
      String message =
          String.format("[ERROR] Failed to deploy phoenix kernel(%s) to host(%s).", version, host);

      ctx.updateStatus(AgentStatus.FAILED, message);
      ctx.println(message);
    }
示例#3
0
    @Override
    protected void doActivity(AgentContext ctx) throws Exception {
      String host = ctx.getHost();
      int id = ctx.getDeployId();

      ctx.println("[INFO] Getting status from host(%s) for deploy(%s) ... ", host, id);

      String url = ctx.getConfigManager().getDeployLogUrl(host, id);

      try {
        String log = ctx.openUrl(url);

        ctx.print(log);
      } catch (Exception e) {
        ctx.println(e.toString());
        moveTo(ctx, FAILED);
        return;
      }

      if (ctx.getStatus() == AgentStatus.FAILED) {
        moveTo(ctx, FAILED);
      } else {
        moveTo(ctx, SUCCESSFUL);
      }
    }
示例#4
0
  @Override
  protected void work() {
    while (waitForNextInterval()) {
      RelDb ownSrcNdtDb = null;
      RelDb ownDstNdtDb = null;
      try {
        ownSrcNdtDb = getController().getRelDbPoolFactory().ndtBridge().src().get();
        ownDstNdtDb = getController().getRelDbPoolFactory().ndtBridge().dst().get();
        final AgentContext agentContext = (AgentContext) getCtx().get(AgentContext.class);
        notNull(agentContext);

        log.debug("Execute clog GC at {}", ownSrcNdtDb);
        dbAgentExecutor.clogAgentGc(agentContext.getSrcClogAgent(), ownSrcNdtDb);

        log.debug("Execute clog GC at {}", ownDstNdtDb);
        dbAgentExecutor.clogAgentGc(agentContext.getDstClogAgent(), ownDstNdtDb);
      } finally {
        IoUtils.silentClose(ownSrcNdtDb, ownDstNdtDb);
      }
    }
  }
示例#5
0
  void moveTo(AgentContext ctx, AgentState nextState) throws Exception {
    boolean found = false;
    int nextId = nextState.getId();

    for (int id : m_nextIds) {
      if (id == nextId) {
        found = true;
        break;
      }
    }

    if (!found) {
      throw new IllegalStateException(
          String.format("Can't move deploy state from %s to %s!", this, nextState));
    }

    doEpilog(ctx);
    nextState.doProlog(ctx);
    ctx.setState(nextState);
    nextState.doActivity(ctx);
  }
示例#6
0
    @Override
    protected void doActivity(AgentContext ctx) throws Exception {
      int retriedCount = ctx.getRetriedCount();

      if (retriedCount >= MAX_RETRY_COUNT) {
        moveTo(ctx, FAILED);
      } else {

        long retryInterval = ctx.getConfigManager().getDeployRetryInterval();

        ctx.setRetriedCount(retriedCount + 1);

        Thread.sleep(retryInterval); // sleep a while before retry

        Transaction t =
            Cat.newTransaction(
                "phoenix-agent:" + ctx.getDomain(),
                ctx.getHost() + ":" + ctx.getWarType() + ":" + ctx.getVersion());

        String host = ctx.getHost();
        int id = ctx.getDeployId();
        String domain = ctx.getDomain();
        String version = ctx.getVersion();
        String type = ctx.getWarType();
        boolean skipTest = ctx.isSkipTest();
        String url = ctx.getConfigManager().getDeployUrl(type, host, id, domain, version, skipTest);
        String json = null;

        ctx.print(
            "[WARN] Retry to deploy phoenix kernel(%s) to host(%s) for deploy(%s) of domain(%s)  ... ",
            version, host, id, domain);

        boolean shouldRetry = false;

        try {
          json = ctx.openUrl(url);
          t.setStatus(Message.SUCCESS);
        } catch (Exception e) {
          ctx.println(e.toString());

          t.setStatus(e);
          Cat.logError(e);

          shouldRetry = true;
          return;
        } finally {
          t.complete();

          if (shouldRetry) {
            moveTo(ctx, UNREACHABLE);
          }
        }

        Response response = DefaultJsonParser.parse(json);

        if ("ok".equals(response.getStatus())) {
          ctx.println("ACCEPTED");

          moveTo(ctx, SUBMITTED);
        } else {
          ctx.print(response.getStatus()).println();
          ctx.println(response.getMessage());

          moveTo(ctx, FAILED);
        }
      }
    }
示例#7
0
  public static void execute(AgentContext ctx) throws Exception {
    AgentState initial = CREATED;

    ctx.setState(initial);
    initial.doActivity(ctx);
  }
示例#8
0
    @Override
    protected void doActivity(AgentContext ctx) throws Exception {
      Transaction t =
          Cat.newTransaction(
              "phoenix-agent:" + ctx.getDomain(),
              ctx.getHost() + ":" + ctx.getWarType() + ":" + ctx.getVersion());

      int id = ctx.getDeployId();
      String domain = ctx.getDomain();
      String version = ctx.getVersion();
      String host = ctx.getHost();
      String type = ctx.getWarType();
      boolean skipTest = ctx.isSkipTest();
      String url = ctx.getConfigManager().getDeployUrl(type, host, id, domain, version, skipTest);
      String json = null;

      ctx.println(String.format("[INFO] Deploy URL: %s", url));
      ctx.print(
          "[INFO] Deploying phoenix kernel(%s) to host(%s) for deploy(%s) of domain(%s)  ... ",
          version, host, id, domain);

      boolean shouldRetry = false;

      try {
        json = ctx.openUrl(url);
        t.setStatus(Message.SUCCESS);
      } catch (Exception e) {
        t.setStatus(e);
        Cat.logError(e);

        ctx.println(e.toString());
        shouldRetry = true;
        return;
      } finally {
        t.complete();

        if (shouldRetry) {
          moveTo(ctx, UNREACHABLE);
        }
      }

      Response response;

      try {
        response = DefaultJsonParser.parse(json);
      } catch (Exception e) {
        ctx.println("Invalid JSON result:\r\n%s", json);
        return;
      }

      if ("ok".equals(response.getStatus())) {
        ctx.println("ACCEPTED");

        moveTo(ctx, SUBMITTED);
      } else {
        ctx.print(response.getStatus()).println();
        ctx.println(response.getMessage());

        moveTo(ctx, FAILED);
      }
    }