in src/libs/deploy_utils/WorkspaceUtils.py [0:0]
def recursive_delete_child_entites(self, entity_id):
# first we do a depth first recursive delete to get down to the leaf nodes
while True:
next_token = ''
resp = self.iottwinmaker_client.list_entities(workspaceId=self.workspace_id, filters=[{'parentEntityId': entity_id}], maxResults=200, nextToken=next_token)
for i, entity in enumerate(resp['entitySummaries']):
self.recursive_delete_child_entites(entity_id=entity['entityId'])
nextToken = resp.get('nextToken', None)
if nextToken == None:
break
# at this point we have called recursive delete on all of children and will wait for our immediate children to finish deleting
resp = self.iottwinmaker_client.list_entities(workspaceId=self.workspace_id, filters=[{'parentEntityId': entity_id}])
while len(resp['entitySummaries']) > 0:
print(f" waiting for children of {entity_id} to finish deleting. ({len(resp['entitySummaries'])} remaining)")
time.sleep(1)
resp = self.iottwinmaker_client.list_entities(workspaceId=self.workspace_id, filters=[{'parentEntityId': entity_id}])
# children are now deleted so delete self
if entity_id!='$ROOT':
print(f" deleting entity: {entity_id}")
try:
resp = self.iottwinmaker_client.delete_entity(workspaceId=self.workspace_id, entityId=entity_id, isRecursive=True)
except Exception as e:
print(f" failed to delete entity: {entity_id}")