/** * Submits an application using an {@code ApplicationServiceMXBean} control * registered with the specified {@code ControlService}. * * @param applicationName the name of the application to submit * @param controlService the control service */ public static void submitApplication(String applicationName, ControlService controlService) { try { ApplicationServiceMXBean control = controlService.getControl( ApplicationServiceMXBean.TYPE, ApplicationService.ALIAS, ApplicationServiceMXBean.class); if (control == null) { throw new IllegalStateException( "Could not find a registered control with the following interface: " + ApplicationServiceMXBean.class.getName()); } // TODO add ability to submit with the initial application configuration logger.info("Restarting monitored application {}", applicationName); control.submit(applicationName, null); } catch (Exception e) { throw new RuntimeException(e); } }
private void registerControl(ControlService cs) { if (cs == null) throw new IllegalArgumentException("ControlService must not be null"); logger.trace("Registering control for job id {}, job name {}", job.getId(), job.getName()); this.controlService = cs; JobMXBean oldControl = cs.getControl(JobMXBean.TYPE, job.getName(), JobMXBean.class); if (oldControl != null) { String oldControlId = cs.getControlId(JobMXBean.TYPE, job.getName(), JobMXBean.class); if (oldControlId != null) { if (isJobClosed(oldControl)) { cs.unregister(oldControlId); logger.debug("Old control id {} for CLOSED job name {} was unregistered", oldControlId, job.getName()); } else { throw new IllegalStateException( "Cannot register job control for alias " + job.getName() + " because a job control with id " + oldControlId + " for the same alias already exists and is not CLOSED"); } } } this.controlId = cs.registerControl(JobMXBean.TYPE, job.getId(), job.getName(), JobMXBean.class, this); logger.debug("Control for job id {}, job name {} was registered with id {}", job.getId(), job.getName(), controlId); }
/** * Submits an application using an {@code ApplicationServiceMXBean} control * registered with the specified {@code ControlService}. * * @param applicationName the name of the application to submit * @param controlService the control service */ public static void submitApplication(String applicationName, ControlService controlService) { try { ApplicationServiceMXBean control = controlService.getControl( ApplicationServiceMXBean.TYPE, ApplicationService.ALIAS, ApplicationServiceMXBean.class); if (control == null) { throw new IllegalStateException( "Could not find a registered control with the following interface: " + ApplicationServiceMXBean.class.getName()); } // TODO add ability to submit with the initial application configuration logger.info("Restarting monitored application {}", applicationName); control.submit(applicationName, null); } catch (Exception e) { throw new RuntimeException(e); } }
private void registerControl(ControlService cs) { if (cs == null) throw new IllegalArgumentException("ControlService must not be null"); logger.trace("Registering control for job id {}, job name {}", job.getId(), job.getName()); this.controlService = cs; JobMXBean oldControl = cs.getControl(JobMXBean.TYPE, job.getName(), JobMXBean.class); if (oldControl != null) { String oldControlId = cs.getControlId(JobMXBean.TYPE, job.getName(), JobMXBean.class); if (oldControlId != null) { if (isJobClosed(oldControl)) { cs.unregister(oldControlId); logger.debug("Old control id {} for CLOSED job name {} was unregistered", oldControlId, job.getName()); } else { throw new IllegalStateException( "Cannot register job control for alias " + job.getName() + " because a job control with id " + oldControlId + " for the same alias already exists and is not CLOSED"); } } } this.controlId = cs.registerControl(JobMXBean.TYPE, job.getId(), job.getName(), JobMXBean.class, this); logger.debug("Control for job id {}, job name {} was registered with id {}", job.getId(), job.getName(), controlId); }
JobMXBean jobMbean = controlService.getControl(JobMXBean.TYPE, jobName, JobMXBean.class); if (jobMbean == null) { throw new IllegalStateException(
JobMXBean jobMbean = controlService.getControl(JobMXBean.TYPE, jobName, JobMXBean.class); if (jobMbean == null) { throw new IllegalStateException(
/** * 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); }
@Override public StreamScopeMXBean lookup(String jobId, String opletId, int oport) { // lazy-register the mbeans String streamId = StreamScopeRegistry.mkStreamId(jobId, opletId, oport); StreamScopeMXBean mbean = cs.getControl(StreamScopeMXBean.TYPE, streamId, StreamScopeMXBean.class); if (mbean == null) { String name = StreamScopeRegistry.nameForStreamId(streamId); StreamScope<?> ss = rgy.lookup(name); if (ss != null) { mbean = new StreamScopeBean(ss); String controlId = cs.registerControl(StreamScopeMXBean.TYPE, StreamScopeMXBean.TYPE+streamId, streamId, StreamScopeMXBean.class, mbean); controlIdMap.put(name, controlId); } } return mbean; }
static <T> void setPollFrequency(TStream<T> pollStream, long period, TimeUnit unit) { ControlService cs = pollStream.topology().getRuntimeServiceSupplier() .get().getService(ControlService.class); PeriodMXBean control = cs.getControl(TStream.TYPE, pollStream.getAlias(), PeriodMXBean.class); control.setPeriod(period, unit); }
@Test public void testRegistryControlRegistered() throws Exception { Topology t1 = newTopology(); ControlService cs1 = t1.getRuntimeServiceSupplier().get() .getService(ControlService.class); StreamScopeRegistryMXBean rgy1 = cs1.getControl(StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.class); assertNotNull(rgy1); Topology t2 = newTopology(); ControlService cs2 = t2.getRuntimeServiceSupplier().get() .getService(ControlService.class); StreamScopeRegistryMXBean rgy2 = cs2.getControl(StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.class); assertNotNull(rgy2); // The rgy1, rgy1 mbean instances may or may not be the same object // depending on the ControlService implementation. For JMXControlService, // each getControl() yields a different MXBeanProxy instance but they are // for the underlying bean (same objectname). //assertSame(rgy1, rgy2); }
do { Thread.sleep(100); jobMbean = cs.getControl(JobMXBean.TYPE, "AppOne", JobMXBean.class); } while (jobMbean == null); assertEquals("AppOne", jobMbean.getName()); jobMbean = cs.getControl(JobMXBean.TYPE, "AppOne", JobMXBean.class); assertNull(jobMbean); appStarter.stateChange(Action.CLOSE);
.getService(ControlService.class); StreamScopeRegistryMXBean rgyBean = cs.getControl(StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.TYPE, StreamScopeRegistryMXBean.class); assertNotNull(rgyBean);