use of org.opensearch.Build in project OpenSearch by opensearch-project.
the class MainResponseTests method testToXContent.
public void testToXContent() throws IOException {
String clusterUUID = randomAlphaOfLengthBetween(10, 20);
final Build current = Build.CURRENT;
Build build = new Build(current.type(), current.hash(), current.date(), current.isSnapshot(), current.getQualifiedVersion(), current.getDistribution());
Version version = Version.CURRENT;
MainResponse response = new MainResponse("nodeName", version, new ClusterName("clusterName"), clusterUUID, build);
XContentBuilder builder = XContentFactory.jsonBuilder();
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
assertEquals("{" + "\"name\":\"nodeName\"," + "\"cluster_name\":\"clusterName\"," + "\"cluster_uuid\":\"" + clusterUUID + "\"," + "\"version\":{" + "\"distribution\":\"" + build.getDistribution() + "\"," + "\"number\":\"" + build.getQualifiedVersion() + "\"," + "\"build_type\":\"" + current.type().displayName() + "\"," + "\"build_hash\":\"" + current.hash() + "\"," + "\"build_date\":\"" + current.date() + "\"," + "\"build_snapshot\":" + current.isSnapshot() + "," + "\"lucene_version\":\"" + version.luceneVersion.toString() + "\"," + "\"minimum_wire_compatibility_version\":\"" + version.minimumCompatibilityVersion().toString() + "\"," + "\"minimum_index_compatibility_version\":\"" + version.minimumIndexCompatibilityVersion().toString() + "\"}," + "\"tagline\":\"" + TAGLINE + "\"" + "}", Strings.toString(builder));
}
use of org.opensearch.Build in project OpenSearch by opensearch-project.
the class NodeInfoStreamingTests method createNodeInfo.
private static NodeInfo createNodeInfo() {
Build build = Build.CURRENT;
DiscoveryNode node = new DiscoveryNode("test_node", buildNewFakeTransportAddress(), emptyMap(), emptySet(), VersionUtils.randomVersion(random()));
Settings settings = randomBoolean() ? null : Settings.builder().put("test", "setting").build();
OsInfo osInfo = null;
if (randomBoolean()) {
int availableProcessors = randomIntBetween(1, 64);
int allocatedProcessors = randomIntBetween(1, availableProcessors);
long refreshInterval = randomBoolean() ? -1 : randomNonNegativeLong();
String name = randomAlphaOfLengthBetween(3, 10);
String arch = randomAlphaOfLengthBetween(3, 10);
String version = randomAlphaOfLengthBetween(3, 10);
osInfo = new OsInfo(refreshInterval, availableProcessors, allocatedProcessors, name, name, arch, version);
}
ProcessInfo process = randomBoolean() ? null : new ProcessInfo(randomInt(), randomBoolean(), randomNonNegativeLong());
JvmInfo jvm = randomBoolean() ? null : JvmInfo.jvmInfo();
ThreadPoolInfo threadPoolInfo = null;
if (randomBoolean()) {
int numThreadPools = randomIntBetween(1, 10);
List<ThreadPool.Info> threadPoolInfos = new ArrayList<>(numThreadPools);
for (int i = 0; i < numThreadPools; i++) {
threadPoolInfos.add(new ThreadPool.Info(randomAlphaOfLengthBetween(3, 10), randomFrom(ThreadPool.ThreadPoolType.values()), randomInt()));
}
threadPoolInfo = new ThreadPoolInfo(threadPoolInfos);
}
Map<String, BoundTransportAddress> profileAddresses = new HashMap<>();
BoundTransportAddress dummyBoundTransportAddress = new BoundTransportAddress(new TransportAddress[] { buildNewFakeTransportAddress() }, buildNewFakeTransportAddress());
profileAddresses.put("test_address", dummyBoundTransportAddress);
TransportInfo transport = randomBoolean() ? null : new TransportInfo(dummyBoundTransportAddress, profileAddresses);
HttpInfo httpInfo = randomBoolean() ? null : new HttpInfo(dummyBoundTransportAddress, randomNonNegativeLong());
PluginsAndModules pluginsAndModules = null;
if (randomBoolean()) {
int numPlugins = randomIntBetween(0, 5);
List<PluginInfo> plugins = new ArrayList<>();
for (int i = 0; i < numPlugins; i++) {
String name = randomAlphaOfLengthBetween(3, 10);
plugins.add(new PluginInfo(name, randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10), VersionUtils.randomVersion(random()), "1.8", randomAlphaOfLengthBetween(3, 10), name, Collections.emptyList(), randomBoolean()));
}
int numModules = randomIntBetween(0, 5);
List<PluginInfo> modules = new ArrayList<>();
for (int i = 0; i < numModules; i++) {
String name = randomAlphaOfLengthBetween(3, 10);
modules.add(new PluginInfo(name, randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10), VersionUtils.randomVersion(random()), "1.8", randomAlphaOfLengthBetween(3, 10), name, Collections.emptyList(), randomBoolean()));
}
pluginsAndModules = new PluginsAndModules(plugins, modules);
}
IngestInfo ingestInfo = null;
if (randomBoolean()) {
int numProcessors = randomIntBetween(0, 5);
List<ProcessorInfo> processors = new ArrayList<>(numProcessors);
for (int i = 0; i < numProcessors; i++) {
processors.add(new ProcessorInfo(randomAlphaOfLengthBetween(3, 10)));
}
ingestInfo = new IngestInfo(processors);
}
AggregationInfo aggregationInfo = null;
if (randomBoolean()) {
AggregationUsageService.Builder builder = new AggregationUsageService.Builder();
int numOfAggs = randomIntBetween(0, 10);
for (int i = 0; i < numOfAggs; i++) {
String aggName = randomAlphaOfLength(10);
try {
if (randomBoolean()) {
builder.registerAggregationUsage(aggName);
} else {
int numOfTypes = randomIntBetween(1, 10);
for (int j = 0; j < numOfTypes; j++) {
builder.registerAggregationUsage(aggName, randomAlphaOfLength(10));
}
}
} catch (IllegalArgumentException ex) {
// Ignore duplicate strings
}
}
aggregationInfo = builder.build().info();
}
ByteSizeValue indexingBuffer = null;
if (randomBoolean()) {
// pick a random long that sometimes exceeds an int:
indexingBuffer = new ByteSizeValue(random().nextLong() & ((1L << 40) - 1));
}
return new NodeInfo(VersionUtils.randomVersion(random()), build, node, settings, osInfo, process, jvm, threadPoolInfo, transport, httpInfo, pluginsAndModules, ingestInfo, aggregationInfo, indexingBuffer);
}
use of org.opensearch.Build in project OpenSearch by opensearch-project.
the class RestMainActionTests method testHeadResponse.
public void testHeadResponse() throws Exception {
final String nodeName = "node1";
final ClusterName clusterName = new ClusterName("cluster1");
final String clusterUUID = randomAlphaOfLengthBetween(10, 20);
final Version version = Version.CURRENT;
final Build build = Build.CURRENT;
final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build);
XContentBuilder builder = JsonXContent.contentBuilder();
RestRequest restRequest = new FakeRestRequest() {
@Override
public Method method() {
return Method.HEAD;
}
};
BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
assertNotNull(response);
assertThat(response.status(), equalTo(RestStatus.OK));
// the empty responses are handled in the HTTP layer so we do
// not assert on them here
}
Aggregations