use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportGroupService method searchForHostExport.
/**
* Performs the search query based on the host Id.
*
* @param hostId the host Id to search
* @param resRepLists search result are placed in this param
* @param selfOnly true or false
*/
private void searchForHostExport(String hostId, 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, "hosts", hostId));
} else {
List<NamedElement> initiatorElements = getModelClient().initiators().findIdsByHost(URI.create(hostId));
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.Host.name(), authorized);
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportGroupService method pathsAdjustment.
/**
* Export paths adjustment
*
* @param id The export group id
* @param param The parameters including addedPaths, removedPaths, storage system URI, exportPathParameters,
* and waitBeforeRemovePaths
* @brief Initiate port allocations for export
* @return The pending task
* @throws ControllerException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/paths-adjustment")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep pathsAdjustment(@PathParam("id") URI id, ExportPathsAdjustmentParam param) throws ControllerException {
// Basic validation of ExportGroup and the 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);
validateSuspendSetForNonDiscoverableHosts(exportGroup, param.getWaitBeforeRemovePaths(), param.getRemovedPaths().isEmpty());
ArgValidator.checkUri(param.getStorageSystem());
StorageSystem system = queryObject(StorageSystem.class, param.getStorageSystem(), true);
// Log the input parameters
param.logParameters(_log);
// 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();
}
validatePathAdjustment(exportGroup, system, param, varray);
Boolean wait = new Boolean(param.getWaitBeforeRemovePaths());
String task = UUID.randomUUID().toString();
Operation op = initTaskStatus(exportGroup, task, Operation.Status.pending, ResourceOperationTypeEnum.EXPORT_PATHS_ADJUSTMENT);
// persist the export group to the database
_dbClient.updateObject(exportGroup);
auditOp(OperationTypeEnum.EXPORT_PATH_ADJUSTMENT, true, AuditLogManager.AUDITOP_BEGIN, exportGroup.getLabel(), exportGroup.getId().toString(), exportGroup.getVirtualArray().toString(), exportGroup.getProject().toString());
TaskResourceRep taskRes = toTask(exportGroup, task, op);
BlockExportController exportController = getExportController();
_log.info("Submitting export path adjustment request.");
Map<URI, List<URI>> addedPaths = convertInitiatorPathParamToMap(param.getAdjustedPaths());
Map<URI, List<URI>> removedPaths = convertInitiatorPathParamToMap(param.getRemovedPaths());
ExportPathParams pathParam = new ExportPathParams(param.getExportPathParameters(), exportGroup);
exportController.exportGroupPortRebalance(param.getStorageSystem(), id, varray, addedPaths, removedPaths, pathParam, wait, task);
return taskRes;
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportGroupService method validateNotSameNameProjectAndVarray.
/**
* Validates that we are not creating an ExportGroup of with a duplicate name
* in the same project and varray. This is used to detect collisions where doing
* concurrent exports from the UI.
*
* @param param
*/
private void validateNotSameNameProjectAndVarray(ExportCreateParam param) {
URIQueryResultList exportGroupURIList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectExportGroupConstraint(param.getProject()), exportGroupURIList);
Iterator<URI> exportGroupURIIterator = exportGroupURIList.iterator();
while (exportGroupURIIterator.hasNext()) {
ExportGroup eg = _dbClient.queryObject(ExportGroup.class, exportGroupURIIterator.next());
if ((null != eg) && eg.getLabel().equals(param.getName()) && eg.getVirtualArray().equals(param.getVarray())) {
throw APIException.badRequests.duplicateExportGroupProjectAndVarray(param.getName());
}
}
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportGroupService method deactivateExportGroup.
/**
* Deactivate block export. It will be deleted by the garbage collector on a
* subsequent iteration
* <p>
* This removes visibility of shared storage in the block export to servers through initiators in the block export.
* <p>
* If SAN Zones were created as a result of this Export Group (see Export Group Create), they will be removed if they are not in use by
* other Export Groups.
* <p>
*
* NOTE: This is an asynchronous operation.
*
* @param groupId Block export identifier
* @brief Delete block export
* @return Task resource representation
* @throws ControllerException
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep deactivateExportGroup(@PathParam("id") URI groupId) throws ControllerException {
String task = UUID.randomUUID().toString();
Operation op = null;
ExportGroup exportGroup = lookupExportGroup(groupId);
Map<URI, Map<URI, Integer>> storageMap = ExportUtils.getStorageToVolumeMap(exportGroup, true, _dbClient);
validateExportGroupNoPendingEvents(exportGroup);
// Validate that none of the volumes are mounted (datastores, etc)
if (exportGroup.getVolumes() != null) {
validateVolumesNotMounted(exportGroup, URIUtil.toURIList(exportGroup.getVolumes().keySet()));
}
// Don't allow deactivation if there is an operation in progress.
Set<URI> tenants = new HashSet<URI>();
tenants.add(exportGroup.getTenant().getURI());
Set<ExportGroup> dataObjects = new HashSet<ExportGroup>();
dataObjects.add(exportGroup);
checkForPendingTasks(tenants, dataObjects);
// Mark deletion in progress. This will cause future updates to fail.
exportGroup.addInternalFlags(DataObject.Flag.DELETION_IN_PROGRESS);
// Remove any associated ExportPathParam
if (exportGroup.getVolumes() != null && !exportGroup.getVolumes().isEmpty() && !exportGroup.getPathParameters().isEmpty()) {
removeBlockObjectsFromPathParamMap(URIUtil.uris(exportGroup.getVolumes().keySet()), exportGroup);
}
if (storageMap.isEmpty()) {
op = initTaskStatus(exportGroup, task, Operation.Status.ready, ResourceOperationTypeEnum.DELETE_EXPORT_GROUP);
_dbClient.markForDeletion(exportGroup);
} else {
op = initTaskStatus(exportGroup, task, Operation.Status.pending, ResourceOperationTypeEnum.DELETE_EXPORT_GROUP);
_dbClient.persistObject(exportGroup);
BlockExportController exportController = getExportController();
exportController.exportGroupDelete(exportGroup.getId(), task);
}
auditOp(OperationTypeEnum.DELETE_EXPORT_GROUP, true, AuditLogManager.AUDITOP_BEGIN, exportGroup.getLabel(), exportGroup.getId().toString(), exportGroup.getVirtualArray().toString(), exportGroup.getProject().toString());
return toTask(exportGroup, task, op);
}
use of com.emc.storageos.db.client.model.ExportGroup in project coprhd-controller by CoprHD.
the class ExportGroupService method lookupExportGroup.
/**
* Given the export name and a project URI, get the applicable export object.
*
* @param groupId@return - null, if not found, otherwise the EXPORT associated
* with the project with name as 'groupName'.
*/
private ExportGroup lookupExportGroup(URI groupId) {
ArgValidator.checkUri(groupId);
ExportGroup group = _permissionsHelper.getObjectById(groupId, ExportGroup.class);
ArgValidator.checkEntityNotNull(group, groupId, isIdEmbeddedInURL(groupId));
return group;
}
Aggregations