Search in sources :

Example 1 with PluginExecutionException

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);
        });
    }
}
Also used : PostProcessPlugin(org.codice.ddf.catalog.async.plugin.api.internal.PostProcessPlugin) ProcessCreateItem(org.codice.ddf.catalog.async.data.api.internal.ProcessCreateItem) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 2 with PluginExecutionException

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;
}
Also used : Query(ddf.catalog.operation.Query) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) PreFederatedQueryPlugin(ddf.catalog.plugin.PreFederatedQueryPlugin) HashMap(java.util.HashMap) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Source(ddf.catalog.source.Source) PostFederatedQueryPlugin(ddf.catalog.plugin.PostFederatedQueryPlugin) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Future(java.util.concurrent.Future) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 3 with PluginExecutionException

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);
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Metacard(ddf.catalog.data.Metacard) PreDeliveryPlugin(ddf.catalog.plugin.PreDeliveryPlugin) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Update(ddf.catalog.operation.Update) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 4 with PluginExecutionException

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;
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) Response(javax.ws.rs.core.Response) CreateResponse(ddf.catalog.operation.CreateResponse) UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) Update(ddf.catalog.operation.Update) WebClient(org.apache.cxf.jaxrs.client.WebClient) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 5 with PluginExecutionException

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IISRandomAccessIO(com.github.jaiimageio.jpeg2000.impl.IISRandomAccessIO) BufferedImage(java.awt.image.BufferedImage) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) Result(ddf.catalog.data.Result)

Aggregations

PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)18 Metacard (ddf.catalog.data.Metacard)7 QueryRequest (ddf.catalog.operation.QueryRequest)5 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)5 StopProcessingException (ddf.catalog.plugin.StopProcessingException)4 IOException (java.io.IOException)4 Query (ddf.catalog.operation.Query)3 QueryResponse (ddf.catalog.operation.QueryResponse)3 PreFederatedQueryPlugin (ddf.catalog.plugin.PreFederatedQueryPlugin)3 Source (ddf.catalog.source.Source)3 HashMap (java.util.HashMap)3 BinaryContent (ddf.catalog.data.BinaryContent)2 Result (ddf.catalog.data.Result)2 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)2 CopyFilterDelegate (ddf.catalog.filter.delegate.CopyFilterDelegate)2 SourceResponse (ddf.catalog.operation.SourceResponse)2 Update (ddf.catalog.operation.Update)2 UpdateRequest (ddf.catalog.operation.UpdateRequest)2 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)2