/** * Acts as a service provider for executable elements in the graph, first * looking for a service specific to this job, and then one from the * container. */ @Override public <T> T getService(Class<T> serviceClass) { T service = jobServices.getService(serviceClass); if (service != null) return service; return containerServices.getService(serviceClass); }
/** * Acts as a service provider for executable elements in the graph, first * looking for a service specific to this job, and then one from the * container. */ @Override public <T> T getService(Class<T> serviceClass) { T service = jobServices.getService(serviceClass); if (service != null) return service; return containerServices.getService(serviceClass); }
/** * Get the application service. * Callers may use this to register applications to * be executed by this provider. * @return application service. */ public ApplicationService getApplicationService() { return getServices().getService(ApplicationService.class); }
/** * Get the application service. * Callers may use this to register applications to * be executed by this provider. * @return application service. */ public ApplicationService getApplicationService() { return getServices().getService(ApplicationService.class); }
private void validateSubmitter() { ControlService controlService = submitter.getServices().getService(ControlService.class); if (controlService == null) { throw new IllegalArgumentException("Could not access service " + ControlService.class.getName()); } ApplicationService appService = submitter.getServices().getService(ApplicationService.class); if (appService == null) { throw new IllegalArgumentException("Could not access service " + ApplicationService.class.getName()); } JobRegistryService jobRegistryService = submitter.getServices().getService(JobRegistryService.class); if (jobRegistryService == null) { throw new IllegalArgumentException("Could not access service " + JobRegistryService.class.getName()); } } }
private void validateSubmitter() { ControlService controlService = submitter.getServices().getService(ControlService.class); if (controlService == null) { throw new IllegalArgumentException("Could not access service " + ControlService.class.getName()); } ApplicationService appService = submitter.getServices().getService(ApplicationService.class); if (appService == null) { throw new IllegalArgumentException("Could not access service " + ApplicationService.class.getName()); } JobRegistryService jobRegistryService = submitter.getServices().getService(JobRegistryService.class); if (jobRegistryService == null) { throw new IllegalArgumentException("Could not access service " + JobRegistryService.class.getName()); } } }
/** * Creates a new {@code EtiaoJob} instance which controls the lifecycle * of the specified graph. * * @param graph graph representation of the topology * @param topologyName name of the topology * @param jobName name of the Job. If null, a name of {@code topologyName_jobId} is assigned. * @param container service container */ EtiaoJob(DirectGraph graph, String topologyName, String jobName, ServiceContainer container) { this.graph = graph; this.id = ID_PREFIX + String.valueOf(jobID.getAndIncrement()); this.topologyName = topologyName; if (jobName == null) jobName = this.topologyName + "_" + this.id; this.name = jobName; this.containerServices = container; ControlService cs = container.getService(ControlService.class); if (cs != null) { EtiaoJobBean.registerControl(cs, this); } this.jobs = container.getService(JobRegistryService.class); if (jobs != null) jobs.addJob(this); }
/** * Creates a new {@code EtiaoJob} instance which controls the lifecycle * of the specified graph. * * @param graph graph representation of the topology * @param topologyName name of the topology * @param jobName name of the Job. If null, a name of {@code topologyName_jobId} is assigned. * @param container service container */ EtiaoJob(DirectGraph graph, String topologyName, String jobName, ServiceContainer container) { this.graph = graph; this.id = ID_PREFIX + String.valueOf(jobID.getAndIncrement()); this.topologyName = topologyName; if (jobName == null) jobName = this.topologyName + "_" + this.id; this.name = jobName; this.containerServices = container; ControlService cs = container.getService(ControlService.class); if (cs != null) { EtiaoJobBean.registerControl(cs, this); } this.jobs = container.getService(JobRegistryService.class); if (jobs != null) jobs.addJob(this); }
/** * Create an {@code ApplicationService} instance. * @param provider Provider to create topology instances for registered applications. * @param submitter Submitter for registered applications. * @param alias Alias used to register the control MBean. */ public AppService(TopologyProvider provider, DirectSubmitter<Topology, Job> submitter, String alias) { this.provider = provider; this.submitter = submitter; ControlService cs = submitter.getServices().getService(ControlService.class); if (cs != null) cs.registerControl(ApplicationServiceMXBean.TYPE, ALIAS+System.currentTimeMillis(), alias, ApplicationServiceMXBean.class, new AppServiceControl(this)); }
/** * Create an {@code ApplicationService} instance. * @param provider Provider to create topology instances for registered applications. * @param submitter Submitter for registered applications. * @param alias Alias used to register the control MBean. */ public AppService(TopologyProvider provider, DirectSubmitter<Topology, Job> submitter, String alias) { this.provider = provider; this.submitter = submitter; ControlService cs = submitter.getServices().getService(ControlService.class); if (cs != null) cs.registerControl(ApplicationServiceMXBean.TYPE, ALIAS+System.currentTimeMillis(), alias, ApplicationServiceMXBean.class, new AppServiceControl(this)); }
/** * Register a {@link StreamScopeRegistryMXBean} with the registered * {@link ControlService} (for use by the Edgent Console). */ private void registerRegistryBean(ServiceContainer services) { ControlService cs = services.getService(ControlService.class); if (cs == null || rgy == null) throw new IllegalStateException(); { // more workaround... // // If a rgyBean control is already registered, then don't reregister // (this will/should be the JMXControlService case) so as to avoid // an "already registered" exception from the ControlService. // The rgyBean is gotta be for the matching rgy with this // singleton StreamScopeSetup instance scheme so everything is OK. StreamScopeRegistryMXBean mbean = cs.getControl(StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.class); if (mbean != null) { return; } } if (rgyBean == null) rgyBean = new StreamScopeRegistryBean(rgy, cs); rgyBeanControlId = cs.registerControl(StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.TYPE+"_0", StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.class, rgyBean); }
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); } } }
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 public void testNoPreferences() { IotProvider provider1 = new IotProvider(EchoIotDevice::new); assertNull(provider1.getServices().getService(Preferences.class)); IotProvider provider2 = new IotProvider(null, EchoIotDevice::new); assertNull(provider2.getServices().getService(Preferences.class)); }
try { PrintWriter writer = new PrintWriter("consoleUrl.txt", "UTF-8"); writer.println(tp.getServices().getService(HttpServer.class).getConsoleUrl()); writer.close(); } catch ( Exception e) {
IotProvider provider2 = new IotProvider(PP2, EchoIotDevice::new); Preferences pp1 = provider1.getServices().getService(Preferences.class); assertNotNull(pp1); assertSame(pp1, pp1S); Preferences pp2 = provider2.getServices().getService(Preferences.class); assertNotNull(pp2); Preferences pp1N = provider1N.getServices().getService(Preferences.class); assertNotNull(pp1N); assertEquals("one", pp1N.get("a", "unset")); Preferences pp2N = provider2N.getServices().getService(Preferences.class); assertNotNull(pp2N); assertEquals("two", pp2N.get("a", "unset"));
provider.getServices().getService(ApplicationService.class)); Job appStarter = provider.submit(submitter).get(); ControlService cs = provider.getServices().getService(ControlService.class); assertTrue(cs instanceof JsonControlService); JsonControlService jsc = (JsonControlService) cs;
provider.getServices().getService(ApplicationService.class));