クラスタサマリ情報に対してトポロジ名を指定してトポロジIDを抽出する。

@param clusterSummary クラスタサマリ情報
@param topologyName トポロジ名称
@return トポロジ名に対応するトポロジID。存在しない場合はnullを返す。
174194
public static String extractStormTopologyId(ClusterSummary clusterSummary, String topologyName)
    {

        List<TopologySummary> topologyList = clusterSummary.get_topologies();

        for (TopologySummary targetTopology : topologyList)
        {
            // トポロジ名が一致しているトポロジ情報のIDを取得
            if (StringUtils.equals(topologyName, targetTopology.get_name()) == true)
            {
                return targetTopology.get_id();
            }
        }

        return null;
    }
629726
@Override
  public String describeClusterName() throws HectorException {
    Operation<String> op = new Operation<String>(OperationType.META_READ, getCredentials()) {
      @Override
      public String execute(Cassandra.Client cassandra) throws HectorException {
        try {
          return cassandra.describe_cluster_name();
        } catch (Exception e) {
          throw xtrans.translate(e);
        }
      }
    };
    connectionManager.operateWithFailover(op);
    return op.getResult();
  }
570975
public final CellName clusteringKey(CellName cellName) {
        CBuilder builder = cellNameType.builder();
        for (int i = 0; i < metadata.clusteringColumns().size(); i++) {
            ByteBuffer component = cellName.get(i);
            builder.add(component);
        }
        Composite prefix = builder.build();
        return cellNameType.rowMarker(prefix);
    }
787269
private ArrayList<String> getNameInCluster(Cluster cluster) {
    ArrayList<String> itemsInCluster = new ArrayList<String>();

    String nodeName;
    if (cluster.isLeaf()) {
      nodeName = cluster.getName();
      itemsInCluster.add(nodeName);
    }
    else {
      // String[] clusterName = cluster.getName().split("#");
      // nodeName = clusterName[1];
    }

    for (Cluster child : cluster.getChildren()) {
      ArrayList<String> childrenNames = getNameInCluster(child);
      itemsInCluster.addAll(childrenNames);
    }
    return itemsInCluster;
  }
1129637
protected Clustering<?> runClusteringAlgorithm(ResultHierarchy hierarchy, Result parent, DBIDs ids, DataStore<DoubleVector> store, int dim, String title) {
    SimpleTypeInformation<DoubleVector> t = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim);
    Relation<DoubleVector> sample = new MaterializedRelation<>(t, ids, title, store);
    ProxyDatabase d = new ProxyDatabase(ids, sample);
    Clustering<?> clusterResult = samplesAlgorithm.run(d);
    d.getHierarchy().remove(sample);
    d.getHierarchy().remove(clusterResult);
    hierarchy.add(parent, sample);
    hierarchy.add(sample, clusterResult);
    return clusterResult;
  }
935857
def describe_cluster_name(self, ):
    
    self._seqid += 1
    d = self._reqs[self._seqid] = defer.Deferred()
    self.send_describe_cluster_name()
    return d
813360
public ListClustersResponse getClusters() {
    logger.info("Reading clusters.");
    return client.listCluster(
      ListClustersRequest.newBuilder().setParent(instanceName.getInstanceName()).build());
  }
288752
public String getNodeId(final String clusterId, final HttpServletRequest request)
    {
        if (clusterId == null)
        {
            return null;
        }
        if (_workerName != null)
        {
            return clusterId + '.' + _workerName;
        }
        return clusterId;
    }
701779
public static List<String> getKeyListFromId(NimbusData data, String topologyId)
            throws IOException, KeyNotFoundException {
        List<String> keys = new ArrayList<>();
        keys.add(StormConfig.master_stormjar_key(topologyId));
        keys.add(StormConfig.master_stormcode_key(topologyId));
        keys.add(StormConfig.master_stormconf_key(topologyId));
        keys.add(StormConfig.master_stormcode_bak_key(topologyId));
        keys.add(StormConfig.master_stormjar_bak_key(topologyId));

        Map stormConf = null;
        try {
            stormConf = StormConfig.read_nimbus_topology_conf(topologyId, data.getBlobStore());
        } catch (Exception e) {
            LOG.warn("can't find conf of topology {}, {}", topologyId, e);
        }
        if (stormConf != null) {
            List<String> libs = (List<String>) stormConf.get(GenericOptionsParser.TOPOLOGY_LIB_NAME);
            if (libs != null) {
                for (String libName : libs) {
                    keys.add(StormConfig.master_stormlib_key(topologyId, libName));
                }
            }
        } else {
            //topologyId + "-stormconf.ser maybe be clean
            try {
                String filterName = topologyId + "-lib-";
                List<String> blobKeys = data.getStormClusterState().blobstoreInfo(null);
                for (String blobkey : blobKeys) {
                    if (blobkey.startsWith(filterName))
                        keys.add(blobkey);
                }
            } catch (Exception e) {
                LOG.warn("error!!!", e);
            }
        }
        return keys;
    }
760726
@Override
    public ClusterSummary getClusterInfo() throws TException {
        long start = System.nanoTime();
        try {
            StormClusterState stormClusterState = data.getStormClusterState();

            Map<String, Assignment> assignments = new HashMap<>();

            // get TopologySummary
            List<TopologySummary> topologySummaries = NimbusUtils.getTopologySummary(stormClusterState, assignments);

            // all supervisors
            Map<String, SupervisorInfo> supervisorInfos = Cluster.get_all_SupervisorInfo(stormClusterState, null);

            // generate SupervisorSummaries
            List<SupervisorSummary> supervisorSummaries = NimbusUtils.mkSupervisorSummaries(supervisorInfos, assignments);

            NimbusSummary nimbusSummary = NimbusUtils.getNimbusSummary(stormClusterState, supervisorSummaries, data);

            return new ClusterSummary(nimbusSummary, supervisorSummaries, topologySummaries);
        } catch (TException e) {
            LOG.info("Failed to get ClusterSummary ", e);
            throw e;
        } catch (Exception e) {
            LOG.info("Failed to get ClusterSummary ", e);
            throw new TException(e);
        } finally {
            long end = System.nanoTime();
            SimpleJStormMetric.updateNimbusHistogram("getClusterInfo", (end - start) / TimeUtils.NS_PER_US);
        }
    }
1018903
public JStormCache putMetricData(String topologyId, TopologyMetric tpMetric) {
        // map<key, [ts, metric_info]>
        Map<String, Object> batchData = new HashMap<>();
        long ts = System.currentTimeMillis();
        int tp = 0, comp = 0, compStream = 0, task = 0, stream = 0, worker = 0, netty = 0;
        if (tpMetric.get_componentMetric().get_metrics_size() > 0) {
            batchData.put(METRIC_DATA_30M_COMPONENT + topologyId, new Object[]{ts, tpMetric.get_componentMetric()});
            comp += tpMetric.get_componentMetric().get_metrics_size();
        }
        if (tpMetric.is_set_compStreamMetric() && tpMetric.get_compStreamMetric().get_metrics_size() > 0) {
            batchData.put(METRIC_DATA_30M_COMP_STREAM + topologyId, new Object[]{ts, tpMetric.get_compStreamMetric()});
            compStream += tpMetric.get_compStreamMetric().get_metrics_size();
        }
        if (tpMetric.get_taskMetric().get_metrics_size() > 0) {
            tryCombineMetricInfo(METRIC_DATA_30M_TASK + topologyId, tpMetric.get_taskMetric(), MetaType.TASK, ts);
            task += tpMetric.get_taskMetric().get_metrics_size();
        }
        if (tpMetric.get_streamMetric().get_metrics_size() > 0) {
            tryCombineMetricInfo(METRIC_DATA_30M_STREAM + topologyId, tpMetric.get_streamMetric(), MetaType.STREAM, ts);
            stream += tpMetric.get_streamMetric().get_metrics_size();
        }
        if (tpMetric.get_workerMetric().get_metrics_size() > 0) {
            tryCombineMetricInfo(METRIC_DATA_30M_WORKER + topologyId, tpMetric.get_workerMetric(), MetaType.WORKER, ts);
            worker += tpMetric.get_workerMetric().get_metrics_size();
        }
        if (tpMetric.get_nettyMetric().get_metrics_size() > 0) {
            tryCombineMetricInfo(METRIC_DATA_30M_NETTY + topologyId, tpMetric.get_nettyMetric(), MetaType.NETTY, ts);
            netty += tpMetric.get_nettyMetric().get_metrics_size();
        }

        // store 30 snapshots of topology metrics
        if (tpMetric.get_topologyMetric().get_metrics_size() > 0) {
            String keyPrefix = METRIC_DATA_30M_TOPOLOGY + topologyId + "-";
            int page = getRingAvailableIndex(keyPrefix);

            batchData.put(keyPrefix + page, new Object[]{ts, tpMetric.get_topologyMetric()});
            tp += tpMetric.get_topologyMetric().get_metrics_size();
        }
        LOG.info("caching metric data for topology:{},tp:{},comp:{},comp_stream:{},task:{},stream:{},worker:{},netty:{},cost:{}",
                topologyId, tp, comp, compStream, task, stream, worker, netty, System.currentTimeMillis() - ts);

        return putBatch(batchData);
    }
693982
public static void doMetaSetPair(AdminClient adminClient,
                                         List<Integer> nodeIds,
                                         Object clusterValue,
                                         Object storesValue) {
            VectorClock updatedClusterVersion = null;
            VectorClock updatedStoresVersion = null;
            for(Integer nodeId: nodeIds) {
                if(updatedClusterVersion == null && updatedStoresVersion == null) {
                    updatedClusterVersion = (VectorClock) adminClient.metadataMgmtOps.getRemoteMetadata(nodeId,
                                                                                                        MetadataStore.CLUSTER_KEY)
                                                                                     .getVersion();
                    updatedStoresVersion = (VectorClock) adminClient.metadataMgmtOps.getRemoteMetadata(nodeId,
                                                                                                       MetadataStore.STORES_KEY)
                                                                                    .getVersion();
                } else {
                    updatedClusterVersion = updatedClusterVersion.merge((VectorClock) adminClient.metadataMgmtOps.getRemoteMetadata(nodeId,
                                                                                                                                    MetadataStore.CLUSTER_KEY)
                                                                                                                 .getVersion());
                    updatedStoresVersion = updatedStoresVersion.merge((VectorClock) adminClient.metadataMgmtOps.getRemoteMetadata(nodeId,
                                                                                                                                  MetadataStore.STORES_KEY)
                                                                                                               .getVersion());
                }

                // TODO: This will work for now but we should take a step back
                // and
                // think about a uniform clock for the metadata values.
                updatedClusterVersion = updatedClusterVersion.incremented(nodeIds.iterator().next(),
                                                                          System.currentTimeMillis());
                updatedStoresVersion = updatedStoresVersion.incremented(nodeIds.iterator().next(),
                                                                        System.currentTimeMillis());
            }
            adminClient.metadataMgmtOps.updateRemoteMetadataPair(nodeIds,
                                                                 MetadataStore.CLUSTER_KEY,
                                                                 Versioned.value(clusterValue.toString(),
                                                                                 updatedClusterVersion),
                                                                 MetadataStore.STORES_KEY,
                                                                 Versioned.value(storesValue.toString(),
                                                                                 updatedStoresVersion));
        }
334123
public final CellName clusteringKey(Document document) {
        String string = document.get(FIELD_NAME);
        ByteBuffer bb = ByteBufferUtils.fromString(string);
        return cellNameType.cellFromByteBuffer(bb);
    }
620526
public Scheduler.SchedulerLocation getSchedulerLocation(String topologyName) {
    return awaitResult(delegate.getSchedulerLocation(null, topologyName));
  }
949819
public TopologyExecutionStatus getExecution(String topologyName, String nimbusHost,
            int nimbusPort, int interval, int number) throws ConnectFailException
    {

        NimbusClientFactory factory = new NimbusClientFactory();
        // RuntimeExceptionが発生
        NimbusClient nimbusClient = factory.createClient(nimbusHost, nimbusPort);
        Nimbus.Client client = nimbusClient.getClient();
        ClusterSummary clusterSummary = null;
        try
        {
            clusterSummary = client.getClusterInfo();
        }
        catch (org.apache.thrift7.TException ex)
        {
            throw new ConnectFailException(ex);
        }

        String topologyId = StormSummaryExtractor.extractStormTopologyId(clusterSummary,
                topologyName);

        if (topologyId == null)
        {
            return TopologyExecutionStatus.NOT_ALIVED;
        }

        TopologyExecutionCount compareCount = null;

        for (int getCount = 0; getCount < number; getCount++)
        {
            TopologyInfo topologyInfo = null;

            try
            {
                topologyInfo = client.getTopologyInfo(topologyId);
            }
            catch (NotAliveException ex)
            {
                return TopologyExecutionStatus.NOT_ALIVED;
            }
            catch (org.apache.thrift7.TException ex)
            {
                throw new ConnectFailException(ex);
            }

            TopologyExecutionCount nowCount = StormSummaryExtractor.convertToTotalCount(topologyInfo);
            // 初回の情報取得の場合、初回の取得結果を比較対象として設定
            if (compareCount == null)
            {
                compareCount = nowCount;
            }
            else
            {
                // 文字列表現が異なる場合、処理が継続しているため、ログ出力して「処理中」と返す。
                if (StringUtils.equals(compareCount.toString(), nowCount.toString()) == false)
                {
                    return TopologyExecutionStatus.EXECUTING;
                }
            }

            try
            {
                TimeUnit.MILLISECONDS.sleep(interval);
            }
            catch (InterruptedException ex)
            {
                continue;
            }
        }

        // 指定回数変化がなかった場合、停止として扱う。
        return TopologyExecutionStatus.STOP;
    }
19637
public GeometryCollection generateVoronoi(int outputDimension) throws TopologyException {
        GeometryFactory geometryFactory = inputTriangles.getFactory();
        if(triangleNeighbors == null || triangleNeighbors.length == 0) {
            return geometryFactory.createMultiLineString(new LineString[0]);
        }
        Coordinate[] triangleCircumcenter = new Coordinate[inputTriangles.getNumGeometries()];
        if(outputDimension == 2 && envelope == null) {
            List<Polygon> polygons = new ArrayList<Polygon>(triangleCircumcenter.length);
            Set<Integer> processedVertex = new HashSet<Integer>();
            for (int idgeom = 0; idgeom < triangleCircumcenter.length; idgeom++) {
                    Geometry geomItem = inputTriangles.getGeometryN(idgeom);
                    if (geomItem instanceof Polygon) {
                        if(doProcessTriangle(idgeom, triangleCircumcenter)) {
                            Triple neigh = triangleNeighbors[idgeom];
                            for (int sideNeigh = 0; sideNeigh < 3; sideNeigh++) {
                                int neighIndex = neigh.get(sideNeigh);
                                for (int vertexSide = 0; vertexSide < 3; vertexSide++) {
                                    // If vertex is shared by this neighbor (see ascii art of triangle)
                                    if (vertexSide != sideNeigh) {
                                        int vertexIndex = triangleVertex[idgeom].get(vertexSide);
                                        if (neighIndex != -1 && !processedVertex.contains(vertexIndex)) {
                                            // Add voronoi edge between circumcentre of A and current triangle circumcenter
                                            Polygon result = generateVoronoiPolygon(idgeom, vertexIndex, triangleCircumcenter);
                                            if (result != null) {
                                                polygons.add(result);
                                            }
                                            processedVertex.add(vertexIndex);
                                        }
                                    }
                                }
                            }
                        }
                } else {
                    throw new TopologyException("Voronoi method accept only polygons");
                }
            }
            MultiPolygon result = geometryFactory.createMultiPolygon(polygons.toArray(new Polygon[0]));
            if(envelope == null) {
                return result;
            } else {
                return (GeometryCollection)geometryFactory.toGeometry(envelope).intersection(result);
            }
        } else if(outputDimension == 1 || (envelope != null && outputDimension == 2)) {
            //.. later
            List<LineString> lineStrings = new ArrayList<LineString>(triangleCircumcenter.length);
            List<LineString> voronoiBorderLines = new ArrayList<LineString>();
            for (int idgeom = 0; idgeom < triangleCircumcenter.length; idgeom++) {
                Geometry geomItem = inputTriangles.getGeometryN(idgeom);
                if (geomItem instanceof Polygon) {
                    if(doProcessTriangle(idgeom, triangleCircumcenter))  {
                        Triple neigh = triangleNeighbors[idgeom];
                        for(int side = 0;side < 3; side ++) {
                            int neighIndex = neigh.get(side);
                            if(neighIndex >= 0 && !doProcessTriangle(neighIndex, triangleCircumcenter)) {
                                neighIndex = -1;
                            }
                            // If segment not already processed
                            if (neighIndex > idgeom) {
                                LineString lineString = geometryFactory.createLineString(new Coordinate[]{getCircumcenter(idgeom,
                                        triangleCircumcenter), getCircumcenter(neighIndex, triangleCircumcenter)});
                                if(lineString.getLength() > epsilon) {
                                    lineStrings.add(lineString);
                                }
                            } else if(neighIndex == -1 && envelope != null) {
                                LineString lineString = voronoiSide(idgeom, side, geometryFactory,
                                        getCircumcenter(idgeom, triangleCircumcenter));
                                if(lineString != null) {
                                    voronoiBorderLines.add(lineString);
                                }
                            }
                        }
                    }
                } else {
                    throw new TopologyException("Voronoi method accept only polygons");
                }
            }
            // Generate envelope segments
            if(envelope != null) {
                voronoiBorderLines.add(((Polygon)geometryFactory.toGeometry(envelope)).getExteriorRing());
                MultiLineString env = (MultiLineString)geometryFactory.createMultiLineString(voronoiBorderLines.
                        toArray(new LineString[0])).union();
                for (int i = 0; i < env.getNumGeometries(); i++) {
                    lineStrings.add((LineString) env.getGeometryN(i));
                }
            }
            if(outputDimension == 1) {
                return geometryFactory.createMultiLineString(lineStrings.toArray(new LineString[0]));
            } else {
                Polygonizer polygonizer = new Polygonizer();
                MultiLineString voronoiSegs = geometryFactory.createMultiLineString(lineStrings.toArray(new LineString[0]));
                polygonizer.add(voronoiSegs);
                return geometryFactory.createMultiPolygon(GeometryFactory.toPolygonArray(polygonizer.getPolygons()));
            }
        } else {
            Coordinate[] circumcenters = new Coordinate[inputTriangles.getNumGeometries()];
            for (int idgeom = 0; idgeom < triangleCircumcenter.length; idgeom++) {
                Geometry geomItem = inputTriangles.getGeometryN(idgeom);
                if (geomItem instanceof Polygon) {
                    circumcenters[idgeom] = getCircumcenter(idgeom, triangleCircumcenter);
                }
            }
            MultiPoint result = geometryFactory.createMultiPoint(circumcenters);
            if(envelope == null) {
                return result;
            } else {
                return (GeometryCollection)geometryFactory.toGeometry(envelope).intersection(result);
            }
        }
    }
1033896
public PhysicalPlans.PhysicalPlan getPhysicalPlan(String topologyName) {
    return awaitResult(delegate.getPhysicalPlan(null, topologyName));
  }