1
0
Fork 0

Fixes in workflow.xml

This commit is contained in:
Serafeim Chatzopoulos 2023-07-21 15:26:50 +03:00
parent db4ca43ee8
commit 2cc5b1a39b
10 changed files with 100 additions and 92 deletions

View File

@ -9,7 +9,6 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers.BipProjectModel;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.SequenceFileOutputFormat; import org.apache.hadoop.mapred.SequenceFileOutputFormat;
@ -25,8 +24,9 @@ import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers.BipResultModel;
import eu.dnetlib.dhp.actionmanager.bipmodel.BipScore; import eu.dnetlib.dhp.actionmanager.bipmodel.BipScore;
import eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers.BipProjectModel;
import eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers.BipResultModel;
import eu.dnetlib.dhp.application.ArgumentApplicationParser; import eu.dnetlib.dhp.application.ArgumentApplicationParser;
import eu.dnetlib.dhp.common.HdfsSupport; import eu.dnetlib.dhp.common.HdfsSupport;
import eu.dnetlib.dhp.schema.action.AtomicAction; import eu.dnetlib.dhp.schema.action.AtomicAction;
@ -89,8 +89,7 @@ public class SparkAtomicActionScoreJob implements Serializable {
default: default:
throw new RuntimeException("Unknown target entity: " + targetEntity); throw new RuntimeException("Unknown target entity: " + targetEntity);
} }
} });
);
} }
private static <I extends Project> void prepareProjects(SparkSession spark, String inputPath, String outputPath) { private static <I extends Project> void prepareProjects(SparkSession spark, String inputPath, String outputPath) {
@ -98,17 +97,18 @@ public class SparkAtomicActionScoreJob implements Serializable {
// read input bip project scores // read input bip project scores
Dataset<BipProjectModel> projectScores = readPath(spark, inputPath, BipProjectModel.class); Dataset<BipProjectModel> projectScores = readPath(spark, inputPath, BipProjectModel.class);
projectScores.map( (MapFunction<BipProjectModel, Project>) bipProjectScores -> { projectScores.map((MapFunction<BipProjectModel, Project>) bipProjectScores -> {
Project project = new Project(); Project project = new Project();
project.setId(bipProjectScores.getProjectId()); project.setId(bipProjectScores.getProjectId());
project.setMeasures(bipProjectScores.toMeasures()); project.setMeasures(bipProjectScores.toMeasures());
return project; return project;
}, Encoders.bean(Project.class)) }, Encoders.bean(Project.class))
.toJavaRDD() .toJavaRDD()
.map(p -> new AtomicAction(Project.class, p)) .map(p -> new AtomicAction(Project.class, p))
.mapToPair( aa -> new Tuple2<>(new Text(aa.getClazz().getCanonicalName()), .mapToPair(
new Text(OBJECT_MAPPER.writeValueAsString(aa)))) aa -> new Tuple2<>(new Text(aa.getClazz().getCanonicalName()),
.saveAsHadoopFile(outputPath, Text.class, Text.class, SequenceFileOutputFormat.class); new Text(OBJECT_MAPPER.writeValueAsString(aa))))
.saveAsHadoopFile(outputPath, Text.class, Text.class, SequenceFileOutputFormat.class);
} }

View File

@ -1,69 +1,74 @@
package eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers; package eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers;
import com.opencsv.bean.CsvBindByPosition; import static eu.dnetlib.dhp.actionmanager.Constants.*;
import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.oaf.KeyValue;
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import eu.dnetlib.dhp.schema.oaf.Measure;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static eu.dnetlib.dhp.actionmanager.Constants.*; import com.opencsv.bean.CsvBindByPosition;
import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.oaf.KeyValue;
import eu.dnetlib.dhp.schema.oaf.Measure;
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
@Setter @Setter
public class BipProjectModel { public class BipProjectModel {
String projectId; String projectId;
String numOfInfluentialResults; String numOfInfluentialResults;
String numOfPopularResults; String numOfPopularResults;
String totalImpulse; String totalImpulse;
String totalCitationCount; String totalCitationCount;
// each project bip measure has exactly one value, hence one key-value pair // each project bip measure has exactly one value, hence one key-value pair
private Measure createMeasure(String measureId, String measureValue) { private Measure createMeasure(String measureId, String measureValue) {
KeyValue kv = new KeyValue(); KeyValue kv = new KeyValue();
kv.setKey("score"); kv.setKey("score");
kv.setValue(measureValue); kv.setValue(measureValue);
kv.setDataInfo( kv
OafMapperUtils.dataInfo( .setDataInfo(
false, OafMapperUtils
UPDATE_DATA_INFO_TYPE, .dataInfo(
true, false,
false, UPDATE_DATA_INFO_TYPE,
OafMapperUtils.qualifier( true,
UPDATE_MEASURE_BIP_CLASS_ID, false,
UPDATE_CLASS_NAME, OafMapperUtils
ModelConstants.DNET_PROVENANCE_ACTIONS, .qualifier(
ModelConstants.DNET_PROVENANCE_ACTIONS), UPDATE_MEASURE_BIP_CLASS_ID,
"") UPDATE_CLASS_NAME,
); ModelConstants.DNET_PROVENANCE_ACTIONS,
ModelConstants.DNET_PROVENANCE_ACTIONS),
""));
Measure measure = new Measure(); Measure measure = new Measure();
measure.setId(measureId); measure.setId(measureId);
measure.setUnit(Collections.singletonList(kv)); measure.setUnit(Collections.singletonList(kv));
return measure; return measure;
} }
public List<Measure> toMeasures() {
return Arrays.asList( public List<Measure> toMeasures() {
createMeasure("numOfInfluentialResults", numOfInfluentialResults), return Arrays
createMeasure("numOfPopularResults", numOfPopularResults), .asList(
createMeasure("totalImpulse", totalImpulse), createMeasure("numOfInfluentialResults", numOfInfluentialResults),
createMeasure("totalCitationCount", totalCitationCount) createMeasure("numOfPopularResults", numOfPopularResults),
); createMeasure("totalImpulse", totalImpulse),
} createMeasure("totalCitationCount", totalCitationCount));
}
} }

View File

@ -1,13 +1,13 @@
package eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers; package eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers;
import eu.dnetlib.dhp.actionmanager.bipmodel.Score;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import eu.dnetlib.dhp.actionmanager.bipmodel.Score;
/** /**
* Class that maps the model of the bipFinder! input data. * Class that maps the model of the bipFinder! input data.
* Only needed for deserialization purposes * Only needed for deserialization purposes

View File

@ -24,8 +24,8 @@ import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers.BipResultModel;
import eu.dnetlib.dhp.actionmanager.bipmodel.BipScore; import eu.dnetlib.dhp.actionmanager.bipmodel.BipScore;
import eu.dnetlib.dhp.actionmanager.bipmodel.score.deserializers.BipResultModel;
import eu.dnetlib.dhp.application.ArgumentApplicationParser; import eu.dnetlib.dhp.application.ArgumentApplicationParser;
import eu.dnetlib.dhp.common.HdfsSupport; import eu.dnetlib.dhp.common.HdfsSupport;
import eu.dnetlib.dhp.schema.common.ModelConstants; import eu.dnetlib.dhp.schema.common.ModelConstants;

View File

@ -7,8 +7,6 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import eu.dnetlib.dhp.schema.oaf.KeyValue;
import eu.dnetlib.dhp.schema.oaf.Project;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Text;
import org.apache.spark.SparkConf; import org.apache.spark.SparkConf;
@ -28,6 +26,8 @@ import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.dhp.schema.action.AtomicAction; import eu.dnetlib.dhp.schema.action.AtomicAction;
import eu.dnetlib.dhp.schema.oaf.KeyValue;
import eu.dnetlib.dhp.schema.oaf.Project;
import eu.dnetlib.dhp.schema.oaf.Result; import eu.dnetlib.dhp.schema.oaf.Result;
public class SparkAtomicActionScoreJobTest { public class SparkAtomicActionScoreJobTest {
@ -73,15 +73,16 @@ public class SparkAtomicActionScoreJobTest {
} }
private void runJob(String inputPath, String outputPath, String targetEntity) throws Exception { private void runJob(String inputPath, String outputPath, String targetEntity) throws Exception {
SparkAtomicActionScoreJob.main( SparkAtomicActionScoreJob
new String[] { .main(
new String[] {
"-isSparkSessionManaged", Boolean.FALSE.toString(), "-isSparkSessionManaged", Boolean.FALSE.toString(),
"-inputPath", inputPath, "-inputPath", inputPath,
"-outputPath", outputPath, "-outputPath", outputPath,
"-targetEntity", targetEntity, "-targetEntity", targetEntity,
} });
);
} }
@Test @Test
void testResultScores() throws Exception { void testResultScores() throws Exception {
final String targetEntity = RESULT; final String targetEntity = RESULT;
@ -149,8 +150,8 @@ public class SparkAtomicActionScoreJobTest {
void testProjectScores() throws Exception { void testProjectScores() throws Exception {
String targetEntity = PROJECT; String targetEntity = PROJECT;
String inputResultScores = getClass() String inputResultScores = getClass()
.getResource("/eu/dnetlib/dhp/actionmanager/bipfinder/project_bip_scores.json") .getResource("/eu/dnetlib/dhp/actionmanager/bipfinder/project_bip_scores.json")
.getPath(); .getPath();
String outputPath = workingDir.toString() + "/" + targetEntity + "/actionSet"; String outputPath = workingDir.toString() + "/" + targetEntity + "/actionSet";
// execute the job to generate the action sets for project scores // execute the job to generate the action sets for project scores
@ -159,9 +160,9 @@ public class SparkAtomicActionScoreJobTest {
final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext()); final JavaSparkContext sc = new JavaSparkContext(spark.sparkContext());
JavaRDD<Project> projects = sc JavaRDD<Project> projects = sc
.sequenceFile(outputPath, Text.class, Text.class) .sequenceFile(outputPath, Text.class, Text.class)
.map(value -> OBJECT_MAPPER.readValue(value._2().toString(), AtomicAction.class)) .map(value -> OBJECT_MAPPER.readValue(value._2().toString(), AtomicAction.class))
.map(aa -> ((Project) aa.getPayload())); .map(aa -> ((Project) aa.getPayload()));
// test the number of projects // test the number of projects
assertEquals(4, projects.count()); assertEquals(4, projects.count());
@ -171,7 +172,8 @@ public class SparkAtomicActionScoreJobTest {
// count that the project with id testProjectId is present // count that the project with id testProjectId is present
assertEquals(1, projects.filter(row -> row.getId().equals(testProjectId)).count()); assertEquals(1, projects.filter(row -> row.getId().equals(testProjectId)).count());
projects.filter(row -> row.getId().equals(testProjectId)) projects
.filter(row -> row.getId().equals(testProjectId))
.flatMap(r -> r.getMeasures().iterator()) .flatMap(r -> r.getMeasures().iterator())
.foreach(m -> { .foreach(m -> {
log.info(m.getId() + " " + m.getUnit()); log.info(m.getId() + " " + m.getUnit());
@ -184,7 +186,7 @@ public class SparkAtomicActionScoreJobTest {
// ensure that the correct key is provided, i.e. score // ensure that the correct key is provided, i.e. score
assertEquals("score", kv.getKey()); assertEquals("score", kv.getKey());
switch(m.getId()) { switch (m.getId()) {
case "numOfInfluentialResults": case "numOfInfluentialResults":
assertEquals("0", kv.getValue()); assertEquals("0", kv.getValue());
break; break;

View File

@ -92,7 +92,7 @@ public class PrepareH2020ProgrammeTest {
Assertions.assertEquals(0, verificationDataset.filter("classification = ''").count()); Assertions.assertEquals(0, verificationDataset.filter("classification = ''").count());
//tmp.foreach(csvProgramme -> System.out.println(OBJECT_MAPPER.writeValueAsString(csvProgramme))); // tmp.foreach(csvProgramme -> System.out.println(OBJECT_MAPPER.writeValueAsString(csvProgramme)));
Assertions Assertions
.assertEquals( .assertEquals(

View File

@ -98,7 +98,7 @@ public class ReadProjectsTest {
Assertions.assertEquals("H2020-EU.1.3.", project.getLegalBasis()); Assertions.assertEquals("H2020-EU.1.3.", project.getLegalBasis());
Assertions.assertEquals("MSCA-IF-2019", project.getTopics()); Assertions.assertEquals("MSCA-IF-2019", project.getTopics());
//tmp.foreach(p -> System.out.println(OBJECT_MAPPER.writeValueAsString(p))); // tmp.foreach(p -> System.out.println(OBJECT_MAPPER.writeValueAsString(p)));
} }
} }

View File

@ -93,7 +93,7 @@ public class ReadTopicTest {
Assertions.assertEquals("Individual Fellowships", topic.getTitle()); Assertions.assertEquals("Individual Fellowships", topic.getTitle());
Assertions.assertEquals("MSCA-IF-2019", topic.getTopic()); Assertions.assertEquals("MSCA-IF-2019", topic.getTopic());
//tmp.foreach(p -> System.out.println(OBJECT_MAPPER.writeValueAsString(p))); // tmp.foreach(p -> System.out.println(OBJECT_MAPPER.writeValueAsString(p)));
} }
} }

View File

@ -97,7 +97,7 @@ oozie.wf.application.path=${oozieTopWfApplicationPath}
# Path where the final output should be? # Path where the final output should be?
actionSetOutputPath=${workingDir}/bip_actionsets/ actionSetOutputPath=${workingDir}/bip_actionsets
# The directory to store project impact indicators # The directory to store project impact indicators
projectImpactIndicatorsOutput=${workingDir}/project_indicators projectImpactIndicatorsOutput=${workingDir}/project_indicators

View File

@ -24,20 +24,21 @@
<case to="spark-impulse">${wf:conf('resume') eq "impulse"}</case> <case to="spark-impulse">${wf:conf('resume') eq "impulse"}</case>
<case to="spark-pagerank">${wf:conf('resume') eq "pagerank"}</case> <case to="spark-pagerank">${wf:conf('resume') eq "pagerank"}</case>
<case to="spark-attrank">${wf:conf('resume') eq "attrank"}</case> <case to="spark-attrank">${wf:conf('resume') eq "attrank"}</case>
<!-- Removed for serafeim -->
<!-- <case to="iterative-rankings">${wf:conf('resume') eq "rankings-iterative"}</case> --> <!-- <case to="iterative-rankings">${wf:conf('resume') eq "rankings-iterative"}</case> -->
<case to="get-file-names">${wf:conf('resume') eq "format-results"}</case> <case to="get-file-names">${wf:conf('resume') eq "format-results"}</case>
<case to="map-openaire-to-doi">${wf:conf('resume') eq "map-ids"}</case> <case to="map-openaire-to-doi">${wf:conf('resume') eq "map-ids"}</case>
<case to="map-scores-to-dois">${wf:conf('resume') eq "map-scores"}</case> <case to="map-scores-to-dois">${wf:conf('resume') eq "map-scores"}</case>
<case to="create-openaire-ranking-graph">${wf:conf('resume') eq "start"}</case> <case to="create-openaire-ranking-graph">${wf:conf('resume') eq "start"}</case>
<case to="project-impact-indicators">${wf:conf('resume') eq "projects-impact"}</case>
<!-- TODO: add action set creation here --> <!-- Aggregation of impact scores on the project level -->
<case to="project-impact-indicators">${wf:conf('resume') eq "projects-impact"}</case>
<case to="create-actionset-for-projects">${wf:conf('resume') eq "projects-impact-actionsets"}</case>
<default to="create-openaire-ranking-graph" /> <default to="create-openaire-ranking-graph" />
</switch> </switch>
</decision> </decision>
<!-- Script here written by Serafeim: maps openaire ids to their synonyms --> <!-- maps openaire ids to their synonyms -->
<action name="create-openaire-ranking-graph"> <action name="create-openaire-ranking-graph">
<!-- This is required as a tag for spark jobs, regardless of programming language --> <!-- This is required as a tag for spark jobs, regardless of programming language -->
<spark xmlns="uri:oozie:spark-action:0.2"> <spark xmlns="uri:oozie:spark-action:0.2">
@ -479,7 +480,7 @@
<!-- Finish formatting data and end --> <!-- Finish formatting data and end -->
<join name="join-file-formatting" to="map-openaire-to-doi"/> <join name="join-file-formatting" to="map-openaire-to-doi"/>
<!-- Script here written by Serafeim: maps openaire ids to their synonyms --> <!-- maps openaire ids to their synonyms -->
<action name="map-openaire-to-doi"> <action name="map-openaire-to-doi">
<!-- This is required as a tag for spark jobs, regardless of programming language --> <!-- This is required as a tag for spark jobs, regardless of programming language -->
<spark xmlns="uri:oozie:spark-action:0.2"> <spark xmlns="uri:oozie:spark-action:0.2">
@ -526,7 +527,7 @@
</action> </action>
<!-- Script here written by Serafeim: maps openaire ids to their synonyms --> <!-- maps openaire ids to their synonyms -->
<action name="map-scores-to-dois"> <action name="map-scores-to-dois">
<!-- This is required as a tag for spark jobs, regardless of programming language --> <!-- This is required as a tag for spark jobs, regardless of programming language -->
<spark xmlns="uri:oozie:spark-action:0.2"> <spark xmlns="uri:oozie:spark-action:0.2">
@ -568,14 +569,14 @@
</spark> </spark>
<!-- Do this after finishing okay --> <!-- Do this after finishing okay -->
<ok to="deleteOutputPathForActionSet" /> <ok to="delete-output-path-for-actionset" />
<!-- This is the initial code <ok to="deleteOutputPathForActionSet" /> --> <!-- This is the initial code <ok to="delete-output-path-for-actionset" /> -->
<!-- Go there if we have an error --> <!-- Go there if we have an error -->
<error to="map-scores-fail" /> <error to="map-scores-fail" />
</action> </action>
<action name="deleteOutputPathForActionSet"> <action name="delete-output-path-for-actionset">
<fs> <fs>
<delete path="${actionSetOutputPath}/results/"/> <delete path="${actionSetOutputPath}/results/"/>
<delete path="${actionSetOutputPath}/projects/"/> <delete path="${actionSetOutputPath}/projects/"/>
@ -583,13 +584,13 @@
<mkdir path="${actionSetOutputPath}/results/"/> <mkdir path="${actionSetOutputPath}/results/"/>
<mkdir path="${actionSetOutputPath}/projects/"/> <mkdir path="${actionSetOutputPath}/projects/"/>
</fs> </fs>
<ok to="createActionSetForResults"/> <ok to="create-actionset-for-results"/>
<error to="actionset-delete-fail"/> <error to="actionset-delete-fail"/>
</action> </action>
<action name="createActionSetForResults"> <action name="create-actionset-for-results">
<spark xmlns="uri:oozie:spark-action:0.2"> <spark xmlns="uri:oozie:spark-action:0.2">
<master>yarn</master> <master>yarn-cluster</master>
<mode>cluster</mode> <mode>cluster</mode>
<name>Produces the atomic action with the bip finder scores for publications</name> <name>Produces the atomic action with the bip finder scores for publications</name>
<class>eu.dnetlib.dhp.actionmanager.bipfinder.SparkAtomicActionScoreJob</class> <class>eu.dnetlib.dhp.actionmanager.bipfinder.SparkAtomicActionScoreJob</class>
@ -640,7 +641,7 @@
<!-- Script arguments here --> <!-- Script arguments here -->
<!-- graph data folder from which to read relations --> <!-- graph data folder from which to read relations -->
<arg>${openaireDataInput}/relations</arg> <arg>${openaireDataInput}/relation</arg>
<!-- input files with impact indicators for results --> <!-- input files with impact indicators for results -->
<arg>${nameNode}/${workingDir}/${wf:actionData('get-file-names')['pr_file']}</arg> <arg>${nameNode}/${workingDir}/${wf:actionData('get-file-names')['pr_file']}</arg>
@ -658,16 +659,16 @@
</spark> </spark>
<!-- Do this after finishing okay --> <!-- Do this after finishing okay -->
<ok to="createActionSetForProjects" /> <ok to="create-actionset-for-projects" />
<!-- Go there if we have an error --> <!-- Go there if we have an error -->
<error to="project-impact-indicators-fail" /> <error to="project-impact-indicators-fail" />
</action> </action>
<action name="createActionSetForProjects"> <action name="create-actionset-for-projects">
<spark xmlns="uri:oozie:spark-action:0.2"> <spark xmlns="uri:oozie:spark-action:0.2">
<master>yarn</master> <master>yarn-cluster</master>
<mode>cluster</mode> <mode>cluster</mode>
<name>Produces the atomic action with the bip finder scores for projects</name> <name>Produces the atomic action with the bip finder scores for projects</name>
<class>eu.dnetlib.dhp.actionmanager.bipfinder.SparkAtomicActionScoreJob</class> <class>eu.dnetlib.dhp.actionmanager.bipfinder.SparkAtomicActionScoreJob</class>