Search in sources :

Example 1 with Vcenter

use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method createOrUpdateVcenterCluster.

private void createOrUpdateVcenterCluster(boolean createCluster, AsyncTask task, URI clusterUri, URI[] addHostUris, URI[] removeHostUris, URI[] volumeUris) throws InternalException {
    TaskCompleter completer = null;
    try {
        _log.info("createOrUpdateVcenterCluster " + createCluster + " " + task + " " + clusterUri + " " + addHostUris + " " + removeHostUris);
        if (task == null) {
            _log.error("AsyncTask is null");
            throw new Exception("AsyncTask is null");
        }
        URI vcenterDataCenterId = task._id;
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDataCenterId);
        if (clusterUri == null) {
            _log.error("Cluster URI is null");
            throw new Exception("Cluster URI is null");
        }
        Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
        Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
        _log.info("Request to create or update cluster " + vcenter.getIpAddress() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel());
        Collection<Host> addHosts = new ArrayList<Host>();
        if (addHostUris == null || addHostUris.length == 0) {
            _log.info("Add host URIs is null or empty - Cluster will be created without hosts");
        } else {
            for (URI hostUri : addHostUris) {
                _log.info("createOrUpdateVcenterCluster " + clusterUri + " with add host " + hostUri);
            }
            addHosts = _dbClient.queryObject(Host.class, addHostUris);
        }
        Collection<Host> removeHosts = new ArrayList<Host>();
        if (removeHostUris == null || removeHostUris.length == 0) {
            _log.info("Remove host URIs is null or empty - Cluster will have no removed hosts");
        } else {
            for (URI hostUri : removeHostUris) {
                _log.info("createOrUpdateVcenterCluster " + clusterUri + " with remove host " + hostUri);
            }
            removeHosts = _dbClient.queryObject(Host.class, removeHostUris);
        }
        Collection<Volume> volumes = new ArrayList<Volume>();
        if (volumeUris == null || volumeUris.length == 0) {
            _log.info("Volume URIs is null or empty - Cluster will be created without datastores");
        } else {
            for (URI volumeUri : volumeUris) {
                _log.info("createOrUpdateVcenterCluster " + clusterUri + " with volume " + volumeUri);
            }
            volumes = _dbClient.queryObject(Volume.class, volumeUris);
        }
        completer = new VcenterClusterCompleter(vcenterDataCenterId, task._opId, OperationTypeEnum.CREATE_UPDATE_VCENTER_CLUSTER, "VCENTER_CONTROLLER");
        Workflow workflow = _workflowService.getNewWorkflow(this, "CREATE_UPDATE_VCENTER_CLUSTER_WORKFLOW", true, task._opId);
        String clusterStep = workflow.createStep("CREATE_UPDATE_VCENTER_CLUSTER_STEP", String.format("vCenter cluster operation in vCenter datacenter %s", vcenterDataCenterId), null, vcenterDataCenterId, vcenterDataCenterId.toString(), this.getClass(), new Workflow.Method("createUpdateVcenterClusterOperation", createCluster, vcenter.getId(), vcenterDataCenter.getId(), cluster.getId()), null, null);
        String lastStep = clusterStep;
        if (!removeHosts.isEmpty()) {
            for (Host host : removeHosts) {
                String hostStep = workflow.createStep("VCENTER_CLUSTER_REMOVE_HOST", String.format("vCenter cluster remove host operation %s", host.getId()), clusterStep, vcenterDataCenterId, vcenterDataCenterId.toString(), this.getClass(), new Workflow.Method("vcenterClusterRemoveHostOperation", vcenter.getId(), vcenterDataCenter.getId(), cluster.getId(), host.getId()), null, null);
                // add host will wait on last of these
                lastStep = hostStep;
            }
        }
        if (!addHosts.isEmpty()) {
            for (Host host : addHosts) {
                String hostStep = workflow.createStep("VCENTER_CLUSTER_ADD_HOST", String.format("vCenter cluster add host operation %s", host.getId()), lastStep, vcenterDataCenterId, vcenterDataCenterId.toString(), this.getClass(), new Workflow.Method("vcenterClusterAddHostOperation", vcenter.getId(), vcenterDataCenter.getId(), cluster.getId(), host.getId()), null, null);
            }
        }
        workflow.executePlan(completer, "Success");
    } catch (Exception e) {
        _log.error("createOrUpdateVcenterCluster caught an exception.", e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        completer.error(_dbClient, serviceError);
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ArrayList(java.util.ArrayList) VcenterClusterCompleter(com.emc.storageos.vcentercontroller.VcenterClusterCompleter) Cluster(com.emc.storageos.db.client.model.Cluster) Workflow(com.emc.storageos.workflow.Workflow) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) Volume(com.emc.storageos.db.client.model.Volume) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter)

Example 2 with Vcenter

use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method removeVcenterCluster.

@Override
public void removeVcenterCluster(URI datacenterUri, URI clusterUri) throws InternalException {
    VcenterApiClient vcenterApiClient = null;
    try {
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
        Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
        Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
        _log.info("Request to remove cluster " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel());
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        vcenterApiClient.removeCluster(vcenterDataCenter.getLabel(), cluster.getExternalId());
    } catch (VcenterObjectConnectionException e) {
        throw VcenterControllerException.exceptions.objectConnectionException(e.getLocalizedMessage(), e);
    } catch (VcenterObjectNotFoundException e) {
        throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
    } catch (VcenterServerConnectionException e) {
        throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
    } catch (Exception e) {
        _log.error("removeVcenterCluster exception " + e);
        throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)

Example 3 with Vcenter

use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.

the class VcenterControllerImpl method exitMaintenanceMode.

@Override
public void exitMaintenanceMode(URI datacenterUri, URI clusterUri, URI hostUri) throws InternalException {
    VcenterApiClient vcenterApiClient = null;
    try {
        Host host = _dbClient.queryObject(Host.class, hostUri);
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
        Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
        Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
        _log.info("Request to exit maintenance mode for " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel() + "/" + host.getHostName());
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        vcenterApiClient.exitMaintenanceMode(vcenterDataCenter.getLabel(), cluster.getExternalId(), host.getHostName());
    } catch (VcenterObjectConnectionException e) {
        throw VcenterControllerException.exceptions.objectConnectionException(e.getLocalizedMessage(), e);
    } catch (VcenterObjectNotFoundException e) {
        throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
    } catch (VcenterServerConnectionException e) {
        throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
    } catch (Exception e) {
        _log.error("exitMaintenanceMode exception " + e);
        throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)

Example 4 with Vcenter

use of com.emc.storageos.db.client.model.Vcenter in project coprhd-controller by CoprHD.

the class VcenterDiscoveryAdapter method discoverTarget.

@Override
public void discoverTarget(String targetId) {
    Vcenter vcenter = getModelClient().vcenters().findById(targetId);
    discoverVCenter(vcenter);
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter)

Example 5 with Vcenter

use of com.emc.storageos.db.client.model.Vcenter 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)

Aggregations

Vcenter (com.emc.storageos.db.client.model.Vcenter)35 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)25 Host (com.emc.storageos.db.client.model.Host)18 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)15 Cluster (com.emc.storageos.db.client.model.Cluster)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)8 VCenterAPI (com.iwave.ext.vmware.VCenterAPI)7 URI (java.net.URI)7 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)5 GetVcenter (com.emc.sa.service.vmware.tasks.GetVcenter)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