Search in sources :

Example 31 with StreamInput

use of org.opensearch.common.io.stream.StreamInput in project anomaly-detection by opensearch-project.

the class GetAnomalyDetectorTransportActionTests method testGetAnomalyDetectorRequestNoEntityValue.

@Test
public void testGetAnomalyDetectorRequestNoEntityValue() throws IOException {
    GetAnomalyDetectorRequest request = new GetAnomalyDetectorRequest("1234", 4321, true, false, "", "abcd", false, null);
    BytesStreamOutput out = new BytesStreamOutput();
    request.writeTo(out);
    StreamInput input = out.bytes().streamInput();
    GetAnomalyDetectorRequest newRequest = new GetAnomalyDetectorRequest(input);
    Assert.assertNull(newRequest.getEntity());
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 32 with StreamInput

use of org.opensearch.common.io.stream.StreamInput in project anomaly-detection by opensearch-project.

the class GetAnomalyDetectorTransportActionTests method testGetAnomalyDetectorRequest.

@Test
public void testGetAnomalyDetectorRequest() throws IOException {
    GetAnomalyDetectorRequest request = new GetAnomalyDetectorRequest("1234", 4321, true, false, "", "abcd", false, entity);
    BytesStreamOutput out = new BytesStreamOutput();
    request.writeTo(out);
    StreamInput input = out.bytes().streamInput();
    GetAnomalyDetectorRequest newRequest = new GetAnomalyDetectorRequest(input);
    Assert.assertEquals(request.getDetectorID(), newRequest.getDetectorID());
    Assert.assertEquals(request.getRawPath(), newRequest.getRawPath());
    Assert.assertNull(newRequest.validate());
}
Also used : NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 33 with StreamInput

use of org.opensearch.common.io.stream.StreamInput in project asynchronous-search by opensearch-project.

the class AsynchronousSearchManagementService method performCleanUp.

public final void performCleanUp() {
    final ThreadContext threadContext = threadPool.getThreadContext();
    try (ThreadContext.StoredContext ignore = threadContext.stashContext()) {
        // we have to execute under the system context so that if security is enabled the sync is authorized
        threadContext.markAsSystemContext();
        ImmutableOpenMap<String, DiscoveryNode> dataNodes = clusterService.state().nodes().getDataNodes();
        List<DiscoveryNode> nodes = Stream.of(dataNodes.values().toArray(DiscoveryNode.class)).collect(Collectors.toList());
        if (nodes == null || nodes.isEmpty()) {
            logger.debug("Found empty data nodes with asynchronous search enabled attribute [{}] for response clean up", dataNodes);
            return;
        }
        int pos = Randomness.get().nextInt(nodes.size());
        DiscoveryNode randomNode = nodes.get(pos);
        transportService.sendRequest(randomNode, PERSISTED_RESPONSE_CLEANUP_ACTION_NAME, new AsynchronousSearchCleanUpRequest(threadPool.absoluteTimeInMillis()), new TransportResponseHandler<AcknowledgedResponse>() {

            @Override
            public AcknowledgedResponse read(StreamInput in) throws IOException {
                return new AcknowledgedResponse(in);
            }

            @Override
            public void handleResponse(AcknowledgedResponse response) {
                logger.debug("Successfully executed clean up action on node [{}] with response [{}]", randomNode, response.isAcknowledged());
            }

            @Override
            public void handleException(TransportException e) {
                logger.error(() -> new ParameterizedMessage("Exception executing action [{}]", PERSISTED_RESPONSE_CLEANUP_ACTION_NAME), e);
            }

            @Override
            public String executor() {
                return AsynchronousSearchPlugin.OPEN_DISTRO_ASYNC_SEARCH_GENERIC_THREAD_POOL_NAME;
            }
        });
    } catch (Exception ex) {
        logger.error("Failed to schedule asynchronous search cleanup", ex);
    }
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) AcknowledgedResponse(org.opensearch.search.asynchronous.response.AcknowledgedResponse) IOException(java.io.IOException) TransportException(org.opensearch.transport.TransportException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) ActionRequestValidationException(org.opensearch.action.ActionRequestValidationException) IOException(java.io.IOException) TransportException(org.opensearch.transport.TransportException) StreamInput(org.opensearch.common.io.stream.StreamInput) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage)

Example 34 with StreamInput

use of org.opensearch.common.io.stream.StreamInput in project OpenSearch by opensearch-project.

the class IngestStatsTests method testBWCIngestProcessorTypeStats.

public void testBWCIngestProcessorTypeStats() throws IOException {
    IngestStats.Stats totalStats = new IngestStats.Stats(50, 100, 200, 300);
    List<IngestStats.PipelineStat> pipelineStats = createPipelineStats();
    Map<String, List<IngestStats.ProcessorStat>> processorStats = createProcessorStats(pipelineStats);
    IngestStats expectedIngestStats = new IngestStats(totalStats, pipelineStats, processorStats);
    // legacy output logic
    BytesStreamOutput out = new BytesStreamOutput();
    out.setVersion(VersionUtils.getPreviousVersion(LegacyESVersion.V_7_6_0));
    expectedIngestStats.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    in.setVersion(VersionUtils.getPreviousVersion(LegacyESVersion.V_7_6_0));
    IngestStats serializedStats = new IngestStats(in);
    assertIngestStats(expectedIngestStats, serializedStats, true, false);
}
Also used : StreamInput(org.opensearch.common.io.stream.StreamInput) List(java.util.List) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 35 with StreamInput

use of org.opensearch.common.io.stream.StreamInput in project OpenSearch by opensearch-project.

the class GeoTileGridTests method testSerializationPreBounds.

public void testSerializationPreBounds() throws Exception {
    Version noBoundsSupportVersion = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, LegacyESVersion.V_7_5_0);
    GeoTileGridAggregationBuilder builder = createTestAggregatorBuilder();
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        output.setVersion(LegacyESVersion.V_7_6_0);
        builder.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), new NamedWriteableRegistry(Collections.emptyList()))) {
            in.setVersion(noBoundsSupportVersion);
            GeoTileGridAggregationBuilder readBuilder = new GeoTileGridAggregationBuilder(in);
            assertThat(readBuilder.geoBoundingBox(), equalTo(new GeoBoundingBox(new GeoPoint(Double.NaN, Double.NaN), new GeoPoint(Double.NaN, Double.NaN))));
        }
    }
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) GeoPoint(org.opensearch.common.geo.GeoPoint) GeoTileGridAggregationBuilder(org.opensearch.search.aggregations.bucket.geogrid.GeoTileGridAggregationBuilder) Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) StreamInput(org.opensearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) GeoBoundingBox(org.opensearch.common.geo.GeoBoundingBox) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Aggregations

StreamInput (org.opensearch.common.io.stream.StreamInput)276 BytesStreamOutput (org.opensearch.common.io.stream.BytesStreamOutput)180 IOException (java.io.IOException)49 NamedWriteableAwareStreamInput (org.opensearch.common.io.stream.NamedWriteableAwareStreamInput)43 Version (org.opensearch.Version)30 Test (org.junit.Test)27 InputStreamStreamInput (org.opensearch.common.io.stream.InputStreamStreamInput)23 OpenSearchException (org.opensearch.OpenSearchException)22 Matchers.containsString (org.hamcrest.Matchers.containsString)19 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)19 HashMap (java.util.HashMap)18 BytesReference (org.opensearch.common.bytes.BytesReference)18 Matchers.hasToString (org.hamcrest.Matchers.hasToString)17 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)17 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)16 UncheckedIOException (java.io.UncheckedIOException)15 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)15 TransportException (org.opensearch.transport.TransportException)15 ArrayList (java.util.ArrayList)14 CountDownLatch (java.util.concurrent.CountDownLatch)14