-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* better handle cache related operations * basic testing to ensure named ops work * sonar smells * whitespace * add option to let results stay separate #3118 * add option to specify to use default graph ids * typo * check style --------- Co-authored-by: p29876 <165825455+p29876@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
375 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...in/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/EitherOperationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2024 Crown Copyright | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.gchq.gaffer.federated.simple.operation.handler; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import uk.gov.gchq.gaffer.operation.Operation; | ||
import uk.gov.gchq.gaffer.operation.OperationException; | ||
import uk.gov.gchq.gaffer.store.Context; | ||
import uk.gov.gchq.gaffer.store.Store; | ||
import uk.gov.gchq.gaffer.store.operation.handler.OperationHandler; | ||
|
||
/** | ||
* Custom handler for operations that could in theory target sub graphs or the | ||
* federated store directly. | ||
*/ | ||
public class EitherOperationHandler<O extends Operation> implements OperationHandler<O> { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(EitherOperationHandler.class); | ||
|
||
private final OperationHandler<O> standardHandler; | ||
|
||
public EitherOperationHandler(final OperationHandler<O> standardHandler) { | ||
this.standardHandler = standardHandler; | ||
} | ||
|
||
/** | ||
* If graph IDs are in the options the operation will be handled by a | ||
* {@link FederatedOperationHandler}, otherwise the original handler will be | ||
* used e.g. executed on the federated store directly. | ||
*/ | ||
@Override | ||
public Object doOperation(final O operation, final Context context, final Store store) throws OperationException { | ||
LOGGER.debug("Checking if Operation should be handled locally or on sub graphs: {}", operation); | ||
|
||
// If we have graph IDs then run as a federated operation | ||
if (operation.containsOption(FederatedOperationHandler.OPT_GRAPH_IDS) || | ||
operation.containsOption(FederatedOperationHandler.OPT_SHORT_GRAPH_IDS) || | ||
operation.containsOption(FederatedOperationHandler.OPT_EXCLUDE_GRAPH_IDS) || | ||
operation.containsOption(FederatedOperationHandler.OPT_USE_DFLT_GRAPH_IDS)) { | ||
LOGGER.debug("Operation has specified graph IDs, it will be handled by sub graphs"); | ||
return new FederatedOperationHandler<>().doOperation(operation, context, store); | ||
} | ||
|
||
// No sub graphs involved just run the handler for this operations on the federated store | ||
return standardHandler.doOperation(operation, context, store); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ain/java/uk/gov/gchq/gaffer/federated/simple/operation/handler/SeparateOutputHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2024 Crown Copyright | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uk.gov.gchq.gaffer.federated.simple.operation.handler; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import uk.gov.gchq.gaffer.federated.simple.FederatedStore; | ||
import uk.gov.gchq.gaffer.graph.GraphSerialisable; | ||
import uk.gov.gchq.gaffer.operation.OperationException; | ||
import uk.gov.gchq.gaffer.operation.io.Output; | ||
import uk.gov.gchq.gaffer.store.Context; | ||
import uk.gov.gchq.gaffer.store.Store; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Handler for running federated operations but keeping the results separate | ||
* under a key of the graph ID the results come from. | ||
*/ | ||
public class SeparateOutputHandler<P extends Output<O>, O> extends FederatedOperationHandler<P> { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(SeparateOutputHandler.class); | ||
|
||
@Override | ||
public Map<String, O> doOperation(final P operation, final Context context, final Store store) throws OperationException { | ||
List<GraphSerialisable> graphsToExecute = this.getGraphsToExecuteOn(operation, context, (FederatedStore) store); | ||
|
||
if (graphsToExecute.isEmpty()) { | ||
return new HashMap<>(); | ||
} | ||
|
||
// Execute the operation chain on each graph | ||
LOGGER.debug("Returning separated graph results"); | ||
Map<String, O> results = new HashMap<>(); | ||
for (final GraphSerialisable gs : graphsToExecute) { | ||
try { | ||
results.put(gs.getGraphId(), gs.getGraph().execute(operation, context.getUser())); | ||
} catch (final OperationException | UnsupportedOperationException e) { | ||
// Optionally skip this error if user has specified to do so | ||
LOGGER.error("Operation failed on graph: {}", gs.getGraphId()); | ||
if (!Boolean.parseBoolean(operation.getOption(OPT_SKIP_FAILED_EXECUTE, "false"))) { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
} |
Oops, something went wrong.