Skip to content

Commit

Permalink
Manage non existent processes in check status end-points
Browse files Browse the repository at this point in the history
  • Loading branch information
josegar74 committed Oct 9, 2023
1 parent 2d47ff8 commit a57880e
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public WorkedDeterminedFinished determineIfWorkCompleted(String harvestId) {
}
}

public HarvestJob getById(String id) {
return harvestJobRepo.findById(id).get();
public Optional<HarvestJob> getById(String id) {
return harvestJobRepo.findById(id);
}

public Optional<HarvestJob> getLastCompletedHarvestJobIdByLongTermTag(String longTermTag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public List<Event> newEventProcessing() throws Exception {
List<Event> result = new ArrayList<>();
String harvestId = getInitiatingEvent().getHarvesterId();

HarvestJob harvestJob = harvestJobService.getById(harvestId);
HarvestJob harvestJob = harvestJobService.getById(harvestId).get();
List<EndpointJob> endpointJobs = harvestJobService.getEndpointJobs(harvestId);

for (EndpointJob job : endpointJobs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public EventProcessor_EndpointHarvestComplete internalProcessing() throws Except
boolean thisJobDone = job.getState() == EndpointJobState.RECORDS_RECEIVED;
allDone = allDone && thisJobDone;
}
HarvestJob harvestJob = harvestJobService.getById(getInitiatingEvent().getHarvestId());
HarvestJob harvestJob = harvestJobService.getById(getInitiatingEvent().getHarvestId()).get();
EndpointJob endpointJob = endpointJobService.getById(getInitiatingEvent().getEndPointId());
getRecordsResponseEvaluator.evaluate_duplicateUUIDs(harvestJob, endpointJob);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public EventProcessor_GetRecordsCommand externalProcessing() throws Exception {
//logger.debug("finish parse xml");

GetRecordsResponseInfo info = new GetRecordsResponseInfo(xmlParsed);
HarvestJob harvestJob = harvestJobService.getById(e.getHarvesterId());
HarvestJob harvestJob = harvestJobService.getById(e.getHarvesterId()).get();
EndpointJob endpointJob = endpointJobService.getById(e.getEndPointId());
RecordSet recordSet = recordSetService.getById(e.getRecordSetId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public EventProcessor_HarvestAbortEvent externalProcessing() {
public EventProcessor_HarvestAbortEvent internalProcessing() {
String processID = getInitiatingEvent().getProcessID();
logger.warn("attempting to user abort for " + processID);
HarvestJob job = harvestJobService.getById(processID);
HarvestJob job = harvestJobService.getById(processID).get();
if ((job.getState() != HarvestJobState.COMPLETE)
&& (job.getState() != HarvestJobState.ERROR)
&& (job.getState() != HarvestJobState.USERABORT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public class HarvestStatus {
public List<EndpointStatus> endpoints;


private HarvestStatus(String processID) {
this.processID = processID;
endpoints = new ArrayList<>();
stackTraces = new ArrayList<>();
errorMessage = new ArrayList<>();
}

public HarvestStatus(HarvestJob job) {
this.processID = job.getJobId();
this.url = job.getInitialUrl();
Expand All @@ -29,4 +36,10 @@ public HarvestStatus(HarvestJob job) {
stackTraces = new ArrayList<>();
errorMessage = new ArrayList<>();
}

public static HarvestStatus createHarvestStatusNoProcessId(String processID) {
HarvestStatus harvestStatus = new HarvestStatus(processID);
harvestStatus.errorMessage.add(String.format("Harvester with processID %s doesn't exist", processID));
return harvestStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

@Component
Expand All @@ -43,19 +41,30 @@ public class GetStatusService {
LogbackLoggingEventExceptionRepo logbackLoggingEventExceptionRepo;

public HarvestStatus getStatus(String processId, Boolean quick) {
if (quick == null)
if (quick == null) {
quick = DEFAULT_QUICK;
HarvestJob job = harvestJobService.getById(processId);
List<EndpointJob> endpointJobs = endpointJobService.findAll(processId);

HarvestStatus result = new HarvestStatus(job);
if (!quick) {
setupErrorMessages(result);
for (EndpointJob endpointJob : endpointJobs) {
long numberReceived = computeNumberReceived(endpointJob);
result.endpoints.add(new EndpointStatus(endpointJob, (int) numberReceived));
}

HarvestStatus result;

Optional<HarvestJob> jobOptional = harvestJobService.getById(processId);

if (jobOptional.isPresent()) {
List<EndpointJob> endpointJobs = endpointJobService.findAll(processId);

result = new HarvestStatus(jobOptional.get());
if (!quick) {
setupErrorMessages(result);
for (EndpointJob endpointJob : endpointJobs) {
long numberReceived = computeNumberReceived(endpointJob);
result.endpoints.add(new EndpointStatus(endpointJob, (int) numberReceived));
}
}
} else {
result = HarvestStatus.createHarvestStatusNoProcessId(processId);
}


return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.geocat.ingester.model.ingester;


import java.util.ArrayList;
import java.util.List;

public class IngestStatus {
public String processID;
public String harvesterJobId;
Expand All @@ -11,6 +14,13 @@ public class IngestStatus {
public long numberOfRecordsIngested;
public long numberOfRecordsIndexed;

public List<String> errorMessage;

private IngestStatus(String processID) {
this.processID = processID;
errorMessage = new ArrayList<>();
}

public IngestStatus(IngestJob job) {
this.processID = job.getJobId();
this.totalRecords = (job.getTotalRecords() == null ? 0 : job.getTotalRecords());
Expand All @@ -20,5 +30,12 @@ public IngestStatus(IngestJob job) {
this.state = job.getState().toString();
this.createTimeUTC = job.getCreateTimeUTC().toInstant().toString();
this.lastUpdateUTC = job.getLastUpdateUTC().toInstant().toString();
this.errorMessage = new ArrayList<>();
}

public static IngestStatus createIngestStatusNoProcessId(String processID) {
IngestStatus ingestStatus = new IngestStatus(processID);
ingestStatus.errorMessage.add(String.format("Ingester with processID %s doesn't exist", processID));
return ingestStatus;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
@Scope("prototype")
public class GetStatusService {
Expand All @@ -14,9 +16,15 @@ public class GetStatusService {
IngestJobService ingestJobService;

public IngestStatus getStatus(String processId) {
IngestJob job = ingestJobService.getById(processId);
Optional<IngestJob> jobOptional = ingestJobService.getById(processId);

IngestStatus result;

IngestStatus result = new IngestStatus(job);
if (jobOptional.isPresent()) {
result = new IngestStatus(jobOptional.get());
} else {
result = IngestStatus.createIngestStatusNoProcessId(processId);
}

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public IngestJob updateIngestJobStateInDBDeletedRecords(String guid, long totalD
return ingestJobRepo.save(job);
}

public IngestJob getById(String id) {
return ingestJobRepo.findById(id).get();
public Optional<IngestJob> getById(String id) {
return ingestJobRepo.findById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
package net.geocat.service;

import net.geocat.database.linkchecker.entities.LinkCheckJob;
import net.geocat.database.linkchecker.entities.LinkCheckJobState;
import net.geocat.database.linkchecker.entities.helper.LogbackLoggingEvent;
import net.geocat.database.linkchecker.entities.helper.LogbackLoggingEventException;
import net.geocat.database.linkchecker.entities.helper.StatusQueryItem;
Expand All @@ -45,10 +46,7 @@
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

@Component
Expand Down Expand Up @@ -77,19 +75,33 @@ public class GetStatusService {

public LinkCheckStatus getStatus(String processID, Boolean showErrors, Boolean quick) throws Exception {
try {
if (quick == null)
if (quick == null) {
quick = DEFAULT_QUICK;
}
showErrors = showErrors == null ? false : showErrors;
LinkCheckJob job = linkCheckJobRepo.findById(processID).get();

LinkCheckStatus result = new LinkCheckStatus(processID, job.getState());
if (!quick) {
result.setServiceRecordStatus(computeServiceRecords(processID));
result.setDatasetRecordStatus(computeDatasetRecords(processID));
Optional<LinkCheckJob> jobOptional = linkCheckJobRepo.findById(processID);

LinkCheckStatus result;

if (jobOptional.isPresent()) {
LinkCheckJob job = jobOptional.get();

result = new LinkCheckStatus(processID, job.getState());

if (!quick) {
result.setServiceRecordStatus(computeServiceRecords(processID));
result.setDatasetRecordStatus(computeDatasetRecords(processID));
}

if (showErrors) {
setupErrorMessages(result);
}
} else {
result = new LinkCheckStatus(processID, LinkCheckJobState.ERROR);
result.errorMessage.add(String.format("Harvester with processID %s doesn't exist", processID));
}

if (showErrors)
setupErrorMessages(result);
return result;
} catch (Exception e) {
throw new Exception("Linkchecker - GetStatusService#getStatus threw error for processID=" + processID + ", showErrors=" + showErrors + ", quick=" + quick);
Expand Down

0 comments on commit a57880e

Please sign in to comment.