use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportGroupService method searchForClusterExport.
/**
* Performs the search query based on the cluster Id.
*
* @param clusterId search param
* @param resRepLists result
* @param selfOnly true or false
*/
private void searchForClusterExport(String clusterId, List<SearchResultResourceRep> resRepLists, boolean selfOnly, boolean authorized) {
URIQueryResultList egUris = new URIQueryResultList();
Set<URI> resultUris = new HashSet<URI>();
List<ExportGroup> exportGroups = new ArrayList<ExportGroup>();
if (selfOnly) {
exportGroups = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, ExportGroup.class, AlternateIdConstraint.Factory.getConstraint(ExportGroup.class, "clusters", clusterId));
} else {
List<NamedElement> hostElements = getModelClient().hosts().findIdsByCluster(URI.create(clusterId));
List<URI> hosts = toURIs(hostElements);
for (URI hUri : hosts) {
List<NamedElement> initiatorElements = getModelClient().initiators().findIdsByHost(hUri);
List<URI> initiators = toURIs(initiatorElements);
for (URI iUri : initiators) {
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportGroupInitiatorConstraint(iUri.toString()), egUris);
for (URI eUri : egUris) {
resultUris.add(eUri);
}
}
}
exportGroups = _dbClient.queryObject(ExportGroup.class, resultUris, true);
}
buildExportGroupSearchResponse(exportGroups, resRepLists, selfOnly, ExportGroupType.Cluster.name(), authorized);
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportGroupService method getPortGroupsForPortGroupChange.
/**
* Get list of eligible port groups for Change Port Group for Host operation.
* This API returns the list of Port Groups that a user can choose from for the Change Port Group for Host operation. Currently this API
* is available only for VMAX systems
*
* @param currentPortGroupURI contains CurrentPortGroup
* @param hostOrClusterIDURI contains Host/ClusterID
* @param varrayIDURI contains varrayID
* @return the list of port groups that are eligible for CHnage Port Group for Host
* @throws ControllerException
*/
@GET
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/target-storage-port-groups")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public StoragePortGroupChangeList getPortGroupsForPortGroupChange(@QueryParam("currentPortGroup") String currentPortGroupURI, @QueryParam("hostOrClusterID") String hostOrClusterIDURI, @QueryParam("varrayID") String varrayIDURI) throws ControllerException {
ArgValidator.checkFieldNotEmpty(currentPortGroupURI, "currentPortGroup");
ArgValidator.checkFieldNotEmpty(hostOrClusterIDURI, "hostOrClusterID");
ArgValidator.checkFieldNotEmpty(varrayIDURI, "varrayID");
ArgValidator.checkUri(URIUtil.uri(currentPortGroupURI));
_log.info("verfying Port Group id: {}", currentPortGroupURI);
ArgValidator.checkUri(URIUtil.uri(hostOrClusterIDURI));
_log.info("verfying Host/Cluster id: {}", hostOrClusterIDURI);
ArgValidator.checkUri(URIUtil.uri(varrayIDURI));
_log.info("verfying Virtual Array id: {}", varrayIDURI);
// Get the current port group
StoragePortGroup currentPortGroup = queryObject(StoragePortGroup.class, URIUtil.uri(currentPortGroupURI), true);
// Get the storage system of current port group
URI currrentPortGroupStorageSystem = currentPortGroup.getStorageDevice();
StorageSystem currentStorageSystem = queryObject(StorageSystem.class, currrentPortGroupStorageSystem, true);
_log.info("storage system of current port group: {}", currentStorageSystem.getId());
// Get the ports of the current port group
StringSet currentPortGroupPorts = currentPortGroup.getStoragePorts();
// Get the current Export Group
URIQueryResultList exportMasksURIs = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMasksByPortGroup(currentPortGroup.getId().toString()), exportMasksURIs);
Set<URI> exportMaskURI = new HashSet<URI>();
for (URI exportMaskURIiterator : exportMasksURIs) {
exportMaskURI.add(exportMaskURIiterator);
}
ExportGroup currentExportGroup = new ExportGroup();
URIQueryResultList exportGroupURIs = new URIQueryResultList();
for (URI exportMaskURIiterator : exportMaskURI) {
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getExportMaskExportGroupConstraint(exportMaskURIiterator), exportGroupURIs);
int flag = 0;
for (URI exportGroupURIiterator : exportGroupURIs) {
ExportGroup trialExportGroup = queryObject(ExportGroup.class, exportGroupURIiterator, true);
Set<String> hostsInExportGroup = trialExportGroup.getHosts();
Set<String> clustersInExportGroup = trialExportGroup.getClusters();
if ((hostsInExportGroup != null && hostsInExportGroup.contains(URIUtil.uri(hostOrClusterIDURI).toString())) || (clustersInExportGroup != null && clustersInExportGroup.contains(URIUtil.uri(hostOrClusterIDURI).toString()))) {
currentExportGroup = trialExportGroup;
_log.info("the ExportGroup of current port group is: {}", currentExportGroup.getId());
flag = 1;
break;
}
}
if (flag == 1) {
break;
}
}
// Get volumes currently in Export Group
List<URI> volumes = new ArrayList<URI>();
for (Map.Entry<String, String> entry : currentExportGroup.getVolumes().entrySet()) {
URI volumeToAdd = URI.create(entry.getKey().toString());
if (volumeToAdd != null) {
volumes.add(volumeToAdd);
}
}
// Get current ExportPathParams
ExportPathParams pathParams = _blockStorageScheduler.calculateExportPathParamForVolumes(volumes, currentExportGroup.getNumPaths(), currentStorageSystem.getId(), currentExportGroup.getId());
// Get initiators of Export Group
List<Initiator> currentInitiators = getInitiators(currentExportGroup);
StoragePortGroupChangeList invalidPortGroupList = new StoragePortGroupChangeList();
// Get the port groups associated with the ports in the varray and the storage system
List<StoragePortGroup> listOfPortGroups = new ArrayList<StoragePortGroup>();
Set<URI> setOfpgURIs = new HashSet<URI>();
Set<String> currentSystemPortsInVarray = ExportMaskUtils.getStoragePortUrisAssociatedWithVarrayAndStorageArray(currentPortGroup.getStorageDevice(), URIUtil.uri(varrayIDURI), _dbClient);
if (null != currentSystemPortsInVarray && !currentSystemPortsInVarray.isEmpty()) {
for (String portUriStr : currentSystemPortsInVarray) {
URIQueryResultList pgURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePortPortGroupConstraint(URIUtil.uri(portUriStr)), pgURIs);
setOfpgURIs.addAll(pgURIs);
}
Iterator<StoragePortGroup> _dbIterator = _dbClient.queryIterativeObjects(StoragePortGroup.class, setOfpgURIs);
listOfPortGroups = IteratorUtils.toList(_dbIterator);
}
// remove port groups from the list if they do not follow conditions
for (Iterator<StoragePortGroup> it = listOfPortGroups.iterator(); it.hasNext(); ) {
StoragePortGroup trialPortGroup = it.next();
StringBuffer notAllowedReasonBuff = new StringBuffer();
// Remove trialPortGroup if it is inactive or not usable
if (trialPortGroup == null || trialPortGroup.getInactive() || !trialPortGroup.isUsable()) {
it.remove();
notAllowedReasonBuff.append("Is either Inactive or not usable");
invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
continue;
}
// Remove trialPortGroup if it is the same as the currentPortGroup
if (trialPortGroup.getId().equals(currentPortGroup.getId())) {
_log.info("filtered out port group {} because it is the same as the current port group", trialPortGroup.getId());
it.remove();
notAllowedReasonBuff.append("Same as the current port group");
invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
continue;
}
// Remove trialPortGroup if it has overlapping ports with currentPortGroup
StringSet trialPortGroupPorts = trialPortGroup.getStoragePorts();
if (!Collections.disjoint(trialPortGroupPorts, currentPortGroupPorts)) {
_log.info("filtered out port group {} because it has ports overlapping the current port group", trialPortGroup.getId());
it.remove();
notAllowedReasonBuff.append("Ports overlapping with current port group");
invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
continue;
}
// Remove trialPortGroup if its ports do not fulfill ExportPathParams of the currentPortGroup
pathParams.setStoragePorts(trialPortGroup.getStoragePorts());
Map<URI, List<URI>> assignment = null;
try {
assignment = _blockStorageScheduler.verifyStoragePortGroups(currentStorageSystem, currentExportGroup.getVirtualArray(), currentInitiators, pathParams, new StringSetMap(), volumes);
if (CollectionUtils.isEmpty(assignment)) {
_log.info("filtered out port group {} because it does not fulfil ExportPathParams of existing PortGroup", trialPortGroup.getId());
it.remove();
notAllowedReasonBuff.append("Does not fulfil ExportPathParams of existing PortGroup");
invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
continue;
}
} catch (Exception e) {
_log.debug("filtered out the current port group because: {}", e.getMessage());
if (CollectionUtils.isEmpty(assignment)) {
it.remove();
notAllowedReasonBuff.append(e.getMessage());
invalidPortGroupList.getPortGroups().add(new StoragePortGroupChangeRep(trialPortGroup.getId(), trialPortGroup.getLabel(), notAllowedReasonBuff.toString(), false));
continue;
}
}
}
StoragePortGroupChangeList changePortGroupList = new StoragePortGroupChangeList();
// Sort the list based on its metrics
Collections.sort(listOfPortGroups, new StoragePortGroupComparator());
// Add the valid PGs
for (StoragePortGroup portGroup : listOfPortGroups) {
StoragePortGroupChangeRep changePG = new StoragePortGroupChangeRep(null, true);
StoragePortGroupRestRep pgRep = MapStoragePortGroup.getInstance(_dbClient).toStoragePortGroupRestRep(portGroup);
changePG.setChangePGOtherParams(pgRep);
changePortGroupList.getPortGroups().add(changePG);
}
// Add invalid PGs
for (StoragePortGroupChangeRep invalidPG : invalidPortGroupList.getPortGroups()) {
changePortGroupList.getPortGroups().add(invalidPG);
}
return changePortGroupList;
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ActionableEventExecutor method hostClusterChangeDetails.
/**
* Get details for the hostClusterChange method
* NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
*
* @param hostId the host that is moving clusters
* @param clusterId the cluster the host is moving to
* @param isVcenter if true, vcenter api operations will be executed against the host to detach/unmount and attach/mount disks and
* datastores
* @param vCenterDataCenterId the datacenter to assign the host to
* @return list of event details
*/
// Invoked using reflection for the event framework
@SuppressWarnings("unused")
public List<String> hostClusterChangeDetails(URI hostId, URI clusterId, URI vCenterDataCenterId, boolean isVcenter) {
List<String> result = Lists.newArrayList();
Host host = _dbClient.queryObject(Host.class, hostId);
if (host == null) {
return Lists.newArrayList("Host has been deleted");
}
URI oldClusterURI = host.getCluster();
Cluster oldCluster = null;
if (!NullColumnValueGetter.isNullURI(oldClusterURI)) {
oldCluster = _dbClient.queryObject(Cluster.class, oldClusterURI);
}
Cluster newCluster = null;
if (!NullColumnValueGetter.isNullURI(clusterId)) {
newCluster = _dbClient.queryObject(Cluster.class, clusterId);
}
if (newCluster != null && oldCluster != null) {
result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeDetails", host.getLabel(), oldCluster.getLabel(), newCluster.getLabel()));
} else if (newCluster == null && oldCluster != null) {
result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeDetailsRemovedFromCluster", host.getLabel(), oldCluster.getLabel()));
} else if (newCluster != null && oldCluster == null) {
result.add(ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeDetailsAddedToCluster", host.getLabel(), newCluster.getLabel()));
}
if (!NullColumnValueGetter.isNullURI(oldClusterURI) && NullColumnValueGetter.isNullURI(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI)) {
List<ExportGroup> exportGroups = ComputeSystemControllerImpl.getSharedExports(_dbClient, oldClusterURI);
for (ExportGroup export : exportGroups) {
if (export != null) {
List<BlockObjectDetails> affectedVolumes = getBlockObjectDetails(hostId, export.getVolumes());
result.addAll(getVolumeDetails(affectedVolumes, false));
}
}
} else if (NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, clusterId)) {
// Non-clustered host being added to a cluster
List<ExportGroup> exportGroups = ComputeSystemControllerImpl.getSharedExports(_dbClient, clusterId);
for (ExportGroup eg : exportGroups) {
List<BlockObjectDetails> affectedVolumes = getBlockObjectDetails(hostId, eg.getVolumes());
result.addAll(getVolumeDetails(affectedVolumes, true));
}
} else if (!NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && !oldClusterURI.equals(clusterId) && (ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI) || ComputeSystemHelper.isClusterInExport(_dbClient, clusterId))) {
// Clustered host being moved to another cluster
List<ExportGroup> exportGroups = ComputeSystemControllerImpl.getSharedExports(_dbClient, oldClusterURI);
for (ExportGroup export : exportGroups) {
if (export != null) {
List<BlockObjectDetails> affectedVolumes = getBlockObjectDetails(hostId, export.getVolumes());
result.addAll(getVolumeDetails(affectedVolumes, false));
}
}
exportGroups = ComputeSystemControllerImpl.getSharedExports(_dbClient, clusterId);
for (ExportGroup eg : exportGroups) {
List<BlockObjectDetails> affectedVolumes = getBlockObjectDetails(hostId, eg.getVolumes());
result.addAll(getVolumeDetails(affectedVolumes, true));
}
}
return result;
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExternalDeviceExportOperations method removeVolumes.
@Override
public void removeVolumes(StorageSystem storage, URI exportMaskUri, List<URI> volumeUris, List<com.emc.storageos.db.client.model.Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
log.info("{} removeVolumes START...", storage.getSerialNumber());
try {
log.info("removeVolumes: Export mask id: {}", exportMaskUri);
log.info("removeVolumes: volumes: {}", Joiner.on(',').join(volumeUris));
if (initiatorList != null) {
log.info("removeVolumes: impacted initiators: {}", Joiner.on(",").join(initiatorList));
}
BlockStorageDriver driver = externalDevice.getDriver(storage.getSystemType());
ExportMask exportMask = (ExportMask) dbClient.queryObject(exportMaskUri);
StringSet maskInitiators = exportMask.getInitiators();
List<String> maskInitiatorList = new ArrayList<>();
for (String initiatorUri : maskInitiators) {
maskInitiatorList.add(initiatorUri);
}
log.info("Export mask existing initiators: {} ", Joiner.on(",").join(maskInitiatorList));
// Prepare volumes. We send to driver only new volumes for the export mask.
List<StorageVolume> driverVolumes = new ArrayList<>();
prepareVolumes(storage, volumeUris, driverVolumes);
// Prepare initiators
Set<com.emc.storageos.db.client.model.Initiator> initiators = ExportMaskUtils.getInitiatorsForExportMask(dbClient, exportMask, null);
List<Initiator> driverInitiators = new ArrayList<>();
// Get export group uri from task completer
URI exportGroupUri = taskCompleter.getId();
ExportGroup exportGroup = (ExportGroup) dbClient.queryObject(exportGroupUri);
prepareInitiators(initiators, exportGroup.forCluster(), driverInitiators);
// Ready to call driver
DriverTask task = driver.unexportVolumesFromInitiators(driverInitiators, driverVolumes);
// todo: need to implement support for async case.
if (task.getStatus() == DriverTask.TaskStatus.READY) {
String msg = String.format("Removed volumes from export: %s.", task.getMessage());
log.info(msg);
taskCompleter.ready(dbClient);
} else {
String errorMsg = String.format("Failed to remove volumes from export mask: %s .", task.getMessage());
log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.deleteVolumesFromExportMaskFailed("removeVolumes", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
} catch (Exception ex) {
log.error("Problem in removeVolumes: ", ex);
String errorMsg = String.format("Failed to remove volumes from export mask: %s .", ex.getMessage());
log.error(errorMsg);
ServiceError serviceError = ExternalDeviceException.errors.deleteVolumesFromExportMaskFailed("removeVolumes", errorMsg);
taskCompleter.error(dbClient, serviceError);
}
log.info("{} removeVolumes END...", storage.getSerialNumber());
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportAddInitiatorCompleter method complete.
@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
try {
ExportGroup exportGroup = dbClient.queryObject(ExportGroup.class, getId());
Operation operation = new Operation();
switch(status) {
case error:
operation.error(coded);
break;
case ready:
operation.ready();
break;
case suspended_no_error:
operation.suspendedNoError();
break;
case suspended_error:
operation.suspendedError(coded);
break;
default:
break;
}
exportGroup.getOpStatus().updateTaskStatus(getOpId(), operation);
_log.info("export_initiator_add: completed");
_log.info(String.format("Done ExportMaskAddInitiator - Id: %s, OpId: %s, status: %s", getId().toString(), getOpId(), status.name()));
for (URI initiatorURI : _initiatorURIs) {
Initiator initiator = dbClient.queryObject(Initiator.class, initiatorURI);
recordBlockExportOperation(dbClient, OperationTypeEnum.ADD_EXPORT_INITIATOR, status, eventMessage(status, initiator, exportGroup), exportGroup, initiator);
if (status.name().equals(Operation.Status.error.name())) {
exportGroup.removeInitiator(initiator);
}
}
dbClient.updateObject(exportGroup);
} catch (Exception e) {
_log.error(String.format("Failed updating status for ExportMaskAddInitiator - Id: %s, OpId: %s", getId().toString(), getOpId()), e);
} finally {
super.complete(dbClient, status, coded);
}
}
Aggregations