use of com.emc.storageos.svcs.errorhandling.resources.InternalException 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.svcs.errorhandling.resources.InternalException in project coprhd-controller by CoprHD.
the class FileService method reduce.
/**
* Reduce file system quota -- supported only on Isilon
*
* @param id - the URN of a ViPR File system
* @param param - File system reduction parameters
* @return Task resource representation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/reduce")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep reduce(@PathParam("id") URI id, FileSystemReduceParam param) throws InternalException {
_log.info(String.format("FileShareReduce --- FileShare id: %1$s, New Quota: %2$s", id, param.getNewSize()));
// check file system
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
if (!device.deviceIsType(DiscoveredDataObject.Type.isilon)) {
String msg = String.format("reducing filesystem is not supported for storage system %s", device.getSystemType());
throw APIException.badRequests.reduceFileSystemNotSupported(msg);
}
Long newFSsize = SizeUtil.translateSize(param.getNewSize());
long quotaFsSize = newFSsize - fs.getCapacity();
final long MIN_EXPAND_SIZE = SizeUtil.translateSize("1MB") + 1;
if (newFSsize <= 0) {
throw APIException.badRequests.parameterMustBeGreaterThan("new_size", 0);
} else {
if (quotaFsSize < MIN_EXPAND_SIZE) {
List<QuotaDirectory> quotaDirs = queryDBQuotaDirectories(fs);
if (null != quotaDirs && !quotaDirs.isEmpty()) {
long qdsize = 0;
// that new size should not be less than any of the sub quota.
for (QuotaDirectory quotaDir : quotaDirs) {
qdsize = newFSsize - quotaDir.getSize();
Double quotasize = SizeUtil.translateSize(quotaDir.getSize(), SizeUtil.SIZE_GB);
Double newFScapacity = SizeUtil.translateSize(newFSsize, SizeUtil.SIZE_GB);
if (qdsize < MIN_EXPAND_SIZE) {
String msg = String.format("as requested reduced size [%.1fGB] is smaller than its quota size [%.1fGB] for filesystem %s", newFScapacity, quotasize, fs.getName());
throw APIException.badRequests.reduceFileSystemNotSupported(msg);
}
}
}
} else {
throw APIException.badRequests.parameterMustBeLessThan("new_size", fs.getCapacity());
}
}
String task = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.REDUCE_FILE_SYSTEM);
op.setDescription("Filesystem reduce quota");
FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
try {
fileServiceApi.reduceFileShareQuota(fs, newFSsize, task);
} catch (InternalException e) {
if (_log.isErrorEnabled()) {
_log.error("Reduce File Quota error", e);
}
fs = _dbClient.queryObject(FileShare.class, fs.getId());
op = fs.getOpStatus().get(task);
op.error(e);
fs.getOpStatus().updateTaskStatus(task, op);
_dbClient.updateObject(fs);
throw e;
}
return toTask(fs, task, op);
}
use of com.emc.storageos.svcs.errorhandling.resources.InternalException in project coprhd-controller by CoprHD.
the class FileService method updateFileSystemAcls.
/**
* Update existing file system ACL
*
* @param id
* the URN of a ViPR fileSystem
* @param param
* FileNfsACLUpdateParams
* @brief Update file system ACL
* @return Task resource representation
* @throws InternalException
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/acl")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateFileSystemAcls(@PathParam("id") URI id, FileNfsACLUpdateParams param) throws InternalException {
// log input received.
_log.info("Update FS ACL : request received for {} with {}", id, param);
// Validate the FS id.
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
// Check for VirtualPool whether it has NFS v4 enabled
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
if (!vpool.getProtocols().contains(StorageProtocol.File.NFSv4.name())) {
// Throw an error
throw APIException.methodNotAllowed.vPoolDoesntSupportProtocol("Vpool does not support " + StorageProtocol.File.NFSv4.name() + " protocol");
}
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
FileController controller = getController(FileController.class, device.getSystemType());
String task = UUID.randomUUID().toString();
String path = fs.getPath();
_log.info("fileSystem path {} ", path);
Operation op = new Operation();
try {
_log.info("Sub Dir Provided {}", param.getSubDir());
// Validate the input
NfsACLUtility util = new NfsACLUtility(_dbClient, fs, null, param.getSubDir());
util.verifyNfsACLs(param);
_log.info("No Errors found proceeding further {}, {}, {}", new Object[] { _dbClient, fs, param });
op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.UPDATE_FILE_SYSTEM_NFS_ACL);
op.setDescription("Filesystem NFS ACL update");
controller.updateNFSAcl(device.getId(), fs.getId(), param, task);
auditOp(OperationTypeEnum.UPDATE_FILE_SYSTEM_NFS_ACL, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), param);
} catch (BadRequestException e) {
op = _dbClient.error(FileShare.class, fs.getId(), task, e);
_log.error("Error Processing File System ACL Updates {}, {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Error Processing File System ACL Updates {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return toTask(fs, task, op);
}
use of com.emc.storageos.svcs.errorhandling.resources.InternalException in project coprhd-controller by CoprHD.
the class FileService method expand.
/**
* Expand file system.
* <p>
* NOTE: This is an asynchronous operation.
*
* @param param
* File system expansion parameters
* @param id
* the URN of a ViPR File system
* @brief Expand file system
* @return Task resource representation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/expand")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep expand(@PathParam("id") URI id, FileSystemExpandParam param) throws InternalException {
_log.info(String.format("FileShareExpand --- FileShare id: %1$s, New Size: %2$s", id, param.getNewSize()));
// check file System
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
Long newFSsize = SizeUtil.translateSize(param.getNewSize());
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
if (newFSsize <= 0) {
throw APIException.badRequests.parameterMustBeGreaterThan("new_size", 0);
}
// checkQuota
long expand = newFSsize - fs.getCapacity();
final long MIN_EXPAND_SIZE = SizeUtil.translateSize("1MB") + 1;
if (expand < MIN_EXPAND_SIZE) {
throw APIException.badRequests.invalidParameterBelowMinimum("new_size", newFSsize, fs.getCapacity() + MIN_EXPAND_SIZE, "bytes");
}
Project project = _dbClient.queryObject(Project.class, fs.getProject().getURI());
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, fs.getTenant().getURI());
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
CapacityUtils.validateQuotasForProvisioning(_dbClient, vpool, project, tenant, expand, "filesystem");
String task = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.EXPAND_FILE_SYSTEM);
op.setDescription("Filesystem expand");
FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
try {
fileServiceApi.expandFileShare(fs, newFSsize, task);
} catch (InternalException e) {
if (_log.isErrorEnabled()) {
_log.error("Expand File Size 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;
}
return toTask(fs, task, op);
}
use of com.emc.storageos.svcs.errorhandling.resources.InternalException in project coprhd-controller by CoprHD.
the class FileService method failbackProtection.
/**
* Request to fail Back the protection link associated with the param.copyID.
*
* NOTE: This is an asynchronous operation.
*
* @prereq none
*
* @param id
* the URN of a ViPR Source files hare
* @param param
* FileReplicationParam to fail Back to
*
* @brief Fail Back 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/failback")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failbackProtection(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
doMirrorOperationValidation(id, ProtectionOp.FAILBACK.toString());
TaskResourceRep taskResp = null;
StoragePort storageportNFS = null;
StoragePort storageportCIFS = null;
TaskList taskList = new TaskList();
String task = UUID.randomUUID().toString();
FileShare sourceFileShare = queryResource(id);
Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILBACK);
op.setDescription("failback to source file system from target system");
boolean replicateConfiguration = param.isReplicateConfiguration();
if (replicateConfiguration) {
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
FileShare targetFileShare = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
SMBShareMap smbShareMap = targetFileShare.getSMBFileShares();
if (smbShareMap != null) {
storageportCIFS = _fileScheduler.placeFileShareExport(sourceFileShare, StorageProtocol.File.CIFS.name(), null);
}
FSExportMap nfsExportMap = targetFileShare.getFsExports();
if (nfsExportMap != null) {
storageportNFS = _fileScheduler.placeFileShareExport(sourceFileShare, StorageProtocol.File.NFS.name(), null);
}
}
FileServiceApi fileServiceApi = getFileShareServiceImpl(sourceFileShare, _dbClient);
try {
fileServiceApi.failbackFileShare(sourceFileShare.getId(), storageportNFS, storageportCIFS, replicateConfiguration, task);
} catch (InternalException e) {
if (_log.isErrorEnabled()) {
_log.error("", e);
}
op = sourceFileShare.getOpStatus().get(task);
op.error(e);
sourceFileShare.getOpStatus().updateTaskStatus(task, op);
_dbClient.updateObject(sourceFileShare);
throw e;
}
taskResp = toTask(sourceFileShare, task, op);
taskList.getTaskList().add(taskResp);
return taskList;
}
Aggregations