Skip to content

Commit

Permalink
Merge pull request #27 from ErnestOrt/git-info
Browse files Browse the repository at this point in the history
Git info
  • Loading branch information
ErnestOrt authored Sep 21, 2017
2 parents 55febfc + 7893416 commit 912be2d
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 31 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ Also you will be able to:
* Configurable Actuator endpoint & VM arguments
* Monitor memory usage for each instance, capturing their metrics every 30 seconds.
* Monitor intances trace information any point in time
* Visualize GIT branch and last commit on instances
* Define microservices groups and launch them all with one click

### Requirements

* Java && (Apache Maven || Gradle wrapper)
* Include your Gradle Wrapper next to your build files if your choice is Gradle as a Build Tool
* Start actuator sub-project of Spring Boot on your microservices
* Set up logging.path and/or logging.file properties defined on your microservices in order to be able to visulize logs
* Include your Gradle Wrapper next to your build files if your choice is Gradle as a Build Tool
* Set up git info pluggin on your ms to visulaize git information on deployed instances (see examples provided)

### How do I make it work?

Expand All @@ -42,7 +44,7 @@ You can use Apache Maven or a Gradle Wrapper

Theoretically yes, but only has been fully tested on Windows and Mac OS.

* Will I have to enter data all the time?.
* Can I run it on any OS?.

* I am working with Spring Boot 1.3 or less and instances do not start.

Expand All @@ -56,6 +58,22 @@ You should add security starter on your microservices pom.xml:
```

* Which are the pluggins I should use to retrieve git information?.

```
"gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:1.4.17"
```

```
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.3</version>
</plugin>
```

* Will I have to enter data all the time?.

No, information introduced will be stored in a settings file, next to the script to launch each microservices :grin:

### Contributing
Expand Down
7 changes: 7 additions & 0 deletions microservice-example-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ buildscript {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
maven { url "https://plugins.gradle.org/m2/" }
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:1.4.17")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: "com.gorylenko.gradle-git-properties"

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
Expand All @@ -27,3 +30,7 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

gitProperties {
gitRepositoryRoot = new File("${project.rootDir}/..")
}
6 changes: 6 additions & 0 deletions microservice-example-maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.3</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
endpoints.shutdown.enabled=true
logging.file=service.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.ernest.applications.trampoline.collectors;

import org.ernest.applications.trampoline.entities.Instance;
import org.ernest.applications.trampoline.entities.InstanceInfo;
import org.ernest.applications.trampoline.services.EcosystemManager;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.sql.Date;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

@Component
public class InstanceInfoCollector {

private static final Logger LOGGER = LoggerFactory.getLogger(TraceCollector.class);

@Autowired
EcosystemManager ecosystemManager;

public InstanceInfo getInfo(String idInstance) {
InstanceInfo info = new InstanceInfo();

Instance instance = ecosystemManager.getEcosystem().getInstances().stream().filter(i -> i.getId().equals(idInstance)).findAny().get();
info.setPomLocation(instance.getPomLocation());
try {
JSONObject infoJson = new JSONObject(new RestTemplate().getForObject("http://127.0.0.1:" + instance.getPort() + instance.getActuatorPrefix() + "/info", String.class));

info.setBranch(infoJson.getJSONObject("git").get("branch").toString());
info.setCommitMessage(infoJson.getJSONObject("git").getJSONObject("commit").getJSONObject("message").get("full").toString());
info.setCommitOwner(infoJson.getJSONObject("git").getJSONObject("commit").getJSONObject("user").get("name").toString() + "["+infoJson.getJSONObject("git").getJSONObject("commit").getJSONObject("user").get("email").toString()+"]");

Long timestamp = Long.valueOf(infoJson.getJSONObject("git").getJSONObject("commit").get("time").toString());
info.setCommitDate(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format( new Date(new Timestamp(timestamp).getTime())));
}catch (Exception e){
info.setBranch("-");
info.setCommitMessage("-");
info.setCommitOwner("-");
info.setCommitDate("-");

LOGGER.error("Not possible to retrieve git info for instance: ["+instance.getId()+"] hosted on port: ["+instance.getPort()+"]");
}
return info;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
@Component
public class TraceCollector {

private static final Logger LOGGER = LoggerFactory.getLogger(MetricsCollector.class);

@Autowired
EcosystemManager ecosystemManager;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.ernest.applications.trampoline.controller;

import org.ernest.applications.trampoline.entities.Ecosystem;
import org.ernest.applications.trampoline.entities.Metrics;
import org.ernest.applications.trampoline.entities.Microservice;
import org.ernest.applications.trampoline.entities.TraceActuator;
import org.ernest.applications.trampoline.collectors.InstanceInfoCollector;
import org.ernest.applications.trampoline.entities.*;
import org.ernest.applications.trampoline.exceptions.*;
import org.ernest.applications.trampoline.services.EcosystemManager;
import org.ernest.applications.trampoline.collectors.MetricsCollector;
Expand Down Expand Up @@ -35,6 +33,9 @@ public class InstancesController {
@Autowired
TraceCollector traceCollector;

@Autowired
InstanceInfoCollector instanceInfoCollector;

@RequestMapping("")
public String getInstanceView(Model model) {
Ecosystem ecosystem = ecosystemManager.getEcosystem();
Expand Down Expand Up @@ -81,6 +82,12 @@ public List<TraceActuator> getTraces(@RequestParam(value="id") String id) throws
return traceCollector.getTraces(id);
}

@RequestMapping(value= "/info", method = RequestMethod.POST)
@ResponseBody
public InstanceInfo getInstanceInfoWhenDeployed(@RequestParam(value="id") String id) throws CreatingSettingsFolderException, ReadingEcosystemException {
return instanceInfoCollector.getInfo(id);
}

@RequestMapping(value= "/checkport", method = RequestMethod.POST)
@ResponseBody
public boolean checkPort(@RequestParam(value="port") int port) throws CreatingSettingsFolderException, ReadingEcosystemException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.ernest.applications.trampoline.entities;


public class InstanceInfo {

private String pomLocation;
private String branch;
private String commitMessage;
private String commitOwner;
private String commitDate;

public String getPomLocation() {
return pomLocation;
}

public void setPomLocation(String pomLocation) {
this.pomLocation = pomLocation;
}

public String getBranch() {
return branch;
}

public void setBranch(String branch) {
this.branch = branch;
}

public String getCommitMessage() {
return commitMessage;
}

public void setCommitMessage(String commitMessage) {
this.commitMessage = commitMessage;
}

public String getCommitOwner() {
return commitOwner;
}

public void setCommitOwner(String commitOwner) {
this.commitOwner = commitOwner;
}

public String getCommitDate() {
return commitDate;
}

public void setCommitDate(String commitDate) {
this.commitDate = commitDate;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Microservice {
private String actuatorPrefix;
private String vmArguments;
private BuildTools buildTool;
private Float version;

public String getId() {
return id;
Expand Down Expand Up @@ -54,4 +55,12 @@ public BuildTools getBuildTool() {
public void setBuildTool(BuildTools buildTool) {
this.buildTool = buildTool;
}

public Float getVersion() {
return version;
}

public void setVersion(Float version) {
this.version = version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class FileManager {
@Value("${settings.file.name}")
private String settingsFileName;

@Value("${trampoline.version}")
private float currentVersion;

public Ecosystem getEcosystem() throws CreatingSettingsFolderException, ReadingEcosystemException {
checkIfFileExistsAndCreatedIfNeeded();
Ecosystem ecosystem = null;
Expand All @@ -51,23 +54,35 @@ public Ecosystem getEcosystem() throws CreatingSettingsFolderException, ReadingE
return ecosystem;
}

private void updateMicroservicesInformationStored(Ecosystem ecosystem) {
if(ecosystem.getMicroservices().stream().anyMatch(m -> m.getActuatorPrefix() == null || m.getVmArguments() == null)){
ecosystem.getMicroservices().stream().filter(m -> m.getActuatorPrefix() == null || m.getVmArguments() == null).forEach(m ->{
m.setVmArguments("");
m.setActuatorPrefix("");
m.setBuildTool(BuildTools.MAVEN);
createScript(m);
});

saveEcosystem(ecosystem);
}

if(ecosystem.getMicroservices().stream().anyMatch(m -> m.getBuildTool() == null)){
ecosystem.getMicroservices().stream().filter(m -> m.getBuildTool() == null).forEach(m -> m.setBuildTool(BuildTools.MAVEN));
private void updateMicroservicesInformationStored(Ecosystem ecosystem) {
boolean ecosystemChanged = false;
if(ecosystem.getMicroservices().stream().anyMatch(m -> m.getActuatorPrefix() == null || m.getVmArguments() == null)){
ecosystem.getMicroservices().stream().filter(m -> m.getActuatorPrefix() == null || m.getVmArguments() == null).forEach(m ->{
m.setVmArguments("");
m.setActuatorPrefix("");
m.setBuildTool(BuildTools.MAVEN);
createScript(m);
});
ecosystemChanged = true;
}

if(ecosystem.getMicroservices().stream().anyMatch(m -> m.getBuildTool() == null)){
ecosystem.getMicroservices().stream().filter(m -> m.getBuildTool() == null).forEach(m -> m.setBuildTool(BuildTools.MAVEN));
ecosystemChanged = true;
}

if(ecosystem.getMicroservices().stream().anyMatch(m -> m.getVersion() == null)){
ecosystem.getMicroservices().stream().filter(m -> m.getVersion() == null).forEach(m -> {
m.setVersion(currentVersion);
createScript(m);
});
ecosystemChanged = true;
}

if(ecosystemChanged){
saveEcosystem(ecosystem);
}
}
}

public void saveEcosystem(Ecosystem ecosystem) throws SavingEcosystemException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ public class ScriptContentsProvider {

public static String getMavenWindows(String pomLocation){
return "SET M2_HOME=#mavenHomeLocation&& SET PATH=%PATH%;#mavenBinaryLocation&& cd " + pomLocation + " && mvn spring-boot:run -Dserver.port=#port "
+ "-Dendpoints.shutdown.enabled=true -Dmanagement.security.enabled=false #vmArguments";
+ "-Dendpoints.shutdown.enabled=true -Dmanagement.security.enabled=false -Dmanagement.info.git.mode=full #vmArguments";
}

public static String getGradleWindows(String pomLocation){
return "SET server.port=#port&& SET endpoints.shutdown.enabled=true&& SET management.security.enabled=false #vmArguments&& cd "+pomLocation+" && gradlew.bat bootRun ";
return "SET server.port=#port&& SET endpoints.shutdown.enabled=true&& SET management.security.enabled=false&& SET management.info.git.mode=full #vmArguments&& cd "+pomLocation+" && gradlew.bat bootRun ";
}

public static String getMavenUnix(String pomLocation){
return "export M2_HOME=$1; export PATH=$PATH:$2; cd " + pomLocation + "; mvn spring-boot:run -Dserver.port=$3 -Dendpoints.shutdown.enabled=true -Dmanagement.security.enabled=false $4";
return "export M2_HOME=$1; export PATH=$PATH:$2; cd " + pomLocation + "; mvn spring-boot:run -Dserver.port=$3 -Dendpoints.shutdown.enabled=true -Dmanagement.security.enabled=false -Dmanagement.info.git.mode=full $4";
}

public static String getGradleUnix(String pomLocation){
return "export SERVER_PORT=$1; export ENDPOINTS_SHUTDOWN_ENABLED=true; export MANAGEMENT_SECURITY_ENABLED=false $2; cd " + pomLocation + "; ./gradlew bootRun";
return "export SERVER_PORT=$1; export ENDPOINTS_SHUTDOWN_ENABLED=true; export MANAGEMENT_SECURITY_ENABLED=false; export MANAGEMENT_INFO_GIT_MODE=full $2; cd " + pomLocation + "; ./gradlew bootRun";
}
}
3 changes: 2 additions & 1 deletion trampoline/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
settings.folder.path.linux=/home/#userName/Documents/trampoline
settings.folder.path.mac=/Users/#userName/Documents/trampoline
settings.folder.path.windows=C:/Temp/trampoline
settings.file.name=settings.txt
settings.file.name=settings.txt
trampoline.version=3.5
20 changes: 20 additions & 0 deletions trampoline/src/main/resources/static/v2/js/app/instances.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,26 @@ function showTraces(instanceId, name, port){
});
}

function showInfo(instanceId, name, port){
$('.front-loading').show();
$("#info-title").html(name+" : "+port);
$.ajax({
url : "/instances/info",
type: "POST",
data : {id: instanceId},
success: function(data, textStatus, jqXHR) {
$("#modal-info-pomLocation").text(data.pomLocation);
$("#modal-info-git-branch").text(data.branch);
$("#modal-info-git-commit-message").text(data.commitMessage);
$("#modal-info-git-commit-owner").text(data.commitOwner);
$("#modal-info-git-commit-date").text(data.commitDate);

$('.front-loading').hide();
$("#modal-instance-info").modal("show");
}
});
}

$( document ).ready(function() {
$(".front-loading").hide();
$(".front-loading").height($("body").height());
Expand Down
Loading

0 comments on commit 912be2d

Please sign in to comment.