Revision 53521
Added by Michele Artini over 5 years ago
modules/dnet-openaireplus-workflows/trunk/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/consistency/FindInvalidRepoProfilesJobNode.java | ||
---|---|---|
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.consistency; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Map; |
|
5 |
import java.util.concurrent.atomic.AtomicInteger; |
|
6 |
import java.util.stream.Collectors; |
|
7 |
|
|
8 |
import org.apache.commons.lang.StringUtils; |
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
import org.springframework.beans.factory.annotation.Autowired; |
|
12 |
|
|
13 |
import com.googlecode.sarasvati.Arc; |
|
14 |
import com.googlecode.sarasvati.NodeToken; |
|
15 |
|
|
16 |
import eu.dnetlib.enabling.datasources.LocalOpenaireDatasourceManager; |
|
17 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
|
18 |
import eu.dnetlib.enabling.is.registry.rmi.ISRegistryService; |
|
19 |
import eu.dnetlib.enabling.locators.UniqueServiceLocator; |
|
20 |
import eu.dnetlib.msro.workflows.nodes.ProgressJobNode; |
|
21 |
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode; |
|
22 |
import eu.dnetlib.msro.workflows.util.ProgressProvider; |
|
23 |
import eu.dnetlib.msro.workflows.util.WorkflowsConstants; |
|
24 |
|
|
25 |
public class FindInvalidRepoProfilesJobNode extends SimpleJobNode implements ProgressJobNode { |
|
26 |
|
|
27 |
@Autowired |
|
28 |
private LocalOpenaireDatasourceManager dsManager; |
|
29 |
|
|
30 |
@Autowired |
|
31 |
private UniqueServiceLocator serviceLocator; |
|
32 |
|
|
33 |
private int current = 0; |
|
34 |
private int total = 0; |
|
35 |
|
|
36 |
private boolean deleteInvalidProfiles = false; |
|
37 |
private boolean registerMissingProfiles = false; |
|
38 |
|
|
39 |
private static final Log log = LogFactory.getLog(FindInvalidRepoProfilesJobNode.class); |
|
40 |
|
|
41 |
@Override |
|
42 |
protected String execute(final NodeToken token) throws Exception { |
|
43 |
|
|
44 |
final Map<String, AtomicInteger> validIds = dsManager.listManagedDatasourceIds().stream().collect(Collectors.toMap(s -> s, s -> new AtomicInteger(0))); |
|
45 |
|
|
46 |
final List<String> list = serviceLocator.getService(ISLookUpService.class).quickSearchProfile( |
|
47 |
"for $x in collection('/db/DRIVER/RepositoryServiceResources/RepositoryServiceResourceType') return concat($x//DATASOURCE_ORIGINAL_ID, ' @@@ ', $x//RESOURCE_IDENTIFIER/@value)"); |
|
48 |
|
|
49 |
this.current = 0; |
|
50 |
this.total = list.size() + validIds.size(); |
|
51 |
int errorInvalidProfiles = 0; |
|
52 |
int errorUnregisteredProfiles = 0; |
|
53 |
int errorTooManyProfiles = 0; |
|
54 |
|
|
55 |
for (final String s : list) { |
|
56 |
current++; |
|
57 |
final String oid = StringUtils.substringBefore(s, "@@@").trim(); |
|
58 |
final String profId = StringUtils.substringAfter(s, "@@@").trim(); |
|
59 |
log.info("Evaluating ds: " + oid); |
|
60 |
if (validIds.containsKey(oid)) { |
|
61 |
validIds.get(oid).incrementAndGet(); |
|
62 |
} else { |
|
63 |
log.warn("Invalid profile " + profId + ", openaireId " + oid + " not registered properly"); |
|
64 |
errorInvalidProfiles++; |
|
65 |
// token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "invalidProfile:" + oid, profId); |
|
66 |
if (deleteInvalidProfiles) { |
|
67 |
log.warn(" - Deleting profile " + profId); |
|
68 |
serviceLocator.getService(ISRegistryService.class).deleteProfile(profId); |
|
69 |
} |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
for (final Map.Entry<String, AtomicInteger> e : validIds.entrySet()) { |
|
74 |
current++; |
|
75 |
final String dsId = e.getKey(); |
|
76 |
final int n = e.getValue().get(); |
|
77 |
if (n == 0) { |
|
78 |
errorUnregisteredProfiles++; |
|
79 |
// token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "unregisterdProfile:" + dsId, dsId); |
|
80 |
log.warn("Missing profile for ds " + dsId); |
|
81 |
if (registerMissingProfiles) { |
|
82 |
dsManager.setManaged(dsId, dsManager.isManaged(dsId)); // This command should regenerate the repo profile |
|
83 |
} |
|
84 |
} else if (n > 1) { |
|
85 |
errorTooManyProfiles++; |
|
86 |
log.error("Too many profiles registerd " + n + " for ds " + dsId); |
|
87 |
// token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "tooManyProfiles:" + dsId, n); |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "errorInvalidProfiles", errorInvalidProfiles); |
|
92 |
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "errorUnregisteredProfiles", errorUnregisteredProfiles); |
|
93 |
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + "errorTooManyProfiles", errorTooManyProfiles); |
|
94 |
|
|
95 |
return Arc.DEFAULT_ARC; |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public ProgressProvider getProgressProvider() { |
|
100 |
return new ProgressProvider() { |
|
101 |
|
|
102 |
@Override |
|
103 |
public int getTotalValue() { |
|
104 |
return total; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public int getCurrentValue() { |
|
109 |
return current; |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public boolean isInaccurate() { |
|
114 |
return false; |
|
115 |
} |
|
116 |
}; |
|
117 |
} |
|
118 |
|
|
119 |
public boolean isDeleteInvalidProfiles() { |
|
120 |
return deleteInvalidProfiles; |
|
121 |
} |
|
122 |
|
|
123 |
public void setDeleteInvalidProfiles(final boolean deleteInvalidProfiles) { |
|
124 |
this.deleteInvalidProfiles = deleteInvalidProfiles; |
|
125 |
} |
|
126 |
|
|
127 |
public boolean isRegisterMissingProfiles() { |
|
128 |
return registerMissingProfiles; |
|
129 |
} |
|
130 |
|
|
131 |
public void setRegisterMissingProfiles(final boolean registerMissingProfiles) { |
|
132 |
this.registerMissingProfiles = registerMissingProfiles; |
|
133 |
} |
|
134 |
} |
modules/dnet-openaireplus-workflows/trunk/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/consistency/FixRepoMdstoreSizesJobNode.java | ||
---|---|---|
108 | 108 |
} |
109 | 109 |
} catch (final Throwable e) { |
110 | 110 |
log.error("Error processing ds: " + dsId, e); |
111 |
token.getEnv().setAttribute(WorkflowsConstants.SYSTEM_ERROR + "::" + dsId, e.getMessage());
|
|
111 |
token.getEnv().setAttribute(WorkflowsConstants.MAIN_LOG_PREFIX + dsId, e.getMessage());
|
|
112 | 112 |
} |
113 | 113 |
} |
114 | 114 |
|
modules/dnet-openaireplus-workflows/trunk/src/main/resources/eu/dnetlib/test/profiles/openaireplus/workflows/consistency/findInvalidRepoProfiles.xml | ||
---|---|---|
1 |
<RESOURCE_PROFILE> |
|
2 |
<HEADER> |
|
3 |
<RESOURCE_IDENTIFIER value="e5bb911b-3fe2-403a-a757-6c1f89ff27e8_V29ya2Zsb3dEU1Jlc291cmNlcy9Xb3JrZmxvd0RTUmVzb3VyY2VUeXBl"/> |
|
4 |
<RESOURCE_TYPE value="WorkflowDSResourceType"/> |
|
5 |
<RESOURCE_KIND value="WorkflowDSResources"/> |
|
6 |
<RESOURCE_URI value=""/> |
|
7 |
<DATE_OF_CREATION value="2015-10-12T14:10:32+00:00"/> |
|
8 |
</HEADER> |
|
9 |
<BODY> |
|
10 |
<WORKFLOW_NAME>Find Invalid Repo Profiles</WORKFLOW_NAME> |
|
11 |
<WORKFLOW_TYPE>Consistency</WORKFLOW_TYPE> |
|
12 |
<WORKFLOW_PRIORITY>30</WORKFLOW_PRIORITY> |
|
13 |
<CONFIGURATION start="manual"> |
|
14 |
<NODE name="find" type="FindInvalidRepoProfiles" isStart="true"> |
|
15 |
<DESCRIPTION>Find Invalid Repo Profiles</DESCRIPTION> |
|
16 |
<PARAMETERS> |
|
17 |
<PARAM name="deleteInvalidProfiles" managedBy="user" required="true" type="boolean">false</PARAM> |
|
18 |
<PARAM name="registerMissingProfiles" managedBy="user" required="true" type="boolean">false</PARAM> |
|
19 |
</PARAMETERS> |
|
20 |
<ARCS> |
|
21 |
<ARC to="success"/> |
|
22 |
</ARCS> |
|
23 |
</NODE> |
|
24 |
</CONFIGURATION> |
|
25 |
<STATUS/> |
|
26 |
</BODY> |
|
27 |
</RESOURCE_PROFILE> |
modules/dnet-openaireplus-workflows/trunk/src/main/resources/eu/dnetlib/test/profiles/openaireplus/workflows/consistency/reposStoresConsistency.meta.xml | ||
---|---|---|
12 | 12 |
<METAWORKFLOW_SECTION>InfoSpace Consistency</METAWORKFLOW_SECTION> |
13 | 13 |
<ADMIN_EMAIL>michele.artini@isti.cnr.it</ADMIN_EMAIL> |
14 | 14 |
<CONFIGURATION status="EXECUTABLE"> |
15 |
<WORKFLOW id="3a5aea4a-cbeb-445e-b39a-52f40f42fa50_V29ya2Zsb3dEU1Jlc291cmNlcy9Xb3JrZmxvd0RTUmVzb3VyY2VUeXBl" name="Refresh Mdstore Sizes"> |
|
16 |
<WORKFLOW id="671e4507-3b0e-4318-8065-ddb856182e9f_V29ya2Zsb3dEU1Jlc291cmNlcy9Xb3JrZmxvd0RTUmVzb3VyY2VUeXBl" name="Repos-Stores consistency"/> |
|
15 |
<WORKFLOW id="e5bb911b-3fe2-403a-a757-6c1f89ff27e8_V29ya2Zsb3dEU1Jlc291cmNlcy9Xb3JrZmxvd0RTUmVzb3VyY2VUeXBl" name="Find Invalid Repo Profiles"> |
|
16 |
<WORKFLOW id="3a5aea4a-cbeb-445e-b39a-52f40f42fa50_V29ya2Zsb3dEU1Jlc291cmNlcy9Xb3JrZmxvd0RTUmVzb3VyY2VUeXBl" name="Refresh Mdstore Sizes"> |
|
17 |
<WORKFLOW id="671e4507-3b0e-4318-8065-ddb856182e9f_V29ya2Zsb3dEU1Jlc291cmNlcy9Xb3JrZmxvd0RTUmVzb3VyY2VUeXBl" name="Repos-Stores consistency"/> |
|
18 |
</WORKFLOW> |
|
17 | 19 |
</WORKFLOW> |
18 | 20 |
</CONFIGURATION> |
19 | 21 |
<SCHEDULING enabled="false"> |
modules/dnet-openaireplus-workflows/trunk/src/main/resources/eu/dnetlib/msro/openaireplus/workflows/applicationContext-msro-openaire-nodes.xml | ||
---|---|---|
326 | 326 |
class="eu.dnetlib.msro.openaireplus.workflows.nodes.consistency.VerifyMdStoreSizesJobNode" |
327 | 327 |
scope="prototype"/> |
328 | 328 |
|
329 |
<bean id="wfNodeFindInvalidRepoProfiles" |
|
330 |
class="eu.dnetlib.msro.openaireplus.workflows.nodes.consistency.FindInvalidRepoProfilesJobNode" |
|
331 |
scope="prototype"/> |
|
332 |
|
|
329 | 333 |
</beans> |
Also available in: Unified diff
Workflow to test invalid repo profiles