-
Notifications
You must be signed in to change notification settings - Fork 70
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
Support dependencies v2 in c* #59
Changes from all 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 |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
import static com.datastax.spark.connector.japi.CassandraJavaUtil.mapRowTo; | ||
import static com.datastax.spark.connector.japi.CassandraJavaUtil.mapToRow; | ||
|
||
import com.datastax.spark.connector.japi.CassandraJavaUtil; | ||
import com.datastax.spark.connector.cql.CassandraConnector; | ||
import com.datastax.spark.connector.japi.CassandraRow; | ||
import com.google.common.base.Joiner; | ||
import com.google.common.net.HostAndPort; | ||
import io.jaegertracing.spark.dependencies.DependenciesSparkHelper; | ||
|
@@ -173,10 +174,19 @@ public void run() { | |
} | ||
|
||
private void store(JavaSparkContext sc, List<Dependency> links) { | ||
CassandraDependencies dependencies = new CassandraDependencies(links, day); | ||
javaFunctions(sc.parallelize(Collections.singletonList(dependencies))) | ||
.writerBuilder(keyspace, "dependencies", mapToRow(CassandraDependencies.class)) | ||
.saveToCassandra(); | ||
String table = dependenciesTable(sc); | ||
log.info("Storing dependencies into {}", table); | ||
if (table == "dependencies_v2") { | ||
CassandraDependenciesV2 dependencies = new CassandraDependenciesV2(links, day); | ||
javaFunctions(sc.parallelize(Collections.singletonList(dependencies))) | ||
.writerBuilder(keyspace, table, mapToRow(CassandraDependenciesV2.class)) | ||
.saveToCassandra(); | ||
} else { | ||
CassandraDependencies dependencies = new CassandraDependencies(links, day); | ||
javaFunctions(sc.parallelize(Collections.singletonList(dependencies))) | ||
.writerBuilder(keyspace, table, mapToRow(CassandraDependencies.class)) | ||
.saveToCassandra(); | ||
} | ||
} | ||
|
||
static String parseHosts(String contactPoints) { | ||
|
@@ -198,6 +208,17 @@ static String parsePort(String contactPoints) { | |
return ports.size() == 1 ? String.valueOf(ports.iterator().next()) : "9042"; | ||
} | ||
|
||
private String dependenciesTable(JavaSparkContext sc) { | ||
try { | ||
javaFunctions(sc) | ||
.cassandraTable(keyspace, "dependencies_v2") | ||
.limit(1L).collect(); | ||
} catch (Exception ex) { | ||
return "dependencies"; | ||
} | ||
return "dependencies_v2"; | ||
} | ||
|
||
/** | ||
* DTO object used to store dependencies to Cassandra, see {@link com.datastax.spark.connector.mapper.JavaBeanColumnMapper} | ||
*/ | ||
|
@@ -224,5 +245,32 @@ public Long getTsIndex() { | |
return zonedDateTime.toInstant().toEpochMilli(); | ||
} | ||
} | ||
|
||
/** | ||
* DTO object used to store dependencies to Cassandra, see {@link com.datastax.spark.connector.mapper.JavaBeanColumnMapper} | ||
*/ | ||
public final static class CassandraDependenciesV2 implements Serializable { | ||
private static final long serialVersionUID = 0L; | ||
|
||
private List<Dependency> dependencies; | ||
private ZonedDateTime zonedDateTime; | ||
|
||
public CassandraDependenciesV2(List<Dependency> dependencies, ZonedDateTime ts) { | ||
this.dependencies = dependencies; | ||
this.zonedDateTime = ts; | ||
} | ||
|
||
public List<Dependency> getDependencies() { | ||
return dependencies; | ||
} | ||
|
||
public Long getTs() { | ||
return zonedDateTime.toInstant().toEpochMilli(); | ||
} | ||
|
||
public Long getTsBucket() { | ||
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. @black-adder is this ok? 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 should truncate the time as well, ala |
||
return zonedDateTime.toInstant().toEpochMilli(); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,13 @@ public boolean equals(Object o) { | |
&& this.callCount == that.callCount; | ||
} | ||
|
||
public String getSource() { | ||
return "jaeger"; | ||
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. @black-adder is this ok? 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. yup |
||
} | ||
|
||
public void setSource(String source) { | ||
} | ||
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. is this a no-op on purpose? 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. yep |
||
|
||
@Override | ||
public int hashCode() { | ||
int h = 1; | ||
|
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.
I think using equals() is better.
use == to compare strings, in this case, it works but makes confusing.