Table of Contents |
---|
Related JIRAs
Jira | ||||||
---|---|---|---|---|---|---|
|
Jira | ||||||
---|---|---|---|---|---|---|
|
Goal
Currently, the Admin API allows management and access to topologies, descriptors, and provider configurations but does not provide access to the Service Definitions for the proxied services.
The goal is to expand the Admin API to include service definitions and allow for customization through the API: we should be able to create, read, update and delete service definitions including both service and rewrite XML files. Changes made via the new API should target topology file redeployment that is referencing the changed service definition.
How to fetch service definitions
...
- service descriptor: identifies and described describes the service with name/role/version. This is specified in a file named
service.xml
underGATEYAY_DATA_DIR/services/$service/$version
folder. - rules: specifies the list of rewrite rules - read from rewrite.xml - belong to the given service/role/version. This is optional, in case there are no rewrite rules for the given service you will not see any XML element/JSON data with the name '
rules'
.
All of the below fetch operations will provide you a result with the following structure:
- as XML
Code Block |
---|
<serviceDefinitions> |
...
<serviceDefinition> |
...
<service name="..." role="..." version="..."> |
...
... |
...
</service> |
...
<rules> |
...
... |
...
</rules> |
...
</serviceDefinition> |
...
<serviceDefinition> |
...
... |
...
<serviceDefinition> |
...
... |
...
</serviceDefinitions> |
- as JSON
Code Block |
---|
...
{ |
...
...
"serviceDefinitions" : { |
...
...
|
...
"serviceDefinition" : [ { |
...
"service" : { |
...
...
"name" : "...", |
...
...
|
...
"role" : "...", |
...
...
"version" : "...", |
...
... |
...
...
}, |
...
...
"rules" : { |
...
...
... |
...
...
} |
...
}, { |
...
...
|
...
"service" : { |
...
...
}, |
...
"rules" : { |
...
...
} ] |
...
} |
...
} |
To read an existing service definition or a list of service definitions you should send a GET request to one of the following REST API endpoints:
Fetching all service definitions
...
https://{gateway-host}:{gateway-port}/{gateway-path}/admin/api/v1/servicedefinitions
Sample:
Code Block |
---|
$ curl -ku admin: |
...
*** -H "Accept: application/json" -X GET 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/' { "serviceDefinitions" : { "serviceDefinition" : [ { "service" : { "name" : "ambari", "role" : "AMBARI", "version" : "0.2.2.0", "routes" : { "route" : [ { "path" : "/ambari/api/v1/**", "rewrite" : [ { "apply" : "AMBARI/ambari/api/outbound", "to" : "response.body" }, { "apply" : "AMBARI/ambari/api/inbound", "to" : "request.body" } ] }, { "path" : "/ambari/api/v1/persist/*?*", "rewrite" : [ { "apply" : "AMBARI/ambari/api/inbound", "to" : "request.body" } ] } ] } }, "rules" : { "rule" : { "dir" : "IN", "name" : "AMBARI/ambari/inbound", "pattern" : "*://*:*/**/ambari/api/v1/{**}?{**}", "rewrite" : { "template" : "{$serviceUrl[AMBARI]}/api/v1/{**}?{**}" } }, "rule" : { "dir" : "OUT", "name" : "AMBARI/ambari/href/outbound", "match" : { "pattern" : "*://*:*/api/{**}?{**}" }, "rewrite" : { "template" : "{$frontend[url]}/ambari/api/{**}?{**}" } }, "rule" : { "dir" : "OUT", "name" : "AMBARI/ambari/context_path/outbound", "match" : { "pattern" : "/{**}" }, "rewrite" : { "template" : "{$frontend[path]}/ambari/{**}" } }, "filter" : { "name" : "AMBARI/ambari/api/outbound", "content" : { "asType" : "application/json", "type" : "text/plain", "apply" : { "path" : "$.**.href", "rule" : "AMBARI/ambari/href/outbound" }, "apply" : { "path" : "$.**.href", "rule" : "AMBARI/ambari/href/outbound" }, "apply" : { "path" : "$.**.context_path", "rule" : "AMBARI/ambari/context_path/outbound" } } }, "filter" : { "name" : "AMBARI/ambari/api/inbound", "content" : { "asType" : "application/octet-stream", "type" : "application/x-www-form-urlencoded" } } } }, { "service" : { "name" : "ambari", "role" : "AMBARI", "version" : "2.2.0", "dispatch" : { "classname" : "org.apache.knox.gateway.dispatch.PassAllHeadersNoEncodingDispatch", "use-two-way-ssl" : false, "param" : [ ] }, ... }, { "service" : { "name" : "zeppelinws", "role" : "ZEPPELINWS", "version" : "0.8.1", "routes" : { "route" : [ { "path" : "/zeppelin/ws", "rewrite" : [ { "apply" : "ZEPPELINWS/zeppelin/ws/inbound", "to" : "request.url" } ] }, { "path" : "/zeppelin/ws**", "rewrite" : [ { "apply" : "ZEPPELINWS/zeppelin/inbound", "to" : "request.url" } ] } ] } }, "rules" : { "rule" : { "dir" : "IN", "name" : "ZEPPELINWS/zeppelin/ws/inbound", "pattern" : "*://*:*/**/ws", "rewrite" : { "template" : "{$serviceUrl[ZEPPELINWS]}/ws" } }, "rule" : { "dir" : "IN", "name" : "ZEPPELINWS/zeppelin/inbound", "pattern" : "*://*:*/**/ws{**}", "rewrite" : { "template" : "{$serviceUrl[ZEPPELINWS]}/ws{**}" } } } } ] } |
Fetching all service definitions for a particular service
...
https://{gateway-host}:{gateway-port}/{gateway-path}/admin/api/v1/servicedefinitions/{serviceName}
Sample:
Code Block |
---|
$ curl -ku admin:*** -H "Accept: application/json" -X GET 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/atlas-api' { "serviceDefinitions" : { "serviceDefinition" : [ { "service" : { "name" : "atlas-api", "role" : "ATLAS-API", "version" : "0.1.2.0", "dispatch" : { "classname" : "org.apache.knox.gateway.dispatch.DefaultDispatch", "ha-classname" : "org.apache.knox.gateway.ha.dispatch.AtlasApiTrustedProxyHaDispatch", "use-two-way-ssl" : false, "param" : [ ] }, "routes" : { "route" : [ { "path" : "/atlas/api/**" } ] } }, "rules" : { "rule" : { "dir" : "OUT", "name" : "ATLAS-API/atlas/outbound", "pattern" : "hdfs://{host}/{path=**}?{**}", "rewrite" : { "template" : "hdfs://{host}/{path=**}?{**}" } }, "rule" : { "dir" : "IN", "name" : "ATLAS-API/atlas/inbound", "pattern" : "*://*:*/**/atlas/api/{path=**}?{**}", "rewrite" : { "template" : "{$serviceUrl[ATLAS-API]}/api/{path=**}?{**}" } } } }, { "service" : { "name" : "atlas-api", "role" : "ATLAS-API", "version" : "2.0.0", "dispatch" : { "classname" : "org.apache.knox.gateway.dispatch.DefaultDispatch", "ha-classname" : "org.apache.knox.gateway.ha.dispatch.AtlasApiTrustedProxyHaDispatch", "use-two-way-ssl" : false, "param" : [ ] }, "routes" : { "route" : [ { "path" : "/atlas/api/**" } ] } }, "rules" : { "rule" : { "dir" : "OUT", "name" : "ATLAS-API/atlas/outbound", "pattern" : "hdfs://{host}/{path=**}?{**}", "rewrite" : { "template" : "hdfs://{host}/{path=**}?{**}" } }, "rule" : { "dir" : "IN", "name" : "ATLAS-API/atlas/inbound", "pattern" : "*://*:*/**/atlas/api/{path=**}?{**}", "rewrite" : { "template" : "{$serviceUrl[ATLAS-API]}/api/{path=**}?{**}" } } } }, { "service" : { "name" : "atlas-api", "role" : "ATLAS-API", "version" : "0.8.0", "dispatch" : { "classname" : "org.apache.knox.gateway.dispatch.PassAllHeadersDispatch", "ha-classname" : "org.apache.knox.gateway.ha.dispatch.AtlasApiHaDispatch", "use-two-way-ssl" : false, "param" : [ ] }, "policies" : { "policy" : [ { "role" : "webappsec" }, { "name" : "Anonymous", "role" : "authentication" }, { "role" : "rewrite" }, { "role" : "authorization" } ] }, "routes" : { "route" : [ { "path" : "/atlas/api/**" } ] } }, "rules" : { "rule" : { "dir" : "OUT", "name" : "ATLAS-API/atlas/outbound", "pattern" : "hdfs://{host}/{path=**}?{**}", "rewrite" : { "template" : "hdfs://{host}/{path=**}?{**}" } }, "rule" : { "dir" : "IN", "name" : "ATLAS-API/atlas/inbound", "pattern" : "*://*:*/**/atlas/api/{path=**}?{**}", "rewrite" : { "template" : "{$serviceUrl[ATLAS-API]}/api/{path=**}?{**}" } } } } ] } |
Fetching all service definitions for a particular service and role
...
https://{gateway-host}:{gateway-port}/{gateway-path}/admin/api/v1/servicedefinitions/{serviceName}/{roleName}
Sample: curl -ku admin:*** -H "Accept: application/json" -X GET 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/atlas-api/atlas-api'
generates the same output as above for the atlas-api
service since it only has atlas-api
role with different versions
Fetching a service definition for a particular service, role, and version
...
https://{gateway-host}:{gateway-port}/{gateway-path}/admin/api/v1/servicedefinitions/{serviceName}/{roleName}/{version}
Sample:
Code Block |
---|
$ curl -ku admin:admin-password -H "Accept: application/json" -X GET 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/atlas-api/atlas-api/2.0.0' { "serviceDefinitions" : { "serviceDefinition" : [ { "service" : { "name" : "atlas-api", "role" : "ATLAS-API", "version" : "2.0.0", "dispatch" : { "classname" : "org.apache.knox.gateway.dispatch.DefaultDispatch", "ha-classname" : "org.apache.knox.gateway.ha.dispatch.AtlasApiTrustedProxyHaDispatch", "use-two-way-ssl" : false, "param" : [ ] }, "routes" : { "route" : [ { "path" : "/atlas/api/**" } ] } }, "rules" : { "rule" : { "dir" : "OUT", "name" : "ATLAS-API/atlas/outbound", "pattern" : "hdfs://{host}/{path=**}?{**}", "rewrite" : { "template" : "hdfs://{host}/{path=**}?{**}" } }, "rule" : { "dir" : "IN", "name" : "ATLAS-API/atlas/inbound", "pattern" : "*://*:*/**/atlas/api/{path=**}?{**}", "rewrite" : { "template" : "{$serviceUrl[ATLAS-API]}/api/{path=**}?{**}" } } } } ] } } |
How to add a new service definition
How to update existing service definitions
...