Search in sources :

Example 56 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileService method getOtherSearchResults.

/**
 * 'mountPath' is not case sensitive. The complete mountPath should be specified.
 *
 * If a matching filesystem is not found, an empty list is returned.
 *
 * Parameters - mountPath String - mountPath of the filesystem
 */
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    SearchResults result = new SearchResults();
    // Here we search by mountPath
    if (!parameters.containsKey("mountPath")) {
        throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), "mountPath");
    }
    String mountPath = parameters.get("mountPath").get(0);
    List<SearchResultResourceRep> resRepList = new ArrayList<SearchResultResourceRep>();
    URIQueryResultList fsUriList = new URIQueryResultList();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileSystemMountPathConstraint(mountPath), fsUriList);
    _log.info("After query of the database for {} and result {}", mountPath, fsUriList);
    Iterator<URI> fsListIterator = fsUriList.iterator();
    while (fsListIterator.hasNext()) {
        URI uri = fsListIterator.next();
        FileShare fs = _dbClient.queryObject(FileShare.class, uri);
        if (!fs.getInactive()) {
            if (authorized || isAuthorized(fs.getProject().getURI())) {
                RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), uri));
                SearchResultResourceRep r = new SearchResultResourceRep(uri, selfLink, fs.getMountPath());
                resRepList.add(r);
                _log.info("Mount path match " + fs.getMountPath());
            } else {
                _log.info("Mount path match but not authorized " + fs.getMountPath());
            }
        }
    }
    result.setResource(resRepList);
    return result;
}
Also used : SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) SearchResults(com.emc.storageos.model.search.SearchResults) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 57 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileService method assignFilePolicy.

/**
 * Assign existing file system to file policy.
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param filePolicyUri
 *            the URN of a Policy
 * @brief Update file system with Policy detail
 * @return Task resource representation
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/assign-file-policy/{filePolicyUri}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep assignFilePolicy(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri, FilePolicyFileSystemAssignParam param) throws InternalException {
    TaskResourceRep resp = new TaskResourceRep();
    StringBuilder errorMsg = new StringBuilder();
    _log.info("Assigning file policy {} to file system {}", filePolicyUri, id);
    String task = UUID.randomUUID().toString();
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldUriType(filePolicyUri, FilePolicy.class, "filePolicyUri");
    ArgValidator.checkUri(filePolicyUri);
    FilePolicy filePolicy = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
    ArgValidator.checkEntityNotNull(filePolicy, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
    StringSet existingFSPolicies = fs.getFilePolicies();
    if (existingFSPolicies != null && existingFSPolicies.contains(filePolicyUri.toString())) {
        _log.info("Provided file policy {} is already is applied to the file sytem {}", filePolicy.getId(), fs.getId());
        Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.ASSIGN_FILE_POLICY_TO_FILE_SYSTEM);
        op.setDescription("assign file policy to file system");
        _dbClient.ready(FileShare.class, fs.getId(), task);
        return toTask(fs, task, op);
    }
    // check if same TYPE of policy already applied to file system
    if (filePolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name()) && existingFSPolicies != null && !existingFSPolicies.isEmpty()) {
        checkForDuplicatePolicyApplied(filePolicy, existingFSPolicies);
    }
    // Check if the vpool supports provided policy type..
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    FilePolicyServiceUtils.validateVpoolSupportPolicyType(filePolicy, vpool);
    // Check if the vpool supports policy at file system level..
    if (!vpool.getAllowFilePolicyAtFSLevel()) {
        errorMsg.append("Provided vpool :" + vpool.getLabel() + " doesn't support policy at file system level");
        _log.error(errorMsg.toString());
        throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
    }
    // only single replication policy per vpool/project/fs.
    if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && FilePolicyServiceUtils.fsHasReplicationPolicy(_dbClient, vpool.getId(), fs.getProject().getURI(), fs.getId())) {
        errorMsg.append("Provided vpool/project/fs has already assigned with replication policy.");
        _log.error(errorMsg.toString());
        throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
    }
    if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_snapshot.name()) && FilePolicyServiceUtils.fsHasSnapshotPolicyWithSameSchedule(_dbClient, fs.getId(), filePolicy)) {
        errorMsg.append("Snapshot policy with similar schedule is already present on fs " + fs.getLabel());
        _log.error(errorMsg.toString());
        throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
    }
    if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
        return assignFileReplicationPolicyToFS(fs, filePolicy, param, task);
    } else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
        return assignFilePolicyToFS(fs, filePolicy, task);
    }
    return resp;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) 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 58 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileService method getFileSystemShareList.

/**
 * Get list of SMB shares for the specified file system.
 *
 * @param id
 *            the URN of a ViPR File system
 * @brief List file system SMB shares
 * @return List of file system shares.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public FileSystemShareList getFileSystemShareList(@PathParam("id") URI id) {
    _log.info(String.format("Get list of SMB file shares for file system: %1$s", id));
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fileShare = queryResource(id);
    FileSystemShareList fileShareListResponse = new FileSystemShareList();
    if (fileShare.getInactive()) {
        return fileShareListResponse;
    }
    SMBShareMap smbShareMap = fileShare.getSMBFileShares();
    Collection<SMBFileShare> smbShares = new ArrayList<SMBFileShare>();
    if (smbShareMap != null) {
        smbShares = smbShareMap.values();
    }
    // Process each share from the map and add its data to shares in response list.
    for (SMBFileShare smbShare : smbShares) {
        SmbShareResponse shareParam = new SmbShareResponse();
        shareParam.setShareName(smbShare.getName());
        shareParam.setDescription(smbShare.getDescription());
        shareParam.setMaxUsers(Integer.toString(smbShare.getMaxUsers()));
        // Check for "unlimited"
        if (shareParam.getMaxUsers().equals("-1")) {
            shareParam.setMaxUsers(UNLIMITED_USERS);
        }
        shareParam.setPermissionType(smbShare.getPermissionType());
        shareParam.setPermission(smbShare.getPermission());
        shareParam.setMountPoint(smbShare.getMountPoint());
        shareParam.setPath(smbShare.getPath());
        fileShareListResponse.getShareList().add(shareParam);
    }
    return fileShareListResponse;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileSystemShareList(com.emc.storageos.model.file.FileSystemShareList) ArrayList(java.util.ArrayList) SmbShareResponse(com.emc.storageos.model.file.SmbShareResponse) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 59 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileService method failoverProtection.

/**
 * Request to failover the protection link associated with the param.copyID.
 *
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source fileshare
 * @param param
 *            FileReplicationParam to failover to
 *
 * @brief Failover the fileShare protection link
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/failover")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failoverProtection(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
    doMirrorOperationValidation(id, ProtectionOp.FAILOVER.toString());
    TaskResourceRep taskResp = null;
    StoragePort storageportNFS = null;
    StoragePort storageportCIFS = null;
    TaskList taskList = new TaskList();
    String task = UUID.randomUUID().toString();
    FileShare fs = queryResource(id);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER);
    op.setDescription("failover source file system to target system");
    boolean replicateConfiguration = param.isReplicateConfiguration();
    if (replicateConfiguration) {
        List<String> targetfileUris = new ArrayList<String>();
        targetfileUris.addAll(fs.getMirrorfsTargets());
        FileShare targetFileShare = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        SMBShareMap smbShareMap = fs.getSMBFileShares();
        if (smbShareMap != null) {
            storageportCIFS = _fileScheduler.placeFileShareExport(targetFileShare, StorageProtocol.File.CIFS.name(), null);
        }
        FSExportMap nfsExportMap = fs.getFsExports();
        if (nfsExportMap != null) {
            storageportNFS = _fileScheduler.placeFileShareExport(targetFileShare, StorageProtocol.File.NFS.name(), null);
        }
    }
    FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
    try {
        fileServiceApi.failoverFileShare(id, storageportNFS, storageportCIFS, replicateConfiguration, task);
    } catch (InternalException e) {
        if (_log.isErrorEnabled()) {
            _log.error("", e);
        }
        FileShare fileShare = _dbClient.queryObject(FileShare.class, fs.getId());
        op = fs.getOpStatus().get(task);
        op.error(e);
        fileShare.getOpStatus().updateTaskStatus(task, op);
        _dbClient.updateObject(fs);
        throw e;
    }
    taskResp = toTask(fs, task, op);
    taskList.getTaskList().add(taskResp);
    return taskList;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) TaskList(com.emc.storageos.model.TaskList) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 60 with FileShare

use of com.emc.storageos.db.client.model.FileShare in project coprhd-controller by CoprHD.

the class FileService method getFileSystemSchedulePolicySnapshots.

/**
 * Get file system Snapshot created by policy
 *
 * @param id
 *            The URN of a ViPR file system
 * @param filePolicyUri
 *            The URN of a file policy schedule
 * @param timeout
 *            Time limit in seconds to get the output .Default is 30 seconds
 * @brief Get snapshots related to the specified policy
 * @return List of snapshots created by a file policy
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/file-policies/{filePolicyUri}/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ScheduleSnapshotList getFileSystemSchedulePolicySnapshots(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri, @QueryParam("timeout") int timeout) {
    // valid value of timeout is 10 sec to 10 min
    if (timeout < 10 || timeout > 600) {
        // default timeout value.
        timeout = 30;
    }
    ScheduleSnapshotList list = new ScheduleSnapshotList();
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldUriType(filePolicyUri, FilePolicy.class, "filePolicyUri");
    ArgValidator.checkUri(filePolicyUri);
    FilePolicy sp = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
    ArgValidator.checkEntityNotNull(sp, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
    // verify the schedule policy is associated with file system or not.
    if (!fs.getFilePolicies().contains(filePolicyUri.toString())) {
        throw APIException.badRequests.cannotFindAssociatedPolicy(filePolicyUri);
    }
    String task = UUID.randomUUID().toString();
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE);
    op.setDescription("list snapshots created by a policy");
    try {
        _log.info("No Errors found. Proceeding further {}, {}, {}", new Object[] { _dbClient, fs, sp });
        controller.listSanpshotByPolicy(device.getId(), fs.getId(), sp.getId(), task);
        Task taskObject = null;
        auditOp(OperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), sp.getId());
        int timeoutCounter = 0;
        // wait till timeout or result from controller service ,whichever is earlier
        do {
            TimeUnit.SECONDS.sleep(1);
            taskObject = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), task);
            timeoutCounter++;
        // exit the loop if task is completed with error/success or timeout
        } while ((taskObject != null && !(taskObject.isReady() || taskObject.isError())) && timeoutCounter < timeout);
        if (taskObject == null) {
            throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots task information");
        } else if (taskObject.isReady()) {
            URIQueryResultList snapshotsURIs = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(id), snapshotsURIs);
            List<Snapshot> snapList = _dbClient.queryObject(Snapshot.class, snapshotsURIs);
            for (Snapshot snap : snapList) {
                if (!snap.getInactive() && snap.getExtensions().containsKey("schedule")) {
                    ScheduleSnapshotRestRep snapRest = new ScheduleSnapshotRestRep();
                    getScheduleSnapshotRestRep(snapRest, snap);
                    list.getScheduleSnapList().add(snapRest);
                    snap.setInactive(true);
                    _dbClient.updateObject(snap);
                }
            }
        } else if (taskObject.isError()) {
            throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to" + taskObject.getMessage());
        } else {
            throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to timeout");
        }
    } catch (BadRequestException e) {
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Error while getting  Filesystem policy  Snapshots {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    } catch (Exception e) {
        _log.error("Error while getting  Filesystem policy  Snapshots {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return list;
}
Also used : TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileController(com.emc.storageos.volumecontroller.FileController) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Snapshot(com.emc.storageos.db.client.model.Snapshot) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) FilePolicyList(com.emc.storageos.model.file.FilePolicyList) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) QuotaDirectoryList(com.emc.storageos.model.file.QuotaDirectoryList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) FileSystemShareList(com.emc.storageos.model.file.FileSystemShareList) List(java.util.List) FileSystemExportList(com.emc.storageos.model.file.FileSystemExportList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) MirrorList(com.emc.storageos.model.block.MirrorList) SnapshotList(com.emc.storageos.model.SnapshotList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) ScheduleSnapshotRestRep(com.emc.storageos.model.file.ScheduleSnapshotRestRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

FileShare (com.emc.storageos.db.client.model.FileShare)289 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)155 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)107 URI (java.net.URI)93 ArrayList (java.util.ArrayList)79 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)73 ControllerException (com.emc.storageos.volumecontroller.ControllerException)65 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)61 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)57 Operation (com.emc.storageos.db.client.model.Operation)56 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)56 URISyntaxException (java.net.URISyntaxException)56 Path (javax.ws.rs.Path)56 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)52 Produces (javax.ws.rs.Produces)51 Snapshot (com.emc.storageos.db.client.model.Snapshot)50 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)49 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)45 WorkflowException (com.emc.storageos.workflow.WorkflowException)42 NamedURI (com.emc.storageos.db.client.model.NamedURI)36