Closed neilspink closed 5 years ago
@neilspink we will reproduce the issue and try to fix this weekend
@neilspink hi
Below I provide an example using curl command to create an environment:
curl -k -c cookie.txt -X POST -d "username=admin&password=q123" https://192.168.0.102:8443/login
curl -k -b cookie.txt -X GET https://192.168.0.102:8443/rest/v1/environments
curl -k -b cookie.txt -X POST -d "topology={ \"name\": \"my-awesome-environment\", \"nodes\": [ { \"hostname\": \"my-awesome-container\", \"templateName\": \"debian-stretch\" } ] }" https://192.168.0.102:8443/rest/v1/environments
I see the CURL command is using -d and had to look that up, it means the data needs to be sent form urlencoded: -d "param1=value1¶m2=value2" I missed what was written the instructions "Form parameter topology"
Thanks, I got my Python program working now https://github.com/neilspink/subutai-resources/blob/master/Python/create-environment
Following the instructions on the wiki https://github.com/subutai-io/peer-os/wiki/Environment-management I wrote a Python3 program, note the peer is my own and I created an account on it for calling the API.
The KARAF logs only show NullPointerException: Invalid request. So, Im stuck on what the problem might be...
`import requests import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
BASEURL = 'https://2488df0152e67b8d4a835e0e71d5d8f844c463f.peers.subut.ai:37445'
s = requests.Session()
payload = {"username": "keith", "password": "SUPER-SECRET"} resp = s.post(BASEURL + '/login', data=payload, verify=False)
if resp.status_code != 200: print('Failed /login/ {}'.format(resp.status_code)) exit()
print('Login OK')
print('Environments:')
resp = s.get(BASEURL + '/rest/v1/environments')
if resp.status_code != 200: print('Failed GET /environments/ {}'.format(resp.status_code))
print(resp.json())
payload = { "name": "my", "nodes": [ { "hostname": "pap", "templateName": "ansible-debug" } ] }
print('Create:')
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} resp = s.post(BASEURL + '/rest/v1/environments' , data=payload , verify=False)
, headers=headers)
if resp.status_code != 200: print('CREATE /environments/ {} {}'.format(resp.status_code, resp.text)) else: print('Success')
`
2019-06-05 06:29:43,040 | DEBUG | 983868318-575749 | AuthorizationInterceptor | 3 - io.subutai.core.blueprint.auth - 8.6.1 | Granting access to Method: public javax.ws.rs.core.Response io.subutai.core.executor.rest.RestServiceImpl.check(java.lang.String) for RolePrincipal[Resource-Management|Read]. 2019-06-05 06:29:43,917 | INFO | 983868318-575749 | Login | 229 - io.subutai.webui - 8.6.1 | 7DC0FFB75A90CDE6DDC7ED6ADFB5A1280785BC48 2019-06-05 06:29:43,917 | INFO | 983868318-575749 | Login | 229 - io.subutai.webui - 8.6.1 | neilspink@gmail.com 2019-06-05 06:29:43,917 | INFO | 983868318-575749 | Login | 229 - io.subutai.webui - 8.6.1 | api 2019-06-05 06:29:43,917 | INFO | 983868318-575749 | Login | 229 - io.subutai.webui - 8.6.1 | 1018-6c819fda-3123-49bd-97a2-2bafeac09c11 2019-06-05 06:29:43,917 | INFO | 983868318-575749 | Login | 229 - io.subutai.webui - 8.6.1 | keith 2019-06-05 06:29:44,086 | DEBUG | 983868318-575660 | BazaaarAdapterImpl | 190 - io.subutai.core.bazaarmanager.impl - 8.6.1 | Active user: username=keith, email=neilspink@gmail.com 2019-06-05 06:29:44,086 | DEBUG | 983868318-575660 | BazaaarAdapterImpl | 190 - io.subutai.core.bazaarmanager.impl - 8.6.1 | Can't get proper user id for Bazaar 2019-06-05 06:29:44,492 | ERROR | 983868318-575728 | RestServiceImpl | 149 - io.subutai.core.environment.rest - 8.6.1 | Invalid request java.lang.NullPointerException: Invalid request at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:226)[79:com.google.guava:18.0.0] at io.subutai.core.environment.rest.RestServiceImpl.prepare2(RestServiceImpl.java:64)[149:io.subutai.core.environment.rest:8.6.1] at io.subutai.core.environment.rest.RestServiceImpl.createEnvironment(RestServiceImpl.java:127)[149:io.subutai.core.environment.rest:8.6.1] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_212] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_212] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_212] at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_212] at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:181)[91:org.apache.cxf.cxf-core:3.1.0] at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:97)[91:org.apache.cxf.cxf-core:3.1.0] at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:200)[90:org.apache.cxf.cxf-rt-frontend-jaxrs:3.1.0] at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99)[90:org.apache.cxf.cxf-rt-frontend-jaxrs:3.1.0] at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)[91:org.apache.cxf.cxf-core:3.1.0] at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)[91:org.apache.cxf.cxf-core:3.1.0] at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)[91:org.apache.cxf.cxf-core:3.1.0] at io.subutai.core.channel.impl.interceptor.AccessControlInterceptor$1.run(AccessControlInterceptor.java:67)[128:io.subutai.core.channel.impl:8.6.1] at io.subutai.core.channel.impl.interceptor.AccessControlInterceptor$1.run(AccessControlInterceptor.java:61)[128:io.subutai.core.channel.impl:8.6.1] at java.security.AccessController.doPrivileged(Native Method)[:1.8.0_212] at javax.security.auth.Subject.doAs(Subject.java:360)[:1.8.0_212] at io.subutai.core.channel.impl.interceptor.AccessControlInterceptor.handleMessage(AccessControlInterceptor.java:60)[128:io.subutai.core.channel.impl:8.6.1] at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)[91:org.apache.cxf.cxf-core:3.1.0] at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[91:org.apache.cxf.cxf-core:3.1.0] at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)[96:org.apache.cxf.cxf-rt-transports-http:3.1.0] at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)[96:org.apache.cxf.cxf-rt-transports-http:3.1.0] at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)[96:org.apache.cxf.cxf-rt-transports-http:3.1.0] at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)[96:org.apache.cxf.cxf-rt-transports-http:3.1.0] at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)[96:org.apache.cxf.cxf-rt-transports-http:3.1.0] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)[96:org.apache.cxf.cxf-rt-transports-http:3.1.0] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:212)[96:org.apache.cxf.cxf-rt-transports-http:3.1.0] at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)[40:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0.0] at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)[96:org.apache.cxf.cxf-rt-transports-http:3.1.0] at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:69)[54:org.ops4j.pax.web.pax-web-jetty:3.2.6] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:240)[54:org.ops4j.pax.web.pax-web-jetty:3.2.6] at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)[54:org.ops4j.pax.web.pax-web-jetty:3.2.6] at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.Server.handle(Server.java:370)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.io.nio.SslConnection.handle(SslConnection.java:196)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[45:org.eclipse.jetty.aggregate.jetty-all-server:8.1.17.v20150415] at java.lang.Thread.run(Thread.java:748)[:1.8.0_212] 2019-06-05 06:29:44,495 | INFO | pool-1-thread-8 | LogListenerImpl | 190 - io.subutai.core.bazaarmanager.impl - 8.6.1 | RECEIVED: :io.subutai.core.appender.SubutaiErrorEvent@41603377 2019-06-05 06:29:45,830 | DEBUG | pool-37-thread-1 | EnvironmentManagerImpl | 147 - io.subutai.core.environment.impl - 8.6.1 | Environment background tasks started... 2019-06-05 06:29:45,830 | DEBUG | pool-37-thread-1 | EnvironmentManagerImpl | 147 - io.subutai.core.environment.impl - 8.6.1 | Environment background tasks finished. 2019-06-05 06:29:49,405 | WARN | ool-42-thread-10 | IdentityManagerImpl | 221 - io.subutai.core.identity.impl - 8.6.1 | * Cannot find active User (no session): Subject is null 2019-06-05 06:29:49,405 | WARN | ool-42-thread-10 | CommandProcessor | 162 - io.subutai.core.executor.impl - 8.6.1 | ** Command: 'subutai tunnel list | grep 10.10.10.1:8443' is running without user privileges 2019-06-05 06:29:49,457 | DEBUG | ool-42-thread-10 | CommandProcessor | 162 - io.subutai.core.executor.impl - 8.6.1 | Sending: { "request": { "type": "EXECUTE_REQUEST", "id": "E222F4D7CD0C9EF537FB50090C39148710FFC75A", "commandId": "ee11ec8f-7332-47d1-8ade-66bc52a010a6", "workingDirectory": "/", "command": "subutai tunnel list | grep 10.10.10.1:8443", "stdOut": "RETURN", "stdErr": "RETURN", "runAs": "root", "timeout": 60, "isDaemon": 0 } } 2019-06-05 06:29:49,674 | DEBUG | 983868318-575749 | AuthorizationInterceptor | 3 - io.subutai.core.blueprint.auth - 8.6.1 | Granting access to Method: public javax.ws.rs.core.Response io.subutai.core.executor.rest.RestServiceImpl.getRequests(java.lang.String) for RolePrincipal[Resource-Management|Read]. 2019-06-05 06:29:49,674 | DEBUG | 983868318-575749 | RestServiceImpl | 165 - io.subutai.core.executor.rest - 8.6.1 | Requested commands for RH E222F4D7CD0C9EF537FB50090C39148710FFC75A. 1 requests 2019-06-05 06:29:49,778 | DEBUG | 983868318-575728 | AuthorizationInterceptor | 3 - io.subutai.core.blueprint.auth - 8.6.1 | Granting access to Method: public javax.ws.rs.core.Response io.subutai.core.executor.rest.RestServiceImpl.processResponse(java.lang.String) for RolePrincipal[Resource-Management|Write]. 2019-06-05 06:29:49,816 | DEBUG | 983868318-575728 | CommandProcessor | 162 - io.subutai.core.executor.impl - 8.6.1 | Response: ResponseImpl[type=EXECUTE_RESPONSE,id=E222F4D7CD0C9EF537FB50090C39148710FFC75A,commandId=ee11ec8f-7332-47d1-8ade-66bc52a010a6,pid=0,responseNumber=1,stdOut=62.138.16.160:37445 10.10.10.1:8443 -1 ,stdErr=,exitCode=0]
2019-06-05 06:29:49,816 | INFO | ool-42-thread-10 | BazaarRestClient | 190 - io.subutai.core.bazaarmanager.impl - 8.6.1 | GET /rest/v1/tunnel/7AB52DF0152E67B8D4A835E0E71D5D8F844C463F
2019-06-05 06:29:50,066 | INFO | ool-42-thread-10 | BazaarRestClient | 190 - io.subutai.core.bazaarmanager.impl - 8.6.1 | response.status: 200 - OK
2019-06-05 06:29:50,071 | DEBUG | ool-42-thread-10 | TunnelHelper | 190 - io.subutai.core.bazaarmanager.impl - 8.6.1 | Response: HTTP 200 - OK
2019-06-05 06:29:53,078 | DEBUG | 983868318-575660 | AuthorizationInterceptor | 3 - io.subutai.core.blueprint.auth - 8.6.1 | Granting access to Method: public javax.ws.rs.core.Response io.subutai.core.executor.rest.RestServiceImpl.check(java.lang.String) for RolePrincipal[Resource-Management|Read].
2019-06-05 06:29:53,707 | DEBUG | 983868318-575726 | AuthorizationInterceptor | 3 - io.subutai.core.blueprint.auth - 8.6.1 | Granting access to Method: public javax.ws.rs.core.Response io.subutai.core.executor.rest.RestServiceImpl.check(java.lang.String) for RolePrincipal[Resource-Management|Read].
2019-06-05 06:29:58,405 | INFO | pool-43-thread-1 | HeartbeatProcessor | 190 - io.subutai.core.bazaarmanager.impl - 8.6.1 | Sending heartbeat to Bazaar: interval=60, force=false, fastModeLeft=-10534
2019-06-05 06:29:58,405 | INFO | pool-43-thread-1 | HeartbeatProcessor | 190 - io.subutai.core.bazaarmanager.impl - 8.6.1 | Heartbeat - START