Compare commits

...

2 Commits

Author SHA1 Message Date
Akshay Jagadish
137e8596a2 WIFI-846: Add component version and commit hash to application ping
response
2020-10-01 18:21:17 -04:00
Akshay Jagadish
cbad366ac3 WIFI-846: Add component version and commit hash to application ping
response
2020-10-01 13:32:28 -04:00
4 changed files with 89 additions and 5 deletions

View File

@@ -0,0 +1,44 @@
package com.telecominfraproject.wlan.core.server.container;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CommitProperties {
private static final Logger LOG = LoggerFactory.getLogger(CommitProperties.class);
private static final String PROP_FILE = "commit.properties";
private final Properties prop = new Properties();
private final String date;
private final String commitId;
private final String version;
public CommitProperties() {
loadStream(prop);
this.date = prop.getProperty("date", "");
this.commitId = prop.getProperty("commitId", "");
this.version = prop.getProperty("projectVersion", "");
}
public String getCommitDate() {
return date;
}
public String getCommitID() {
return commitId;
}
public String getProjectVersion() {
return version;
}
private void loadStream(final Properties prop) {
try (final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(PROP_FILE)) {
prop.load(inputStream);
} catch (final Exception e) {
LOG.info("Properties file not present");
}
}
}

View File

@@ -34,6 +34,12 @@ public abstract class ServletContainerCustomizer implements WebServerFactoryCust
return new ConnectorPropertiesImpl(appContext.getEnvironment()); return new ConnectorPropertiesImpl(appContext.getEnvironment());
} }
@Bean
CommitProperties commitProperties(){
return new CommitProperties();
}
private static final Logger LOG = LoggerFactory.getLogger(ServletContainerCustomizer.class); private static final Logger LOG = LoggerFactory.getLogger(ServletContainerCustomizer.class);
// see http://docs.spring.io/spring-boot/docs/1.1.1.RELEASE/reference/htmlsingle/#howto-terminate-ssl-in-tomcat // see http://docs.spring.io/spring-boot/docs/1.1.1.RELEASE/reference/htmlsingle/#howto-terminate-ssl-in-tomcat

View File

@@ -7,6 +7,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.telecominfraproject.wlan.core.server.container.CommitProperties;
import com.telecominfraproject.wlan.core.server.container.ConnectorProperties; import com.telecominfraproject.wlan.core.server.container.ConnectorProperties;
@@ -21,19 +22,26 @@ public class PingController {
private static final Logger LOG = LoggerFactory.getLogger(PingController.class); private static final Logger LOG = LoggerFactory.getLogger(PingController.class);
@Autowired private ApplicationContext applicationContext; @Autowired private ApplicationContext applicationContext;
@Autowired private ConnectorProperties connectorProperties; @Autowired private ConnectorProperties connectorProperties;
@Autowired private CommitProperties commitProperties;
@GetMapping("/ping") @GetMapping("/ping")
public @ResponseBody PingResponse ping() { public @ResponseBody PingResponse ping() {
PingResponse ret = new PingResponse( PingResponse ret = new PingResponse(
applicationContext.getStartupDate(), applicationContext.getStartupDate(),
System.currentTimeMillis(), System.currentTimeMillis(),
applicationContext.getEnvironment().getProperty("app.name"), applicationContext.getEnvironment().getProperty("app.name"),
applicationContext.getEnvironment().getProperty("elb", connectorProperties.getExternalHostName())); applicationContext.getEnvironment().getProperty("elb", connectorProperties.getExternalHostName()),
commitProperties.getCommitID(),
commitProperties.getCommitDate(),
commitProperties.getProjectVersion()
);
LOG.debug("ping: {} / {}", ret.getStartupTime(), ret.getCurrentTime()); LOG.debug("ping: {} / {}", ret.getStartupTime(), ret.getCurrentTime());
return ret; return ret;
} }
} }

View File

@@ -14,6 +14,12 @@ public class PingResponse extends BaseJsonModel {
private String applicationName; private String applicationName;
private String hostName; private String hostName;
private String commitID;
private String commitDate;
private String projectVersion;
protected PingResponse() protected PingResponse()
{ {
super(); super();
@@ -26,6 +32,13 @@ public class PingResponse extends BaseJsonModel {
this.hostName = hostName; this.hostName = hostName;
} }
public PingResponse(long startupTime, long currentTime, String applicationName, String hostName, String commitID, String commitDate, String projectVersion){
this(startupTime, currentTime, applicationName, hostName);
this.commitID = commitID;
this.commitDate = commitDate;
this.projectVersion = projectVersion;
}
public long getStartupTime() { public long getStartupTime() {
return startupTime; return startupTime;
} }
@@ -40,4 +53,17 @@ public class PingResponse extends BaseJsonModel {
return hostName; return hostName;
} }
public String getCommitID() {
return commitID;
}
public String getCommitDate() {
return commitDate;
}
public String getProjectVersion() {
return projectVersion;
}
} }