public static void doDeactivateVcenterDataCenter(DbClient dbClient,VcenterDataCenter dataCenter){
  List<NamedElementQueryResultList.NamedElement> hostUris=listChildren(dbClient,dataCenter.getId(),Host.class,"label","vcenterDataCenter");
  Set<URI> doNotDeleteclusters=new HashSet<URI>();
  for (  NamedElementQueryResultList.NamedElement hostUri : hostUris) {
    Host host=dbClient.queryObject(Host.class,hostUri.getId());
    if (host != null && !host.getInactive()) {
      if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        doDeactivateHost(dbClient,host);
      }
 else {
        host.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
        dbClient.persistObject(host);
        if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
          doNotDeleteclusters.add(host.getCluster());
        }
      }
    }
  }
  List<NamedElementQueryResultList.NamedElement> clustersUris=listChildren(dbClient,dataCenter.getId(),Cluster.class,"label","vcenterDataCenter");
  for (  NamedElementQueryResultList.NamedElement clusterUri : clustersUris) {
    Cluster cluster=dbClient.queryObject(Cluster.class,clusterUri.getId());
    if (cluster != null && !cluster.getInactive()) {
      if (doNotDeleteclusters.contains(cluster.getId())) {
        cluster.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
        cluster.setExternalId(NullColumnValueGetter.getNullStr());
        dbClient.persistObject(cluster);
      }
 else {
        dbClient.markForDeletion(cluster);
        EventUtils.deleteResourceEvents(dbClient,cluster.getId());
      }
    }
  }
  _log.info("marking DC for deletion: {} {}",dataCenter.getLabel(),dataCenter.getId());
  dbClient.markForDeletion(dataCenter);
  EventUtils.deleteResourceEvents(dbClient,dataCenter.getId());
}

public static void doDeactivateVcenterDataCenter ( DbClient dbClient , VcenterDataCenter dataCenter ) { List < NamedElementQueryResultList . NamedElement > hostUris = listChildren ( dbClient , dataCenter . getId ( ) , Host . class , "label" , "vcenterDataCenter" ) ; Set < URI > doNotDeleteclusters = new HashSet < URI > ( ) ; for ( NamedElementQueryResultList . NamedElement hostUri : hostUris ) { Host host = dbClient . queryObject ( Host . class , hostUri . getId ( ) ) ; if ( host != null && ! host . getInactive ( ) ) { if ( NullColumnValueGetter . isNullURI ( host . getComputeElement ( ) ) ) { doDeactivateHost ( dbClient , host ) ; } else { host . setVcenterDataCenter ( NullColumnValueGetter . getNullURI ( ) ) ; dbClient . persistObject ( host ) ; if ( ! NullColumnValueGetter . isNullURI ( host . getCluster ( ) ) ) { doNotDeleteclusters . add ( host . getCluster ( ) ) ; } } } } List < NamedElementQueryResultList . NamedElement > clustersUris = listChildren ( dbClient , dataCenter . getId ( ) , Cluster . class , "label" , "vcenterDataCenter" ) ; for ( NamedElementQueryResultList . NamedElement clusterUri : clustersUris ) { Cluster cluster = dbClient . queryObject ( Cluster . class , clusterUri . getId ( ) ) ; if ( cluster != null && ! cluster . getInactive ( ) ) { if ( doNotDeleteclusters . contains ( cluster . getId ( ) ) ) { cluster . setVcenterDataCenter ( NullColumnValueGetter . getNullURI ( ) ) ; cluster . setExternalId ( NullColumnValueGetter . getNullStr ( ) ) ; dbClient . persistObject ( cluster ) ; } else { dbClient . markForDeletion ( cluster ) ; EventUtils . deleteResourceEvents ( dbClient , cluster . getId ( ) ) ; } } } _log . info ( "marking DC for deletion: {} {}" , dataCenter . getLabel ( ) , dataCenter . getId ( ) ) ; dbClient . markForDeletion ( dataCenter ) ; EventUtils . deleteResourceEvents ( dbClient , dataCenter . getId ( ) ) ; }
utility function to recursively deactivate all the hosts / clusters from datacenter
