use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.
the class InMemoryProcessingFramework method submitCreate.
@Override
public void submitCreate(ProcessRequest<ProcessCreateItem> input) {
if (postProcessPlugins == null || postProcessPlugins.isEmpty()) {
LOGGER.debug("postProcessPlugins is empty. Not starting post process thread");
} else {
threadPool.submit(() -> {
ProcessRequest<ProcessCreateItem> request = input;
for (PostProcessPlugin plugin : postProcessPlugins) {
try {
request = plugin.processCreate(request);
} catch (PluginExecutionException e) {
LOGGER.debug("Unable to process create request through plugin: {}", plugin.getClass().getCanonicalName(), e);
}
}
storeProcessRequest(request);
closeInputStream(request);
});
}
}
use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.
the class AbstractFederationStrategy method federate.
@Override
public QueryResponse federate(List<Source> sources, final QueryRequest queryRequest) {
final String methodName = "federate";
LOGGER.trace("ENTERING: {}", methodName);
if (LOGGER.isDebugEnabled()) {
for (Source source : sources) {
if (source != null) {
LOGGER.debug("source to query: {}", source.getId());
}
}
}
Query originalQuery = queryRequest.getQuery();
int offset = originalQuery.getStartIndex();
final int pageSize = originalQuery.getPageSize();
// limit offset to max value
if (offset > this.maxStartIndex) {
offset = this.maxStartIndex;
}
final QueryResponseImpl queryResponseQueue = new QueryResponseImpl(queryRequest, null);
Map<Source, Future<SourceResponse>> futures = new HashMap<Source, Future<SourceResponse>>();
Query modifiedQuery = getModifiedQuery(originalQuery, sources.size(), offset, pageSize);
QueryRequest modifiedQueryRequest = new QueryRequestImpl(modifiedQuery, queryRequest.isEnterprise(), queryRequest.getSourceIds(), queryRequest.getProperties());
// Do NOT call source.isAvailable() when checking sources
for (final Source source : sources) {
if (source != null) {
if (!futures.containsKey(source)) {
LOGGER.debug("running query on source: {}", source.getId());
try {
for (PreFederatedQueryPlugin service : preQuery) {
try {
modifiedQueryRequest = service.process(source, modifiedQueryRequest);
} catch (PluginExecutionException e) {
LOGGER.info("Error executing PreFederatedQueryPlugin: ", e);
}
}
} catch (StopProcessingException e) {
LOGGER.info("Plugin stopped processing: ", e);
}
futures.put(source, queryExecutorService.submit(new CallableSourceResponse(source, modifiedQueryRequest.getQuery(), modifiedQueryRequest.getProperties())));
} else {
LOGGER.info("Duplicate source found with name {}. Ignoring second one.", source.getId());
}
}
}
QueryResponseImpl offsetResults = null;
// OffsetResultHandler does.
if (offset > 1 && sources.size() > 1) {
offsetResults = new QueryResponseImpl(queryRequest, null);
queryExecutorService.submit(new OffsetResultHandler(queryResponseQueue, offsetResults, pageSize, offset));
}
queryExecutorService.submit(createMonitor(queryExecutorService, futures, queryResponseQueue, modifiedQueryRequest.getQuery()));
QueryResponse queryResponse = null;
if (offset > 1 && sources.size() > 1) {
queryResponse = offsetResults;
LOGGER.debug("returning offsetResults");
} else {
queryResponse = queryResponseQueue;
LOGGER.debug("returning returnResults: {}", queryResponse);
}
try {
for (PostFederatedQueryPlugin service : postQuery) {
try {
queryResponse = service.process(queryResponse);
} catch (PluginExecutionException e) {
LOGGER.info("Error executing PostFederatedQueryPlugin: ", e);
}
}
} catch (StopProcessingException e) {
LOGGER.info("Plugin stopped processing: ", e);
}
LOGGER.debug("returning Query Results: {}", queryResponse);
LOGGER.trace("EXITING: {}.federate", CLASS_NAME);
return queryResponse;
}
use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.
the class DeliveryProcessor method process.
public void process(Event event) {
String methodName = "process";
LOGGER.debug("ENTERING: {}", methodName);
Metacard entry = (Metacard) event.getProperty(PubSubConstants.HEADER_ENTRY_KEY);
String operation = event.getProperty(PubSubConstants.HEADER_OPERATION_KEY).toString();
LOGGER.debug("Delivering catalog entry.");
if (subscription != null) {
if (entry != null) {
if (operation.equalsIgnoreCase(PubSubConstants.CREATE)) {
try {
for (PreDeliveryPlugin plugin : preDelivery) {
LOGGER.debug("Processing 'created' entry with preDelivery plugin");
entry = plugin.processCreate(entry);
}
subscription.getDeliveryMethod().created(entry);
} catch (PluginExecutionException e) {
LOGGER.debug("Plugin had exception during execution - still delivering the entry", e);
subscription.getDeliveryMethod().created(entry);
} catch (StopProcessingException e) {
LOGGER.info("Pre-delivery plugin determined entry cannot be delivered", e);
}
} else if (operation.equalsIgnoreCase(PubSubConstants.UPDATE)) {
// TODO: Handle hit or miss
try {
for (PreDeliveryPlugin plugin : preDelivery) {
LOGGER.debug("Processing 'updated' entry with preDelivery plugin");
Update updatedEntry = plugin.processUpdateHit(new UpdateImpl(entry, null));
entry = updatedEntry.getNewMetacard();
}
subscription.getDeliveryMethod().updatedHit(entry, entry);
} catch (PluginExecutionException e) {
LOGGER.debug("Plugin had exception during execution - still delivering the entry", e);
subscription.getDeliveryMethod().updatedHit(entry, entry);
} catch (StopProcessingException e) {
LOGGER.info("Pre-delivery plugin determined entry cannot be delivered", e);
}
} else if (operation.equalsIgnoreCase(PubSubConstants.DELETE)) {
try {
for (PreDeliveryPlugin plugin : preDelivery) {
LOGGER.debug("Processing 'deleted' entry with preDelivery plugin");
entry = plugin.processCreate(entry);
}
subscription.getDeliveryMethod().deleted(entry);
} catch (PluginExecutionException e) {
LOGGER.debug("Plugin had exception during execution - still delivering the entry", e);
subscription.getDeliveryMethod().deleted(entry);
} catch (StopProcessingException e) {
LOGGER.info("Pre-delivery plugin determined entry cannot be delivered", e);
}
} else {
LOGGER.debug("Could not deliver hit for subscription.");
}
} else {
LOGGER.debug("Could not deliver hit for subscription. Catalog entry is null.");
}
} else {
LOGGER.debug("Could not deliver hit for subscription. Subscription is null.");
}
LOGGER.debug("EXITING: {}", methodName);
}
use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.
the class RestReplicatorPlugin method process.
@Override
public UpdateResponse process(UpdateResponse input) throws PluginExecutionException {
if (Requests.isLocal(input.getRequest()) && client != null && transformer != null) {
WebClient updateClient = WebClient.fromClient(client);
updateClient.type(MediaType.APPLICATION_JSON);
List<Update> updates = input.getUpdatedMetacards();
if (updates == null) {
return input;
}
UpdateRequest request = input.getRequest();
if (request != null && !Metacard.ID.equals(request.getAttributeName())) {
throw new PluginExecutionException(new UnsupportedOperationException("Cannot replicate records that are not updated by " + Metacard.ID));
}
for (int i = 0; i < updates.size(); i++) {
Update update = updates.get(i);
if (request != null && request.getUpdates() != null && request.getUpdates().get(i) != null && request.getUpdates().get(i).getKey() != null) {
updateClient.path(request.getUpdates().get(i).getKey());
Metacard newMetacard = update.getNewMetacard();
String newData = transform(newMetacard, updateClient);
Response r = updateClient.put(newData);
LOGGER.debug("RESPONSE: [{}]", ToStringBuilder.reflectionToString(r));
}
}
}
return input;
}
use of ddf.catalog.plugin.PluginExecutionException in project ddf by codice.
the class Jpeg2000ThumbnailConverter method process.
@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
for (Result result : input.getResults()) {
Metacard metacard = result.getMetacard();
byte[] thumbnailBytes = metacard.getThumbnail();
if (thumbnailBytes == null) {
continue;
}
try (ByteArrayInputStream original = new ByteArrayInputStream(thumbnailBytes);
ByteArrayOutputStream converted = new ByteArrayOutputStream()) {
IISRandomAccessIO in = new IISRandomAccessIO(ImageIO.createImageInputStream(original));
if (in.length() == 0) {
continue;
}
// extracted from jj2000.j2k.fileformat.reader.FileFormatReader
if (in.readInt() != OTHER_JP2_SIGNATURE || in.readInt() != JP2_SIGNATURE_BOX || in.readInt() != OFFICIAL_JP2_SIGNATURE) {
// Not a JP2 file
in.seek(0);
if (in.readShort() != START_OF_CODESTREAM_MARKER) {
//Standard syntax marker found
continue;
}
}
// convert j2k thumbnail to jpeg thumbnail
original.reset();
BufferedImage thumbnail = ImageIO.read(original);
if (thumbnail == null) {
continue;
}
ImageIO.write(thumbnail, "jpeg", converted);
metacard.setAttribute(new AttributeImpl(Metacard.THUMBNAIL, converted.toByteArray()));
} catch (IOException e) {
throw new PluginExecutionException(e);
}
}
return input;
}
Aggregations