From cf9e6c70dbf39d52e8f940f8df95baa9529a3870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernest=20Ortun=CC=83o=20Torra?= Date: Thu, 10 Aug 2017 15:12:31 +0200 Subject: [PATCH 1/2] Backward compatibility No need to register previous registered microservices: * Initializing new attributes * Regeneration init scripts * Adding spring-boot-maven-plugin on microservices example --- microservice-example/pom.xml | 16 +++++++++++++ .../CreatingMicroserviceScriptException.java | 2 +- .../CreatingSettingsFolderException.java | 2 +- .../exceptions/ReadingEcosystemException.java | 2 +- .../RunningMicroserviceScriptException.java | 2 +- .../exceptions/SavingEcosystemException.java | 2 +- .../ShuttingDownInstanceException.java | 2 +- .../trampoline/services/FileManager.java | 23 +++++++++++++++---- 8 files changed, 41 insertions(+), 10 deletions(-) diff --git a/microservice-example/pom.xml b/microservice-example/pom.xml index 60e1c2d..2c769cf 100644 --- a/microservice-example/pom.xml +++ b/microservice-example/pom.xml @@ -29,4 +29,20 @@ spring-boot-starter-actuator + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/CreatingMicroserviceScriptException.java b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/CreatingMicroserviceScriptException.java index f788b99..2947b0f 100644 --- a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/CreatingMicroserviceScriptException.java +++ b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/CreatingMicroserviceScriptException.java @@ -1,5 +1,5 @@ package org.ernest.applications.trampoline.exceptions; -public class CreatingMicroserviceScriptException extends Exception { +public class CreatingMicroserviceScriptException extends RuntimeException { } diff --git a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/CreatingSettingsFolderException.java b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/CreatingSettingsFolderException.java index 4398302..6b3141c 100644 --- a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/CreatingSettingsFolderException.java +++ b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/CreatingSettingsFolderException.java @@ -1,3 +1,3 @@ package org.ernest.applications.trampoline.exceptions; -public class CreatingSettingsFolderException extends Exception{} +public class CreatingSettingsFolderException extends RuntimeException{} diff --git a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/ReadingEcosystemException.java b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/ReadingEcosystemException.java index 77d512b..5187da9 100644 --- a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/ReadingEcosystemException.java +++ b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/ReadingEcosystemException.java @@ -1,5 +1,5 @@ package org.ernest.applications.trampoline.exceptions; -public class ReadingEcosystemException extends Exception { +public class ReadingEcosystemException extends RuntimeException { } diff --git a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/RunningMicroserviceScriptException.java b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/RunningMicroserviceScriptException.java index d2aa163..7639dbd 100644 --- a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/RunningMicroserviceScriptException.java +++ b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/RunningMicroserviceScriptException.java @@ -1,5 +1,5 @@ package org.ernest.applications.trampoline.exceptions; -public class RunningMicroserviceScriptException extends Exception { +public class RunningMicroserviceScriptException extends RuntimeException { } diff --git a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/SavingEcosystemException.java b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/SavingEcosystemException.java index edfb2bf..5127c7d 100644 --- a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/SavingEcosystemException.java +++ b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/SavingEcosystemException.java @@ -1,5 +1,5 @@ package org.ernest.applications.trampoline.exceptions; -public class SavingEcosystemException extends Exception { +public class SavingEcosystemException extends RuntimeException { } diff --git a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/ShuttingDownInstanceException.java b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/ShuttingDownInstanceException.java index 244e0e1..c15c94b 100644 --- a/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/ShuttingDownInstanceException.java +++ b/trampoline/src/main/java/org/ernest/applications/trampoline/exceptions/ShuttingDownInstanceException.java @@ -1,5 +1,5 @@ package org.ernest.applications.trampoline.exceptions; -public class ShuttingDownInstanceException extends Exception { +public class ShuttingDownInstanceException extends RuntimeException { } diff --git a/trampoline/src/main/java/org/ernest/applications/trampoline/services/FileManager.java b/trampoline/src/main/java/org/ernest/applications/trampoline/services/FileManager.java index bdb48f8..61592fd 100644 --- a/trampoline/src/main/java/org/ernest/applications/trampoline/services/FileManager.java +++ b/trampoline/src/main/java/org/ernest/applications/trampoline/services/FileManager.java @@ -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)); @@ -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); @@ -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"); } From 49b7ed5c740216f502cfc2d673510f188e6e7dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernest=20Ortun=CC=83o=20Torra?= Date: Thu, 10 Aug 2017 15:12:52 +0200 Subject: [PATCH 2/2] Minor error on Metrics Graphs on Safari --- .../resources/static/js/backend.requests.js | 69 ++++++++++++------- .../src/main/resources/templates/home.html | 2 +- 2 files changed, 45 insertions(+), 26 deletions(-) diff --git a/trampoline/src/main/resources/static/js/backend.requests.js b/trampoline/src/main/resources/static/js/backend.requests.js index 9692653..e65b95d 100644 --- a/trampoline/src/main/resources/static/js/backend.requests.js +++ b/trampoline/src/main/resources/static/js/backend.requests.js @@ -1,3 +1,4 @@ +var metricsCharts; function setMavenBinaryLocation(){ if($("#input-mavenbinarylocation").val() == ''){ $("#form-group-mavenbinarylocation").addClass("has-error"); @@ -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(); } }); } @@ -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: {} + }); }); \ No newline at end of file diff --git a/trampoline/src/main/resources/templates/home.html b/trampoline/src/main/resources/templates/home.html index 4e60c13..e067f2a 100644 --- a/trampoline/src/main/resources/templates/home.html +++ b/trampoline/src/main/resources/templates/home.html @@ -196,7 +196,7 @@

-