Пример #1
0
  /** The plugin provides a set of logs associated with each identified cluster */
  public ProvidedObject[] getProvidedObjects() {
    ProvidedObject[] p = null;
    ArrayList a = new ArrayList();
    if (selectedCluster != null) {
      if (selectedCluster.getHeuristicsNet() != null) {
        a.add(
            new ProvidedObject(
                "Heuristics net with " + selectedCluster.getName(),
                new Object[] {selectedCluster.getHeuristicsNet(), selectedCluster.getLog()}));
        a.add(
            new ProvidedObject(
                "Heuristics net with whole log",
                new Object[] {selectedCluster.getHeuristicsNet(), root.getLog()}));
      }
    }

    /*
     * if (root.getChildren().size()>0){ for (int
     * i=0;i<root.getChildren().size();i++){ Cluster
     * c=(Cluster)root.getChildren().get(i); LogReader logc=c.getLog();
     * a.add(new ProvidedObject(c.getName(), new Object[] { logc })); } }
     */
    if (selectedCluster != null && selectedCluster.getHeuristicsNet() == null) {
      Cluster c = selectedCluster;
      LogReader logc = c.getLog();
      a.add(new ProvidedObject(c.getName(), new Object[] {logc}));
    }
    p = new ProvidedObject[a.size()];
    for (int i = 0; i < a.size(); i++) {
      p[i] = (ProvidedObject) a.get(i);
    }
    return p;
  }
 // ----------------------------------------------------------------------------------------
 public void handleCluster(String source, Cluster cluster) {
   System.out.println(
       "cluster ready, rowNames "
           + cluster.getRowNames().length
           + " columnNames "
           + cluster.getColumnNames().length);
   this.clusterName = cluster.getName();
   this.clusterRowNames = cluster.getRowNames();
   this.clusterColumnNames = cluster.getColumnNames();
   defaultSpecies = cluster.getSpecies();
 }
  protected void createClustersTable() throws UnsupportedEncodingException {
    table().attr("cellpadding", "0", "cellspacing", "0", "border", "0", "class", "display");
    thead();
    tr();
    createThs("Name", "#Nodes", "Health");
    end();
    end();
    tbody();
    for (Cluster c : router.getClusterManager().getClusters()) {
      tr();
      td();
      createLink(c.getName(), "clusters", "show", createQueryString("cluster", c.getName()));
      end();

      createTds(
          String.valueOf(router.getClusterManager().getAllNodesByCluster(c.getName()).size()),
          getFormatedHealth(c.getName()));
      end();
    }
    end();
    end();
  }
Пример #4
0
  /** Saves data about clusters and hosts to the supplied output stream. */
  public String saveXML(final OutputStream outputStream, final boolean saveAll) throws IOException {
    final String encoding = "UTF-8";
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;

    try {
      db = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException pce) {
      assert false;
    }
    final Document doc = db.newDocument();
    final Element root = (Element) doc.appendChild(doc.createElement("drbdgui"));
    if (Tools.getConfigData().getLoginSave()) {
      final String downloadUser = Tools.getConfigData().getDownloadUser();
      final String downloadPasswd = Tools.getConfigData().getDownloadPassword();
      if (downloadUser != null && downloadPasswd != null) {
        root.setAttribute(DOWNLOAD_USER_ATTR, downloadUser);
        root.setAttribute(DOWNLOAD_PASSWD_ATTR, downloadPasswd);
      }
    }
    final Element hosts = (Element) root.appendChild(doc.createElement("hosts"));
    for (final Host host : Tools.getConfigData().getHosts().getHostSet()) {
      if (!saveAll && !host.isSavable()) {
        continue;
      }
      host.setSavable(true);
      final String hostName = host.getHostname();
      final String ip = host.getIp();
      final String username = host.getUsername();
      final String sshPort = host.getSSHPort();
      final Boolean useSudo = host.isUseSudo();
      final String color = host.getColor();
      final Element hostNode = (Element) hosts.appendChild(doc.createElement(HOST_NODE_STRING));
      hostNode.setAttribute(HOST_NAME_ATTR, hostName);
      hostNode.setAttribute(HOST_SSHPORT_ATTR, sshPort);
      if (color != null) {
        hostNode.setAttribute(HOST_COLOR_ATTR, color);
      }
      if (useSudo != null && useSudo) {
        hostNode.setAttribute(HOST_USESUDO_ATTR, "true");
      }
      if (ip != null) {
        final Node ipNode = (Element) hostNode.appendChild(doc.createElement("ip"));

        ipNode.appendChild(doc.createTextNode(ip));
      }
      if (username != null) {
        final Node usernameNode = (Element) hostNode.appendChild(doc.createElement("user"));

        usernameNode.appendChild(doc.createTextNode(username));
      }
    }
    final Element clusters = (Element) root.appendChild(doc.createElement("clusters"));

    final Set<Cluster> clusterSet = Tools.getConfigData().getClusters().getClusterSet();
    for (final Cluster cluster : clusterSet) {
      if (!saveAll && !cluster.isSavable()) {
        continue;
      }
      cluster.setSavable(true);
      final String clusterName = cluster.getName();
      final Element clusterNode = (Element) clusters.appendChild(doc.createElement("cluster"));
      clusterNode.setAttribute(CLUSTER_NAME_ATTR, clusterName);
      for (final Host host : cluster.getHosts()) {
        final String hostName = host.getHostname();
        final Element hostNode =
            (Element) clusterNode.appendChild(doc.createElement(HOST_NODE_STRING));
        hostNode.appendChild(doc.createTextNode(hostName));
      }
    }

    final TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = null;
    try {
      t = tf.newTransformer();
      t.setOutputProperty(OutputKeys.INDENT, "yes");
      t.setOutputProperty(OutputKeys.METHOD, "xml");
      t.setOutputProperty(OutputKeys.ENCODING, encoding);
    } catch (TransformerConfigurationException tce) {
      assert false;
    }
    final DOMSource doms = new DOMSource(doc);
    final StreamResult sr = new StreamResult(outputStream);
    try {
      t.transform(doms, sr);
    } catch (TransformerException te) {
      final IOException ioe = new IOException();
      ioe.initCause(te);
      throw ioe;
    }
    return "";
  }
  /**
   * @param args
   * @throws InvalidEducationValueException
   */
  public static void main(String[] args) throws InvalidEducationValueException {
    final ClusterNumberFormat cnf = new ClusterNumberFormat();
    final ClusterTestData ctd = new ClusterTestData();

    Cluster tempClusterI = null;
    Cluster tempClusterJ = null;
    Cluster minClusterA = null;
    Cluster minClusterB = null;
    Instance tempClusterIInstance = null;
    Instance tempClusterJInstance = null;
    Instance minInstanceA = null;
    Instance minInstanceB = null;

    double dist = 0.0;
    double minDist = Double.POSITIVE_INFINITY;

    ArrayList<Cluster> clusters = ctd.getClusters();

    while (clusters.size() > 1) {
      for (int i = 0; i < clusters.size(); i++) {
        for (int j = i + 1; j < clusters.size(); j++) {
          tempClusterI = clusters.get(i);
          tempClusterJ = clusters.get(j);

          System.out.println(
              "Cluster "
                  + tempClusterI.getName()
                  + " has Instance(s) "
                  + tempClusterI.getInstancesNameSet());
          System.out.println(
              "Cluster "
                  + tempClusterJ.getName()
                  + " has Instance(s) "
                  + tempClusterJ.getInstancesNameSet());

          for (int k = 0; k < tempClusterI.size(); k++) {
            for (int l = 0; l < tempClusterJ.size(); l++) {
              tempClusterIInstance = tempClusterI.get(k);
              tempClusterJInstance = tempClusterJ.get(l);

              dist = ClusterCalculation.distance(tempClusterIInstance, tempClusterJInstance);

              System.out.println(
                  "   DIST("
                      + tempClusterIInstance.getName()
                      + ","
                      + tempClusterJInstance.getName()
                      + ") = "
                      + cnf.format(dist));

              if (dist < minDist) {
                minDist = dist;
                minClusterA = tempClusterI;
                minInstanceA = tempClusterIInstance;
                minClusterB = tempClusterJ;
                minInstanceB = tempClusterJInstance;
              }
            }
          }
        }
      }

      System.out.println(
          "*** Minimum exists between Instance "
              + minInstanceA.getName()
              + " of Cluster "
              + minClusterA.getName()
              + " and Instance "
              + minInstanceB.getName()
              + " of Cluster "
              + minClusterB.getName()
              + " with a distance of "
              + cnf.format(minDist));
      System.out.print(
          "  * Merging cluster "
              + minClusterB.getName()
              + " into cluster "
              + minClusterA.getName()
              + ": ");

      // minClusterA and minClusterB are the two clusters with the closest member Instance(s).
      // Merge B into A and remove B from the list of Clusters.
      minClusterA.merge(minClusterB);
      clusters.remove(minClusterB);

      System.out.println(
          "Cluster "
              + minClusterA.getName()
              + " now contains instance(s) "
              + minClusterA.getInstancesNameSet());

      minDist = Double.POSITIVE_INFINITY;
    }
  }