Skip to content

Commit

Permalink
Use field initialization for default values
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Hervieux authored and laurent-barbisan-ullink committed Nov 29, 2018
1 parent 51f11f6 commit 0c3ed6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ import org.elasticsearch.transport.client.PreBuiltTransportClient

class ElasticSearchProcessor {

InputStream DEFAULT_PROPERTIES_FILE
Properties parameters

ElasticSearchProcessor() {
DEFAULT_PROPERTIES_FILE = ElasticSearchProcessor.class.getResourceAsStream("/elastic-search.properties")
this.parameters = new PropertiesLoader(DEFAULT_PROPERTIES_FILE).getParameters()
}

def buildTransportClient(Properties parameters) {
String clusterName = parameters.getProperty("clusterName", "elasticsearch")
Settings settings = new Settings.Builder()
Expand Down
26 changes: 7 additions & 19 deletions src/main/groovy/com/ullink/testtools/elastic/TestExportTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class TestExportTask extends Exec {

@Input
@Optional
String port
String port = "9300"

@Input
@Optional
String clusterName
String clusterName = "elasticsearch"

@Input
@Optional
String host
String host = "127.0.0.1"

@Input
@Optional
Expand Down Expand Up @@ -68,25 +68,13 @@ class TestExportTask extends Exec {
@Internal
TransportClient client

static def overrideDefaultProperties(TestExportTask task, Properties properties) {
if (task.host != null) {
log.info "setting host ${task.host}" +
properties.setProperty('host', task.host)
}
if (task.clusterName != null) {
properties.setProperty('clusterName', task.clusterName)
}
if (task.port != null) {
properties.setProperty('port', task.port)
}

return properties
}

@Override
void exec() {
ElasticSearchProcessor elasticSearchProcessor = new ElasticSearchProcessor()
Properties parameters = overrideDefaultProperties(this, elasticSearchProcessor.getParameters())
Properties parameters = new Properties()
parameters.setProperty('host', host)
parameters.setProperty('port', port)
parameters.setProperty('clusterName', clusterName)

def bulkProcessorListener = elasticSearchProcessor.buildBulkProcessorListener()
client = elasticSearchProcessor.buildTransportClient(parameters)
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/elastic-search.properties

This file was deleted.

0 comments on commit 0c3ed6a

Please sign in to comment.