Search in sources :

Example 1 with Build

use of org.opensearch.Build in project OpenSearch by opensearch-project.

the class MainResponseTests method createServerTestInstance.

@Override
protected org.opensearch.action.main.MainResponse createServerTestInstance(XContentType xContentType) {
    String clusterUuid = randomAlphaOfLength(10);
    ClusterName clusterName = new ClusterName(randomAlphaOfLength(10));
    String nodeName = randomAlphaOfLength(10);
    final String date = new Date(randomNonNegativeLong()).toString();
    Version version = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, Version.CURRENT);
    Build build = new Build(Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(), version.toString(), version.before(Version.V_1_0_0) ? null : "opensearch");
    return new org.opensearch.action.main.MainResponse(nodeName, version, clusterName, clusterUuid, build);
}
Also used : LegacyESVersion(org.opensearch.LegacyESVersion) Version(org.opensearch.Version) Build(org.opensearch.Build) ClusterName(org.opensearch.cluster.ClusterName) Date(java.util.Date)

Example 2 with Build

use of org.opensearch.Build in project OpenSearch by opensearch-project.

the class MainResponseTests method createTestInstance.

@Override
protected MainResponse createTestInstance() {
    String clusterUuid = randomAlphaOfLength(10);
    ClusterName clusterName = new ClusterName(randomAlphaOfLength(10));
    String nodeName = randomAlphaOfLength(10);
    final String date = new Date(randomNonNegativeLong()).toString();
    Version version = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, Version.CURRENT);
    Build build = new Build(Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(), version.toString(), version.onOrAfter(Version.V_1_0_0) ? randomAlphaOfLength(10) : "");
    return new MainResponse(nodeName, version, clusterName, clusterUuid, build);
}
Also used : Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) Build(org.opensearch.Build) ClusterName(org.opensearch.cluster.ClusterName) Date(java.util.Date)

Example 3 with Build

use of org.opensearch.Build in project OpenSearch by opensearch-project.

the class RestMainActionTests method testGetResponse.

public void testGetResponse() 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 boolean prettyPrint = randomBoolean();
    final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build);
    XContentBuilder builder = JsonXContent.contentBuilder();
    Map<String, String> params = new HashMap<>();
    if (prettyPrint == false) {
        params.put("pretty", String.valueOf(prettyPrint));
    }
    RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();
    BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
    assertNotNull(response);
    assertThat(response.status(), equalTo(RestStatus.OK));
    assertThat(response.content().length(), greaterThan(0));
    XContentBuilder responseBuilder = JsonXContent.contentBuilder();
    if (prettyPrint) {
        // do this to mimic what the rest layer does
        responseBuilder.prettyPrint().lfAtEnd();
    }
    mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS);
    BytesReference xcontentBytes = BytesReference.bytes(responseBuilder);
    assertEquals(xcontentBytes, response.content());
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) HashMap(java.util.HashMap) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) RestRequest(org.opensearch.rest.RestRequest) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) Version(org.opensearch.Version) MainResponse(org.opensearch.action.main.MainResponse) Build(org.opensearch.Build) BytesRestResponse(org.opensearch.rest.BytesRestResponse) ClusterName(org.opensearch.cluster.ClusterName) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 4 with Build

use of org.opensearch.Build in project OpenSearch by opensearch-project.

the class MainResponseTests method mutateInstance.

@Override
protected MainResponse mutateInstance(MainResponse mutateInstance) {
    String clusterUuid = mutateInstance.getClusterUuid();
    Build build = mutateInstance.getBuild();
    Version version = mutateInstance.getVersion();
    String nodeName = mutateInstance.getNodeName();
    ClusterName clusterName = mutateInstance.getClusterName();
    switch(randomIntBetween(0, 4)) {
        case 0:
            clusterUuid = clusterUuid + randomAlphaOfLength(5);
            break;
        case 1:
            nodeName = nodeName + randomAlphaOfLength(5);
            break;
        case 2:
            // toggle the snapshot flag of the original Build parameter
            build = new Build(Build.Type.UNKNOWN, build.hash(), build.date(), !build.isSnapshot(), build.getQualifiedVersion(), build.getDistribution());
            break;
        case 3:
            version = randomValueOtherThan(version, () -> VersionUtils.randomVersion(random()));
            break;
        case 4:
            clusterName = new ClusterName(clusterName + randomAlphaOfLength(5));
            break;
    }
    return new MainResponse(nodeName, version, clusterName, clusterUuid, build);
}
Also used : Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) Build(org.opensearch.Build) ClusterName(org.opensearch.cluster.ClusterName)

Example 5 with Build

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));
}
Also used : Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) Build(org.opensearch.Build) ClusterName(org.opensearch.cluster.ClusterName) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

Build (org.opensearch.Build)7 Version (org.opensearch.Version)6 ClusterName (org.opensearch.cluster.ClusterName)6 LegacyESVersion (org.opensearch.LegacyESVersion)4 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)4 Date (java.util.Date)2 HashMap (java.util.HashMap)2 MainResponse (org.opensearch.action.main.MainResponse)2 BytesRestResponse (org.opensearch.rest.BytesRestResponse)2 RestRequest (org.opensearch.rest.RestRequest)2 FakeRestRequest (org.opensearch.test.rest.FakeRestRequest)2 ArrayList (java.util.ArrayList)1 NodeInfo (org.opensearch.action.admin.cluster.node.info.NodeInfo)1 PluginsAndModules (org.opensearch.action.admin.cluster.node.info.PluginsAndModules)1 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)1 BytesReference (org.opensearch.common.bytes.BytesReference)1 Settings (org.opensearch.common.settings.Settings)1 BoundTransportAddress (org.opensearch.common.transport.BoundTransportAddress)1 ByteSizeValue (org.opensearch.common.unit.ByteSizeValue)1 XContentFactory.jsonBuilder (org.opensearch.common.xcontent.XContentFactory.jsonBuilder)1