Search in sources :

Example 6 with Vcenter

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

the class TenantsService method createVcenter.

/**
 * Creates a new vCenter for the tenant organization. Discovery is initiated
 * after the vCenter is created.
 *
 * @param tid
 *            the tenant organization id
 * @param createParam
 *            the parameter that has the attributes of the vCenter to be created.
 * @prereq none
 * @brief Create tenant vCenter
 * @return the vCenter discovery async task.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/vcenters")
public TaskResourceRep createVcenter(@PathParam("id") URI tid, VcenterCreateParam createParam, @QueryParam("validate_connection") @DefaultValue("false") final Boolean validateConnection) {
    // This validates the tenant
    TenantOrg tenant = getTenantById(tid, true);
    VcenterService service = _vcenterService;
    // validates the create param and validation is successful then creates and persist the vcenter
    Vcenter vcenter = service.createNewTenantVcenter(tenant, createParam, validateConnection);
    vcenter.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
    _dbClient.createObject(vcenter);
    recordTenantResourceOperation(OperationTypeEnum.CREATE_VCENTER, tid, vcenter);
    return service.doDiscoverVcenter(vcenter);
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with Vcenter

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

the class ActionableEventExecutor method hostVcenterUnassignDetails.

/**
 * Get details for the hostVcenterUnassign method
 * NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
 *
 * @param hostId the host id to unassign from vCenter
 * @return list of event details
 */
// Invoked using reflection for the event framework
@SuppressWarnings("unused")
public List<String> hostVcenterUnassignDetails(URI hostId) {
    List<String> result = Lists.newArrayList();
    Host host = _dbClient.queryObject(Host.class, hostId);
    if (host != null) {
        Vcenter vcenter = ComputeSystemHelper.getHostVcenter(_dbClient, host);
        result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterUnassignDetails", host.getLabel(), vcenter == null ? "N/A" : vcenter.getLabel()));
        result.addAll(hostClusterChangeDetails(hostId, NullColumnValueGetter.getNullURI(), NullColumnValueGetter.getNullURI(), true));
    }
    return result;
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) Host(com.emc.storageos.db.client.model.Host)

Example 8 with Vcenter

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

the class ComputeSystemControllerImpl method attachAndMount.

/**
 * Attaches and mounts every disk and datastore associated with the volumes in the export group.
 * For each volume in the export group, the associated disk is attached to the host and any datastores backed by the
 * volume are mounted
 * to the host.
 *
 * @param exportGroupId
 *            export group that contains volumes
 * @param hostId
 *            host to attach and mount to
 * @param vcenterId
 *            vcenter that the host belongs to
 * @param vcenterDatacenter
 *            vcenter datacenter that the host belongs to
 * @param stepId
 *            the id of the workflow step
 */
public void attachAndMount(URI exportGroupId, URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
    WorkflowStepCompleter.stepExecuting(stepId);
    try {
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_054);
        Host esxHost = _dbClient.queryObject(Host.class, hostId);
        Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
        VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupId);
        VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
        HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
        if (hostSystem == null) {
            _log.info("Not able to find host " + esxHost.getLabel() + " in vCenter. Unable to attach disks and mount datastores");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
        if (exportGroup != null && exportGroup.getVolumes() != null) {
            _log.info("Refreshing storage");
            storageAPI.refreshStorage();
            Set<BlockObject> blockObjects = Sets.newHashSet();
            for (String volume : exportGroup.getVolumes().keySet()) {
                BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
                blockObjects.add(blockObject);
                for (HostScsiDisk entry : storageAPI.listScsiDisks()) {
                    if (VolumeWWNUtils.wwnMatches(VMwareUtils.getDiskWwn(entry), blockObject.getWWN())) {
                        if (VMwareUtils.isDiskOff(entry)) {
                            _log.info("Attach SCSI Lun " + entry.getCanonicalName() + " on host " + esxHost.getLabel());
                            storageAPI.attachScsiLun(entry);
                        }
                        // Test mechanism to invoke a failure. No-op on production systems.
                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_055);
                        break;
                    }
                }
            }
            int retries = 0;
            while (retries++ < MAXIMUM_RESCAN_ATTEMPTS && !blockObjects.isEmpty()) {
                _log.info("Rescanning VMFS for host " + esxHost.getLabel());
                storageAPI.getStorageSystem().rescanVmfs();
                _log.info("Waiting for {} milliseconds before checking for datastores", RESCAN_DELAY_MS);
                Thread.sleep(RESCAN_DELAY_MS);
                _log.info("Looking for datastores for {} volumes", blockObjects.size());
                Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(hostSystem);
                Iterator<BlockObject> objectIterator = blockObjects.iterator();
                while (objectIterator.hasNext()) {
                    BlockObject blockObject = objectIterator.next();
                    if (blockObject != null) {
                        Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
                        if (datastore != null && VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
                            _log.info("Datastore {} is already mounted on {}", datastore.getName(), esxHost.getLabel());
                            objectIterator.remove();
                        } else if (datastore != null && !VMwareUtils.isDatastoreMountedOnHost(datastore, hostSystem)) {
                            _log.info("Mounting datastore {} on host {}", datastore.getName(), esxHost.getLabel());
                            storageAPI.mountDatastore(datastore);
                            objectIterator.remove();
                            // Test mechanism to invoke a failure. No-op on production systems.
                            InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_056);
                        }
                    }
                }
            }
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception ex) {
        _log.error(ex.getMessage(), ex);
        WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) Vcenter(com.emc.storageos.db.client.model.Vcenter) Host(com.emc.storageos.db.client.model.Host) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Datastore(com.vmware.vim25.mo.Datastore) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostScsiDisk(com.vmware.vim25.HostScsiDisk) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 9 with Vcenter

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

the class ComputeSystemControllerImpl method rescanHostStorage.

/**
 * Rescans HBAs and storage system for an ESX host
 *
 * @param hostId the host id
 * @param vCenterId the vcenter id
 * @param vcenterDatacenter the vcenter datacenter id
 * @param stepId the workflow step
 */
public void rescanHostStorage(URI hostId, URI vCenterId, URI vcenterDatacenter, String stepId) {
    WorkflowStepCompleter.stepExecuting(stepId);
    try {
        Host esxHost = _dbClient.queryObject(Host.class, hostId);
        Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
        VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
        VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
        HostSystem hostSystem = api.findHostSystem(vCenterDataCenter.getLabel(), esxHost.getLabel());
        if (hostSystem == null) {
            _log.info("Not able to find host {} in vCenter. Unable to refresh HBAs", esxHost.getLabel());
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        HostStorageAPI storageAPI = new HostStorageAPI(hostSystem);
        storageAPI.refreshStorage();
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception ex) {
        _log.error(ex.getMessage(), ex);
        WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) Vcenter(com.emc.storageos.db.client.model.Vcenter) HostSystem(com.vmware.vim25.mo.HostSystem) Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) HostStorageAPI(com.iwave.ext.vmware.HostStorageAPI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException)

Example 10 with Vcenter

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

the class ComputeSystemControllerImpl method verifyDatastore.

/**
 * Verifies that datastores contained within an export group can be unmounted. It must not be entering maintenance mode or contain any
 * virtual machines running on the given ESXi host.
 *
 * @param exportGroupId
 *            export group that contains volumes
 * @param vcenterId
 *            vcenter that the host belongs to
 * @param vcenterDatacenter
 *            vcenter datacenter that the host belongs to
 * @param esxHostname
 *            the hostname of the ESXi host
 *
 * @param stepId
 *            the id of the workflow step
 */
public void verifyDatastore(URI exportGroupId, URI vCenterId, URI vcenterDatacenter, String esxHostname, String stepId) {
    WorkflowStepCompleter.stepExecuting(stepId);
    try {
        Vcenter vCenter = _dbClient.queryObject(Vcenter.class, vCenterId);
        VcenterDataCenter vCenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, vcenterDatacenter);
        ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupId);
        VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vCenter);
        HostSystem host = api.findHostSystem(vCenterDataCenter.getLabel(), esxHostname);
        if (host == null) {
            _log.info("Not able to find host " + esxHostname + " in vCenter. Unable to validate");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        Map<String, Datastore> wwnDatastores = getWwnDatastoreMap(host);
        if (exportGroup != null && exportGroup.getVolumes() != null) {
            for (String volume : exportGroup.getVolumes().keySet()) {
                BlockObject blockObject = BlockObject.fetch(_dbClient, URI.create(volume));
                Datastore datastore = getDatastoreByWwn(wwnDatastores, blockObject.getWWN());
                if (datastore != null) {
                    ComputeSystemHelper.verifyDatastore(datastore, host);
                }
            }
        }
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_029);
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception ex) {
        _log.error(ex.getMessage(), ex);
        WorkflowStepCompleter.stepFailed(stepId, DeviceControllerException.errors.jobFailed(ex));
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) Vcenter(com.emc.storageos.db.client.model.Vcenter) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Datastore(com.vmware.vim25.mo.Datastore) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) BlockObject(com.emc.storageos.db.client.model.BlockObject) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) RemoteException(java.rmi.RemoteException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) ClientControllerException(com.emc.storageos.exceptions.ClientControllerException)

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