3

I was able to configure the following setup,

[enter image description here]

I am able to add a task in a job to run the testapi.py file which takes a simple string as input and send it to the flask app running inside the docker container.

But,

The task execution is throwing an error

> Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 160, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
    raise err
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 355, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 183, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.6/site-packages/urllib3/connection.py", line 169, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fe6ff71e630>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.6/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=6789): Max retries exceeded with url: /upload (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe6ff71e630>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "preload_testapi.py", line 37, in <module>
    r = requests.post(url, json=got_json)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=6789): Max retries exceeded with url: /upload (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe6ff71e630>: Failed to establish a new connection: [Errno 111] Connection refused',))
  • Things i have done

    1. I made sure that the start task(which runs the flask app) is executed by sudo user created by me (not _azbatch user), tasks inside the jobs are also executed by the same user.

    2. I tested the same command executed by the task by doing ssh into the same node with the user login created by me and the command runs
      fine.

    3. when I run the command from _azbatch it throws the same error.

    4. It is not a flask port issue.

enter image description here

@fpark my start task execution is done properly, during node creation I download an image from Azure container registry, download 2 files from azure storage blob as resource files, start task is to run one of these files(shell script) which makes a container, run a flask app inside it from that image. added tasks are to hit the running flask app using the 2nd file(testapi.py)with different parameters for each task.

cerofrais
  • 1,117
  • 1
  • 12
  • 32
  • Are you by any chance using docker? [Same issue](https://github.com/Azure/azure-cli/issues/7686) was discussed here and solved by chaning dockerfile. – Šimon Kocúrek Sep 18 '19 at 12:08
  • [Another discussion](https://github.com/Azure/azure-kusto-python/issues/115) suggests using `requests` instead of `urlib3`, if that is possible. – Šimon Kocúrek Sep 18 '19 at 12:12
  • @ŠimonKocúrek i am using requests inside my testapi.py file – cerofrais Sep 18 '19 at 12:16
  • @simon sorry if i didnt make it clear but i am not using azure cli, using azure python sdk [Link](https://learn.microsoft.com/en-us/python/api/azure-batch/azure.batch.models?view=azure-python) – cerofrais Sep 18 '19 at 12:19
  • Thanks for the info. In that case, look at this thread: https://stackoverflow.com/questions/36088409/error-111-connecting-to-localhost6379-connection-refused-django-heroku (it is same error, even though a different platform) – Šimon Kocúrek Sep 18 '19 at 12:22
  • 1
    Can you please expand your question with the relevant start task and task configurations? It is difficult to understand what you are doing with the existing question. – fpark Sep 18 '19 at 14:51
  • @fpark explained in detail, please tell me if you need more explination – cerofrais Sep 19 '19 at 03:16

1 Answers1

1

You can hit the flask API using a task. Follow this way:

Give a job that has two tasks to your compute node where task 1 runs the flask API and task 2 hits the API. And also enable parallel task execution for your nodes before trying this.

Hope this helps (~ ̄▽ ̄)~