org.elasticsearch.Build Java Examples

The following examples show how to use org.elasticsearch.Build. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InfoApiMain.java    From elasticsearch-pool with Apache License 2.0 6 votes vote down vote up
public static void info() throws IOException {
    try{
        RestHighLevelClient client = HighLevelClient.getInstance();

        MainResponse response = client.info();

        ClusterName clusterName = response.getClusterName();
        String clusterUuid = response.getClusterUuid();
        String nodeName = response.getNodeName();
        Version version = response.getVersion();
        Build build = response.getBuild();

        System.out.println("clusterName: "+clusterName);
        System.out.println("clusterUuid: "+clusterUuid);
        System.out.println("nodeName: "+nodeName);
        System.out.println("version: "+version);
        System.out.println("build: "+build);

    }finally{
        HighLevelClient.close();
    }
}
 
Example #2
Source File: NodeInfo.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public NodeInfo(Version version, Build build, DiscoveryNode node, @Nullable ImmutableMap<String, String> serviceAttributes, @Nullable Settings settings,
                @Nullable OsInfo os, @Nullable ProcessInfo process, @Nullable JvmInfo jvm, @Nullable ThreadPoolInfo threadPool,
                @Nullable TransportInfo transport, @Nullable HttpInfo http, @Nullable PluginsAndModules plugins) {
    super(node);
    this.version = version;
    this.build = build;
    this.serviceAttributes = serviceAttributes;
    this.settings = settings;
    this.os = os;
    this.process = process;
    this.jvm = jvm;
    this.threadPool = threadPool;
    this.transport = transport;
    this.http = http;
    this.plugins = plugins;
}
 
Example #3
Source File: Node.java    From crate with Apache License 2.0 6 votes vote down vote up
private void logVersion(Logger logger, JvmInfo jvmInfo) {
    logger.info(
        "version[{}], pid[{}], build[{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}]",
        Version.displayVersion(Version.CURRENT, Version.CURRENT.isSnapshot()),
        jvmInfo.pid(),
        Build.CURRENT.hashShort(),
        Build.CURRENT.timestamp(),
        Constants.OS_NAME,
        Constants.OS_VERSION,
        Constants.OS_ARCH,
        Constants.JVM_VENDOR,
        Constants.JVM_NAME,
        Constants.JAVA_VERSION,
        Constants.JVM_VERSION);
    warnIfPreRelease(Version.CURRENT, Version.CURRENT.isSnapshot(), logger);
}
 
Example #4
Source File: MainAndStaticFileHandler.java    From crate with Apache License 2.0 6 votes vote down vote up
private static void writeJSON(OutputStream outputStream,
                              ClusterStateResponse response,
                              HttpResponseStatus status,
                              @Nullable String nodeName) throws IOException {
    var builder = new XContentBuilder(JsonXContent.JSON_XCONTENT, outputStream);
    builder.prettyPrint().lfAtEnd();
    builder.startObject();
    builder.field("ok", status == HttpResponseStatus.OK);
    builder.field("status", HttpResponseStatus.OK.code());
    if (nodeName != null && !nodeName.isEmpty()) {
        builder.field("name", nodeName);
    }
    builder.field("cluster_name", response.getClusterName().value());
    builder.startObject("version")
        .field("number", Version.CURRENT.externalNumber())
        .field("build_hash", Build.CURRENT.hash())
        .field("build_timestamp", Build.CURRENT.timestamp())
        .field("build_snapshot", Version.CURRENT.isSnapshot())
        .field("lucene_version", org.apache.lucene.util.Version.LATEST.toString())
        .endObject();
    builder.endObject();
    builder.flush();
    builder.close();
}
 
Example #5
Source File: RestMainAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, RestChannel channel, final Client client) throws Exception {

    RestStatus status = RestStatus.OK;
    if (clusterService.state().blocks().hasGlobalBlock(RestStatus.SERVICE_UNAVAILABLE)) {
        status = RestStatus.SERVICE_UNAVAILABLE;
    }
    if (request.method() == RestRequest.Method.HEAD) {
        channel.sendResponse(new BytesRestResponse(status));
        return;
    }

    XContentBuilder builder = channel.newBuilder();

    // Default to pretty printing, but allow ?pretty=false to disable
    if (!request.hasParam("pretty")) {
        builder.prettyPrint().lfAtEnd();
    }

    builder.startObject();
    if (settings.get("name") != null) {
        builder.field("name", settings.get("name"));
    }
    builder.field("cluster_name", clusterName.value());
    builder.startObject("version")
            .field("number", version.number())
            .field("build_hash", Build.CURRENT.hash())
            .field("build_timestamp", Build.CURRENT.timestamp())
            .field("build_snapshot", version.snapshot)
            .field("lucene_version", version.luceneVersion.toString())
            .endObject();
    builder.field("tagline", "You Know, for Search");
    builder.endObject();

    channel.sendResponse(new BytesRestResponse(status, builder));
}
 
Example #6
Source File: NodeService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public NodeInfo info() {
    return new NodeInfo(version, Build.CURRENT, discovery.localNode(), serviceAttributes,
            settings,
            monitorService.osService().info(),
            monitorService.processService().info(),
            monitorService.jvmService().info(),
            threadPool.info(),
            transportService.info(),
            httpServer == null ? null : httpServer.info(),
            pluginService == null ? null : pluginService.info()
    );
}
 
Example #7
Source File: NodeService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public NodeInfo info(boolean settings, boolean os, boolean process, boolean jvm, boolean threadPool,
                     boolean transport, boolean http, boolean plugin) {
    return new NodeInfo(version, Build.CURRENT, discovery.localNode(), serviceAttributes,
            settings ? this.settings : null,
            os ? monitorService.osService().info() : null,
            process ? monitorService.processService().info() : null,
            jvm ? monitorService.jvmService().info() : null,
            threadPool ? this.threadPool.info() : null,
            transport ? transportService.info() : null,
            http ? (httpServer == null ? null : httpServer.info()) : null,
            plugin ? (pluginService == null ? null : pluginService.info()) : null
    );
}
 
Example #8
Source File: TransportSQLActionClassLifecycleTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testSysNodesVersionFromMultipleNodes() throws Exception {
    SQLResponse response = execute("select version, version['number'], " +
                                   "version['build_hash'], version['build_snapshot'] " +
                                   "from sys.nodes");
    assertThat(response.rowCount(), is(2L));
    for (int i = 0; i <= 1; i++) {
        assertThat(response.rows()[i][0], instanceOf(Map.class));
        assertThat((Map<String, Object>) response.rows()[i][0], allOf(hasKey("number"), hasKey("build_hash"), hasKey("build_snapshot")));
        assertThat((String) response.rows()[i][1], Matchers.is(Version.CURRENT.externalNumber()));
        assertThat((String) response.rows()[i][2], is(Build.CURRENT.hash()));
        assertThat((Boolean) response.rows()[i][3], is(Version.CURRENT.isSnapshot()));
    }
}
 
Example #9
Source File: NodeInfo.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    version = Version.readVersion(in);
    build = Build.readBuild(in);
    if (in.readBoolean()) {
        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        int size = in.readVInt();
        for (int i = 0; i < size; i++) {
            builder.put(in.readString(), in.readString());
        }
        serviceAttributes = builder.build();
    }
    if (in.readBoolean()) {
        settings = Settings.readSettingsFromStream(in);
    }
    if (in.readBoolean()) {
        os = OsInfo.readOsInfo(in);
    }
    if (in.readBoolean()) {
        process = ProcessInfo.readProcessInfo(in);
    }
    if (in.readBoolean()) {
        jvm = JvmInfo.readJvmInfo(in);
    }
    if (in.readBoolean()) {
        threadPool = ThreadPoolInfo.readThreadPoolInfo(in);
    }
    if (in.readBoolean()) {
        transport = TransportInfo.readTransportInfo(in);
    }
    if (in.readBoolean()) {
        http = HttpInfo.readHttpInfo(in);
    }
    if (in.readBoolean()) {
        plugins = new PluginsAndModules();
        plugins.readFrom(in);
    }
}
 
Example #10
Source File: NodeStatsContext.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
public void writeTo(StreamOutput out) throws IOException {
    DataTypes.STRING.writeValueTo(out, id);
    DataTypes.STRING.writeValueTo(out, name);
    DataTypes.STRING.writeValueTo(out, hostname);
    out.writeLong(timestamp);
    out.writeBoolean(version != null);
    if (version != null) {
        Version.writeVersion(version, out);
    }
    out.writeBoolean(build != null);
    if (build != null) {
        Build.writeBuildTo(build, out);
    }
    DataTypes.STRING.writeValueTo(out, restUrl);
    out.writeOptionalVInt(pgPort);
    out.writeOptionalVInt(httpPort);
    out.writeOptionalVInt(transportPort);
    out.writeOptionalWriteable(jvmStats);
    out.writeOptionalWriteable(osInfo);
    out.writeOptionalWriteable(processStats);
    out.writeOptionalWriteable(osStats);
    out.writeOptionalWriteable(fsInfo);
    out.writeOptionalWriteable(extendedOsStats);
    out.writeOptionalWriteable(threadPools);
    out.writeOptionalWriteable(httpStats);
    out.writeOptionalWriteable(psqlStats);
    out.writeLong(openTransportConnections);
    out.writeLong(clusterStateVersion);

    DataTypes.STRING.writeValueTo(out, osName);
    DataTypes.STRING.writeValueTo(out, osArch);
    DataTypes.STRING.writeValueTo(out, osVersion);
    DataTypes.STRING.writeValueTo(out, javaVersion);
    DataTypes.STRING.writeValueTo(out, jvmName);
    DataTypes.STRING.writeValueTo(out, jvmVendor);
    DataTypes.STRING.writeValueTo(out, jvmVersion);
}
 
Example #11
Source File: NodeStatsContext.java    From crate with Apache License 2.0 5 votes vote down vote up
public NodeStatsContext(StreamInput in, boolean complete) throws IOException {
    this.complete = complete;
    this.id = DataTypes.STRING.readValueFrom(in);
    this.name = DataTypes.STRING.readValueFrom(in);
    this.hostname = DataTypes.STRING.readValueFrom(in);
    this.timestamp = in.readLong();
    this.version = in.readBoolean() ? Version.readVersion(in) : null;
    this.build = in.readBoolean() ? Build.readBuild(in) : null;
    this.restUrl = DataTypes.STRING.readValueFrom(in);
    this.pgPort = in.readOptionalVInt();
    this.httpPort = in.readOptionalVInt();
    this.transportPort = in.readOptionalVInt();
    this.jvmStats = in.readOptionalWriteable(JvmStats::new);
    this.osInfo = in.readOptionalWriteable(OsInfo::new);
    this.processStats = in.readOptionalWriteable(ProcessStats::new);
    this.osStats = in.readOptionalWriteable(OsStats::new);
    this.fsInfo = in.readOptionalWriteable(FsInfo::new);
    this.extendedOsStats = in.readOptionalWriteable(ExtendedOsStats::new);
    this.threadPools = in.readOptionalWriteable(ThreadPoolStats::new);
    this.httpStats = in.readOptionalWriteable(HttpStats::new);
    this.psqlStats = in.readOptionalWriteable(ConnectionStats::new);
    this.openTransportConnections = in.readLong();
    this.clusterStateVersion = in.readLong();

    this.osName = DataTypes.STRING.readValueFrom(in);
    this.osArch = DataTypes.STRING.readValueFrom(in);
    this.osVersion = DataTypes.STRING.readValueFrom(in);
    this.javaVersion = DataTypes.STRING.readValueFrom(in);
    this.jvmName = DataTypes.STRING.readValueFrom(in);
    this.jvmVendor = DataTypes.STRING.readValueFrom(in);
    this.jvmVersion = DataTypes.STRING.readValueFrom(in);
}
 
Example #12
Source File: CrateDB.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception {
    if (options.nonOptionArguments().isEmpty() == false) {
        throw new UserException(ExitCodes.USAGE, "Positional arguments not allowed, found " + options.nonOptionArguments());
    }
    if (options.has(versionOption)) {
        if (options.has(daemonizeOption) || options.has(pidfileOption)) {
            throw new UserException(ExitCodes.USAGE, "CrateDB version option is mutually exclusive with any other option");
        }
        terminal.println("Version: " + Version.CURRENT
                         + ", Build: " + Build.CURRENT.hashShort() + "/" + Build.CURRENT.timestamp()
                         + ", JVM: " + JvmInfo.jvmInfo().version());
        return;
    }

    final boolean daemonize = options.has(daemonizeOption);

    final Path pidFile = pidfileOption.value(options);
    env = addPidFileSetting(pidFile, env);

    final boolean quiet = options.has(quietOption);

    try {
        init(daemonize, quiet, env);
    } catch (NodeValidationException e) {
        throw new UserException(ExitCodes.CONFIG, e.getMessage());
    }
}
 
Example #13
Source File: VersionFunction.java    From crate with Apache License 2.0 5 votes vote down vote up
private static String formatVersion() {
    String version = Version.displayVersion(Version.CURRENT, Version.CURRENT.isSnapshot());
    String built = String.format(
        Locale.ENGLISH,
        "built %s/%s",
        Build.CURRENT.hashShort(),
        Build.CURRENT.timestamp());
    String vmVersion = String.format(
        Locale.ENGLISH,
        "%s %s",
        System.getProperty("java.vm.name"),
        System.getProperty("java.vm.version"));
    String osVersion = String.format(
        Locale.ENGLISH,
        "%s %s %s",
        System.getProperty("os.name"),
        System.getProperty("os.version"),
        System.getProperty("os.arch"));

    return String.format(
        Locale.ENGLISH,
        "CrateDB %s (%s, %s, %s)",
        version,
        built,
        osVersion,
        vmVersion);
}
 
Example #14
Source File: NodeStatsContextTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testStreamContext() throws Exception {
    NodeStatsContext ctx1 = new NodeStatsContext(true);
    ctx1.id("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18");
    ctx1.name("crate1");
    ctx1.hostname("crate1.example.com");
    ctx1.timestamp(100L);
    ctx1.version(Version.CURRENT);
    ctx1.build(Build.CURRENT);
    ctx1.httpPort(4200);
    ctx1.transportPort(4300);
    ctx1.restUrl("10.0.0.1:4200");
    ctx1.jvmStats(JvmStats.jvmStats());
    ctx1.osInfo(DummyOsInfo.INSTANCE);
    ProcessProbe processProbe = ProcessProbe.getInstance();
    ctx1.processStats(processProbe.processStats());
    OsProbe osProbe = OsProbe.getInstance();
    ctx1.osStats(osProbe.osStats());
    ctx1.extendedOsStats(extendedNodeInfo.osStats());
    ctx1.threadPools(threadPool.stats());
    ctx1.clusterStateVersion(10L);

    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    StreamOutput out = new OutputStreamStreamOutput(outBuffer);
    ctx1.writeTo(out);

    ByteArrayInputStream inBuffer = new ByteArrayInputStream(outBuffer.toByteArray());
    InputStreamStreamInput in = new InputStreamStreamInput(inBuffer);
    NodeStatsContext ctx2 = new NodeStatsContext(in, true);

    assertThat(ctx1.id(), is(ctx2.id()));
    assertThat(ctx1.name(), is(ctx2.name()));
    assertThat(ctx1.hostname(), is(ctx2.hostname()));
    assertThat(ctx1.timestamp(), is(100L));
    assertThat(ctx1.version(), is(ctx2.version()));
    assertThat(ctx1.build().hash(), is(ctx2.build().hash()));
    assertThat(ctx1.restUrl(), is(ctx2.restUrl()));
    assertThat(ctx1.httpPort(), is(ctx2.httpPort()));
    assertThat(ctx1.transportPort(), is(ctx2.transportPort()));
    assertThat(ctx1.pgPort(), is(ctx2.pgPort()));
    assertThat(ctx1.jvmStats().getTimestamp(), is(ctx2.jvmStats().getTimestamp()));
    assertThat(ctx1.osInfo().getArch(), is(ctx2.osInfo().getArch()));
    assertThat(ctx1.processStats().getTimestamp(), is(ctx2.processStats().getTimestamp()));
    assertThat(ctx1.osStats().getTimestamp(), is(ctx2.osStats().getTimestamp()));
    assertThat(ctx1.extendedOsStats().uptime(), is(ctx2.extendedOsStats().uptime()));
    assertThat(ctx1.threadPools().iterator().next().getActive(), is(ctx2.threadPools().iterator().next().getActive()));
    assertThat(ctx1.clusterStateVersion(), is(ctx2.clusterStateVersion()));
}
 
Example #15
Source File: NodeStatsContext.java    From crate with Apache License 2.0 4 votes vote down vote up
public Build build() {
    return build;
}
 
Example #16
Source File: BootstrapCLIParser.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ExitStatus execute(Settings settings, Environment env) throws Exception {
    terminal.println("Version: %s, Build: %s/%s, JVM: %s", org.elasticsearch.Version.CURRENT, Build.CURRENT.hashShort(), Build.CURRENT.timestamp(), JvmInfo.jvmInfo().version());
    return ExitStatus.OK_AND_EXIT;
}
 
Example #17
Source File: NodeInfo.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);
    out.writeVInt(version.id);
    Build.writeBuild(build, out);
    if (getServiceAttributes() == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        out.writeVInt(serviceAttributes.size());
        for (Map.Entry<String, String> entry : serviceAttributes.entrySet()) {
            out.writeString(entry.getKey());
            out.writeString(entry.getValue());
        }
    }
    if (settings == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        Settings.writeSettingsToStream(settings, out);
    }
    if (os == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        os.writeTo(out);
    }
    if (process == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        process.writeTo(out);
    }
    if (jvm == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        jvm.writeTo(out);
    }
    if (threadPool == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        threadPool.writeTo(out);
    }
    if (transport == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        transport.writeTo(out);
    }
    if (http == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        http.writeTo(out);
    }
    if (plugins == null) {
        out.writeBoolean(false);
    } else {
        out.writeBoolean(true);
        plugins.writeTo(out);
    }
}
 
Example #18
Source File: NodeInfo.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * The build version of the node.
 */
public Build getBuild() {
    return this.build;
}
 
Example #19
Source File: HttpDownloadHelper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private URLConnection openConnection(URL aSource) throws IOException {

            // set up the URL connection
            URLConnection connection = aSource.openConnection();
            // modify the headers
            // NB: things like user authentication could go in here too.
            if (hasTimestamp) {
                connection.setIfModifiedSince(timestamp);
            }

            // in case the plugin manager is its own project, this can become an authenticator
            boolean isSecureProcotol = "https".equalsIgnoreCase(aSource.getProtocol());
            boolean isAuthInfoSet = !Strings.isNullOrEmpty(aSource.getUserInfo());
            if (isAuthInfoSet) {
                if (!isSecureProcotol) {
                    throw new IOException("Basic auth is only supported for HTTPS!");
                }
                String basicAuth = Base64.encodeBytes(aSource.getUserInfo().getBytes(StandardCharsets.UTF_8));
                connection.setRequestProperty("Authorization", "Basic " + basicAuth);
            }

            if (connection instanceof HttpURLConnection) {
                ((HttpURLConnection) connection).setInstanceFollowRedirects(false);
                connection.setUseCaches(true);
                connection.setConnectTimeout(5000);
            }
            connection.setRequestProperty("ES-Version", Version.CURRENT.toString());
            connection.setRequestProperty("ES-Build-Hash", Build.CURRENT.hashShort());
            connection.setRequestProperty("User-Agent", "elasticsearch-plugin-manager");

            // connect to the remote site (may take some time)
            connection.connect();

            // First check on a 301 / 302 (moved) response (HTTP only)
            if (connection instanceof HttpURLConnection) {
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                int responseCode = httpConnection.getResponseCode();
                if (responseCode == HttpURLConnection.HTTP_MOVED_PERM ||
                        responseCode == HttpURLConnection.HTTP_MOVED_TEMP ||
                        responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
                    String newLocation = httpConnection.getHeaderField("Location");
                    URL newURL = new URL(newLocation);
                    if (!redirectionAllowed(aSource, newURL)) {
                        return null;
                    }
                    return openConnection(newURL);
                }
                // next test for a 304 result (HTTP only)
                long lastModified = httpConnection.getLastModified();
                if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
                        || (lastModified != 0 && hasTimestamp && timestamp >= lastModified)) {
                    // not modified so no file download. just return
                    // instead and trace out something so the user
                    // doesn't think that the download happened when it
                    // didn't
                    return null;
                }
                // test for 401 result (HTTP only)
                if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
                    String message = "HTTP Authorization failure";
                    throw new IOException(message);
                }
            }

            //REVISIT: at this point even non HTTP connections may
            //support the if-modified-since behaviour -we just check
            //the date of the content and skip the write if it is not
            //newer. Some protocols (FTP) don't include dates, of
            //course.
            return connection;
        }