use of com.emc.storageos.model.portgroup.StoragePortGroupChangeRep 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.model.portgroup.StoragePortGroupChangeRep in project coprhd-controller by CoprHD.
the class BlockProvider method getExportPortGroups.
@Asset("exportChangePortGroup")
@AssetDependencies({ "host", "exportPathVirtualArray", "exportCurrentPortGroup" })
public List<AssetOption> getExportPortGroups(AssetOptionsContext ctx, URI hostOrClusterId, URI varrayId, URI exportCurrentPortGroupId) {
final ViPRCoreClient client = api(ctx);
List<StoragePortGroupChangeRep> portGroupsRestRep = client.blockExports().getPortGroupsForPortGroupChange(exportCurrentPortGroupId, hostOrClusterId, varrayId);
return createPortGroupChangeOptions(portGroupsRestRep);
}
use of com.emc.storageos.model.portgroup.StoragePortGroupChangeRep in project coprhd-controller by CoprHD.
the class BlockProvider method createPortGroupChangeOptions.
private List<AssetOption> createPortGroupChangeOptions(List<StoragePortGroupChangeRep> portGroups) {
List<AssetOption> options = Lists.newArrayList();
List<AssetOption> valid = Lists.newArrayList();
List<AssetOption> invalid = Lists.newArrayList();
for (StoragePortGroupChangeRep group : portGroups) {
String label;
if (group.getAllowed()) {
String portMetric = (group.getPortMetric() != null) ? String.valueOf(Math.round(group.getPortMetric() * 100 / 100)) + "%" : "N/A";
String volumeCount = (group.getVolumeCount() != null) ? String.valueOf(group.getVolumeCount()) : "N/A";
String nGuid = group.getNativeGuid();
String nativeGuid = EMPTY_STRING;
try {
// Remove the PG name from the native GUID.
// Ex:
// From -> SYMMETRIX+000196801518+PORTGROUP+lglw7136_pg
// To -> SYMMETRIX+000196801518
nativeGuid = nGuid.replaceAll("\\+PORTGROUP.*$", "");
} catch (Exception e) {
nativeGuid = nGuid;
warn("Issue encountered parsing native guid %s, exception: %s", nativeGuid, e.getMessage());
}
label = getMessage("exportPortGroup.portGroups", group.getName(), nativeGuid, portMetric, volumeCount);
valid.add(new AssetOption(group.getId(), label));
} else {
label = getMessage("exportPortGroup.portGroups.portGroupChangeReason", group.getName(), group.getNotAllowedReason());
invalid.add(new AssetOption(EMPTY_STRING, label));
}
}
options.addAll(valid);
options.addAll(invalid);
return options;
}
Aggregations