public NflowStandardEnvironment(Map<String, Object> overrideProperties) { getPropertySources().addFirst(new MapPropertySource("override", overrideProperties)); addExternalPropertyResource(); String env = getProperty("env", "local"); addActiveProfile(env); addPropertyResource(env); addPropertyResource("common"); addPropertyResource("nflow-server"); String profiles = getProperty("profiles", String.class, ""); for (String profile : profiles.split(",")) { if (!profile.trim().isEmpty()) { addActiveProfile(profile); } } setupDbProfile(); }
private void setupDbProfile() { boolean dbProfileDefined = false; String[] activeProfiles = getActiveProfiles(); for (String profile : activeProfiles) { if (profile.startsWith("nflow.db")) { if (dbProfileDefined) { throw new RuntimeException("Multiple nflow.db profiles defined: " + Arrays.toString(activeProfiles)); } dbProfileDefined = true; } } if (!dbProfileDefined) { addActiveProfile(H2); } }
private void addExternalPropertyResource() { String externalLocation = getProperty("nflow.external.config"); if (!isEmpty(externalLocation)) { try { getPropertySources().addLast(new ResourcePropertySource(externalLocation)); logger.info("Using external configuration file: {}", externalLocation); } catch (IOException e) { throw new RuntimeException("Failed to initialize external properties from location " + externalLocation, e); } } }
private void addPropertyResource(String name) { name += ".properties"; try { getPropertySources().addLast(new ResourcePropertySource(name, getClass().getClassLoader())); } catch (@SuppressWarnings("unused") IOException e) { logger.info("Failed to initialize environment-specific properties from resource {}", name); } } }
public JettyServerContainer startJetty(Map<String, Object> properties) throws Exception { long start = currentTimeMillis(); // also CXF uses JDK logging SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); ConfigurableEnvironment env = new NflowStandardEnvironment(properties); String host = env.getRequiredProperty("host"); int port = env.getRequiredProperty("port", Integer.class); KillProcess.gracefullyTerminateOrKillProcessUsingPort(port, env.getRequiredProperty("terminate.timeout", Integer.class), true); Server server = setupServer(); setupJmx(server, env); setupServerConnector(server, host, port); ServletContextHandler context = setupServletContextHandler(env.getRequiredProperty("extra.resource.directories", String[].class)); setupHandlers(server, context, env); setupSpring(context, env); setupCxf(context); setupMetricsAdminServlet(context); server.start(); long end = currentTimeMillis(); JettyServerContainer startedServer = new JettyServerContainer(server); port = startedServer.getPort(); logger.info("Successfully started Jetty on port {} in {} seconds in environment {}", port, (end - start) / 1000.0, Arrays.toString(env.getActiveProfiles())); logger.info("API available at http://{}:{}/nflow/api/", host, port); logger.info("Swagger available at http://{}:{}/nflow/ui/doc/", host, port); logger.info("Explorer available at http://{}:{}/nflow/ui/explorer/", host, port); logger.info("Metrics and health checks available at http://{}:{}/nflow/metrics/", host, port); return startedServer; }