Search in sources :

Example 6 with DefaultScheduler

use of org.apache.storm.scheduler.DefaultScheduler 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 7 with DefaultScheduler

use of org.apache.storm.scheduler.DefaultScheduler 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 8 with DefaultScheduler

use of org.apache.storm.scheduler.DefaultScheduler 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)

Aggregations

DefaultScheduler (org.apache.storm.scheduler.DefaultScheduler)8 HashMap (java.util.HashMap)7 Config (org.apache.storm.Config)7 DaemonConfig (org.apache.storm.DaemonConfig)7 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)7 Cluster (org.apache.storm.scheduler.Cluster)7 INimbus (org.apache.storm.scheduler.INimbus)7 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)7 Topologies (org.apache.storm.scheduler.Topologies)7 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ResourceMetrics (org.apache.storm.scheduler.resource.normalization.ResourceMetrics)6 Test (org.junit.Test)6 SchedulerAssignmentImpl (org.apache.storm.scheduler.SchedulerAssignmentImpl)5 HashSet (java.util.HashSet)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Set (java.util.Set)1 IScheduler (org.apache.storm.scheduler.IScheduler)1