コード例 #1
0
ファイル: Nanny.java プロジェクト: jivesoftware/upena
  public synchronized String nanny(UbaCoordinate ubaCoordinate)
      throws InterruptedException, ExecutionException {

    long now = System.currentTimeMillis();
    if (restartAtTimestamp.get() > 0 && restartAtTimestamp.get() < now) {
      status.set("Restarting");
      deployLog.log("Nanny", "restart triggered by timestamp. " + this, null);
      if (kill()) {
        lastRestart.set(now);
        restartAtTimestamp.set(-1);
      }
    }

    try {
      if (destroyed.get()) {
        status.set("Destroying");
        deployLog.log("Nanny", "tried to check a service that has been destroyed. " + this, null);
        return deployLog.getState();
      }
      if (linkedBlockingQueue.size() == 0) {
        try {
          if (redeploy.get()) {
            status.set("Redeploy");
            NannyDestroyCallable destroyTask =
                new NannyDestroyCallable(
                    instanceDescriptor.get(),
                    instancePath,
                    deployLog,
                    healthLog,
                    invokeScript,
                    ubaLog);

            deployLog.log("Nanny", "destroying in preperation to redeploy. " + this, null);
            Future<Boolean> destroyFuture = threadPoolExecutor.submit(destroyTask);
            status.set("Destroying");
            if (destroyFuture.get()) {

              NannyDeployCallable deployTask =
                  new NannyDeployCallable(
                      repositoryProvider,
                      ubaCoordinate,
                      instanceDescriptor.get(),
                      instancePath,
                      deployLog,
                      healthLog,
                      deployableValidator,
                      invokeScript,
                      ubaLog);
              deployLog.log("Nanny", "redeploying. " + this, null);
              Future<Boolean> deployedFuture = threadPoolExecutor.submit(deployTask);
              try {
                status.set("Deploying");
                if (deployedFuture.get()) {
                  try {
                    try (FileWriter writer = new FileWriter(instancePath.deployLog())) {
                      for (String line : deployLog.peek()) {
                        writer.write(line);
                      }
                    }
                    redeploy.set(false);
                    status.set("Redeployed");
                    deployLog.log("Nanny", "successfully redeployed. " + this, null);
                  } catch (Exception x) {
                    status.set("Failed redeployed");
                    deployLog.log("Nanny", "failed to redeployed. " + this, x);
                  }
                }
              } catch (ExecutionException ee) {
                status.set("Unexpected state");
                deployLog.log("Nanny", "encountered an unexpected condition. " + this, ee);
              }
            }
          }

          NannyStatusCallable nannyTask =
              new NannyStatusCallable(
                  this,
                  status,
                  startupTimestamp,
                  instanceDescriptor.get(),
                  instancePath,
                  deployLog,
                  healthLog,
                  invokeScript,
                  ubaLog,
                  haveRunConfigExtractionCache);
          if (nannyTask.callable()) {
            threadPoolExecutor.submit(nannyTask);
          } else {
            deployLog.log("Nanny", "skipped status check. " + this, null);
          }

        } catch (InterruptedException | ExecutionException x) {
          deployLog.log("Nanny", "is already running. " + this, x);
        }
        return deployLog.getState();
      } else {
        return deployLog.getState();
      }
    } finally {
      deployLog.commit();
    }
  }
コード例 #2
0
ファイル: Nanny.java プロジェクト: jivesoftware/upena
 public NannyReport report() {
   return new NannyReport(deployLog.getState(), instanceDescriptor.get(), deployLog.commitedLog());
 }