diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1e0ac85a..8151a4ba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## [16.3.0] - TBD
+### Added
+* Added method `newInstance(CopierContext)` to `com.hotels.bdp.circustrain.api.copier.CopierFactory`. This provides Copiers with more configuration information in a future proof manner. See [#195](https://github.com/HotelsDotCom/circus-train/issues/195).
+### Deprecated
+* Deprecated other `newInstance()` methods on `com.hotels.bdp.circustrain.api.copier.CopierFactory`.
+
## [16.2.0] - 2020-07-01
### Changed
* Changed version of `hive.version` to `2.3.7` (was `2.3.2`). This allows Circus Train to be used on JDK>=9.
diff --git a/circus-train-api/pom.xml b/circus-train-api/pom.xml
index 06582359..643f976f 100644
--- a/circus-train-api/pom.xml
+++ b/circus-train-api/pom.xml
@@ -4,7 +4,7 @@
com.hotels
circus-train-parent
- 16.2.1-SNAPSHOT
+ 16.3.0-SNAPSHOT
circus-train-api
diff --git a/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CompositeCopierFactory.java b/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CompositeCopierFactory.java
index e8770fbf..d8488dcf 100644
--- a/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CompositeCopierFactory.java
+++ b/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CompositeCopierFactory.java
@@ -82,21 +82,20 @@ public boolean supportsSchemes(String sourceScheme, String replicaScheme) {
}
@Override
- public Copier newInstance(
- String eventId,
- Path sourceBaseLocation,
- List sourceSubLocations,
- Path replicaLocation,
- Map copierOptions) {
+ public Copier newInstance(CopierContext copierContext) {
List copiers = new ArrayList<>(delegates.size());
int i = 0;
for (CopierFactory delegate : delegates) {
- CopierPathGeneratorParams copierPathGeneratorParams = CopierPathGeneratorParams.newParams(i++, eventId,
- sourceBaseLocation, sourceSubLocations, replicaLocation, copierOptions);
+ CopierPathGeneratorParams copierPathGeneratorParams = CopierPathGeneratorParams
+ .newParams(i++, copierContext.getEventId(), copierContext.getSourceBaseLocation(),
+ copierContext.getSourceSubLocations(), copierContext.getReplicaLocation(),
+ copierContext.getCopierOptions());
Path newSourceBaseLocation = pathGenerator.generateSourceBaseLocation(copierPathGeneratorParams);
Path newReplicaLocation = pathGenerator.generateReplicaLocation(copierPathGeneratorParams);
- Copier copier = delegate.newInstance(eventId, newSourceBaseLocation, sourceSubLocations, newReplicaLocation,
- copierOptions);
+
+ CopierContext delegateContext = new CopierContext(copierContext.getEventId(), newSourceBaseLocation,
+ copierContext.getSourceSubLocations(), newReplicaLocation, copierContext.getCopierOptions());
+ Copier copier = delegate.newInstance(delegateContext);
copiers.add(copier);
}
return new CompositeCopier(copiers, metricsMerger);
@@ -108,17 +107,20 @@ public Copier newInstance(
Path sourceBaseLocation,
Path replicaLocation,
Map copierOptions) {
- List copiers = new ArrayList<>(delegates.size());
- int i = 0;
- for (CopierFactory delegatee : delegates) {
- CopierPathGeneratorParams copierPathGeneratorParams = CopierPathGeneratorParams.newParams(i++, eventId,
- sourceBaseLocation, null, replicaLocation, copierOptions);
- Path newReplicaLocation = pathGenerator.generateReplicaLocation(copierPathGeneratorParams);
- Path newSourceBaseLocation = pathGenerator.generateSourceBaseLocation(copierPathGeneratorParams);
- Copier copier = delegatee.newInstance(eventId, newSourceBaseLocation, newReplicaLocation, copierOptions);
- copiers.add(copier);
- }
- return new CompositeCopier(copiers, metricsMerger);
+ CopierContext copierContext = new CopierContext(eventId, sourceBaseLocation, replicaLocation, copierOptions);
+ return newInstance(copierContext);
+ }
+
+ @Override
+ public Copier newInstance(
+ String eventId,
+ Path sourceBaseLocation,
+ List sourceSubLocations,
+ Path replicaLocation,
+ Map copierOptions) {
+ CopierContext copierContext = new CopierContext(eventId, sourceBaseLocation, sourceSubLocations, replicaLocation,
+ copierOptions);
+ return newInstance(copierContext);
}
}
diff --git a/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierContext.java b/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierContext.java
new file mode 100644
index 00000000..d961af96
--- /dev/null
+++ b/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierContext.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright (C) 2016-2020 Expedia, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.hotels.bdp.circustrain.api.copier;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.fs.Path;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+import com.hotels.bdp.circustrain.api.conf.TableReplication;
+
+public final class CopierContext {
+
+ private String eventId;
+ private Path sourceBaseLocation;
+ private List sourceSubLocations = ImmutableList.copyOf(Collections.emptyList());
+ private Path replicaLocation;
+ private Map copierOptions;
+ private TableReplication tableReplication;
+
+ public CopierContext(
+ TableReplication tableReplication,
+ String eventId,
+ Path sourceBaseLocation,
+ List sourceSubLocations,
+ Path replicaLocation,
+ Map copierOptions) {
+ this.tableReplication = tableReplication;
+ this.eventId = eventId;
+ this.sourceBaseLocation = sourceBaseLocation;
+ if (sourceSubLocations != null) {
+ this.sourceSubLocations = ImmutableList.copyOf(sourceSubLocations);
+ }
+ this.replicaLocation = replicaLocation;
+ this.copierOptions = ImmutableMap.copyOf(copierOptions);
+ }
+
+ public CopierContext(
+ TableReplication tableReplication,
+ String eventId,
+ Path sourceLocation,
+ Path replicaLocation,
+ Map copierOptions) {
+ this(tableReplication, eventId, sourceLocation, null, replicaLocation, copierOptions);
+ }
+
+ public CopierContext(
+ String eventId,
+ Path sourceBaseLocation,
+ List sourceSubLocations,
+ Path replicaLocation,
+ Map copierOptions) {
+ this(null, eventId, sourceBaseLocation, sourceSubLocations, replicaLocation, copierOptions);
+ }
+
+ public CopierContext(
+ String eventId,
+ Path sourceBaseLocation,
+ Path replicaLocation,
+ Map copierOptions) {
+ this(null, eventId, sourceBaseLocation, null, replicaLocation, copierOptions);
+ }
+
+ public String getEventId() {
+ return eventId;
+ }
+
+ public Path getSourceBaseLocation() {
+ return sourceBaseLocation;
+ }
+
+ public List getSourceSubLocations() {
+ return sourceSubLocations;
+ }
+
+ public Path getReplicaLocation() {
+ return replicaLocation;
+ }
+
+ public Map getCopierOptions() {
+ return copierOptions;
+ }
+
+ public TableReplication getTableReplication() {
+ return tableReplication;
+ }
+
+}
diff --git a/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierFactory.java b/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierFactory.java
index 1da54c80..b612cc3b 100644
--- a/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierFactory.java
+++ b/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierFactory.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2016-2019 Expedia, Inc.
+ * Copyright (C) 2016-2020 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,20 @@ public interface CopierFactory {
boolean supportsSchemes(String sourceScheme, String replicaScheme);
/**
+ * Creates a new Copier.
+ *
+ * @param copierContext Context object containing configuration values for the Copier.
+ * @return
+ */
+ default Copier newInstance(CopierContext copierContext) {
+ //TODO: this is only here for backwards compatibility with CopierFactorys using older versions of Circus Train, when the below
+ //deprecated methods are removed so should this default implementation
+ return newInstance(copierContext.getEventId(), copierContext.getSourceBaseLocation(), copierContext.getSourceSubLocations(), copierContext.getReplicaLocation(),
+ copierContext.getCopierOptions());
+ }
+
+ /**
+ * @deprecated As of release 16.3.0, replaced by {@link #newInstance(CopierContext)}.
* @param eventId
* @param sourceBaseLocation
* @param sourceSubLocations
@@ -32,6 +46,7 @@ public interface CopierFactory {
* @param copierOptions, contains both global and per table override configured options
* @return
*/
+ @Deprecated
Copier newInstance(
String eventId,
Path sourceBaseLocation,
@@ -40,12 +55,15 @@ Copier newInstance(
Map copierOptions);
/**
+ * @deprecated As of release 16.3.0, replaced by {@link #newInstance(CopierContext)}.
+ *
* @param eventId
* @param sourceBaseLocation
* @param replicaLocation
* @param copierOptions, contains both global and per table override configured options
* @return
*/
+ @Deprecated
Copier newInstance(String eventId, Path sourceBaseLocation, Path replicaLocation, Map copierOptions);
}
diff --git a/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierPathGeneratorParams.java b/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierPathGeneratorParams.java
index e6dd85e0..a1597039 100644
--- a/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierPathGeneratorParams.java
+++ b/circus-train-api/src/main/java/com/hotels/bdp/circustrain/api/copier/CopierPathGeneratorParams.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2016-2019 Expedia, Inc.
+ * Copyright (C) 2016-2020 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/circus-train-api/src/test/java/com/hotels/bdp/circustrain/api/copier/CompositeCopierFactoryTest.java b/circus-train-api/src/test/java/com/hotels/bdp/circustrain/api/copier/CompositeCopierFactoryTest.java
index 2d5fd709..9a0f8c05 100644
--- a/circus-train-api/src/test/java/com/hotels/bdp/circustrain/api/copier/CompositeCopierFactoryTest.java
+++ b/circus-train-api/src/test/java/com/hotels/bdp/circustrain/api/copier/CompositeCopierFactoryTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2016-2019 Expedia, Inc.
+ * Copyright (C) 2016-2020 Expedia, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,9 @@
import static java.util.Arrays.asList;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
@@ -31,7 +32,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Matchers;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@@ -66,14 +67,8 @@ public Path generateReplicaLocation(CopierPathGeneratorParams copierParams) {
@Before
public void init() {
- doReturn(firstCopier).when(firstCopierFactory).newInstance(anyString(), any(Path.class),
- Matchers.> any(), any(Path.class), Matchers.