Search in sources :

Example 26 with Object

use of com.google.storage.v2.Object in project act-platform by mnemonic-no.

the class ObjectSearchDelegateTest method testSearchObjectsIncludeTimeFilterInStatisticsCriteria.

@Test
public void testSearchObjectsIncludeTimeFilterInStatisticsCriteria() throws Exception {
    int count = 3;
    when(objectFactDao.searchObjects(any())).thenReturn(createSearchResult(count));
    when(objectFactDao.calculateObjectStatistics(any())).thenReturn(ObjectStatisticsContainer.builder().build());
    SearchObjectRequest request = new SearchObjectRequest().setIncludeStatistics(true).setAfter(11111L).setBefore(22222L);
    ResultSet<Object> result = delegate.handle(request);
    assertEquals(count, result.getCount());
    assertEquals(count, ListUtils.list(result.iterator()).size());
    verify(objectFactDao).searchObjects(notNull());
    verify(objectFactDao).calculateObjectStatistics(argThat(criteria -> {
        assertEquals(request.getAfter(), criteria.getStartTimestamp());
        assertEquals(request.getBefore(), criteria.getEndTimestamp());
        return true;
    }));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) TiSecurityContext(no.mnemonic.act.platform.service.ti.TiSecurityContext) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) SearchObjectRequest(no.mnemonic.act.platform.api.request.v1.SearchObjectRequest) FactSearchCriteria(no.mnemonic.act.platform.dao.api.criteria.FactSearchCriteria) ObjectStatisticsContainer(no.mnemonic.act.platform.dao.api.result.ObjectStatisticsContainer) AccessControlCriteria(no.mnemonic.act.platform.dao.api.criteria.AccessControlCriteria) ObjectRecord(no.mnemonic.act.platform.dao.api.record.ObjectRecord) ArrayList(java.util.ArrayList) SearchObjectRequestConverter(no.mnemonic.act.platform.service.ti.converters.request.SearchObjectRequestConverter) Before(org.junit.Before) AccessDeniedException(no.mnemonic.act.platform.api.exceptions.AccessDeniedException) ResultSet(no.mnemonic.services.common.api.ResultSet) ObjectTypeByIdResponseResolver(no.mnemonic.act.platform.service.ti.resolvers.response.ObjectTypeByIdResponseResolver) ResultContainer(no.mnemonic.act.platform.dao.api.result.ResultContainer) TiFunctionConstants(no.mnemonic.act.platform.service.ti.TiFunctionConstants) Test(org.junit.Test) UUID(java.util.UUID) AccessControlCriteriaResolver(no.mnemonic.act.platform.service.ti.resolvers.AccessControlCriteriaResolver) FactTypeByIdResponseResolver(no.mnemonic.act.platform.service.ti.resolvers.response.FactTypeByIdResponseResolver) Mockito(org.mockito.Mockito) List(java.util.List) ObjectFactDao(no.mnemonic.act.platform.dao.api.ObjectFactDao) ListUtils(no.mnemonic.commons.utilities.collections.ListUtils) Assert(org.junit.Assert) Object(no.mnemonic.act.platform.api.model.v1.Object) Object(no.mnemonic.act.platform.api.model.v1.Object) SearchObjectRequest(no.mnemonic.act.platform.api.request.v1.SearchObjectRequest) Test(org.junit.Test)

Example 27 with Object

use of com.google.storage.v2.Object in project act-platform by mnemonic-no.

the class ObjectResponseConverterTest method testConvertWithStatistics.

@Test
public void testConvertWithStatistics() {
    ObjectResponseConverter converter = new ObjectResponseConverter(objectTypeConverter, factTypeConverter, id -> Collections.singleton(new ObjectStatisticsContainer.FactStatistic(UUID.randomUUID(), 42, 123456789, 987654321)));
    ObjectRecord record = createRecord();
    Object model = converter.apply(record);
    assertModel(record, model);
    assertEquals(1, model.getStatistics().size());
    assertNotNull(model.getStatistics().get(0).getType());
    assertEquals(42, model.getStatistics().get(0).getCount());
    assertEquals(123456789, (long) model.getStatistics().get(0).getLastAddedTimestamp());
    assertEquals(987654321, (long) model.getStatistics().get(0).getLastSeenTimestamp());
}
Also used : ObjectRecord(no.mnemonic.act.platform.dao.api.record.ObjectRecord) Object(no.mnemonic.act.platform.api.model.v1.Object) Test(org.junit.Test)

Example 28 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 29 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 30 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)

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