brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [2/6] git commit: Build produces Git SHA 1 and branch name metadata
Date Wed, 27 Aug 2014 10:02:19 GMT
Build produces Git SHA 1 and branch name metadata

Incorporated into
* manifests as Implementation-SHA-1 and Implementation-Branch
* REST API at /v1/server/version.
* jsgui (only sha-1) as comment in index.html


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/8887561d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/8887561d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/8887561d

Branch: refs/heads/master
Commit: 8887561dbd2e61f53b444808c373bff228d39341
Parents: c742881
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Fri Aug 22 15:39:23 2014 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Fri Aug 22 15:39:23 2014 +0100

----------------------------------------------------------------------
 pom.xml                                         | 23 ++++++++
 usage/jsgui/pom.xml                             |  4 ++
 usage/jsgui/src/main/webapp/index.html          |  3 +-
 .../main/java/brooklyn/rest/api/ServerApi.java  |  3 +-
 .../brooklyn/rest/domain/VersionSummary.java    | 61 ++++++++++++++++++++
 usage/rest-server/pom.xml                       |  7 +++
 .../brooklyn/rest/resources/ServerResource.java | 22 ++++++-
 .../main/resources/build-metadata.properties    | 18 ++++++
 .../rest/resources/ServerResourceTest.java      |  5 +-
 9 files changed, 139 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8887561d/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index aca1329..b8caa25 100644
--- a/pom.xml
+++ b/pom.xml
@@ -822,6 +822,14 @@
                     <version>1.4.0</version>
                 </plugin>
                 <plugin>
+                    <groupId>org.codehaus.mojo</groupId>
+                    <artifactId>buildnumber-maven-plugin</artifactId>
+                    <version>1.3</version>
+                    <configuration>
+                        <getRevisionOnlyOnce>true</getRevisionOnlyOnce>
+                    </configuration>
+                </plugin>
+                <plugin>
                     <!-- This configuration is used for Eclipse settings only. -->
                     <groupId>org.eclipse.m2e</groupId>
                     <artifactId>lifecycle-mapping</artifactId>
@@ -913,10 +921,23 @@
                          </lifecycleMappingMetadata>
                     </configuration>
                 </plugin>
+
             </plugins>
         </pluginManagement>
         <plugins>
             <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>buildnumber-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>validate</phase>
+                        <goals>
+                            <goal>create</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
                 <artifactId>maven-enforcer-plugin</artifactId>
                 <executions>
                     <execution>
@@ -1251,6 +1272,8 @@
                                     what is really needed.
                                 -->
                                 <Export-Package>brooklyn.*</Export-Package>
+                                <Implementation-SHA-1>${buildNumber}</Implementation-SHA-1>
+                                <Implementation-Branch>${scmBranch}</Implementation-Branch>
                             </instructions>
                         </configuration>
                     </plugin>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8887561d/usage/jsgui/pom.xml
----------------------------------------------------------------------
diff --git a/usage/jsgui/pom.xml b/usage/jsgui/pom.xml
index 85e90bc..a768298 100644
--- a/usage/jsgui/pom.xml
+++ b/usage/jsgui/pom.xml
@@ -394,6 +394,10 @@
                                     <token>assets/css/styles.css</token>
                                     <value>assets/css/styles.min.css</value>
                                 </replacement>
+                                <replacement>
+                                    <token>GIT_SHA_1</token>
+                                    <value>${buildNumber}</value>
+                                </replacement>
                             </replacements>
                         </configuration>
                     </plugin>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8887561d/usage/jsgui/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/usage/jsgui/src/main/webapp/index.html b/usage/jsgui/src/main/webapp/index.html
index 0bdead6..f621f4d 100644
--- a/usage/jsgui/src/main/webapp/index.html
+++ b/usage/jsgui/src/main/webapp/index.html
@@ -1,4 +1,3 @@
-
 <!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
@@ -17,7 +16,7 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 -->
-
+<!-- Brooklyn SHA-1: GIT_SHA_1 -->
 <!DOCTYPE html>
 <html>
 <head>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8887561d/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
index 8aae011..fb9d3c1 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java
@@ -29,6 +29,7 @@ import javax.ws.rs.core.MediaType;
 
 import brooklyn.rest.apidoc.Apidoc;
 import brooklyn.rest.domain.HighAvailabilitySummary;
+import brooklyn.rest.domain.VersionSummary;
 
 import com.google.common.annotations.Beta;
 import com.wordnik.swagger.core.ApiOperation;
@@ -57,7 +58,7 @@ public interface ServerApi {
     @GET
     @Path("/version")
     @ApiOperation(value = "Return version identifier information for this Brooklyn instance",
responseClass = "String", multiValueResponse = false)
-    public String getVersion();
+    public VersionSummary getVersion();
 
     @GET
     @Path("/status")

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8887561d/usage/rest-api/src/main/java/brooklyn/rest/domain/VersionSummary.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/VersionSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/VersionSummary.java
new file mode 100644
index 0000000..9bcbaea
--- /dev/null
+++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/VersionSummary.java
@@ -0,0 +1,61 @@
+/*
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 brooklyn.rest.domain;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+public class VersionSummary {
+
+    private final String version;
+    private final String buildSha1;
+    private final String buildBranch;
+
+    public VersionSummary(String version) {
+        this(version, null, null);
+    }
+
+    public VersionSummary(
+            @JsonProperty("version") String version,
+            @JsonProperty("buildSha1")String buildSha1,
+            @JsonProperty("buildBranch") String buildBranch) {
+        this.version = checkNotNull(version, "version");
+        this.buildSha1 = buildSha1;
+        this.buildBranch = buildBranch;
+    }
+
+    @Nonnull
+    public String getVersion() {
+        return version;
+    }
+
+    @Nullable
+    public String getBuildSha1() {
+        return buildSha1;
+    }
+
+    @Nullable
+    public String getBuildBranch() {
+        return buildBranch;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8887561d/usage/rest-server/pom.xml
----------------------------------------------------------------------
diff --git a/usage/rest-server/pom.xml b/usage/rest-server/pom.xml
index 39c6ecb..2a6997d 100644
--- a/usage/rest-server/pom.xml
+++ b/usage/rest-server/pom.xml
@@ -243,6 +243,13 @@
     </dependencies>
 
     <build>
+        <resources>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+                <!-- Required to set values in build-metadata.properties -->
+                <filtering>true</filtering>
+            </resource>
+        </resources>
         <plugins>
 
 <!-- if you want to build a WAR, full or skinny:

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8887561d/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
index b9b7180..4a52672 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/ServerResource.java
@@ -18,8 +18,11 @@
  */
 package brooklyn.rest.resources;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Properties;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,7 +39,9 @@ import brooklyn.management.ha.ManagementPlaneSyncRecord;
 import brooklyn.management.internal.ManagementContextInternal;
 import brooklyn.rest.api.ServerApi;
 import brooklyn.rest.domain.HighAvailabilitySummary;
+import brooklyn.rest.domain.VersionSummary;
 import brooklyn.rest.transform.HighAvailabilityTransformer;
+import brooklyn.util.ResourceUtils;
 import brooklyn.util.time.CountdownTimer;
 import brooklyn.util.time.Duration;
 
@@ -44,6 +49,9 @@ public class ServerResource extends AbstractBrooklynRestResource implements
Serv
 
     private static final Logger log = LoggerFactory.getLogger(ServerResource.class);
 
+    private static final String BUILD_SHA_1_PROPERTY = "git-sha-1";
+    private static final String BUILD_BRANCH_PROPERTY = "git-branch-name";
+
     @Override
     public void reloadBrooklynProperties() {
         brooklyn().reloadBrooklynProperties();
@@ -81,8 +89,18 @@ public class ServerResource extends AbstractBrooklynRestResource implements
Serv
     }
 
     @Override
-    public String getVersion() {
-        return BrooklynVersion.get();
+    public VersionSummary getVersion() {
+        InputStream input = ResourceUtils.create().getResourceFromUrl("classpath://build-metadata.properties");
+        Properties properties = new Properties();
+        String gitSha1 = null, gitBranch = null;
+        try {
+            properties.load(input);
+            gitSha1 = properties.getProperty(BUILD_SHA_1_PROPERTY);
+            gitBranch = properties.getProperty(BUILD_BRANCH_PROPERTY);
+        } catch (IOException e) {
+            log.error("Failed to load build-metadata.properties", e);
+        }
+        return new VersionSummary(BrooklynVersion.get(), gitSha1, gitBranch);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8887561d/usage/rest-server/src/main/resources/build-metadata.properties
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/resources/build-metadata.properties b/usage/rest-server/src/main/resources/build-metadata.properties
new file mode 100644
index 0000000..eab85ef
--- /dev/null
+++ b/usage/rest-server/src/main/resources/build-metadata.properties
@@ -0,0 +1,18 @@
+# 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
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+git-sha-1 = ${buildNumber}
+git-branch-name = ${scmBranch}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8887561d/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
b/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
index a540046..3e4951a 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/ServerResourceTest.java
@@ -33,6 +33,7 @@ import brooklyn.BrooklynVersion;
 import brooklyn.management.ManagementContext;
 import brooklyn.management.entitlement.Entitlements;
 import brooklyn.rest.domain.HighAvailabilitySummary;
+import brooklyn.rest.domain.VersionSummary;
 import brooklyn.rest.testing.BrooklynRestResourceTest;
 import brooklyn.test.Asserts;
 
@@ -50,8 +51,8 @@ public class ServerResourceTest extends BrooklynRestResourceTest {
 
     @Test
     public void testGetVersion() throws Exception {
-        String version = client().resource("/v1/server/version").get(String.class);
-        assertEquals(version, BrooklynVersion.get());
+        VersionSummary version = client().resource("/v1/server/version").get(VersionSummary.class);
+        assertEquals(version.getVersion(), BrooklynVersion.get());
     }
 
     @Test


Mime
View raw message