-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enriching export #16
base: master
Are you sure you want to change the base?
Enriching export #16
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module external.linked.project.id="gradle-test-export-plugin" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.ullink.gradle" external.system.module.version="0.2" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<excludeFolder url="file://$MODULE_DIR$/.gradle" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build" /> | ||
<excludeFolder url="file://$MODULE_DIR$/out" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package com.ullink.testtools.elastic | |
import com.ullink.testtools.elastic.models.Result | ||
import groovy.io.FileType | ||
import groovy.json.JsonOutput | ||
import groovy.json.JsonSlurper | ||
import groovy.util.logging.Slf4j | ||
import org.elasticsearch.action.bulk.BulkProcessor | ||
import org.elasticsearch.action.index.IndexRequest | ||
|
@@ -44,6 +45,14 @@ class TestExportTask extends Exec { | |
@Optional | ||
def targetDirectory | ||
|
||
@Input | ||
@Optional | ||
def enrichment | ||
|
||
@Input | ||
@Optional | ||
def featureExport | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can add another task instead of export using a closure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in a new FeatureExportTask class inside the project that just prompts the ullink plugin to export the feature? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a new task depends on this task, exporting the feature is ok |
||
|
||
@Input | ||
@Optional | ||
def type = "testcase" | ||
|
@@ -54,31 +63,36 @@ class TestExportTask extends Exec { | |
|
||
@Input | ||
@Optional | ||
String indexTimestampPattern = "yyyy-MM-dd" | ||
String indexTimestampPattern = "yyyy-MM" | ||
|
||
@Input | ||
@Optional | ||
String buildTime = LocalDateTime.now().toString() | ||
|
||
@Internal | ||
BulkProcessor processor | ||
@Internal | ||
TransportClient client | ||
|
||
def overrideDefaultProperties(Properties properties) { | ||
if (getHost() != null) { | ||
log.error "setting host " + getHost() | ||
properties.setProperty('host', getHost()) | ||
static def overrideDefaultProperties(TestExportTask task, Properties properties) { | ||
if (task.host != null) { | ||
log.info "setting host ${task.host}" + | ||
properties.setProperty('host', task.host) | ||
} | ||
if (getClusterName() != null) { | ||
properties.setProperty('clusterName', getClusterName()) | ||
if (task.clusterName != null) { | ||
properties.setProperty('clusterName', task.clusterName) | ||
} | ||
if (getPort() != null) { | ||
properties.setProperty('port', getPort()) | ||
if (task.port != null) { | ||
properties.setProperty('port', task.port) | ||
} | ||
|
||
return properties | ||
} | ||
|
||
@Override | ||
void exec() { | ||
ElasticSearchProcessor elasticSearchProcessor = new ElasticSearchProcessor() | ||
Properties parameters = overrideDefaultProperties(elasticSearchProcessor.getParameters()) | ||
Properties parameters = overrideDefaultProperties(this, elasticSearchProcessor.getParameters()) | ||
|
||
def bulkProcessorListener = elasticSearchProcessor.buildBulkProcessorListener() | ||
client = elasticSearchProcessor.buildTransportClient(parameters) | ||
|
@@ -106,9 +120,14 @@ class TestExportTask extends Exec { | |
def list = parseTestFiles(files) | ||
list.each { | ||
def output = JsonOutput.toJson(it) | ||
def timetamp = LocalDateTime.parse(it.timestamp) | ||
String index = indexPrefix + timetamp.format(DateTimeFormatter.ofPattern(indexTimestampPattern)) | ||
output = new JsonSlurper().parseText(output) | ||
assert output instanceof Map | ||
output.remove("timestamp") | ||
|
||
def timestamp = LocalDateTime.parse(it.timestamp) | ||
String index = indexPrefix + timestamp.format(DateTimeFormatter.ofPattern(indexTimestampPattern)) | ||
index = index.replace('.', '-') | ||
|
||
String typeFinal | ||
switch (type) { | ||
case GString: | ||
|
@@ -123,42 +142,52 @@ class TestExportTask extends Exec { | |
default: | ||
throw new IllegalArgumentException("'type' attribute of type ${type.getClass()} is not supported") | ||
} | ||
|
||
String id = sha1Hashed(it.getClassname() + it.getName() + it.timestamp) | ||
IndexRequest indexObj = new IndexRequest(index, typeFinal, id) | ||
processor.add(indexObj.source(output, XContentType.JSON)) | ||
} | ||
} | ||
|
||
|
||
if (featureExport) { | ||
featureExport.exportFeature(this) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this part should not be done in here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but the internal one |
||
|
||
processor.close() | ||
} | ||
|
||
static def sha1Hashed(String value) { | ||
def messageDigest = MessageDigest.getInstance("SHA-1") | ||
String hexString = messageDigest.digest(value.getBytes()).collect { String.format('%02x', it)}.join() | ||
String hexString = messageDigest.digest(value.getBytes()).collect { String.format('%02x', it) }.join() | ||
return hexString | ||
} | ||
|
||
List<Result> parseTestFiles(List<File> files) { | ||
def list = [] | ||
files.each { | ||
def xmlDoc = new XmlSlurper().parse(it) | ||
String timestamp = xmlDoc.@timestamp | ||
def fileName = (xmlDoc.@name) | ||
|
||
xmlDoc.children().each { | ||
if (it.name() == "testcase") { | ||
Result result = parseTestCase(it) | ||
result.timestamp = timestamp | ||
|
||
if (enrichment) { | ||
result = enrichment.enrichJson(result, it, fileName) | ||
} | ||
|
||
list << result | ||
} | ||
} | ||
} | ||
|
||
list | ||
} | ||
|
||
def parseTestCase(def p) { | ||
String testname = p.@name | ||
Result result = new Result(name: testname) | ||
String testName = p.@name | ||
Result result = new Result(name: testName) | ||
result.timestamp = buildTime | ||
def time = Float.parseFloat([email protected]()) * 1000 | ||
result.with { | ||
classname = p.@classname | ||
|
@@ -171,7 +200,6 @@ class TestExportTask extends Exec { | |
result.with { | ||
failureMessage = node.@message | ||
failureType = node.@type | ||
failureText = node.text() | ||
resultType = TestResult.ResultType.FAILURE | ||
} | ||
} | ||
|
@@ -180,6 +208,8 @@ class TestExportTask extends Exec { | |
} | ||
} | ||
result.properties = resolveProperties(p) | ||
result.projectName = project.getName() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, it should be done in enrichment |
||
result | ||
} | ||
|
||
|
@@ -192,4 +222,5 @@ class TestExportTask extends Exec { | |
} | ||
return null | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't have to commit this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noted