|
@@ -16,30 +16,28 @@
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
|
|
|
-package org.apache.hadoop.ozone.client;
|
|
|
-
|
|
|
-import java.text.ParseException;
|
|
|
-import java.time.Instant;
|
|
|
-import java.time.ZoneId;
|
|
|
-import java.time.ZonedDateTime;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
+package org.apache.hadoop.hdds.scm.client;
|
|
|
|
|
|
+import com.google.common.base.Preconditions;
|
|
|
import org.apache.hadoop.classification.InterfaceAudience;
|
|
|
import org.apache.hadoop.classification.InterfaceStability;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
-import org.apache.hadoop.hdsl.conf.OzoneConfiguration;
|
|
|
+import org.apache.hadoop.hdds.scm.ScmConfigKeys;
|
|
|
import org.apache.hadoop.ozone.OzoneConfigKeys;
|
|
|
import org.apache.hadoop.ozone.OzoneConsts;
|
|
|
-import org.apache.hadoop.scm.ScmConfigKeys;
|
|
|
-
|
|
|
-import com.google.common.base.Preconditions;
|
|
|
import org.apache.http.client.config.RequestConfig;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
/**
|
|
|
* Utility methods for Ozone and Container Clients.
|
|
|
*
|
|
@@ -49,14 +47,14 @@ import org.slf4j.LoggerFactory;
|
|
|
*/
|
|
|
@InterfaceAudience.Public
|
|
|
@InterfaceStability.Unstable
|
|
|
-public final class OzoneClientUtils {
|
|
|
+public final class HddsClientUtils {
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(
|
|
|
- OzoneClientUtils.class);
|
|
|
+ HddsClientUtils.class);
|
|
|
|
|
|
private static final int NO_PORT = -1;
|
|
|
|
|
|
- private OzoneClientUtils() {
|
|
|
+ private HddsClientUtils() {
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -69,55 +67,28 @@ public final class OzoneClientUtils {
|
|
|
return format.withZone(ZoneId.of(OzoneConsts.OZONE_TIME_ZONE));
|
|
|
});
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * Returns the cache value to be used for list calls.
|
|
|
- * @param conf Configuration object
|
|
|
- * @return list cache size
|
|
|
+ * Convert time in millisecond to a human readable format required in ozone.
|
|
|
+ * @return a human readable string for the input time
|
|
|
*/
|
|
|
- public static int getListCacheSize(Configuration conf) {
|
|
|
- return conf.getInt(OzoneConfigKeys.OZONE_CLIENT_LIST_CACHE_SIZE,
|
|
|
- OzoneConfigKeys.OZONE_CLIENT_LIST_CACHE_SIZE_DEFAULT);
|
|
|
+ public static String formatDateTime(long millis) {
|
|
|
+ ZonedDateTime dateTime = ZonedDateTime.ofInstant(
|
|
|
+ Instant.ofEpochSecond(millis), DATE_FORMAT.get().getZone());
|
|
|
+ return DATE_FORMAT.get().format(dateTime);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return a default instance of {@link CloseableHttpClient}.
|
|
|
+ * Convert time in ozone date format to millisecond.
|
|
|
+ * @return time in milliseconds
|
|
|
*/
|
|
|
- public static CloseableHttpClient newHttpClient() {
|
|
|
- return OzoneClientUtils.newHttpClient(new OzoneConfiguration());
|
|
|
+ public static long formatDateTime(String date) throws ParseException {
|
|
|
+ Preconditions.checkNotNull(date, "Date string should not be null.");
|
|
|
+ return ZonedDateTime.parse(date, DATE_FORMAT.get())
|
|
|
+ .toInstant().getEpochSecond();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Returns a {@link CloseableHttpClient} configured by given configuration.
|
|
|
- * If conf is null, returns a default instance.
|
|
|
- *
|
|
|
- * @param conf configuration
|
|
|
- * @return a {@link CloseableHttpClient} instance.
|
|
|
- */
|
|
|
- public static CloseableHttpClient newHttpClient(Configuration conf) {
|
|
|
- long socketTimeout = OzoneConfigKeys
|
|
|
- .OZONE_CLIENT_SOCKET_TIMEOUT_DEFAULT;
|
|
|
- long connectionTimeout = OzoneConfigKeys
|
|
|
- .OZONE_CLIENT_CONNECTION_TIMEOUT_DEFAULT;
|
|
|
- if (conf != null) {
|
|
|
- socketTimeout = conf.getTimeDuration(
|
|
|
- OzoneConfigKeys.OZONE_CLIENT_SOCKET_TIMEOUT,
|
|
|
- OzoneConfigKeys.OZONE_CLIENT_SOCKET_TIMEOUT_DEFAULT,
|
|
|
- TimeUnit.MILLISECONDS);
|
|
|
- connectionTimeout = conf.getTimeDuration(
|
|
|
- OzoneConfigKeys.OZONE_CLIENT_CONNECTION_TIMEOUT,
|
|
|
- OzoneConfigKeys.OZONE_CLIENT_CONNECTION_TIMEOUT_DEFAULT,
|
|
|
- TimeUnit.MILLISECONDS);
|
|
|
- }
|
|
|
|
|
|
- CloseableHttpClient client = HttpClients.custom()
|
|
|
- .setDefaultRequestConfig(
|
|
|
- RequestConfig.custom()
|
|
|
- .setSocketTimeout(Math.toIntExact(socketTimeout))
|
|
|
- .setConnectTimeout(Math.toIntExact(connectionTimeout))
|
|
|
- .build())
|
|
|
- .build();
|
|
|
- return client;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* verifies that bucket name / volume name is a valid DNS name.
|
|
@@ -199,23 +170,53 @@ public final class OzoneClientUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Convert time in millisecond to a human readable format required in ozone.
|
|
|
- * @return a human readable string for the input time
|
|
|
+ * Returns the cache value to be used for list calls.
|
|
|
+ * @param conf Configuration object
|
|
|
+ * @return list cache size
|
|
|
*/
|
|
|
- public static String formatDateTime(long millis) {
|
|
|
- ZonedDateTime dateTime = ZonedDateTime.ofInstant(
|
|
|
- Instant.ofEpochSecond(millis), DATE_FORMAT.get().getZone());
|
|
|
- return DATE_FORMAT.get().format(dateTime);
|
|
|
+ public static int getListCacheSize(Configuration conf) {
|
|
|
+ return conf.getInt(OzoneConfigKeys.OZONE_CLIENT_LIST_CACHE_SIZE,
|
|
|
+ OzoneConfigKeys.OZONE_CLIENT_LIST_CACHE_SIZE_DEFAULT);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Convert time in ozone date format to millisecond.
|
|
|
- * @return time in milliseconds
|
|
|
+ * @return a default instance of {@link CloseableHttpClient}.
|
|
|
*/
|
|
|
- public static long formatDateTime(String date) throws ParseException {
|
|
|
- Preconditions.checkNotNull(date, "Date string should not be null.");
|
|
|
- return ZonedDateTime.parse(date, DATE_FORMAT.get())
|
|
|
- .toInstant().getEpochSecond();
|
|
|
+ public static CloseableHttpClient newHttpClient() {
|
|
|
+ return HddsClientUtils.newHttpClient(new Configuration());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns a {@link CloseableHttpClient} configured by given configuration.
|
|
|
+ * If conf is null, returns a default instance.
|
|
|
+ *
|
|
|
+ * @param conf configuration
|
|
|
+ * @return a {@link CloseableHttpClient} instance.
|
|
|
+ */
|
|
|
+ public static CloseableHttpClient newHttpClient(Configuration conf) {
|
|
|
+ long socketTimeout = OzoneConfigKeys
|
|
|
+ .OZONE_CLIENT_SOCKET_TIMEOUT_DEFAULT;
|
|
|
+ long connectionTimeout = OzoneConfigKeys
|
|
|
+ .OZONE_CLIENT_CONNECTION_TIMEOUT_DEFAULT;
|
|
|
+ if (conf != null) {
|
|
|
+ socketTimeout = conf.getTimeDuration(
|
|
|
+ OzoneConfigKeys.OZONE_CLIENT_SOCKET_TIMEOUT,
|
|
|
+ OzoneConfigKeys.OZONE_CLIENT_SOCKET_TIMEOUT_DEFAULT,
|
|
|
+ TimeUnit.MILLISECONDS);
|
|
|
+ connectionTimeout = conf.getTimeDuration(
|
|
|
+ OzoneConfigKeys.OZONE_CLIENT_CONNECTION_TIMEOUT,
|
|
|
+ OzoneConfigKeys.OZONE_CLIENT_CONNECTION_TIMEOUT_DEFAULT,
|
|
|
+ TimeUnit.MILLISECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
+ CloseableHttpClient client = HttpClients.custom()
|
|
|
+ .setDefaultRequestConfig(
|
|
|
+ RequestConfig.custom()
|
|
|
+ .setSocketTimeout(Math.toIntExact(socketTimeout))
|
|
|
+ .setConnectTimeout(Math.toIntExact(connectionTimeout))
|
|
|
+ .build())
|
|
|
+ .build();
|
|
|
+ return client;
|
|
|
}
|
|
|
|
|
|
/**
|