Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not able/failing to stop app #50

Open
silomare opened this issue Jun 4, 2019 · 3 comments
Open

not able/failing to stop app #50

silomare opened this issue Jun 4, 2019 · 3 comments

Comments

@silomare
Copy link

silomare commented Jun 4, 2019

successfully instantiating client and retrieving an app with
app = client.v2.apps.get_first(**{'name': <app_name>})

successfully checking app object with
type(app)
app.summary()

but getting this exception when running
app.stop()
would you please help? is there anything I maybe missing?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/cloudfoundry_client/v2/apps.py", line 22, in stop
    return self.client.v2.apps.stop(self['metadata']['guid'])
  File "/Library/Python/2.7/site-packages/cloudfoundry_client/v2/apps.py", line 89, in stop
    result = super(AppManager, self)._update(application_guid, dict(state='STOPPED'))
  File "/Library/Python/2.7/site-packages/cloudfoundry_client/v2/entities.py", line 79, in _update
    return self._put(url, data, **kwargs)
  File "/Library/Python/2.7/site-packages/cloudfoundry_client/v2/entities.py", line 91, in _put
    response = self.client.put(url, json=data, **kwargs)
  File "/Library/Python/2.7/site-packages/cloudfoundry_client/client.py", line 175, in put
    return CloudFoundryClient._check_response(response)
  File "/Library/Python/2.7/site-packages/cloudfoundry_client/client.py", line 194, in _check_response
    raise InvalidStatusCode(response.status_code, body)
cloudfoundry_client.errors.InvalidStatusCode: 400 : {"code": 1001, "error_code": "CF-MessageParseError", "description": "Request invalid due to parse error: Decoded JSON cannot be nil"}
@antechrestos
Copy link
Member

Hi,

This is a strange behaviour. Running the following code with my instance of cloudfoundry works

    app = client.apps.get_first(name='my-application')
    print(type(app))
    print(app.summary())
    app.stop()

Is your CF instance recent? Do you have the last version of the cf-python ?
Because the error returned by CF tells the body is empty while we do a PUToperation with the body dict(state='STOPPED')....

@silomare
Copy link
Author

silomare commented Jun 5, 2019

I'm running the latest version of the client library against PCF 2.4
I tried both with python 2.7.10 and 3.7.3

@antechrestos
Copy link
Member

Hi

Sorry for the late reply I've been struggling installing PCFDEV 1.2.0 for PAS 2.4.4

Running the following script against a running application works

import os
from cloudfoundry_client.client import CloudFoundryClient

def build_client(access_token, refresh_token, target_endpoint):
    result = CloudFoundryClient(target_endpoint, verify=False)
    result._access_token = access_token
    result.refresh_token = refresh_token
    return result

if __name__ == '__main__':
    local_endpoint = 'http://api.dev.cfdev.sh'
    with open(os.path.expanduser('~/.cf/config.json'), 'r') as f:
        data = json.load(f)
        client = build_client(data['AccessToken'], data['RefreshToken'], local_endpoint)
    app = client.apps.get_first(name='my-static-application')
    print(type(app))
    print(app.summary())
    app.stop()

We can increase logging to debug by inserting at the beginning of the script

if sys.version_info.major == 2:
    import httplib as http_client
elif sys.version_info.major == 3:
    import http.client as http_client
else:
    raise ImportError('Invalid major version: %d' % sys.version_info.major)

http_client.HTTPConnection.debuglevel = 1
logging.basicConfig(level=logging.ERROR,
                    format='%(levelname)5s - %(name)s -  %(message)s')
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

The output of script shows

...
send: b'PUT /v2/apps/80716071-12cf-4100-b38f-12b27b79b35a HTTP/1.1\r\nHost: api.dev.cfdev.sh\r\nUser-Agent: python-requests/2.21.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nAuthorization: Bearer eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vdWFhLmRldi5jZmRldi5zaC90b2tlbl9rZXlzIiwia2lkIjoia2V5LTEiLCJ0eXAiOiJKV1QifQ.eyJqdGkiOiI5NjhhNmI4Yjc1Zjg0MjAzOWFlMjZkN2EwZjlhZThmMSIsInN1YiI6ImU1M2FkYTI5LWJiNjMtNGVjMS04ZmVhLTg2YTc3NmI2OThhOCIsInNjb3BlIjpbImNsb3VkX2NvbnRyb2xsZXIucmVhZCIsInBhc3N3b3JkLndyaXRlIiwiY2xvdWRfY29udHJvbGxlci53cml0ZSIsIm9wZW5pZCIsInVhYS51c2VyIl0sImNsaWVudF9pZCI6ImNmIiwiY2lkIjoiY2YiLCJhenAiOiJjZiIsImdyYW50X3R5cGUiOiJwYXNzd29yZCIsInVzZXJfaWQiOiJlNTNhZGEyOS1iYjYzLTRlYzEtOGZlYS04NmE3NzZiNjk4YTgiLCJvcmlnaW4iOiJ1YWEiLCJ1c2VyX25hbWUiOiJ1c2VyIiwiZW1haWwiOiJ1c2VyIiwiYXV0aF90aW1lIjoxNTYwMzQwNjkwLCJyZXZfc2lnIjoiMTQzMTg2NmQiLCJpYXQiOjE1NjAzNDMxNzMsImV4cCI6MTU2MDM1MDM3MywiaXNzIjoiaHR0cHM6Ly91YWEuZGV2LmNmZGV2LnNoL29hdXRoL3Rva2VuIiwiemlkIjoidWFhIiwiYXVkIjpbImNsb3VkX2NvbnRyb2xsZXIiLCJwYXNzd29yZCIsImNmIiwidWFhIiwib3BlbmlkIl19.IVSA3X5of5CFWw0atYw_MS4iB19APrrjHgjk86PWoDq1-ljcSbUfsxGybZ4h2SHTSOA2SXyMEur2a1p-iu7kFsqPTPzSrv6zklQ_JHJTzoJSL_RjBlEaCj-C2Gi2zFdasS_ZwYQPHzg_0Z1kZ4TV-8w1a5-5wttMoL1xEXL6dphLnqSH0XOipvz53I5AgJHEvqfrUVcFn50pDNVAeFUMganvRnma0DgYMCRMYQpymSElmyETgKHmyIZVQNk-lJE6xMD8eHmeXrqyskUW2HmrLofP8eIDVezLODHHhmtItS9HJoICOAx6tG9-mZYVZb3CQ7Gk4gWGp-xgo1ZQ4o2mhg\r\nContent-Length: 20\r\nContent-Type: application/json\r\n\r\n'
send: b'{"state": "STOPPED"}'
reply: 'HTTP/1.1 201 Created\r\n'
header: Content-Length: 1914
header: Content-Type: application/json;charset=utf-8
header: Date: Wed, 12 Jun 2019 12:39:33 GMT
header: Server: nginx
header: X-Content-Type-Options: nosniff
header: X-Vcap-Request-Id: 0c4760d1-4fb8-4c23-703a-931be1b7d332::0ed0cb8b-dff2-476e-aa03-acb39fc040b7
...

As you can see, the body {"state": "STOPPED"} is sent while requesting the stopping of application.

You can debug further by using wireshark but I fear it may shows the same behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants