Search in sources :

Example 11 with VcenterDataCenter

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());
        }
    }
}
Also used : VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter)

Example 12 with VcenterDataCenter

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);
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host)

Example 13 with VcenterDataCenter

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());
        }
    }
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 14 with VcenterDataCenter

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());
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) NamedURI(com.emc.storageos.db.client.model.NamedURI) ModelClient(com.emc.sa.model.dao.ModelClient) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VirtualMachine(com.emc.storageos.db.client.model.uimodels.VirtualMachine) Test(org.junit.Test)

Example 15 with VcenterDataCenter

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;
}
Also used : VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter)

Aggregations

VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)40 Host (com.emc.storageos.db.client.model.Host)27 Vcenter (com.emc.storageos.db.client.model.Vcenter)25 Cluster (com.emc.storageos.db.client.model.Cluster)19 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)15 URI (java.net.URI)12 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)11 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)11 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)11 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)11 VcenterApiClient (com.emc.storageos.vcentercontroller.VcenterApiClient)10 HostSystem (com.vmware.vim25.mo.HostSystem)9 VCenterAPI (com.iwave.ext.vmware.VCenterAPI)7 GetVcenterDataCenter (com.emc.sa.service.vmware.tasks.GetVcenterDataCenter)4 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)4 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)4 ClientControllerException (com.emc.storageos.exceptions.ClientControllerException)4 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)4 ControllerException (com.emc.storageos.volumecontroller.ControllerException)4