jqmlogger.info("\tfile produced storage directory: " + n.getDlRepo()); jqmlogger.info("\tHTTP listening interface: " + n.getDns()); jqmlogger.info("\tlooks for payloads inside: " + n.getRepo()); jqmlogger.info("\tlog level: " + n.getRootLogLevel()); jqmlogger.info("\ttemp files will be created inside: " + n.getTmpDirectory()); jqmlogger.info("\tJMX registry port: " + n.getJmxRegistryPort()); jqmlogger.info("\tJMX server port: " + n.getJmxServerPort()); jqmlogger.info("\tHTTP listening port: " + n.getPort()); jqmlogger.info("\tAPI admin enabled: " + n.getLoadApiAdmin()); jqmlogger.info("\tAPI client enabled: " + n.getLoadApiClient()); jqmlogger.info("\tAPI simple enabled: " + n.getLoapApiSimple()); List<DeploymentParameter> dps = DeploymentParameter.select(cnx, "dp_select_for_node", n.getId()); for (DeploymentParameter dp : dps)
node = Node.select_single(cnx, "node_select_by_key", nodeName); if (node.getLastSeenAlive() != null && Calendar.getInstance().getTimeInMillis() - node.getLastSeenAlive().getTimeInMillis() <= toWait) long r = Calendar.getInstance().getTimeInMillis() - node.getLastSeenAlive().getTimeInMillis(); throw new JqmInitErrorTooSoon("Another engine named " + nodeName + " was running less than " + r / 1000 + " seconds ago. Either stop the other node, or if it already stopped, please wait " + (toWait - r) / 1000 + (node.getLastSeenAlive() == null ? "" : ft.format(node.getLastSeenAlive().getTime()))); QueryResult qr = cnx.runUpdate("node_update_alive_by_id", node.getId()); cnx.commit(); if (qr.nbUpdated == 0) if (node.getJmxRegistryPort() != null && node.getJmxServerPort() != null && node.getJmxRegistryPort() > 0 && node.getJmxServerPort() > 0) JmxAgent.registerAgent(node.getJmxRegistryPort(), node.getJmxServerPort(), node.getDns()); if (node.getJmxServerPort() != null && node.getJmxServerPort() > 0) name = new ObjectName("com.enioka.jqm:type=Node,name=" + this.node.getName()); mbs.registerMBean(this, name); JqmEngine.latestNodeStartedName = node.getName(); if (this.handler != null)
@Override public String getWebApiLocalUrl(DbConn cnx) { // Do not use port from engine.getNode, as it may have been set AFTER engine startup. Node node = Node.select_single(cnx, "node_select_by_id", this.engine.getNode().getId()); boolean useSsl = Boolean.parseBoolean(GlobalParameter.getParameter(cnx, "enableWsApiSsl", "false")); return (useSsl ? "https://localhost:" : "http://localhost:") + node.getPort(); } }
if (!this.logLevel.equals(node.getRootLogLevel())) this.logLevel = node.getRootLogLevel(); CommonService.setLogLevel(this.logLevel); String np = node.getDns() + node.getPort() + node.getLoadApiAdmin() + node.getLoadApiClient() + node.getLoapApiSimple(); if (nodePrms == null)
/** * See {@link #getNode()} */ public void setNode(final Node node) { this.n = node; this.node_id = node.getId(); }
if (!node.getLoadApiAdmin() && !node.getLoadApiClient() && !node.getLoapApiSimple()) JdbcCa.prepareWebServerStores(cnx, "CN=" + node.getDns(), "./conf/keystore.pfx", "./conf/trusted.jks", pfxPassword, node.getDns(), "./conf/server.cer", "./conf/ca.cer"); InetAddress[] adresses = InetAddress.getAllByName(node.getDns()); for (InetAddress s : adresses) if (node.getDns().equals("0.0.0.0")) connector.setPort(node.getPort()); ls.add(connector); jqmlogger.debug("Jetty will bind on all interfaces on port " + node.getPort()); else if (s.isLoopbackAddress() || "localhost".equals(node.getDns())) connector.setPort(node.getPort()); ls.add(connector); jqmlogger.debug("Jetty will bind on loopback - localhost:" + node.getPort()); connector.setPort(node.getPort()); ls.add(connector); jqmlogger.debug("Jetty will bind on " + s.getHostAddress() + ":" + node.getPort()); jqmlogger.warn("Could not resolve name " + node.getDns() + ". Will bind on all interfaces."); Connector connector = new SelectChannelConnector(); connector.setHost(null); connector.setPort(node.getPort()); ls.add(connector);
static void checkConfiguration(String nodeName, DbConn cnx) List<Node> nodes = Node.select(cnx, "node_select_by_key", nodeName); if (nodes.size() == 0) if (!StringUtils.hasText(nn.getDlRepo()) || !StringUtils.hasText(nn.getRepo()) || !StringUtils.hasText(nn.getTmpDirectory())) int i = cnx.runSelectSingle("dp_select_count_for_node", Integer.class, nn.getId()); if (i == 0)
int port = Node.select_single(cnx, "node_select_by_id", TestHelpers.node.getId()).getPort(); HttpUriRequest rq = new HttpGet("https://" + TestHelpers.node.getDns() + ":" + port + "/ws/simple/status?id=" + i); jqmlogger.debug(rq.getURI().toString()); CloseableHttpResponse rs = cl.execute(rq);
/** * This actually starts the different engines configured with {@link #addNode(String)}.<br> * This can usually only be called once (it can actually be called again but only after calling {@link #stop()}). */ public JqmAsyncTester start() { if (hasStarted) { throw new IllegalStateException("cannot start twice"); } if (nodes.isEmpty()) { throw new IllegalStateException("no engines defined"); } if (queues.isEmpty()) { throw new IllegalStateException("no queues defined"); } if (!oneQueueDeployed) { throw new IllegalStateException("no queue was ever deployed to any node"); } hasStarted = true; for (Node n : nodes.values()) { engines.put(n.getName(), JqmEngineFactory.startEngine(n.getName(), null)); } return this; }
pb.directory(new File(this.ji.getNode().getRepo())); pb.redirectErrorStream(false); env.put("JQM_JI_DELIVERY_DIR", this.deliveryDir.getAbsolutePath()); env.put("JQM_NODE_NAME", this.ji.getNode().getName()); env.put("JQM_NODE_APPLICATION_ROOT", this.ji.getNode().getRepo()); env.put("JQM_NODE_LOG_LEVEL", this.ji.getNode().getRootLogLevel());
@Before public void before() throws IOException { Helpers.setSingleParam("disableWsApi", "false", cnx); Helpers.setSingleParam("enableWsApiAuth", "false", cnx); File jar = FileUtils.listFiles(new File("../jqm-ws/target/"), new String[] { "war" }, false).iterator().next(); FileUtils.copyFile(jar, new File("./webapp/jqm-ws.war")); addAndStartEngine(); TestHelpers.node = Node.select_single(cnx, "node_select_by_id", TestHelpers.node.getId()); }
node = Node.select_single(cnx, "node_select_by_id", node.getId()); if (node == null || node.isStop()) cnx.runUpdate("node_update_alive_by_id", node.getId()); cnx.commit(); ResultSet rs = cnx.runSelect("ji_select_instructions_by_node", node.getId()); while (rs.next())
/** * Version of {@link JqmClient#getDeliverableContent(Deliverable)} which does not require the web service APIs to be enabled to work. * Also, returned files do not self-destruct on stream close.<br> * See the javadoc of the original method for details. * * @throws FileNotFoundException */ public InputStream getDeliverableContent(Deliverable file) throws FileNotFoundException { List<com.enioka.jqm.model.Deliverable> dd = com.enioka.jqm.model.Deliverable.select(cnx, "deliverable_select_by_id", file.getId()); if (dd.isEmpty()) { throw new JqmInvalidRequestException("no deliverable with this ID"); } com.enioka.jqm.model.Deliverable d = dd.get(0); JobInstance ji = Query.create().setJobInstanceId(d.getJobId()).run().get(0); String nodeName = ji.getNodeName(); Node n = nodes.get(nodeName); return new FileInputStream(FilenameUtils.concat(n.getDlRepo(), file.getFilePath())); } }
TestHelpers.node = Node.create(cnx, "localhost", 0, "./target/outputfiles/", "./../", "./target/tmp", dns, "DEBUG"); TestHelpers.node2 = Node.create(cnx, "localhost2", 0, "./target/outputfiles/", "./../", "./target/tmp", dns, "DEBUG"); TestHelpers.node3 = Node.create(cnx, "localhost3", 0, "./target/outputfiles/", "./../", "./target/tmp", dns, "DEBUG"); TestHelpers.nodeMix = Node.create(cnx, "localhost4", 0, "./target/outputfiles/", "./../", "./target/tmp", dns, "DEBUG"); TestHelpers.nodeMix2 = Node.create(cnx, "localhost5", 0, "./target/outputfiles/", "./../", "./target/tmp", dns, "DEBUG"); TestHelpers.dpSlow3 = DeploymentParameter.create(cnx, node3, 1, 1000, qSlow3); if (!(new File(TestHelpers.node.getDlRepo())).isDirectory() && !(new File(TestHelpers.node.getDlRepo())).mkdir())
/** * Create a new node. It is not started by this method.<br> * This must be called before starting the tester. * * @param nodeName * the name of the node. Must be unique. */ public JqmAsyncTester addNode(String nodeName) { if (hasStarted) { throw new IllegalStateException("tester has already started"); } File resDirectoryPath = Common.createTempDirectory(); Node node = Node.create(cnx, nodeName, 12, resDirectoryPath.getAbsolutePath(), ".", resDirectoryPath.getAbsolutePath(), "test", logLevel); cnx.commit(); nodes.put(nodeName, node); setNodesLogLevel(logLevel); return this; }
/** * Returns true if the libraries should be loaded in cache. Two cases: never loaded and should be reloaded (jar is more recent than * cache) */ private boolean shouldLoad(Node node, JobDef jd) { if (!cache.containsKey(jd.getApplicationName())) { return true; } // If here: cache exists. JobDefLibrary libs = cache.get(jd.getApplicationName()); // Is cache stale? Date lastLoaded = libs.loadTime; File jarFile = new File(FilenameUtils.concat(new File(node.getRepo()).getAbsolutePath(), jd.getJarPath())); File jarDir = jarFile.getParentFile(); File libDir = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "lib")); if (lastLoaded.before(new Date(jarFile.lastModified())) || lastLoaded.before(new Date(jarDir.lastModified())) || lastLoaded.before(new Date(libDir.lastModified()))) { jqmlogger.info("The cache for application " + jd.getApplicationName() + " will be reloaded"); return true; } // If here, the cache is OK return false; }
Node n = Node.select_single(cnx, "node_select_by_id", id); Calendar limit = Calendar.getInstance(); limit.add(Calendar.MINUTE, -10); if (n.getLastSeenAlive() != null && n.getLastSeenAlive().after(limit))
42, "Marsu-Application", null, "Franquin", "ModuleMachin", "other", "other", true, cnx); HttpPost post = new HttpPost("http://" + TestHelpers.node.getDns() + ":" + TestHelpers.node.getPort() + "/ws/simple/ji"); List<NameValuePair> nvps = new ArrayList<>(); nvps.add(new BasicNameValuePair("applicationname", "Marsu-Application")); HttpGet rq = new HttpGet("http://" + TestHelpers.node.getDns() + ":" + TestHelpers.node.getPort() + "/ws/simple/status?id=" + jid); res = client.execute(rq); Assert.assertEquals(200, res.getStatusLine().getStatusCode());