Skip to content

Commit

Permalink
Merge pull request #8 from ErnestOrt/backwards-compatibility
Browse files Browse the repository at this point in the history
Backwards compatibility & minor Safari metrics chart issue
  • Loading branch information
codependent authored Aug 11, 2017
2 parents df4fa37 + 49b7ed5 commit a257ed0
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 36 deletions.
16 changes: 16 additions & 0 deletions microservice-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,20 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.ernest.applications.trampoline.exceptions;

public class CreatingMicroserviceScriptException extends Exception {
public class CreatingMicroserviceScriptException extends RuntimeException {

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package org.ernest.applications.trampoline.exceptions;

public class CreatingSettingsFolderException extends Exception{}
public class CreatingSettingsFolderException extends RuntimeException{}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.ernest.applications.trampoline.exceptions;

public class ReadingEcosystemException extends Exception {
public class ReadingEcosystemException extends RuntimeException {

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.ernest.applications.trampoline.exceptions;

public class RunningMicroserviceScriptException extends Exception {
public class RunningMicroserviceScriptException extends RuntimeException {

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.ernest.applications.trampoline.exceptions;

public class SavingEcosystemException extends Exception {
public class SavingEcosystemException extends RuntimeException {

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.ernest.applications.trampoline.exceptions;

public class ShuttingDownInstanceException extends Exception {
public class ShuttingDownInstanceException extends RuntimeException {

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,25 @@ public Ecosystem getEcosystem() throws CreatingSettingsFolderException, ReadingE
e.printStackTrace();
throw new ReadingEcosystemException();
}

updateMicroservicesInformationStored(ecosystem);

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("");
createScript(m.getId(), m.getPomLocation());
});

saveEcosystem(ecosystem);
}
}

public void saveEcosystem(Ecosystem ecosystem) throws SavingEcosystemException {
try {
FileUtils.writeStringToFile(new File(getSettingsFolder() + "/" + settingsFileName), new Gson().toJson(ecosystem));
Expand All @@ -54,9 +70,8 @@ public void saveEcosystem(Ecosystem ecosystem) throws SavingEcosystemException {
}

public void runScript(String id, String mavenBinaryLocation, String mavenHomeLocation, String port, String vmArguments) throws RunningMicroserviceScriptException {
System.out.println(mavenBinaryLocation + " " + port);
try {
mavenBinaryLocation = (mavenBinaryLocation != null && mavenBinaryLocation.trim().length() > 0) ? mavenBinaryLocation: mavenHomeLocation + "/bin";
mavenBinaryLocation = (mavenBinaryLocation != null && mavenBinaryLocation.trim().length() > 0) ? mavenBinaryLocation : mavenHomeLocation + "/bin";
if(System.getProperties().getProperty("os.name").contains("Windows")){
String commands = FileUtils.readFileToString(new File(getSettingsFolder() +"/"+ id +".txt"));
commands = commands.replace("#mavenBinaryLocation", mavenBinaryLocation);
Expand All @@ -82,7 +97,7 @@ public void createScript(String id, String pomLocation) throws CreatingMicroserv
"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");
}else{
FileUtils.writeStringToFile(new File(getSettingsFolder() +"/"+ id +".sh"),
FileUtils.writeStringToFile(new File(getSettingsFolder() +"/"+ id +".sh"),
"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");
}
Expand Down
69 changes: 44 additions & 25 deletions trampoline/src/main/resources/static/js/backend.requests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var metricsCharts;
function setMavenBinaryLocation(){
if($("#input-mavenbinarylocation").val() == ''){
$("#form-group-mavenbinarylocation").addClass("has-error");
Expand Down Expand Up @@ -114,31 +115,23 @@ function showMetrics(instanceId, name, port){
dataMemoryFree.push(value.freeMemoryKB);
usedHeapKB.push(value.usedHeapKB)
});
var ctx = document.getElementById('myChart').getContext('2d');
new Chart(ctx, {
// The type of chart we want to create
type: 'line',

// The data for our dataset
data: {
labels: dates,
datasets: [{
label: "Memory Free KB",
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
data: dataMemoryFree,
},
{
label: "Heap Used KB",
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
data: usedHeapKB,
}]
},

// Configuration options go here
options: {}
});
metricsCharts.config.data = {
labels: dates,
datasets: [{
label: "Memory Free KB",
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
data: dataMemoryFree,
},
{
label: "Heap Used KB",
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
data: usedHeapKB,
}]
}

metricsCharts.update();
}
});
}
Expand Down Expand Up @@ -199,4 +192,30 @@ setInterval(updateStatusInstances, 15000);

$( document ).ready(function() {
updateStatusInstances();

var ctx = document.getElementById('myChart').getContext('2d');
metricsCharts = new Chart(ctx, {
// The type of chart we want to create
type: 'line',

// The data for our dataset
data: {
labels: [],
datasets: [{
label: "Memory Free KB",
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)',
data: [],
},
{
label: "Heap Used KB",
backgroundColor: 'rgba(54, 162, 235, 0.2)',
borderColor: 'rgba(54, 162, 235, 1)',
data: [],
}]
},

// Configuration options go here
options: {}
});
});
2 changes: 1 addition & 1 deletion trampoline/src/main/resources/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ <h4>
<div class="modal-header">
<h4 class="modal-title"><span id="metrics-title"></span></h4>
</div>
<div class="modal-body">
<div class="modal-body" id="#canvas-wrapper">
<canvas id="myChart" width="400" height="400"></canvas>
</div>
<div class="modal-footer">
Expand Down

0 comments on commit a257ed0

Please sign in to comment.