embulk-input-marketo 0.6.9 → 0.6.10.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/build.gradle +1 -1
- data/src/main/java/org/embulk/input/marketo/MarketoService.java +0 -4
- data/src/main/java/org/embulk/input/marketo/MarketoServiceImpl.java +0 -16
- data/src/main/java/org/embulk/input/marketo/delegate/LeadBulkExtractInputPlugin.java +3 -6
- data/src/main/java/org/embulk/input/marketo/delegate/LeadServiceResponseMapperBuilder.java +85 -0
- data/src/main/java/org/embulk/input/marketo/delegate/LeadWithListInputPlugin.java +25 -5
- data/src/main/java/org/embulk/input/marketo/delegate/LeadWithProgramInputPlugin.java +21 -4
- data/src/main/java/org/embulk/input/marketo/delegate/MarketoBaseBulkExtractInputPlugin.java +0 -1
- data/src/main/java/org/embulk/input/marketo/delegate/MarketoBaseInputPluginDelegate.java +6 -28
- data/src/main/java/org/embulk/input/marketo/model/MarketoField.java +9 -0
- data/src/main/java/org/embulk/input/marketo/rest/MarketoRestClient.java +18 -2
- data/src/test/java/org/embulk/input/marketo/MarketoServiceImplTest.java +0 -25
- data/src/test/java/org/embulk/input/marketo/delegate/LeadServiceResponseMapperBuilderTest.java +119 -0
- data/src/test/java/org/embulk/input/marketo/rest/MarketoRestClientTest.java +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22645790a18bbe5578b7146e488167fe0139a1a1
|
4
|
+
data.tar.gz: b26ea8361cbe4f5d32796eb7295250becc11497d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c64fa145b1717cbf966b1e92052372fec3cd7848e97c128b769aba1721c4d5a852f1a1c7d656017c529009492a3f530c863e328275aab57e2c81f6942f3bd31
|
7
|
+
data.tar.gz: d0f35afc155263d59d5c491784481f189d491b5c5866fc7a983dc3621dc7b7efbf1173524ac9490310c725a926fc44cff89c4299aac8a02be1947bfe156feeb1
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
## 0.6.
|
1
|
+
## 0.6.9 - 2018-04-16
|
2
2
|
* [fixed] Fix wrapped TimeoutException not retry [#85](https://github.com/treasure-data/embulk-input-marketo/pull/85)
|
3
3
|
* [enhance] Make read_timeout configurable [#85](https://github.com/treasure-data/embulk-input-marketo/pull/85)
|
4
4
|
|
data/build.gradle
CHANGED
@@ -14,10 +14,6 @@ public interface MarketoService
|
|
14
14
|
{
|
15
15
|
List<MarketoField> describeLead();
|
16
16
|
|
17
|
-
List<MarketoField> describeLeadByProgram();
|
18
|
-
|
19
|
-
List<MarketoField> describeLeadByLists();
|
20
|
-
|
21
17
|
File extractLead(Date startTime, Date endTime, List<String> extractedFields, String filterField, int pollingTimeIntervalSecond, int bulkJobTimeoutSecond);
|
22
18
|
|
23
19
|
File extractAllActivity(Date startTime, Date endTime, int pollingTimeIntervalSecond, int bulkJobTimeoutSecond);
|
@@ -185,22 +185,6 @@ public class MarketoServiceImpl implements MarketoService
|
|
185
185
|
return marketoRestClient.describeLead();
|
186
186
|
}
|
187
187
|
|
188
|
-
@Override
|
189
|
-
public List<MarketoField> describeLeadByProgram()
|
190
|
-
{
|
191
|
-
List<MarketoField> columns = marketoRestClient.describeLead();
|
192
|
-
columns.add(new MarketoField(MarketoUtils.PROGRAM_ID_COLUMN_NAME, MarketoField.MarketoDataType.STRING));
|
193
|
-
return columns;
|
194
|
-
}
|
195
|
-
|
196
|
-
@Override
|
197
|
-
public List<MarketoField> describeLeadByLists()
|
198
|
-
{
|
199
|
-
List<MarketoField> columns = marketoRestClient.describeLead();
|
200
|
-
columns.add(new MarketoField(MarketoUtils.LIST_ID_COLUMN_NAME, MarketoField.MarketoDataType.STRING));
|
201
|
-
return columns;
|
202
|
-
}
|
203
|
-
|
204
188
|
private static class DownloadBulkExtractException extends Exception
|
205
189
|
{
|
206
190
|
private final long byteWritten;
|
@@ -7,8 +7,6 @@ import org.embulk.config.Config;
|
|
7
7
|
import org.embulk.config.ConfigDefault;
|
8
8
|
import org.embulk.input.marketo.MarketoService;
|
9
9
|
import org.embulk.input.marketo.MarketoServiceImpl;
|
10
|
-
import org.embulk.input.marketo.MarketoUtils;
|
11
|
-
import org.embulk.input.marketo.model.MarketoField;
|
12
10
|
import org.embulk.input.marketo.rest.MarketoRestClient;
|
13
11
|
import org.embulk.spi.DataException;
|
14
12
|
import org.embulk.spi.Exec;
|
@@ -29,7 +27,7 @@ public class LeadBulkExtractInputPlugin extends MarketoBaseBulkExtractInputPlugi
|
|
29
27
|
|
30
28
|
private static final String UPDATED_AT = "updatedAt";
|
31
29
|
|
32
|
-
public interface PluginTask extends MarketoBaseBulkExtractInputPlugin.PluginTask
|
30
|
+
public interface PluginTask extends MarketoBaseBulkExtractInputPlugin.PluginTask, LeadServiceResponseMapperBuilder.PluginTask
|
33
31
|
{
|
34
32
|
@Config("use_updated_at")
|
35
33
|
@ConfigDefault("false")
|
@@ -63,9 +61,8 @@ public class LeadBulkExtractInputPlugin extends MarketoBaseBulkExtractInputPlugi
|
|
63
61
|
{
|
64
62
|
try (MarketoRestClient marketoRestClient = createMarketoRestClient(task)) {
|
65
63
|
MarketoService marketoService = new MarketoServiceImpl(marketoRestClient);
|
66
|
-
|
67
|
-
|
68
|
-
return MarketoUtils.buildDynamicResponseMapper(task.getSchemaColumnPrefix(), columns);
|
64
|
+
LeadServiceResponseMapperBuilder<PluginTask> leadServiceResponseMapperBuilder = new LeadServiceResponseMapperBuilder<>(task, marketoService);
|
65
|
+
return leadServiceResponseMapperBuilder.buildServiceResponseMapper(task);
|
69
66
|
}
|
70
67
|
}
|
71
68
|
}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
package org.embulk.input.marketo.delegate;
|
2
|
+
|
3
|
+
import com.google.common.base.Optional;
|
4
|
+
import org.embulk.base.restclient.ServiceResponseMapper;
|
5
|
+
import org.embulk.base.restclient.ServiceResponseMapperBuildable;
|
6
|
+
import org.embulk.base.restclient.record.ValueLocator;
|
7
|
+
import org.embulk.config.Config;
|
8
|
+
import org.embulk.config.ConfigDefault;
|
9
|
+
import org.embulk.input.marketo.MarketoService;
|
10
|
+
import org.embulk.input.marketo.MarketoUtils;
|
11
|
+
import org.embulk.input.marketo.model.MarketoField;
|
12
|
+
import org.embulk.spi.Exec;
|
13
|
+
import org.slf4j.Logger;
|
14
|
+
|
15
|
+
import java.util.ArrayList;
|
16
|
+
import java.util.List;
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Created by tai.khuu on 5/21/18.
|
20
|
+
*/
|
21
|
+
public class LeadServiceResponseMapperBuilder<T extends LeadServiceResponseMapperBuilder.PluginTask> implements ServiceResponseMapperBuildable<T>
|
22
|
+
{
|
23
|
+
private static final Logger LOGGER = Exec.getLogger(LeadServiceResponseMapperBuilder.class);
|
24
|
+
private MarketoService marketoService;
|
25
|
+
|
26
|
+
private T pluginTask;
|
27
|
+
|
28
|
+
public interface PluginTask extends MarketoBaseInputPluginDelegate.PluginTask
|
29
|
+
{
|
30
|
+
@Config("included_fields")
|
31
|
+
@ConfigDefault("null")
|
32
|
+
Optional<List<String>> getIncludedLeadFields();
|
33
|
+
|
34
|
+
@Config("extracted_fields")
|
35
|
+
@ConfigDefault("[]")
|
36
|
+
List<String> getExtractedFields();
|
37
|
+
|
38
|
+
void setExtractedFields(List<String> extractedFields);
|
39
|
+
}
|
40
|
+
|
41
|
+
public LeadServiceResponseMapperBuilder(T task, MarketoService marketoService)
|
42
|
+
{
|
43
|
+
this.pluginTask = task;
|
44
|
+
this.marketoService = marketoService;
|
45
|
+
}
|
46
|
+
|
47
|
+
protected List<MarketoField> getLeadColumns()
|
48
|
+
{
|
49
|
+
List<MarketoField> columns = marketoService.describeLead();
|
50
|
+
if (pluginTask.getIncludedLeadFields().isPresent() && !pluginTask.getIncludedLeadFields().get().isEmpty()) {
|
51
|
+
List<MarketoField> filteredColumns = new ArrayList<>();
|
52
|
+
List<String> includedFields = pluginTask.getIncludedLeadFields().get();
|
53
|
+
for (String fieldName : includedFields) {
|
54
|
+
Optional<MarketoField> includedField = lookupFieldIgnoreCase(columns, fieldName);
|
55
|
+
if (includedField.isPresent()) {
|
56
|
+
filteredColumns.add(includedField.get());
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
LOGGER.warn("Included field [{}] not found in Marketo lead field", fieldName);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
columns = filteredColumns;
|
63
|
+
LOGGER.info("Included Fields option is set, included columns: [{}]", columns);
|
64
|
+
}
|
65
|
+
return columns;
|
66
|
+
}
|
67
|
+
|
68
|
+
private static Optional<MarketoField> lookupFieldIgnoreCase(List<MarketoField> inputList, String lookupFieldName)
|
69
|
+
{
|
70
|
+
for (MarketoField marketoField : inputList) {
|
71
|
+
if (marketoField.getName().equalsIgnoreCase(lookupFieldName)) {
|
72
|
+
return Optional.of(marketoField);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
return Optional.absent();
|
76
|
+
}
|
77
|
+
|
78
|
+
@Override
|
79
|
+
public ServiceResponseMapper<? extends ValueLocator> buildServiceResponseMapper(T task)
|
80
|
+
{
|
81
|
+
List<MarketoField> leadColumns = getLeadColumns();
|
82
|
+
pluginTask.setExtractedFields(MarketoUtils.getFieldNameFromMarketoFields(leadColumns));
|
83
|
+
return MarketoUtils.buildDynamicResponseMapper(pluginTask.getSchemaColumnPrefix(), leadColumns);
|
84
|
+
}
|
85
|
+
}
|
@@ -10,6 +10,7 @@ import org.embulk.input.marketo.MarketoUtils;
|
|
10
10
|
import org.embulk.input.marketo.model.MarketoField;
|
11
11
|
import org.embulk.input.marketo.rest.MarketoRestClient;
|
12
12
|
|
13
|
+
import java.util.ArrayList;
|
13
14
|
import java.util.Iterator;
|
14
15
|
import java.util.List;
|
15
16
|
|
@@ -18,7 +19,7 @@ import java.util.List;
|
|
18
19
|
*/
|
19
20
|
public class LeadWithListInputPlugin extends MarketoBaseInputPluginDelegate<LeadWithListInputPlugin.PluginTask>
|
20
21
|
{
|
21
|
-
public interface PluginTask extends MarketoBaseInputPluginDelegate.PluginTask
|
22
|
+
public interface PluginTask extends MarketoBaseInputPluginDelegate.PluginTask, LeadServiceResponseMapperBuilder.PluginTask
|
22
23
|
{
|
23
24
|
}
|
24
25
|
|
@@ -29,7 +30,10 @@ public class LeadWithListInputPlugin extends MarketoBaseInputPluginDelegate<Lead
|
|
29
30
|
@Override
|
30
31
|
protected Iterator<ServiceRecord> getServiceRecords(MarketoService marketoService, PluginTask task)
|
31
32
|
{
|
32
|
-
|
33
|
+
List<String> extractedFields = task.getExtractedFields();
|
34
|
+
// Remove LIST_ID_COLUMN_NAME when sent fields to Marketo since LIST_ID_COLUMN_NAME are added by plugin code
|
35
|
+
extractedFields.remove(MarketoUtils.LIST_ID_COLUMN_NAME);
|
36
|
+
return FluentIterable.from(marketoService.getAllListLead(extractedFields)).transform(MarketoUtils.TRANSFORM_OBJECT_TO_JACKSON_SERVICE_RECORD_FUNCTION).iterator();
|
33
37
|
}
|
34
38
|
|
35
39
|
@Override
|
@@ -37,9 +41,25 @@ public class LeadWithListInputPlugin extends MarketoBaseInputPluginDelegate<Lead
|
|
37
41
|
{
|
38
42
|
try (MarketoRestClient marketoRestClient = createMarketoRestClient(task)) {
|
39
43
|
MarketoService marketoService = new MarketoServiceImpl(marketoRestClient);
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
LeadWithListServiceResponseMapper serviceResponseMapper = new LeadWithListServiceResponseMapper(task, marketoService);
|
45
|
+
return serviceResponseMapper.buildServiceResponseMapper(task);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
private static class LeadWithListServiceResponseMapper extends LeadServiceResponseMapperBuilder<PluginTask>
|
50
|
+
{
|
51
|
+
|
52
|
+
public LeadWithListServiceResponseMapper(LeadWithListInputPlugin.PluginTask task, MarketoService marketoService)
|
53
|
+
{
|
54
|
+
super(task, marketoService);
|
55
|
+
}
|
56
|
+
|
57
|
+
@Override
|
58
|
+
protected List<MarketoField> getLeadColumns()
|
59
|
+
{
|
60
|
+
List<MarketoField> leadColumns = super.getLeadColumns();
|
61
|
+
leadColumns.add(new MarketoField(MarketoUtils.LIST_ID_COLUMN_NAME, MarketoField.MarketoDataType.STRING));
|
62
|
+
return leadColumns;
|
43
63
|
}
|
44
64
|
}
|
45
65
|
}
|
@@ -18,7 +18,7 @@ import java.util.List;
|
|
18
18
|
*/
|
19
19
|
public class LeadWithProgramInputPlugin extends MarketoBaseInputPluginDelegate<LeadWithProgramInputPlugin.PluginTask>
|
20
20
|
{
|
21
|
-
public interface PluginTask extends MarketoBaseInputPluginDelegate.PluginTask
|
21
|
+
public interface PluginTask extends MarketoBaseInputPluginDelegate.PluginTask, LeadServiceResponseMapperBuilder.PluginTask
|
22
22
|
{
|
23
23
|
}
|
24
24
|
|
@@ -26,6 +26,8 @@ public class LeadWithProgramInputPlugin extends MarketoBaseInputPluginDelegate<L
|
|
26
26
|
protected Iterator<ServiceRecord> getServiceRecords(MarketoService marketoService, PluginTask task)
|
27
27
|
{
|
28
28
|
List<String> fieldNames = task.getExtractedFields();
|
29
|
+
// Remove PROGRAM_ID_COLUMN_NAME when sent fields to Marketo since PROGRAM_ID_COLUMN_NAME are added by plugin code
|
30
|
+
fieldNames.remove(MarketoUtils.PROGRAM_ID_COLUMN_NAME);
|
29
31
|
return FluentIterable.from(marketoService.getAllProgramLead(fieldNames)).
|
30
32
|
transform(MarketoUtils.TRANSFORM_OBJECT_TO_JACKSON_SERVICE_RECORD_FUNCTION).iterator();
|
31
33
|
}
|
@@ -35,9 +37,24 @@ public class LeadWithProgramInputPlugin extends MarketoBaseInputPluginDelegate<L
|
|
35
37
|
{
|
36
38
|
try (MarketoRestClient marketoRestClient = createMarketoRestClient(task)) {
|
37
39
|
MarketoService marketoService = new MarketoServiceImpl(marketoRestClient);
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
LeadWithProgramServiceResponseMapper serviceResponseMapper = new LeadWithProgramServiceResponseMapper(task, marketoService);
|
41
|
+
return serviceResponseMapper.buildServiceResponseMapper(task);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
private static class LeadWithProgramServiceResponseMapper extends LeadServiceResponseMapperBuilder<PluginTask>
|
46
|
+
{
|
47
|
+
public LeadWithProgramServiceResponseMapper(LeadWithProgramInputPlugin.PluginTask task, MarketoService marketoService)
|
48
|
+
{
|
49
|
+
super(task, marketoService);
|
50
|
+
}
|
51
|
+
|
52
|
+
@Override
|
53
|
+
protected List<MarketoField> getLeadColumns()
|
54
|
+
{
|
55
|
+
List<MarketoField> leadColumns = super.getLeadColumns();
|
56
|
+
leadColumns.add(new MarketoField(MarketoUtils.PROGRAM_ID_COLUMN_NAME, MarketoField.MarketoDataType.STRING));
|
57
|
+
return leadColumns;
|
41
58
|
}
|
42
59
|
}
|
43
60
|
}
|
@@ -1,16 +1,14 @@
|
|
1
1
|
package org.embulk.input.marketo.delegate;
|
2
2
|
|
3
3
|
import com.google.common.annotations.VisibleForTesting;
|
4
|
+
import com.google.common.base.Optional;
|
4
5
|
import org.embulk.base.restclient.DefaultServiceDataSplitter;
|
5
6
|
import org.embulk.base.restclient.RestClientInputPluginDelegate;
|
6
7
|
import org.embulk.base.restclient.RestClientInputTaskBase;
|
7
8
|
import org.embulk.base.restclient.ServiceDataSplitter;
|
8
9
|
import org.embulk.base.restclient.record.RecordImporter;
|
9
10
|
import org.embulk.base.restclient.record.ServiceRecord;
|
10
|
-
import org.embulk.config
|
11
|
-
import org.embulk.config.ConfigDefault;
|
12
|
-
import org.embulk.config.ConfigDiff;
|
13
|
-
import org.embulk.config.TaskReport;
|
11
|
+
import org.embulk.config.*;
|
14
12
|
import org.embulk.input.marketo.MarketoService;
|
15
13
|
import org.embulk.input.marketo.MarketoServiceImpl;
|
16
14
|
import org.embulk.input.marketo.rest.MarketoRestClient;
|
@@ -30,33 +28,13 @@ import java.util.List;
|
|
30
28
|
public abstract class MarketoBaseInputPluginDelegate<T extends MarketoBaseInputPluginDelegate.PluginTask> implements RestClientInputPluginDelegate<T>
|
31
29
|
{
|
32
30
|
public static final int PREVIEW_RECORD_LIMIT = 15;
|
33
|
-
private static final int CONNECT_TIMEOUT_IN_MILLIS = 30000;
|
34
|
-
private static final int IDLE_TIMEOUT_IN_MILLIS = 60000;
|
35
31
|
public interface PluginTask
|
36
32
|
extends RestClientInputTaskBase, MarketoRestClient.PluginTask
|
37
33
|
{
|
38
|
-
@Config("maximum_retries")
|
39
|
-
@ConfigDefault("7")
|
40
|
-
Integer getMaximumRetries();
|
41
|
-
|
42
|
-
@Config("initial_retry_interval_milis")
|
43
|
-
@ConfigDefault("20000")
|
44
|
-
Integer getInitialRetryIntervalMilis();
|
45
|
-
|
46
|
-
@Config("maximum_retries_interval_milis")
|
47
|
-
@ConfigDefault("120000")
|
48
|
-
Integer getMaximumRetriesIntervalMilis();
|
49
|
-
|
50
34
|
@Config("schema_column_prefix")
|
51
35
|
@ConfigDefault("\"mk\"")
|
52
36
|
String getSchemaColumnPrefix();
|
53
37
|
|
54
|
-
@Config("extracted_fields")
|
55
|
-
@ConfigDefault("[]")
|
56
|
-
List<String> getExtractedFields();
|
57
|
-
|
58
|
-
void setExtractedFields(List<String> extractedFields);
|
59
|
-
|
60
38
|
DateTime getJobStartTime();
|
61
39
|
|
62
40
|
void setJobStartTime(DateTime dateTime);
|
@@ -77,6 +55,9 @@ public abstract class MarketoBaseInputPluginDelegate<T extends MarketoBaseInputP
|
|
77
55
|
@Override
|
78
56
|
public TaskReport ingestServiceData(T task, RecordImporter recordImporter, int taskIndex, PageBuilder pageBuilder)
|
79
57
|
{
|
58
|
+
if (Exec.isPreview()) {
|
59
|
+
task.setBatchSize(PREVIEW_RECORD_LIMIT);
|
60
|
+
}
|
80
61
|
try (MarketoRestClient restClient = createMarketoRestClient(task)) {
|
81
62
|
MarketoService marketoService = new MarketoServiceImpl(restClient);
|
82
63
|
Iterator<ServiceRecord> serviceRecords = getServiceRecords(marketoService, task);
|
@@ -95,10 +76,7 @@ public abstract class MarketoBaseInputPluginDelegate<T extends MarketoBaseInputP
|
|
95
76
|
@VisibleForTesting
|
96
77
|
public MarketoRestClient createMarketoRestClient(PluginTask task)
|
97
78
|
{
|
98
|
-
|
99
|
-
task.setBatchSize(PREVIEW_RECORD_LIMIT);
|
100
|
-
}
|
101
|
-
return new MarketoRestClient(task, new Jetty92RetryHelper(task.getMaximumRetries(), task.getInitialRetryIntervalMilis(), task.getMaximumRetriesIntervalMilis(), new DefaultJetty92ClientCreator(CONNECT_TIMEOUT_IN_MILLIS, IDLE_TIMEOUT_IN_MILLIS)));
|
79
|
+
return new MarketoRestClient(task);
|
102
80
|
}
|
103
81
|
|
104
82
|
@Override
|
@@ -114,4 +114,13 @@ public class MarketoField
|
|
114
114
|
return Optional.fromNullable(format);
|
115
115
|
}
|
116
116
|
}
|
117
|
+
|
118
|
+
@Override
|
119
|
+
public String toString()
|
120
|
+
{
|
121
|
+
return "MarketoField{" +
|
122
|
+
"name='" + name + '\'' +
|
123
|
+
", marketoDataType=" + marketoDataType +
|
124
|
+
'}';
|
125
|
+
}
|
117
126
|
}
|
@@ -23,6 +23,7 @@ import org.embulk.spi.DataException;
|
|
23
23
|
import org.embulk.spi.Exec;
|
24
24
|
import org.embulk.spi.type.Type;
|
25
25
|
import org.embulk.spi.type.Types;
|
26
|
+
import org.embulk.util.retryhelper.jetty92.DefaultJetty92ClientCreator;
|
26
27
|
import org.embulk.util.retryhelper.jetty92.Jetty92RetryHelper;
|
27
28
|
import org.slf4j.Logger;
|
28
29
|
|
@@ -53,6 +54,9 @@ public class MarketoRestClient extends MarketoBaseRestClient
|
|
53
54
|
|
54
55
|
private static final String RANGE_HEADER = "Range";
|
55
56
|
|
57
|
+
private static final int CONNECT_TIMEOUT_IN_MILLIS = 30000;
|
58
|
+
private static final int IDLE_TIMEOUT_IN_MILLIS = 60000;
|
59
|
+
|
56
60
|
private String endPoint;
|
57
61
|
|
58
62
|
private Integer batchSize;
|
@@ -108,11 +112,23 @@ public class MarketoRestClient extends MarketoBaseRestClient
|
|
108
112
|
@Config("read_timeout_millis")
|
109
113
|
@ConfigDefault("60000")
|
110
114
|
Long getReadTimeoutMillis();
|
115
|
+
|
116
|
+
@Config("maximum_retries")
|
117
|
+
@ConfigDefault("7")
|
118
|
+
Integer getMaximumRetries();
|
119
|
+
|
120
|
+
@Config("initial_retry_interval_milis")
|
121
|
+
@ConfigDefault("20000")
|
122
|
+
Integer getInitialRetryIntervalMilis();
|
123
|
+
|
124
|
+
@Config("maximum_retries_interval_milis")
|
125
|
+
@ConfigDefault("120000")
|
126
|
+
Integer getMaximumRetriesIntervalMilis();
|
111
127
|
}
|
112
128
|
|
113
|
-
public MarketoRestClient(PluginTask task
|
129
|
+
public MarketoRestClient(PluginTask task)
|
114
130
|
{
|
115
|
-
this(MarketoUtils.getEndPoint(task.getAccountId()), MarketoUtils.getIdentityEndPoint(task.getAccountId()), task.getClientId(), task.getClientSecret(), task.getBatchSize(), task.getMaxReturn(), task.getReadTimeoutMillis(), task.getMarketoLimitIntervalMilis(),
|
131
|
+
this(MarketoUtils.getEndPoint(task.getAccountId()), MarketoUtils.getIdentityEndPoint(task.getAccountId()), task.getClientId(), task.getClientSecret(), task.getBatchSize(), task.getMaxReturn(), task.getReadTimeoutMillis(), task.getMarketoLimitIntervalMilis(), new Jetty92RetryHelper(task.getMaximumRetries(), task.getInitialRetryIntervalMilis(), task.getMaximumRetriesIntervalMilis(), new DefaultJetty92ClientCreator(CONNECT_TIMEOUT_IN_MILLIS, IDLE_TIMEOUT_IN_MILLIS)));
|
116
132
|
}
|
117
133
|
|
118
134
|
public MarketoRestClient(String endPoint, String identityEndPoint, String clientId, String clientSecret, Integer batchSize, Integer maxReturn, long readTimeoutMilis, int marketoLimitIntervalMilis, Jetty92RetryHelper retryHelper)
|
@@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
5
5
|
import com.google.common.io.ByteStreams;
|
6
6
|
import org.embulk.EmbulkTestRuntime;
|
7
7
|
import org.embulk.input.marketo.model.BulkExtractRangeHeader;
|
8
|
-
import org.embulk.input.marketo.model.MarketoField;
|
9
8
|
import org.embulk.input.marketo.rest.MarketoRestClient;
|
10
9
|
import org.embulk.input.marketo.rest.RecordPagingIterable;
|
11
10
|
import org.junit.Assert;
|
@@ -135,28 +134,4 @@ public class MarketoServiceImplTest
|
|
135
134
|
marketoService.describeLead();
|
136
135
|
Mockito.verify(mockMarketoRestClient, Mockito.times(1)).describeLead();
|
137
136
|
}
|
138
|
-
|
139
|
-
@Test
|
140
|
-
public void describeLeadByProgram() throws Exception
|
141
|
-
{
|
142
|
-
List<MarketoField> marketoFields = new ArrayList<>();
|
143
|
-
Mockito.when(mockMarketoRestClient.describeLead()).thenReturn(marketoFields);
|
144
|
-
marketoService.describeLeadByProgram();
|
145
|
-
Mockito.verify(mockMarketoRestClient, Mockito.times(1)).describeLead();
|
146
|
-
Assert.assertEquals(1, marketoFields.size());
|
147
|
-
Assert.assertEquals("programId", marketoFields.get(0).getName());
|
148
|
-
Assert.assertEquals(MarketoField.MarketoDataType.STRING, marketoFields.get(0).getMarketoDataType());
|
149
|
-
}
|
150
|
-
|
151
|
-
@Test
|
152
|
-
public void describeLeadByLists() throws Exception
|
153
|
-
{
|
154
|
-
List<MarketoField> marketoFields = new ArrayList<>();
|
155
|
-
Mockito.when(mockMarketoRestClient.describeLead()).thenReturn(marketoFields);
|
156
|
-
marketoService.describeLeadByLists();
|
157
|
-
Mockito.verify(mockMarketoRestClient, Mockito.times(1)).describeLead();
|
158
|
-
Assert.assertEquals(1, marketoFields.size());
|
159
|
-
Assert.assertEquals("listId", marketoFields.get(0).getName());
|
160
|
-
Assert.assertEquals(MarketoField.MarketoDataType.STRING, marketoFields.get(0).getMarketoDataType());
|
161
|
-
}
|
162
137
|
}
|
data/src/test/java/org/embulk/input/marketo/delegate/LeadServiceResponseMapperBuilderTest.java
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
package org.embulk.input.marketo.delegate;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.databind.JavaType;
|
4
|
+
import org.embulk.EmbulkTestRuntime;
|
5
|
+
import org.embulk.base.restclient.ServiceResponseMapper;
|
6
|
+
import org.embulk.base.restclient.record.ValueLocator;
|
7
|
+
import org.embulk.config.ConfigLoader;
|
8
|
+
import org.embulk.config.ConfigSource;
|
9
|
+
import org.embulk.input.marketo.MarketoService;
|
10
|
+
import org.embulk.input.marketo.MarketoUtils;
|
11
|
+
import org.embulk.input.marketo.model.MarketoField;
|
12
|
+
import org.embulk.spi.Schema;
|
13
|
+
import org.junit.Assert;
|
14
|
+
import org.junit.Before;
|
15
|
+
import org.junit.Rule;
|
16
|
+
import org.junit.Test;
|
17
|
+
import org.mockito.Mockito;
|
18
|
+
|
19
|
+
import java.io.IOException;
|
20
|
+
import java.util.ArrayList;
|
21
|
+
import java.util.List;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Created by tai.khuu on 5/24/18.
|
25
|
+
*/
|
26
|
+
public class LeadServiceResponseMapperBuilderTest
|
27
|
+
{
|
28
|
+
private LeadServiceResponseMapperBuilder<LeadServiceResponseMapperBuilder.PluginTask> leadServiceResponseMapperBuilder;
|
29
|
+
|
30
|
+
@Rule
|
31
|
+
public EmbulkTestRuntime embulkTestRuntime = new EmbulkTestRuntime();
|
32
|
+
|
33
|
+
private LeadServiceResponseMapperBuilder.PluginTask pluginTask;
|
34
|
+
|
35
|
+
private ConfigSource configSource;
|
36
|
+
|
37
|
+
private MarketoService marketoService;
|
38
|
+
|
39
|
+
@Before
|
40
|
+
public void setUp() throws Exception
|
41
|
+
{
|
42
|
+
ConfigLoader configLoader = embulkTestRuntime.getExec().getInjector().getInstance(ConfigLoader.class);
|
43
|
+
configSource = configLoader.fromYamlString("--- \n" +
|
44
|
+
"account_id: 389-FLQ-873\n" +
|
45
|
+
"client_id: 87bdd058-12ff-49b8-8d29-c0518669e59a\n" +
|
46
|
+
"client_secret: 2uauyk43zzwjlUZwboZVxQ3SMTHe8ILY\n" +
|
47
|
+
"included_fields: \n" +
|
48
|
+
" - company\n" +
|
49
|
+
" - site\n" +
|
50
|
+
" - billingstreet\n" +
|
51
|
+
" - billingcity\n" +
|
52
|
+
" - billingstate\n" +
|
53
|
+
" - billingcountry\n" +
|
54
|
+
" - billingpostalCode\n" +
|
55
|
+
" - website\n" +
|
56
|
+
" - mainphone\n" +
|
57
|
+
" - annualrevenue\n" +
|
58
|
+
" - numberofemployees\n" +
|
59
|
+
" - industry\n" +
|
60
|
+
" - siccode\n" +
|
61
|
+
" - mktoCompanyNotes\n" +
|
62
|
+
" - externalcompanyId\n" +
|
63
|
+
" - id\n" +
|
64
|
+
"target: all_lead_with_list_id\n");
|
65
|
+
pluginTask = configSource.loadConfig(LeadServiceResponseMapperBuilder.PluginTask.class);
|
66
|
+
marketoService = Mockito.mock(MarketoService.class);
|
67
|
+
JavaType marketoFieldsType = MarketoUtils.OBJECT_MAPPER.getTypeFactory().constructParametrizedType(List.class, List.class, MarketoField.class);
|
68
|
+
List<MarketoField> marketoFields = MarketoUtils.OBJECT_MAPPER.readValue(this.getClass().getResourceAsStream("/fixtures/lead_describe_marketo_fields_full.json"), marketoFieldsType);
|
69
|
+
Mockito.when(marketoService.describeLead()).thenReturn(marketoFields);
|
70
|
+
}
|
71
|
+
|
72
|
+
@Test
|
73
|
+
public void buildServiceResponseMapper() throws Exception
|
74
|
+
{
|
75
|
+
leadServiceResponseMapperBuilder = new LeadServiceResponseMapperBuilder<>(pluginTask, marketoService);
|
76
|
+
ServiceResponseMapper<? extends ValueLocator> serviceResponseMapper = leadServiceResponseMapperBuilder.buildServiceResponseMapper(pluginTask);
|
77
|
+
Assert.assertFalse(pluginTask.getExtractedFields().isEmpty());
|
78
|
+
Assert.assertEquals(16, pluginTask.getExtractedFields().size());
|
79
|
+
Schema embulkSchema = serviceResponseMapper.getEmbulkSchema();
|
80
|
+
Assert.assertEquals(16, embulkSchema.getColumns().size());
|
81
|
+
Assert.assertEquals("mk_billingStreet", embulkSchema.getColumns().get(2).getName());
|
82
|
+
Assert.assertEquals("mk_company", embulkSchema.getColumn(0).getName());
|
83
|
+
Assert.assertEquals("mk_billingStreet", embulkSchema.getColumn(2).getName());
|
84
|
+
Assert.assertEquals("mk_id", embulkSchema.getColumn(15).getName());
|
85
|
+
}
|
86
|
+
|
87
|
+
@Test
|
88
|
+
public void getLeadColumnsIncludedEmpty() throws IOException
|
89
|
+
{
|
90
|
+
configSource = configSource.set("included_fields", MarketoUtils.OBJECT_MAPPER.readTree("[]"));
|
91
|
+
pluginTask = configSource.loadConfig(LeadServiceResponseMapperBuilder.PluginTask.class);
|
92
|
+
leadServiceResponseMapperBuilder = new LeadServiceResponseMapperBuilder<>(pluginTask, marketoService);
|
93
|
+
List<MarketoField> leadColumns = leadServiceResponseMapperBuilder.getLeadColumns();
|
94
|
+
Assert.assertEquals(129, leadColumns.size());
|
95
|
+
}
|
96
|
+
|
97
|
+
@Test
|
98
|
+
public void getLeadColumnsIncluded1() throws IOException
|
99
|
+
{
|
100
|
+
configSource = configSource.set("included_fields", MarketoUtils.OBJECT_MAPPER.readTree("[\"company\",\"incorrect_value\"]"));
|
101
|
+
pluginTask = configSource.loadConfig(LeadServiceResponseMapperBuilder.PluginTask.class);
|
102
|
+
leadServiceResponseMapperBuilder = new LeadServiceResponseMapperBuilder<>(pluginTask, marketoService);
|
103
|
+
List<MarketoField> leadColumns = leadServiceResponseMapperBuilder.getLeadColumns();
|
104
|
+
Assert.assertEquals(1, leadColumns.size());
|
105
|
+
Assert.assertEquals("company", leadColumns.get(0).getName());
|
106
|
+
}
|
107
|
+
|
108
|
+
@Test
|
109
|
+
public void getLeadColumnsIncluded2() throws IOException
|
110
|
+
{
|
111
|
+
configSource = configSource.set("included_fields", MarketoUtils.OBJECT_MAPPER.readTree("[\"company\",\"incorrect_value\"]"));
|
112
|
+
pluginTask = configSource.loadConfig(LeadServiceResponseMapperBuilder.PluginTask.class);
|
113
|
+
marketoService = Mockito.mock(MarketoService.class);
|
114
|
+
leadServiceResponseMapperBuilder = new LeadServiceResponseMapperBuilder<>(pluginTask, marketoService);
|
115
|
+
Mockito.when(marketoService.describeLead()).thenReturn(new ArrayList<MarketoField>());
|
116
|
+
List<MarketoField> leadColumns = leadServiceResponseMapperBuilder.getLeadColumns();
|
117
|
+
Assert.assertTrue(leadColumns.isEmpty());
|
118
|
+
}
|
119
|
+
}
|
@@ -72,7 +72,7 @@ public class MarketoRestClientTest
|
|
72
72
|
configSource.set("max_return", 2);
|
73
73
|
MarketoRestClient.PluginTask task = configSource.loadConfig(MarketoRestClient.PluginTask.class);
|
74
74
|
mockRetryHelper = Mockito.mock(Jetty92RetryHelper.class);
|
75
|
-
MarketoRestClient realRestClient = new MarketoRestClient(task
|
75
|
+
MarketoRestClient realRestClient = new MarketoRestClient(task);
|
76
76
|
marketoRestClient = Mockito.spy(realRestClient);
|
77
77
|
}
|
78
78
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-input-marketo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.10.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uu59
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-05-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- src/main/java/org/embulk/input/marketo/delegate/ActivityBulkExtractInputPlugin.java
|
74
74
|
- src/main/java/org/embulk/input/marketo/delegate/CampaignInputPlugin.java
|
75
75
|
- src/main/java/org/embulk/input/marketo/delegate/LeadBulkExtractInputPlugin.java
|
76
|
+
- src/main/java/org/embulk/input/marketo/delegate/LeadServiceResponseMapperBuilder.java
|
76
77
|
- src/main/java/org/embulk/input/marketo/delegate/LeadWithListInputPlugin.java
|
77
78
|
- src/main/java/org/embulk/input/marketo/delegate/LeadWithProgramInputPlugin.java
|
78
79
|
- src/main/java/org/embulk/input/marketo/delegate/MarketoBaseBulkExtractInputPlugin.java
|
@@ -97,6 +98,7 @@ files:
|
|
97
98
|
- src/test/java/org/embulk/input/marketo/delegate/ActivityBulkExtractInputPluginTest.java
|
98
99
|
- src/test/java/org/embulk/input/marketo/delegate/CampaignInputPluginTest.java
|
99
100
|
- src/test/java/org/embulk/input/marketo/delegate/LeadBulkExtractInputPluginTest.java
|
101
|
+
- src/test/java/org/embulk/input/marketo/delegate/LeadServiceResponseMapperBuilderTest.java
|
100
102
|
- src/test/java/org/embulk/input/marketo/delegate/LeadWithListInputPluginTest.java
|
101
103
|
- src/test/java/org/embulk/input/marketo/delegate/LeadWithProgramInputPluginTest.java
|
102
104
|
- src/test/java/org/embulk/input/marketo/delegate/MarketoBaseBulkExtractInputPluginTest.java
|
@@ -124,9 +126,9 @@ files:
|
|
124
126
|
- src/test/resources/fixtures/program_response.json
|
125
127
|
- classpath/jetty-http-9.2.14.v20151106.jar
|
126
128
|
- classpath/embulk-base-restclient-0.5.3.jar
|
129
|
+
- classpath/embulk-input-marketo-0.6.10.alpha.jar
|
127
130
|
- classpath/jetty-client-9.2.14.v20151106.jar
|
128
131
|
- classpath/jetty-util-9.2.14.v20151106.jar
|
129
|
-
- classpath/embulk-input-marketo-0.6.9.jar
|
130
132
|
- classpath/embulk-util-retryhelper-jetty92-0.5.3.jar
|
131
133
|
- classpath/jetty-io-9.2.14.v20151106.jar
|
132
134
|
homepage: https://github.com/treasure-data/embulk-input-marketo
|
@@ -144,9 +146,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
146
|
version: '0'
|
145
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
148
|
requirements:
|
147
|
-
- - '
|
149
|
+
- - '>'
|
148
150
|
- !ruby/object:Gem::Version
|
149
|
-
version:
|
151
|
+
version: 1.3.1
|
150
152
|
requirements: []
|
151
153
|
rubyforge_project:
|
152
154
|
rubygems_version: 2.1.9
|