Repository: incubator-unomi Updated Branches: refs/heads/master 710ed14bb -> 32a7704f3
UNOMI-73 Add a log when Unomi is properly initialized. - Display shutdown message in System.out, but only once - Add version, build number and timestamp to log - Quick cleanups Signed-off-by: Serge Huber <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/32a7704f Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/32a7704f Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/32a7704f Branch: refs/heads/master Commit: 32a7704f3f591bb8742fd12bbd4dc118191843d5 Parents: 710ed14 Author: Serge Huber <[email protected]> Authored: Fri Jan 20 11:52:50 2017 +0100 Committer: Serge Huber <[email protected]> Committed: Fri Jan 20 11:52:50 2017 +0100 ---------------------------------------------------------------------- lifecycle-watcher/pom.xml | 34 ++++++++++ .../apache/unomi/lifecycle/BundleWatcher.java | 69 +++++++++++++------- .../ElasticSearchPersistenceServiceImpl.java | 5 -- src/site/markdown/configuration.md | 2 +- 4 files changed, 81 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/32a7704f/lifecycle-watcher/pom.xml ---------------------------------------------------------------------- diff --git a/lifecycle-watcher/pom.xml b/lifecycle-watcher/pom.xml index b8e7353..419f7bf 100644 --- a/lifecycle-watcher/pom.xml +++ b/lifecycle-watcher/pom.xml @@ -38,4 +38,38 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>buildnumber-maven-plugin</artifactId> + <version>1.4</version> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>create</goal> + </goals> + </execution> + </executions> + <configuration> + <shortRevisionLength>5</shortRevisionLength> + <doCheck>false</doCheck> + <doUpdate>false</doUpdate> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> + <Implementation-Build>${buildNumber}</Implementation-Build> + <Implementation-TimeStamp>${timestamp}</Implementation-TimeStamp> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + </project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/32a7704f/lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcher.java ---------------------------------------------------------------------- diff --git a/lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcher.java b/lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcher.java index d688ff8..edce52d 100644 --- a/lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcher.java +++ b/lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcher.java @@ -45,6 +45,7 @@ public class BundleWatcher implements SynchronousBundleListener, ServiceListener private BundleContext bundleContext; private boolean startupMessageAlreadyDisplayed = false; + private boolean shutdownMessageAlreadyDisplayed = false; private List<String> logoLines = new ArrayList<>(); public void setRequiredStartedBundleCount(long requiredStartedBundleCount) { @@ -71,28 +72,7 @@ public class BundleWatcher implements SynchronousBundleListener, ServiceListener public void init() { bundleContext.addBundleListener(this); bundleContext.addServiceListener(this); - URL logoURL = bundleContext.getBundle().getResource("logo.txt"); - if (logoURL != null) { - BufferedReader bufferedReader = null; - try { - bufferedReader = new BufferedReader(new InputStreamReader(logoURL.openStream())); - String line; - while ((line = bufferedReader.readLine()) != null) { - if (!line.trim().startsWith("#")) { - logoLines.add(line); - } - } - } catch (IOException e) { - logger.error("Error loading logo lines", e); - } finally { - if (bufferedReader != null) { - try { - bufferedReader.close(); - } catch (IOException e) { - } - } - } - } + loadLogo(); startupTime = System.currentTimeMillis(); logger.info("Bundle watcher initialized."); } @@ -155,7 +135,11 @@ public class BundleWatcher implements SynchronousBundleListener, ServiceListener for (Filter requiredService : requiredServicesFilters) { if (requiredService.match(serviceReference)) { matchedRequiredServicesCount--; - logger.info("Apache Unomi no longer available, as required service {} is shutdown !", serviceReference); + if (!shutdownMessageAlreadyDisplayed) { + System.out.println("Apache Unomi shutting down..."); + logger.info("Apache Unomi no longer available, as required service {} is shutdown !", serviceReference); + shutdownMessageAlreadyDisplayed = true; + } startupMessageAlreadyDisplayed = false; } } @@ -172,9 +156,22 @@ public class BundleWatcher implements SynchronousBundleListener, ServiceListener System.out.println(logoLine); } } + String buildNumber = "n/a"; + if (bundleContext.getBundle().getHeaders().get("Implementation-Build") != null) { + buildNumber = bundleContext.getBundle().getHeaders().get("Implementation-Build"); + } + String timestamp = "n/a"; + if (bundleContext.getBundle().getHeaders().get("Implementation-TimeStamp") != null) { + timestamp = bundleContext.getBundle().getHeaders().get("Implementation-TimeStamp"); + } + String versionMessage = " " + bundleContext.getBundle().getVersion().toString() + " Build:" + buildNumber + " Timestamp:" + timestamp; + System.out.println(versionMessage); + System.out.println("--------------------------------------------------------------------------"); System.out.println("Successfully started " + unomiStartedBundleCount + " bundles and " + matchedRequiredServicesCount + " required services in " + totalStartupTime + " ms"); + logger.info("Apache Unomi version: " + versionMessage); logger.info("Apache Unomi successfully started {} bundles and {} required services in {} ms", unomiStartedBundleCount, matchedRequiredServicesCount, totalStartupTime); startupMessageAlreadyDisplayed = true; + shutdownMessageAlreadyDisplayed = false; } } @@ -187,4 +184,30 @@ public class BundleWatcher implements SynchronousBundleListener, ServiceListener } return true; } + + private void loadLogo() { + URL logoURL = bundleContext.getBundle().getResource("logo.txt"); + if (logoURL != null) { + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new InputStreamReader(logoURL.openStream())); + String line; + while ((line = bufferedReader.readLine()) != null) { + if (!line.trim().startsWith("#")) { + logoLines.add(line); + } + } + } catch (IOException e) { + logger.error("Error loading logo lines", e); + } finally { + if (bufferedReader != null) { + try { + bufferedReader.close(); + } catch (IOException e) { + } + } + } + } + } + } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/32a7704f/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java ---------------------------------------------------------------------- diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java index 04f0602..e2d1645 100644 --- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java +++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java @@ -97,11 +97,6 @@ public class ElasticSearchPersistenceServiceImpl implements PersistenceService, private static final Logger logger = LoggerFactory.getLogger(ElasticSearchPersistenceServiceImpl.class.getName()); - public static final String CONTEXTSERVER_ADDRESS = "contextserver.address"; - public static final String CONTEXTSERVER_PORT = "contextserver.port"; - public static final String CONTEXTSERVER_SECURE_ADDRESS = "contextserver.secureAddress"; - public static final String CONTEXTSERVER_SECURE_PORT = "contextserver.securePort"; - public static final String NUMBER_OF_SHARDS = "number_of_shards"; public static final String NUMBER_OF_REPLICAS = "number_of_replicas"; public static final String CLUSTER_NAME = "cluster.name"; http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/32a7704f/src/site/markdown/configuration.md ---------------------------------------------------------------------- diff --git a/src/site/markdown/configuration.md b/src/site/markdown/configuration.md index df8afb7..1d39ba9 100644 --- a/src/site/markdown/configuration.md +++ b/src/site/markdown/configuration.md @@ -35,7 +35,7 @@ If you need to specify an Elasticsearch cluster name, or a host and port that ar it is recommended to do this BEFORE you start the server for the first time, or you will loose all the data you have stored previously. -To change these settings, first create a file called +To change these settings, you will need to modify a file called $MY_KARAF_HOME/etc/org.apache.unomi.persistence.elasticsearch.cfg
