Table of Contents |
---|
Related JIRAs
Jira | ||||||
---|---|---|---|---|---|---|
|
...
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
...
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
Important note: in case you are fetching a non-existing service definition you will receive an empty list of service definitions along with an HTTP response with 200 response code. For instance:
Code Block |
---|
$ curl -iku admin:*** -H "Accept: application/json" -X GET 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/nonExistingService'
HTTP/1.1 200 OK
Date: Tue, 19 Nov 2019 12:56:52 GMT
Set-Cookie: KNOXSESSIONID=node014vzonbq60zjn19nnzpveqsiw316.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 12:56:52 GMT
Content-Type: application/json
Content-Length: 68
Server: Jetty(9.4.22.v20191022)
{
"serviceDefinitions" : {
"serviceDefinition" : [ ]
}
} |
How to add a new service definition
The https://{gateway-host}:{gateway-port}/{gateway-path}/admin/api/v1/servicedefinitions
endpoint accepts POST requests to create a brand new service definition. In case the service definition you are trying to create exists already an HTTP response with 500 error code will be returned.
Sample:
Code Block |
---|
$ curl -H "Content-Type: application/xml" -iku admin:*** -d "@testServiceDefinitionPayload.xml" -X POST 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions'
HTTP/1.1 100 Continue
HTTP/1.1 201 Created
Date: Tue, 19 Nov 2019 13:01:29 GMT
Set-Cookie: KNOXSESSIONID=node0cyn7v4caqbpk1wsou1qmdq1qb17.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 13:01:29 GMT
Location: https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mySampleService/MYSAMPLEROLE/2.0.0
Content-Length: 0
Server: Jetty(9.4.22.v20191022)
$ curl -H "Content-Type: application/xml" -iku admin:*** -d "@testServiceDefinitionPayload.xml" -X POST 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions'
HTTP/1.1 100 Continue
HTTP/1.1 500 Internal Server Error
Date: Tue, 19 Nov 2019 13:01:36 GMT
Set-Cookie: KNOXSESSIONID=node0i9vn469u6vjkinkf8wh9hrk418.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 13:01:36 GMT
Content-Type: application/json
Content-Length: 111
Server: Jetty(9.4.22.v20191022)
{ "CREATION_ERROR": "The requested service definition (mySampleService, MYSAMPLEROLE, 2.0.0) already exists!" } |
How to update existing service definitions
In order to update the existing service definition(s), you need to use the same endpoint as you used above for service definition creation but you should issue a PUT request.
Sample (please note that I kept the previously added mySampleService, MYSAMPLEROLE, 2.0.0 for testing purposes):
Code Block |
---|
$ curl -H "Content-Type: application/xml" -iku admin:*** -d "@testServiceDefinitionPayload.xml" -X PUT 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions'
HTTP/1.1 100 Continue
HTTP/1.1 201 Created
Date: Tue, 19 Nov 2019 13:08:20 GMT
Set-Cookie: KNOXSESSIONID=node0h67f7dq41ydl8ci18t41vld319.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 13:08:20 GMT
Location: https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mySampleService/MYSAMPLEROLE/2.0.0
Content-Length: 0
Server: Jetty(9.4.22.v20191022) |
How to delete an existing service definition
The https://{gateway-host}:{gateway-port}/{gateway-path}/admin/api/v1/servicedefinitions/{service}/{role}/{version}
endpoint accepts DELETE requests to remove an existing service definition. In case the service definition you are trying to delete does not exist an HTTP response with 500 error code will be returned.
Sample:
Code Block |
---|
$ $ curl -H "Content-Type: application/xml" -iku admin:*** -X DELETE 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mysampleservice/mysamplerole/2.0.0'
HTTP/1.1 200 OK
Date: Tue, 19 Nov 2019 13:23:15 GMT
Set-Cookie: KNOXSESSIONID=node015yf04uunrpyjocl05uz4or6k22.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 13:23:15 GMT
Location: https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mysampleservice/mysamplerole/2.0.0
Content-Length: 0
Server: Jetty(9.4.22.v20191022)
$ curl -H "Content-Type: application/xml" -iku admin:admin-password -X DELETE 'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mysampleservice/mysamplerole/2.0.0'
HTTP/1.1 500 Internal Server Error
Date: Tue, 19 Nov 2019 13:23:22 GMT
Set-Cookie: KNOXSESSIONID=node017x14a6arppex10ucm0ooygohp23.node0; Path=/gateway/admin; Secure; HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: rememberMe=deleteMe; Path=/gateway/admin; Max-Age=0; Expires=Mon, 18-Nov-2019 13:23:22 GMT
Content-Type: application/json
Content-Length: 116
Server: Jetty(9.4.22.v20191022)
{ "DELETION_ERROR": "There is no service definition with the given attributes: mysampleservice,mysamplerole,2.0.0" } |
Service Definition Management in the Admin UI
The Admin UI has also been modified to support the previously introduced service definition management features
Service Definition Management in the Admin UI