2019-12-17 16:24:49 +01:00
|
|
|
package eu.dnetlib.dhp.graph;
|
|
|
|
|
|
|
|
import eu.dnetlib.dhp.application.ArgumentApplicationParser;
|
2020-02-13 16:53:27 +01:00
|
|
|
import eu.dnetlib.dhp.graph.utils.ContextMapper;
|
2019-12-17 16:24:49 +01:00
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
|
import org.apache.hadoop.fs.Path;
|
2020-01-21 16:35:44 +01:00
|
|
|
import org.apache.spark.SparkConf;
|
2019-12-17 16:24:49 +01:00
|
|
|
import org.apache.spark.sql.SparkSession;
|
|
|
|
|
2020-01-30 17:46:29 +01:00
|
|
|
public class SparkXmlRecordBuilderJob {
|
2019-12-17 16:24:49 +01:00
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
2020-02-13 16:53:27 +01:00
|
|
|
final ArgumentApplicationParser parser = new ArgumentApplicationParser(IOUtils.toString(SparkXmlRecordBuilderJob.class.getResourceAsStream("/eu/dnetlib/dhp/graph/input_params_build_adjacency_lists.json")));
|
2019-12-17 16:24:49 +01:00
|
|
|
parser.parseArgument(args);
|
2020-01-21 16:35:44 +01:00
|
|
|
|
2020-02-13 16:53:27 +01:00
|
|
|
final String master = parser.get("master");
|
2020-01-21 16:35:44 +01:00
|
|
|
final SparkConf conf = new SparkConf()
|
2020-01-30 17:46:29 +01:00
|
|
|
.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer");
|
2020-01-21 16:35:44 +01:00
|
|
|
|
2020-02-13 16:53:27 +01:00
|
|
|
try(SparkSession spark = getSession(conf, master)) {
|
|
|
|
|
|
|
|
final String inputPath = parser.get("sourcePath");
|
|
|
|
final String outputPath = parser.get("outputPath");
|
|
|
|
final String isLookupUrl = parser.get("isLookupUrl");
|
2019-12-17 16:24:49 +01:00
|
|
|
|
2020-02-13 16:53:27 +01:00
|
|
|
final FileSystem fs = FileSystem.get(spark.sparkContext().hadoopConfiguration());
|
|
|
|
if (fs.exists(new Path(outputPath))) {
|
|
|
|
fs.delete(new Path(outputPath), true);
|
|
|
|
fs.mkdirs(new Path(outputPath));
|
|
|
|
}
|
2019-12-17 16:24:49 +01:00
|
|
|
|
2020-02-13 16:53:27 +01:00
|
|
|
new GraphJoiner(spark, ContextMapper.fromIS(isLookupUrl), inputPath, outputPath)
|
|
|
|
.adjacencyLists();
|
2019-12-17 16:24:49 +01:00
|
|
|
}
|
2020-02-13 16:53:27 +01:00
|
|
|
}
|
2019-12-17 16:24:49 +01:00
|
|
|
|
2020-02-13 16:53:27 +01:00
|
|
|
private static SparkSession getSession(SparkConf conf, String master) {
|
|
|
|
return SparkSession
|
|
|
|
.builder()
|
|
|
|
.config(conf)
|
|
|
|
.appName(SparkXmlRecordBuilderJob.class.getSimpleName())
|
|
|
|
.master(master)
|
|
|
|
.getOrCreate();
|
2019-12-17 16:24:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|