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] 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"); }