You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ha...@apache.org on 2016/11/10 04:26:28 UTC
incubator-eagle git commit: [EAGLE-734] Integrate
maven-buildNumber-plugin and Version.java
Repository: incubator-eagle
Updated Branches:
refs/heads/master 32582d230 -> 3099a9e8c
[EAGLE-734] Integrate maven-buildNumber-plugin and Version.java
* Integrate maven-buildNumber-plugin and Version.java
* Format eagle version desc
* Add `/server/version` and `/server/config` API
Author: Hao Chen <ha...@apache.org>
Closes #639 from haoch/buildNumberVersion.
Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/3099a9e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/3099a9e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/3099a9e8
Branch: refs/heads/master
Commit: 3099a9e8ccabd3c371afe8f61fd8a1a151083232
Parents: 32582d2
Author: Hao Chen <ha...@apache.org>
Authored: Thu Nov 10 12:26:22 2016 +0800
Committer: Hao Chen <ha...@apache.org>
Committed: Thu Nov 10 12:26:22 2016 +0800
----------------------------------------------------------------------
eagle-core/eagle-common/pom.xml | 43 ++++++++++++++
.../org/apache/eagle/common/Version.java | 59 ++++++++++++++++++++
.../org/apache/eagle/common/TestVersion.java | 27 +++++++++
.../apache/eagle/server/ServerApplication.java | 6 +-
.../org/apache/eagle/server/ServerConfig.java | 22 ++++++--
.../org/apache/eagle/server/ServerMain.java | 9 ++-
.../server/managedtask/ApplicationTask.java | 43 --------------
.../eagle/server/resource/ServerResource.java | 48 ++++++++++++++++
.../eagle/server/task/ApplicationTask.java | 42 ++++++++++++++
pom.xml | 16 +++++-
10 files changed, 262 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/eagle-core/eagle-common/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/pom.xml b/eagle-core/eagle-common/pom.xml
index 26b8f8f..933d4e2 100644
--- a/eagle-core/eagle-common/pom.xml
+++ b/eagle-core/eagle-common/pom.xml
@@ -109,6 +109,49 @@
<failsOnError>true</failsOnError>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>buildnumber-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>1</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>create</goal>
+ <goal>create-metadata</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <format>{0,number}</format>
+ <items>
+ <item>buildNumber</item>
+ </items>
+ <attach>false</attach>
+ <addOutputDirectoryToResources>true</addOutputDirectoryToResources>
+ <doCheck>true</doCheck>
+ <doUpdate>true</doUpdate>
+ <properties>
+ <buildNumber>${buildNumber}</buildNumber>
+ <userName>${user.name}</userName>
+ </properties>
+ <useLastCommittedRevision>false</useLastCommittedRevision>
+ <revisionOnScmFailure>unknown</revisionOnScmFailure>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>templating-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>filtering-java-templates</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>filter-sources</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/eagle-core/eagle-common/src/main/java-templates/org/apache/eagle/common/Version.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java-templates/org/apache/eagle/common/Version.java b/eagle-core/eagle-common/src/main/java-templates/org/apache/eagle/common/Version.java
new file mode 100644
index 0000000..0b84211
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java-templates/org/apache/eagle/common/Version.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.eagle.common;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Properties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class Version {
+ public static final String projectName = "Eagle";
+ public static final String moduleName = "${project.name}";
+ public static final String version = "${project.version}";
+ public static final String buildNumber = "${buildNumber}";
+ public static String gitRevision = "${revision}";
+ public static final String userName = "${user.name}";
+ public static final String timestamp = "${timestamp}";
+
+ private static final Logger LOG = LoggerFactory.getLogger(Version.class);
+
+ static {
+ InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("build.properties");
+ Properties p = new Properties();
+ try {
+ p.load(resourceAsStream);
+ gitRevision = p.getProperty("revision", "unknown");
+ } catch (IOException e) {
+ LOG.error(e.getMessage(),e);
+ } finally {
+ LOG.info("Eagle {} {}",Version.version, DateTimeUtil.millisecondsToHumanDateWithSeconds(Long.parseLong(Version.timestamp)));
+ }
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s version=%s buildNumber=%s gitRevision=%s built by %s on %s",
+ projectName, version, buildNumber, gitRevision, userName, new Date(Long.parseLong(timestamp)));
+ }
+
+ public static String str() {
+ return new Version().toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestVersion.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestVersion.java b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestVersion.java
new file mode 100644
index 0000000..889cf88
--- /dev/null
+++ b/eagle-core/eagle-common/src/test/java/org/apache/eagle/common/TestVersion.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.eagle.common;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestVersion {
+ @Test
+ public void testVersion(){
+ Assert.assertNotNull(Version.str());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java b/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java
index df1d7e7..8facd15 100644
--- a/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java
+++ b/eagle-server/src/main/java/org/apache/eagle/server/ServerApplication.java
@@ -28,11 +28,12 @@ import io.swagger.jaxrs.config.BeanConfig;
import io.swagger.jaxrs.listing.ApiListingResource;
import org.apache.eagle.alert.coordinator.CoordinatorListener;
import org.apache.eagle.alert.resource.SimpleCORSFiler;
+import org.apache.eagle.common.Version;
import org.apache.eagle.log.base.taggedlog.EntityJsonModule;
import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
import org.apache.eagle.metadata.service.ApplicationStatusUpdateService;
import org.apache.eagle.server.authentication.BasicAuthProviderBuilder;
-import org.apache.eagle.server.managedtask.ApplicationTask;
+import org.apache.eagle.server.task.ApplicationTask;
import org.apache.eagle.server.module.GuiceBundleLoader;
import javax.servlet.DispatcherType;
@@ -69,11 +70,12 @@ class ServerApplication extends Application<ServerConfig> {
BeanConfig swaggerConfig = new BeanConfig();
swaggerConfig.setTitle(ServerConfig.getServerName());
- swaggerConfig.setVersion(ServerConfig.getServerVersion());
+ swaggerConfig.setVersion(ServerConfig.getServerVersion().version);
swaggerConfig.setBasePath(ServerConfig.getApiBasePath());
swaggerConfig.setResourcePackage(ServerConfig.getResourcePackage());
swaggerConfig.setLicense(ServerConfig.getLicense());
swaggerConfig.setLicenseUrl(ServerConfig.getLicenseUrl());
+ swaggerConfig.setDescription(Version.str());
swaggerConfig.setScan(true);
// Simple CORS filter
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java b/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java
index 0afe63b..89d600a 100644
--- a/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java
+++ b/eagle-server/src/main/java/org/apache/eagle/server/ServerConfig.java
@@ -19,12 +19,12 @@ package org.apache.eagle.server;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import io.dropwizard.Configuration;
+import org.apache.eagle.common.Version;
import org.apache.eagle.server.authentication.config.AuthenticationSettings;
import org.codehaus.jackson.annotate.JsonProperty;
public class ServerConfig extends Configuration {
private static final String SERVER_NAME = "Apache Eagle";
- private static final String SERVER_VERSION = "0.5.0-incubating";
private static final String API_BASE_PATH = "/rest/*";
private static final String CONTEXT_PATH = "/";
private static final String RESOURCE_PACKAGE = "org.apache.eagle";
@@ -47,12 +47,12 @@ public class ServerConfig extends Configuration {
this.auth = auth;
}
- static String getServerName() {
+ public static String getServerName() {
return SERVER_NAME;
}
- static String getServerVersion() {
- return SERVER_VERSION;
+ public static ServerVersion getServerVersion() {
+ return ServerVersion.CURRENT;
}
static String getApiBasePath() {
@@ -74,4 +74,18 @@ public class ServerConfig extends Configuration {
static String getLicenseUrl() {
return LICENSE_URL;
}
+
+ public static final class ServerVersion {
+ public final String name = SERVER_NAME;
+ public final String version = Version.version;
+ public final String buildNumber = Version.buildNumber;
+ public final String gitRevision = Version.gitRevision;
+ public final String userName = Version.userName;
+ public final String timestamp = Version.timestamp;
+ public final String description = Version.str();
+
+ private ServerVersion(){}
+
+ private static final ServerVersion CURRENT = new ServerVersion();
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/eagle-server/src/main/java/org/apache/eagle/server/ServerMain.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/ServerMain.java b/eagle-server/src/main/java/org/apache/eagle/server/ServerMain.java
index cdb243e..318a74e 100644
--- a/eagle-server/src/main/java/org/apache/eagle/server/ServerMain.java
+++ b/eagle-server/src/main/java/org/apache/eagle/server/ServerMain.java
@@ -16,12 +16,15 @@
*/
package org.apache.eagle.server;
+import org.apache.eagle.common.Version;
+
+import java.util.Date;
+
public class ServerMain {
public static void main(String[] args) {
System.out.println(
- "----------------------------\n"
- + " Apache Eagle\u2122 (Incubating)\n"
- + "----------------------------"
+ "\nApache Eagle\u2122 v" + Version.version + ": "
+ + "built with git revision " + Version.gitRevision + " by " + Version.userName + " on " + new Date(Long.parseLong(Version.timestamp))
);
System.out.println("\nStarting Eagle Server ...\n");
try {
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/eagle-server/src/main/java/org/apache/eagle/server/managedtask/ApplicationTask.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/managedtask/ApplicationTask.java b/eagle-server/src/main/java/org/apache/eagle/server/managedtask/ApplicationTask.java
deleted file mode 100644
index b3a1b95..0000000
--- a/eagle-server/src/main/java/org/apache/eagle/server/managedtask/ApplicationTask.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.eagle.server.managedtask;
-
-import com.google.common.util.concurrent.AbstractScheduledService;
-import io.dropwizard.lifecycle.Managed;
-import org.apache.eagle.app.service.impl.ApplicationStatusUpdateServiceImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ApplicationTask implements Managed {
- private static final Logger LOG = LoggerFactory.getLogger(ApplicationTask.class);
- private final AbstractScheduledService service;
-
- public ApplicationTask(AbstractScheduledService service) {
- this.service = service;
- }
-
- @Override
- public void start() throws Exception {
- LOG.info("Application update task started:");
- service.startAsync().awaitRunning();
- }
-
- @Override
- public void stop() throws Exception {
- service.stopAsync().awaitTerminated();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/eagle-server/src/main/java/org/apache/eagle/server/resource/ServerResource.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/resource/ServerResource.java b/eagle-server/src/main/java/org/apache/eagle/server/resource/ServerResource.java
new file mode 100644
index 0000000..3dececc
--- /dev/null
+++ b/eagle-server/src/main/java/org/apache/eagle/server/resource/ServerResource.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.eagle.server.resource;
+
+import com.google.inject.Inject;
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigRenderOptions;
+import org.apache.eagle.server.ServerConfig;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+/**
+ * Serve server internal information as API.
+ */
+@Path("server")
+public class ServerResource {
+ private @Inject Config config;
+
+ @GET
+ @Path("/version")
+ @Produces( {"application/json"})
+ public ServerConfig.ServerVersion version() {
+ return ServerConfig.getServerVersion();
+ }
+
+ @GET
+ @Path("/config")
+ @Produces( {"application/json"})
+ public String config() {
+ return config.root().render(ConfigRenderOptions.concise());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/eagle-server/src/main/java/org/apache/eagle/server/task/ApplicationTask.java
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/java/org/apache/eagle/server/task/ApplicationTask.java b/eagle-server/src/main/java/org/apache/eagle/server/task/ApplicationTask.java
new file mode 100644
index 0000000..0cddee7
--- /dev/null
+++ b/eagle-server/src/main/java/org/apache/eagle/server/task/ApplicationTask.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.eagle.server.task;
+
+import com.google.common.util.concurrent.AbstractScheduledService;
+import io.dropwizard.lifecycle.Managed;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ApplicationTask implements Managed {
+ private static final Logger LOG = LoggerFactory.getLogger(ApplicationTask.class);
+ private final AbstractScheduledService service;
+
+ public ApplicationTask(AbstractScheduledService service) {
+ this.service = service;
+ }
+
+ @Override
+ public void start() throws Exception {
+ LOG.info("Application update task started:");
+ service.startAsync().awaitRunning();
+ }
+
+ @Override
+ public void stop() throws Exception {
+ service.stopAsync().awaitTerminated();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3099a9e8/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 941e889..0108df4 100755
--- a/pom.xml
+++ b/pom.xml
@@ -170,6 +170,9 @@
<cobertura-maven.version>2.7</cobertura-maven.version>
<coveralls-maven.version>4.3.0</coveralls-maven.version>
+ <buildnumber-maven.version>1.4</buildnumber-maven.version>
+ <templating-maven.version>1.0.0</templating-maven.version>
+
<!-- Environment Versions-->
<thrift.version>0.9.2</thrift.version>
<hadoop.version>2.6.0.2.2.5.1-3</hadoop.version>
@@ -1185,6 +1188,16 @@
<artifactId>coveralls-maven-plugin</artifactId>
<version>${coveralls-maven.version}</version>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>buildnumber-maven-plugin</artifactId>
+ <version>${buildnumber-maven.version}</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>templating-maven-plugin</artifactId>
+ <version>${templating-maven.version}</version>
+ </plugin>
</plugins>
</pluginManagement>
<plugins>
@@ -1284,10 +1297,11 @@
<exclude>**/jquery-*.js</exclude>
<exclude>**/MANIFEST.MF</exclude>
<!-- External dependency script -->
- <exclude>**/resource/serf/etc/ambari.json</exclude>
+ <exclude>**/.json</exclude>
<exclude>**/webapp/**</exclude>
<exclude>**/*.pid</exclude>
+ <exclude>**/buildNumber.properties</exclude>
</excludes>
</configuration>
</execution>