Search in sources :

Example 21 with Object

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());
}
Also used : TraverseByObjectSearchRequest(no.mnemonic.act.platform.api.request.v1.TraverseByObjectSearchRequest) Object(no.mnemonic.act.platform.api.model.v1.Object) Test(org.junit.Test)

Example 22 with Object

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);
    }
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ObjectVertex(no.mnemonic.act.platform.dao.tinkerpop.ObjectVertex) OperationTimeoutException(no.mnemonic.act.platform.api.exceptions.OperationTimeoutException) GremlinExecutor(org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor) TimeoutException(java.util.concurrent.TimeoutException) InvalidArgumentException(no.mnemonic.act.platform.api.exceptions.InvalidArgumentException) AccessDeniedException(no.mnemonic.act.platform.api.exceptions.AccessDeniedException) AuthenticationFailedException(no.mnemonic.act.platform.api.exceptions.AuthenticationFailedException) ExecutionException(java.util.concurrent.ExecutionException) OperationTimeoutException(no.mnemonic.act.platform.api.exceptions.OperationTimeoutException) Graph(org.apache.tinkerpop.gremlin.structure.Graph) ActGraph(no.mnemonic.act.platform.dao.tinkerpop.ActGraph) InvalidArgumentException(no.mnemonic.act.platform.api.exceptions.InvalidArgumentException) Object(no.mnemonic.act.platform.api.model.v1.Object) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) OperationTimeoutException(no.mnemonic.act.platform.api.exceptions.OperationTimeoutException)

Example 23 with Object

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();
}
Also used : AccessDeniedException(no.mnemonic.act.platform.api.exceptions.AccessDeniedException) ObjectRecord(no.mnemonic.act.platform.dao.api.record.ObjectRecord) Object(no.mnemonic.act.platform.api.model.v1.Object) FactSearchCriteria(no.mnemonic.act.platform.dao.api.criteria.FactSearchCriteria)

Example 24 with Object

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;
}
Also used : PathBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.pcrpt.message.reports.PathBuilder) Ero(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)

Example 25 with Object

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;
}
Also used : Srp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.srp.object.Srp) Tlvs(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.srp.object.srp.Tlvs) ReportsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcrpt.message.pcrpt.message.ReportsBuilder) Object(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)

Aggregations

Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)33 ArrayList (java.util.ArrayList)25 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object)18 StorageClient (com.google.storage.v2.StorageClient)16 Object (com.google.storage.v2.Object)12 Test (org.junit.Test)12 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)12 VendorInformationObject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject)12 Object (no.mnemonic.act.platform.api.model.v1.Object)8 Preconditions (com.google.common.base.Preconditions)6 ObjectRecord (no.mnemonic.act.platform.dao.api.record.ObjectRecord)6 Metrics (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.Metrics)6 Metrics (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.Metrics)5 Ero (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero)5 AbstractMessage (com.google.protobuf.AbstractMessage)4 ByteString (com.google.protobuf.ByteString)4 PCEPErrors (org.opendaylight.protocol.pcep.spi.PCEPErrors)4 UnknownObject (org.opendaylight.protocol.pcep.spi.UnknownObject)4 Lsp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp)4 ListObjectsPagedResponse (com.google.storage.v2.StorageClient.ListObjectsPagedResponse)3