ObjectNode toObjectNode(ClusterComputeResource ccr) { ObjectNode n = mapper.createObjectNode().put("vmw_name", ccr.getName()).put("id", computeUniqueId(ccr.getMOR())); return n; }
/** * Returns a JSON-formatted array with the clusters list for use with * Zabbix low-level discovery */ private void getClusters(PrintWriter out) throws IOException { try { ManagedEntity[] cl = getManagedEntities("ClusterComputeResource"); JsonArray jArray = new JsonArray(); for (int j = 0; j < cl.length; j++) { ClusterComputeResource c = (ClusterComputeResource) cl[j]; String name = c.getName(); ComputeResourceSummary s = c.getSummary(); JsonObject jObject = new JsonObject(); jObject.addProperty("{#CLUSTER}", name); jArray.add(jObject); } JsonObject jOutput = new JsonObject(); jOutput.add("data", jArray); out.print(jOutput); out.flush(); } catch (Exception ex) { LOG.error("An error occurred : " + ex.toString()); } }
public void scanAllClusters() { VMWareQueryTemplate t = new VMWareQueryTemplate(getServiceInstance()); for (ClusterComputeResource ccr : t.findAllClusters()) { try { scanCluster(ccr); } catch (RuntimeException e) { logger.warn("scan cluster failed: " + ccr.getName(), e); } } }
protected void scanCluster(ClusterComputeResource cluster) { logger.info("scanning cluster={}",cluster.getName()); ObjectNode n = toObjectNode(cluster); updateCluster(n); for (HostSystem host : cluster.getHosts()) { scanHost(host, false); updateClusterHostRelationship(cluster, host); } }
protected void updateClusterHostRelationship(ClusterComputeResource cluster, HostSystem host) { logger.debug("updating relationship between cluster={} and host={}", cluster.getName(), host.getName()); String cypher = "match (h {id:{hostId} }), (c:VMWareCluster {id: {clusterId}}) MERGE (c)-[r:CONTAINS]->(h) ON CREATE SET r.updateTs=timestamp(),r.createTs=timestamp() ON MATCH SET r.updateTs=timestamp() return r"; getProjector().getNeoRxClient().execCypher(cypher, "hostId", getUniqueId(host), "clusterId", getUniqueId(cluster)); }
protected void updateDatacenterClusterRelationship(Datacenter dc, ClusterComputeResource cluster) { logger.debug("updating relationship between dc={} and cluster={}", dc.getName(), cluster.getName()); String cypher = "match (d:VMWareDatacenter {id:{datacenterId} }), (c:VMWareCluster {id: {clusterId}}) MERGE (d)-[r:CONTAINS]->(c) ON CREATE SET r.updateTs=timestamp(),r.createTs=timestamp() ON MATCH SET r.updateTs=timestamp() return r"; getProjector().getNeoRxClient().execCypher(cypher, "datacenterId", computeUniqueId(dc.getMOR()), "clusterId", computeUniqueId(cluster.getMOR())); JsonNode vcenter = ensureController(); String vcenterid = vcenter.get("id").asText(); cypher = "match (c:ComputeController:VMWareVCenter {id:{vcenterId}}), (dc:VMWareDatacenter {id:{datacenterId} }) MERGE (c)-[r:MANAGES]->(dc) ON CREATE SET r.updateTs=timestamp() ON MATCH SET r.updateTs=timestamp() return r"; getProjector().getNeoRxClient().execCypher(cypher, "vcenterId", vcenterid, "datacenterId", computeUniqueId(dc.getMOR())); }