3333import java .util .Map ;
3434import java .util .Objects ;
3535import java .util .Set ;
36+ import java .util .UUID ;
3637import java .util .concurrent .ConcurrentHashMap ;
3738import java .util .concurrent .Future ;
3839import java .util .concurrent .TimeUnit ;
6869import org .apache .hugegraph .config .TypedOption ;
6970import org .apache .hugegraph .event .EventHub ;
7071import org .apache .hugegraph .exception .ExistedException ;
72+ import org .apache .hugegraph .exception .NotFoundException ;
7173import org .apache .hugegraph .exception .NotSupportException ;
7274import org .apache .hugegraph .io .HugeGraphSONModule ;
7375import org .apache .hugegraph .k8s .K8sDriver ;
@@ -195,7 +197,17 @@ public final class GraphManager {
195197 public GraphManager (HugeConfig conf , EventHub hub ) {
196198 LOG .info ("Init graph manager" );
197199 E .checkArgumentNotNull (conf , "The config can't be null" );
200+
201+ // Auto-generate server.id if not configured.
202+ // Random generation is to prevent duplicate id error reports.This id is currently
203+ // meaningless and needs to be completely removed serverInfoManager in
204+ // the future
198205 String server = conf .get (ServerOptions .SERVER_ID );
206+ if (StringUtils .isEmpty (server )) {
207+ server = "server-" + UUID .randomUUID ().toString ().substring (0 , 8 );
208+ LOG .info ("Auto-generated server.id: {}" , server );
209+ conf .setProperty (ServerOptions .SERVER_ID .name (), server );
210+ }
199211 String role = conf .get (ServerOptions .SERVER_ROLE );
200212
201213 this .config = conf ;
@@ -206,10 +218,6 @@ public GraphManager(HugeConfig conf, EventHub hub) {
206218 conf .get (ServerOptions .SERVER_DEPLOY_IN_K8S );
207219 this .startIgnoreSingleGraphError = conf .get (
208220 ServerOptions .SERVER_START_IGNORE_SINGLE_GRAPH_ERROR );
209- E .checkArgument (server != null && !server .isEmpty (),
210- "The server name can't be null or empty" );
211- E .checkArgument (role != null && !role .isEmpty (),
212- "The server role can't be null or empty" );
213221 this .graphsDir = conf .get (ServerOptions .GRAPHS );
214222 this .cluster = conf .get (ServerOptions .CLUSTER );
215223 this .graphSpaces = new ConcurrentHashMap <>();
@@ -1637,10 +1645,6 @@ private void checkBackendVersionOrExit(HugeConfig config) {
16371645 private void initNodeRole () {
16381646 String id = config .get (ServerOptions .SERVER_ID );
16391647 String role = config .get (ServerOptions .SERVER_ROLE );
1640- E .checkArgument (StringUtils .isNotEmpty (id ),
1641- "The server name can't be null or empty" );
1642- E .checkArgument (StringUtils .isNotEmpty (role ),
1643- "The server role can't be null or empty" );
16441648
16451649 NodeRole nodeRole = NodeRole .valueOf (role .toUpperCase ());
16461650 boolean supportRoleElection = !nodeRole .computer () &&
@@ -1960,7 +1964,7 @@ public HugeGraph graph(String graphSpace, String name) {
19601964 } else if (graph instanceof HugeGraph ) {
19611965 return (HugeGraph ) graph ;
19621966 }
1963- throw new NotSupportException ( "graph instance of %s " , graph . getClass ( ));
1967+ throw new NotFoundException ( String . format ( "Graph '%s' does not exist " , name ));
19641968 }
19651969
19661970 public void dropGraphLocal (String name ) {
0 commit comments