use of com.emc.storageos.model.block.export.ExportPathParameters in project coprhd-controller by CoprHD.
the class ExportGroupService method validatePathAdjustment.
/**
* Validate the path adjustment request parameters
*
* @param exportGroup ExportGroup object
* @param system StorageSystem object
* @param param Export Path Adjustment Parameters
* @param varray URI of the virtual array, used to check any supplied ports are in correct varray
*/
private void validatePathAdjustment(ExportGroup exportGroup, StorageSystem system, ExportPathsAdjustmentParam param, URI varray) {
String systemType = system.getSystemType();
if (!Type.vmax.name().equalsIgnoreCase(systemType) && !Type.vplex.name().equalsIgnoreCase(systemType)) {
throw APIException.badRequests.exportPathAdjustmentSystemNotSupported(systemType);
}
List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup, system.getId());
if (exportMasks.isEmpty()) {
throw APIException.badRequests.exportPathAdjustmentSystemExportGroupNotMatch(exportGroup.getLabel(), system.getNativeGuid());
}
ExportPathParameters pathParam = param.getExportPathParameters();
if (pathParam == null) {
throw APIException.badRequests.exportPathAdjustementNoPathParameters();
}
URI pgURI = pathParam.getPortGroup();
// Check if exportMask has existing volumes, if it does, make sure no remove paths.
for (ExportMask exportMask : exportMasks) {
List<InitiatorPathParam> removePaths = param.getRemovedPaths();
if (removePaths.isEmpty() || !exportMask.hasAnyExistingVolumes()) {
continue;
}
Map<URI, List<URI>> removes = new HashMap<URI, List<URI>>();
for (InitiatorPathParam initPath : removePaths) {
removes.put(initPath.getInitiator(), initPath.getStoragePorts());
}
Map<URI, List<URI>> removedPathForMask = ExportMaskUtils.getRemovePathsForExportMask(exportMask, removes);
if (removedPathForMask != null && !removedPathForMask.isEmpty() && pgURI == null) {
_log.error("It has removed path for the ExportMask with existing volumes: " + exportMask.getMaskName());
throw APIException.badRequests.externallyAddedVolumes(exportMask.getMaskName(), exportMask.getExistingVolumes().toString());
}
}
// check adjusted paths are valid. initiators are in the export group, and the targets are in the storage system, and
// in valid state.
Map<URI, List<URI>> adjustedPaths = convertInitiatorPathParamToMap(param.getAdjustedPaths());
List<URI> pathInitiatorURIs = new ArrayList<URI>(adjustedPaths.keySet());
StringSet initiatorIds = exportGroup.getInitiators();
if (!initiatorIds.containsAll(StringSetUtil.uriListToStringSet(pathInitiatorURIs))) {
// Determine all the host URIs for the egInitiators
Set<URI> egHostURIs = new HashSet<URI>();
List<Initiator> egInitiators = ExportUtils.getExportGroupInitiators(exportGroup, _dbClient);
for (Initiator egInitiator : egInitiators) {
if (!NullColumnValueGetter.isNullURI(egInitiator.getHost())) {
egHostURIs.add(egInitiator.getHost());
}
}
// Now, only throw error if there are initiators that are not of any of the egHostURIs
List<Initiator> pathInitiators = _dbClient.queryObject(Initiator.class, pathInitiatorURIs);
List<String> badInitiators = new ArrayList<String>();
for (Initiator pathInitiator : pathInitiators) {
// Bad if not in the EG initiatorIds AND not from an identifiable host or not from a host in EG
if (!initiatorIds.contains(pathInitiator.getId().toString())) {
if (pathInitiator.getHost() == null || !egHostURIs.contains(pathInitiator.getHost())) {
badInitiators.add(pathInitiator.getHostName() + "-" + pathInitiator.getInitiatorPort());
}
}
}
if (!badInitiators.isEmpty()) {
throw APIException.badRequests.exportPathAdjustmentAdjustedPathNotValid(Joiner.on(", ").join(badInitiators));
}
}
Set<URI> pathTargets = new HashSet<URI>();
for (List<URI> targets : adjustedPaths.values()) {
pathTargets.addAll(targets);
}
Set<URI> systemPorts = new HashSet<URI>();
URIQueryResultList storagePortURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(system.getId()), storagePortURIs);
// Validate the targets to be provisioned have a valid state (COMPATIBLE, REGISTERED, and VISIBLE) and
// that their tagged virtual array contains our varray.
List<StoragePort> storagePorts = _dbClient.queryObject(StoragePort.class, storagePortURIs);
for (StoragePort port : storagePorts) {
if (!port.getInactive() && port.getCompatibilityStatus().equals(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name()) && port.getRegistrationStatus().equals(StoragePort.RegistrationStatus.REGISTERED.name()) && port.getDiscoveryStatus().equals(DiscoveryStatus.VISIBLE.name()) && port.getTaggedVirtualArrays() != null && port.getTaggedVirtualArrays().contains(varray.toString())) {
systemPorts.add(port.getId());
}
}
if (!systemPorts.containsAll(pathTargets)) {
// List only the invalid targets
pathTargets.removeAll(systemPorts);
throw APIException.badRequests.exportPathAdjustmentAdjustedPathNotValid(Joiner.on(",").join(pathTargets));
}
}
use of com.emc.storageos.model.block.export.ExportPathParameters in project coprhd-controller by CoprHD.
the class AddHostToExport method doExecute.
@Override
protected Task<ExportGroupRestRep> doExecute() throws Exception {
ExportUpdateParam exportUpdateParam = new ExportUpdateParam();
exportUpdateParam.setHosts(new HostsUpdateParam());
exportUpdateParam.getHosts().getAdd().add(hostId);
// Only add the export path parameters to the call if we have to
boolean addExportPathParameters = false;
ExportPathParameters exportPathParameters = new ExportPathParameters();
if (minPaths != null && maxPaths != null && pathsPerInitiator != null) {
exportPathParameters.setMinPaths(minPaths);
exportPathParameters.setMaxPaths(maxPaths);
exportPathParameters.setPathsPerInitiator(pathsPerInitiator);
addExportPathParameters = true;
}
if (portGroup != null) {
exportPathParameters.setPortGroup(portGroup);
addExportPathParameters = true;
}
if (addExportPathParameters) {
exportUpdateParam.setExportPathParameters(exportPathParameters);
}
return getClient().blockExports().update(exportId, exportUpdateParam);
}
use of com.emc.storageos.model.block.export.ExportPathParameters in project coprhd-controller by CoprHD.
the class BlockProvider method generateExportPathPreview.
private ExportPathsAdjustmentPreviewRestRep generateExportPathPreview(AssetOptionsContext ctx, URI hostOrClusterId, URI vArrayId, URI exportId, Integer minPaths, Integer maxPaths, Integer pathsPerInitiator, String useExisting, URI storageSystemId, List<URI> ports) {
ViPRCoreClient client = api(ctx);
ExportPathsAdjustmentPreviewParam param = new ExportPathsAdjustmentPreviewParam();
ExportPathParameters exportPathParameters = new ExportPathParameters();
exportPathParameters.setMinPaths(minPaths);
exportPathParameters.setMaxPaths(maxPaths);
exportPathParameters.setPathsPerInitiator(pathsPerInitiator);
exportPathParameters.setStoragePorts(ports);
param.setUseExistingPaths(useExisting.equalsIgnoreCase(YES_VALUE) ? true : false);
param.setVirtualArray(vArrayId);
param.setStorageSystem(storageSystemId);
param.setExportPathParameters(exportPathParameters);
return client.blockExports().getExportPathAdjustmentPreview(exportId, param);
}
use of com.emc.storageos.model.block.export.ExportPathParameters in project coprhd-controller by CoprHD.
the class ExportGroupService method createExportGroup.
/**
* Create block export.
* <p>
* Block export method is use to export one or more volumes to one or more hosts. This is a required step for a host to be able to
* access a block volume, although in some scenarios, additional configurations may be required. There are three main types of export
* group to meet the common use cases:
* <ol>
*
* <li>Create an initiator type export group so that a single host can see one or more volumes. An example would be an export group for
* a host boot lun or a private volume that is meant to be used by only one host. The assumption is, in this case the user wants the
* boot or private volume to be accessed via known initiators. For this type of export, the request object is expected to have only
* initiators (i.e. no hosts or clusters). Further, the initiators are expected to belong to the same host. While an initiator type
* export group can belong to only one host, this does not mean the host can only have the initiator type export group. A hosts can be
* part of many export groups of any type. The export group type {@link ExportGroupType#Initiator} should be specified in the request
* for this type of export.</li>
*
* <li>Create an export group so that one or more hosts, which are not part of a cluster, can access one or more volumes. This is the
* use case of a shared data lun. In this case, it is assumed that the user wants all the hosts initiators that are connected to the
* storage array (up to the maximum specified by the virtual pool) to be able to access the volume. The export group type
* {@link ExportGroupType#Host} should be specified in the request for this type of export.</li>
*
* <li>Create an export group so that one or more clusters of hosts can access one or more volumes. This is the same use case of shared
* data lun as the {@link ExportGroupType#Host} use case with the exception that the user is managing a cluster of hosts as opposed to
* individual hosts. In this case, the same assumption about the initiators as in the previous case is made. The export group type
* {@link ExportGroupType#Cluster} should be specified in the request for this type of export.</li>
* </ol>
*
* Note that the above discussion only mentions volumes but mirrors and snapshots can also be used in export groups.
*
* <p>
* Once a block export is created, following incremental changes can be applied to it: - add volume or volume snapshot to the shared
* storage pool - remove volume or volume snapshot from the shared storage pool - add new server to the cluster by adding initiator from
* that server to the block export - remove visibility of shared storage to a server by removing initiators from the block export
*
* <p>
* Similar to block storage provisioning, block export is also created within the scope of a varray. Hence, volumes and snapshots being
* added to a block export must belong to the same varray. Fibre Channel and iSCSI initiators must be part of SANs belonging to the same
* varray as block export.
* <p>
* For Fibre Channel initiators, SAN zones will also be created when the export group is created if the networks are discovered and:
* <ol>
* <li>at least one of the Network Systems can provision the Vsan or Fabric in which the each endpoint exists, and</li>
* <li>the VirtualArray has "auto_san_zoning" set to true.</li>
* </ol>
* The SAN zones each consists of an initiator (from the arguments) and a storage port that is selected. The number of zones created
* will be determined from the number of required initiator/storage-port communication paths.
* <p>
* NOTE: This is an asynchronous operation.
*
* @param param Export creation parameters
* @brief Create block export
* @return Block export details
* @throws ControllerException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public TaskResourceRep createExportGroup(ExportCreateParam param) throws ControllerException {
// Validate count of number of volumes to export
if (param.getVolumes() != null && param.getVolumes().size() > MAX_VOLUME_COUNT) {
throw APIException.badRequests.exceedingLimit("count", MAX_VOLUME_COUNT);
}
// validate input for the type of export
validateCreateInputForExportType(param);
// backend volumes to a group.
if (param.getVolumes() != null && !param.getVolumes().isEmpty()) {
List<URI> addVolumeURIs = new ArrayList<URI>();
for (VolumeParam volParam : param.getVolumes()) {
addVolumeURIs.add(volParam.getId());
}
BlockService.validateNoInternalBlockObjects(_dbClient, addVolumeURIs, false);
/**
* Validate ExportGroup add volume's nativeId/nativeGuid
*/
validateBlockObjectNativeId(addVolumeURIs);
}
// Validate the project and check its permissions
Project project = queryObject(Project.class, param.getProject(), true);
StorageOSUser user = getUserFromContext();
if (!(_permissionsHelper.userHasGivenRole(user, project.getTenantOrg().getURI(), Role.TENANT_ADMIN) || _permissionsHelper.userHasGivenACL(user, project.getId(), ACL.OWN, ACL.ALL))) {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
// Validate the varray and check its permissions
VirtualArray neighborhood = _dbClient.queryObject(VirtualArray.class, param.getVarray());
_permissionsHelper.checkTenantHasAccessToVirtualArray(project.getTenantOrg().getURI(), neighborhood);
validateBlockSnapshotsForExportGroupCreate(param);
// prepare the export group object
ExportGroup exportGroup = prepareExportGroup(project, param);
// validate block objects input and package them
Map<URI, Map<URI, Integer>> storageMap = new HashMap<URI, Map<URI, Integer>>();
Map<URI, Integer> volumeMap = validateBlockObjectsAndGetMap(param.getVolumes(), exportGroup, storageMap);
_log.info("Computed storage map: {} volumes in {} storage systems: {}", new Object[] { volumeMap.size(), storageMap.size(), storageMap.keySet().toArray() });
// Validate that there is not already an ExportGroup of the same name, project, and varray.
// If so, this is like because concurrent operations were in the API at the same time and another created
// the ExportGroup.
validateNotSameNameProjectAndVarray(param);
// If ExportPathParameter block is present, and volumes are present, validate have permissions.
// Processing will be in the aysnc. task.
ExportPathParameters pathParam = param.getExportPathParameters();
if (pathParam != null && !volumeMap.keySet().isEmpty()) {
// Only [RESTRICTED_]SYSTEM_ADMIN may override the Vpool export parameters
if ((pathParam.getMaxPaths() != null || pathParam.getMinPaths() != null || pathParam.getPathsPerInitiator() != null) && !_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN)) {
throw APIException.forbidden.onlySystemAdminsCanOverrideVpoolPathParameters(exportGroup.getLabel());
}
}
validatePortGroupWhenAddVolumesForExportGroup(volumeMap.keySet(), (pathParam != null ? pathParam.getPortGroup() : null), null);
// COP-14028
// Changing the return of a TaskList to return immediately while the underlying tasks are
// being built up. Steps:
// 1. Create a task object ahead of time and persist it for the export group
// 2. Fire off a thread that does the scheduling (planning) of the export operation
// 3. Return to the caller the new Task objects that is in the pending state.
// create export groups in the array but only when the export
// group has both block objects and initiators.
String task = UUID.randomUUID().toString();
Operation.Status status = storageMap.isEmpty() ? Operation.Status.ready : Operation.Status.pending;
_dbClient.createObject(exportGroup);
Operation op = initTaskStatus(exportGroup, task, status, ResourceOperationTypeEnum.CREATE_EXPORT_GROUP);
// persist the export group to the database
auditOp(OperationTypeEnum.CREATE_EXPORT_GROUP, true, AuditLogManager.AUDITOP_BEGIN, param.getName(), neighborhood.getId().toString(), project.getId().toString());
TaskResourceRep taskRes = toTask(exportGroup, task, op);
// call thread that does the work.
CreateExportGroupSchedulingThread.executeApiTask(this, _asyncTaskService.getExecutorService(), _dbClient, neighborhood, project, exportGroup, storageMap, param.getClusters(), param.getHosts(), param.getInitiators(), volumeMap, param.getExportPathParameters(), task, taskRes);
_log.info("Kicked off thread to perform export create scheduling. Returning task: " + taskRes.getId());
return taskRes;
}
use of com.emc.storageos.model.block.export.ExportPathParameters in project coprhd-controller by CoprHD.
the class ExportGroupService method updateExportGroup.
/**
* Update an export group which includes:
* <ol>
* <li>Add/Remove block objects (volumes, mirrors and snapshots)</li>
* <li>Add/remove clusters</li>
* <li>Add/remove hosts</li>
* <li>Add/remove initiators</li>
* </ol>
* Depending on the export group type (Initiator, Host or Cluster), the
* request is restricted to enforce the same rules as {@link #createExportGroup(ExportCreateParam)}:
* <ol>
* <li>For initiator type groups, only initiators are accepted in the request. Further the initiators must be in the same host as the
* existing initiators.</li>
* <li>For host type groups, only hosts and initiators that belong to existing hosts will be accepted.</li>
* <li>For cluster type groups, only clusters, hosts and initiators will be accepted. Hosts and initiators must belong to existing
* clusters and hosts.</li>
* </ol>
* <b>Note:</b> The export group name, project and varray can not be modified.
*
* @param id the URN of a ViPR export group to be updated
* @param param the request parameter
* @brief Update block export
* @return the update job tracking task id
* @throws ControllerException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateExportGroup(@PathParam("id") URI id, ExportUpdateParam 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());
}
Project project = queryObject(Project.class, exportGroup.getProject().getURI(), true);
validateUpdateInputForExportType(param, exportGroup);
validateUpdateRemoveInitiators(param, exportGroup);
validateUpdateIsNotForVPlexBackendVolumes(param, exportGroup);
validateBlockSnapshotsForExportGroupUpdate(param, exportGroup);
validateExportGroupNoPendingEvents(exportGroup);
/**
* ExportGroup Add/Remove volume should have valid nativeId
*/
List<URI> boURIList = new ArrayList<>();
if (param.getVolumes() != null) {
if (param.getVolumes().getAdd() != null) {
for (VolumeParam volParam : param.getVolumes().getAdd()) {
boURIList.add(volParam.getId());
}
}
if (param.getVolumes().getRemove() != null) {
for (URI volURI : param.getVolumes().getRemove()) {
boURIList.add(volURI);
}
validateVolumesNotMounted(exportGroup, param.getVolumes().getRemove());
}
}
validateBlockObjectNativeId(boURIList);
if (param.getExportPathParameters() != null) {
// Only [RESTRICTED_]SYSTEM_ADMIN may override the Vpool export parameters
ExportPathParameters pathParam = param.getExportPathParameters();
if ((pathParam.getMaxPaths() != null || pathParam.getMinPaths() != null || pathParam.getPathsPerInitiator() != null) && !_permissionsHelper.userHasGivenRole(getUserFromContext(), null, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN)) {
throw APIException.forbidden.onlySystemAdminsCanOverrideVpoolPathParameters(exportGroup.getLabel());
}
}
// call the controller to handle all updated
String task = UUID.randomUUID().toString();
Operation op = initTaskStatus(exportGroup, task, Operation.Status.pending, ResourceOperationTypeEnum.UPDATE_EXPORT_GROUP);
// persist the export group to the database
_dbClient.persistObject(exportGroup);
auditOp(OperationTypeEnum.UPDATE_EXPORT_GROUP, true, AuditLogManager.AUDITOP_BEGIN, exportGroup.getLabel(), exportGroup.getId().toString(), exportGroup.getVirtualArray().toString(), exportGroup.getProject().toString());
TaskResourceRep taskRes = toTask(exportGroup, task, op);
CreateExportGroupUpdateSchedulingThread.executeApiTask(this, _asyncTaskService.getExecutorService(), _dbClient, project, exportGroup, param, task, taskRes);
_log.info("Kicked off thread to perform export update scheduling. Returning task: " + taskRes.getId());
return taskRes;
}
Aggregations