Search in sources :

Example 91 with Cluster

use of org.apache.storm.scheduler.Cluster in project storm by apache.

the class TestBlacklistScheduler method TestReleaseBlacklist.

@Test
public void TestReleaseBlacklist() {
    INimbus iNimbus = new TestUtilsForBlacklistScheduler.INimbusTest();
    Map<String, SupervisorDetails> supMap = TestUtilsForBlacklistScheduler.genSupervisors(3, 4);
    Config config = new Config();
    config.putAll(Utils.readDefaultConfig());
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_TOLERANCE_TIME, 200);
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_TOLERANCE_COUNT, 2);
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_RESUME_TIME, 300);
    Map<String, TopologyDetails> topoMap = new HashMap<String, TopologyDetails>();
    TopologyDetails topo1 = TestUtilsForBlacklistScheduler.getTopology("topo-1", config, 5, 15, 1, 1, currentTime - 2, true);
    TopologyDetails topo2 = TestUtilsForBlacklistScheduler.getTopology("topo-2", config, 5, 15, 1, 1, currentTime - 8, true);
    TopologyDetails topo3 = TestUtilsForBlacklistScheduler.getTopology("topo-3", config, 5, 15, 1, 1, currentTime - 16, true);
    TopologyDetails topo4 = TestUtilsForBlacklistScheduler.getTopology("topo-4", config, 5, 15, 1, 1, currentTime - 32, true);
    topoMap.put(topo1.getId(), topo1);
    Topologies topologies = new Topologies(topoMap);
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    ResourceMetrics resourceMetrics = new ResourceMetrics(metricsRegistry);
    Cluster cluster = new Cluster(iNimbus, resourceMetrics, supMap, new HashMap<String, SchedulerAssignmentImpl>(), topologies, config);
    scheduler = new BlacklistScheduler(new DefaultScheduler());
    scheduler.prepare(config, metricsRegistry);
    scheduler.schedule(topologies, cluster);
    cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removeSupervisorFromSupervisors(supMap, "sup-0"), TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
    scheduler.schedule(topologies, cluster);
    cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removeSupervisorFromSupervisors(supMap, "sup-0"), TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
    scheduler.schedule(topologies, cluster);
    cluster = new Cluster(iNimbus, resourceMetrics, supMap, TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
    scheduler.schedule(topologies, cluster);
    Assert.assertEquals("blacklist", Collections.singleton("host-0"), cluster.getBlacklistedHosts());
    topoMap.put(topo2.getId(), topo2);
    topoMap.put(topo3.getId(), topo3);
    topoMap.put(topo4.getId(), topo4);
    topologies = new Topologies(topoMap);
    cluster = new Cluster(iNimbus, resourceMetrics, supMap, TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
    scheduler.schedule(topologies, cluster);
    Assert.assertEquals("blacklist", Collections.emptySet(), cluster.getBlacklistedHosts());
}
Also used : HashMap(java.util.HashMap) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) SchedulerAssignmentImpl(org.apache.storm.scheduler.SchedulerAssignmentImpl) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) DefaultScheduler(org.apache.storm.scheduler.DefaultScheduler) Test(org.junit.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 92 with Cluster

use of org.apache.storm.scheduler.Cluster in project storm by apache.

the class TestBlacklistScheduler method TestResumeBlacklist.

@Test
public void TestResumeBlacklist() {
    INimbus iNimbus = new TestUtilsForBlacklistScheduler.INimbusTest();
    Map<String, SupervisorDetails> supMap = TestUtilsForBlacklistScheduler.genSupervisors(3, 4);
    Config config = new Config();
    config.putAll(Utils.readDefaultConfig());
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_TOLERANCE_TIME, 200);
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_TOLERANCE_COUNT, 2);
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_RESUME_TIME, 300);
    Map<String, TopologyDetails> topoMap = new HashMap<String, TopologyDetails>();
    TopologyDetails topo1 = TestUtilsForBlacklistScheduler.getTopology("topo-1", config, 5, 15, 1, 1, currentTime - 2, true);
    topoMap.put(topo1.getId(), topo1);
    Topologies topologies = new Topologies(topoMap);
    StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
    ResourceMetrics resourceMetrics = new ResourceMetrics(metricsRegistry);
    Cluster cluster = new Cluster(iNimbus, resourceMetrics, supMap, new HashMap<String, SchedulerAssignmentImpl>(), topologies, config);
    scheduler = new BlacklistScheduler(new DefaultScheduler());
    scheduler.prepare(config, metricsRegistry);
    scheduler.schedule(topologies, cluster);
    cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removeSupervisorFromSupervisors(supMap, "sup-0"), TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
    scheduler.schedule(topologies, cluster);
    cluster = new Cluster(iNimbus, resourceMetrics, TestUtilsForBlacklistScheduler.removeSupervisorFromSupervisors(supMap, "sup-0"), TestUtilsForBlacklistScheduler.assignmentMapToImpl(cluster.getAssignments()), topologies, config);
    scheduler.schedule(topologies, cluster);
    cluster = new Cluster(iNimbus, resourceMetrics, supMap, new HashMap<String, SchedulerAssignmentImpl>(), topologies, config);
    scheduler.schedule(topologies, cluster);
    Assert.assertEquals("blacklist", Collections.singleton("host-0"), cluster.getBlacklistedHosts());
    for (int i = 0; i < 300 / 10 - 2; i++) {
        scheduler.schedule(topologies, cluster);
    }
    Assert.assertEquals("blacklist", Collections.singleton("host-0"), cluster.getBlacklistedHosts());
    scheduler.schedule(topologies, cluster);
    Assert.assertEquals("blacklist", Collections.emptySet(), cluster.getBlacklistedHosts());
}
Also used : HashMap(java.util.HashMap) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) SchedulerAssignmentImpl(org.apache.storm.scheduler.SchedulerAssignmentImpl) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) DefaultScheduler(org.apache.storm.scheduler.DefaultScheduler) Test(org.junit.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 93 with Cluster

use of org.apache.storm.scheduler.Cluster in project storm by apache.

the class TestBlacklistScheduler method TestList.

@Test
public void TestList() {
    INimbus iNimbus = new TestUtilsForBlacklistScheduler.INimbusTest();
    Config config = new Config();
    config.putAll(Utils.readDefaultConfig());
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_TOLERANCE_TIME, 200);
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_TOLERANCE_COUNT, 2);
    config.put(DaemonConfig.BLACKLIST_SCHEDULER_RESUME_TIME, 300);
    Map<String, TopologyDetails> topoMap = new HashMap<String, TopologyDetails>();
    TopologyDetails topo1 = TestUtilsForBlacklistScheduler.getTopology("topo-1", config, 5, 15, 1, 1, currentTime - 2, true);
    TopologyDetails topo2 = TestUtilsForBlacklistScheduler.getTopology("topo-2", config, 5, 15, 1, 1, currentTime - 2, true);
    topoMap.put(topo1.getId(), topo1);
    topoMap.put(topo2.getId(), topo2);
    Topologies topologies = new Topologies(topoMap);
    scheduler = new BlacklistScheduler(new DefaultScheduler());
    scheduler.prepare(config, new StormMetricsRegistry());
    List<Map<Integer, List<Integer>>> faultList = new ArrayList<>();
    faultList.add(new HashMap<>());
    faultList.add(ImmutableMap.of(0, ImmutableList.of(0, 1)));
    faultList.add(ImmutableMap.of(0, new ArrayList<>()));
    for (int i = 0; i < 17; i++) {
        faultList.add(new HashMap<>());
    }
    faultList.add(ImmutableMap.of(0, ImmutableList.of(0, 1)));
    faultList.add(ImmutableMap.of(1, ImmutableList.of(1)));
    for (int i = 0; i < 8; i++) {
        faultList.add(new HashMap<>());
    }
    faultList.add(ImmutableMap.of(0, ImmutableList.of(1)));
    faultList.add(ImmutableMap.of(1, ImmutableList.of(1)));
    for (int i = 0; i < 30; i++) {
        faultList.add(new HashMap<>());
    }
    List<Map<String, SupervisorDetails>> supervisorsList = FaultGenerateUtils.getSupervisorsList(3, 4, faultList);
    Cluster cluster = null;
    int count = 0;
    for (Map<String, SupervisorDetails> supervisors : supervisorsList) {
        cluster = FaultGenerateUtils.nextCluster(cluster, supervisors, iNimbus, config, topologies);
        scheduler.schedule(topologies, cluster);
        if (count == 0) {
            Set<String> hosts = new HashSet<>();
            Assert.assertEquals("blacklist", hosts, cluster.getBlacklistedHosts());
        } else if (count == 2) {
            Set<String> hosts = new HashSet<>();
            Assert.assertEquals("blacklist", hosts, cluster.getBlacklistedHosts());
        } else if (count == 3) {
            Set<String> hosts = new HashSet<>();
            hosts.add("host-0");
            Assert.assertEquals("blacklist", hosts, cluster.getBlacklistedHosts());
        } else if (count == 30) {
            Set<String> hosts = new HashSet<>();
            hosts.add("host-0");
            Assert.assertEquals("blacklist", hosts, cluster.getBlacklistedHosts());
        } else if (count == 31) {
            Set<String> hosts = new HashSet<>();
            hosts.add("host-0");
            hosts.add("host-1");
            Assert.assertEquals("blacklist", hosts, cluster.getBlacklistedHosts());
        } else if (count == 32) {
            Set<String> hosts = new HashSet<>();
            hosts.add("host-0");
            hosts.add("host-1");
            Assert.assertEquals("blacklist", hosts, cluster.getBlacklistedHosts());
        } else if (count == 60) {
            Set<String> hosts = new HashSet<>();
            hosts.add("host-0");
            hosts.add("host-1");
            Assert.assertEquals("blacklist", hosts, cluster.getBlacklistedHosts());
        } else if (count == 61) {
            Set<String> hosts = new HashSet<>();
            hosts.add("host-0");
            Assert.assertEquals("blacklist", hosts, cluster.getBlacklistedHosts());
        } else if (count == 62) {
            Set<String> hosts = new HashSet<>();
            Assert.assertEquals("blacklist", hosts, cluster.getBlacklistedHosts());
        }
        count++;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) ArrayList(java.util.ArrayList) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) HashSet(java.util.HashSet) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultScheduler(org.apache.storm.scheduler.DefaultScheduler) Test(org.junit.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 94 with Cluster

use of org.apache.storm.scheduler.Cluster in project storm by apache.

the class Nimbus method normalizeConf.

@SuppressWarnings("unchecked")
private static /**
 * Create a normalized topology conf.
 *
 * @param conf  the nimbus conf
 * @param topoConf initial topology conf
 * @param topology  the Storm topology
 */
Map<String, Object> normalizeConf(Map<String, Object> conf, Map<String, Object> topoConf, StormTopology topology) {
    // ensure that serializations are same for all tasks no matter what's on
    // the supervisors. this also allows you to declare the serializations as a sequence
    List<Map<String, Object>> allConfs = new ArrayList<>();
    for (Object comp : StormCommon.allComponents(topology).values()) {
        allConfs.add(StormCommon.componentConf(comp));
    }
    Set<String> decorators = new HashSet<>();
    // Yes we are putting in a config that is not the same type we pulled out.
    Map<String, String> serializers = new HashMap<>();
    for (Map<String, Object> c : allConfs) {
        addToDecorators(decorators, (List<String>) c.get(Config.TOPOLOGY_KRYO_DECORATORS));
        addToSerializers(serializers, (List<Object>) c.get(Config.TOPOLOGY_KRYO_REGISTER));
    }
    addToDecorators(decorators, (List<String>) topoConf.getOrDefault(Config.TOPOLOGY_KRYO_DECORATORS, conf.get(Config.TOPOLOGY_KRYO_DECORATORS)));
    addToSerializers(serializers, (List<Object>) topoConf.getOrDefault(Config.TOPOLOGY_KRYO_REGISTER, conf.get(Config.TOPOLOGY_KRYO_REGISTER)));
    Map<String, Object> mergedConf = Utils.merge(conf, topoConf);
    Map<String, Object> ret = new HashMap<>(topoConf);
    ret.put(Config.TOPOLOGY_KRYO_REGISTER, serializers);
    ret.put(Config.TOPOLOGY_KRYO_DECORATORS, new ArrayList<>(decorators));
    ret.put(Config.TOPOLOGY_ACKER_EXECUTORS, mergedConf.get(Config.TOPOLOGY_ACKER_EXECUTORS));
    ret.put(Config.TOPOLOGY_EVENTLOGGER_EXECUTORS, mergedConf.get(Config.TOPOLOGY_EVENTLOGGER_EXECUTORS));
    ret.put(Config.TOPOLOGY_MAX_TASK_PARALLELISM, mergedConf.get(Config.TOPOLOGY_MAX_TASK_PARALLELISM));
    // storm.messaging.netty.authentication is about inter-worker communication
    // enforce netty authentication when either topo or daemon set it to true
    boolean enforceNettyAuth = false;
    if (!topoConf.containsKey(Config.STORM_MESSAGING_NETTY_AUTHENTICATION)) {
        enforceNettyAuth = (Boolean) conf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION);
    } else {
        enforceNettyAuth = (Boolean) topoConf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION) || (Boolean) conf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION);
    }
    LOG.debug("For netty authentication, topo conf is: {}, cluster conf is: {}, Enforce netty auth: {}", topoConf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION), conf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION), enforceNettyAuth);
    ret.put(Config.STORM_MESSAGING_NETTY_AUTHENTICATION, enforceNettyAuth);
    if (!mergedConf.containsKey(Config.TOPOLOGY_METRICS_REPORTERS) && mergedConf.containsKey(Config.STORM_METRICS_REPORTERS)) {
        ret.put(Config.TOPOLOGY_METRICS_REPORTERS, mergedConf.get(Config.STORM_METRICS_REPORTERS));
    }
    // add any system metrics reporters to the topology metrics reporters
    if (conf.containsKey(Config.STORM_TOPOLOGY_METRICS_SYSTEM_REPORTERS)) {
        List<Map<String, Object>> reporters = (List<Map<String, Object>>) ret.computeIfAbsent(Config.TOPOLOGY_METRICS_REPORTERS, (key) -> new ArrayList<>());
        List<Map<String, Object>> systemReporters = (List<Map<String, Object>>) conf.get(Config.STORM_TOPOLOGY_METRICS_SYSTEM_REPORTERS);
        reporters.addAll(systemReporters);
    }
    // Don't allow topoConf to override various cluster-specific properties.
    // Specifically adding the cluster settings to the topoConf here will make sure these settings
    // also override the subsequently generated conf picked up locally on the classpath.
    // 
    // We will be dealing with 3 confs:
    // 1) the submitted topoConf created here
    // 2) the combined classpath conf with the topoConf added on top
    // 3) the nimbus conf with conf 2 above added on top.
    // 
    // By first forcing the topology conf to contain the nimbus settings, we guarantee all three confs
    // will have the correct settings that cannot be overriden by the submitter.
    ret.put(Config.STORM_CGROUP_HIERARCHY_DIR, conf.get(Config.STORM_CGROUP_HIERARCHY_DIR));
    ret.put(Config.WORKER_METRICS, conf.get(Config.WORKER_METRICS));
    if (mergedConf.containsKey(Config.TOPOLOGY_WORKER_TIMEOUT_SECS)) {
        int workerTimeoutSecs = (Integer) ObjectReader.getInt(mergedConf.get(Config.TOPOLOGY_WORKER_TIMEOUT_SECS));
        int workerMaxTimeoutSecs = (Integer) ObjectReader.getInt(mergedConf.get(Config.WORKER_MAX_TIMEOUT_SECS));
        if (workerTimeoutSecs > workerMaxTimeoutSecs) {
            ret.put(Config.TOPOLOGY_WORKER_TIMEOUT_SECS, workerMaxTimeoutSecs);
            String topoId = (String) mergedConf.get(Config.STORM_ID);
            LOG.warn("Topology {} topology.worker.timeout.secs is too large. Reducing from {} to {}", topoId, workerTimeoutSecs, workerMaxTimeoutSecs);
        }
    }
    return ret;
}
Also used : ZooDefs(org.apache.storm.shade.org.apache.zookeeper.ZooDefs) MetricSet(com.codahale.metrics.MetricSet) AssignmentDistributionService(org.apache.storm.nimbus.AssignmentDistributionService) DerivativeGauge(com.codahale.metrics.DerivativeGauge) INimbus(org.apache.storm.scheduler.INimbus) Assignment(org.apache.storm.generated.Assignment) ServerSocket(java.net.ServerSocket) DaemonConfig(org.apache.storm.DaemonConfig) DaemonType(org.apache.storm.cluster.DaemonType) IAuthorizer(org.apache.storm.security.auth.IAuthorizer) Map(java.util.Map) SchedulerAssignmentImpl(org.apache.storm.scheduler.SchedulerAssignmentImpl) TupleUtils(org.apache.storm.utils.TupleUtils) ComponentPageInfo(org.apache.storm.generated.ComponentPageInfo) SupervisorAssignments(org.apache.storm.generated.SupervisorAssignments) SpecificAggregateStats(org.apache.storm.generated.SpecificAggregateStats) IPrincipalToLocal(org.apache.storm.security.auth.IPrincipalToLocal) TopologyInfo(org.apache.storm.generated.TopologyInfo) WorkerTokenManager(org.apache.storm.security.auth.workertoken.WorkerTokenManager) SupervisorWorkerHeartbeat(org.apache.storm.generated.SupervisorWorkerHeartbeat) SimpleVersion(org.apache.storm.utils.SimpleVersion) Time(org.apache.storm.utils.Time) DefaultScheduler(org.apache.storm.scheduler.DefaultScheduler) INimbusCredentialPlugin(org.apache.storm.security.INimbusCredentialPlugin) Shutdownable(org.apache.storm.daemon.Shutdownable) StormCommon(org.apache.storm.daemon.StormCommon) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta) ErrorInfo(org.apache.storm.generated.ErrorInfo) ProfileAction(org.apache.storm.generated.ProfileAction) AggLevel(org.apache.storm.metricstore.AggLevel) MetricStore(org.apache.storm.metricstore.MetricStore) TopologyPageInfo(org.apache.storm.generated.TopologyPageInfo) Topologies(org.apache.storm.scheduler.Topologies) SupervisorSummary(org.apache.storm.generated.SupervisorSummary) ServerUtils(org.apache.storm.utils.ServerUtils) ConfigValidation(org.apache.storm.validation.ConfigValidation) SupervisorPageInfo(org.apache.storm.generated.SupervisorPageInfo) LocalState(org.apache.storm.utils.LocalState) WrappedAuthorizationException(org.apache.storm.utils.WrappedAuthorizationException) TopologyInitialStatus(org.apache.storm.generated.TopologyInitialStatus) ServerConfigUtils(org.apache.storm.utils.ServerConfigUtils) IOException(java.io.IOException) Utils(org.apache.storm.utils.Utils) ReqContext(org.apache.storm.security.auth.ReqContext) AtomicLong(java.util.concurrent.atomic.AtomicLong) Constants(org.apache.storm.Constants) WritableByteChannel(java.nio.channels.WritableByteChannel) TopologySummary(org.apache.storm.generated.TopologySummary) ComponentType(org.apache.storm.generated.ComponentType) ClusterSummary(org.apache.storm.generated.ClusterSummary) StatsUtil(org.apache.storm.stats.StatsUtil) IllegalStateException(org.apache.storm.generated.IllegalStateException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) IWorkerHeartbeatsRecoveryStrategy(org.apache.storm.nimbus.IWorkerHeartbeatsRecoveryStrategy) MultitenantScheduler(org.apache.storm.scheduler.multitenant.MultitenantScheduler) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) GetInfoOptions(org.apache.storm.generated.GetInfoOptions) WorkerMetricPoint(org.apache.storm.generated.WorkerMetricPoint) KillOptions(org.apache.storm.generated.KillOptions) UptimeComputer(org.apache.storm.utils.Utils.UptimeComputer) LSTopoHistory(org.apache.storm.generated.LSTopoHistory) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) Metric(org.apache.storm.metricstore.Metric) ThriftServer(org.apache.storm.security.auth.ThriftServer) Collection(java.util.Collection) ClientStatsUtil(org.apache.storm.stats.ClientStatsUtil) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) BlacklistScheduler(org.apache.storm.scheduler.blacklist.BlacklistScheduler) ProfileRequest(org.apache.storm.generated.ProfileRequest) Entry(java.util.Map.Entry) OciUtils(org.apache.storm.container.oci.OciUtils) WorkerHeartbeatsRecoveryStrategyFactory(org.apache.storm.nimbus.WorkerHeartbeatsRecoveryStrategyFactory) ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) RebalanceOptions(org.apache.storm.generated.RebalanceOptions) Iface(org.apache.storm.generated.Nimbus.Iface) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Function(java.util.function.Function) HashSet(java.util.HashSet) Meter(com.codahale.metrics.Meter) TopologyStatus(org.apache.storm.generated.TopologyStatus) IGroupMappingServiceProvider(org.apache.storm.security.auth.IGroupMappingServiceProvider) VisibleForTesting(org.apache.storm.shade.com.google.common.annotations.VisibleForTesting) JSONValue(org.json.simple.JSONValue) OwnerResourceSummary(org.apache.storm.generated.OwnerResourceSummary) DefaultTopologyValidator(org.apache.storm.nimbus.DefaultTopologyValidator) DaemonCommon(org.apache.storm.daemon.DaemonCommon) Logger(org.slf4j.Logger) KeySequenceNumber(org.apache.storm.blobstore.KeySequenceNumber) Channels(java.nio.channels.Channels) NimbusInfo(org.apache.storm.nimbus.NimbusInfo) FileInputStream(java.io.FileInputStream) ResourceUtils(org.apache.storm.scheduler.resource.ResourceUtils) WrappedNotAliveException(org.apache.storm.utils.WrappedNotAliveException) Subject(javax.security.auth.Subject) TopologyActionOptions(org.apache.storm.generated.TopologyActionOptions) WrappedInvalidTopologyException(org.apache.storm.utils.WrappedInvalidTopologyException) Comparator(java.util.Comparator) SpoutAggregateStats(org.apache.storm.generated.SpoutAggregateStats) ClusterMetricsConsumerExecutor(org.apache.storm.metric.ClusterMetricsConsumerExecutor) ClientAuthUtils(org.apache.storm.security.auth.ClientAuthUtils) ComponentAggregateStats(org.apache.storm.generated.ComponentAggregateStats) Arrays(java.util.Arrays) UnaryOperator(java.util.function.UnaryOperator) CachedGauge(com.codahale.metrics.CachedGauge) RotatingMap(org.apache.storm.utils.RotatingMap) BlobStore(org.apache.storm.blobstore.BlobStore) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) CommonAggregateStats(org.apache.storm.generated.CommonAggregateStats) ListBlobsResult(org.apache.storm.generated.ListBlobsResult) BoltAggregateStats(org.apache.storm.generated.BoltAggregateStats) Set(java.util.Set) Credentials(org.apache.storm.generated.Credentials) AuthorizationException(org.apache.storm.generated.AuthorizationException) ConfigUtils(org.apache.storm.utils.ConfigUtils) InputStreamWithMeta(org.apache.storm.blobstore.InputStreamWithMeta) NotAliveException(org.apache.storm.generated.NotAliveException) Timer(com.codahale.metrics.Timer) Config(org.apache.storm.Config) MapDifference(org.apache.storm.shade.com.google.common.collect.MapDifference) ImmutableMap(org.apache.storm.shade.com.google.common.collect.ImmutableMap) ITopologyActionNotifierPlugin(org.apache.storm.nimbus.ITopologyActionNotifierPlugin) ITopologyValidator(org.apache.storm.nimbus.ITopologyValidator) AclEnforcement(org.apache.storm.zookeeper.AclEnforcement) WrappedAlreadyAliveException(org.apache.storm.utils.WrappedAlreadyAliveException) InterruptedIOException(java.io.InterruptedIOException) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ILeaderElector(org.apache.storm.nimbus.ILeaderElector) NumErrorsChoice(org.apache.storm.generated.NumErrorsChoice) Zookeeper(org.apache.storm.zookeeper.Zookeeper) ReflectionUtils(org.apache.storm.utils.ReflectionUtils) ExecutorInfo(org.apache.storm.generated.ExecutorInfo) Maps(org.apache.storm.shade.com.google.common.collect.Maps) NodeInfo(org.apache.storm.generated.NodeInfo) ClusterStateContext(org.apache.storm.cluster.ClusterStateContext) DefaultWatcherCallBack(org.apache.storm.callback.DefaultWatcherCallBack) MetricRegistry(com.codahale.metrics.MetricRegistry) NimbusPrincipal(org.apache.storm.security.auth.NimbusPrincipal) ExecutorStats(org.apache.storm.generated.ExecutorStats) WorkerSummary(org.apache.storm.generated.WorkerSummary) Strings(org.apache.storm.shade.com.google.common.base.Strings) FileOutputStream(java.io.FileOutputStream) IStormClusterState(org.apache.storm.cluster.IStormClusterState) ACL(org.apache.storm.shade.org.apache.zookeeper.data.ACL) File(java.io.File) LocalFsBlobStore(org.apache.storm.blobstore.LocalFsBlobStore) Cluster(org.apache.storm.scheduler.Cluster) TimeCacheMap(org.apache.storm.utils.TimeCacheMap) StormTimer(org.apache.storm.StormTimer) SupervisorWorkerHeartbeats(org.apache.storm.generated.SupervisorWorkerHeartbeats) ObjectReader(org.apache.storm.utils.ObjectReader) CuratorFramework(org.apache.storm.shade.org.apache.curator.framework.CuratorFramework) ClusterInfo(org.apache.storm.metric.api.IClusterMetricsConsumer.ClusterInfo) IClusterMetricsConsumer(org.apache.storm.metric.api.IClusterMetricsConsumer) LogLevel(org.apache.storm.generated.LogLevel) NormalizedResourceRequest(org.apache.storm.scheduler.resource.normalization.NormalizedResourceRequest) TopologyHistoryInfo(org.apache.storm.generated.TopologyHistoryInfo) LoggerFactory(org.slf4j.LoggerFactory) ByteBuffer(java.nio.ByteBuffer) SubmitOptions(org.apache.storm.generated.SubmitOptions) SupervisorResources(org.apache.storm.scheduler.SupervisorResources) DebugOptions(org.apache.storm.generated.DebugOptions) VersionInfo(org.apache.storm.utils.VersionInfo) BlobStoreAclHandler(org.apache.storm.blobstore.BlobStoreAclHandler) ThriftConnectionType(org.apache.storm.security.auth.ThriftConnectionType) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) LogConfig(org.apache.storm.generated.LogConfig) TException(org.apache.storm.thrift.TException) WrappedIllegalStateException(org.apache.storm.utils.WrappedIllegalStateException) WorkerMetrics(org.apache.storm.generated.WorkerMetrics) WorkerResources(org.apache.storm.generated.WorkerResources) List(java.util.List) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) Principal(java.security.Principal) ICredentialsRenewer(org.apache.storm.security.auth.ICredentialsRenewer) SupervisorInfo(org.apache.storm.generated.SupervisorInfo) BufferInputStream(org.apache.storm.utils.BufferInputStream) SpoutSpec(org.apache.storm.generated.SpoutSpec) AtomicOutputStream(org.apache.storm.blobstore.AtomicOutputStream) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) ClusterUtils(org.apache.storm.cluster.ClusterUtils) SlidingTimeWindowReservoir(com.codahale.metrics.SlidingTimeWindowReservoir) MetricStoreConfig(org.apache.storm.metricstore.MetricStoreConfig) Histogram(com.codahale.metrics.Histogram) IScheduler(org.apache.storm.scheduler.IScheduler) HashMap(java.util.HashMap) BindException(java.net.BindException) ClientZookeeper(org.apache.storm.zookeeper.ClientZookeeper) BeginDownloadResult(org.apache.storm.generated.BeginDownloadResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) Bolt(org.apache.storm.generated.Bolt) StormTopology(org.apache.storm.generated.StormTopology) DataPoint(org.apache.storm.metric.api.DataPoint) ThriftAccessLogger(org.apache.storm.logging.ThriftAccessLogger) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) OutputStream(java.io.OutputStream) StormBase(org.apache.storm.generated.StormBase) NimbusSummary(org.apache.storm.generated.NimbusSummary) Iterator(java.util.Iterator) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) ExecutorSummary(org.apache.storm.generated.ExecutorSummary) TimeUnit(java.util.concurrent.TimeUnit) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) LogLevelAction(org.apache.storm.generated.LogLevelAction) Processor(org.apache.storm.generated.Nimbus.Processor) Collections(java.util.Collections) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkerMetricPoint(org.apache.storm.generated.WorkerMetricPoint) DataPoint(org.apache.storm.metric.api.DataPoint) ArrayList(java.util.ArrayList) List(java.util.List) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Map(java.util.Map) NavigableMap(java.util.NavigableMap) RotatingMap(org.apache.storm.utils.RotatingMap) ImmutableMap(org.apache.storm.shade.com.google.common.collect.ImmutableMap) TimeCacheMap(org.apache.storm.utils.TimeCacheMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 95 with Cluster

use of org.apache.storm.scheduler.Cluster in project storm by apache.

the class Nimbus method computeNewSchedulerAssignments.

private Map<String, SchedulerAssignment> computeNewSchedulerAssignments(Map<String, Assignment> existingAssignments, Topologies topologies, Map<String, StormBase> bases, String scratchTopologyId) throws KeyNotFoundException, AuthorizationException, InvalidTopologyException, IOException {
    Map<String, Set<List<Integer>>> topoToExec = computeTopologyToExecutors(bases);
    Set<String> zkHeartbeatTopologies = topologies.getTopologies().stream().filter(topo -> !supportRpcHeartbeat(topo)).map(TopologyDetails::getId).collect(Collectors.toSet());
    updateAllHeartbeats(existingAssignments, topoToExec, zkHeartbeatTopologies);
    Map<String, Set<List<Integer>>> topoToAliveExecutors = computeTopologyToAliveExecutors(existingAssignments, topoToExec, scratchTopologyId);
    Map<String, Set<Long>> supervisorToDeadPorts = computeSupervisorToDeadPorts(existingAssignments, topoToExec, topoToAliveExecutors);
    Map<String, SchedulerAssignmentImpl> topoToSchedAssignment = computeTopologyToSchedulerAssignment(existingAssignments, topoToAliveExecutors);
    Set<String> missingAssignmentTopologies = new HashSet<>();
    for (TopologyDetails topo : topologies.getTopologies()) {
        String id = topo.getId();
        Set<List<Integer>> allExecs = topoToExec.get(id);
        Set<List<Integer>> aliveExecs = topoToAliveExecutors.get(id);
        int numDesiredWorkers = topo.getNumWorkers();
        int numAssignedWorkers = numUsedWorkers(topoToSchedAssignment.get(id));
        if (allExecs == null || allExecs.isEmpty() || !allExecs.equals(aliveExecs) || numDesiredWorkers > numAssignedWorkers) {
            // We have something to schedule...
            missingAssignmentTopologies.add(id);
        }
    }
    Map<String, SupervisorDetails> supervisors = readAllSupervisorDetails(supervisorToDeadPorts, topologies, missingAssignmentTopologies);
    Cluster cluster = new Cluster(inimbus, resourceMetrics, supervisors, topoToSchedAssignment, topologies, conf);
    cluster.setStatusMap(idToSchedStatus.get());
    schedulingStartTimeNs.set(Time.nanoTime());
    scheduler.schedule(topologies, cluster);
    // Get and set the start time before getting current time in order to avoid potential race with the longest-scheduling-time-ms gauge
    final Long startTime = schedulingStartTimeNs.getAndSet(null);
    long elapsedNs = Time.nanoTime() - startTime;
    longestSchedulingTime.accumulateAndGet(elapsedNs, Math::max);
    schedulingDuration.update(elapsedNs, TimeUnit.NANOSECONDS);
    LOG.debug("Scheduling took {} ms for {} topologies", TimeUnit.NANOSECONDS.toMillis(elapsedNs), topologies.getTopologies().size());
    // merge with existing statuses
    idToSchedStatus.set(Utils.merge(idToSchedStatus.get(), cluster.getStatusMap()));
    nodeIdToResources.set(cluster.getSupervisorsResourcesMap());
    // This is a hack for non-ras scheduler topology and worker resources
    Map<String, TopologyResources> resources = cluster.getTopologyResourcesMap();
    idToResources.getAndAccumulate(resources, (orig, update) -> Utils.merge(orig, update));
    Map<String, Map<WorkerSlot, WorkerResources>> workerResources = new HashMap<>();
    for (Entry<String, Map<WorkerSlot, WorkerResources>> uglyWorkerResources : cluster.getWorkerResourcesMap().entrySet()) {
        Map<WorkerSlot, WorkerResources> slotToResources = new HashMap<>();
        for (Entry<WorkerSlot, WorkerResources> uglySlotToResources : uglyWorkerResources.getValue().entrySet()) {
            WorkerResources wr = uglySlotToResources.getValue();
            slotToResources.put(uglySlotToResources.getKey(), wr);
        }
        workerResources.put(uglyWorkerResources.getKey(), slotToResources);
    }
    idToWorkerResources.getAndAccumulate(workerResources, (orig, update) -> Utils.merge(orig, update));
    return cluster.getAssignments();
}
Also used : MetricSet(com.codahale.metrics.MetricSet) HashSet(java.util.HashSet) Set(java.util.Set) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) SchedulerAssignmentImpl(org.apache.storm.scheduler.SchedulerAssignmentImpl) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) ArrayList(java.util.ArrayList) List(java.util.List) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) HashSet(java.util.HashSet) WorkerResources(org.apache.storm.generated.WorkerResources) Cluster(org.apache.storm.scheduler.Cluster) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) WorkerMetricPoint(org.apache.storm.generated.WorkerMetricPoint) DataPoint(org.apache.storm.metric.api.DataPoint) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) NavigableMap(java.util.NavigableMap) RotatingMap(org.apache.storm.utils.RotatingMap) ImmutableMap(org.apache.storm.shade.com.google.common.collect.ImmutableMap) TimeCacheMap(org.apache.storm.utils.TimeCacheMap) HashMap(java.util.HashMap)

Aggregations

Cluster (org.apache.storm.scheduler.Cluster)95 Config (org.apache.storm.Config)85 Topologies (org.apache.storm.scheduler.Topologies)83 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)81 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)79 INimbus (org.apache.storm.scheduler.INimbus)73 HashMap (java.util.HashMap)69 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)68 ResourceMetrics (org.apache.storm.scheduler.resource.normalization.ResourceMetrics)62 TestUtilsForResourceAwareScheduler (org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler)59 Map (java.util.Map)44 DaemonConfig (org.apache.storm.DaemonConfig)43 SchedulerAssignment (org.apache.storm.scheduler.SchedulerAssignment)40 ResourceAwareScheduler (org.apache.storm.scheduler.resource.ResourceAwareScheduler)40 HashSet (java.util.HashSet)39 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)39 Test (org.junit.Test)37 WorkerSlot (org.apache.storm.scheduler.WorkerSlot)35 Test (org.junit.jupiter.api.Test)35 SchedulerAssignmentImpl (org.apache.storm.scheduler.SchedulerAssignmentImpl)33