You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by am...@apache.org on 2023/06/21 10:39:57 UTC

[knox] branch master updated: KNOX-2914 - Ozone HttpFS integration for Apache Knox (#765)

This is an automated email from the ASF dual-hosted git repository.

amagyar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 6b5de546e KNOX-2914 - Ozone HttpFS integration for Apache Knox (#765)
6b5de546e is described below

commit 6b5de546edbf375046f465f2da836f90514d44b9
Author: muskan1012 <55...@users.noreply.github.com>
AuthorDate: Wed Jun 21 16:09:51 2023 +0530

    KNOX-2914 - Ozone HttpFS integration for Apache Knox (#765)
---
 .../ozone/OzoneHttpfsServiceModelGenerator.java    | 79 ++++++++++++++++++++++
 ...way.topology.discovery.cm.ServiceModelGenerator |  1 +
 .../OzoneHttpfsServiceModelGeneratorTest.java      | 55 +++++++++++++++
 .../services/ozone-httpfs/1.4.0/rewrite.xml        | 23 +++++++
 .../services/ozone-httpfs/1.4.0/service.xml        | 38 +++++++++++
 5 files changed, 196 insertions(+)

diff --git a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/ozone/OzoneHttpfsServiceModelGenerator.java b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/ozone/OzoneHttpfsServiceModelGenerator.java
new file mode 100644
index 000000000..8f7b78239
--- /dev/null
+++ b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/ozone/OzoneHttpfsServiceModelGenerator.java
@@ -0,0 +1,79 @@
+/*
+ * 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.knox.gateway.topology.discovery.cm.model.ozone;
+
+import com.cloudera.api.swagger.client.ApiException;
+import com.cloudera.api.swagger.model.ApiConfigList;
+import com.cloudera.api.swagger.model.ApiRole;
+import com.cloudera.api.swagger.model.ApiService;
+import com.cloudera.api.swagger.model.ApiServiceConfig;
+import org.apache.knox.gateway.topology.discovery.cm.ServiceModel;
+import org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGenerator;
+
+import java.util.Locale;
+
+public class OzoneHttpfsServiceModelGenerator extends AbstractServiceModelGenerator {
+
+    public static final String SERVICE      = "OZONE-HTTPFS";
+    public static final String SERVICE_TYPE = "OZONE";
+    public static final String ROLE_TYPE    = "HTTPFS_GATEWAY";
+
+
+    static final String SSL_ENABLED = "ssl_enabled";
+
+    static final String HTTP_PORT   = "ozone.httpfs.http-port";
+
+
+    @Override
+    public String getService() {
+        return SERVICE;
+    }
+
+    @Override
+    public String getServiceType() {
+        return SERVICE_TYPE;
+    }
+
+    @Override
+    public String getRoleType() {
+        return ROLE_TYPE;
+    }
+
+    @Override
+    public ServiceModel.Type getModelType() {
+        return ServiceModel.Type.API;
+    }
+
+    @Override
+    public ServiceModel generateService(ApiService       service,
+                                        ApiServiceConfig serviceConfig,
+                                        ApiRole          role,
+                                        ApiConfigList    roleConfig) throws ApiException {
+        String hostname = role.getHostRef().getHostname();
+
+        boolean sslEnabled = Boolean.parseBoolean(getRoleConfigValue(roleConfig, SSL_ENABLED));
+        String scheme = sslEnabled ? "https" : "http";
+        String port = getRoleConfigValue(roleConfig, HTTP_PORT);
+
+        ServiceModel model = createServiceModel(String.format(Locale.getDefault(), "%s://%s:%s/webhdfs/", scheme, hostname, port));
+        model.addRoleProperty(getRoleType(),SSL_ENABLED, getRoleConfigValue(roleConfig, SSL_ENABLED));
+        model.addRoleProperty(getRoleType(), HTTP_PORT, getRoleConfigValue(roleConfig, HTTP_PORT));
+
+        return model;
+    }
+
+}
\ No newline at end of file
diff --git a/gateway-discovery-cm/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator b/gateway-discovery-cm/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator
index 72de48d17..dbea07ab1 100644
--- a/gateway-discovery-cm/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator
+++ b/gateway-discovery-cm/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator
@@ -57,5 +57,6 @@ org.apache.knox.gateway.topology.discovery.cm.model.cm.ClouderaManagerUIServiceM
 org.apache.knox.gateway.topology.discovery.cm.model.ozone.OzoneServiceModelGenerator
 org.apache.knox.gateway.topology.discovery.cm.model.ozone.ReconServiceModelGenerator
 org.apache.knox.gateway.topology.discovery.cm.model.ozone.SCMServiceModelGenerator
+org.apache.knox.gateway.topology.discovery.cm.model.ozone.OzoneHttpfsServiceModelGenerator
 
 
diff --git a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/ozone/OzoneHttpfsServiceModelGeneratorTest.java b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/ozone/OzoneHttpfsServiceModelGeneratorTest.java
new file mode 100644
index 000000000..da9856eed
--- /dev/null
+++ b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/ozone/OzoneHttpfsServiceModelGeneratorTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.knox.gateway.topology.discovery.cm.model.ozone;
+
+import org.apache.knox.gateway.topology.discovery.cm.ServiceModelGenerator;
+import org.apache.knox.gateway.topology.discovery.cm.model.AbstractServiceModelGeneratorTest;
+
+import org.junit.Test;
+
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class OzoneHttpfsServiceModelGeneratorTest extends AbstractServiceModelGeneratorTest {
+
+    @Test
+    public void testServiceModelMetadata() {
+        final Map<String, String> serviceConfig = new HashMap<>();
+        final Map<String, String> roleConfig = new HashMap<>();
+        roleConfig.put(OzoneHttpfsServiceModelGenerator.SSL_ENABLED, "true");
+        roleConfig.put(OzoneHttpfsServiceModelGenerator.HTTP_PORT, "9778");
+
+        validateServiceModel(createServiceModel(serviceConfig, roleConfig), serviceConfig, roleConfig);
+    }
+
+    @Override
+    protected String getServiceType() {
+        return OzoneHttpfsServiceModelGenerator.SERVICE_TYPE;
+    }
+
+    @Override
+    protected String getRoleType() {
+        return OzoneHttpfsServiceModelGenerator.ROLE_TYPE;
+    }
+
+    @Override
+    protected ServiceModelGenerator newGenerator() {
+        return new OzoneHttpfsServiceModelGenerator();
+    }
+
+}
diff --git a/gateway-service-definitions/src/main/resources/services/ozone-httpfs/1.4.0/rewrite.xml b/gateway-service-definitions/src/main/resources/services/ozone-httpfs/1.4.0/rewrite.xml
new file mode 100644
index 000000000..63ee36423
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/ozone-httpfs/1.4.0/rewrite.xml
@@ -0,0 +1,23 @@
+<!-- 
+   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.
+ -->
+<rules>
+    <rule dir="IN" name="OZONE-HTTPFS/httpfs/inbound/root" pattern="*://*:*/**/httpfs/{version}/?{**}">
+        <rewrite template="{$serviceUrl[OZONE-HTTPFS]}/{version}/?{**}"/>
+    </rule>
+    <filter name="OZONE-HTTPFS/httpfs/outbound/headers">
+    </filter>
+</rules>
\ No newline at end of file
diff --git a/gateway-service-definitions/src/main/resources/services/ozone-httpfs/1.4.0/service.xml b/gateway-service-definitions/src/main/resources/services/ozone-httpfs/1.4.0/service.xml
new file mode 100644
index 000000000..d09bcebff
--- /dev/null
+++ b/gateway-service-definitions/src/main/resources/services/ozone-httpfs/1.4.0/service.xml
@@ -0,0 +1,38 @@
+<!-- 
+   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.
+ -->
+<service role="OZONE-HTTPFS" name="ozone-httpfs" version="1.4.0">
+    <metadata>
+        <type>API</type>
+        <context>/httpfs</context>
+        <shortDesc>Ozone HttpFS Gateway</shortDesc>
+    </metadata>
+    <routes>
+        <route path="/httpfs/v1/?**">
+            <rewrite apply="OZONE-HTTPFS/httpfs/inbound/root" to="request.url"/>
+        </route>
+        <route path="/httpfs/v1/**?**">
+            <rewrite apply="OZONE-HTTPFS/httpfs/outbound/headers" to="response.headers"/>
+            <rewrite apply="OZONE-HTTPFS/httpfs/outbound/headers" to="response.body"/>
+        </route>
+        <route path="/httpfs/v1/~/**?**">
+            <rewrite apply="OZONE-HTTPFS/httpfs/outbound/headers" to="response.headers"/>
+        </route>
+    </routes>
+    <testURLs>
+        <testURL>/httpfs/v1/?op=LISTSTATUS</testURL>
+    </testURLs>
+</service>
\ No newline at end of file