Skip to content
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

MBean registration / Ignore existing #5670

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public ServletPathFinder(ServletContext servletContext) {
baseUrl = resource.substring(resource.indexOf('/', 1), resource.length() - 1);
} catch (java.net.MalformedURLException e) { // unlikely
baseUrl = servletContext.getServletContextName();
} catch (NullPointerException e) { // in test using GeonetMockServletContext
baseUrl = "/";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public MetadataIndexerProcessor(DataManager dm) {
this.dm = dm;
}

public abstract void process() throws Exception;
public abstract void process(String catalogueId) throws Exception;

protected DataManager getDataManager() {
return dm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void synchronizeDbWithIndex(ServiceContext context, Boolean force, Boolea
Set<Integer> integerList = toIndex.stream().map(Integer::parseInt).collect(Collectors.toSet());
new BatchOpsMetadataReindexer(
context.getBean(DataManager.class),
integerList).process(false);
integerList).process(settingManager.getSiteId(), false);
} else {
metadataIndexer.batchIndexInThreadPool(context, toIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,19 @@ public int getInError() {
return inError.intValue();
}

public void process(boolean runInCurrentThread) throws Exception {
wrapAsyncProcess(runInCurrentThread);
public void process(String catalogueId, boolean runInCurrentThread) throws Exception {
wrapAsyncProcess(catalogueId, runInCurrentThread);
allCompleted.get();
}

public void process() throws Exception {
process(false);
public void process(String catalogueId) throws Exception {
process(catalogueId, false);
}

public String wrapAsyncProcess(boolean runInCurrentThread) throws Exception {
probeName = new ObjectName(String.format("geonetwork:name=indexing-task,idx=%s", this.hashCode()));
public String wrapAsyncProcess(String catalogueId, boolean runInCurrentThread) throws Exception {
probeName = new ObjectName(String.format(
"geonetwork-%s:name=indexing-task,idx=%s",
catalogueId, this.hashCode()));
exporter.registerManagedResource(this, probeName);
return processAsync(runInCurrentThread);
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/resources/config-spring-geonetwork.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="namingStrategy" ref="namingStrategy"/>
<property name="registrationPolicy" value="IGNORE_EXISTING"/>
</bean>

<bean id="namingStrategy"
class="org.springframework.jmx.export.naming.KeyNamingStrategy">
<property name="mappings">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ public HarvestWithIndexProcessor(DataManager dm, Logger logger) {
}

@Override
public void process() throws Exception {
public void process(String catalogueId) throws Exception {
doHarvest(logger);
}
}
Expand Down Expand Up @@ -673,7 +673,7 @@ protected OperResult harvest() {
logger.info("Started harvesting from node : " + nodeName);
HarvestWithIndexProcessor h = new HarvestWithIndexProcessor(dataMan, logger);
// todo check (was: processwithfastindexing)
h.process();
h.process(settingManager.getSiteId());
logger.info("Ended harvesting from node : " + nodeName);

if (getParams().isOneRunOnly()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ public class EmptySlot implements SelfNaming {

private ObjectName objectName;

public EmptySlot(int i) {
public EmptySlot(String catalogueId, int i) {
try {
objectName = new ObjectName(String.format("geonetwork:name=url-check,idx=empty-slot-%d", i));
objectName = new ObjectName(String.format(
"geonetwork-%s:name=url-check,idx=empty-slot-%d",
catalogueId, i));
} catch (MalformedObjectNameException e) {
e.printStackTrace();
}
Expand All @@ -23,4 +25,4 @@ public EmptySlot(int i) {
public ObjectName getObjectName() throws MalformedObjectNameException {
return objectName;
}
}
}
11 changes: 9 additions & 2 deletions services/src/main/java/org/fao/geonet/api/links/LinksApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.fao.geonet.kernel.AccessManager;
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.datamanager.IMetadataUtils;
import org.fao.geonet.kernel.setting.SettingManager;
import org.fao.geonet.kernel.url.UrlAnalyzer;
import org.fao.geonet.repository.LinkRepository;
import org.fao.geonet.repository.MetadataRepository;
Expand Down Expand Up @@ -105,13 +106,15 @@ public class LinksApi {
MBeanExporter mBeanExporter;
@Autowired
AccessManager accessManager;
@Autowired
SettingManager settingManager;

private ArrayDeque<SelfNaming> mAnalyseProcesses = new ArrayDeque<>(NUMBER_OF_SUBSEQUENT_PROCESS_MBEAN_TO_KEEP);

@PostConstruct
public void iniMBeansSlidingWindowWithEmptySlot() {
for (int i = 0; i < NUMBER_OF_SUBSEQUENT_PROCESS_MBEAN_TO_KEEP; i++) {
EmptySlot emptySlot = new EmptySlot(i);
EmptySlot emptySlot = new EmptySlot(settingManager.getSiteId(), i);
mAnalyseProcesses.addFirst(emptySlot);
try {
mBeanExporter.registerManagedResource(emptySlot, emptySlot.getObjectName());
Expand Down Expand Up @@ -364,7 +367,11 @@ public ResponseEntity purgeAll() throws IOException, JDOMException {
}

private MAnalyseProcess getRegistredMAnalyseProcess() {
MAnalyseProcess mAnalyseProcess = new MAnalyseProcess(linkRepository, metadataRepository, urlAnalyser, appContext);
MAnalyseProcess mAnalyseProcess = new MAnalyseProcess(
settingManager.getSiteId(),
linkRepository,
metadataRepository,
urlAnalyser, appContext);
mBeanExporter.registerManagedResource(mAnalyseProcess, mAnalyseProcess.getObjectName());
try {
mBeanExporter.unregisterManagedResource(mAnalyseProcesses.removeLast().getObjectName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ public class MAnalyseProcess implements SelfNaming {
private long testLinkDate = Long.MAX_VALUE;


public MAnalyseProcess(LinkRepository linkRepository, MetadataRepository metadataRepository, UrlAnalyzer urlAnalyser, ApplicationContext appContext) {
public MAnalyseProcess(String catalogueId,
LinkRepository linkRepository,
MetadataRepository metadataRepository,
UrlAnalyzer urlAnalyser,
ApplicationContext appContext) {
this.linkRepository = linkRepository;
this.metadataRepository = metadataRepository;
this.urlAnalyser = urlAnalyser;
this.appContext = appContext;
try {
this.probeName = new ObjectName(String.format("geonetwork:name=url-check,idx=%s", this.hashCode()));
this.probeName = new ObjectName(String.format("geonetwork-%s:name=url-check,idx=%s", catalogueId, this.hashCode()));
} catch (MalformedObjectNameException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class EmptySlotBatch implements SelfNaming {

public EmptySlotBatch(String name, int i) {
try {
objectName = new ObjectName(String.format("geonetwork:name=%s,idx=empty-slot-%d", name, i));
objectName = new ObjectName(String.format("geonetwork-%s:idx=empty-slot-%d", name, i));
} catch (MalformedObjectNameException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,18 @@ public class MInspireEtfValidateProcess implements SelfNaming {
private long analyseMdDate = Long.MAX_VALUE;


public MInspireEtfValidateProcess(String URL,
ServiceContext serviceContext, ApplicationContext appContext) {
public MInspireEtfValidateProcess(String catalogueId,
String URL,
ServiceContext serviceContext,
ApplicationContext appContext) {
this.URL = URL;
this.serviceContext = serviceContext;
this.appContext = appContext;

try {
this.probeName = new ObjectName(String.format("geonetwork:name=batch-etf-inspire,idx=%s", this.hashCode()));
this.probeName = new ObjectName(String.format(
"geonetwork-%s:name=batch-etf-inspire,idx=%s",
catalogueId, this.hashCode()));
} catch (MalformedObjectNameException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public MetadataSearchAndReplace(DataManager dm,
}

@Override
public void process() throws Exception {
public void process(String catalogueId) throws Exception {
GeonetContext gc = (GeonetContext) context
.getHandlerContext(Geonet.CONTEXT_NAME);
DataManager dm = gc.getBean(DataManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.fao.geonet.api.processing.report.ProcessingReport;
import org.fao.geonet.api.processing.report.registry.IProcessingReportRegistry;
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.setting.SettingManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -64,6 +65,9 @@ public class ProcessApi {
@Autowired
DataManager dataMan;

@Autowired
SettingManager settingManager;

@io.swagger.v3.oas.annotations.Operation(
summary = "Get current process reports",
description = "When processing, the report is stored in memory and allows to retrieve " +
Expand Down Expand Up @@ -184,7 +188,7 @@ public MetadataReplacementProcessingReport searchAndReplace(
isTesting, isCaseInsensitive, vacuumMode,
allParams,
ApiUtils.createServiceContext(request), records, report);
m.process();
m.process(settingManager.getSiteId());
} catch (Exception e) {
throw e;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public SimpleMetadataProcessingReport validateRecords(

// index records
BatchOpsMetadataReindexer r = new BatchOpsMetadataReindexer(dataMan, report.getMetadata());
r.process(true);
r.process(settingManager.getSiteId(), true);
} catch (Exception e) {
throw e;
} finally {
Expand Down Expand Up @@ -278,7 +278,7 @@ public SimpleMetadataProcessingReport cleanValidationStatus(

// index records
BatchOpsMetadataReindexer r = new BatchOpsMetadataReindexer(dataMan, report.getMetadata());
r.process(true);
r.process(settingManager.getSiteId(), true);
} catch (Exception e) {
throw e;
} finally {
Expand Down Expand Up @@ -344,7 +344,7 @@ public ResponseEntity validateRecordsInspire(
private MInspireEtfValidateProcess getRegistredMInspireEtfValidateProcess(ServiceContext serviceContext) {
String URL = settingManager.getValue(Settings.SYSTEM_INSPIRE_REMOTE_VALIDATION_URL);

MInspireEtfValidateProcess mAnalyseProcess = new MInspireEtfValidateProcess(URL, serviceContext, appContext);
MInspireEtfValidateProcess mAnalyseProcess = new MInspireEtfValidateProcess(settingManager.getSiteId(), URL, serviceContext, appContext);
mBeanExporter.registerManagedResource(mAnalyseProcess, mAnalyseProcess.getObjectName());
try {
mBeanExporter.unregisterManagedResource(mAnalyseProcesses.removeLast().getObjectName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.MetadataIndexerProcessor;
import org.fao.geonet.kernel.SchemaManager;
import org.fao.geonet.kernel.setting.SettingManager;
import org.fao.geonet.utils.Log;
import org.fao.geonet.utils.Xml;
import org.jdom.Element;
Expand Down Expand Up @@ -94,6 +95,9 @@ public class XslProcessApi {
@Autowired
SchemaManager schemaMan;

@Autowired
SettingManager settingManager;

@io.swagger.v3.oas.annotations.Operation(
summary = "Preview process result applied to one or more records",
description = ApiParams.API_OP_NOTE_PROCESS_PREVIEW +
Expand Down Expand Up @@ -299,7 +303,7 @@ public XsltMetadataProcessingReport processRecords(
ApiUtils.createServiceContext(request),
dataMan, records, process, httpSession, siteURL,
xslProcessingReport, request, index, updateDateStamp, userSession.getUserIdAsInt());
m.process();
m.process(settingManager.getSiteId());

} catch (Exception exception) {
xslProcessingReport.addError(exception);
Expand Down Expand Up @@ -346,7 +350,7 @@ public BatchXslMetadataReindexer(ServiceContext context,
}

@Override
public void process() throws Exception {
public void process(String catalogueId) throws Exception {
DataManager dataMan = context.getBean(DataManager.class);
ApplicationContext appContext = ApplicationContextHolder.get();
for (String uuid : this.records) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.fao.geonet.kernel.DataManager;
import org.fao.geonet.kernel.SelectionManager;
import org.fao.geonet.kernel.search.index.BatchOpsMetadataReindexer;
import org.fao.geonet.kernel.setting.SettingManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -62,6 +63,9 @@ public class MetadataIndexApi {
@Autowired
DataManager dataManager;

@Autowired
SettingManager settingManager;

@io.swagger.v3.oas.annotations.Operation(
summary = "Index a set of records",
description = "Index a set of records provided either by a bucket or a list of uuids")
Expand Down Expand Up @@ -123,7 +127,8 @@ JSONObject index(
}
}
index = ids.size();
new BatchOpsMetadataReindexer(dataManager, ids).process(false);
new BatchOpsMetadataReindexer(dataManager, ids)
.process(settingManager.getSiteId(), false);

JSONObject res = new JSONObject();
res.put("success", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private ResponseEntity<Object> collectEntries(
if (save) {
dataManager.flush();
BatchOpsMetadataReindexer r = new BatchOpsMetadataReindexer(dataManager, listOfEntriesInternalId);
r.process();
r.process(settingManager.getSiteId());
report.close();
return new ResponseEntity<>(report, HttpStatus.CREATED);
} else {
Expand Down Expand Up @@ -496,7 +496,7 @@ private ResponseEntity<Object> updateRecordEntries(
dataManager.flush();
BatchOpsMetadataReindexer r =
new BatchOpsMetadataReindexer(dataManager, listOfRecordInternalId);
r.process();
r.process(settingManager.getSiteId());
report.close();
return new ResponseEntity<>(report, HttpStatus.CREATED);
} else {
Expand Down Expand Up @@ -714,7 +714,7 @@ public SimpleMetadataProcessingReport importSpatialEntries(
));

BatchOpsMetadataReindexer r = new BatchOpsMetadataReindexer(dataManager, listOfRecordInternalId);
r.process();
r.process(settingManager.getSiteId());

errors.forEach((k, v) ->
report.addError(v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void syncMonoThread() throws Exception {
Set<Integer> toIndex = createMetadataToIndex();

BatchOpsMetadataReindexer toTest = new BatchOpsMetadataReindexer(mockDataMan, toIndex);
toTest.process(false);
toTest.process("siteId", false);

ArgumentCaptor<String> metadataIdCaptor = captureIndexationLaunched(mockDataMan);
assertEquals("1-2-3-4", metadataIdCaptor.getAllValues().stream().collect(Collectors.joining("-")));
Expand All @@ -56,7 +56,7 @@ public void syncMultiThread() throws Exception {
Set<Integer> toIndex = createMetadataToIndex();

BatchOpsMetadataReindexer toTest = new BatchOpsMetadataReindexer(mockDataMan, toIndex);
toTest.process(false);
toTest.process("siteId", false);

ArgumentCaptor<String> metadataIdCaptor = captureIndexationLaunched(mockDataMan);
assertEquals("1-2-3-4", metadataIdCaptor.getAllValues().stream().sorted().collect(Collectors.joining("-")));
Expand All @@ -72,7 +72,7 @@ public void syncManyThreadButRunInCurrent() throws Exception {
Set<Integer> toIndex = createMetadataToIndex();

BatchOpsMetadataReindexer toTest = new BatchOpsMetadataReindexer(mockDataMan, toIndex);
toTest.process(true);
toTest.process("siteId", true);

ArgumentCaptor<String> metadataIdCaptor = captureIndexationLaunched(mockDataMan);
assertEquals("1-2-3-4", metadataIdCaptor.getAllValues().stream().sorted().collect(Collectors.joining("-")));
Expand All @@ -93,7 +93,7 @@ public void asyncMonoThread() throws Exception {
assertEquals(0, toTest.getProcessed());
assertEquals(4, toTest.getToProcessCount());

toTest.wrapAsyncProcess(false);
toTest.wrapAsyncProcess("siteId", false);

latch.countDown();
Thread.sleep(500);
Expand All @@ -118,7 +118,7 @@ public void asyncMultiThread() throws Exception {

assertEquals(0, toTest.getProcessed());
assertEquals(4, toTest.getToProcessCount());
toTest.wrapAsyncProcess(false);
toTest.wrapAsyncProcess("siteId",false);

latch.countDown();
Thread.sleep(500);
Expand All @@ -143,7 +143,7 @@ public void asyncManyThreadButRunInCurrent() throws Exception {
@Override
public void run() {
try {
toTest.wrapAsyncProcess(true);
toTest.wrapAsyncProcess("siteId",true);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Loading