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;
}
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);
}
}
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;
}
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);
}
}
}
}
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);
}
}
Aggregations