コード例 #1
0
 /**
  * attempts to resolve hostnameTarget from origin
  *
  * @return null if it definitively can't be resolved, best-effort IP address if possible, or blank
  *     if we could not run ssh or make sense of the output
  */
 public static String getResolvedAddress(
     Entity entity, SshMachineLocation origin, String hostnameTarget) {
   ProcessTaskWrapper<Integer> task =
       SshTasks.newSshExecTaskFactory(origin, "ping -c 1 -t 1 " + hostnameTarget)
           .summary("checking resolution of " + hostnameTarget)
           .allowingNonZeroExitCode()
           .newTask();
   DynamicTasks.queueIfPossible(task).orSubmitAndBlock(entity).asTask().blockUntilEnded();
   if (task.asTask().isError()) {
     log.warn(
         "ping could not be run, at "
             + entity
             + " / "
             + origin
             + ": "
             + Tasks.getError(task.asTask()));
     return "";
   }
   if (task.getExitCode() == null || task.getExitCode() != 0) {
     if (task.getExitCode() != null && task.getExitCode() < 10) {
       // small number means ping failed to resolve or ping the hostname
       log.debug(
           "not able to resolve "
               + hostnameTarget
               + " from "
               + origin
               + " for "
               + entity
               + " because exit code was "
               + task.getExitCode());
       return null;
     }
     // large number means ping probably did not run
     log.warn(
         "ping not run as expected, at "
             + entity
             + " / "
             + origin
             + " (code "
             + task.getExitCode()
             + "):\n"
             + task.getStdout().trim()
             + " --- "
             + task.getStderr().trim());
     return "";
   }
   String out = task.getStdout();
   try {
     String line1 = Strings.getFirstLine(out);
     String ip = Strings.getFragmentBetween(line1, "(", ")");
     if (Strings.isNonBlank(ip)) return ip;
   } catch (Exception e) {
     Exceptions.propagateIfFatal(e);
     /* ignore non-parseable output */
   }
   if (out.contains("127.0.0.1")) return "127.0.0.1";
   return "";
 }
コード例 #2
0
  @Override
  public void customize() {
    newScript(CUSTOMIZING)
        .body
        .append(
            format("mkdir -p %s", getRunDir()),
            format("cp -R %s/dist/{conf,html,logs,sbin} %s", getExpandedInstallDir(), getRunDir()))
        .execute();

    // Install static content archive, if specified
    String archiveUrl = entity.getConfig(NginxController.STATIC_CONTENT_ARCHIVE_URL);
    if (Strings.isNonBlank(archiveUrl)) {
      getEntity().deploy(archiveUrl);
    }

    customizationCompleted = true;
    getEntity().doExtraConfigurationDuringStart();
  }
コード例 #3
0
 @SuppressWarnings("rawtypes")
 private static void addNamedAction(
     MutableMap.Builder<String, URI> lb,
     RendererHints.NamedAction na,
     Entity entity,
     Sensor<?> sensor) {
   if (na instanceof RendererHints.NamedActionWithUrl) {
     try {
       String v =
           ((RendererHints.NamedActionWithUrl) na).getUrl(entity, (AttributeSensor<?>) sensor);
       if (Strings.isNonBlank(v)) {
         String action = na.getActionName().toLowerCase();
         lb.putIfAbsent("action:" + action, URI.create(v));
       }
     } catch (Exception e) {
       Exceptions.propagateIfFatal(e);
       log.warn("Unable to make use of URL sensor " + sensor + " on " + entity + ": " + e);
     }
   }
 }
コード例 #4
0
 @Override
 public boolean isAuthenticated(HttpSession session) {
   if (session == null) return false;
   Object value = session.getAttribute(getAuthenticationKey());
   return Strings.isNonBlank(Strings.toString(value));
 }