Пример #1
0
  public void updateForPage(String aName) {
    // KH - we should probably set the instance information as we get the
    // responses, to avoid waiting, then doing it in serial! (not that it's
    // _that_ slow)
    MSiteConfig siteConfig = WOTaskdHandler.siteConfig();
    startReading();
    try {
      aName = ERXStringUtilities.lastPropertyKeyInKeyPath(aName);
      if (siteConfig.hostArray().count() != 0) {
        if (ApplicationsPage.class.getName().endsWith(aName)
            && (siteConfig.applicationArray().count() != 0)) {

          for (Enumeration e = siteConfig.applicationArray().objectEnumerator();
              e.hasMoreElements(); ) {
            MApplication anApp = (MApplication) e.nextElement();
            anApp.setRunningInstancesCount(0);
          }
          NSArray<MHost> hostArray = siteConfig.hostArray();
          getApplicationStatusForHosts(hostArray);
        } else if (AppDetailPage.class.getName().endsWith(aName)) {
          NSArray<MHost> hostArray = siteConfig.hostArray();

          getInstanceStatusForHosts(hostArray);
        } else if (HostsPage.class.getName().endsWith(aName)) {
          NSArray<MHost> hostArray = siteConfig.hostArray();

          getHostStatusForHosts(hostArray);
        }
      }
    } finally {
      endReading();
    }
  }
Пример #2
0
  public void getApplicationStatusForHosts(NSArray<MHost> hostArray) {

    WOResponse[] responses = sendQueryToWotaskds("APPLICATION", hostArray);

    NSMutableArray errorArray = new NSMutableArray();
    NSDictionary applicationResponseDictionary;
    NSDictionary queryResponseDictionary;
    NSArray responseArray = null;
    NSDictionary responseDictionary = null;
    for (int i = 0; i < responses.length; i++) {
      if ((responses[i] == null) || (responses[i].content() == null)) {
        queryResponseDictionary = emptyResponse;
      } else {
        try {
          queryResponseDictionary =
              (NSDictionary) new _JavaMonitorDecoder().decodeRootObject(responses[i].content());
        } catch (WOXMLException wxe) {
          NSLog.err.appendln(
              "MonitorComponent pageWithName(ApplicationsPage) Error decoding response: "
                  + responses[i].contentString());
          queryResponseDictionary = responseParsingFailed;
        }
      }
      getGlobalErrorFromResponse(queryResponseDictionary, errorArray);

      applicationResponseDictionary =
          (NSDictionary) queryResponseDictionary.valueForKey("queryWotaskdResponse");
      if (applicationResponseDictionary != null) {
        responseArray = (NSArray) applicationResponseDictionary.valueForKey("applicationResponse");
        if (responseArray != null) {
          for (int j = 0; j < responseArray.count(); j++) {
            responseDictionary = (NSDictionary) responseArray.objectAtIndex(j);
            String appName = (String) responseDictionary.valueForKey("name");
            Integer runningInstances = (Integer) responseDictionary.valueForKey("runningInstances");
            MApplication anApplication = siteConfig().applicationWithName(appName);
            if (anApplication != null) {
              anApplication.setRunningInstancesCount(
                  anApplication.runningInstancesCount() + runningInstances.intValue());
            }
          }
        }
      }
    } // for
    if (NSLog.debugLoggingAllowedForLevelAndGroups(
        NSLog.DebugLevelDetailed, NSLog.DebugGroupDeployment))
      NSLog.debug.appendln("##### pageWithName(ApplicationsPage) errors: " + errorArray);
    mySession().addObjectsFromArrayIfAbsentToErrorMessageArray(errorArray);
  }
Пример #3
0
 public void sendUpdateApplicationAndInstancesToWotaskds(
     MApplication changedApplication, NSArray wotaskdArray) {
   WOResponse[] responses =
       sendRequest(
           createUpdateRequestDictionary(
               null, null, changedApplication, changedApplication.instanceArray(), "configure"),
           wotaskdArray,
           true);
   NSDictionary[] responseDicts = generateResponseDictionaries(responses);
   getUpdateErrors(responseDicts, "configure", false, true, true, false);
 }
Пример #4
0
  private String _generateModRewriteConfig() {
    StringBuilder result = new StringBuilder();
    result.append("This is the content of the apache conf file\n\n\n");
    result.append("#\n");
    result.append("# Rewrite Engine\n");
    result.append("#\n");
    result.append("RewriteEngine On\n\n");
    result.append("# Rewrite rules\n");

    NSMutableArray<String> rewriteRules = new NSMutableArray<String>();
    NSMutableArray<String> properitesRules = new NSMutableArray<String>();

    for (Enumeration<MApplication> e = siteConfig().applicationArray().objectEnumerator();
        e.hasMoreElements(); ) {
      MApplication anApp = e.nextElement();
      anApp.extractAdaptorValuesFromSiteConfig();

      String tmpAdaptor = siteConfig().woAdaptor();
      tmpAdaptor = StringUtils.removeEnd(tmpAdaptor, "/");

      NSArray<String> tmpPath = NSArray.componentsSeparatedByString(tmpAdaptor, "/");

      int count = tmpPath.count();
      String adaptorPath = "/" + tmpPath.get(count - 2) + "/" + tmpPath.get(count - 1) + "/";

      rewriteRules.add(
          "RewriteRule ^/"
              + anApp.name().toLowerCase()
              + "(.*)$ "
              + adaptorPath
              + anApp.name()
              + ".woa");

      properitesRules.add(
          "er.extensions.ERXApplication.replaceApplicationPath.pattern="
              + adaptorPath
              + anApp.name()
              + ".woa");
      properitesRules.add(
          "er.extensions.ERXApplication.replaceApplicationPath.replace=/"
              + anApp.name().toLowerCase());
    }

    result.append(rewriteRules.componentsJoinedByString("\n"));
    result.append("\n");
    result.append("\n");
    result.append("\n");
    result.append("This is the content of the application properties file\n\n\n");
    result.append(properitesRules.componentsJoinedByString("\n"));

    result.append("\n");

    result.append('\n');
    return result.toString();
  }
Пример #5
0
  /* ******** Common Functionality ********* */
  private static NSMutableDictionary createUpdateRequestDictionary(
      MSiteConfig _Config,
      MHost _Host,
      MApplication _Application,
      NSArray _InstanceArray,
      String requestType) {
    NSMutableDictionary monitorRequest = new NSMutableDictionary(1);
    NSMutableDictionary updateWotaskd = new NSMutableDictionary(1);
    NSMutableDictionary requestTypeDict = new NSMutableDictionary();

    if (_Config != null) {
      NSDictionary site = new NSDictionary(_Config.values());
      requestTypeDict.takeValueForKey(site, "site");
    }
    if (_Host != null) {
      NSArray hostArray = new NSArray(_Host.values());
      requestTypeDict.takeValueForKey(hostArray, "hostArray");
    }
    if (_Application != null) {
      NSArray applicationArray = new NSArray(_Application.values());
      requestTypeDict.takeValueForKey(applicationArray, "applicationArray");
    }
    if (_InstanceArray != null) {
      int instanceCount = _InstanceArray.count();
      NSMutableArray instanceArray = new NSMutableArray(instanceCount);
      for (int i = 0; i < instanceCount; i++) {
        MInstance anInst = (MInstance) _InstanceArray.objectAtIndex(i);
        instanceArray.addObject(anInst.values());
      }
      requestTypeDict.takeValueForKey(instanceArray, "instanceArray");
    }

    updateWotaskd.takeValueForKey(requestTypeDict, requestType);
    monitorRequest.takeValueForKey(updateWotaskd, "updateWotaskd");

    return monitorRequest;
  }
Пример #6
0
  private String _generateModProxyConfig() {
    StringBuilder result = new StringBuilder();

    result.append("#\n");
    result.append("# Common configuration (if not already set)\n");
    result.append("#\n");
    result.append("ProxyRequests Off\nProxyVia Full\n");
    result.append("#\n");
    result.append("# Give us a name\n");
    result.append("#\n");
    result.append("RequestHeader append x-webobjects-adaptor-version \"mod_proxy\"\n\n\n");

    result.append("#\n");
    result.append("# Balancer routes\n");
    result.append("#\n");

    for (Enumeration<MApplication> e = siteConfig().applicationArray().objectEnumerator();
        e.hasMoreElements(); ) {
      MApplication anApp = e.nextElement();
      anApp.extractAdaptorValuesFromSiteConfig();

      String tmpAdaptor = siteConfig().woAdaptor();
      tmpAdaptor = StringUtils.removeEnd(tmpAdaptor, "/");

      NSArray<String> tmpPath = NSArray.componentsSeparatedByString(tmpAdaptor, "/");

      int count = tmpPath.count();
      String adaptorPath = "/" + tmpPath.get(count - 2) + "/" + tmpPath.get(count - 1) + "/";

      result.append("<Proxy balancer://" + anApp.name() + ".woa>\n");

      NSMutableArray<String> reversePathes = new NSMutableArray<String>();

      for (Enumeration<MInstance> e2 = anApp.instanceArray().objectEnumerator();
          e2.hasMoreElements(); ) {
        MInstance anInst = e2.nextElement();

        anInst.extractAdaptorValuesFromApplication();

        String host = anInst.values().valueForKey("hostName").toString();
        String port = anInst.values().valueForKey("port").toString();

        String url = "http://" + host + ":" + port + adaptorPath + anApp.name() + ".woa";

        result.append("\tBalancerMember ");
        result.append(url);
        result.append(" route=");
        result.append(_proxyBalancerRoute(anApp.name(), host, port));
        result.append('\n');

        reversePathes.add(url);
      }

      result.append("</Proxy>\n");
      result.append("ProxyPass ");
      result.append(adaptorPath);
      result.append(anApp.name());
      result.append(".woa balancer://");
      result.append(anApp.name());
      result.append(".woa stickysession=");
      result.append(_proxyBalancerCookieName(anApp.name()));
      result.append(" nofailover=On\n");

      for (int i = 0; i < reversePathes.count(); i++) {
        String url = reversePathes.objectAtIndex(i);
        result.append("ProxyPassReverse / ");
        result.append(url);
        result.append('\n');
      }
      result.append('\n');
    }

    result.append("#\n");
    result.append("# Balancer configuration\n");
    result.append("#\n");
    for (Enumeration<MApplication> e = siteConfig().applicationArray().objectEnumerator();
        e.hasMoreElements(); ) {
      MApplication anApp = e.nextElement();
      anApp.extractAdaptorValuesFromSiteConfig();
      String name = anApp.name();
      result.append("ProxySet balancer://" + name + ".woa");
      if (timeout != null && timeout.intValue() > 0) {
        result.append(" timeout=");
        result.append(timeout);
      }
      if (loadBalancer != null) {
        result.append(" lbmethod=");
        result.append(loadBalancer);
      } else {
        result.append(" lbmethod=byrequests");
      }
      result.append('\n');
    }

    result.append("#\n");
    result.append("#\n");
    result.append("#\n");

    result.append('\n');
    return result.toString();
  }