From common-commits-return-77370-archive-asf-public=cust-asf.ponee.io@hadoop.apache.org Thu Jan 4 00:47:21 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id D3D0818077A for ; Thu, 4 Jan 2018 00:47:21 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C1F2C160C3B; Wed, 3 Jan 2018 23:47:21 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B4ED1160C39 for ; Thu, 4 Jan 2018 00:47:20 +0100 (CET) Received: (qmail 40708 invoked by uid 500); 3 Jan 2018 23:47:19 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 40670 invoked by uid 99); 3 Jan 2018 23:47:19 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Jan 2018 23:47:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 97CD5DFC3E; Wed, 3 Jan 2018 23:47:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aengineer@apache.org To: common-commits@hadoop.apache.org Message-Id: <06b10866f3524e248a0c1cfe134bc78d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HDFS-12870. Ozone: Service Discovery: REST endpoint in KSM for getServiceList. Contributed by Nanda kumar. Date: Wed, 3 Jan 2018 23:47:19 +0000 (UTC) Repository: hadoop Updated Branches: refs/heads/HDFS-7240 ace9aece2 -> 45118257a HDFS-12870. Ozone: Service Discovery: REST endpoint in KSM for getServiceList. Contributed by Nanda kumar. Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/45118257 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/45118257 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/45118257 Branch: refs/heads/HDFS-7240 Commit: 45118257aba4452ae337798269982153c046321b Parents: ace9aec Author: Anu Engineer Authored: Wed Jan 3 15:31:27 2018 -0800 Committer: Anu Engineer Committed: Wed Jan 3 15:31:27 2018 -0800 ---------------------------------------------------------------------- .../org/apache/hadoop/ozone/OzoneConsts.java | 5 + .../hadoop/ozone/ksm/helpers/ServiceInfo.java | 80 ++++++++++--- .../hadoop/ozone/ksm/KeySpaceManager.java | 7 +- .../ozone/ksm/KeySpaceManagerHttpServer.java | 6 +- .../ozone/ksm/ServiceListJSONServlet.java | 103 +++++++++++++++++ .../hadoop/ozone/web/OzoneHttpServer.java | 21 ++++ .../ksm/TestKeySpaceManagerHttpServer.java | 2 +- .../ksm/TestKeySpaceManagerRestInterface.java | 113 +++++++++++++++++++ 8 files changed, 317 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/45118257/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java index fe8319c..8ea7a23 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java @@ -149,6 +149,11 @@ public final class OzoneConsts { public static final int INVALID_PORT = -1; + + // The ServiceListJSONServlet context attribute where KeySpaceManager + // instance gets stored. + public static final String KSM_CONTEXT_ATTRIBUTE = "ozone.ksm"; + private OzoneConsts() { // Never Constructed } http://git-wip-us.apache.org/repos/asf/hadoop/blob/45118257/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/ksm/helpers/ServiceInfo.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/ksm/helpers/ServiceInfo.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/ksm/helpers/ServiceInfo.java index 375e78c..1c76b8a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/ksm/helpers/ServiceInfo.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/ozone/ksm/helpers/ServiceInfo.java @@ -19,12 +19,18 @@ package org.apache.hadoop.ozone.ksm.helpers; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.ObjectWriter; import com.google.common.base.Preconditions; +import org.apache.hadoop.ozone.client.rest.response.BucketInfo; import org.apache.hadoop.ozone.protocol.proto.KeySpaceManagerProtocolProtos; import org.apache.hadoop.ozone.protocol.proto.KeySpaceManagerProtocolProtos .ServicePort; import org.apache.hadoop.ozone.protocol.proto.OzoneProtos.NodeType; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -36,35 +42,45 @@ import java.util.stream.Collectors; */ public final class ServiceInfo { + private static final ObjectReader READER = + new ObjectMapper().readerFor(ServiceInfo.class); + private static final ObjectWriter WRITER = + new ObjectMapper().writerWithDefaultPrettyPrinter(); + /** * Type of node/service. */ - private final NodeType nodeType; + private NodeType nodeType; /** * Hostname of the node in which the service is running. */ - private final String hostname; + private String hostname; /** * List of ports the service listens to. */ - private final Map portsMap; + private Map ports; + + /** + * Default constructor for JSON deserialization. + */ + public ServiceInfo() {} /** * Constructs the ServiceInfo for the {@code nodeType}. * @param nodeType type of node/service * @param hostname hostname of the service - * @param ports list of ports the service listens to + * @param portList list of ports the service listens to */ private ServiceInfo( - NodeType nodeType, String hostname, List ports) { + NodeType nodeType, String hostname, List portList) { Preconditions.checkNotNull(nodeType); Preconditions.checkNotNull(hostname); this.nodeType = nodeType; this.hostname = hostname; - this.portsMap = new HashMap<>(); - for (ServicePort port : ports) { - portsMap.put(port.getType(), port); + this.ports = new HashMap<>(); + for (ServicePort port : portList) { + ports.put(port.getType(), port.getValue()); } } @@ -85,11 +101,11 @@ public final class ServiceInfo { } /** - * Returns the list of port which the service listens to. - * @return List + * Returns ServicePort.Type to port mappings. + * @return ports */ - public List getPorts() { - return portsMap.values().parallelStream().collect(Collectors.toList()); + public Map getPorts() { + return ports; } /** @@ -99,8 +115,9 @@ public final class ServiceInfo { * @param type the type of port. * ex: RPC, HTTP, HTTPS, etc.. */ + @JsonIgnore public int getPort(ServicePort.Type type) { - return portsMap.get(type).getValue(); + return ports.get(type); } /** @@ -108,12 +125,20 @@ public final class ServiceInfo { * * @return KeySpaceManagerProtocolProtos.ServiceInfo */ + @JsonIgnore public KeySpaceManagerProtocolProtos.ServiceInfo getProtobuf() { KeySpaceManagerProtocolProtos.ServiceInfo.Builder builder = KeySpaceManagerProtocolProtos.ServiceInfo.newBuilder(); builder.setNodeType(nodeType) .setHostname(hostname) - .addAllServicePorts(portsMap.values()); + .addAllServicePorts( + ports.entrySet().stream() + .map( + entry -> + ServicePort.newBuilder() + .setType(entry.getKey()) + .setValue(entry.getValue()).build()) + .collect(Collectors.toList())); return builder.build(); } @@ -122,6 +147,7 @@ public final class ServiceInfo { * * @return {@link ServiceInfo} */ + @JsonIgnore public static ServiceInfo getFromProtobuf( KeySpaceManagerProtocolProtos.ServiceInfo serviceInfo) { return new ServiceInfo(serviceInfo.getNodeType(), @@ -129,6 +155,26 @@ public final class ServiceInfo { serviceInfo.getServicePortsList()); } + /** + * Returns a JSON string of this object. + * + * @return String - json string + * @throws IOException + */ + public String toJsonString() throws IOException { + return WRITER.writeValueAsString(this); + } + + /** + * Parse a JSON string into ServiceInfo Object. + * + * @param jsonString Json String + * @return BucketInfo + * @throws IOException + */ + public static BucketInfo parse(String jsonString) throws IOException { + return READER.readValue(jsonString); + } /** * Creates a new builder to build {@link ServiceInfo}. @@ -145,7 +191,7 @@ public final class ServiceInfo { private NodeType node; private String host; - private List ports = new ArrayList<>(); + private List portList = new ArrayList<>(); /** @@ -174,7 +220,7 @@ public final class ServiceInfo { * @return the builder */ public Builder addServicePort(ServicePort servicePort) { - ports.add(servicePort); + portList.add(servicePort); return this; } @@ -184,7 +230,7 @@ public final class ServiceInfo { * @return {@link ServiceInfo} */ public ServiceInfo build() { - return new ServiceInfo(node, host, ports); + return new ServiceInfo(node, host, portList); } } http://git-wip-us.apache.org/repos/asf/hadoop/blob/45118257/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManager.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManager.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManager.java index 359dad7..cb960f5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManager.java @@ -173,7 +173,7 @@ public class KeySpaceManager extends ServiceRuntimeInfoImpl metrics = KSMMetrics.create(); keyManager = new KeyManagerImpl(scmBlockClient, metadataManager, configuration); - httpServer = new KeySpaceManagerHttpServer(configuration); + httpServer = new KeySpaceManagerHttpServer(configuration, this); } /** @@ -785,6 +785,11 @@ public class KeySpaceManager extends ServiceRuntimeInfoImpl return "" + ksmRpcAddress.getPort(); } + @VisibleForTesting + public KeySpaceManagerHttpServer getHttpServer() { + return httpServer; + } + @Override public List getServiceList() throws IOException { // When we implement multi-home this call has to be handled properly. http://git-wip-us.apache.org/repos/asf/hadoop/blob/45118257/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManagerHttpServer.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManagerHttpServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManagerHttpServer.java index 395c782..b229c89 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManagerHttpServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/KeySpaceManagerHttpServer.java @@ -19,6 +19,7 @@ package org.apache.hadoop.ozone.ksm; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.ozone.OzoneConfigKeys; +import org.apache.hadoop.ozone.OzoneConsts; import org.apache.hadoop.ozone.web.OzoneHttpServer; import java.io.IOException; @@ -28,8 +29,11 @@ import java.io.IOException; */ public class KeySpaceManagerHttpServer extends OzoneHttpServer { - public KeySpaceManagerHttpServer(Configuration conf) throws IOException { + public KeySpaceManagerHttpServer(Configuration conf, KeySpaceManager ksm) + throws IOException { super(conf, "ksm"); + addServlet("serviceList", "/serviceList", ServiceListJSONServlet.class); + getWebAppContext().setAttribute(OzoneConsts.KSM_CONTEXT_ATTRIBUTE, ksm); } @Override protected String getHttpAddressKey() { http://git-wip-us.apache.org/repos/asf/hadoop/blob/45118257/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/ServiceListJSONServlet.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/ServiceListJSONServlet.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/ServiceListJSONServlet.java new file mode 100644 index 0000000..34a80ce --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/ksm/ServiceListJSONServlet.java @@ -0,0 +1,103 @@ +/** + * 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.hadoop.ozone.ksm; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +import org.apache.hadoop.ozone.OzoneConsts; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + + +/** + * Provides REST access to Ozone Service List. + *

+ * This servlet generally will be placed under the /serviceList URL of + * KeySpaceManager HttpServer. + * + * The return format is of JSON and in the form + *

+ *

+ *  {
+ *    "services" : [
+ *      {
+ *        "NodeType":"KSM",
+ *        "Hostname" "$hostname",
+ *        "ports" : {
+ *          "$PortType" : "$port",
+ *          ...
+ *        }
+ *      }
+ *    ]
+ *  }
+ *  
+ *

+ * + */ +public class ServiceListJSONServlet extends HttpServlet { + + private static final Logger LOG = + LoggerFactory.getLogger(ServiceListJSONServlet.class); + private static final long serialVersionUID = 1L; + + private KeySpaceManager ksm; + + public void init() throws ServletException { + this.ksm = (KeySpaceManager) getServletContext() + .getAttribute(OzoneConsts.KSM_CONTEXT_ATTRIBUTE); + } + + /** + * Process a GET request for the specified resource. + * + * @param request + * The servlet request we are processing + * @param response + * The servlet response we are creating + */ + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) { + try { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.enable(SerializationFeature.INDENT_OUTPUT); + response.setContentType("application/json; charset=utf8"); + PrintWriter writer = response.getWriter(); + try { + writer.write(objectMapper.writeValueAsString(ksm.getServiceList())); + } finally { + if (writer != null) { + writer.close(); + } + } + } catch (IOException e) { + LOG.error( + "Caught an exception while processing ServiceList request", e); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + } + } + +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/45118257/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/OzoneHttpServer.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/OzoneHttpServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/OzoneHttpServer.java index 74105aa..b6a8fda 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/OzoneHttpServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/OzoneHttpServer.java @@ -25,9 +25,11 @@ import org.apache.hadoop.http.HttpConfig; import org.apache.hadoop.http.HttpServer2; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.ozone.client.OzoneClientUtils; +import org.eclipse.jetty.webapp.WebAppContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.servlet.http.HttpServlet; import java.io.IOException; import java.net.InetSocketAddress; @@ -80,6 +82,25 @@ public abstract class OzoneHttpServer { } + /** + * Add a servlet to OzoneHttpServer. + * @param servletName The name of the servlet + * @param pathSpec The path spec for the servlet + * @param clazz The servlet class + */ + protected void addServlet(String servletName, String pathSpec, + Class clazz) { + httpServer.addServlet(servletName, pathSpec, clazz); + } + + /** + * Returns the WebAppContext associated with this HttpServer. + * @return WebAppContext + */ + protected WebAppContext getWebAppContext() { + return httpServer.getWebAppContext(); + } + protected InetSocketAddress getBindAddress(String bindHostKey, String addressKey, String bindHostDefault, int bindPortdefault) { final Optional bindHost = http://git-wip-us.apache.org/repos/asf/hadoop/blob/45118257/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/ksm/TestKeySpaceManagerHttpServer.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/ksm/TestKeySpaceManagerHttpServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/ksm/TestKeySpaceManagerHttpServer.java index d16d251..c64f9e5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/ksm/TestKeySpaceManagerHttpServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/ksm/TestKeySpaceManagerHttpServer.java @@ -99,7 +99,7 @@ public class TestKeySpaceManagerHttpServer { InetSocketAddress addr = InetSocketAddress.createUnresolved("localhost", 0); KeySpaceManagerHttpServer server = null; try { - server = new KeySpaceManagerHttpServer(conf); + server = new KeySpaceManagerHttpServer(conf, null); server.start(); Assert.assertTrue(implies(policy.isHttpEnabled(), http://git-wip-us.apache.org/repos/asf/hadoop/blob/45118257/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/ksm/TestKeySpaceManagerRestInterface.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/ksm/TestKeySpaceManagerRestInterface.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/ksm/TestKeySpaceManagerRestInterface.java new file mode 100644 index 0000000..c719356 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/ksm/TestKeySpaceManagerRestInterface.java @@ -0,0 +1,113 @@ +/** + * 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.hadoop.ozone.ksm; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.type.TypeReference; +import org.apache.hadoop.conf.OzoneConfiguration; +import org.apache.hadoop.net.NetUtils; +import org.apache.hadoop.ozone.MiniOzoneClassicCluster; +import org.apache.hadoop.ozone.MiniOzoneCluster; +import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.client.OzoneClientUtils; +import org.apache.hadoop.ozone.ksm.helpers.ServiceInfo; +import org.apache.hadoop.ozone.protocol.proto.KeySpaceManagerProtocolProtos; +import org.apache.hadoop.ozone.protocol.proto.OzoneProtos; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * This class is to test the REST interface exposed by KeySpaceManager. + */ +public class TestKeySpaceManagerRestInterface { + + private static MiniOzoneCluster cluster; + private static OzoneConfiguration conf; + + @BeforeClass + public static void setUp() throws Exception { + conf = new OzoneConfiguration(); + cluster = new MiniOzoneClassicCluster.Builder(conf) + .setHandlerType(OzoneConsts.OZONE_HANDLER_DISTRIBUTED) + .setClusterId(UUID.randomUUID().toString()) + .setScmId(UUID.randomUUID().toString()) + .build(); + } + + @AfterClass + public static void tearDown() throws Exception { + if (cluster != null) { + cluster.close(); + } + } + + @Test + public void testGetServiceList() throws Exception { + KeySpaceManagerHttpServer server = + cluster.getKeySpaceManager().getHttpServer(); + HttpClient client = HttpClients.createDefault(); + String connectionUri = "http://" + + NetUtils.getHostPortString(server.getHttpAddress()); + HttpGet httpGet = new HttpGet(connectionUri + "/serviceList"); + HttpResponse response = client.execute(httpGet); + String serviceListJson = EntityUtils.toString(response.getEntity()); + + ObjectMapper objectMapper = new ObjectMapper(); + TypeReference> serviceInfoReference = + new TypeReference>() {}; + List serviceInfos = objectMapper.readValue( + serviceListJson, serviceInfoReference); + Map serviceMap = new HashMap<>(); + for (ServiceInfo serviceInfo : serviceInfos) { + serviceMap.put(serviceInfo.getNodeType(), serviceInfo); + } + + InetSocketAddress ksmAddress = + OzoneClientUtils.getKsmAddressForClients(conf); + ServiceInfo ksmInfo = serviceMap.get(OzoneProtos.NodeType.KSM); + + Assert.assertEquals(ksmAddress.getHostName(), ksmInfo.getHostname()); + Assert.assertEquals(ksmAddress.getPort(), + ksmInfo.getPort(KeySpaceManagerProtocolProtos.ServicePort.Type.RPC)); + Assert.assertEquals(server.getHttpAddress().getPort(), + ksmInfo.getPort(KeySpaceManagerProtocolProtos.ServicePort.Type.HTTP)); + + InetSocketAddress scmAddress = + OzoneClientUtils.getScmAddressForClients(conf); + ServiceInfo scmInfo = serviceMap.get(OzoneProtos.NodeType.SCM); + + Assert.assertEquals(scmAddress.getHostName(), scmInfo.getHostname()); + Assert.assertEquals(scmAddress.getPort(), + scmInfo.getPort(KeySpaceManagerProtocolProtos.ServicePort.Type.RPC)); + } + +} --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org