Skip to content

Commit

Permalink
Improve TestGrid Logging Structure (#299)
Browse files Browse the repository at this point in the history
* Revise log file structure

* Fix persist logs according to the test run number

* Add logging documentation

* Fix issue in generating test run number
  • Loading branch information
vidurananayakkara authored and kasunbg committed Jan 4, 2018
1 parent e0c8e92 commit 34d0a71
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public void setId(String id) {
* @return created timestamp
*/
public Timestamp getCreatedTimestamp() {
if (createdTimestamp == null) {
return null;
}
return new Timestamp(createdTimestamp.getTime());
}

Expand All @@ -103,6 +106,9 @@ public void setCreatedTimestamp(Timestamp createdTimestamp) {
* @return modified test case timestamp
*/
public Timestamp getModifiedTimestamp() {
if (modifiedTimestamp == null) {
return null;
}
return new Timestamp(modifiedTimestamp.getTime());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,26 @@
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
* This represents a model of the DeploymentPattern.
*
* @since 1.0.0
*/
@SqlResultSetMapping(name = "DeploymentPatternTestFailureStatMapping",
classes = {
@ConstructorResult(targetClass = DeploymentPatternTestFailureStat.class,
columns = {@ColumnResult(name = "deploymentPatternId"), @ColumnResult(name = "failureCount")}
)}
classes = {
@ConstructorResult(targetClass = DeploymentPatternTestFailureStat.class,
columns = {@ColumnResult(name = "deploymentPatternId"),
@ColumnResult(name = "failureCount")}
)}
)
@Entity
@Table(name = DeploymentPattern.DEPLOYMENT_PATTERN_TABLE)
@Table(
name = DeploymentPattern.DEPLOYMENT_PATTERN_TABLE,
uniqueConstraints = {
@UniqueConstraint(columnNames = {DeploymentPattern.NAME_COLUMN, DeploymentPattern.PRODUCT_COLUMN})
})
public class DeploymentPattern extends AbstractUUIDEntity implements Serializable {

/**
Expand Down Expand Up @@ -127,13 +133,25 @@ public void setTestPlans(List<TestPlan> testPlans) {
this.testPlans = testPlans;
}

/**
* Adds a test plan to the test plans list.
*
* @param testPlan test plan to be added
*/
public void addTestPlan(TestPlan testPlan) {
testPlans.add(testPlan);
}

@Override
public String toString() {
String id = this.getId() != null ? this.getId() : "";
String createdTimestamp = this.getCreatedTimestamp() != null ? this.getCreatedTimestamp().toString() : "";
String modifiedTimestamp = this.getModifiedTimestamp() != null ? this.getModifiedTimestamp().toString() : "";
return StringUtil.concatStrings("DeploymentPattern{",
"id='", this.getId(), "\'",
"id='", id, "\'",
", name='", name, "\'",
", createdTimestamp='", this.getCreatedTimestamp(), "\'",
", modifiedTimestamp='", this.getModifiedTimestamp(), "\'",
", createdTimestamp='", createdTimestamp, "\'",
", modifiedTimestamp='", modifiedTimestamp, "\'",
", product='", product, "\'",
'}');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Infrastructure implements Serializable {
private ProviderType providerType;
private InstanceType instanceType;
private ClusterType clusterType;
private List<Map<String, Object>> infraParams;
private Map<String, Object> infraParams;
private Map<String, String> securityProperties;
private List<Script> scripts;
private String region;
Expand Down Expand Up @@ -118,7 +118,7 @@ public void setClusterType(ClusterType clusterType) {
*
* @return infrastructure combination
*/
public List<Map<String, Object>> getInfraParams() {
public Map<String, Object> getInfraParams() {
return infraParams;
}

Expand All @@ -127,7 +127,7 @@ public List<Map<String, Object>> getInfraParams() {
*
* @param infraParams infrastructure combination
*/
public void setInfraParams(List<Map<String, Object>> infraParams) {
public void setInfraParams(Map<String, Object> infraParams) {
this.infraParams = infraParams;
}

Expand Down
16 changes: 12 additions & 4 deletions common/src/main/java/org/wso2/testgrid/common/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javax.persistence.OneToMany;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
* This represents a model of the Product which includes the name, version and the channel.
Expand All @@ -52,7 +53,11 @@
@ColumnResult(name = "testExecutionTime")})}
)
@Entity
@Table(name = Product.PRODUCT_TABLE)
@Table(
name = Product.PRODUCT_TABLE,
uniqueConstraints = {
@UniqueConstraint(columnNames = {Product.NAME_COLUMN, Product.VERSION_COLUMN, Product.CHANNEL_COLUMN})
})
public class Product extends AbstractUUIDEntity implements Serializable {

/**
Expand Down Expand Up @@ -156,13 +161,16 @@ public void setDeploymentPatterns(List<DeploymentPattern> deploymentPatterns) {

@Override
public String toString() {
String id = this.getId() != null ? this.getId() : "";
String createdTimestamp = this.getCreatedTimestamp() != null ? this.getCreatedTimestamp().toString() : "";
String modifiedTimestamp = this.getModifiedTimestamp() != null ? this.getModifiedTimestamp().toString() : "";
return StringUtil.concatStrings("Product{",
"id='", this.getId(), "\'",
"id='", id, "\'",
", name='", name, "\'",
", version='", version, "\'",
", channel='", channel, "\'",
", createdTimestamp='", this.getCreatedTimestamp(), "\'",
", modifiedTimestamp='", this.getModifiedTimestamp(), "\'",
", createdTimestamp='", createdTimestamp, "\'",
", modifiedTimestamp='", modifiedTimestamp, "\'",
'}');
}

Expand Down
9 changes: 6 additions & 3 deletions common/src/main/java/org/wso2/testgrid/common/TestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,16 @@ public void setTestScenario(TestScenario testScenario) {

@Override
public String toString() {
String id = this.getId() != null ? this.getId() : "";
String createdTimestamp = this.getCreatedTimestamp() != null ? this.getCreatedTimestamp().toString() : "";
String modifiedTimestamp = this.getModifiedTimestamp() != null ? this.getModifiedTimestamp().toString() : "";
return StringUtil.concatStrings("TestCase{",
"id='", this.getId(),
"id='", id,
", name='", name, "\'",
", isSuccess='", isSuccess, "\'",
", failureMessage='", failureMessage, "\'",
", createdTimestamp='", this.getCreatedTimestamp(), "\'",
", modifiedTimestamp='", this.getModifiedTimestamp(), "\'",
", createdTimestamp='", createdTimestamp, "\'",
", modifiedTimestamp='", modifiedTimestamp, "\'",
", testScenario='", testScenario, "\'",
'}');
}
Expand Down
49 changes: 37 additions & 12 deletions common/src/main/java/org/wso2/testgrid/common/TestPlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public class TestPlan extends AbstractUUIDEntity implements Serializable {
@Column(name = "infra_parameters")
private String infraParameters;

@Column(name = "test_run_number")
private int testRunNumber;

@ManyToOne(optional = false, cascade = CascadeType.ALL, targetEntity = DeploymentPattern.class,
fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn(name = "DEPLOYMENTPATTERN_id", referencedColumnName = ID_COLUMN)
Expand Down Expand Up @@ -165,6 +168,24 @@ public void setDeploymentPattern(DeploymentPattern deploymentPattern) {
this.deploymentPattern = deploymentPattern;
}

/**
* Returns the test run number.
*
* @return test run number
*/
public int getTestRunNumber() {
return testRunNumber;
}

/**
* Sets the test run number.
*
* @param testRunNumber test run number
*/
public void setTestRunNumber(int testRunNumber) {
this.testRunNumber = testRunNumber;
}

/**
* Returns the associated test scenarios.
*
Expand Down Expand Up @@ -293,6 +314,22 @@ public void setDeploymentScript(Script deploymentScript) {
this.deploymentScript = deploymentScript;
}

@Override
public String toString() {
String id = this.getId() != null ? this.getId() : "";
String createdTimestamp = this.getCreatedTimestamp() != null ? this.getCreatedTimestamp().toString() : "";
String modifiedTimestamp = this.getModifiedTimestamp() != null ? this.getModifiedTimestamp().toString() : "";
return StringUtil.concatStrings("TestPlan{",
"id='", id, "\'",
", status='", status, "\'",
", logLocation='", logLocation, "\'",
", testRunNumber='", testRunNumber, "\'",
", createdTimestamp='", createdTimestamp, "\'",
", modifiedTimestamp='", modifiedTimestamp, "\'",
", deploymentPattern='", deploymentPattern, "\'",
'}');
}

/**
* This defines the supported deployment automation tools.
*
Expand Down Expand Up @@ -336,16 +373,4 @@ public String toString() {
return this.deployerType;
}
}

@Override
public String toString() {
return StringUtil.concatStrings("TestPlan{",
"id='", this.getId(), "\'",
", status='", status, "\'",
", logLocation='", logLocation, "\'",
", createdTimestamp='", this.getCreatedTimestamp(), "\'",
", modifiedTimestamp='", this.getModifiedTimestamp(), "\'",
", deploymentPattern='", deploymentPattern, "\'",
'}');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,15 @@ public void addTestCase(TestCase testCase) {

@Override
public String toString() {
String id = this.getId() != null ? this.getId() : "";
String createdTimestamp = this.getCreatedTimestamp() != null ? this.getCreatedTimestamp().toString() : "";
String modifiedTimestamp = this.getModifiedTimestamp() != null ? this.getModifiedTimestamp().toString() : "";
return StringUtil.concatStrings("TestScenario{",
"id='", this.getId(), "\'",
"id='", id, "\'",
", name='", name, "\'",
", status='", status, "\'",
", createdTimestamp='", this.getCreatedTimestamp(), "\'",
", modifiedTimestamp='", this.getModifiedTimestamp(), "\'",
", createdTimestamp='", createdTimestamp, "\'",
", modifiedTimestamp='", modifiedTimestamp, "\'",
", testPlan='", testPlan, "\'",
'}');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import java.util.UUID;

/**
* This Util class holds the common utility methods.
Expand Down Expand Up @@ -149,4 +151,14 @@ public static String getTestGridHomePath() {
Path testGridHomePath = Paths.get(testGridHome);
return testGridHomePath.toAbsolutePath().toString();
}

/**
* Returns a UUID specific to the infra parameters.
*
* @param infraParams infra parameters to get the UUID
* @return UUID specific to the infra parameters
*/
public static String getInfraParamUUID(String infraParams) {
return UUID.nameUUIDFromBytes(infraParams.getBytes(Charset.defaultCharset())).toString();
}
}
12 changes: 0 additions & 12 deletions core/src/main/java/org/wso2/testgrid/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,9 @@ public static void main(String[] args) {
CmdLineParser parser = new CmdLineParser(commandHandler);
parser.parseArgument(args);

// TODO: Remove default arguments
// String repo = "https://github.com/sameerawickramasekara/test-grid-is-resources.git";
String product = "WSO2_Identity_Server";
String productVersion = "5.3.0";
if (args.length == 3) {
// repo = args[0];
product = args[1];
productVersion = args[2];
}

// Validate test grid home
String testGridHome = TestGridUtil.getTestGridHomePath();
if (!StringUtil.isStringNullOrEmpty(testGridHome)) {
logger.info("Initializing TestGrid for product : '"
+ product + ", version '" + productVersion + "'");
commandHandler.execute();
}
} catch (CmdLineException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.wso2.testgrid.core.TestConfig;
import org.wso2.testgrid.dao.TestGridDAOException;
import org.wso2.testgrid.dao.uow.ProductUOW;
import org.wso2.testgrid.logging.plugins.LogFilePathLookup;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

Expand Down Expand Up @@ -84,6 +85,9 @@ public class GenerateTestPlanCommand implements Command {
@Override
public void execute() throws CommandExecutionException {
try {
//Set the log file path
LogFilePathLookup.setLogFilePath(deriveLogFilePath(productName, productVersion, channel));

// Validate test configuration file name
if (StringUtil.isStringNullOrEmpty(testConfigFile) || !testConfigFile.endsWith(YAML_EXTENSION)) {
throw new CommandExecutionException(StringUtil.concatStrings("Invalid test configuration ",
Expand Down Expand Up @@ -326,4 +330,17 @@ private void removeDirectories(Path directory) throws IOException {
FileUtils.forceDelete(new File(directory.toString()));
}
}

/**
* Returns the path of the log file.
*
* @param productName product name
* @param productVersion product version
* @param channel channel
* @return log file path
*/
private String deriveLogFilePath(String productName, String productVersion, String channel) {
String productDir = StringUtil.concatStrings(productName, "_", productVersion, "_", channel);
return Paths.get(productDir, "testgrid").toString();
}
}
Loading

0 comments on commit 34d0a71

Please sign in to comment.