Search in sources :

Example 81 with ExportGroup

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);
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet)

Example 82 with ExportGroup

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;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) BlockExportController(com.emc.storageos.volumecontroller.BlockExportController) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) StoragePortGroupChangeList(com.emc.storageos.model.portgroup.StoragePortGroupChangeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ExportPathParams(com.emc.storageos.db.client.model.ExportPathParams) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 83 with ExportGroup

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());
        }
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 84 with ExportGroup

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);
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) BlockExportController(com.emc.storageos.volumecontroller.BlockExportController) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 85 with ExportGroup

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;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup)

Aggregations

ExportGroup (com.emc.storageos.db.client.model.ExportGroup)278 URI (java.net.URI)206 ArrayList (java.util.ArrayList)139 ExportMask (com.emc.storageos.db.client.model.ExportMask)138 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)111 HashMap (java.util.HashMap)94 Initiator (com.emc.storageos.db.client.model.Initiator)86 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)84 NamedURI (com.emc.storageos.db.client.model.NamedURI)80 HashSet (java.util.HashSet)70 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)63 Workflow (com.emc.storageos.workflow.Workflow)61 List (java.util.List)59 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)55 BlockObject (com.emc.storageos.db.client.model.BlockObject)49 Map (java.util.Map)47 ExportOrchestrationTask (com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportOrchestrationTask)44 ControllerException (com.emc.storageos.volumecontroller.ControllerException)41 StringSet (com.emc.storageos.db.client.model.StringSet)38 StringMap (com.emc.storageos.db.client.model.StringMap)33