Skip to content

Commit

Permalink
KNOX-2914 - Ozone HttpFS integration for Apache Knox (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
muskan1012 authored Jun 21, 2023
1 parent 017242a commit 6b5de54
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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


Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 6b5de54

Please sign in to comment.