/** * Create Job monitor application. * @see JobMonitorApp */ protected void createJobMonitorApp() { getApplicationService().registerTopology(JobMonitorApp.APP_NAME, (topology, config) -> JobMonitorApp.declareTopology(topology)); systemApps.add(JobMonitorApp.APP_NAME); }
@Test public void testRegisterTopology() { DirectProvider direct = new DirectProvider(); ApplicationService appService = AppService.createAndRegister(direct, direct); assertTrue(appService.getApplicationNames().isEmpty()); appService.registerTopology("FirstApp", (t,c) -> t.strings("a")); assertEquals(1, appService.getApplicationNames().size()); assertTrue(appService.getApplicationNames().contains("FirstApp")); appService.registerTopology("SecondApp", (t,c) -> t.strings("b")); assertEquals(2, appService.getApplicationNames().size()); assertTrue(appService.getApplicationNames().contains("FirstApp")); assertTrue(appService.getApplicationNames().contains("SecondApp")); }
@Test public void testRegisterJar() throws Exception { DirectProvider direct = new DirectProvider(); ApplicationService appService = AppService.createAndRegister(direct, direct); // Make sure the applications haven't been available before registering the jar. assertEquals(0, appService.getApplicationNames().size()); File testAppsJar = getServerJar(); assertNotNull(testAppsJar); assertTrue(testAppsJar.exists()); System.out.println("Using server jar at: " + testAppsJar.toString()); URL testAppsJarURL = testAppsJar.toURI().toURL(); appService.registerJar(testAppsJarURL.toExternalForm(), null); System.out.println(appService.getApplicationNames()); assertEquals(3, appService.getApplicationNames().size()); assertTrue(appService.getApplicationNames().contains("FirstJarApp")); assertTrue(appService.getApplicationNames().contains("SecondJarApp")); assertTrue(appService.getApplicationNames().contains("ThirdJarApp")); }
static void startMonitoredApplications(DirectSubmitter<Topology, Job> submitter) { ServiceContainer services = submitter.getServices(); ApplicationService appService = services.getService(ApplicationService.class); ControlService controlService = services.getService(ControlService.class); // Submit all applications registered with the ApplicationService for (String name: appService.getApplicationNames()) { JobMonitorApp.submitApplication(name, controlService); } } }
/** * Create Job monitor application. * @see JobMonitorApp */ protected void createJobMonitorApp() { getApplicationService().registerTopology(JobMonitorApp.APP_NAME, (topology, config) -> JobMonitorApp.declareTopology(topology)); systemApps.add(JobMonitorApp.APP_NAME); }
/** * Create application that connects to the message hub. * Subscribes to device events and sends them to the messages hub. * Publishes device commands from the message hub. * @see IotDevicePubSub * @see #createMessageHubDevice(Topology) */ protected void createIotDeviceApp() { getApplicationService().registerTopology(IotDevicePubSub.APP_NAME, (topology, config) -> IotDevicePubSub.createApplication(createMessageHubDevice(topology))); systemApps.add(IotDevicePubSub.APP_NAME); }
/** * Create application that connects to the message hub. * Subscribes to device events and sends them to the messages hub. * Publishes device commands from the message hub. * @see IotDevicePubSub * @see #createMessageHubDevice(Topology) */ protected void createIotDeviceApp() { getApplicationService().registerTopology(IotDevicePubSub.APP_NAME, (topology, config) -> IotDevicePubSub.createApplication(createMessageHubDevice(topology))); systemApps.add(IotDevicePubSub.APP_NAME); }
getApplicationService().registerTopology(applicationName, (topology,cfg) -> builder.accept(IotDevicePubSub.addIotDevice(topology), cfg)); if (autoSubmit) {
getApplicationService().registerTopology(applicationName, (topology,cfg) -> builder.accept(IotDevicePubSub.addIotDevice(topology), cfg)); if (autoSubmit) {
public static void registerApplications(DirectSubmitter<?, ?> submitter) { ApplicationService apps = submitter.getServices().getService(ApplicationService.class); apps.registerTopology("AppOne", IotTestApps::createApplicationOne); }
/** * Fails every 1.5 seconds (10 tuples * 150 millis) */ static void registerMonitoredApplicationTwo(DirectSubmitter<Topology, Job> submitter, AtomicInteger topoBuiltCnt, AtomicInteger injectedErrorCnt) { ApplicationService appService = submitter.getServices().getService(ApplicationService.class); appService.registerTopology(MONITORED_APP_NAME_2, (topology, config) -> { topoBuiltCnt.incrementAndGet(); Random r = new Random(); TStream<Double> d = topology.poll(() -> r.nextGaussian(), 150, TimeUnit.MILLISECONDS); final AtomicInteger count = new AtomicInteger(0); d = d.filter(tuple -> { int tupleCount = count.incrementAndGet(); if (tupleCount == 10) { injectedErrorCnt.incrementAndGet(); throw new IllegalStateException(MONITORED_APP_NAME_2 + " Injected error " + injectedErrorCnt.get()); } return true; }); d.sink(tuple -> System.out.print("#")); }); }
/** * Fails every 2 seconds (20 tuples * 100 millis) */ static void registerMonitoredApplicationOne(DirectSubmitter<Topology, Job> submitter, AtomicInteger topoBuiltCnt, AtomicInteger injectedErrorCnt) { ApplicationService appService = submitter.getServices().getService(ApplicationService.class); appService.registerTopology(MONITORED_APP_NAME_1, (topology, config) -> { topoBuiltCnt.incrementAndGet(); Random r = new Random(); TStream<Double> d = topology.poll(() -> r.nextGaussian(), 100, TimeUnit.MILLISECONDS); final AtomicInteger count = new AtomicInteger(0); d = d.filter(tuple -> { int tupleCount = count.incrementAndGet(); if (tupleCount == 20) { injectedErrorCnt.incrementAndGet(); throw new IllegalStateException(MONITORED_APP_NAME_1 + " Injected error " + injectedErrorCnt.get()); } return true; }); d.sink(tuple -> System.out.print(".")); }); }
@Test(expected=IllegalArgumentException.class) public void testRegisterNullTopologyName() { DirectProvider direct = new DirectProvider(); ApplicationService appService = AppService.createAndRegister(direct, direct); appService.registerTopology(null, (t,c) -> t.strings("a")); }
@Test(expected=IllegalArgumentException.class) public void testRegisterEmptyTopologyName() { DirectProvider direct = new DirectProvider(); ApplicationService appService = AppService.createAndRegister(direct, direct); appService.registerTopology("", (t,c) -> t.strings("a")); }