Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public boolean isConnected() {
return this.clusterClient.isConnected();
}

public boolean isReady(boolean wait) {
return this.clusterClient.isReady(wait);
}

public void reset() throws IOException {
this.photos.close();
this.clusterClient.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;

import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.Settings.Builder;
Expand All @@ -35,6 +36,7 @@
import org.opensearch.transport.Netty4Plugin;

public class Cluster implements Closeable {
protected static final Set<String> READY_STATUSES = Set.of("yellow", "green");

public class ClusterNode extends Node {
public ClusterNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.opensearch.client.opensearch._global.PutScriptRequest;
import org.opensearch.client.opensearch._global.PutScriptResponse;
import org.opensearch.client.opensearch._types.StoredScript;
import org.opensearch.client.opensearch.cluster.HealthRequest;
import org.opensearch.client.opensearch.cluster.HealthResponse;
import org.opensearch.client.opensearch.indices.CreateRequest;
import org.opensearch.client.opensearch.indices.CreateResponse;
import org.opensearch.client.opensearch.indices.DeleteRequest;
Expand All @@ -51,6 +53,7 @@

import jakarta.json.Json;
import jakarta.json.JsonReader;
import jakarta.json.JsonString;
import jakarta.json.JsonValue;

import com.fasterxml.jackson.core.JsonFactory;
Expand Down Expand Up @@ -91,13 +94,52 @@ public ClusterClient(String host, int port) {
this.osClient = new OpenSearchClient(transport);
}

public Boolean isConnected() {
public boolean isConnected() {
if (this.restClient != null && this.restClient.isRunning() && this.osClient != null) {
try {
BooleanResponse pingResponse = this.osClient.ping();
return pingResponse.value();
} catch (IOException e) {
logger.warn("Fail to ping cluster: " + e.getMessage());
logger.warn("Fail to ping cluster: {}", e.getMessage());
}
}

return false;
}

public boolean isReady(boolean wait) {
if (this.isConnected()) {
try {
// Check that cluster is ready to process requests
// See https://opensearch.org/docs/latest/opensearch/rest-api/cluster-health/
HealthRequest.Builder healthRequestBuilder = new HealthRequest.Builder();
if (wait) {
JsonValue statusJson, timeoutJson;
try (JsonReader jsonreader = Json.createReader(new StringReader("yellow"))) {
statusJson = jsonreader.readValue();
}
try (JsonReader jsonreader = Json.createReader(new StringReader("50s"))) {
timeoutJson = jsonreader.readValue();
}

healthRequestBuilder.waitForStatus(statusJson).timeout(timeoutJson);
}

HealthResponse healthResponse = this.osClient.cluster().health(healthRequestBuilder.build());
JsonValue statusValue = healthResponse.status();
if (statusValue != null && statusValue.getValueType() == JsonValue.ValueType.STRING) {
String status = ((JsonString) statusValue).getString();

if (Cluster.READY_STATUSES.contains(status)) {
return true;
} else {
logger.warn("Cluster is not ready: {}", status);
}
} else {
logger.error("Fail to parse cluster healthcheck response");
}
} catch (IOException e) {
logger.warn("Fail to get cluster health: {}", e.getMessage());
}
}

Expand All @@ -116,8 +158,7 @@ public Boolean createIndex(String index, String mapping) throws IOException {
JsonValue mappingJson = null;

if (mapping != null && !mapping.isEmpty()) {
StringReader mappingStr = new StringReader(mapping);
try (JsonReader jsonreader = Json.createReader(mappingStr)) {
try (JsonReader jsonreader = Json.createReader(new StringReader(mapping))) {
mappingJson = jsonreader.readValue();
}
}
Expand All @@ -127,7 +168,7 @@ public Boolean createIndex(String index, String mapping) throws IOException {
return createIndexResponse.acknowledged();
}

public Boolean isIndexExists(String index) throws IOException {
public boolean isIndexExists(String index) throws IOException {
ExistsRequest existsIndexRequest = new ExistsRequest.Builder().addIndex(index).build();
BooleanResponse boolResponse = this.osClient.indices().exists(existsIndexRequest);
return boolResponse.value();
Expand Down Expand Up @@ -155,7 +196,7 @@ public Boolean loadSearchTemplate(String templateId, String templatePath) throws
try {
searchTemplate = new String(Utils.getInternalResource(templatePath));
} catch (IOException | URISyntaxException e) {
logger.error("Fail to load search template (" + templatePath + ")", e);
logger.error("Fail to load search template ({})", templatePath, e);
throw new IOException(e);
}

Expand Down
2 changes: 2 additions & 0 deletions indexor/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
</Console>
</Appenders>
<Loggers>
<Logger name="org.opensearch.index.seqno.ReplicationTracker" level="info"/>
<Logger name="org.opensearch.monitor.fs.FsHealthService" level="info"/>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
Expand Down
19 changes: 18 additions & 1 deletion ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<!-- Default: no dock name -->
<dock.name.arg></dock.name.arg>
</properties>
<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -245,7 +249,8 @@
<!-- Disable High DPI by enforcing UI scale factor: see docs/WORKAROUNDS.md -->
<!-- macOS only settings -->
<argument>-Dapple.laf.useScreenMenuBar=true</argument>
<argument>-Xdock:name=${project.parent.name}</argument>
<!-- macOS dock name argument, only supported on macOS -->
<argument>${dock.name.arg}</argument>
<!-- macOS only settings -->
<argument>-Xmx2048m</argument>
<!-- TinyWorld'UI jar must come before WorldWind as we override some messages in MessageStrings.properties file -->
Expand All @@ -258,6 +263,18 @@
</plugins>
</build>
</profile>
<!-- macOS-specific: inject dock name argument -->
<profile>
<id>macos-dockname</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<dock.name.arg>-Xdock:name=${project.parent.name}</dock.name.arg>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected void initialize() {
BasicTreeNode root = new BasicTreeNode("Root");
model.setRoot(root);

if (this.indexor.isConnected()) {
if (this.indexor.isReady(true)) {
try {
if (!this.indexor.metadataIndex().exists())
this.indexor.metadataIndex().create();
Expand Down
2 changes: 0 additions & 2 deletions ui/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
</Console>
</Appenders>
<Loggers>
<Logger name="org.opensearch.index.seqno.ReplicationTracker" level="info"/>
<Logger name="org.opensearch.monitor.fs.FsHealthService" level="info"/>
<Root level="debug">
<AppenderRef ref="Console"/>
</Root>
Expand Down