-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KNOX-2914 - Ozone HttpFS integration for Apache Knox (#765)
- Loading branch information
1 parent
017242a
commit 6b5de54
Showing
5 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
...ache/knox/gateway/topology/discovery/cm/model/ozone/OzoneHttpfsServiceModelGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../knox/gateway/topology/discovery/cm/model/ozone/OzoneHttpfsServiceModelGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
gateway-service-definitions/src/main/resources/services/ozone-httpfs/1.4.0/rewrite.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
38 changes: 38 additions & 0 deletions
38
gateway-service-definitions/src/main/resources/services/ozone-httpfs/1.4.0/service.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |