forked from opensearch-project/opensearch-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Nied <peternied@hotmail.com>
- Loading branch information
Showing
5 changed files
with
11 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 8 additions & 19 deletions
27
coreUtilities/src/main/java/org/opensearch/migrations/utils/ProcessHelpers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
package org.opensearch.migrations.utils; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@UtilityClass | ||
public class ProcessHelpers { | ||
private static final String DEFAULT_NODE_ID = UUID.randomUUID().toString(); | ||
|
||
public static String getNodeInstanceName() { | ||
String id = null; | ||
try { | ||
id = System.getenv("ECS_TASK_ID"); // for ECS deployments | ||
if (id != null) { | ||
return id; | ||
} | ||
id = System.getenv("HOSTNAME"); // for any kubernetes deployed pod | ||
if (id != null) { | ||
return id; | ||
} | ||
// add additional fallbacks here | ||
id = DEFAULT_NODE_ID; | ||
return id; | ||
} finally { | ||
if (id != null) { | ||
String finalId = id; | ||
log.atInfo().setMessage(() -> "getNodeInstanceName()=" + finalId).log(); | ||
} | ||
} | ||
var nodeId = Optional.of("ECS_TASK_ID").map(System::getenv) | ||
.or(() -> Optional.of("HOSTNAME").map(System::getenv)) | ||
.orElse(DEFAULT_NODE_ID); | ||
log.atInfo().setMessage(() -> "getNodeInstanceName()=" + nodeId).log(); | ||
return nodeId; | ||
} | ||
} |