/** * Create application connects {@code edgentControl} device commands * to the control service. * * Subscribes to device * commands of type {@link Commands#CONTROL_SERVICE} * and sends the payload into the JSON control service * to invoke the control operation. */ protected void createIotCommandToControlApp() { this.registerTopology(CONTROL_APP_NAME, (iotDevice, config) -> { TStream<JsonObject> controlCommands = iotDevice.commands(Commands.CONTROL_SERVICE); controlCommands.sink(cmd -> { try { getControlService().controlRequest(cmd.getAsJsonObject(IotDevice.CMD_PAYLOAD)); } catch (Exception re) { // If the command fails then don't stop this application, // just process the next command. LoggerFactory.getLogger(ControlService.class).error("Control request failed: {}", cmd, re); } }); }); systemApps.add(CONTROL_APP_NAME); }
/** * Create application connects {@code edgentControl} device commands * to the control service. * * Subscribes to device * commands of type {@link Commands#CONTROL_SERVICE} * and sends the payload into the JSON control service * to invoke the control operation. */ protected void createIotCommandToControlApp() { this.registerTopology(CONTROL_APP_NAME, (iotDevice, config) -> { TStream<JsonObject> controlCommands = iotDevice.commands(Commands.CONTROL_SERVICE); controlCommands.sink(cmd -> { try { getControlService().controlRequest(cmd.getAsJsonObject(IotDevice.CMD_PAYLOAD)); } catch (Exception re) { // If the command fails then don't stop this application, // just process the next command. LoggerFactory.getLogger(ControlService.class).error("Control request failed: {}", cmd, re); } }); }); systemApps.add(CONTROL_APP_NAME); }
@Test //@Ignore("This test relies on an existing war in a given location ... need to refactor this") public void testAppServiceJar() throws Exception { DirectProvider provider = new DirectProvider(); JsonControlService control = new JsonControlService(); provider.getServices().addService(ControlService.class, control); AppService.createAndRegister(provider, provider); File testAppsJar = getServerJar(); assertNotNull(testAppsJar); assertTrue(testAppsJar.exists()); System.out.println("Using server jar at: " + testAppsJar.toString()); URL testAppsJarURL = testAppsJar.toURI().toURL(); JsonObject registerJar = newRegisterJarRequest(testAppsJarURL.toExternalForm()); JsonElement crr = control.controlRequest(registerJar); assertTrue(crr.getAsBoolean()); Thread.sleep(500); JsonObject submitAppTwo = newSubmitRequest("SecondJarApp"); crr = control.controlRequest(submitAppTwo); assertTrue(crr.getAsBoolean()); Thread.sleep(500); }
args.add(new JsonPrimitive("ABC")); req.add(JsonControlService.ARGS_KEY, args); control.controlRequest(req); args.add(new JsonPrimitive("DEF")); req.add(JsonControlService.ARGS_KEY, args); control.controlRequest(req);
args.add(new JsonPrimitive(726)); req.add(JsonControlService.ARGS_KEY, args); control.controlRequest(req); args.add(new JsonPrimitive(2924)); req.add(JsonControlService.ARGS_KEY, args); control.controlRequest(req);
@Test public void testNoArg() throws Exception { JsonControlService control = new JsonControlService(); MyBeanImpl cb1 = new MyBeanImpl(); MyBeanImpl cb2 = new MyBeanImpl(); assertFalse(cb1.isDoneIt()); assertFalse(cb2.isDoneIt()); control.registerControl("myb", "1", null, MyBean.class, cb1); control.registerControl("myb", "2", null, MyBean.class, cb2); assertFalse(cb1.isDoneIt()); assertFalse(cb2.isDoneIt()); JsonObject req = new JsonObject(); req.addProperty(JsonControlService.TYPE_KEY, "myb"); req.addProperty(JsonControlService.ALIAS_KEY, "1"); req.addProperty(JsonControlService.OP_KEY, "doIt"); control.controlRequest(req); assertTrue(cb1.isDoneIt()); assertFalse(cb2.isDoneIt()); req = new JsonObject(); req.addProperty(JsonControlService.TYPE_KEY, "myb"); req.addProperty(JsonControlService.ALIAS_KEY, "2"); req.addProperty(JsonControlService.OP_KEY, "doIt"); control.controlRequest(req); assertTrue(cb1.isDoneIt()); assertTrue(cb2.isDoneIt()); }
@Test public void testAppService() throws Exception { DirectProvider provider = new DirectProvider(); JsonControlService control = new JsonControlService(); provider.getServices().addService(ControlService.class, control); AppService.createAndRegister(provider, provider); IotTestApps.registerApplications(provider); JsonObject submitAppOne = newSubmitRequest("AppOne"); JsonElement crr = control.controlRequest(submitAppOne); assertTrue(crr.getAsBoolean()); }
args.add(new JsonPrimitive(89.24)); req.add(JsonControlService.ARGS_KEY, args); control.controlRequest(req); args.add(new JsonPrimitive(-9235.232)); req.add(JsonControlService.ARGS_KEY, args); control.controlRequest(req);
args.add(new JsonPrimitive(Thread.State.NEW.name())); req.add(JsonControlService.ARGS_KEY, args); control.controlRequest(req); args.add(new JsonPrimitive(Thread.State.BLOCKED.name())); req.add(JsonControlService.ARGS_KEY, args); control.controlRequest(req);
assertEquals(Job.State.RUNNING, jobMbean.getCurrentState()); jsc.controlRequest(closeJob);