[ 
https://issues.apache.org/jira/browse/KNOX-2053?focusedWorklogId=333917&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-333917
 ]

ASF GitHub Bot logged work on KNOX-2053:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Oct/19 06:34
            Start Date: 25/Oct/19 06:34
    Worklog Time Spent: 10m 
      Work Description: smolnar82 commented on pull request #164: KNOX-2053 - 
New REST API to create/read/update/delete service definitions
URL: https://github.com/apache/knox/pull/164
 
 
   ## What changes were proposed in this pull request?
   
   The main purpose of this PR is to introduce a new Admin API to the end-users 
to be able to execute CRUD operations on Knox service definitions. As of now, a 
Knox service definition consists of the following two items:
   1. a service descriptor (`service.xml`)
   2. a list of rewrite rules (inbound/outbound) (`rewrite.xml`)
   
   During the implementation, I realized that storing/loading a service 
descriptor (wrongly named as `ServiceDefinition` in Java) was implemented by 
using JAXB annotations whereas the same features for the rewrite rules were 
coded using DOM (see `XmlUrlRewriteRulesImporter` and 
`XmlUrlRewriteRulesExporter` classes). Checking the object tree of 
`org.apache.knox.gateway.filter.rewrite.api.UrlRewriteRulesDescriptor` and the 
complexity of the current implementation suggested that I need to introduce a 
gateway between the two worlds when serializing/de-serializing the HTTP 
responses/requests. As a result, you will see that I added a custom 
`javax.ws.rs.ext.MessageBodyReader` implementation, as well as I, implemented 
an `javax.xml.bind.annotation.adapters.XmlAdapter` to make my changes easy to 
read, understand and maintain.
   
   I also found out that simply adding the existing `gateway-provider-rewrite` 
Maven project as a new dependency on other projects would lead to cyclic 
dependencies. So that a new Maven project got created - 
`gateway-provider-rewrite-common` - where I moved all the required 
interfaces/classes that were necessary to achieve the above-mentioned goal. 
Please note that
   
   - the majority of the changes in the PR is a result of this new project 
creation
   - only the strictly required resources have been moved to the new project 
(there might be a follow-up JIRA to identify possible enhancements in this 
area).
   
   ## How was this patch tested?
   Extending and running JUnit tests:
   ```
   [INFO] 
------------------------------------------------------------------------
   [INFO] BUILD SUCCESS
   [INFO] 
------------------------------------------------------------------------
   [INFO] Total time: 17:47 min (Wall Clock)
   [INFO] Finished at: 2019-10-14T22:44:44+02:00
   [INFO] Final Memory: 390M/2306M
   [INFO] 
------------------------------------------------------------------------
   ```
   Additionally, I ran the following E2E tests.
   
   Sample service definition I used when tested the POST/PUT requests (I simply 
changed the version attribute to submit mulitple versions):
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <serviceDefinition>
       <service name="mySampleService" role="MYSAMPLEROLE" version="1.0.0">
           <dispatch 
classname="org.apache.knox.gateway.dispatch.PassAllHeadersNoEncodingDispatch" 
use-two-way-ssl="false"/>
           <policies>
               <policy role="webappsec"/>
               <policy name="Anonymous" role="authentication"/>
           </policies>
           <routes>
               <route path="/mysamplerole">
                   <rewrite apply="mySampleService/mysamplerole/inbound/root" 
to="request.url"/>
                   <rewrite 
apply="mySampleService/mysamplerole/outbound/mainpage" to="response.body"/>
               </route>
               <route path="/mysamplerole/**">
                   <rewrite apply="mySampleService/mysamplerole/inbound/path" 
to="request.url"/>
               </route>
               <route 
path="/mysamplerole/views/SMARTSENSE/**/assets/hstapp-*.js">
                   <rewrite 
apply="mySampleService/mysamplerole/outbound/apiendpoint" to="response.body"/>
               </route>
           </routes>
       </service>
       <rules>
           <rule dir="IN" name="mySampleService/mysamplerole/inbound/root" 
pattern="*://*:*/**/mysamplerole/">
               <rewrite template="{$serviceUrl[mySampleService]}/"/>
           </rule>
           <rule dir="IN" name="mySampleService/mysamplerole/inbound/path" 
pattern="*://*:*/**/mysamplerole/{**}">
               <rewrite template="{$serviceUrl[mySampleService]}/{**}"/>
           </rule>
           <rule dir="OUT" 
name="mySampleService/mysamplerole/outbound/sitepath">
               <rewrite template="{$frontend[path]}/mysamplerole"/>
           </rule>
           <rule dir="OUT" 
name="mySampleService/mysamplerole/outbound/websocket">
               <rewrite 
template="{$frontend[path]}/mysamplerolews/api/stomp/v1"/>
           </rule>
   
           <filter name="mySampleService/mysamplerole/outbound/apiendpoint">
               <content type="*/x-javascript">
                   <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
               </content>
               <content type="application/javascript">
                   <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
               </content>
           </filter>
           <filter 
name="mySampleService/mysamplerole/outbound/apiendpoint/html">
               <content type="text/html">
                   <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
               </content>
           </filter>
           <filter name="mySampleService/mysamplerole/outbound/mainpage">
               <content type="*/html">
                   <apply path="stylesheets/vendor.css" 
rule="mySampleService/mysamplerole/outbound/vendorcss" />
                   <apply path="stylesheets/app.css" 
rule="mySampleService/mysamplerole/outbound/appcss" />
                   <apply path="javascripts/vendor.js" 
rule="mySampleService/mysamplerole/outbound/vendorjs" />
                   <apply path="javascripts/app.js" 
rule="mySampleService/mysamplerole/outbound/appjs" />
                   <apply path="/img/logo.png" 
rule="mySampleService/mysamplerole/outbound/favicon"/>
                   <apply path="/licenses/NOTICE.txt" 
rule="mySampleService/mysamplerole/outbound/notice"/>
               </content>
           </filter>
       </rules>
   </serviceDefinition>
   ```
   
   I also modified the `sandbox` topology to include my service:
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <topology>
      <uri>https://localhost:8443/gateway/sandbox</uri>
      <name>sandbox</name>
      ...
      <service>
         <role>MYSAMPLEROLE</role>
         <url>http://localhost:8889</url>
      </service>
   </topology>
   ```
   
   Added a service definition for `mySampleService/MYSAMPLEROLE/1.0.0`
   ```
   $ curl -H "Content-Type: application/xml" -iku admin:admin-password -d 
"@testServiceDefinitionPayload.xml" -X POST 
'https://localhost:8443/gateway/admin/api/v1/servicedefinitions'
   HTTP/1.1 100 Continue
   
   HTTP/1.1 201 Created
   Date: Mon, 14 Oct 2019 13:20:18 GMT
   Set-Cookie: KNOXSESSIONID=node016wqn5epso1bk1th8l5i2wy7fh1.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=Sun, 13-Oct-2019 13:20:18 GMT
   Location: 
https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mysampleservice/MYSAMPLEROLE/1.0.0
   Content-Type: application/json
   Content-Length: 68
   Server: Jetty(9.4.20.v20190813)
   ```
   
   Checking if the folders were created with the appropriate content
   ```
   $ ls -al knoxGateway/data/services/mySampleService/
   total 0
   drwxr-xr-x   3 smolnar  staff   102 Oct 14 15:20 .
   drwxr-xr-x@ 53 smolnar  staff  1802 Oct 14 15:20 ..
   drwxr-xr-x   4 smolnar  staff   136 Oct 14 15:20 1.0.0
   
   $ ls -al knoxGateway/data/services/mySampleService/1.0.0/
   total 16
   drwxr-xr-x  4 smolnar  staff   136 Oct 14 15:20 .
   drwxr-xr-x  3 smolnar  staff   102 Oct 14 15:20 ..
   -rw-r--r--  1 smolnar  staff  2055 Oct 14 15:20 rewrite.xml
   -rw-r--r--  1 smolnar  staff   985 Oct 14 15:20 service.xml
   ```
   
   Confirmed (from the `gateway.log`) that topology 'sandbox' got redeployed:
   ```
   2019-10-14 15:20:18,171 INFO  knox.gateway 
(AclsAuthorizationFilter.java:doFilter(105)) - Access Granted: true
   2019-10-14 15:20:18,443 INFO  knox.gateway 
(DefaultTopologyService.java:lambda$2(539)) - Redeploying topology sandbox due 
to service definition change mySampleService / MYSAMPLEROLE / 1.0.0
   2019-10-14 15:20:23,449 INFO  knox.gateway 
(GatewayServer.java:handleCreateDeployment(973)) - Deploying topology sandbox 
to /Users/smolnar/test/knoxGateway/data/deployments/sandbox.topo.16dca6d3650
   2019-10-14 15:20:23,449 INFO  knox.gateway 
(GatewayServer.java:internalDeactivateTopology(892)) - Deactivating topology 
sandbox
   2019-10-14 15:20:23,500 INFO  knox.gateway 
(DefaultGatewayServices.java:initializeContribution(159)) - Credential store 
found for the cluster: sandbox - no need to create one.
   2019-10-14 15:20:25,688 INFO  knox.gateway 
(GatewayServer.java:internalActivateTopology(858)) - Activating topology sandbox
   2019-10-14 15:20:25,689 INFO  knox.gateway 
(GatewayServer.java:internalActivateArchive(868)) - Activating topology sandbox 
archive %2F
   ```
   
   Modified the `version` XML attribute to `2.0.0` in the payload file and 
added a new service definition
   ```
   $ curl -H "Content-Type: application/xml" -iku admin:admin-password -d 
"@testServiceDefinitionPayload.xml" -X PUT 
'https://localhost:8443/gateway/admin/api/v1/servicedefinitions'
   HTTP/1.1 100 Continue
   
   HTTP/1.1 201 Created
   Date: Mon, 14 Oct 2019 13:24:13 GMT
   Set-Cookie: KNOXSESSIONID=node01gdv2e7960eagmkz7yh14vr5f2.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=Sun, 13-Oct-2019 13:24:13 GMT
   Location: 
https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mysampleservice/MYSAMPLEROLE/2.0.0
   Content-Type: application/json
   Content-Length: 68
   Server: Jetty(9.4.20.v20190813)
   ```
   
   Checking if the folders were created with the appropriate content
   ```
   $ ls -al knoxGateway/data/services/mySampleService/
   total 0
   drwxr-xr-x   4 smolnar  staff   136 Oct 14 15:24 .
   drwxr-xr-x@ 53 smolnar  staff  1802 Oct 14 15:20 ..
   drwxr-xr-x   4 smolnar  staff   136 Oct 14 15:20 1.0.0
   drwxr-xr-x   4 smolnar  staff   136 Oct 14 15:24 2.0.0
   
   $ cat knoxGateway/data/services/mySampleService/2.0.0/service.xml 
   <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   <service name="mySampleService" role="MYSAMPLEROLE" version="2.0.0">
       <dispatch 
classname="org.apache.knox.gateway.dispatch.PassAllHeadersNoEncodingDispatch" 
use-two-way-ssl="false"/>
       <policies>
           <policy role="webappsec"/>
           <policy name="Anonymous" role="authentication"/>
       </policies>
       <routes>
           <route path="/mysamplerole">
               <rewrite apply="mySampleService/mysamplerole/inbound/root" 
to="request.url"/>
               <rewrite apply="mySampleService/mysamplerole/outbound/mainpage" 
to="response.body"/>
           </route>
           <route path="/mysamplerole/**">
               <rewrite apply="mySampleService/mysamplerole/inbound/path" 
to="request.url"/>
           </route>
           <route path="/mysamplerole/views/SMARTSENSE/**/assets/hstapp-*.js">
               <rewrite 
apply="mySampleService/mysamplerole/outbound/apiendpoint" to="response.body"/>
           </route>
       </routes>
   </service>
   
   $ cat knoxGateway/data/services/mySampleService/2.0.0/rewrite.xml 
   <rules>
       <rule dir="IN" name="mySampleService/mysamplerole/inbound/root" 
pattern="*://*:*/**/mysamplerole/">
           <rewrite template="{$serviceUrl[mySampleService]}/"/>
       </rule>
       <rule dir="IN" name="mySampleService/mysamplerole/inbound/path" 
pattern="*://*:*/**/mysamplerole/{**}">
           <rewrite template="{$serviceUrl[mySampleService]}/{**}"/>
       </rule>
       <rule dir="OUT" name="mySampleService/mysamplerole/outbound/sitepath">
           <rewrite template="{$frontend[path]}/mysamplerole"/>
       </rule>
       <rule dir="OUT" name="mySampleService/mysamplerole/outbound/websocket">
           <rewrite template="{$frontend[path]}/mysamplerolews/api/stomp/v1"/>
       </rule>
       <filter name="mySampleService/mysamplerole/outbound/apiendpoint">
           <content type="*/x-javascript">
               <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
           </content>
           <content type="application/javascript">
               <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
           </content>
       </filter>
       <filter name="mySampleService/mysamplerole/outbound/apiendpoint/html">
           <content type="text/html">
               <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
           </content>
       </filter>
       <filter name="mySampleService/mysamplerole/outbound/mainpage">
           <content type="*/html">
               <apply path="stylesheets/vendor.css" 
rule="mySampleService/mysamplerole/outbound/vendorcss"/>
               <apply path="stylesheets/app.css" 
rule="mySampleService/mysamplerole/outbound/appcss"/>
               <apply path="javascripts/vendor.js" 
rule="mySampleService/mysamplerole/outbound/vendorjs"/>
               <apply path="javascripts/app.js" 
rule="mySampleService/mysamplerole/outbound/appjs"/>
               <apply path="/img/logo.png" 
rule="mySampleService/mysamplerole/outbound/favicon"/>
               <apply path="/licenses/NOTICE.txt" 
rule="mySampleService/mysamplerole/outbound/notice"/>
           </content>
       </filter>
   </rules>
   ```
   
   Confirmed (from the `gateway.log`) that topology `sandbox` got redeployed
   ```
   2019-10-14 15:24:13,732 INFO  knox.gateway 
(DefaultTopologyService.java:lambda$2(539)) - Redeploying topology sandbox due 
to service definition change mySampleService / MYSAMPLEROLE / 2.0.0
   2019-10-14 15:24:15,966 INFO  knox.gateway 
(GatewayServer.java:handleCreateDeployment(973)) - Deploying topology sandbox 
to /Users/smolnar/test/knoxGateway/data/deployments/sandbox.topo.16dca70cc48
   2019-10-14 15:24:15,967 INFO  knox.gateway 
(GatewayServer.java:internalDeactivateTopology(892)) - Deactivating topology 
sandbox
   2019-10-14 15:24:16,022 INFO  knox.gateway 
(DefaultGatewayServices.java:initializeContribution(159)) - Credential store 
found for the cluster: sandbox - no need to create one.
   2019-10-14 15:24:18,068 INFO  knox.gateway 
(GatewayServer.java:internalActivateTopology(858)) - Activating topology sandbox
   2019-10-14 15:24:18,068 INFO  knox.gateway 
(GatewayServer.java:internalActivateArchive(868)) - Activating topology sandbox 
archive %2F
   ```
   
   Checked the `GET` interface:
   ```
   $ curl -iku admin:admin-password -X GET 
'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mysampleservice'
   HTTP/1.1 200 OK
   Date: Mon, 14 Oct 2019 13:28:21 GMT
   Set-Cookie: KNOXSESSIONID=node01dtizgdsqpgp21xmmgkjrxin2f3.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=Sun, 13-Oct-2019 13:28:21 GMT
   Content-Type: application/xml
   Content-Length: 6620
   Server: Jetty(9.4.20.v20190813)
   
   <?xml version="1.0" encoding="UTF-8"?>
   <serviceDefinitions>
      <serviceDefinition>
         <service name="mySampleService" role="MYSAMPLEROLE" version="1.0.0">
            <dispatch 
classname="org.apache.knox.gateway.dispatch.PassAllHeadersNoEncodingDispatch" 
use-two-way-ssl="false"/>
            <policies>
               <policy role="webappsec"/>
               <policy name="Anonymous" role="authentication"/>
            </policies>
            <routes>
               <route path="/mysamplerole">
                  <rewrite apply="mySampleService/mysamplerole/inbound/root" 
to="request.url"/>
                  <rewrite 
apply="mySampleService/mysamplerole/outbound/mainpage" to="response.body"/>
               </route>
               <route path="/mysamplerole/**">
                  <rewrite apply="mySampleService/mysamplerole/inbound/path" 
to="request.url"/>
               </route>
               <route 
path="/mysamplerole/views/SMARTSENSE/**/assets/hstapp-*.js">
                  <rewrite 
apply="mySampleService/mysamplerole/outbound/apiendpoint" to="response.body"/>
               </route>
            </routes>
         </service>
         <rules>
            <rule dir="IN" name="mySampleService/mysamplerole/inbound/root" 
pattern="*://*:*/**/mysamplerole/">
               <rewrite template="{$serviceUrl[mySampleService]}/"/>
            </rule>
            <rule dir="IN" name="mySampleService/mysamplerole/inbound/path" 
pattern="*://*:*/**/mysamplerole/{**}">
               <rewrite template="{$serviceUrl[mySampleService]}/{**}"/>
            </rule>
            <rule dir="OUT" 
name="mySampleService/mysamplerole/outbound/sitepath">
               <rewrite template="{$frontend[path]}/mysamplerole"/>
            </rule>
            <rule dir="OUT" 
name="mySampleService/mysamplerole/outbound/websocket">
               <rewrite 
template="{$frontend[path]}/mysamplerolews/api/stomp/v1"/>
            </rule>
            <filter name="mySampleService/mysamplerole/outbound/apiendpoint">
               <content type="*/x-javascript">
                  <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
               </content>
               <content type="application/javascript">
                  <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
               </content>
            </filter>
            <filter 
name="mySampleService/mysamplerole/outbound/apiendpoint/html">
               <content type="text/html">
                  <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
               </content>
            </filter>
            <filter name="mySampleService/mysamplerole/outbound/mainpage">
               <content type="*/html">
                  <apply path="stylesheets/vendor.css" 
rule="mySampleService/mysamplerole/outbound/vendorcss"/>
                  <apply path="stylesheets/app.css" 
rule="mySampleService/mysamplerole/outbound/appcss"/>
                  <apply path="javascripts/vendor.js" 
rule="mySampleService/mysamplerole/outbound/vendorjs"/>
                  <apply path="javascripts/app.js" 
rule="mySampleService/mysamplerole/outbound/appjs"/>
                  <apply path="/img/logo.png" 
rule="mySampleService/mysamplerole/outbound/favicon"/>
                  <apply path="/licenses/NOTICE.txt" 
rule="mySampleService/mysamplerole/outbound/notice"/>
               </content>
            </filter>
         </rules>
      </serviceDefinition>
      <serviceDefinition>
         <service name="mySampleService" role="MYSAMPLEROLE" version="2.0.0">
            <dispatch 
classname="org.apache.knox.gateway.dispatch.PassAllHeadersNoEncodingDispatch" 
use-two-way-ssl="false"/>
            <policies>
               <policy role="webappsec"/>
               <policy name="Anonymous" role="authentication"/>
            </policies>
            <routes>
               <route path="/mysamplerole">
                  <rewrite apply="mySampleService/mysamplerole/inbound/root" 
to="request.url"/>
                  <rewrite 
apply="mySampleService/mysamplerole/outbound/mainpage" to="response.body"/>
               </route>
               <route path="/mysamplerole/**">
                  <rewrite apply="mySampleService/mysamplerole/inbound/path" 
to="request.url"/>
               </route>
               <route 
path="/mysamplerole/views/SMARTSENSE/**/assets/hstapp-*.js">
                  <rewrite 
apply="mySampleService/mysamplerole/outbound/apiendpoint" to="response.body"/>
               </route>
            </routes>
         </service>
         <rules>
            <rule dir="IN" name="mySampleService/mysamplerole/inbound/root" 
pattern="*://*:*/**/mysamplerole/">
               <rewrite template="{$serviceUrl[mySampleService]}/"/>
            </rule>
            <rule dir="IN" name="mySampleService/mysamplerole/inbound/path" 
pattern="*://*:*/**/mysamplerole/{**}">
               <rewrite template="{$serviceUrl[mySampleService]}/{**}"/>
            </rule>
            <rule dir="OUT" 
name="mySampleService/mysamplerole/outbound/sitepath">
               <rewrite template="{$frontend[path]}/mysamplerole"/>
            </rule>
            <rule dir="OUT" 
name="mySampleService/mysamplerole/outbound/websocket">
               <rewrite 
template="{$frontend[path]}/mysamplerolews/api/stomp/v1"/>
            </rule>
            <filter name="mySampleService/mysamplerole/outbound/apiendpoint">
               <content type="*/x-javascript">
                  <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
               </content>
               <content type="application/javascript">
                  <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
               </content>
            </filter>
            <filter 
name="mySampleService/mysamplerole/outbound/apiendpoint/html">
               <content type="text/html">
                  <apply path="/api/v1" 
rule="mySampleService/mysamplerole/outbound/extrapath"/>
               </content>
            </filter>
            <filter name="mySampleService/mysamplerole/outbound/mainpage">
               <content type="*/html">
                  <apply path="stylesheets/vendor.css" 
rule="mySampleService/mysamplerole/outbound/vendorcss"/>
                  <apply path="stylesheets/app.css" 
rule="mySampleService/mysamplerole/outbound/appcss"/>
                  <apply path="javascripts/vendor.js" 
rule="mySampleService/mysamplerole/outbound/vendorjs"/>
                  <apply path="javascripts/app.js" 
rule="mySampleService/mysamplerole/outbound/appjs"/>
                  <apply path="/img/logo.png" 
rule="mySampleService/mysamplerole/outbound/favicon"/>
                  <apply path="/licenses/NOTICE.txt" 
rule="mySampleService/mysamplerole/outbound/notice"/>
               </content>
            </filter>
         </rules>
      </serviceDefinition>
   </serviceDefinitions>
   ```
   
   Removing the service definition I added first:
   ```
   $ curl -H "Content-Type: application/xml" -iku admin:admin-password  -X 
DELETE 
'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mySampleService/mySampleRole/1.0.0'
   HTTP/1.1 200 OK
   Date: Mon, 14 Oct 2019 13:29:46 GMT
   Set-Cookie: KNOXSESSIONID=node0uegx72m31ta2p7p7g6h35yy4.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=Sun, 13-Oct-2019 13:29:46 GMT
   Location: 
https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mySampleService/mySampleRole/1.0.0
   Content-Type: application/json
   Content-Length: 72
   Server: Jetty(9.4.20.v20190813)
   
   $ ls -al knoxGateway/data/services/mySampleService/
   total 0
   drwxr-xr-x   3 smolnar  staff   102 Oct 14 15:29 .
   drwxr-xr-x@ 53 smolnar  staff  1802 Oct 14 15:20 ..
   drwxr-xr-x   4 smolnar  staff   136 Oct 14 15:24 2.0.0
   
   I also confirmed (from the gateway.log) that topology 'sandbox' got 
redeployed.
   ```
   
   Trying to remove it again:
   ```
   $ curl -H "Content-Type: application/xml" -iku admin:admin-password  -X 
DELETE 
'https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mySampleService/mySampleRole/1.0.0'
   HTTP/1.1 500 Internal Server Error
   Date: Mon, 14 Oct 2019 13:31:15 GMT
   Set-Cookie: KNOXSESSIONID=node0oygycvwluoa6p56c5gv6feex5.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=Sun, 13-Oct-2019 13:31:15 GMT
   Content-Type: application/json
   Content-Length: 137
   Server: Jetty(9.4.20.v20190813)
   
   { "DELETION_ERROR": "There is no service definition with the given 
attributes: mySampleService,mySampleRole,1.0.0" }
   ```
   
   Removing the second service definition I added before:
   ```
   $ 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 200 OK
   Date: Mon, 14 Oct 2019 13:31:40 GMT
   Set-Cookie: KNOXSESSIONID=node0nnx2ysaozbhcyg2xgy3jnfal6.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=Sun, 13-Oct-2019 13:31:40 GMT
   Location: 
https://localhost:8443/gateway/admin/api/v1/servicedefinitions/mySampleService/mySampleRole/2.0.0
   Content-Type: application/json
   Content-Length: 72
   Server: Jetty(9.4.20.v20190813)
   
   $ ls -al knoxGateway/data/services/mySampleService/
   ls: knoxGateway/data/services/mySampleService/: No such file or directory
   ```
   
   I also tested the following scenario:
   1. modified the `sandbox` topology: set a valid NameNodeUI URL for 
`MYSAMPLEROLE` (note: there was no other NameNode UI related service listed in 
`sandbox`)
   2. confirmed that 
`https://localhost:8443/gateway/sandbox/hdfs?host=$NAMENODEURL` failed due to 
missing matching path of `/hdfs`
   3. submitted a new service definition (mySampleService/MYSAMPLEROLE/3.0.0) 
with the content of the existing `hdfsui` service (used the GET API to save it 
locally)
   4. retried `https://localhost:8443/gateway/sandbox/hdfs?host=$NAMENODEURL`
   5. confirmed that Knox redirected the request properly to the previously set 
NameNodeUI URL without restarting the Knox Gateway
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 333917)
    Time Spent: 5h 10m  (was: 5h)

> Add Service Definition Management to Admin API
> ----------------------------------------------
>
>                 Key: KNOX-2053
>                 URL: https://issues.apache.org/jira/browse/KNOX-2053
>             Project: Apache Knox
>          Issue Type: Improvement
>          Components: Server
>            Reporter: Larry McCay
>            Assignee: Sandor Molnar
>            Priority: Major
>             Fix For: 1.4.0
>
>          Time Spent: 5h 10m
>  Remaining Estimate: 0h
>
> Currently, the Admin API allows management and access to topologies, 
> descriptors, provider config, etc but does not provide access to the Service 
> Definitions for the proxied services.
> Let's expand the API the include to include service defs and allow for 
> customization through the API. Changes made via the API will typically 
> require a restart and touch of an topology file that is referencing the 
> change service def. This may require a separate Jira and effort to address. 
> In the meantime, we should be able to change, add and delete service 
> definitions including both service and rewrite XML files.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to