IBM / clai

Command Line Artificial Intelligence or CLAI is an open-sourced project from IBM Research aimed to bring the power of AI to the command line interface.
https://clai-home.mybluemix.net/
MIT License
475 stars 73 forks source link

z/OS support for CLAI #96

Closed djfitzgerald closed 3 years ago

djfitzgerald commented 3 years ago

:pushpin: References

:tophat: What is the goal?

Port CLAI to z/OS running Unix System Services. Modify the behavior of some of the existing skills (helpme, nlc2cmd), disable other skills on Z that could not yet be ported (fixit, howdoi, man page explorer), and create new skills targeted at z/OS users.

:memo: How is it being implemented?

New Skills

linuss

A frequent problem experienced by new USS users is that many of the commands they may be familiar with from Linux don't exist in the same form on USS. linuss, "the Linux to USS plugin", serves to bridge that gap.

This new CLAI skill uses a set of predefined equivalences found by comparing the man pages of common Linux commands against those of z/OS Unix System Services. Whenever a command is entered on USS, the equivalences are checked and are suggested to the user if detected. Suggestions can range from an equivalent flag up to an entire command replacement.

image

zmsgcode

IBM Z error messages can seem daunting to an end user. The zmsgcode skill tries to make them a little friendlier by automatically displaying a descriptive help message whenever the console detects any IBM Z style message codes.

Here's how it works: whenever text comes back to the USS shell over the standard error stream, zmsgcode will see if any of it fits the pattern of the message codes standardized for all IBM Z operating systems and related products. If so, and if there is a hexidecimal reason code included, zmsgcode will try to get a message description from the bpxmtext application. If there is no reason code, or if bpxmtext doesn't return a message, zmsgcode will try to search the USS publications on the z/OS KnowledgeCenter website and will return the first result encountered.

image

Modifications to Existing Skills

helpme

In the existing helpme skill, standard error text produced on a command failure is searched against data from the Stack Exchange Unix forum to find an accepted answer that solves the issue, or the most highly rated answer in case of an accepted answer being unavailable. This employs a simple index-based text search to identify the relevant Stack Exchange post and the corresponding answer. The body of the result is then compared against available manpages using a REST API from the man Page Explorer skill to recommend a relevant command to explore.

This feature has the potential to be incredibly helpful to z/OS users, as the proprietary and often esoteric nature of IBM Z can make it difficult to simply search the Internet for a solution to any problems that may arise. But this fact also limits the usefulness of helpme in its original form: by searching the Stack Exchange Unix forums, helpme is likely to return information that doesn't apply to USS or z/OS. To address it, the zATT expanded helpme's search functionality to default to the IBM KnowledgeCenter when run from z/OS. Specifically, standard error is sent as a query to the z/OS KnowledgeCenter API with the tags for the USS product applied. USS publications are searched first, then Redbooks, then DeveloperWorks articles, and then finally Technotes. Unlike the Unix Stack Exchange search, this is very simplistic: the first result found in any KnowledgeCenter database query is the result used for the manpages comparison and eventually returned to the user.

image

nlc2cmd

The existing nlc2cmd skill allows users to specify tasks in English and retrieve Linux command line syntax with the aid of Watson Assistant-based natural language classifiers. To support USS, the IBM Research team created a new classifier with the ability to identify eleven different USS commands from a natural language description. As a result, nlc2cmd can not only respond to USS-specific phrases like "copy file to pds member", but can respond to phrases such as "edit a file" with suggested USS commands instead of their Linux counterparts.

image

:boom: How can it be tested?

Run automated test suites on all supported platforms

djfitzgerald commented 3 years ago

One issue that I've run into in final testing was that the zmsgcode skill no longer is communicating with the KnowledgeCenter. I suspect that this is a configuration issue, so I didn't want it to hold up the final pull request, but I would be curious to hear everybody's thoughts on the matter:

2020-09-17 14:42:19,077 INFO info(34) ==================== In zMsgCode Bot:post_execute ============================
2020-09-17 14:42:19,077 INFO info(34) State:
    Command: cp test.txt test.txt 
    Error Code: 1
    Stderr: FSUM8977 cp: source "test.txt" and target "test.txt" are identical
2020-09-17 14:42:19,077 INFO info(34) ============================================================================
2020-09-17 14:42:19,078 INFO info(34) Analyzing error message 'FSUM8977 cp: source "test.txt" and target "test.txt" are identical'
2020-09-17 14:42:19,078 INFO info(34) ibm_kc: 
    GET --> https://www.ibm.com/support/knowledgecenter/v1/search
    .--[Headers]--------------------------------------------------------------------
    |    Content-Type: application/json
    |    Accept: */*
    `-------------------------------------------------------------------------------
    files: []
    data: []
    json: None
    params: {'query': 'FSUM8977', 'offset': 0, 'limit': 1, 'ta ... BW_2.4.0'}
    auth: None
    cookies: None
    hooks: {'response': []}
2020-09-17 14:42:19,083 INFO info(34) error processing message HTTPSConnectionPool(host='www.ibm.com', port=443): Max retries exceeded with url: /support/knowledgecenter/v1/search?query=FSUM8977&offset=0&limit=1&tags=bpx&products=SSLTBW_2.4.0 (Caused by SSLError(SSLError(0, 'unknown error (_ssl.c:3517)'),))
2020-09-17 14:42:19,084 INFO info(34) Traceback (most recent call last):
  File "/u/danfitz/.local/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 350, in ssl_wrap_socket
    context.load_verify_locations(ca_certs, ca_cert_dir, ca_cert_data)
ssl.SSLError: unknown error (_ssl.c:3517)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/u/danfitz/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/u/danfitz/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/u/danfitz/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
    conn.connect()
  File "/u/danfitz/.local/lib/python3.6/site-packages/urllib3/connection.py", line 371, in connect
    ssl_context=context,
  File "/u/danfitz/.local/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 352, in ssl_wrap_socket
    raise SSLError(e)
urllib3.exceptions.SSLError: unknown error (_ssl.c:3517)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/u/danfitz/.local/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/u/danfitz/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 727, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/u/danfitz/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.ibm.com', port=443): Max retries exceeded with url: /support/knowledgecenter/v1/search?query=FSUM8977&offset=0&limit=1&tags=bpx&products=SSLTBW_2.4.0 (Caused by SSLError(SSLError(0, 'unknown error (_ssl.c:3517)'),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/u/danfitz/.bin/clai/bin/clai/server/message_handler.py", line 106, in process_message
    return self.process_post_command(message)
  File "/u/danfitz/.bin/clai/bin/clai/server/message_handler.py", line 49, in process_post_command
    action = command_runner.execute_post(message)
  File "/u/danfitz/.bin/clai/bin/clai/server/command_runner/agent_command_runner.py", line 33, in execute_post
    action = self.agent_runner.process_post(state, self.ignore_threshold)
  File "/u/danfitz/.bin/clai/bin/clai/server/agent_runner.py", line 109, in process_post
    action_post_executed = plugin_instance.post_execute(command)
  File "/u/danfitz/.bin/clai/bin/clai/server/plugins/zmsgcode/zmsgcode.py", line 99, in post_execute
    data = self.store.search(msgid, service='ibm_kc', size=1)
  File "/u/danfitz/.bin/clai/bin/clai/server/searchlib/data.py", line 44, in search
    res = serviceProvider.call(query, size, **kwargs)
  File "/u/danfitz/.bin/clai/bin/clai/server/searchlib/kc_provider.py", line 74, in call
    r = self.__send_get_request__(target, params=payload)
  File "/u/danfitz/.bin/clai/bin/clai/server/searchlib/providers.py", line 126, in __send_get_request__
    return self.__send_request__(method='GET', uri=uri, **kwargs)
  File "/u/danfitz/.bin/clai/bin/clai/server/searchlib/providers.py", line 120, in __send_request__
    response:Response = session.send(request=request.prepare())
  File "/u/danfitz/.local/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/u/danfitz/.local/lib/python3.6/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.ibm.com', port=443): Max retries exceeded with url: /support/knowledgecenter/v1/search?query=FSUM8977&offset=0&limit=1&tags=bpx&products=SSLTBW_2.4.0 (Caused by SSLError(SSLError(0, 'unknown error (_ssl.c:3517)'),))
djfitzgerald commented 3 years ago

Converting PR to draft while we work out some last minute issues

djfitzgerald commented 3 years ago

Most issues have been resolved. The only issue outstanding is the CA certificate problem discussed above.

djfitzgerald commented 3 years ago

Ready to proceed with review

flipper83 commented 3 years ago

This PR has tons of pylint errors, could you fix it to allow travis to run the tests?