EdColeman commented on code in PR #4082:
URL: https://github.com/apache/accumulo/pull/4082#discussion_r1430759679


##########
core/src/main/java/org/apache/accumulo/core/tabletserver/log/LogEntry.java:
##########
@@ -27,64 +27,106 @@
 import org.apache.accumulo.core.data.Value;
 import 
org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.LogColumnFamily;
 import org.apache.hadoop.io.Text;
+import org.checkerframework.checker.nullness.qual.NonNull;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.net.HostAndPort;
 
-public class LogEntry {
+public final class LogEntry {
 
   private final String filePath;
+  private final HostAndPort tserver;
+  private final UUID uniqueId;
 
-  public LogEntry(String filePath) {
-    validateFilePath(filePath);
+  private LogEntry(String filePath, HostAndPort tserver, UUID uniqueId) {
     this.filePath = filePath;
-  }
-
-  public String getFilePath() {
-    return this.filePath;
+    this.tserver = tserver;
+    this.uniqueId = uniqueId;
   }
 
   /**
-   * Validates the expected format of the file path. We expect the path to 
contain a tserver
-   * (host:port) followed by a UUID as the file name. For example,
-   * localhost:1234/927ba659-d109-4bce-b0a5-bcbbcb9942a2 is a valid file path.
+   * Creates a new LogEntry object after validating the expected format of the 
file path. We expect
+   * the path to contain a tserver (host+port) followed by a UUID as the file 
name as the last two
+   * components.<br>
+   * For example, 
file:///some/dir/path/localhost+1234/927ba659-d109-4bce-b0a5-bcbbcb9942a2 is a
+   * valid file path.
    *
    * @param filePath path to validate
+   * @return an object representation of this log entry
    * @throws IllegalArgumentException if the filePath is invalid
    */
-  private static void validateFilePath(String filePath) {
+  public static LogEntry fromFilePath(String filePath) {
     String[] parts = filePath.split("/");
 
     if (parts.length < 2) {
       throw new IllegalArgumentException(
-          "Invalid filePath format. The path should at least contain 
tserver/UUID.");
+          "Invalid filePath format. The path should end with tserver/UUID.");
     }
 
     String tserverPart = parts[parts.length - 2];
     String uuidPart = parts[parts.length - 1];
 
+    String badTServerMsg =
+        "Invalid tserver in filePath. Expected: host+port. Found '" + 
tserverPart + "'";
+    if (tserverPart.contains(":")) {
+      throw new IllegalArgumentException(badTServerMsg);
+    }
+    HostAndPort tserver;
     try {
-      HostAndPort.fromString(tserverPart);
+      tserver = HostAndPort.fromString(tserverPart.replace("+", ":"));
     } catch (IllegalArgumentException e) {
-      throw new IllegalArgumentException(
-          "Invalid tserver format in filePath. Expected format: host:port. 
Found '" + tserverPart
-              + "'");
+      throw new IllegalArgumentException(badTServerMsg);
     }
 
+    String badUuidMsg = "Expected valid UUID. Found '" + uuidPart + "'";
+    UUID uuid;
     try {
-      UUID.fromString(uuidPart);
+      uuid = UUID.fromString(uuidPart);
     } catch (IllegalArgumentException e) {
-      throw new IllegalArgumentException("Expected valid UUID. Found '" + 
uuidPart + "'");
+      throw new IllegalArgumentException(badUuidMsg);
     }
+    if (!uuid.toString().equals(uuidPart)) {

Review Comment:
   UUID.fromString accepts 1-1-1-1-1



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to