ayushtkn commented on code in PR #4990: URL: https://github.com/apache/hadoop/pull/4990#discussion_r1211229496
########## hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java: ########## @@ -699,32 +697,52 @@ public boolean addMount(AddMountAttributes addMountAttributes) // Get the existing entry MountTableManager mountTable = client.getMountTableManager(); MountTable existingEntry = getMountEntry(mount, mountTable); - MountTable existingOrNewEntry = - addMountAttributes.getNewOrUpdatedMountTableEntryWithAttributes(existingEntry); - if (existingOrNewEntry == null) { + if (existingEntry != null) { + System.err.println("MountTable entry:" + mount + " already exists."); return false; } - if (existingEntry == null) { - AddMountTableEntryRequest request = AddMountTableEntryRequest - .newInstance(existingOrNewEntry); - AddMountTableEntryResponse addResponse = mountTable.addMountTableEntry(request); - boolean added = addResponse.getStatus(); - if (!added) { - System.err.println("Cannot add mount point " + mount); - } - return added; - } else { - UpdateMountTableEntryRequest updateRequest = - UpdateMountTableEntryRequest.newInstance(existingOrNewEntry); - UpdateMountTableEntryResponse updateResponse = - mountTable.updateMountTableEntry(updateRequest); - boolean updated = updateResponse.getStatus(); - if (!updated) { - System.err.println("Cannot update mount point " + mount); - } - return updated; + MountTable mountEntry = addMountAttributes.getMountTableEntryWithAttributes(); + AddMountTableEntryRequest request = AddMountTableEntryRequest.newInstance(mountEntry); + AddMountTableEntryResponse addResponse = mountTable.addMountTableEntry(request); + boolean added = addResponse.getStatus(); + if (!added) { + System.err.println("Cannot add mount point " + mount); } + return added; + } + + /** + * Return the map from namespace to destination. + * @param nss input namespaces. + * @param destinations input destinations. + * @return one map from namespace to destination. + * @throws IOException throw IOException if the destinations is invalida. Review Comment: typo ``invalida`` ########## hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/tools/federation/RouterAdmin.java: ########## @@ -699,32 +697,52 @@ public boolean addMount(AddMountAttributes addMountAttributes) // Get the existing entry MountTableManager mountTable = client.getMountTableManager(); MountTable existingEntry = getMountEntry(mount, mountTable); - MountTable existingOrNewEntry = - addMountAttributes.getNewOrUpdatedMountTableEntryWithAttributes(existingEntry); - if (existingOrNewEntry == null) { + if (existingEntry != null) { + System.err.println("MountTable entry:" + mount + " already exists."); return false; } - if (existingEntry == null) { - AddMountTableEntryRequest request = AddMountTableEntryRequest - .newInstance(existingOrNewEntry); - AddMountTableEntryResponse addResponse = mountTable.addMountTableEntry(request); - boolean added = addResponse.getStatus(); - if (!added) { - System.err.println("Cannot add mount point " + mount); - } - return added; - } else { - UpdateMountTableEntryRequest updateRequest = - UpdateMountTableEntryRequest.newInstance(existingOrNewEntry); - UpdateMountTableEntryResponse updateResponse = - mountTable.updateMountTableEntry(updateRequest); - boolean updated = updateResponse.getStatus(); - if (!updated) { - System.err.println("Cannot update mount point " + mount); - } - return updated; + MountTable mountEntry = addMountAttributes.getMountTableEntryWithAttributes(); + AddMountTableEntryRequest request = AddMountTableEntryRequest.newInstance(mountEntry); + AddMountTableEntryResponse addResponse = mountTable.addMountTableEntry(request); + boolean added = addResponse.getStatus(); + if (!added) { + System.err.println("Cannot add mount point " + mount); } + return added; + } + + /** + * Return the map from namespace to destination. + * @param nss input namespaces. + * @param destinations input destinations. + * @return one map from namespace to destination. + * @throws IOException throw IOException if the destinations is invalida. + */ + public static Map<String, String> getDestMap(String[] nss, String[] destinations) + throws IOException { + if (isInvalidDestinations(nss, destinations)) { + String message = "Invalid number of namespaces and destinations. The number of destinations: " + + destinations.length + " is not equal to the number of namespaces: " + nss.length; + throw new IOException(message); + } + Map<String, String> destMap = new LinkedHashMap<>(); + boolean multiDest = destinations.length > 1; + for (int nsIndex = 0; nsIndex < nss.length; nsIndex++) { + int destIndex = multiDest ? nsIndex : 0; + destMap.put(nss[nsIndex], destinations[destIndex]); + } + return destMap; + } + + private static boolean isInvalidDestinations(String[] nss, String[] destinations) { Review Comment: Can change the name may be, areDestinationsInvalid() should sound more appropriate -- 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: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org