Search in sources :

Example 71 with Host

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

the class XIVExportOperations method refreshSMISExportMask.

private ExportMask refreshSMISExportMask(StorageSystem storage, ExportMask mask) {
    try {
        CIMInstance instance = _helper.getSCSIProtocolController(storage, mask);
        if (instance != null) {
            StringBuilder builder = new StringBuilder();
            String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_NAME);
            // Get volumes and initiators for the masking instance
            CIMObjectPath controllerPath = instance.getObjectPath();
            Map<String, Integer> discoveredVolumes = _helper.getVolumesFromScsiProtocolController(storage, controllerPath);
            Map<String, CIMObjectPath> discoveredPortPaths = _helper.getInitiatorsFromScsiProtocolController(storage, instance.getObjectPath());
            Set<String> discoveredPorts = discoveredPortPaths.keySet();
            Set existingInitiators = (mask.getExistingInitiators() != null) ? mask.getExistingInitiators() : Collections.emptySet();
            Set existingVolumes = (mask.getExistingVolumes() != null) ? mask.getExistingVolumes().keySet() : Collections.emptySet();
            builder.append(String.format("%nXM object: %s I{%s} V:{%s}%n", name, Joiner.on(',').join(existingInitiators), Joiner.on(',').join(existingVolumes)));
            builder.append(String.format("XM discovered: %s I:{%s} V:{%s}%n", name, Joiner.on(',').join(discoveredPorts), Joiner.on(',').join(discoveredVolumes.keySet())));
            // Check the initiators and update the lists as necessary
            boolean addInitiators = false;
            List<String> initiatorsToAdd = new ArrayList<String>();
            for (String port : discoveredPorts) {
                String normalizedPort = Initiator.normalizePort(port);
                if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
                    initiatorsToAdd.add(normalizedPort);
                    addInitiators = true;
                }
            }
            boolean removeInitiators = false;
            List<String> initiatorsToRemove = new ArrayList<String>();
            if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
                initiatorsToRemove.addAll(mask.getExistingInitiators());
                initiatorsToRemove.removeAll(discoveredPorts);
                removeInitiators = !initiatorsToRemove.isEmpty();
            }
            // Check the volumes and update the lists as necessary
            Map<String, Integer> volumesToAdd = ExportMaskUtils.diffAndFindNewVolumes(mask, discoveredVolumes);
            boolean addVolumes = !volumesToAdd.isEmpty();
            boolean removeVolumes = false;
            List<String> volumesToRemove = new ArrayList<String>();
            if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
                volumesToRemove.addAll(mask.getExistingVolumes().keySet());
                volumesToRemove.removeAll(discoveredVolumes.keySet());
                removeVolumes = !volumesToRemove.isEmpty();
            }
            boolean changeName = false;
            if (!mask.getMaskName().equals(name)) {
                changeName = true;
                mask.setLabel(name);
                mask.setMaskName(name);
                // update host label
                StringSet initiators = mask.getInitiators();
                if (initiators != null) {
                    Iterator<String> itr = initiators.iterator();
                    if (itr.hasNext()) {
                        Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(itr.next()));
                        Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                        String label = host.getLabel();
                        if (label.equals(name)) {
                            _helper.unsetTag(host, storage.getSerialNumber());
                        } else {
                            _helper.setTag(host, storage.getSerialNumber(), name);
                        }
                    }
                }
            }
            builder.append(String.format("XM refresh: %s initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAdd), Joiner.on(',').join(initiatorsToRemove)));
            builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
            // Any changes indicated, then update the mask and persist it
            if (addInitiators || removeInitiators || addVolumes || removeVolumes || changeName) {
                builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
                mask.removeFromExistingInitiators(initiatorsToRemove);
                mask.addToExistingInitiatorsIfAbsent(initiatorsToAdd);
                mask.removeFromExistingVolumes(volumesToRemove);
                mask.addToExistingVolumesIfAbsent(volumesToAdd);
                ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
                _dbClient.updateAndReindexObject(mask);
            } else {
                builder.append("XM refresh: There are no changes to the mask\n");
            }
            _networkDeviceController.refreshZoningMap(mask, initiatorsToRemove, Collections.EMPTY_LIST, (addInitiators || removeInitiators), true);
            _log.info(builder.toString());
        }
    } catch (Exception e) {
        boolean throwException = true;
        if (e instanceof WBEMException) {
            WBEMException we = (WBEMException) e;
            // Only throw exception if code is not CIM_ERROR_NOT_FOUND
            throwException = (we.getID() != WBEMException.CIM_ERR_NOT_FOUND);
        }
        if (throwException) {
            String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
            _log.error(MessageFormat.format("Encountered an SMIS error when attempting to refresh existing exports: {0}", msg), e);
            throw SmisException.exceptions.refreshExistingMaskFailure(msg, e);
        }
    }
    return mask;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 72 with Host

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

the class CustomMigrationCallbackExample method validateHostLabelLength.

private void validateHostLabelLength() throws MigrationCallbackException {
    try {
        DbClient dbClient = this.getDbClient();
        List<URI> hostIds = dbClient.queryByType(Host.class, true);
        Iterator<Host> hosts = dbClient.queryIterativeObjects(Host.class, hostIds, true);
        while (hosts.hasNext()) {
            Host host = hosts.next();
            if (host.getLabel() != null && host.getLabel().length() < MIN_LABEL_LENGTH) {
                String errorMsg = String.format("%s failed: invalid label length %s(%s)", this.getName(), Host.class.getSimpleName(), host.getId().toString());
                throw new MigrationCallbackException(errorMsg, new IllegalStateException());
            }
        }
    } catch (Exception e) {
        String errorMsg = String.format("%s encounter unexpected error %s", this.getName(), e.getMessage());
        throw new MigrationCallbackException(errorMsg, e);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)

Example 73 with Host

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

the class HostFinder method findByUuid.

public Host findByUuid(String uuid) {
    List<NamedElement> hostIds = client.findByAlternateId(Host.class, HOST_UUID_COLUMN_NAME, uuid);
    Iterable<Host> hosts = client.findByIds(Host.class, toURIs(hostIds), true);
    for (Host host : hosts) {
        return host;
    }
    return null;
}
Also used : Host(com.emc.storageos.db.client.model.Host) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 74 with Host

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

the class UnexportVMwareVolumeService method precheck.

@Override
public void precheck() throws Exception {
    super.precheck();
    List<Host> hosts = Lists.newArrayList();
    if (BlockStorageUtils.isCluster(hostId)) {
        clusterInstance = BlockStorageUtils.getCluster(hostId);
        exports = BlockStorageUtils.findExportsContainingCluster(hostId, null, null);
        hosts = getModelClient().hosts().findByCluster(hostId);
    } else {
        hostInstance = BlockStorageUtils.getHost(hostId);
        exports = BlockStorageUtils.findExportsContainingHost(hostId, null, null);
        hosts = Arrays.asList(hostInstance);
    }
    filteredExportGroups = BlockStorageUtils.filterExportsByType(exports, hostId);
    String hostOrClusterLabel = clusterInstance == null ? hostInstance.getLabel() : clusterInstance.getLabel();
    if (filteredExportGroups.isEmpty()) {
        ExecutionUtils.fail("failTask.UnexportHostService.export", args(), args(hostOrClusterLabel));
    }
    volumes = BlockStorageUtils.getBlockResources(uris(volumeIds));
    if (volumes.isEmpty()) {
        ExecutionUtils.fail("failTask.UnexportHostService.volumes", args(), args());
    }
    if (volumes.size() < volumeIds.size()) {
        logWarn("unexport.host.service.not.found", volumeIds.size(), volumes.size());
    }
    for (BlockObjectRestRep volume : volumes) {
        String datastoreName = KnownMachineTags.getBlockVolumeVMFSDatastore(hostId, volume);
        if (!StringUtils.isEmpty(datastoreName)) {
            Datastore datastore = vmware.getDatastore(datacenter.getLabel(), datastoreName);
            if (datastore != null) {
                vmware.verifyDatastoreForRemoval(datastore, datacenter.getLabel(), hosts);
            }
        }
    }
}
Also used : Datastore(com.vmware.vim25.mo.Datastore) Host(com.emc.storageos.db.client.model.Host) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep)

Example 75 with Host

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

the class VerifyDatastoreForRemoval method execute.

@Override
public void execute() throws Exception {
    DatastoreSummary summary = datastore.getSummary();
    if (summary == null) {
        throw stateException("verify.datastore.removal.illegalState.summaryUnavailable", datastore.getName());
    }
    checkDatastoreAccessibility(summary);
    ComputeSystemHelper.checkMaintenanceMode(datastore, summary);
    if (hosts != null && !hosts.isEmpty()) {
        for (Host host : hosts) {
            HostSystem hostSystem = vcenter.findHostSystem(datacenterName, host.getHostName());
            ComputeSystemHelper.checkVirtualMachines(datastore, hostSystem);
        }
    } else if (hostSystems != null && !hostSystems.isEmpty()) {
        for (HostSystem hostSystem : hostSystems) {
            ComputeSystemHelper.checkVirtualMachines(datastore, hostSystem);
        }
    } else {
        ComputeSystemHelper.checkVirtualMachines(datastore, null);
    }
}
Also used : DatastoreSummary(com.vmware.vim25.DatastoreSummary) HostSystem(com.vmware.vim25.mo.HostSystem) Host(com.emc.storageos.db.client.model.Host)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16