This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 59c87ba995 HDDS-7301. Cleanup OmUtils (#3812)
59c87ba995 is described below
commit 59c87ba9957abf95a5e5cd681e9c527ee8659f75
Author: Maxim Myskov <[email protected]>
AuthorDate: Sat Feb 18 17:50:10 2023 +0400
HDDS-7301. Cleanup OmUtils (#3812)
---
.../main/java/org/apache/hadoop/ozone/OmUtils.java | 95 ++++------------------
.../om/response/key/OMTrashRecoverResponse.java | 15 ++--
2 files changed, 24 insertions(+), 86 deletions(-)
diff --git
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
index 1eea3abc3f..586ad1d48d 100644
--- a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
+++ b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/OmUtils.java
@@ -122,9 +122,7 @@ public final class OmUtils {
Map<String, List<InetSocketAddress>> result = new HashMap<>();
for (String serviceId : conf.getTrimmedStringCollection(
OZONE_OM_SERVICE_IDS_KEY)) {
- if (!result.containsKey(serviceId)) {
- result.put(serviceId, new ArrayList<>());
- }
+ result.computeIfAbsent(serviceId, x -> new ArrayList<>());
for (String nodeId : getActiveOMNodeIds(conf, serviceId)) {
String rpcAddr = getOmRpcAddress(conf,
ConfUtils.addKeySuffixes(OZONE_OM_ADDRESS_KEY, serviceId, nodeId));
@@ -164,7 +162,8 @@ public final class OmUtils {
final Optional<String> host = getHostNameFromConfigKeys(conf, confKey);
if (host.isPresent()) {
- return host.get() + ":" + getOmRpcPort(conf, confKey);
+ return host.get() + ":" + getPortNumberFromConfigKeys(conf, confKey)
+ .orElse(OZONE_OM_PORT_DEFAULT);
} else {
// The specified confKey is not set
return null;
@@ -222,24 +221,6 @@ public final class OmUtils {
.orElse(OZONE_OM_PORT_DEFAULT);
}
- /**
- * Retrieve the port that is used by OM as specified by the confKey.
- * Return default port if port is not specified in the confKey.
- * @param conf configuration
- * @param confKey configuration key to lookup address from
- * @return Port on which OM RPC server will listen on
- */
- public static int getOmRpcPort(ConfigurationSource conf, String confKey) {
- return getPortNumberFromConfigKeys(conf, confKey)
- .orElse(OZONE_OM_PORT_DEFAULT);
- }
-
- public static int getOmRestPort(ConfigurationSource conf) {
- return getPortNumberFromConfigKeys(conf, OZONE_OM_HTTP_ADDRESS_KEY)
- .orElse(OZONE_OM_HTTP_BIND_PORT_DEFAULT);
- }
-
-
/**
* Checks if the OM request is read only or not.
* @param omRequest OMRequest proto
@@ -366,7 +347,7 @@ public final class OmUtils {
* Get a collection of all omNodeIds (active and decommissioned) for a
* gived omServiceId.
*/
- public static Collection<String> getAllOMNodeIds(ConfigurationSource conf,
+ private static Collection<String> getAllOMNodeIds(ConfigurationSource conf,
String omServiceId) {
Set<String> nodeIds = new HashSet<>();
String nodeIdsKey = ConfUtils.addSuffix(OZONE_OM_NODES_KEY, omServiceId);
@@ -379,16 +360,6 @@ public final class OmUtils {
return nodeIds;
}
- /**
- * Get a collection of nodeIds of all decommissioned OMs for a given
- * omServideId.
- */
- public static Collection<String> getDecommissionedNodes(
- ConfigurationSource conf, String omServiceId) {
- return conf.getTrimmedStringCollection(ConfUtils.addKeySuffixes(
- OZONE_OM_DECOMMISSIONED_NODES_KEY, omServiceId));
- }
-
/**
* @return <code>coll</code> if it is non-null and non-empty. Otherwise,
* returns a list with a single null value.
@@ -402,23 +373,6 @@ public final class OmUtils {
}
}
- /**
- * If a OM conf is only set with key suffixed with OM Node ID, return the
- * set value.
- * @return if the value is set for key suffixed with OM Node ID, return the
- * value, else return null.
- */
- public static String getConfSuffixedWithOMNodeId(ConfigurationSource conf,
- String confKey, String omServiceID, String omNodeId) {
- String suffixedConfKey = ConfUtils.addKeySuffixes(
- confKey, omServiceID, omNodeId);
- String confValue = conf.getTrimmed(suffixedConfKey);
- if (StringUtils.isNotEmpty(confValue)) {
- return confValue;
- }
- return null;
- }
-
/**
* Returns the http address of peer OM node.
* @param conf Configuration
@@ -503,7 +457,9 @@ public final class OmUtils {
// If this key is in a GDPR enforced bucket, then before moving
// KeyInfo to deletedTable, remove the GDPR related metadata and
// FileEncryptionInfo from KeyInfo.
- if (Boolean.valueOf(keyInfo.getMetadata().get(OzoneConsts.GDPR_FLAG))) {
+ if (Boolean.parseBoolean(
+ keyInfo.getMetadata().get(OzoneConsts.GDPR_FLAG))
+ ) {
keyInfo.getMetadata().remove(OzoneConsts.GDPR_FLAG);
keyInfo.getMetadata().remove(OzoneConsts.GDPR_ALGORITHM);
keyInfo.getMetadata().remove(OzoneConsts.GDPR_SECRET);
@@ -573,20 +529,6 @@ public final class OmUtils {
return configuration.getObject(OMClientConfig.class).getRpcTimeOut();
}
- /**
- * Return OmKeyInfo that would be recovered.
- */
- public static OmKeyInfo prepareKeyForRecover(OmKeyInfo keyInfo,
- RepeatedOmKeyInfo repeatedOmKeyInfo) {
-
- /* TODO: HDDS-2425. HDDS-2426.*/
- if (repeatedOmKeyInfo.getOmKeyInfoList().contains(keyInfo)) {
- return keyInfo;
- } else {
- return null;
- }
- }
-
public static int getOMEpoch(boolean isRatisEnabled) {
return isRatisEnabled ? EPOCH_WHEN_RATIS_ENABLED :
EPOCH_WHEN_RATIS_NOT_ENABLED;
@@ -709,14 +651,12 @@ public final class OmUtils {
normalizedKeyName = new Path(OM_KEY_PREFIX + keyName)
.toUri().getPath();
}
- if (!keyName.equals(normalizedKeyName)) {
+ if (!keyName.equals(normalizedKeyName) && LOG.isDebugEnabled()) {
LOG.debug("Normalized key {} to {} ", keyName,
normalizedKeyName.substring(1));
}
- if (preserveTrailingSlash) {
- if (keyName.endsWith("/")) {
- return normalizedKeyName.substring(1) + "/";
- }
+ if (preserveTrailingSlash && keyName.endsWith("/")) {
+ return normalizedKeyName.substring(1) + "/";
}
return normalizedKeyName.substring(1);
}
@@ -759,21 +699,20 @@ public final class OmUtils {
} else {
omNodeIds = OmUtils.getActiveOMNodeIds(conf, omServiceId);
}
- Collection<String> decommNodeIds = OmUtils.getDecommissionedNodes(conf,
- omServiceId);
+ Collection<String> decommissionedNodeIds = conf.getTrimmedStringCollection(
+ ConfUtils.addKeySuffixes(OZONE_OM_DECOMMISSIONED_NODES_KEY,
+ omServiceId));
- String rpcAddrStr, hostAddr, httpAddr, httpsAddr;
- int rpcPort, ratisPort;
- if (omNodeIds.size() == 0) {
+ if (omNodeIds.isEmpty()) {
// If there are no nodeIds present, return empty list
- return Collections.EMPTY_LIST;
+ return Collections.emptyList();
}
for (String nodeId : omNodeIds) {
try {
OMNodeDetails omNodeDetails = OMNodeDetails.getOMNodeDetailsFromConf(
conf, omServiceId, nodeId);
- if (decommNodeIds.contains(omNodeDetails.getNodeId())) {
+ if (decommissionedNodeIds.contains(omNodeDetails.getNodeId())) {
omNodeDetails.setDecommissioningState();
}
omNodesList.add(omNodeDetails);
@@ -794,7 +733,7 @@ public final class OmUtils {
* (NodeID[HostAddress:RpcPort]).
*/
public static String getOMAddressListPrintString(List<OMNodeDetails> omList)
{
- if (omList.size() == 0) {
+ if (omList.isEmpty()) {
return null;
}
StringBuilder printString = new StringBuilder();
diff --git
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMTrashRecoverResponse.java
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMTrashRecoverResponse.java
index c6c2fed048..cf94fbdd8a 100644
---
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMTrashRecoverResponse.java
+++
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/response/key/OMTrashRecoverResponse.java
@@ -18,7 +18,6 @@
package org.apache.hadoop.ozone.om.response.key;
-import org.apache.hadoop.ozone.OmUtils;
import org.apache.hadoop.ozone.om.OMMetadataManager;
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
@@ -58,12 +57,12 @@ public class OMTrashRecoverResponse extends OmKeyResponse {
omKeyInfo.getBucketName(), omKeyInfo.getKeyName());
RepeatedOmKeyInfo repeatedOmKeyInfo = omMetadataManager
.getDeletedTable().get(trashKey);
- omKeyInfo = OmUtils.prepareKeyForRecover(omKeyInfo, repeatedOmKeyInfo);
- omMetadataManager.getDeletedTable()
- .deleteWithBatch(batchOperation, omKeyInfo.getKeyName());
- /* TODO: trashKey should be updated to destinationBucket. */
- omMetadataManager.getKeyTable(getBucketLayout())
- .putWithBatch(batchOperation, trashKey, omKeyInfo);
+ if (repeatedOmKeyInfo.getOmKeyInfoList().contains(omKeyInfo)) {
+ omMetadataManager.getDeletedTable()
+ .deleteWithBatch(batchOperation, omKeyInfo.getKeyName());
+ /* TODO: trashKey should be updated to destinationBucket. */
+ omMetadataManager.getKeyTable(getBucketLayout())
+ .putWithBatch(batchOperation, trashKey, omKeyInfo);
+ }
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]