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

chore(testdata): Fix testdata upload and removal for AAS 3.0 specification #414

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions local/testing/testdata/reset-env.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ def delete_shells(url_, headers_):
print(global_asset_id)


def delete_shells_aas_3(url_, headers_):
while session.request(method="GET", url=url_, headers=headers_).json()["result"]:
response = session.request(method="GET", url=url_, headers=headers_)
response_json = response.json()
items = response_json["result"]
for item in items:
global_asset_id = item["id"]
delete_response = session.request(method="DELETE", url=url_ + "/" + global_asset_id, headers=headers_)
print(delete_response)
if delete_response.status_code > 205:
print(global_asset_id)


def delete_(url_, headers_):
response = session.request(method="GET", url=url_, headers=headers_)
values = response.json()
Expand Down Expand Up @@ -58,12 +71,18 @@ def delete_policies_and_assets(policy_url_, asset_url_, headers_):
parser.add_argument("-edc", "--edc", type=str, nargs="*", help="EDC provider control plane display URLs",
required=True)
parser.add_argument("-k", "--apikey", type=str, help="edc api key", required=True)
parser.add_argument("--aas3", help="Create AAS assets in version 3.0", action='store_true', required=False)

args = parser.parse_args()
config = vars(args)
edc_api_key = config.get("apikey")
registry_url = config.get("aas") + "/registry/shell-descriptors"
edc_urls = config.get("edc")
is_aas3 = config.get("aas3")

if is_aas3:
registry_url = config.get("aas") + "/shell-descriptors"
else:
registry_url = config.get("aas") + "/registry/shell-descriptors"

headers = {
'X-Api-Key': edc_api_key,
Expand All @@ -75,12 +94,15 @@ def delete_policies_and_assets(policy_url_, asset_url_, headers_):
session = requests.Session()
session.mount('https://', HTTPAdapter(max_retries=retries))

delete_shells(registry_url, headers)
if is_aas3:
delete_shells_aas_3(registry_url, headers)
else:
delete_shells(registry_url, headers)

for edc_url in edc_urls:
controlplane_data_contracts = edc_url + "/api/v1/management/contractdefinitions"
controlplane_data_policies = edc_url + "/api/v1/management/policydefinitions"
controlplane_data_assets = edc_url + "/api/v1/management/assets"
controlplane_data_contracts = edc_url + "/management/v2/contractdefinitions"
controlplane_data_policies = edc_url + "/management/v2/policydefinitions"
controlplane_data_assets = edc_url + "/management/v2/assets"

delete_contracts(controlplane_data_contracts, headers)

Expand Down
49 changes: 33 additions & 16 deletions local/testing/testdata/transform-and-upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,30 @@ def create_aas_shell_3_0(global_asset_id_, id_short_, identification_, specific_
})


def create_submodel_descriptor_3_0(id_short_, identification_, semantic_id_, endpoint_address_):
def create_submodel_descriptor_3_0(id_short_, identification_, semantic_id_, endpoint_address_, id_, endpoint_):
return json.dumps(
{
"description": [],
"idShort": id_short_,
"id": identification_,
"semanticId": {
"value": [
semantic_id_
"type": "ExternalReference",
"keys": [
{
"type": "GlobalReference",
"value": semantic_id_
}
]
},
"endpoints": [
{
"interface": "HTTP",
"interface": "SUBMODEL-3.0",
"protocolInformation": {
"href": endpoint_address_,
"endpointProtocol": "AAS/IDS",
"endpointProtocolVersion": "0.1",
"subprotocol": "IDS",
"subprotocolBody": "TDB",
"endpointProtocol": "HTTP",
"endpointProtocolVersion": ["1.1"],
"subprotocol": "DSP",
"subprotocolBody": f"id={id_};dspEndpoint={endpoint_}",
"subprotocolBodyEncoding": "plain"
}
}
Expand Down Expand Up @@ -333,6 +337,10 @@ def create_registry_asset(edc_upload_urls_, edc_asset_path_, edc_contract_defini
if aas_upload_url is None:
aas_upload_url = aas_url

registry_path = "/registry/shell-descriptors"
if is_aas3:
registry_path = "/shell-descriptors"

check_url_args(submodel_server_upload_urls, submodel_server_urls, edc_upload_urls, edc_urls)

edc_asset_path = "/management/v2/assets"
Expand Down Expand Up @@ -397,33 +405,40 @@ def create_registry_asset(edc_upload_urls_, edc_asset_path_, edc_contract_defini
identification = uuid.uuid4().urn
tmp_keys = tmp_data.keys()

specific_asset_ids = [
]
specific_asset_ids = []

submodel_descriptors = []

name_at_manufacturer = ""

specific_asset_ids_temp = []
for tmp_key in tmp_keys:
if "Batch" in tmp_key or "SerialPart" in tmp_key:
specific_asset_ids = copy(tmp_data[tmp_key][0]["localIdentifiers"])
specific_asset_ids_temp = copy(tmp_data[tmp_key][0]["localIdentifiers"])
name_at_manufacturer = tmp_data[tmp_key][0]["partTypeInformation"]["nameAtManufacturer"].replace(
" ",
"")
if "PartAsPlanned" in tmp_key:
name_at_manufacturer = tmp_data[tmp_key][0]["partTypeInformation"]["nameAtManufacturer"].replace(
" ",
"")
specific_asset_ids.append({
specific_asset_ids_temp.append({
"value": tmp_data[tmp_key][0]["partTypeInformation"]["manufacturerPartId"],
"key": "manufacturerPartId"
})
print(name_at_manufacturer)

specific_asset_ids.append({
specific_asset_ids_temp.append({
"key": "manufacturerId",
"value": tmp_data["bpnl"]
})
if is_aas3:
for asset in specific_asset_ids_temp:
specific_asset_ids.append({
"name": asset.get("key"),
"value": asset.get("value")
})
else:
specific_asset_ids = specific_asset_ids_temp

if esr_url and apr in tmp_keys and "childItems" in tmp_data[apr][0] and tmp_data[apr][0]["childItems"]:
tmp_data.update({esr: ""})
Expand Down Expand Up @@ -456,7 +471,9 @@ def create_registry_asset(edc_upload_urls_, edc_asset_path_, edc_contract_defini
if is_aas3:
endpoint_address = f"{edc_url}/shells/{catenax_id_urn}/submodels/{submodel_identification_urn}/submodel"
descriptor = create_submodel_descriptor_3_0(submodel_name, submodel_identification, semantic_id,
endpoint_address)
endpoint_address,
f"{catenax_id_urn}-{submodel_identification_urn}",
edc_url)
submodel_descriptors.append(json.loads(descriptor))
else:
descriptor = create_submodel_descriptor(submodel_name, submodel_identification, semantic_id,
Expand Down Expand Up @@ -499,7 +516,7 @@ def create_registry_asset(edc_upload_urls_, edc_asset_path_, edc_contract_defini
else:
payload = create_aas_shell(catenax_id, name_at_manufacturer, identification, specific_asset_ids,
submodel_descriptors)
response = session.request(method="POST", url=f"{aas_url}/registry/shell-descriptors",
response = session.request(method="POST", url=f"{aas_url}{registry_path}",
headers=headers,
data=payload)
print_response(response)
Expand Down