Пример #1
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);
        }
      }
    }
Пример #2
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);
      }
    }