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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations