ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

SystemLink Forum

cancel
Showing results for 
Search instead for 
Did you mean: 

Analysis Automation - nitdmreader.MetadataApi error

 

I'm working on an analysis automation and starting with understanding the following example: https://github.com/ni/systemlink-server-examples/blob/master/jupyter/analysis-automation/BasicExampl...

 

However, when I attempt to execute the following chunk:

 

0 Kudos
Message 1 of 2
(155 Views)

I was able to figure it out. Apparently the ni_analysis_automation variable that is populated when the Jupyter notebook is executed by the automation routine, does not have the correct session variable. 

 

In order to resolve this I extract the ids from the list of files in the passed in variable, then reconstruct the file list:

import urllib.parse as ulp
import json

id_values = []
for link in ni_analysis_automation['data_links']:
    parsed = ulp.urlparse(link['fileId'])
    query_params = ulp.parse_qs(parsed.query)
    # The 'query' param is a JSON string, so we need to load it
    if 'query' in query_params:        
        query_json = json.loads(query_params['query'][0])
        # Extract the id value
        id_value = query_json.get('test', {}).get('id', None)
        if id_value is not None:
            id_values.append(id_value)

payload = {
    "variables": {
        "$URL": {
            "stringArray": {"values": f"corbaname::#{datafinder_name}.ASAM-ODS"}
        }
    }
}
headers = {
    "x-ni-api-key": systemlink_api_key,
    "Content-Type": "application/x-asamods+json"
}
session_response = requests.post(
    f"{systemlink_uri}ni/asam/ods", 
    json=payload, 
    headers=headers, 
    verify=cert_path
)
session = session_response.headers.get("Location")

file_ids = [f"dfs:/?url={session}&query={{\"test\":{{\"id\":{id_val}}}}}" for id_val in id_values]

# Call metadata service (for example)
file_infos = await metadata_api.get_multiple_file_info(tdmreader.FileList(file_ids))

 

Is this really the best solution? This is all that I could come up with.

0 Kudos
Message 2 of 2
(126 Views)