pom.xml: OkHttp version change
README.md: Updated API documentation ConfigurationValues.java: Changed default orchestrator ip SnowflakeService.java: Added instance name
This commit is contained in:
@@ -90,11 +90,17 @@ Http Status: 200
|
||||
}
|
||||
```
|
||||
Response on error:
|
||||
If the version of the client and the orchestrator do not match the orchestrator will respond with a HTTP code 426. The required version will be
|
||||
|
||||
| Value name | Value description |
|
||||
|:-------------------------|:--------------------------|
|
||||
| Http Status | 426 - Upgrade required |
|
||||
| `Upgrade` Header content | required software version |
|
||||
|
||||
| Value name | Value description |
|
||||
|:-------------------------|:--------------------------|
|
||||
| Http Status | 409 - Conflict |
|
||||
| `Upgrade` Header content | required software version |
|
||||
#### Worker heartbeat (internal)
|
||||
```http request
|
||||
GET /orchestra/heartbeat
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -76,7 +76,7 @@
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>6.1.3</version>
|
||||
<version>4.12.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ public enum ConfigurationValues implements ConfigValues {
|
||||
SEQUENCE_BITS("sequencebits", "S", "SEQUENCE_BITS", "bitcount.sequence", "12"),
|
||||
EPOCH("epoch", "E", "EPOCH", "epoch", "1704067200000"),
|
||||
MACHINE_ID("machineid", "I", "MACHINE_ID", "machineid", "-1"),
|
||||
ORCHESTRATOR_IP("orchestrator", "O", "ORCHESTRATOR_IP", "orchestrator.ip", "localhost"),
|
||||
ORCHESTRATOR_IP("orchestrator", "O", "ORCHESTRATOR_IP", "orchestrator.ip", "http://disabled"),
|
||||
;
|
||||
|
||||
private final String cliFlag;
|
||||
|
||||
@@ -4,13 +4,16 @@ import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.joran.JoranConfigurator;
|
||||
import ch.qos.logback.core.joran.spi.JoranException;
|
||||
import ch.qos.logback.core.util.StatusPrinter2;
|
||||
import okhttp3.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import space.b00tload.utils.configuration.Configuration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
|
||||
public class SnowflakeService {
|
||||
|
||||
@@ -18,12 +21,14 @@ public class SnowflakeService {
|
||||
private static String APPLICATION_BASE;
|
||||
private static String USER_AGENT;
|
||||
private static Logger LOGGER;
|
||||
private static String INSTANCE_NAME;
|
||||
|
||||
public static void main(String[] args) {
|
||||
//Set up constants
|
||||
SOFTWARE_VERSION = Objects.requireNonNullElse(SnowflakeService.class.getPackage().getImplementationVersion(), "0.0.1-indev");
|
||||
USER_AGENT = "SnowflakeService " + SOFTWARE_VERSION + "(" + System.getProperty("os.name") + "; " + System.getProperty("os.arch") + ") Java/" + System.getProperty("java.version");
|
||||
APPLICATION_BASE = List.of(args).contains("--docker") ? Paths.get("data", "b00tload-tools", "snowflake").toString() : Paths.get(System.getProperty("user.home"), ".b00tload-tools", "snowflake").toString();
|
||||
INSTANCE_NAME = getHostname() + "_" + getPid() + "_" + new Random().nextInt(9999);
|
||||
|
||||
//Set up logger
|
||||
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
@@ -50,8 +55,24 @@ public class SnowflakeService {
|
||||
long machineBits;
|
||||
long epoch;
|
||||
|
||||
if(!Configuration.getInstance().get(ConfigurationValues.ORCHESTRATOR_IP).equals("localhost")){
|
||||
if(!Configuration.getInstance().get(ConfigurationValues.ORCHESTRATOR_IP).equals(ConfigurationValues.ORCHESTRATOR_IP.getDefaultValue())){
|
||||
OkHttpClient httpClient = new OkHttpClient();
|
||||
try {
|
||||
try (Response r = httpClient.newCall(
|
||||
new Request.Builder()
|
||||
.url(Configuration.getInstance().get(ConfigurationValues.ORCHESTRATOR_IP))
|
||||
.post(
|
||||
new FormBody.Builder().addEncoded("name", INSTANCE_NAME).build()
|
||||
)
|
||||
.build()
|
||||
).execute()){
|
||||
if(r.code() == 200){
|
||||
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else if((Long.parseLong(Configuration.getInstance().get(ConfigurationValues.MACHINE_ID))) != -1L) {
|
||||
|
||||
} else {
|
||||
@@ -60,4 +81,16 @@ public class SnowflakeService {
|
||||
|
||||
}
|
||||
|
||||
private static String getHostname(){
|
||||
String hostname = System.getenv("COMPUTERNAME"); // On Windows
|
||||
if (hostname == null || hostname.isEmpty()) {
|
||||
hostname = System.getenv("HOSTNAME"); // On Unix/Linux
|
||||
}
|
||||
return hostname;
|
||||
}
|
||||
|
||||
private static long getPid(){
|
||||
return ProcessHandle.current().pid();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user