This is an automated email from the ASF dual-hosted git repository.

elserj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new ad6949f  RATIS-520: LogService Configuration
ad6949f is described below

commit ad6949f0e50ab00dcf8fbcc3e11331a114bc6826
Author: Vladimir Rodionov <[email protected]>
AuthorDate: Thu May 30 15:59:50 2019 -0700

    RATIS-520: LogService Configuration
    
    Signed-off-by: Josh Elser <[email protected]>
---
 .../java/org/apache/ratis/conf/RaftProperties.java |   5 +
 ratis-logservice/README.md                         |   5 +
 ratis-logservice/logservice-example.xml            |  88 ++++++++++
 .../logservice/api/LogServiceConfiguration.java    | 188 ++++++++++++++++-----
 .../ratis/logservice/client/LogServiceClient.java  |   2 +-
 .../apache/ratis/logservice/common/Constants.java  |  29 +++-
 .../ratis/logservice/impl/LogStreamImpl.java       |   2 +-
 .../ratis/logservice/impl/LogWriterImpl.java       |   6 +-
 .../apache/ratis/logservice/server/BaseServer.java |  31 +++-
 .../apache/ratis/logservice/server/LogServer.java  |  18 +-
 .../ratis/logservice/server/MetadataServer.java    |  14 +-
 .../apache/ratis/logservice/server/ServerOpts.java |  29 +++-
 12 files changed, 359 insertions(+), 58 deletions(-)

diff --git 
a/ratis-common/src/main/java/org/apache/ratis/conf/RaftProperties.java 
b/ratis-common/src/main/java/org/apache/ratis/conf/RaftProperties.java
index 9b853d6..cda0133 100644
--- a/ratis-common/src/main/java/org/apache/ratis/conf/RaftProperties.java
+++ b/ratis-common/src/main/java/org/apache/ratis/conf/RaftProperties.java
@@ -199,6 +199,11 @@ public class RaftProperties {
     addResourceObject(new Resource(name));
   }
 
+
+  public void addResource(URL path) {
+    addResourceObject(new Resource(path));
+  }
+
   /**
    * Add a configuration resource.
    *
diff --git a/ratis-logservice/README.md b/ratis-logservice/README.md
index b473f18..c169825 100644
--- a/ratis-logservice/README.md
+++ b/ratis-logservice/README.md
@@ -92,3 +92,8 @@ $ ./bin/load-test -q 
master1.logservice.ratis.org:9999,master2.logservice.ratis.
 `client-env.sh` launches a Docker container that can communicate with the 
LogService cluster running from
 `docker-compose`. You can do this by hand, but take care that the correct 
network is provided when launching your
 container.
+
+## Service configuration
+
+The log service loads configuration values from a file named logservice.xml. 
The service looks up this file in an application class path.
+All service configuration options are described in logservice-example.xml file.
diff --git a/ratis-logservice/logservice-example.xml 
b/ratis-logservice/logservice-example.xml
new file mode 100644
index 0000000..ed48777
--- /dev/null
+++ b/ratis-logservice/logservice-example.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
+<!--
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->
+<configuration>
+  <property>
+    <name>logservice.metaserver.port</name>
+    <value>-1</value>
+    <description>Log service meta-server port number</description>
+  </property>
+  <property>
+    <name>logservice.metaserver.hostname</name>
+    <value>localhost</value>
+    <description>Log service meta-server host name</description>
+  </property>
+  <property>
+    <name>logservice.metaserver.workdir</name>
+    <value>.</value>
+    <description>Log service meta-server working directory</description>
+  </property>
+  <property>
+    <name>logservice.logserver.port</name>
+    <value>-1</value>
+    <description>Log service log-server port number</description>
+  </property>
+  <property>
+    <name>logservice.logserver.hostname</name>
+    <value>localhost</value>
+    <description>Log service log-server host name</description>
+  </property>
+  <property>
+    <name>logservice.logserver.workdir</name>
+    <value>.</value>
+    <description>Log service log-server working directory</description>
+  </property>
+  <!--property>
+    <name>logservice.metaquorum</name>
+    <value></value>
+    <description>Log service metaquorum list of nodes</description>
+  </property-->
+  <!--property>
+    <name>logservice.metaserver.groupid</name>
+    <value></value>
+    <description>Log service metaserver stringified UUID</description>
+  </property-->
+  <!--property>
+    <name>logservice.logserver.groupid</name>
+    <value></value>
+    <description>Log service log server stringified UUID</description>
+  </property-->
+  <property>
+    <name>logservice.raft.leader.election.timeout.min</name>
+    <value>1000</value>
+    <description>Raft leader election timeout minimum in ms</description>
+  </property>
+  <property>
+    <name>logservice.raft.leader.election.timeout.max</name>
+    <value>1200</value>
+    <description>Raft leader election timeout maximum in ms</description>
+  </property>
+  <property>
+    <name>logservice.raft.rpc.timeout</name>
+    <value>100000</value>
+    <description>Raft RPC call timeout in ms</description>
+  </property>
+  <property>
+    <name>ratis.raft.segment.size</name>
+    <value>33554432</value>
+    <description>Raft log segment size in bytes</description>
+  </property>
+</configuration>
diff --git 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/api/LogServiceConfiguration.java
 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/api/LogServiceConfiguration.java
index 78119e5..b1089dd 100644
--- 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/api/LogServiceConfiguration.java
+++ 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/api/LogServiceConfiguration.java
@@ -17,72 +17,180 @@
  */
 package org.apache.ratis.logservice.api;
 
-import java.util.Collections;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
+import java.net.URL;
+import java.util.UUID;
+
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.logservice.common.Constants;
+import org.apache.ratis.logservice.server.MetadataServer;
+import org.apache.ratis.logservice.server.ServerOpts;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 
 /**
  * An encapsulation of configuration for a LogService.
+ * The base configuration is defined in logservice.xml file,
+ * which is expected to reside in a class path.
  */
-public class LogServiceConfiguration {
+public final class LogServiceConfiguration extends RaftProperties {
+  private static final Logger LOG = 
LoggerFactory.getLogger(MetadataServer.class);
+  public static final String RESOURCE_NAME = "logservice.xml";
 
-  private ConcurrentHashMap<String, String> configMap =
-      new ConcurrentHashMap<String, String>();
 
   /**
-   * Ctor
+   * Creates default log service configuration object
+   * @return configuration object
    */
-  public LogServiceConfiguration() {
+  public static LogServiceConfiguration create() {
+    return new LogServiceConfiguration();
   }
 
   /**
-   * Fetches the value for the given key from the configuration. If there is 
no entry for
-   * the given key, {@code null} is returned.
-   *
-   * @param key The configuration key
+   * Creates log service configuration object
+   * with a custom configuration file (found on classpath)
+   * @param resourceName name of configuration file
+   * @return configuration object
    */
-  public String get(String key) {
-    return configMap.get(key);
+  public static LogServiceConfiguration create(String resourceName) {
+    return new LogServiceConfiguration(resourceName);
   }
 
   /**
-   * Sets the given key and value into this configuration. The configuration 
key may
-   * not be null. A null value removes the key from the configuration.
-   *
-   * @param key Configuration key, must be non-null
-   * @param value Configuration value
+   * Creates log service configuration object
+   * with a custom configuration URL
+   * @param resourcePath path of configuration file
+   * @return configuration object
    */
-  public void set(String key, String value) {
-    configMap.put(key,  value);
+  public static LogServiceConfiguration create(URL resourcePath) {
+    return new LogServiceConfiguration(resourcePath);
   }
 
-  /**
-   * Removes any entry with the given key from the configuration. If there is 
no entry
-   * for the given key, this method returns without error. The provided key 
must be
-   * non-null.
-   *
-   * @param key The configuration key, must be non-null
-   * @return value
-   */
-  public String remove(String key) {
-    return configMap.remove(key);
+  private LogServiceConfiguration() {
+    super();
+    addResource(RESOURCE_NAME);
+  }
+
+  private LogServiceConfiguration(String resourceName) {
+    super();
+    addResource(resourceName);
+  }
+
+  private LogServiceConfiguration(URL resourcePath) {
+    super();
+    addResource(resourcePath);
   }
 
   /**
-   * Sets the collection of key-value pairs into the configuration. This is 
functionally
-   * equivalent to calling {@link #set(String, String)} numerous time.
+   * Adds configuration options from logservice.xml
+   * for LogServer
+   * @param opts server options
+   * @return server options
    */
-  public void setMany(Iterable<Entry<String,String>> entries) {
-    for (Entry<String, String> entry: entries ) {
-      configMap.put(entry.getKey(), entry.getValue());
+  public ServerOpts addLogServerOpts(ServerOpts opts) {
+    if (!opts.isHostSet()) {
+      String val = get(Constants.LOG_SERVER_HOSTNAME_KEY, "localhost");
+      if (val != null) {
+        opts.setHost(val);
+      }
+    }
+
+    if (!opts.isPortSet()) {
+      String val = get(Constants.LOG_SERVER_PORT_KEY);
+      if (val != null) {
+        try {
+          opts.setPort(Integer.parseInt(val));
+        } catch (Exception e) {
+          LOG.warn("Config value {} for {} is invaild", val, 
Constants.LOG_SERVER_PORT_KEY);
+        }
+      }
+    }
+
+    if (!opts.isWorkingDirSet()) {
+      String val = get(Constants.LOG_SERVER_WORKDIR_KEY);
+      if (val != null) {
+        opts.setWorkingDir(val);
+      }
+    }
+
+    if (!opts.isMetaQuorumSet()) {
+      String val = get(Constants.LOG_SERVICE_METAQUORUM_KEY);
+      if (val != null) {
+        opts.setMetaQuorum(val);
+      }
     }
+
+    if (!opts.isLogServerGroupIdSet()) {
+      String val = get(Constants.LOG_SERVICE_LOG_SERVER_GROUPID_KEY);
+      if (val != null) {
+        try {
+          opts.setLogServerGroupId(UUID.fromString(val));
+        } catch (IllegalArgumentException e) {
+          LOG.warn("Config value {} for {} is invaild", val,
+            Constants.LOG_SERVICE_LOG_SERVER_GROUPID_KEY);
+        }
+      } else {
+        opts.setLogServerGroupId(Constants.SERVERS_GROUP_UUID);
+      }
+    }
+    return opts;
   }
 
+
   /**
-   * Returns an immutable view over the configuration as a {@code Map}.
+   * Adds configuration options from logservice.xml
+   * for MetadataServer
+   * @param opts server options
+   * @return server options
    */
-  public Map<String,String> asMap() {
-    return Collections.unmodifiableMap(configMap);
+  public ServerOpts addMetaServerOpts (ServerOpts opts) {
+    if (!opts.isHostSet()) {
+      String val = get(Constants.META_SERVER_HOSTNAME_KEY);
+      if (val != null) {
+        opts.setHost(val);
+      }
+    }
+
+    if (!opts.isPortSet()) {
+      String val = get(Constants.META_SERVER_PORT_KEY);
+      if (val != null) {
+        try {
+          opts.setPort(Integer.parseInt(val));
+        } catch (Exception e) {
+          LOG.warn("Config value {} for {} is invaild", val,
+            Constants.META_SERVER_PORT_KEY);
+        }
+      }
+    }
+
+    if (!opts.isWorkingDirSet()) {
+      String val = get(Constants.META_SERVER_WORKDIR_KEY);
+      if (val != null) {
+        opts.setWorkingDir(val);
+      }
+    }
+
+    if (!opts.isMetaQuorumSet()) {
+      String val = get(Constants.LOG_SERVICE_METAQUORUM_KEY);
+      if (val != null) {
+        opts.setMetaQuorum(val);
+      }
+    }
+
+    if (!opts.isMetaServerGroupIdSet()) {
+      String val = get(Constants.LOG_SERVICE_META_SERVER_GROUPID_KEY);
+      if (val != null) {
+        try {
+          opts.setMetaGroupId(UUID.fromString(val));
+        } catch (IllegalArgumentException e) {
+          LOG.warn("Config value {} for {} is invaild", val,
+            Constants.LOG_SERVICE_META_SERVER_GROUPID_KEY);
+        }
+      } else {
+        opts.setMetaGroupId(Constants.META_GROUP_UUID);
+      }
+    }
+    return opts;
   }
+
 }
diff --git 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/client/LogServiceClient.java
 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/client/LogServiceClient.java
index 7db7833..7896249 100644
--- 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/client/LogServiceClient.java
+++ 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/client/LogServiceClient.java
@@ -57,7 +57,7 @@ public class LogServiceClient implements AutoCloseable {
      * @param metaQuorum
      */
     public LogServiceClient(String metaQuorum) {
-        this(metaQuorum, new LogServiceConfiguration());
+        this(metaQuorum, LogServiceConfiguration.create());
     }
 
     /**
diff --git 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/common/Constants.java
 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/common/Constants.java
index 2da892b..7366514 100644
--- 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/common/Constants.java
+++ 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/common/Constants.java
@@ -28,6 +28,33 @@ public class Constants {
     public static final RaftGroupId META_GROUP_ID = 
RaftGroupId.valueOf(META_GROUP_UUID);
 
     public static final UUID SERVERS_GROUP_UUID = new UUID(0,2);
-    public static final RaftGroupId SERVERS_GROUP_ID = 
RaftGroupId.valueOf(SERVERS_GROUP_UUID);
+    public static final RaftGroupId SERVERS_GROUP_ID =
+        RaftGroupId.valueOf(SERVERS_GROUP_UUID);
+    public static final String META_SERVER_PORT_KEY = 
"logservice.metaserver.port";
+    public static final String META_SERVER_HOSTNAME_KEY = 
"logservice.metaserver.hostname";
+    public static final String META_SERVER_WORKDIR_KEY = 
"logservice.metaserver.workdir";
+    public static final String LOG_SERVER_PORT_KEY = 
"logservice.logserver.port";
+    public static final String LOG_SERVER_HOSTNAME_KEY = 
"logservice.logserver.hostname";
+    public static final String LOG_SERVER_WORKDIR_KEY = 
"logservice.logserver.workdir";
+    public static final String LOG_SERVICE_METAQUORUM_KEY = 
"logservice.metaquorum";
+    public static final String LOG_SERVICE_META_SERVER_GROUPID_KEY =
+        "logservice.metaserver.groupid";
+    public static final String LOG_SERVICE_LOG_SERVER_GROUPID_KEY = 
"logservice.logserver.groupid";
+    /*
+     * Raft properties
+     */
+    public static final String LOG_SERVICE_LEADER_ELECTION_TIMEOUT_MIN_KEY =
+        "logservice.raft.leader.election.timeout.min"; // in ms
+    public static final String LOG_SERVICE_LEADER_ELECTION_TIMEOUT_MAX_KEY =
+        "logservice.raft.leader.election.timeout.max"; // in ms
+    public static final String LOG_SERVICE_RPC_TIMEOUT_KEY =
+        "logservice.raft.rpc.timeout"; // in ms
+
+    public static final long DEFAULT_LOG_SERVICE_LEADER_ELECTION_TIMEOUT_MIN = 
1000;
+    public static final long DEFAULT_LOG_SERVICE_LEADER_ELECTION_TIMEOUT_MAX = 
1200;
+    public static final long DEFAULT_RPC_TIMEOUT = 100000;// 100 sec (?)
+
+    public static final String RATIS_RAFT_SEGMENT_SIZE_KEY = 
"ratis.raft.segment.size";
+    public static final long DEFAULT_RATIS_RAFT_SEGMENT_SIZE = 32 * 1024 
*1024;// 32MB
 
 }
diff --git 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogStreamImpl.java
 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogStreamImpl.java
index 3f41c80..3394ea6 100644
--- 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogStreamImpl.java
+++ 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogStreamImpl.java
@@ -74,7 +74,7 @@ public class LogStreamImpl implements LogStream {
   public LogStreamImpl(LogName name, RaftClient raftClient) {
     this.raftClient = raftClient;
     this.name = name;
-    this.config = new LogServiceConfiguration();
+    this.config = LogServiceConfiguration.create();
     init();
   }
 
diff --git 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogWriterImpl.java
 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogWriterImpl.java
index d4a0f2d..4ab4f19 100644
--- 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogWriterImpl.java
+++ 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/impl/LogWriterImpl.java
@@ -19,17 +19,17 @@ package org.apache.ratis.logservice.impl;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
-import java.util.concurrent.ExecutionException;
 
 import org.apache.ratis.client.RaftClient;
 import org.apache.ratis.logservice.api.LogServiceConfiguration;
 import org.apache.ratis.logservice.api.LogStream;
 import org.apache.ratis.logservice.api.LogWriter;
+import 
org.apache.ratis.logservice.proto.LogServiceProtos.AppendLogEntryReplyProto;
+import org.apache.ratis.logservice.proto.LogServiceProtos.LogServiceException;
+import org.apache.ratis.logservice.proto.LogServiceProtos.SyncLogReplyProto;
 import org.apache.ratis.logservice.util.LogServiceProtoUtil;
-import org.apache.ratis.logservice.proto.LogServiceProtos.*;
 import org.apache.ratis.protocol.Message;
 import org.apache.ratis.protocol.RaftClientReply;
 import org.slf4j.Logger;
diff --git 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/BaseServer.java
 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/BaseServer.java
index dcd7573..30a938e 100644
--- 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/BaseServer.java
+++ 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/BaseServer.java
@@ -24,6 +24,8 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.grpc.GrpcConfigKeys;
+import org.apache.ratis.logservice.api.LogServiceConfiguration;
+import org.apache.ratis.logservice.common.Constants;
 import org.apache.ratis.logservice.util.LogServiceUtils;
 import org.apache.ratis.netty.NettyConfigKeys;
 import org.apache.ratis.server.RaftServerConfigKeys;
@@ -36,15 +38,20 @@ import org.apache.ratis.util.TimeDuration;
 public abstract class BaseServer implements Closeable {
 
   private final ServerOpts opts;
+  private final LogServiceConfiguration config;
 
   public BaseServer(ServerOpts opts) {
     this.opts = Objects.requireNonNull(opts);
+    this.config = LogServiceConfiguration.create();
   }
 
   public ServerOpts getServerOpts() {
     return opts;
   }
 
+  public LogServiceConfiguration getConfig() {
+    return config;
+  }
   /**
    * Sets common Ratis server properties for both the log and metadata state 
machines.
    */
@@ -54,14 +61,28 @@ public abstract class BaseServer implements Closeable {
     NettyConfigKeys.Server.setPort(properties, opts.getPort());
 
     // Ozone sets the leader election timeout (min) to 1second.
-    TimeDuration leaderElectionTimeoutMin = TimeDuration.valueOf(1, 
TimeUnit.SECONDS);
+    long leaderElectionTimeoutMinVal = getLeaderElectionTimeoutMin();
+    TimeDuration leaderElectionTimeoutMin = 
TimeDuration.valueOf(leaderElectionTimeoutMinVal,
+      TimeUnit.MILLISECONDS);
     RaftServerConfigKeys.Rpc.setTimeoutMin(properties, 
leaderElectionTimeoutMin);
+    long leaderElectionTimeoutMaxVal = getLeaderElectionTimeoutMax();
+
     TimeDuration leaderElectionMaxTimeout = TimeDuration.valueOf(
-        leaderElectionTimeoutMin.toLong(TimeUnit.MILLISECONDS) + 200,
+      leaderElectionTimeoutMaxVal,
         TimeUnit.MILLISECONDS);
     RaftServerConfigKeys.Rpc.setTimeoutMax(properties, 
leaderElectionMaxTimeout);
   }
 
+  private long getLeaderElectionTimeoutMin() {
+    return 
config.getLong(Constants.LOG_SERVICE_LEADER_ELECTION_TIMEOUT_MIN_KEY,
+        Constants.DEFAULT_LOG_SERVICE_LEADER_ELECTION_TIMEOUT_MIN);
+  }
+
+  private long getLeaderElectionTimeoutMax() {
+    return 
config.getLong(Constants.LOG_SERVICE_LEADER_ELECTION_TIMEOUT_MAX_KEY,
+        Constants.DEFAULT_LOG_SERVICE_LEADER_ELECTION_TIMEOUT_MAX);
+  }
+
   /**
    * Validates that there are no properties set which are in conflict with the 
LogService.
    */
@@ -90,14 +111,14 @@ public abstract class BaseServer implements Closeable {
     public abstract T build();
 
     public Builder<T> validate() {
-      if (opts.getPort() == -1) {
+      if (!opts.isPortSet()) {
         InetSocketAddress addr = NetUtils.createLocalServerAddress();
         opts.setPort(addr.getPort());
       }
-      if (opts.getHost() == null) {
+      if (!opts.isHostSet()) {
         opts.setHost(LogServiceUtils.getHostName());
       }
-      if (opts.getWorkingDir() == null) {
+      if (!opts.isWorkingDirSet()) {
         throw new IllegalArgumentException("Working directory was not 
specified");
       }
       return this;
diff --git 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/LogServer.java
 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/LogServer.java
index bed6b2c..1596e72 100644
--- 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/LogServer.java
+++ 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/LogServer.java
@@ -28,6 +28,8 @@ import java.util.concurrent.TimeUnit;
 import org.apache.ratis.client.RaftClient;
 import org.apache.ratis.client.RaftClientConfigKeys;
 import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.logservice.api.LogServiceConfiguration;
+import org.apache.ratis.logservice.common.Constants;
 import org.apache.ratis.logservice.util.LogServiceUtils;
 import org.apache.ratis.logservice.util.MetaServiceProtoUtil;
 import org.apache.ratis.protocol.ClientId;
@@ -69,12 +71,17 @@ public class LogServer extends BaseServer {
       super.setRaftProperties(properties);
 
       // Increase the client timeout
-      RaftClientConfigKeys.Rpc.setRequestTimeout(properties, 
TimeDuration.valueOf(100, TimeUnit.SECONDS));
+      long rpcTimeout = 
getConfig().getLong(Constants.LOG_SERVICE_RPC_TIMEOUT_KEY,
+        Constants.DEFAULT_RPC_TIMEOUT);
+      RaftClientConfigKeys.Rpc.setRequestTimeout(properties,
+        TimeDuration.valueOf(rpcTimeout, TimeUnit.MILLISECONDS));
 
       // Increase the segment size to avoid rolling so quickly
-      SizeInBytes segmentSize = SizeInBytes.valueOf("32MB");
-      RaftServerConfigKeys.Log.setSegmentSizeMax(properties, segmentSize);
-      RaftServerConfigKeys.Log.setPreallocatedSize(properties, segmentSize);
+      long segmentSize = 
getConfig().getLong(Constants.RATIS_RAFT_SEGMENT_SIZE_KEY,
+        Constants.DEFAULT_RATIS_RAFT_SEGMENT_SIZE);
+      SizeInBytes segmentSizeBytes = SizeInBytes.valueOf(segmentSize);
+      RaftServerConfigKeys.Log.setSegmentSizeMax(properties, segmentSizeBytes);
+      RaftServerConfigKeys.Log.setPreallocatedSize(properties, 
segmentSizeBytes);
 
       // TODO this seems to cause errors, not sure if pushing Ratis too hard?
       // SizeInBytes writeBufferSize = SizeInBytes.valueOf("128KB");
@@ -133,6 +140,9 @@ public class LogServer extends BaseServer {
                 .addObject(opts)
                 .build()
                 .parse(args);
+        // Add config from log service configuration file
+        LogServiceConfiguration config = LogServiceConfiguration.create();
+        opts = config.addLogServerOpts(opts);
 
         try (LogServer worker = new LogServer(opts)) {
           worker.start();
diff --git 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/MetadataServer.java
 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/MetadataServer.java
index c7c56b3..3bd75a7 100644
--- 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/MetadataServer.java
+++ 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/MetadataServer.java
@@ -20,6 +20,8 @@ package org.apache.ratis.logservice.server;
 
 import com.beust.jcommander.JCommander;
 import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.logservice.api.LogServiceConfiguration;
+import org.apache.ratis.logservice.common.Constants;
 import org.apache.ratis.logservice.util.LogServiceUtils;
 import org.apache.ratis.protocol.*;
 import org.apache.ratis.server.RaftServer;
@@ -68,7 +70,14 @@ public class MetadataServer extends BaseServer {
         this.lifeCycle = new LifeCycle(this.id);
         RaftProperties properties = new RaftProperties();
         if(opts.getWorkingDir() != null) {
-            RaftServerConfigKeys.setStorageDirs(properties, 
Collections.singletonList(new File(opts.getWorkingDir())));
+            RaftServerConfigKeys.setStorageDirs(properties,
+              Collections.singletonList(new File(opts.getWorkingDir())));
+        } else {
+          String path = getConfig().get(Constants.META_SERVER_WORKDIR_KEY);
+          if (path != null) {
+            RaftServerConfigKeys.setStorageDirs(properties,
+              Collections.singletonList(new File(path)));
+          }
         }
 
         // Set properties common to all log service state machines
@@ -103,6 +112,9 @@ public class MetadataServer extends BaseServer {
                 .addObject(opts)
                 .build()
                 .parse(args);
+        // Add config from log service configuration file
+        LogServiceConfiguration config = LogServiceConfiguration.create();
+        opts = config.addMetaServerOpts(opts);
 
         try (MetadataServer master = new MetadataServer(opts)) {
           master.start();
diff --git 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/ServerOpts.java
 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/ServerOpts.java
index 7ca9f90..1285cf9 100644
--- 
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/ServerOpts.java
+++ 
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/server/ServerOpts.java
@@ -38,7 +38,7 @@ public class ServerOpts {
   }
 
   @Parameter(names = {"-h", "--hostname"}, description = "Hostname")
-  private String host = "localhost";
+  private String host = null;
 
   @Parameter(names = {"-p", "--port"}, description = "Port number")
   private int port = -1;
@@ -47,7 +47,7 @@ public class ServerOpts {
   private String workingDir = null;
 
   @Parameter(names = {"-q", "--metaQuorum"}, description = "Metadata Service 
Quorum")
-  private String metaQuorum;
+  private String metaQuorum = null;
 
   @Parameter(names = {"--metadataServerGroupId"}, description = "UUID 
corresponding to the RAFT metadata servers group",
       converter = UUIDConverter.class)
@@ -65,6 +65,10 @@ public class ServerOpts {
     this.host = host;
   }
 
+  public boolean isHostSet() {
+    return this.host != null;
+  }
+
   public int getPort() {
     return port;
   }
@@ -73,6 +77,10 @@ public class ServerOpts {
     this.port = port;
   }
 
+  public boolean isPortSet() {
+    return this.port != -1;
+  }
+
   public String getWorkingDir() {
     return workingDir;
   }
@@ -81,6 +89,10 @@ public class ServerOpts {
     this.workingDir = workingDir;
   }
 
+  public boolean isWorkingDirSet() {
+    return this.workingDir != null;
+  }
+
   public String getMetaQuorum() {
     return metaQuorum;
   }
@@ -89,6 +101,10 @@ public class ServerOpts {
     this.metaQuorum = metaQuorum;
   }
 
+  public boolean isMetaQuorumSet() {
+    return this.metaQuorum != null;
+  }
+
   public UUID getMetaGroupId() {
     return metaGroupId;
   }
@@ -97,6 +113,10 @@ public class ServerOpts {
     this.metaGroupId = metaGroupId;
   }
 
+  public boolean isMetaServerGroupIdSet() {
+    return this.metaGroupId != null && 
!this.metaGroupId.equals(Constants.META_GROUP_UUID);
+  }
+
   public UUID getLogServerGroupId() {
     return logServerGroupId;
   }
@@ -105,6 +125,11 @@ public class ServerOpts {
     this.logServerGroupId = logServerGroupId;
   }
 
+  public boolean isLogServerGroupIdSet() {
+    return this.logServerGroupId != null &&
+        !this.logServerGroupId.equals(Constants.SERVERS_GROUP_UUID);
+  }
+
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder();

Reply via email to