Search in sources :

Example 1 with TopologyMetricContext

use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.

the class RefreshEvent method syncTopologyMeta.

/**
     * sync topology metric meta from external storage like TDDL/OTS.
     * nimbus server will skip syncing, only followers do this
     */
public void syncTopologyMeta() {
    // sys meta, use remote only
    syncSysMetaFromRemote();
    // normal topology meta, local + remote
    for (Entry<String, TopologyMetricContext> entry : context.getTopologyMetricContexts().entrySet()) {
        String topologyId = entry.getKey();
        TopologyMetricContext metricContext = entry.getValue();
        if (!JStormMetrics.SYS_TOPOLOGY_SET.contains(topologyId)) {
            try {
                syncMetaFromCache(topologyId, metricContext);
                syncMetaFromRemote(topologyId, metricContext);
            } catch (Exception e1) {
                LOG.warn("failed to sync meta for topology:{}", topologyId);
            }
        }
    }
}
Also used : TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext)

Example 2 with TopologyMetricContext

use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.

the class ClusterMetricsContext method registerMetrics.

public Map<String, Long> registerMetrics(String topologyId, Set<String> metricNames) {
    TimeTicker ticker = new TimeTicker(TimeUnit.MILLISECONDS, true);
    TopologyMetricContext topologyMetricContext = topologyMetricContexts.get(topologyId);
    if (topologyMetricContext == null) {
        LOG.warn("topology metrics context does not exist for topology:{}!!!", topologyId);
        return new HashMap<>();
    }
    // if (!topologyMetricContext.finishSyncRemote()) {
    // LOG.warn("waiting for topology {} to finish sync with remote.", topologyId);
    // return new HashMap<>();
    // }
    ConcurrentMap<String, Long> memMeta = topologyMetricContexts.get(topologyId).getMemMeta();
    Map<String, Long> ret = new HashMap<>();
    for (String metricName : metricNames) {
        Long id = memMeta.get(metricName);
        if (id != null && MetricUtils.isValidId(id)) {
            ret.put(metricName, id);
        } else {
            id = metricIDGenerator.genMetricId(metricName);
            Long old = memMeta.putIfAbsent(metricName, id);
            if (old == null) {
                ret.put(metricName, id);
            } else {
                ret.put(metricName, old);
            }
        }
    }
    long cost = ticker.stop();
    LOG.info("register metrics, topology:{}, size:{}, cost:{}", topologyId, metricNames.size(), cost);
    return ret;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext) TimeTicker(com.alibaba.jstorm.metric.TimeTicker)

Example 3 with TopologyMetricContext

use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.

the class ClusterMetricsContext method deleteMetric.

public void deleteMetric(String topologyId, int metaType, List<String> idList) {
    final TopologyMetricContext context = topologyMetricContexts.get(topologyId);
    if (context != null) {
        for (String id : idList) {
            MetricMeta meta = metricQueryClient.getMetricMeta(clusterName, topologyId, MetaType.parse(metaType), id);
            if (meta != null) {
                LOG.warn("deleting metric meta:{}", meta);
                metricQueryClient.deleteMeta(meta);
                context.getMemMeta().remove(meta.getFQN());
                metricCache.put(topologyId, context.getMemMeta());
            } else {
                LOG.warn("Failed to delete metric meta, topology:{}, metaType:{}, id:{}, meta not found", topologyId, metaType, id);
            }
        }
    } else {
        LOG.warn("Failed to delete metric meta, topology:{} doesn't exist!", topologyId);
    }
}
Also used : TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext) MetricMeta(com.alibaba.jstorm.common.metric.MetricMeta)

Example 4 with TopologyMetricContext

use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.

the class RefreshEvent method syncTopologyMetaForFollower.

/**
 * sync topology metric meta from external storage like TDDL/OTS.
 * nimbus server will skip syncing, only followers do this
 */
public void syncTopologyMetaForFollower() {
    // sys meta, use remote only
    syncSysMetaFromRemote();
    // normal topology meta, local + remote
    for (Entry<String, TopologyMetricContext> entry : context.getTopologyMetricContexts().entrySet()) {
        String topology = entry.getKey();
        TopologyMetricContext metricContext = entry.getValue();
        if (!JStormMetrics.SYS_TOPOLOGY_SET.contains(topology)) {
            try {
                syncMetaFromCache(topology, metricContext);
                syncNonSysMetaFromRemote(topology, metricContext);
            } catch (Exception e1) {
                LOG.warn("failed to sync meta for topology:{}", topology);
            }
        }
    }
}
Also used : TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext)

Example 5 with TopologyMetricContext

use of com.alibaba.jstorm.metric.TopologyMetricContext in project jstorm by alibaba.

the class StartTopologyEvent method run.

@Override
public void run() {
    context.getMetricCache().putSampleRate(topologyId, sampleRate);
    context.getMetricUploaderDelegate().sendEvent(context.getClusterName(), this);
    if (!context.getTopologyMetricContexts().containsKey(topologyId)) {
        TopologyMetricContext metricContext = new TopologyMetricContext();
        // note that workerNum is not set here.
        context.getTopologyMetricContexts().put(topologyId, metricContext);
    }
}
Also used : TopologyMetricContext(com.alibaba.jstorm.metric.TopologyMetricContext)

Aggregations

TopologyMetricContext (com.alibaba.jstorm.metric.TopologyMetricContext)10 HashMap (java.util.HashMap)5 Map (java.util.Map)4 MetricInfo (backtype.storm.generated.MetricInfo)2 MetricSnapshot (backtype.storm.generated.MetricSnapshot)2 MetricType (com.alibaba.jstorm.metric.MetricType)2 Assignment (com.alibaba.jstorm.schedule.Assignment)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 TopologyMetric (backtype.storm.generated.TopologyMetric)1 MetricMeta (com.alibaba.jstorm.common.metric.MetricMeta)1 TimeTicker (com.alibaba.jstorm.metric.TimeTicker)1 ResourceWorkerSlot (com.alibaba.jstorm.schedule.default_assign.ResourceWorkerSlot)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1