Skip to content
Snippets Groups Projects

Add random worker names when no worker name is defined on start up

Files

@@ -2,8 +2,10 @@ package nl.tudelft.ewi.auta.worker.config;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
/**
* Global configuration parameters for the worker service.
@@ -71,8 +73,13 @@ public class WorkerSettings {
this.apiProtocol = this.getOne(args, "api-protocol", "https");
this.apiPort = (int) Float.parseFloat(this.getOne(args, "api-port", "12729.0"));
this.name = this.getOne(args, "name");
String tempName;
try {
tempName = this.getOne(args, "name");
} catch (IncompleteConfigurationException ice) {
tempName = this.getNewName();
}
this.name = tempName;
this.temp = Paths.get(this.getOne(args, "temp", System.getProperty("java.io.tmpdir")));
this.maxUnzippedSubmissionSize =
@@ -202,4 +209,21 @@ public class WorkerSettings {
public String getApiAuthToken() {
return this.authToken;
}
/**
* Returns a new randomly chosen name from the list.
* appended with the current date and time to try and ensure uniqueness
* @return the name of the worker
*/
public String getNewName() {
final var names = Arrays.asList("Otto", "Thomas", "Deadlock",
"Switch", "Cindy", "Merel", "Worker", "Jarvis", "Nachos Chili Beef",
"Geike", "Spring", "NodeJS", "Docker", "Zoutelande", "Zebravis",
"Barbeque", "Car Class", "Not Arnold", "f00f", "Twerl",
"Euphey", "Wukl", "HiddenIdentity3", "Tarmac", "Moo League", "Tusk",
"HashMap", "Results", "Entity", "Bidding AI", "KoffieVerspiller",
"StateMachine", "Shopping Cart", "HousingApplication", "Javer");
return new StringBuilder(names.get(ThreadLocalRandom.current().nextInt(names.size())))
.append(System.currentTimeMillis()).toString();
}
}
Loading