VMware {code} Community
stu42j
Contributor
Contributor

Find ID of Deleted Resource

When deleting a vApp, the resulting task contains a reference to the vApp as the Owner. This reference only includes the href and type. From that, how can I get the ID (URN) of the vApp? Normally I would fetch the href but that doesn't work after the vApp has been deleted.

I know that I could parse the href but the documentation advises against doing that as the href formats may change. I'm looking for something official.

Tags (3)
0 Kudos
3 Replies
rkamal
VMware Employee
VMware Employee

Hi,

1. Just before the vapp delete operation you can very well get the id from the vapp object itself.

    Ex: Vapp vapp = Vapp.getVappByReference(client, vappRef);

          String vAppId = vapp.getResource().getId();

          Task task = vapp.delete();

2. If you just have the task, then you can use the queryservice to get the task and also its associated properties in the id format.

    Ex: Task task = vapp.delete();

          String taskId = task.getResource().getId();

          QueryParams<QueryAdminTaskField> queryParams = new QueryParams<QueryAdminTaskField>();

          queryParams.setFilter(new Filter(new Expression(QueryAdminTaskField.ID, taskId, ExpressionType.EQUALS)));

          RecordResult<QueryResultAdminTaskRecordType> taskResult = client.getQueryService().queryIdRecords(QueryRecordType.ADMINTASK,   

queryParams);

          // some checks

          System.out.println(taskResult.getRecords().get(0).getObject());

          System.out.println(taskResult.getRecords().get(0).getObjectName());

          System.out.println(taskResult.getRecords().get(0).getObjectType());

          API

          https://10.132.99.139/api/query?type=adminTask&filter=(id==urn:vcloud:task:506b790c-929f-4d32-b240-7...

<QueryResultRecords>
    <AdminTaskRecord status="success" startDate="2013-02-13T16:05:55.710-08:00" serviceNamespace="com.vmware.vcloud" ownerName="system" owner="urn:vcloud:user:2e37a255-fe53-4cdc-9c0d-935e9aed6f9c" orgName="cloudOrg" org="urn:vcloud:org:f707ba7e-3124-4375-9185-8cdc058dba4f" objectType="vapp" objectName="emptyVapp" object="urn:vcloud:vapp:7f672144-67f0-4ed2-bdaa-28cd5cf107a2" name="vdcDeleteVapp" hasOwner="true" endDate="2013-02-13T16:05:56.083-08:00" cellName="wdc-eeapps-dhcp439.eng.vmware.com" id="urn:vcloud:task:506b790c-929f-4d32-b240-7a66223d6985" details=" " adminDetails=" " debugInformation=" "/>
</QueryResultRecords>

Regards,

Rajesh Kamal.

0 Kudos
stu42j
Contributor
Contributor

Thanks Rajesh. I like the query idea but I'm getting an error when

trying to filter by id.

"Bad request: Unknown property name id."

I should have mentioned that I am still on v1.5. Do you think that might

be the problem?

I just wish all references included the id up front. Would avoid a lot

of extra requests.

0 Kudos
yskp
Enthusiast
Enthusiast

I believe the ability to query for an object by its ID is new to the 5.1 API.

0 Kudos