@Override int doWork() { try (DbConn cnx = Helpers.getNewDbSession()) { jqmlogger.info("Existing nodes: " + MetaService.getNodes(cnx).size()); return 0; } catch (Exception e) { jqmlogger.error("Could not fetch node count", e); return 111; } } }
public static void changeUserPassword(DbConn cnx, String userLogin, String newPassword) { List<RUserDto> dtos = getUsers(cnx, "user_select_by_key", 0, userLogin); if (dtos.size() == 0) { throw new JqmAdminApiUserException("Cannot update the password of a user which does not exist - given login was " + userLogin); } changeUserPassword(cnx, dtos.get(0).getId(), newPassword); }
public static GlobalParameterDto getGlobalParameter(DbConn cnx, String key) { return getGlobalParameter(cnx, "globalprm_select_by_key", key); }
NodeDto template = MetaService.getNode(cnx, templateName); NodeDto target = MetaService.getNode(cnx, nodeName); ArrayList<QueueMappingDto> mappings = new ArrayList<>(MetaService.getQueueMappings(cnx)); List<QueueMappingDto> toRemove = new ArrayList<>(10); List<QueueMappingDto> toAdd = new ArrayList<>(10); MetaService.syncQueueMappings(cnx, mappings); target.setRootLogLevel(template.getRootLogLevel()); target.setTmpDirectory(template.getTmpDirectory()); MetaService.upsertNode(cnx, target);
List<NodeDto> nodes = MetaService.getNodes(cnx); NodeDto node = null; Assert.assertEquals("value1", MetaService.getGlobalParameter(cnx, "key1").getValue()); for (QueueMappingDto qm : MetaService.getQueueMappings(cnx)) QueueDto q = MetaService.getQueue(cnx, queueMapping.getQueueId()); Assert.assertTrue(q.isDefaultQueue()); Assert.assertEquals("test1", MetaService.getJndiObjectResource(cnx, "string/test1").getParameters().get("STRING")); nodes = MetaService.getNodes(cnx); node = null; for (NodeDto dto : nodes) Assert.assertEquals("value2", MetaService.getGlobalParameter(cnx, "key1").getValue()); for (QueueMappingDto qm : MetaService.getQueueMappings(cnx)) q = MetaService.getQueue(cnx, queueMapping.getQueueId()); Assert.assertFalse(q.isDefaultQueue()); Assert.assertEquals("test1_2", MetaService.getJndiObjectResource(cnx, "string/test1").getParameters().get("STRING")); nodes = MetaService.getNodes(cnx); node = null; for (NodeDto dto : nodes)
public static void syncNodes(DbConn cnx, List<NodeDto> dtos) { for (NodeDto existing : getNodes(cnx)) { boolean foundInNewSet = false; for (NodeDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteQueue(cnx, existing.getId()); } } for (NodeDto dto : dtos) { upsertNode(cnx, dto); } }
@Test public void testTemplate() throws Exception { NodeDto template = MetaService.getNode(cnx, TestHelpers.nodeMix.getId()); template.setPort(123); MetaService.upsertNode(cnx, template); cnx.commit(); NodeDto target = MetaService.getNode(cnx, TestHelpers.node.getId()); Assert.assertEquals(3, MetaService.getNodeQueueMappings(cnx, target.getId()).size()); // Capital letter -> should be ignored. Main.runCommand(new String[] { "Install-NodeTemPlate", "-t", TestHelpers.nodeMix.getName(), "-n", TestHelpers.node.getName() }); target = MetaService.getNode(cnx, TestHelpers.node.getId()); Assert.assertEquals(template.getPort(), target.getPort()); Assert.assertEquals(1, MetaService.getNodeQueueMappings(cnx, target.getId()).size()); } }
public static void syncJndiObjectResource(DbConn cnx, List<JndiObjectResourceDto> dtos) { for (JndiObjectResourceDto existing : getJndiObjectResource(cnx)) { boolean foundInNewSet = false; for (JndiObjectResourceDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteJndiObjectResource(cnx, existing.getId()); } } for (JndiObjectResourceDto dto : dtos) { upsertJndiObjectResource(cnx, dto); } }
public static void syncQueueMappings(DbConn cnx, List<QueueMappingDto> dtos) { for (QueueMappingDto existing : getQueueMappings(cnx)) { boolean foundInNewSet = false; for (QueueMappingDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteQueueMapping(cnx, existing.getId()); } } for (QueueMappingDto dto : dtos) { upsertQueueMapping(cnx, dto); } }
public static void syncJobDefs(DbConn cnx, List<JobDefDto> dtos) { for (JobDefDto existing : getJobDef(cnx)) { boolean foundInNewSet = false; for (JobDefDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteJobDef(cnx, existing.getId()); } } for (JobDefDto dto : dtos) { upsertJobDef(cnx, dto); } }
MetaService.upsertJndiObjectResource(cnx, or); JndiObjectResourceDto tmp = MetaService.getJndiObjectResource(cnx, "jndi/resource"); Assert.assertEquals("val1", tmp.getParameters().get("prm1")); MetaService.upsertJndiObjectResource(cnx, tmp); tmp = MetaService.getJndiObjectResource(cnx, "jndi/resource"); Assert.assertEquals("val2", tmp.getParameters().get("prm1")); MetaService.syncJndiObjectResource(cnx, dtos); tmp = MetaService.getJndiObjectResource(cnx, "jndi/resource"); Assert.assertEquals("val2", tmp.getParameters().get("prm1")); MetaService.syncJndiObjectResource(cnx, dtos); tmp = MetaService.getJndiObjectResource(cnx, "jndi/resource"); Assert.assertEquals("val3", tmp.getParameters().get("prm1")); MetaService.syncJndiObjectResource(cnx, dtos); tmp = MetaService.getJndiObjectResource(cnx, "jndi/resource"); Assert.assertEquals("val3", tmp.getParameters().get("prm1")); Assert.assertEquals("val1", tmp.getParameters().get("prm2")); MetaService.syncJndiObjectResource(cnx, dtos); tmp = MetaService.getJndiObjectResource(cnx, "jndi/resource"); Assert.assertEquals("val3", tmp.getParameters().get("prm1")); Assert.assertEquals(1, tmp.getParameters().size()); MetaService.syncJndiObjectResource(cnx, dtos); Assert.assertEquals(0, MetaService.getJndiObjectResource(cnx).size());
public static void syncGlobalParameters(DbConn cnx, List<GlobalParameterDto> dtos) { for (GlobalParameterDto existing : getGlobalParameter(cnx)) { boolean foundInNewSet = false; for (GlobalParameterDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteGlobalParameter(cnx, existing.getId()); } } for (GlobalParameterDto dto : dtos) { upsertGlobalParameter(cnx, dto); } }
public static void syncRoles(DbConn cnx, List<RRoleDto> dtos) { for (RRoleDto existing : getRoles(cnx)) { boolean foundInNewSet = false; for (RRoleDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteRole(cnx, existing.getId(), false); } } for (RRoleDto dto : dtos) { upsertRole(cnx, dto); } }
JobDefDto dto = MetaService.getJobDef(cnx, i); Assert.assertEquals(0, dto.getParameters().size()); MetaService.upsertJobDef(cnx, dto); cnx.commit(); JobDefDto dto2 = MetaService.getJobDef(cnx, i); Assert.assertEquals(1, dto2.getSchedules().size()); Assert.assertEquals("5 * * * *", dto2.getSchedules().get(0).getCronExpression()); MetaService.upsertJobDef(cnx, dto); cnx.commit(); dto2 = MetaService.getJobDef(cnx, i); Assert.assertEquals(update.getTimeInMillis(), dto2.getSchedules().get(0).getLastUpdated().getTimeInMillis()); MetaService.upsertJobDef(cnx, dto2); cnx.commit(); dto2 = MetaService.getJobDef(cnx, i); Assert.assertEquals(1, dto2.getSchedules().get(0).getParameters().size()); Assert.assertNotEquals(update.getTimeInMillis(), dto2.getSchedules().get(0).getLastUpdated().getTimeInMillis()); MetaService.upsertJobDef(cnx, dto2); cnx.commit(); dto2 = MetaService.getJobDef(cnx, i); Assert.assertEquals(0, dto2.getSchedules().get(0).getParameters().size()); MetaService.upsertJobDef(cnx, dto2); cnx.commit(); dto2 = MetaService.getJobDef(cnx, i);
@Override int doWork() { try (DbConn cnx = Helpers.getNewDbSession()) { Helpers.createUserIfMissing(cnx, login, password, "created through CLI", roles.toArray(new String[roles.size()])); MetaService.changeUserPassword(cnx, login, password); cnx.commit(); return 0; } } }
public static List<RRoleDto> getRoles(DbConn cnx) { return getRoles(cnx, "role_select_all", 0); }
@Test // Commented - waiting for one minute is long. public void testSimpleSchedule() { int id = CreationTools.createJobDef(null, true, "pyl.EngineApiSendMsg", null, "jqm-tests/jqm-test-pyl/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", true, cnx); int scheduleId = JobRequest.create("MarsuApplication", "test user").setRecurrence("* * * * *").addParameter("key1", "value1") .submit(); JobDef jd_client = JqmClientFactory.getClient().getJobDefinition("MarsuApplication"); Assert.assertEquals(id, (int) jd_client.getId()); Assert.assertEquals(1, jd_client.getSchedules().size()); Assert.assertEquals(scheduleId, jd_client.getSchedules().get(0).getId()); Assert.assertEquals("* * * * *", jd_client.getSchedules().get(0).getCronExpression()); addAndStartEngine(); TestHelpers.waitFor(1, 150000, cnx); Assert.assertEquals(1, TestHelpers.getOkCount(cnx)); JobDefDto jd = MetaService.getJobDef(cnx, id); Assert.assertEquals(1, jd.getSchedules().size()); JqmClientFactory.getClient().removeRecurrence(scheduleId); jd = MetaService.getJobDef(cnx, id); Assert.assertEquals(0, jd.getSchedules().size()); Assert.assertTrue(Query.create().run().get(0).isFromSchedule()); }
NodeDto template = MetaService.getNode(cnx, templateNode); NodeDto target = MetaService.getNode(cnx, targetNode); ArrayList<QueueMappingDto> mappings = new ArrayList<QueueMappingDto>(MetaService.getQueueMappings(cnx)); List<QueueMappingDto> toRemove = new ArrayList<QueueMappingDto>(10); List<QueueMappingDto> toAdd = new ArrayList<QueueMappingDto>(10); MetaService.syncQueueMappings(cnx, mappings); target.setRootLogLevel(template.getRootLogLevel()); target.setTmpDirectory(template.getTmpDirectory()); MetaService.upsertNode(cnx, target);
public static void syncNodes(DbConn cnx, List<NodeDto> dtos) { for (NodeDto existing : getNodes(cnx)) { boolean foundInNewSet = false; for (NodeDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteQueue(cnx, existing.getId()); } } for (NodeDto dto : dtos) { upsertNode(cnx, dto); } }
public static void syncJndiObjectResource(DbConn cnx, List<JndiObjectResourceDto> dtos) { for (JndiObjectResourceDto existing : getJndiObjectResource(cnx)) { boolean foundInNewSet = false; for (JndiObjectResourceDto newdto : dtos) { if (newdto.getId() != null && newdto.getId().equals(existing.getId())) { foundInNewSet = true; break; } } if (!foundInNewSet) { deleteJndiObjectResource(cnx, existing.getId()); } } for (JndiObjectResourceDto dto : dtos) { upsertJndiObjectResource(cnx, dto); } }