Repository: wso2/testgrid
Issue: Deployment.json is not parsed properly 

**Description:**
Deployment.json created by deploy.sh should be parsed in the format of tomcat host to be able to pass the correct values to replace in the jmeter scripts.

**Suggested Labels:**
Type/Bug

**Suggested Assignees:**
AsmaJ

Changed files:
deployment/src/main/java/org/wso2/testgrid/deployment/DeploymentUtil.java
deployment/src/main/java/org/wso2/testgrid/deployment/deployers/ShellDeployer.java

diff --git a/deployment/src/main/java/org/wso2/testgrid/deployment/DeploymentUtil.java b/deployment/src/main/java/org/wso2/testgrid/deployment/DeploymentUtil.java
index 168a2537..6b1623f7 100755
--- a/deployment/src/main/java/org/wso2/testgrid/deployment/DeploymentUtil.java
+++ b/deployment/src/main/java/org/wso2/testgrid/deployment/DeploymentUtil.java
@@ -22,11 +22,16 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.wso2.testgrid.common.Deployment;
 import org.wso2.testgrid.common.DeploymentCreationResult;
+import org.wso2.testgrid.common.Host;
+import org.wso2.testgrid.common.Port;
 import org.wso2.testgrid.common.exception.TestGridDeployerException;
+import org.wso2.testgrid.common.util.StringUtil;
 
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * This holds the utility methods used by the deployment component.
@@ -38,21 +43,39 @@ public class DeploymentUtil {
     /**
      * Reads the deployment.json file and constructs the deployment object.
      *
-     * @param testPlanLocation location String of the test plan
+     * @param workspace location String of the test plan
      * @return the deployment information ObjectMapper
      * @throws TestGridDeployerException If reading the deployment.json file fails
      */
-    public static DeploymentCreationResult getDeploymentCreationResult(String testPlanLocation)
+    public static DeploymentCreationResult getDeploymentCreationResult(String workspace)
             throws TestGridDeployerException {
-
+        DeploymentCreationResult deploymentCreationResult = new DeploymentCreationResult();
+        List<Host> hosts = new ArrayList<>();
         ObjectMapper mapper = new ObjectMapper();
-        File file = new File(Paths.get(testPlanLocation, DeployerConstants.DEPLOYMENT_FILE).toString());
+        File file = new File(Paths.get(workspace, DeployerConstants.DEPLOYMENT_FILE).toString());
         try {
-            return mapper.readValue(file, DeploymentCreationResult.class);
+            List<Host> hostList = mapper.readValue(file, DeploymentCreationResult.class).getHosts();
+            /* JMeter test files has the values for the host and ports as two properties. In order to replace
+             * the values, the serverHost and serverPort has to be set as two different hosts.
+             */
+            for (Host host : hostList) {
+                Host serverHost = new Host();
+                serverHost.setIp(host.getIp());
+                serverHost.setLabel("serverHost");
+                for (Port port : host.getPorts()) {
+                    Host serverPort = new Host();
+                    serverPort.setIp(String.valueOf(port.getPortNumber()));
+                    serverPort.setLabel("serverPort");
+                    hosts.add(serverPort);
+                }
+                hosts.add(serverHost);
+            }
+            deploymentCreationResult.setHosts(hosts);
+            return deploymentCreationResult;
         } catch (IOException e) {
             logger.error(e.getMessage());
-            throw new TestGridDeployerException("Error occurred while reading the "
-                    + DeployerConstants.DEPLOYMENT_FILE + " file", e);
+            throw new TestGridDeployerException(StringUtil.concatStrings(
+                    "Error occurred while reading ", file.getAbsolutePath(), e));
         }
     }
 }
diff --git a/deployment/src/main/java/org/wso2/testgrid/deployment/deployers/ShellDeployer.java b/deployment/src/main/java/org/wso2/testgrid/deployment/deployers/ShellDeployer.java
index 9f4e4635..e1e98acf 100644
--- a/deployment/src/main/java/org/wso2/testgrid/deployment/deployers/ShellDeployer.java
+++ b/deployment/src/main/java/org/wso2/testgrid/deployment/deployers/ShellDeployer.java
@@ -66,13 +66,14 @@ public class ShellDeployer implements Deployer {
         DeploymentConfig.DeploymentPattern deploymentPatternConfig = testPlan.getDeploymentConfig()
                 .getDeploymentPatterns().get(0);
         logger.info("Performing the Deployment " + deploymentPatternConfig.getName());
+        final Properties inputParameters;
         try {
             Script deployment = getScriptToExecute(testPlan.getDeploymentConfig(), Script.Phase.CREATE);
             logger.info("Performing the Deployment " + deployment.getName());
             String infraArtifact = StringUtil
                     .concatStrings(infrastructureProvisionResult.getResultLocation(),
                             File.separator, "k8s.properties");
-            final Properties inputParameters = getInputParameters(testPlan, deployment);
+            inputParameters = getInputParameters(testPlan, deployment);
             String parameterString = TestGridUtil.getParameterString(infraArtifact, inputParameters);
             ShellExecutor shellExecutor = new ShellExecutor(Paths.get(TestGridUtil.getTestGridHomePath()));
 
@@ -91,8 +92,8 @@ public class ShellDeployer implements Deployer {
         } catch (CommandExecutionException e) {
             throw new TestGridDeployerException(e);
         }
-        DeploymentCreationResult result = DeploymentUtil.getDeploymentCreationResult(infrastructureProvisionResult
-                .getDeploymentScriptsDir());
+        DeploymentCreationResult result = DeploymentUtil
+                .getDeploymentCreationResult(inputParameters.getProperty(WORKSPACE));
         result.setName(deploymentPatternConfig.getName());
 
         List<Host> hosts = new ArrayList<>();