@Override public void activate(String topologyName) throws TException { getNimbus().activate(topologyName); }
@Override public TopologyInfo getTopologyInfo(String id) throws TException { return getNimbus().getTopologyInfo(id); }
@Override public StormTopology getTopology(String id) throws TException { return getNimbus().getTopology(id); }
@Override public ClusterSummary getClusterInfo() throws TException { return getNimbus().getClusterInfo(); }
@Override public void deactivate(String topologyName) throws TException { getNimbus().deactivate(topologyName); }
@Override public String getTopologyConf(String id) throws TException { return getNimbus().getTopologyConf(id); }
@Override public void killTopology(String topologyName) throws TException { getNimbus().killTopology(topologyName); }
@Override public void uploadNewCredentials(String topologyName, Credentials creds) throws TException { getNimbus().uploadNewCredentials(topologyName, creds); }
@Override public void killTopologyWithOpts(String name, KillOptions options) throws TException { getNimbus().killTopologyWithOpts(name, options); }
@Override public void rebalance(String name, RebalanceOptions options) throws TException { getNimbus().rebalance(name, options); }
public void processWorkerMetrics(WorkerMetrics metrics) throws TException { getNimbus().processWorkerMetrics(metrics); }
@Override public LocalTopology submitTopologyWithOpts(String topologyName, Map<String, Object> conf, StormTopology topology, SubmitOptions submitOpts) throws TException { if (!Utils.isValidConf(conf)) { throw new IllegalArgumentException("Topology conf is not json-serializable"); } getNimbus().submitTopologyWithOpts(topologyName, null, JSONValue.toJSONString(conf), Utils.addVersions(topology), submitOpts); return new LocalTopology(topologyName, topology); }
/** * Checks if Nimbuses have elected a leader. * * @return true if there is a leader else false. */ private boolean hasLeader() throws AuthorizationException, TException { ClusterSummary summary = getNimbus().getClusterInfo(); if (summary.is_set_nimbuses()) { for (NimbusSummary sum : summary.get_nimbuses()) { if (sum.is_isLeader()) { return true; } } } return false; }
@Override public LocalTopology submitTopology(String topologyName, Map<String, Object> conf, StormTopology topology) throws TException { if (!Utils.isValidConf(conf)) { throw new IllegalArgumentException("Topology conf is not json-serializable"); } getNimbus().submitTopology(topologyName, null, JSONValue.toJSONString(conf), Utils.addVersions(topology)); ISubmitterHook hook = (ISubmitterHook) Utils.getConfiguredClass(conf, Config.STORM_TOPOLOGY_SUBMISSION_NOTIFIER_PLUGIN); if (hook != null) { TopologyInfo topologyInfo = Utils.getTopologyInfo(topologyName, null, conf); try { hook.notify(topologyInfo, conf, topology); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } return new LocalTopology(topologyName, topology); }
@Test public void testWithLocalCluster() throws Exception { try (LocalCluster cluster = new LocalCluster.Builder() .withSupervisors(2) .withPortsPerSupervisor(5) .build()) { assertThat(cluster, notNullValue()); assertThat(cluster.getNimbus(), notNullValue()); } }
@Test public void testWithSimulatedTimeLocalCluster() throws Exception { assertThat(Time.isSimulating(), is(false)); try (LocalCluster cluster = new LocalCluster.Builder() .withSupervisors(2) .withPortsPerSupervisor(5) .withSimulatedTime() .build()) { assertThat(cluster, notNullValue()); assertThat(cluster.getNimbus(), notNullValue()); assertThat(Time.isSimulating(), is(true)); } }
@Test public void testSubmitInactiveTopology() throws Exception { try (LocalCluster cluster = new LocalCluster.Builder() .withSimulatedTime() .withDaemonConf(Collections.singletonMap(Config.TOPOLOGY_ENABLE_MESSAGE_TIMEOUTS, true)) .build()) { FeederSpout feeder = new FeederSpout(new Fields("field1")); AckFailMapTracker tracker = new AckFailMapTracker(); feeder.setAckFailDelegate(tracker); Map<String, SpoutDetails> spoutMap = new HashMap<>(); spoutMap.put("1", Thrift.prepareSpoutDetails(feeder)); spoutMap.put("2", Thrift.prepareSpoutDetails(new OpenTrackedSpout())); Map<String, BoltDetails> boltMap = new HashMap<>(); boltMap.put("3", Thrift.prepareBoltDetails(Collections.singletonMap(Utils.getGlobalStreamId("1", null), Thrift.prepareGlobalGrouping()), new PrepareTrackedBolt())); boltPrepared = false; spoutOpened = false; StormTopology topology = Thrift.buildTopology(spoutMap, boltMap); cluster.submitTopologyWithOpts("test", Collections.singletonMap(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS, 10), topology, new SubmitOptions(TopologyInitialStatus.INACTIVE)); cluster.advanceClusterTime(11); feeder.feed(new Values("a"), 1); cluster.advanceClusterTime(9); assertThat(boltPrepared, is(false)); assertThat(spoutOpened, is(false)); cluster.getNimbus().activate("test"); cluster.advanceClusterTime(12); assertAcked(tracker, 1); assertThat(boltPrepared, is(true)); assertThat(spoutOpened, is(true)); } }