VMware Cloud Community
aleti
Enthusiast
Enthusiast
Jump to solution

how to delete all catalogs in org using java sdk

I am trying to delete all catalogs from oraganization i have writen below code to get the catloges from org in this same loop not able to use
Admincataloge it's through exception, if any one help me to extent this code to delete the all catalogs in organizaiton, it's greate help for me.  i am new java coding this code not structured, 

if

(!organizationsMap.isEmpty())

{

ReferenceType organizationReference =

organizationsMap .get(organizationName);

System.

out.print(organizationName);

System.

out.println();

System.

out.println(organizationReference.getHref());

Organization organization = Organization.getOrganizationByReference(

vcloudClient, organizationReference);

Collection<ReferenceType> catalogLinks = organization.getCatalogRefs();

if (!catalogLinks.isEmpty())

{

for (ReferenceType catalogLink : catalogLinks)

{

Catalog catalog = Catalog.getCatalogByReference(

vcloudClient, catalogLink);

CatalogType catalogType = catalog.getResource();

System.

out.print("--" + catalogType.getName());

System.

out.println();

//System.out.println("--- " + catalogLink.getHref());

} System.

out.println();

}

else

System.

out.println("No Catalogs Found");

}

else {

System.

out.println("No Organizations");

System.exit(0);

}

Reply
0 Kudos
1 Solution

Accepted Solutions
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

You need to go to the VcloudAdmin and then iterate through the AdminOrganizations and its AdminCatalogs to delete the catalogs.

You can do something like this.

// Get to the Vcloud Admin.

VcloudAdmin admin = vcloudClient.getVcloudAdmin();
// Iterate through the admin organizations.
for (ReferenceType adminOrgRef : admin.getAdminOrgRefs()) {
     AdminOrganization adminOrg = AdminOrganization.getAdminOrgByReference(vcloudClient, adminOrgRef);
     // Iterate through the admin catalogs.
     for (ReferenceType adminCatRef : adminOrg.getCatalogRefs()) {
          try {
                    // Delete the catalog.
                    AdminCatalog.delete(vcloudClient, adminCatRef);
                    System.out.println("Deleted Catalog - "+ adminCatRef.getName());
               } catch (VCloudException e) {
                    System.out.println("Delete Catalog Failed - "+ adminCatRef.getName() + " - "+ e.getLocalizedMessage());
               }
     }
}

Regards,

Rajesh Kamal.

View solution in original post

Reply
0 Kudos
3 Replies
aleti
Enthusiast
Enthusiast
Jump to solution

for got to mention I am using Java SDK for vCloud Director 1.5

Reply
0 Kudos
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

You need to go to the VcloudAdmin and then iterate through the AdminOrganizations and its AdminCatalogs to delete the catalogs.

You can do something like this.

// Get to the Vcloud Admin.

VcloudAdmin admin = vcloudClient.getVcloudAdmin();
// Iterate through the admin organizations.
for (ReferenceType adminOrgRef : admin.getAdminOrgRefs()) {
     AdminOrganization adminOrg = AdminOrganization.getAdminOrgByReference(vcloudClient, adminOrgRef);
     // Iterate through the admin catalogs.
     for (ReferenceType adminCatRef : adminOrg.getCatalogRefs()) {
          try {
                    // Delete the catalog.
                    AdminCatalog.delete(vcloudClient, adminCatRef);
                    System.out.println("Deleted Catalog - "+ adminCatRef.getName());
               } catch (VCloudException e) {
                    System.out.println("Delete Catalog Failed - "+ adminCatRef.getName() + " - "+ e.getLocalizedMessage());
               }
     }
}

Regards,

Rajesh Kamal.

Reply
0 Kudos
aleti
Enthusiast
Enthusiast
Jump to solution

Thanks Rajesh, It's really help full for me a able to execute this code to delete the catalogs for vcd1.5

Reply
0 Kudos