use of com.emc.storageos.model.block.export.InitiatorPortMapRestRep in project coprhd-controller by CoprHD.
the class ExportGroupService method calculateRemovedPaths.
/**
* Traverse the list of ExportMasks looking for StorageSystem matches and calculate the removed paths.
* This is done by comparing the zoningMap containing the new paths with each ExportMasks's zoningMap,
* and reporting eny paths in the EM's zoningMap that are not in the new zoningMap.
* @param response -- OUT REST response where we are filling in removed paths
* @param calculatedZoningMap -- new proposed zoningMap (overall for all ExportMasks)
* @param exportGroup -- Export Group on which provisioning was initiated
* @param system -- StorageSystem
* @param varray -- Virtual Array URI
* @param hosts -- For cluster export group, the hosts that are being processed. Assumes all if emptySet.
*/
private void calculateRemovedPaths(ExportPathsAdjustmentPreviewRestRep response, Map<URI, List<URI>> calculatedZoningMap, ExportGroup exportGroup, StorageSystem system, URI varray, Set<URI> hosts) {
// Find the Export Masks for this Storage System
List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup, system.getId());
for (ExportMask exportMask : exportMasks) {
// For VPLEX, must verify the Export Mask is in the appropriate Varray
if (!ExportMaskUtils.exportMaskInVarray(_dbClient, exportMask, varray)) {
continue;
}
// Get the zoning map from the exportMask, and compare it with the zoningMap newly allocated.
// Remove all entries that are in the new zoningMap (and thus will be kept and not deleted)
StringSetMap existingZoningMap = exportMask.getZoningMap();
if (existingZoningMap == null || existingZoningMap.isEmpty()) {
continue;
}
for (String maskInitiator : existingZoningMap.keySet()) {
for (URI zoningInitiator : calculatedZoningMap.keySet()) {
if (maskInitiator.equalsIgnoreCase(zoningInitiator.toString())) {
// same initiator, remove ports from mask set that are in zoning map
StringSet maskPorts = existingZoningMap.get(maskInitiator);
for (URI zoningPort : calculatedZoningMap.get(zoningInitiator)) {
maskPorts.remove(zoningPort.toString());
}
existingZoningMap.put(maskInitiator, maskPorts);
}
}
}
// Now output the response information for this Export Mask to the removedPaths section.
for (String maskInitiator : existingZoningMap.keySet()) {
StringSet maskPorts = existingZoningMap.get(maskInitiator);
if (maskPorts == null || maskPorts.isEmpty()) {
continue;
}
InitiatorPortMapRestRep zone = new InitiatorPortMapRestRep();
Initiator initiator = queryObject(Initiator.class, URI.create(maskInitiator), false);
if (exportGroup.getType().equals(ExportGroupType.Cluster.name()) && !hosts.isEmpty() && !hosts.contains(initiator.getHost())) {
// If a Cluster export and not in the hosts list, don't process any removes for the initiator
continue;
}
zone.setInitiator(HostMapper.map(initiator));
for (String maskPort : maskPorts) {
StoragePort port = queryObject(StoragePort.class, URI.create(maskPort), false);
zone.getStoragePorts().add(toNamedRelatedResource(port, port.getPortName()));
}
response.getRemovedPaths().add(zone);
}
Collections.sort(response.getRemovedPaths(), response.new InitiatorPortMapRestRepComparator());
}
}
use of com.emc.storageos.model.block.export.InitiatorPortMapRestRep in project coprhd-controller by CoprHD.
the class ExportGroupService method pathsAdjustmentPreview.
/**
* Paths Adjustment Preview
*
* This call does a PORT Allocation which is used for a path adjustment preview operation.
* If the user is satisfied with the ports that are selected, they will invoke the provisioning through a
* separate API.
*
* Inputs are the the Export Group URI, Storage System URI, an optional Varray URI, and the ExportPath parameters.
* There is also a boolean that specifies the allocation should start assuming the existing paths are used (or not).
*
* @param id the URN of a ViPR export group to be updated; ports will be allocated in this context
* @param param -- ExportPortAllocateParam block containing Storage System URI, Varray URI, ExportPathParameters
*
* @brief Preview port allocation paths for export
* @return a PortAllocatePreviewRestRep rest response which contains the new or existing paths that will be provisioned
* or kept; the removed paths; and any other Export Groups that will be affected.
* @throws ControllerException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/paths-adjustment-preview")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public ExportPathsAdjustmentPreviewRestRep pathsAdjustmentPreview(@PathParam("id") URI id, ExportPathsAdjustmentPreviewParam param) throws ControllerException {
// Basic validation of ExportGroup and update request
ExportGroup exportGroup = queryObject(ExportGroup.class, id, true);
if (exportGroup.checkInternalFlags(DataObject.Flag.DELETION_IN_PROGRESS)) {
throw BadRequestException.badRequests.deletionInProgress(exportGroup.getClass().getSimpleName(), exportGroup.getLabel());
}
validateExportGroupNoPendingEvents(exportGroup);
validateHostsInExportGroup(exportGroup, param.getHosts());
// Validate storage system
ArgValidator.checkUri(param.getStorageSystem());
StorageSystem system = queryObject(StorageSystem.class, param.getStorageSystem(), true);
// Get the virtual array, default to Export Group varray. Validate it matches.
URI varray = param.getVirtualArray();
if (varray != null) {
boolean validVarray = varray.equals(exportGroup.getVirtualArray());
if (exportGroup.getAltVirtualArrays() != null && varray.toString().equals(exportGroup.getAltVirtualArrays().get(system.getId().toString()))) {
validVarray = true;
}
if (!validVarray) {
throw APIException.badRequests.varrayNotInExportGroup(varray.toString());
}
} else {
varray = exportGroup.getVirtualArray();
}
// Validate the hosts, if supplied.
for (URI hostId : param.getHosts()) {
// Throw exception of thoe hostId is invalid
queryObject(Host.class, hostId, true);
}
// Get the initiators and validate the ExportMasks are usable.
ExportPathsAdjustmentPreviewRestRep response = new ExportPathsAdjustmentPreviewRestRep();
String storageSystem = system.getNativeGuid();
if (Type.vplex.equals(Type.valueOf(system.getSystemType()))) {
String vplexCluster = ConnectivityUtil.getVplexClusterForVarray(varray, system.getId(), _dbClient);
storageSystem = storageSystem + STORAGE_SYSTEM_CLUSTER + vplexCluster;
}
response.setStorageSystem(storageSystem);
List<Initiator> initiators = getInitiators(exportGroup);
StringSetMap existingPathMap = new StringSetMap();
StringSet storagePorts = new StringSet();
validatePathAdjustment(exportGroup, initiators, system, varray, param.getHosts(), response, existingPathMap, param.getUseExistingPaths(), storagePorts);
try {
// Manufacture an ExportPathParams structure from the REST ExportPathParameters structure
ExportPathParams pathParam = new ExportPathParams(param.getExportPathParameters(), exportGroup);
if (!storagePorts.isEmpty()) {
// check if storage ports are specified
StringSet paramPorts = pathParam.getStoragePorts();
if (paramPorts != null && !paramPorts.isEmpty()) {
if (!storagePorts.containsAll(paramPorts)) {
_log.error("Selected ports are not in the port group");
throw APIException.badRequests.pathAdjustmentSelectedPortsNotInPortGroup(Joiner.on(',').join(paramPorts), Joiner.on(',').join(storagePorts));
}
} else {
pathParam.setStoragePorts(storagePorts);
}
}
// Call the storage port allocator/assigner for all initiators (host or cluster) in
// the Export Group. Pass in the existing paths if requested in the parameters.
List<URI> volumes = StringSetUtil.stringSetToUriList(exportGroup.getVolumes().keySet());
Map<URI, List<URI>> zoningMap = _blockStorageScheduler.assignStoragePorts(system, varray, initiators, pathParam, (param.getUseExistingPaths() ? existingPathMap : new StringSetMap()), volumes);
for (Entry<URI, List<URI>> entry : zoningMap.entrySet()) {
InitiatorPortMapRestRep zone = new InitiatorPortMapRestRep();
Initiator initiator = queryObject(Initiator.class, entry.getKey(), false);
zone.setInitiator(HostMapper.map(initiator));
for (URI portURI : entry.getValue()) {
StoragePort port = queryObject(StoragePort.class, portURI, false);
zone.getStoragePorts().add(toNamedRelatedResource(port, port.getPortName()));
}
response.getAdjustedPaths().add(zone);
}
addRetainedPathsFromHosts(response, existingPathMap, param.getHosts());
Collections.sort(response.getAdjustedPaths(), response.new InitiatorPortMapRestRepComparator());
calculateRemovedPaths(response, zoningMap, exportGroup, system, varray, param.getHosts());
response.logResponse(_log);
return response;
} catch (ControllerException ex) {
_log.error(ex.getLocalizedMessage());
throw (ex);
}
}
Aggregations