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());
}
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());
}
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);
}
}
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);
}
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))));
}
}
}
Aggregations