use of com.google.storage.v2.Object in project act-platform by mnemonic-no.
the class TraverseGraphDelegateTest method testTraverseGraphByObjectSearchWithoutSearchResult.
@Test
public void testTraverseGraphByObjectSearchWithoutSearchResult() throws Exception {
TraverseByObjectSearchRequest request = new TraverseByObjectSearchRequest();
when(objectSearch.handle(request)).thenReturn(StreamingResultSet.<Object>builder().build());
ResultSet<?> result = delegate.handle(request);
assertFalse(result.iterator().hasNext());
}
use of com.google.storage.v2.Object in project act-platform by mnemonic-no.
the class TraverseGraphDelegate method executeTraversal.
private void executeTraversal(Collection<UUID> startingObjects, String query) throws InvalidArgumentException, OperationTimeoutException {
try (Graph graph = createGraph();
GremlinExecutor executor = createExecutor()) {
// Create the first step of the graph traversal, i.e. starting the traversal at the Object(s) specified in the request.
// This is injected into the script execution as variable 'g'. Every query has to start from 'g'.
GraphTraversal<Vertex, Vertex> startingPoint = graph.traversal().V(startingObjects.toArray());
Map<String, java.lang.Object> bindings = MapUtils.map(T("g", startingPoint));
// Start script execution and wait until result arrived or execution is aborted.
// Use 'withResult' callback here because the graph will then be iterated inside the 'eval' thread, thus, every
// exception caused by the traversal will be handled inside that thread as well which will result in an ExecutionException.
executor.eval(query, SCRIPT_ENGINE, bindings, this::produceTraversalResult).get();
} catch (ExecutionException ex) {
// Exceptions causing the script execution to fail are wrapped inside an ExecutionException. Need to unwrap them.
Throwable cause = ObjectUtils.ifNull(ex.getCause(), ex);
// In both cases throw an own OperationTimeoutException in order to signal the timeout to the user.
if (cause instanceof TimeoutException) {
throw new OperationTimeoutException("The performed graph traversal query timed out.", "graph.traversal.timeout");
}
// e.g. invalid syntax, an unsupported operation such as 'addE()', or an operation not allowed by the sandbox.
throw new InvalidArgumentException().addValidationError(cause.getMessage(), "graph.traversal.failure", "query", query);
} catch (Exception ex) {
// Something bad happened, abort method.
throw new IllegalStateException("Could not perform graph traversal.", ex);
}
}
use of com.google.storage.v2.Object in project act-platform by mnemonic-no.
the class ObjectSearchDelegate method handle.
public ResultSet<Object> handle(SearchObjectRequest request) throws AccessDeniedException, AuthenticationFailedException, InvalidArgumentException {
securityContext.checkPermission(TiFunctionConstants.viewThreatIntelFact);
FactSearchCriteria criteria = requestConverter.apply(request);
if (criteria.isUnbounded()) {
throw new AccessDeniedException("Unbounded searches are not allowed. Specify at least one search parameter (in addition to 'limit').");
}
ResultContainer<ObjectRecord> searchResult = objectFactDao.searchObjects(criteria);
// Return search result and add statistics while iterating over the result.
return StreamingResultSet.<Object>builder().setCount(searchResult.getCount()).setLimit(criteria.getLimit()).setValues(new AddStatisticsIterator(searchResult, request)).build();
}
use of com.google.storage.v2.Object in project bgpcep by opendaylight.
the class StatefulPCReportMessageParser method validatePath.
private static boolean validatePath(final Queue<Object> objects, final List<Message> errors, final ReportsBuilder builder) {
final PathBuilder pBuilder = new PathBuilder();
Object object = objects.remove();
if (object instanceof Ero) {
pBuilder.setEro((Ero) object);
} else {
errors.add(createErrorMsg(PCEPErrors.ERO_MISSING, Optional.empty()));
return false;
}
parsePath(objects, pBuilder);
builder.setPath(pBuilder.build());
return true;
}
use of com.google.storage.v2.Object in project bgpcep by opendaylight.
the class StatefulPCReportMessageParser method getValidReports.
protected Reports getValidReports(final Queue<Object> objects, final List<Message> errors) {
final ReportsBuilder builder = new ReportsBuilder();
boolean lspViaSR = false;
Object object = objects.remove();
if (object instanceof Srp) {
final Srp srp = (Srp) object;
final Tlvs tlvs = srp.getTlvs();
if (tlvs != null) {
lspViaSR = PSTUtil.isDefaultPST(tlvs.getPathSetupType());
}
builder.setSrp(srp);
object = objects.poll();
}
if (validateLsp(object, lspViaSR, errors, builder)) {
if (!objects.isEmpty()) {
if (!validatePath(objects, errors, builder)) {
return null;
}
}
return builder.build();
}
return null;
}
Aggregations