Skip to content

Commit

Permalink
Merge pull request #620 from azinneera/persistence-error
Browse files Browse the repository at this point in the history
Set host details from deployment.json in the proper format
  • Loading branch information
harshanL authored Mar 29, 2018
2 parents b5cfc1e + a0f5e7e commit 80d3041
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@
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.
Expand All @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ public DeploymentCreationResult deploy(TestPlan testPlan,
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()));

Expand All @@ -91,8 +92,8 @@ public DeploymentCreationResult deploy(TestPlan testPlan,
} 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<>();
Expand Down

0 comments on commit 80d3041

Please sign in to comment.