Skip to content

Commit 834c0b3

Browse files
authored
Merge pull request #107 from datastax/issue/CDM-13
CDM-13 : properties now retrieved via helpers rather than SparkConf
2 parents 3867931 + fd83462 commit 834c0b3

File tree

8 files changed

+1649
-22
lines changed

8 files changed

+1649
-22
lines changed

pom.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<scalatest.version>3.2.12</scalatest.version>
1616
<connector.version>3.2.0</connector.version>
1717
<cassandra.version>3.11.13</cassandra.version>
18-
<junit.version>4.13.2</junit.version>
18+
<junit.version>5.9.1</junit.version>
1919
</properties>
2020

2121
<distributionManagement>
@@ -44,6 +44,10 @@
4444
<groupId>log4j</groupId>
4545
<artifactId>log4j</artifactId>
4646
</exclusion>
47+
<exclusion>
48+
<groupId>org.apache.logging.log4j</groupId>
49+
<artifactId>log4j-slf4j-impl</artifactId>
50+
</exclusion>
4751
</exclusions>
4852
</dependency>
4953
<dependency>
@@ -101,8 +105,8 @@
101105
<scope>test</scope>
102106
</dependency>
103107
<dependency>
104-
<groupId>junit</groupId>
105-
<artifactId>junit</artifactId>
108+
<groupId>org.junit.jupiter</groupId>
109+
<artifactId>junit-jupiter-engine</artifactId>
106110
<version>${junit.version}</version>
107111
<scope>test</scope>
108112
</dependency>
@@ -178,9 +182,6 @@
178182
<groupId>org.apache.maven.plugins</groupId>
179183
<artifactId>maven-surefire-plugin</artifactId>
180184
<version>2.22.2</version>
181-
<configuration>
182-
<skipTests>true</skipTests>
183-
</configuration>
184185
</plugin>
185186
<!-- enable scalatest -->
186187
<plugin>

src/main/java/datastax/astra/migrate/MigrateDataType.java

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,52 @@
1313

1414
public class MigrateDataType {
1515
Class typeClass = Object.class;
16+
String dataTypeString = "";
17+
int type = -1;
1618
List<Class> subTypes = new ArrayList<Class>();
19+
private boolean isValid = false;
20+
private static int minType = 0;
21+
private static int maxType = 19;
1722

1823
public MigrateDataType(String dataType) {
24+
dataTypeString = dataType;
1925
if (dataType.contains("%")) {
2026
int count = 1;
2127
for (String type : dataType.split("%")) {
28+
int typeAsInt = typeAsInt(type);
2229
if (count == 1) {
23-
typeClass = getType(Integer.parseInt(type));
30+
this.type = typeAsInt;
2431
} else {
25-
subTypes.add(getType(Integer.parseInt(type)));
32+
subTypes.add(getType(typeAsInt));
2633
}
2734
count++;
2835
}
2936
} else {
30-
int type = Integer.parseInt(dataType);
31-
typeClass = getType(type);
37+
this.type = typeAsInt(dataType);
3238
}
39+
this.typeClass = getType(this.type);
40+
41+
if (this.type >= minType && this.type <= maxType) {
42+
isValid = true;
43+
for (Object o : subTypes) {
44+
if (null == o || Object.class == o) {
45+
isValid = false;
46+
}
47+
}
48+
}
49+
else {
50+
isValid = false;
51+
}
52+
}
53+
54+
private int typeAsInt(String dataType) {
55+
int rtn = -1;
56+
try {
57+
rtn = Integer.parseInt(dataType);
58+
} catch (NumberFormatException e) {
59+
rtn = -1;
60+
}
61+
return rtn;
3362
}
3463

3564
public boolean diff(Object source, Object astra) {
@@ -91,4 +120,25 @@ private Class getType(int type) {
91120
return Object.class;
92121
}
93122

123+
public Class getType() {
124+
return this.typeClass;
125+
}
126+
127+
public boolean isValid() {
128+
return isValid;
129+
}
130+
131+
@Override
132+
public boolean equals(Object o) {
133+
if (this == o) return true;
134+
if (o == null || getClass() != o.getClass()) return false;
135+
MigrateDataType that = (MigrateDataType) o;
136+
return type == that.type &&
137+
Objects.equals(subTypes, that.subTypes);
138+
}
139+
140+
@Override
141+
public String toString() {
142+
return dataTypeString;
143+
}
94144
}

src/main/java/datastax/astra/migrate/Util.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package datastax.astra.migrate;
22

33
import com.datastax.oss.driver.api.core.ConsistencyLevel;
4+
import datastax.astra.migrate.properties.KnownProperties;
5+
import datastax.astra.migrate.properties.PropertyHelper;
46
import org.apache.commons.lang.StringUtils;
57
import org.apache.spark.SparkConf;
68

@@ -12,21 +14,19 @@
1214
public class Util {
1315

1416
public static String getSparkProp(SparkConf sc, String prop) {
15-
try {
16-
return sc.get(prop);
17-
} catch (NoSuchElementException nse) {
18-
String newProp = prop.replace("origin", "source").replace("target", "destination");
19-
return sc.get(newProp);
17+
String retVal = PropertyHelper.getInstance(sc).getAsString(prop);
18+
if (StringUtils.isEmpty(retVal) && (prop.contains("origin") || prop.contains("target"))) {
19+
retVal = PropertyHelper.getInstance(sc).getAsString(prop.replace("origin", "source").replace("target", "destination"));
20+
}
21+
if (!KnownProperties.isKnown(prop)) {
22+
throw new IllegalArgumentException("Unknown property: " + prop + "; this is a bug in the code: the property is not configured in KnownProperties.java");
2023
}
24+
return retVal;
2125
}
2226

2327
public static String getSparkPropOr(SparkConf sc, String prop, String defaultVal) {
24-
try {
25-
return sc.get(prop);
26-
} catch (NoSuchElementException nse) {
27-
String newProp = prop.replace("origin", "source").replace("target", "destination");
28-
return sc.get(newProp, defaultVal);
29-
}
28+
String retVal = getSparkProp(sc,prop);
29+
return StringUtils.isEmpty(retVal) ? defaultVal : retVal;
3030
}
3131

3232
public static String getSparkPropOrEmpty(SparkConf sc, String prop) {

0 commit comments

Comments
 (0)