use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class VcenterDataCenterCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
super.complete(dbClient, status, coded);
switch(status) {
case error:
dbClient.error(VcenterDataCenter.class, this.getId(), getOpId(), coded);
break;
default:
dbClient.ready(VcenterDataCenter.class, this.getId(), getOpId());
}
if (deactivateOnComplete && status.equals(Status.ready)) {
VcenterDataCenter datacenter = dbClient.queryObject(VcenterDataCenter.class, this.getId());
if (datacenter != null && !datacenter.getInactive()) {
ComputeSystemHelper.doDeactivateVcenterDataCenter(dbClient, datacenter);
_logger.info("Deactivating datacenter: " + this.getId());
}
}
}
use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class VcenterDiscoveryAdapter method discoveryFailure.
@Override
public void discoveryFailure(DiscoveredSystemObject target, String compatibilityStatus, String errorMessage) {
super.discoveryFailure(target, compatibilityStatus, errorMessage);
Vcenter vcenter = getModelClient().vcenters().findById(target.getId());
Iterable<VcenterDataCenter> dataCenters = getModelClient().datacenters().findByVCenter(vcenter.getId(), true);
for (VcenterDataCenter dataCenter : dataCenters) {
Iterable<Host> hosts = getModelClient().hosts().findByVcenterDatacenter(dataCenter.getId());
for (Host host : hosts) {
host.setDiscoveryStatus(DataCollectionJobStatus.ERROR.name());
host.setLastDiscoveryRunTime(System.currentTimeMillis());
host.setCompatibilityStatus(compatibilityStatus);
host.setLastDiscoveryStatusMessage("vCenter Discovery Failed: " + errorMessage);
save(host);
}
}
}
use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class VcenterDiscoveryAdapter method deleteDatacenters.
private void deleteDatacenters(Iterable<VcenterDataCenter> datacenters, List<URI> deletedHosts, List<URI> deletedClusters) {
for (VcenterDataCenter datacenter : datacenters) {
boolean containsHosts = false;
boolean clustersInUse = false;
for (Cluster cluster : getClusters(datacenter)) {
deletedClusters.add(cluster.getId());
}
for (Host host : getHosts(datacenter)) {
deletedHosts.add(host.getId());
containsHosts = true;
}
for (Cluster cluster : getClusters(datacenter)) {
URI clusterId = cluster.getId();
List<URI> hostUris = ComputeSystemHelper.getChildrenUris(dbClient, clusterId, Host.class, "cluster");
if (hostUris.isEmpty() && !ComputeSystemHelper.isClusterInExport(dbClient, clusterId) && EventUtils.findAffectedResourcePendingEvents(dbClient, clusterId).isEmpty()) {
info("Deactivating Cluster: " + clusterId);
ComputeSystemHelper.doDeactivateCluster(dbClient, cluster);
} else {
info("Unable to delete cluster " + clusterId);
clustersInUse = true;
}
}
// delete datacenters that don't contain any clusters or hosts, don't have any exports, and don't have any pending events
if (!containsHosts && !clustersInUse && !ComputeSystemHelper.isDataCenterInUse(dbClient, datacenter.getId()) && EventUtils.findAffectedResourcePendingEvents(dbClient, datacenter.getId()).isEmpty()) {
info("Deactivating Datacenter: " + datacenter.getId());
ComputeSystemHelper.doDeactivateVcenterDataCenter(dbClient, datacenter);
} else {
info("Unable to delete datacenter " + datacenter.getId());
}
}
}
use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class VirtualMachineTest method testFindByDatacenter.
@Test
public void testFindByDatacenter() throws Exception {
_logger.info("Starting findByDatacenter test");
ModelClient modelClient = getModelClient();
Vcenter v2 = createVCenterWithLabel("v2");
modelClient.save(v2);
VcenterDataCenter dc2 = createDatacenterWithLabel("dc2");
dc2.setVcenter(v2.getId());
modelClient.save(dc2);
VirtualMachine vm1 = createWithLabel("vm1");
vm1.setDatacenterId(new NamedURI(dc2.getId(), dc2.getLabel()));
modelClient.save(vm1);
VcenterDataCenter dc3 = createDatacenterWithLabel("dc3");
dc3.setVcenter(v2.getId());
modelClient.save(dc3);
VirtualMachine vm2 = createWithLabel("vm2");
vm2.setDatacenterId(new NamedURI(dc3.getId(), dc3.getLabel()));
modelClient.save(vm2);
VirtualMachine vm3 = createWithLabel("vm3");
vm3.setDatacenterId(new NamedURI(dc3.getId(), dc3.getLabel()));
modelClient.save(vm3);
List<VirtualMachine> virtualMachines = modelClient.virtualMachines().findByDatacenter(dc2.getId());
Assert.assertNotNull(virtualMachines);
Assert.assertEquals(1, virtualMachines.size());
virtualMachines = modelClient.virtualMachines().findByDatacenter(dc3.getId());
Assert.assertNotNull(virtualMachines);
Assert.assertEquals(2, virtualMachines.size());
}
use of com.emc.storageos.db.client.model.VcenterDataCenter in project coprhd-controller by CoprHD.
the class VirtualMachineTest method createDatacenterWithLabel.
private VcenterDataCenter createDatacenterWithLabel(String label) {
VcenterDataCenter model = new VcenterDataCenter();
model.setId(URIUtil.createId(VcenterDataCenter.class));
model.setLabel(label);
return model;
}
Aggregations