ayushtkn commented on code in PR #426:
URL: https://github.com/apache/tez/pull/426#discussion_r2319160671


##########
tez-api/src/main/java/org/apache/tez/client/registry/AMRecord.java:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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.
+ */
+
+package org.apache.tez.client.registry;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.registry.client.types.ServiceRecord;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+
+
+/**
+ * Represents an instance of an AM (DAGClientServer) in the AM registry.
+ */
+@InterfaceAudience.Public
+public class AMRecord {
+  private static final String APP_ID_RECORD_KEY = "appId";
+  private static final String HOST_RECORD_KEY = "host";
+  private static final String PORT_RECORD_KEY = "port";
+  private static final String OPAQUE_ID_KEY = "id";
+
+  private final ApplicationId appId;
+  private final String host;
+  private final int port;
+  private final String id;
+
+  public AMRecord(ApplicationId appId, String host, int port, String id) {
+    this.appId = appId;
+    this.host = host;
+    this.port = port;
+    //If id is not provided, convert to empty string
+    this.id = (id == null) ? "" : id;
+  }
+
+  public AMRecord(AMRecord other) {
+    this.appId = other.getApplicationId();
+    this.host = other.getHost();
+    this.port = other.getPort();
+    this.id = other.getId();
+  }
+
+  public AMRecord(ServiceRecord serviceRecord) {
+    this.appId = 
ApplicationId.fromString(serviceRecord.get(APP_ID_RECORD_KEY));
+    this.host = serviceRecord.get(HOST_RECORD_KEY);
+    this.port = Integer.parseInt(serviceRecord.get(PORT_RECORD_KEY));
+    this.id = serviceRecord.get(OPAQUE_ID_KEY);
+  }

Review Comment:
   these two aren't used anywhere



##########
tez-api/src/main/java/org/apache/tez/client/registry/AMRecord.java:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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.
+ */
+
+package org.apache.tez.client.registry;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.registry.client.types.ServiceRecord;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+
+
+/**
+ * Represents an instance of an AM (DAGClientServer) in the AM registry.
+ */
+@InterfaceAudience.Public
+public class AMRecord {
+  private static final String APP_ID_RECORD_KEY = "appId";
+  private static final String HOST_RECORD_KEY = "host";
+  private static final String PORT_RECORD_KEY = "port";
+  private static final String OPAQUE_ID_KEY = "id";
+
+  private final ApplicationId appId;
+  private final String host;
+  private final int port;
+  private final String id;
+
+  public AMRecord(ApplicationId appId, String host, int port, String id) {
+    this.appId = appId;
+    this.host = host;
+    this.port = port;
+    //If id is not provided, convert to empty string
+    this.id = (id == null) ? "" : id;
+  }
+
+  public AMRecord(AMRecord other) {
+    this.appId = other.getApplicationId();
+    this.host = other.getHost();
+    this.port = other.getPort();
+    this.id = other.getId();
+  }
+
+  public AMRecord(ServiceRecord serviceRecord) {
+    this.appId = 
ApplicationId.fromString(serviceRecord.get(APP_ID_RECORD_KEY));
+    this.host = serviceRecord.get(HOST_RECORD_KEY);
+    this.port = Integer.parseInt(serviceRecord.get(PORT_RECORD_KEY));
+    this.id = serviceRecord.get(OPAQUE_ID_KEY);
+  }
+
+  public ApplicationId getApplicationId() {
+    return appId;
+  }
+
+  public String getHost() {
+    return host;
+  }
+
+  public int getPort() {
+    return port;
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (other instanceof AMRecord otherRecord) {
+      return appId.equals(otherRecord.appId)
+          && host.equals(otherRecord.host)
+          && port == otherRecord.port
+          && id.equals(otherRecord.id);
+    } else {
+      return false;
+    }
+  }
+
+  public ServiceRecord toServiceRecord() {

Review Comment:
   this isn't used either?



##########
tez-api/src/main/java/org/apache/tez/dag/api/TezConstants.java:
##########
@@ -102,6 +102,9 @@ public final class TezConstants {
   /// Version-related Environment variables
   public static final String TEZ_CLIENT_VERSION_ENV = "TEZ_CLIENT_VERSION";
 
+  //Arbitrary opaque ID to identify AM instances from AMRegistryClient
+  public static final String TEZ_AM_UUID = "UUID";

Review Comment:
   is there a possibility to use ``TEZ_AM_UUID`` rather than just ``UUID``?



##########
tez-dag/src/test/java/org/apache/tez/dag/api/client/registry/TestAMRegistry.java:
##########
@@ -0,0 +1,95 @@
+/**
+ * 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.
+ */
+
+package org.apache.tez.dag.api.client.registry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.*;
+
+import java.net.InetSocketAddress;
+import java.util.UUID;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.tez.client.registry.AMRecord;
+import org.apache.tez.dag.api.TezConfiguration;
+import org.apache.tez.dag.api.client.DAGClientHandler;
+import org.apache.tez.dag.api.client.DAGClientServer;
+import org.apache.tez.dag.app.DAGAppMaster;
+import org.apache.tez.dag.utils.AMRegistryUtils;
+
+import org.junit.Test;
+
+public class TestAMRegistry {
+
+  @Test(timeout = 5000)
+  public void testAMRegistryFactory() throws Exception {
+    Configuration conf = new Configuration();
+    AMRegistry amRegistry = AMRegistryUtils.createAMRegistry(conf);
+    assertNull(amRegistry);
+    String className = 
"org.apache.tez.dag.api.client.registry.TestAMRegistry$SkeletonAMRegistry";
+    conf.set(TezConfiguration.TEZ_AM_REGISTRY_CLASS, className);
+    amRegistry = AMRegistryUtils.createAMRegistry(conf);
+    assertEquals(className, amRegistry.getClass().getName());

Review Comment:
   should add 
   ```
    assertNotNull(amRegistry);
   ```
   Else if it still stays `null`, rather than failing with some nice error, it 
will fail with NPE



##########
tez-api/src/main/java/org/apache/tez/client/registry/AMRecord.java:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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.
+ */
+
+package org.apache.tez.client.registry;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.registry.client.types.ServiceRecord;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+
+
+/**
+ * Represents an instance of an AM (DAGClientServer) in the AM registry.
+ */
+@InterfaceAudience.Public
+public class AMRecord {
+  private static final String APP_ID_RECORD_KEY = "appId";
+  private static final String HOST_RECORD_KEY = "host";
+  private static final String PORT_RECORD_KEY = "port";
+  private static final String OPAQUE_ID_KEY = "id";
+
+  private final ApplicationId appId;
+  private final String host;
+  private final int port;
+  private final String id;
+
+  public AMRecord(ApplicationId appId, String host, int port, String id) {
+    this.appId = appId;
+    this.host = host;
+    this.port = port;
+    //If id is not provided, convert to empty string
+    this.id = (id == null) ? "" : id;
+  }
+
+  public AMRecord(AMRecord other) {
+    this.appId = other.getApplicationId();
+    this.host = other.getHost();
+    this.port = other.getPort();
+    this.id = other.getId();
+  }
+
+  public AMRecord(ServiceRecord serviceRecord) {
+    this.appId = 
ApplicationId.fromString(serviceRecord.get(APP_ID_RECORD_KEY));
+    this.host = serviceRecord.get(HOST_RECORD_KEY);
+    this.port = Integer.parseInt(serviceRecord.get(PORT_RECORD_KEY));
+    this.id = serviceRecord.get(OPAQUE_ID_KEY);
+  }
+
+  public ApplicationId getApplicationId() {
+    return appId;
+  }
+
+  public String getHost() {
+    return host;
+  }
+
+  public int getPort() {
+    return port;
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (other instanceof AMRecord otherRecord) {
+      return appId.equals(otherRecord.appId)
+          && host.equals(otherRecord.host)
+          && port == otherRecord.port
+          && id.equals(otherRecord.id);
+    } else {
+      return false;
+    }
+  }
+
+  public ServiceRecord toServiceRecord() {
+    ServiceRecord serviceRecord = new ServiceRecord();
+    serviceRecord.set(APP_ID_RECORD_KEY, appId);
+    serviceRecord.set(HOST_RECORD_KEY, host);
+    serviceRecord.set(PORT_RECORD_KEY, port);
+    serviceRecord.set(OPAQUE_ID_KEY, id);
+    return serviceRecord;
+  }
+
+  @Override
+  public int hashCode() {
+    return appId.hashCode() * host.hashCode() * id.hashCode() + port;

Review Comment:
   multiplying can easily lead to overflow & two values can collide easily. If 
any of ``appId``, ``host`` or ``id`` is ``null``, this will lead to NPE as well.
   
   How about using
   ```
       return Objects.hash(appId, host, port, id);
   ```



##########
tez-api/pom.xml:
##########
@@ -73,6 +73,11 @@
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-yarn-client</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-yarn-registry</artifactId>

Review Comment:
   use ``hadoop-registry``,  ``hadoop-yarn-registry`` is just a stub pom, which 
has only ``hadoop-registry`` 
   https://issues.apache.org/jira/browse/HADOOP-15821



##########
tez-api/src/main/java/org/apache/tez/client/registry/AMRecord.java:
##########
@@ -0,0 +1,104 @@
+/**
+ * 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.
+ */
+
+package org.apache.tez.client.registry;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.registry.client.types.ServiceRecord;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+
+
+/**
+ * Represents an instance of an AM (DAGClientServer) in the AM registry.
+ */
+@InterfaceAudience.Public
+public class AMRecord {
+  private static final String APP_ID_RECORD_KEY = "appId";
+  private static final String HOST_RECORD_KEY = "host";
+  private static final String PORT_RECORD_KEY = "port";
+  private static final String OPAQUE_ID_KEY = "id";
+
+  private final ApplicationId appId;
+  private final String host;
+  private final int port;
+  private final String id;
+
+  public AMRecord(ApplicationId appId, String host, int port, String id) {
+    this.appId = appId;
+    this.host = host;
+    this.port = port;
+    //If id is not provided, convert to empty string
+    this.id = (id == null) ? "" : id;
+  }
+
+  public AMRecord(AMRecord other) {
+    this.appId = other.getApplicationId();
+    this.host = other.getHost();
+    this.port = other.getPort();
+    this.id = other.getId();
+  }
+
+  public AMRecord(ServiceRecord serviceRecord) {
+    this.appId = 
ApplicationId.fromString(serviceRecord.get(APP_ID_RECORD_KEY));
+    this.host = serviceRecord.get(HOST_RECORD_KEY);
+    this.port = Integer.parseInt(serviceRecord.get(PORT_RECORD_KEY));
+    this.id = serviceRecord.get(OPAQUE_ID_KEY);
+  }
+
+  public ApplicationId getApplicationId() {
+    return appId;
+  }
+
+  public String getHost() {
+    return host;
+  }
+
+  public int getPort() {
+    return port;
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  @Override
+  public boolean equals(Object other) {
+    if (other instanceof AMRecord otherRecord) {

Review Comment:
   should we bail out early if other == this?



##########
tez-dag/src/test/java/org/apache/tez/dag/api/client/registry/TestAMRegistry.java:
##########
@@ -0,0 +1,95 @@
+/**
+ * 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.
+ */
+
+package org.apache.tez.dag.api.client.registry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.*;
+
+import java.net.InetSocketAddress;
+import java.util.UUID;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
+import org.apache.hadoop.yarn.api.records.ApplicationId;
+import org.apache.tez.client.registry.AMRecord;
+import org.apache.tez.dag.api.TezConfiguration;
+import org.apache.tez.dag.api.client.DAGClientHandler;
+import org.apache.tez.dag.api.client.DAGClientServer;
+import org.apache.tez.dag.app.DAGAppMaster;
+import org.apache.tez.dag.utils.AMRegistryUtils;
+
+import org.junit.Test;
+
+public class TestAMRegistry {
+
+  @Test(timeout = 5000)
+  public void testAMRegistryFactory() throws Exception {
+    Configuration conf = new Configuration();
+    AMRegistry amRegistry = AMRegistryUtils.createAMRegistry(conf);
+    assertNull(amRegistry);
+    String className = 
"org.apache.tez.dag.api.client.registry.TestAMRegistry$SkeletonAMRegistry";

Review Comment:
   can we do ``    String className = SkeletonAMRegistry.class.getName();`` 
rather than hardcoding



-- 
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: issues-unsubscr...@tez.apache.org

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

Reply via email to