eclipse-basyx / basyx-python-sdk

MIT License
61 stars 28 forks source link

Asset serialization not recognized by basyx-registry component #28

Closed vChavezB closed 1 year ago

vChavezB commented 2 years ago

I am testing the Basyx registry component and I am having a problem when creating a new asset, saving it as AASX and sending it to the registry with the HTTP API .

As a test I have created a package from the example located here.

Afterwards I created a script to try to upload the package to the Basyx-registry but I get the following error:

{
    "success": false,
    "isException": true,
    "messages": [{
        "messageType": 6,
        "code": "400",
        "text": "MalformedRequestException: AssetAdministrationShellDescriptor is missing identification entry"
    }]
}

The script I am using to send the asset (.aasx) is the following:

import requests
import json
from basyx.aas import model
from basyx.aas.adapter import aasx
import basyx.aas.adapter.json

def AddAsset(asset_path):
    object_store: model.DictObjectStore[model.Identifiable] = model.DictObjectStore()
    file_store = aasx.DictSupplementaryFileContainer()
    with aasx.AASXReader(asset_path) as reader:
        reader.read_into(object_store=object_store,
                         file_store=file_store)

   #Store the serialized basyx json to debug the serialization
    with open('data.json', 'w', encoding='utf-8') as json_file:
        basyx.aas.adapter.json.write_aas_json_file(json_file, object_store)

    json_aasx_str = basyx.aas.adapter.json.object_store_to_json(object_store)
    json_aasx = json.loads(json_aasx_str)
    # Assuming there is only one asset
    asset_id = "asset_sample"
    json_aasx["shortId"]= asset_id #Removes bug about missing shortId in Asset Admin. shell descriptor
    registry_url = "http://localhost:8082/registry/api/v1/registry"
    asset_put = registry_url+"/"+asset_id
    payload = str(json_aasx)
    r = requests.put(asset_put, data=payload)
    print(r)
    print(r.content)
#Asset generated with basyx-python-sdk example
asset_path = "MyAASXPackage.aasx"
AddAsset(asset_path)

I am not sure if I am doing something wrong as I am still new to the basyx middleware and would be helpful to get any feedback at to where the problem might be located. As additional info, I tested the sample JSON payload in the Swaggerhub API website and that works fine but building the package with basxy-python-sdk and serializing for the HTTP endpoint is not working as expected.

What I have noticed is that the serialized JSON from the basyx-python-sdk API does not have a 'shortId', which I fixed by adding this key to the dictionary.

vChavezB commented 2 years ago

I have also tried sending according to my example the key ["assetAdministrationShells"][0] from the json dictionary and I get the following error:

'{"success":false,
"isException":true,
"messages":[{"messageType":6,
"code":"400",
"text":"MalformedRequestException: Given newValue map has not the correct ModelType"}]}'
jkhsjdhjs commented 2 years ago

The API you linked is the registry API, used to register AssetAdministrationShells and other objects by their identifier and endpoint via Descriptor objects. This is not equivalent to the usual AssetAdministrationShell / Submodel objects as the descriptor objects don't contain all the data of an AssetAdministrationShell or Submodel object. Descriptor objects are currently not supported by the basyx-python-sdk, they'll maybe be implemented when the HTTP API component is implemented.

If you want to store the entire AssetAdministrationShell or Submodel object via an HTTP API you'll need an application that implements https://app.swaggerhub.com/apis/BaSyx/BaSyx_Registry_API/v1. I'm not familiar with the software currently available for that, so I can't recommend you any.

BTW: The two different interfaces (AAS and Registry) are specified in this document in Chapter 4 and 5 respectively: https://www.plattform-i40.de/IP/Redaktion/EN/Downloads/Publikation/Details_of_the_Asset_Administration_Shell_Part2_V1.html

vChavezB commented 2 years ago

Thanks for info. I will check the spec. part 2. My use case is that I want to dynamically add assets to the server and remove them if they are not online anymore.

If you want to store the entire AssetAdministrationShell or Submodel object via an HTTP API you'll need an application that implements https://app.swaggerhub.com/apis/BaSyx/BaSyx_Registry_API/v1.

So does this mean that the implementation of the Basyx Registry does not have this option at the moment ... or would that mean I have to implement (for example) the API PutAssetAdministrationShell (section 4.2.3) and use the swaggerhub API from basyx as backend. Sorry if I am asking something redundant but I am still getting to know the spec.

jkhsjdhjs commented 2 years ago

If you want to store the entire AssetAdministrationShell or Submodel object via an HTTP API you'll need an application that implements https://app.swaggerhub.com/apis/BaSyx/BaSyx_Registry_API/v1.

So does this mean that the implementation of the Basyx Registry does not have this option at the moment ... or would that mean I have to implement (for example) the API PutAssetAdministrationShell (section 4.2.3) and use the swaggerhub API from basyx as backend. Sorry if I am asking something redundant but I am still getting to know the spec.

Ah sorry, I linked the wrong spec. I meant to link: https://app.swaggerhub.com/apis/BaSyx/basyx_asset_administration_shell_repository_http_rest_api/v1

chrweiss commented 2 years ago

Ah sorry, I linked the wrong spec. I meant to link: https://app.swaggerhub.com/apis/BaSyx/basyx_asset_administration_shell_repository_http_rest_api/v1

Are there any plans to implement this REST spec? Or would I have to implement it on my own as the author of this issue currently is?

jkhsjdhjs commented 2 years ago

Ah sorry, I linked the wrong spec. I meant to link: https://app.swaggerhub.com/apis/BaSyx/basyx_asset_administration_shell_repository_http_rest_api/v1

Are there any plans to implement this REST spec? Or would I have to implement it on my own as the author of this issue currently is?

There are no plans to implement the linked API, as it is specific to the BaSyx project. Once https://github.com/eclipse-basyx/basyx-python-sdk/pull/18 is finalized though, we plan to implement https://app.swaggerhub.com/apis/Plattform_i40/Entire-API-Collection/V1.0RC03 in an HTTP server and an HTTP client.