requests-simulator

Details

diff --git a/src/main/java/br/ufrgs/inf/prosoft/requestssimulator/Main.java b/src/main/java/br/ufrgs/inf/prosoft/requestssimulator/Main.java
index 6decb4c..191f47e 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/requestssimulator/Main.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/requestssimulator/Main.java
@@ -20,8 +20,8 @@ public class Main {
         System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT+%1$tL] [%4$-7s] [RequestsSimulator] %5$s %n");
 
         if (args.length < 2) {
-            System.err.println("--profile=<ProfilePath> --time=<time> [--users=<users>] [--log=<LogPath>] [--throughput=<ThroughputPath>]");
-            System.err.println("--profile=<ProfilePath> --execute=<LogPath> [--throughput=<ThroughputPath>]");
+            System.err.println("--profile=<ProfilePath> --time=<time> [--users=<users>] [--log=<LogPath>] [--throughput=<ThroughputPath>] [--host=<host>]");
+            System.err.println("--profile=<ProfilePath> --execute=<LogPath> [--throughput=<ThroughputPath>] [--host=<host>]");
             System.err.println("--throughput=<ThroughputPath> --reduce=<ReducePath> --prefix=<prefix>");
             System.exit(1);
         }
@@ -30,7 +30,7 @@ public class Main {
             arg = arg.replaceFirst("--", "");
             String[] split = arg.split("=");
             if (split.length < 2) {
-                return new String[]{"", ""};
+                return new String[]{arg, ""};
             }
             return split;
         }).collect(Collectors.toMap(array -> {
@@ -55,12 +55,17 @@ public class Main {
             System.exit(0);
         }
 
+        String host = arguments.get("host");
+        if (host == null) {
+            host = "localhost";
+        }
+
         String profilePath = arguments.get("profile");
         if (profilePath == null) {
             System.err.println("<profile> is required");
             System.exit(1);
         }
-        Profile profile = ProfileReader.parseFile(profilePath);
+        Profile profile = ProfileReader.parseFile(profilePath, host);
 
         Request.REQUESTS_LOG = throughputPath;
         String logPath = arguments.get("execute");
diff --git a/src/main/java/br/ufrgs/inf/prosoft/requestssimulator/ProfileReader.java b/src/main/java/br/ufrgs/inf/prosoft/requestssimulator/ProfileReader.java
index 6d8855f..b435f1a 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/requestssimulator/ProfileReader.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/requestssimulator/ProfileReader.java
@@ -27,6 +27,10 @@ import java.util.logging.Logger;
 public class ProfileReader {
 
     public static Profile parseFile(String profilePath) {
+        return parseFile(profilePath, "localhost");
+    }
+
+    public static Profile parseFile(String profilePath, String host) {
         FileReader fileReader = null;
         try {
             fileReader = new FileReader(profilePath);
@@ -34,17 +38,23 @@ public class ProfileReader {
             Logger.getLogger(ProfileReader.class.getName()).log(Level.SEVERE, "File not found");
             System.exit(1);
         }
-        Map<String, RequestPlan> urlHasRequestPlan = new HashMap<>();
+        Map<String, RequestPlan> referenceHasRequestPlan = new HashMap<>();
         Gson gson = new Gson();
         JsonParser jsonParser = new JsonParser();
         JsonObject jsonObject = jsonParser.parse(fileReader).getAsJsonObject();
         jsonObject.entrySet().forEach(entry -> {
+            JsonElement urlJsonElement = entry.getValue().getAsJsonObject().get("URL");
+            if (urlJsonElement != null) {
+                String URL = urlJsonElement.getAsString().replaceFirst("localhost", host);
+                entry.getValue().getAsJsonObject().remove("URL");
+                entry.getValue().getAsJsonObject().addProperty("URL", URL);
+            }
             RequestPlan requestPlan = gson.fromJson(entry.getValue(), RequestPlan.class);
             requestPlan.setReference(entry.getKey());
-            urlHasRequestPlan.put(requestPlan.getReference(), requestPlan);
+            referenceHasRequestPlan.put(requestPlan.getReference(), requestPlan);
         });
         jsonObject.entrySet().forEach(entry -> {
-            RequestPlan requestPlan = urlHasRequestPlan.get(entry.getKey());
+            RequestPlan requestPlan = referenceHasRequestPlan.get(entry.getKey());
             Collection<String> linksReferences = new ArrayList<>();
             JsonObject jsonRequestPlan = entry.getValue().getAsJsonObject();
             JsonElement linksReferencesElement = jsonRequestPlan.get("linksReferences");
@@ -57,7 +67,7 @@ public class ProfileReader {
                     public void accept(String linkReference) {
                         RequestPlan link;
                         if (linkReference.charAt(0) == '*') {
-                            link = urlHasRequestPlan.get(linkReference.substring(1));
+                            link = referenceHasRequestPlan.get(linkReference.substring(1));
                             if (link == null) {
                                 throw new RuntimeException("link not declared: " + linkReference);
                             }
@@ -65,7 +75,7 @@ public class ProfileReader {
                                 accept(referenceToCopy.getReference());
                             });
                         } else {
-                            link = urlHasRequestPlan.get(linkReference);
+                            link = referenceHasRequestPlan.get(linkReference);
                             if (link == null) {
                                 throw new RuntimeException("link not declared: " + linkReference);
                             }
@@ -77,12 +87,12 @@ public class ProfileReader {
             JsonElement requirementsReferences = jsonRequestPlan.get("requirementsReferences");
             if (requirementsReferences != null) {
                 requirementsReferences.getAsJsonArray().forEach(requirementReference -> {
-                    RequestPlan link = urlHasRequestPlan.get(requirementReference.getAsString());
+                    RequestPlan link = referenceHasRequestPlan.get(requirementReference.getAsString());
                     requestPlan.addRequirement(link);
                 });
             }
         });
-        Profile profile = new Profile(urlHasRequestPlan);
+        Profile profile = new Profile(referenceHasRequestPlan);
         return profile;
     }
 }