use of com.emc.storageos.volumecontroller.FileShareQuotaDirectory in project coprhd-controller by CoprHD.
the class FileDeviceController method createQuotaDirectory.
@Override
public void createQuotaDirectory(URI storage, FileShareQuotaDirectory quotaDir, URI fs, String task) throws ControllerException {
ControllerUtils.setThreadLocalLogData(fs, task);
FileShare fsObj = null;
QuotaDirectory quotaDirObj = null;
try {
String[] params = { storage.toString(), fs.toString(), quotaDir.toString() };
_log.info("FileDeviceController::createQtree: create QuotaDirectory: storage : {}, quotaDir : {}, fs : {}", params);
StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
fsObj = _dbClient.queryObject(FileShare.class, fs);
URI qtreeURI = quotaDir.getId();
quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, qtreeURI);
FileDeviceInputOutput args = new FileDeviceInputOutput();
// Set up args
args.addFileShare(fsObj);
args.addQuotaDirectory(quotaDirObj);
args.setOpId(task);
FileStorageDevice nasDevice = getDevice(storageObj.getSystemType());
BiosCommandResult result = nasDevice.doCreateQuotaDirectory(storageObj, args, quotaDirObj);
if (result.getCommandPending()) {
return;
}
fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
quotaDirObj.getOpStatus().updateTaskStatus(task, result.toOperation());
String fsName = fsObj.getName();
quotaDirObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirObj, fsName));
// In case of an error, set the quotaDir to an 'inactive' state.
if (!result.isCommandSuccess()) {
quotaDirObj.setInactive(true);
_log.error("FileDeviceController::createQtree: QuotaDirectory create command is not successfull");
}
_dbClient.updateObject(quotaDirObj);
_dbClient.updateObject(fsObj);
fsObj = _dbClient.queryObject(FileShare.class, fs);
_log.debug("FileDeviceController::createQtree: After QuotaDirectory created and fs persisted, Task Stauts {} -- Operation Details : {}", fsObj.getOpStatus().get(task).getStatus(), result.toOperation());
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, result.isCommandSuccess(), eventMsg, "", quotaDirObj, fsObj);
} catch (Exception e) {
String[] params = { storage.toString(), fs.toString(), quotaDir.toString(), e.getMessage() };
_log.error("FileDeviceController::createQtree: Unable to create file system quotaDir: storage {}, FS {}, snapshot {}: {}", params);
// remove from DB
if (quotaDirObj != null) {
quotaDirObj.setInactive(true);
_dbClient.updateObject(quotaDirObj);
}
updateTaskStatus(task, fsObj, e);
updateTaskStatus(task, quotaDirObj, e);
if ((fsObj != null) && (quotaDirObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, false, e.getMessage(), "", quotaDirObj, fsObj);
}
}
}
use of com.emc.storageos.volumecontroller.FileShareQuotaDirectory in project coprhd-controller by CoprHD.
the class FileDeviceController method updateQuotaDirectory.
@Override
public void updateQuotaDirectory(URI storage, FileShareQuotaDirectory quotaDir, URI fs, String task) throws ControllerException {
ControllerUtils.setThreadLocalLogData(fs, task);
FileShare fsObj = null;
StorageSystem storageObj = null;
QuotaDirectory quotaDirObj = null;
FileDeviceInputOutput args = new FileDeviceInputOutput();
try {
String[] params = { storage.toString(), fs.toString(), quotaDir.toString() };
_log.info("FileDeviceController::updateQtree: storage : {}, fs : {}, quotaDir : {}", params);
fsObj = _dbClient.queryObject(FileShare.class, fs);
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir.getId());
if (null != quotaDir.getSize()) {
quotaDirObj.setSize(quotaDir.getSize());
}
quotaDirObj.setSoftLimit(quotaDir.getSoftLimit());
quotaDirObj.setSoftGrace(quotaDir.getSoftGrace());
quotaDirObj.setNotificationLimit(quotaDir.getNotificationLimit());
if (null != quotaDir.getOpLock()) {
quotaDirObj.setOpLock(quotaDir.getOpLock());
}
if (null != quotaDir.getSecurityStyle()) {
quotaDirObj.setSecurityStyle(quotaDir.getSecurityStyle());
}
// Set up args
args.addFileShare(fsObj);
args.addQuotaDirectory(quotaDirObj);
args.setOpId(task);
FileStorageDevice nasDevice = getDevice(storageObj.getSystemType());
BiosCommandResult result = nasDevice.doUpdateQuotaDirectory(storageObj, args, quotaDirObj);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
_log.error("FileDeviceController::updateQtree: QuotaDirectory update command is not successful");
// The quota object was already modified with changes.
// if it fail to update the quota directory,
// restore the object with the original quota directory!!!
quotaDirObj = _dbClient.queryObject(QuotaDirectory.class, quotaDir.getId());
}
quotaDirObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, quotaDirObj, fsObj.getName()));
fsObj.getOpStatus().updateTaskStatus(task, result.toOperation());
quotaDirObj.getOpStatus().updateTaskStatus(task, result.toOperation());
// save the task status into db
_dbClient.updateObject(quotaDirObj);
_dbClient.updateObject(fsObj);
fsObj = _dbClient.queryObject(FileShare.class, fs);
_log.debug("FileDeviceController::updateQtree: After QuotaDirectory updated and fs persisted, Task Stauts {} -- Operation Details : {}", fsObj.getOpStatus().get(task).getStatus(), result.toOperation());
String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
recordFileDeviceOperation(_dbClient, OperationTypeEnum.UPDATE_FILE_SYSTEM_QUOTA_DIR, result.isCommandSuccess(), eventMsg, "", quotaDirObj, fsObj);
} catch (Exception e) {
String[] params = { storage.toString(), fs.toString(), quotaDir.toString(), e.getMessage() };
_log.error("FileDeviceController::updateQtree: Unable to update file system quotaDir: storage {}, FS {}, snapshot {}: {}", params);
updateTaskStatus(task, fsObj, e);
updateTaskStatus(task, quotaDirObj, e);
if ((fsObj != null) && (quotaDirObj != null)) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, false, e.getMessage(), "", quotaDirObj, fsObj);
}
}
}
use of com.emc.storageos.volumecontroller.FileShareQuotaDirectory in project coprhd-controller by CoprHD.
the class FileService method createQuotaDirectory.
/**
* Create Quota directory for a file system
* <p>
* NOTE: This is an asynchronous operation.
*
* @param id
* the URN of a ViPR File system
* @param param
* File system Quota directory parameters
* @brief Create file system Quota directory
* @return Task resource representation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/quota-directories")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep createQuotaDirectory(@PathParam("id") URI id, QuotaDirectoryCreateParam param) throws InternalException {
_log.info("FileService::createQtree Request recieved {}", id);
String origQtreeName = param.getQuotaDirName();
ArgValidator.checkQuotaDirName(origQtreeName, "name");
ArgValidator.checkFieldMaximum(param.getSoftLimit(), 100, "softLimit");
ArgValidator.checkFieldMaximum(param.getNotificationLimit(), 100, "notificationLimit");
if (param.getSoftLimit() != 0L) {
ArgValidator.checkFieldMinimum(param.getSoftGrace(), 1L, "softGrace");
}
// check duplicate QuotaDirectory names for this fileshare
checkForDuplicateName(origQtreeName, QuotaDirectory.class, id, "parent", _dbClient);
String task = UUID.randomUUID().toString();
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
if (param.getSecurityStyle() != null) {
ArgValidator.checkFieldValueFromEnum(param.getSecurityStyle(), "security_style", EnumSet.allOf(QuotaDirectory.SecurityStyles.class));
}
// Get the FileSystem object from the URN
FileShare fs = queryResource(id);
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
int fsSoftLimit = -1;
if (null != fs.getSoftLimit()) {
fsSoftLimit = fs.getSoftLimit().intValue();
}
int fsNotifiLimit = -1;
if (null != fs.getNotificationLimit()) {
fsNotifiLimit = fs.getNotificationLimit().intValue();
}
int fsGraceLimit = -1;
if (null != fs.getSoftGracePeriod()) {
fsGraceLimit = fs.getSoftGracePeriod().intValue();
}
// Create the QuotaDirectory object for the DB
QuotaDirectory quotaDirectory = new QuotaDirectory();
quotaDirectory.setId(URIUtil.createId(QuotaDirectory.class));
// ICICIC - Curious !
quotaDirectory.setParent(new NamedURI(id, origQtreeName));
quotaDirectory.setLabel(origQtreeName);
quotaDirectory.setOpStatus(new OpStatusMap());
quotaDirectory.setProject(new NamedURI(fs.getProject().getURI(), origQtreeName));
quotaDirectory.setTenant(new NamedURI(fs.getTenant().getURI(), origQtreeName));
quotaDirectory.setSoftLimit(param.getSoftLimit() > 0 ? param.getSoftLimit() : fsSoftLimit > 0 ? fsSoftLimit : 0);
quotaDirectory.setSoftGrace(param.getSoftGrace() > 0 ? param.getSoftGrace() : fsGraceLimit > 0 ? fsGraceLimit : 0);
quotaDirectory.setNotificationLimit(param.getNotificationLimit() > 0 ? param.getNotificationLimit() : fsNotifiLimit > 0 ? fsNotifiLimit : 0);
String convertedName = origQtreeName.replaceAll("[^\\dA-Za-z_]", "");
_log.info("FileService::QuotaDirectory Original name {} and converted name {}", origQtreeName, convertedName);
quotaDirectory.setName(convertedName);
if (param.getOpLock() != null) {
quotaDirectory.setOpLock(param.getOpLock());
} else {
quotaDirectory.setOpLock(true);
}
if (param.getSecurityStyle() != null) {
quotaDirectory.setSecurityStyle(param.getSecurityStyle());
} else {
quotaDirectory.setSecurityStyle(SecurityStyles.parent.toString());
}
if (param.getSize() != null) {
// converts the input string in format "<value>GB"
Long quotaSize = SizeUtil.translateSize(param.getSize());
// to bytes
ArgValidator.checkFieldMaximum(quotaSize, fs.getCapacity(), SizeUtil.SIZE_B, "size", true);
quotaDirectory.setSize(quotaSize);
} else {
quotaDirectory.setSize((long) 0);
}
fs.setOpStatus(new OpStatusMap());
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR);
quotaDirectory.getOpStatus().createTaskStatus(task, op);
fs.getOpStatus().createTaskStatus(task, op);
_dbClient.createObject(quotaDirectory);
_dbClient.persistObject(fs);
// Create an object of type "FileShareQuotaDirectory" to be passed into the south-bound layers.
FileShareQuotaDirectory qt = new FileShareQuotaDirectory(quotaDirectory);
// Now get ready to make calls into the controller
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
FileController controller = getController(FileController.class, device.getSystemType());
try {
controller.createQuotaDirectory(device.getId(), qt, fs.getId(), task);
} catch (InternalException e) {
quotaDirectory.setInactive(true);
_dbClient.persistObject(quotaDirectory);
// should discriminate between validation problems vs. internal errors
throw e;
}
auditOp(OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, true, AuditLogManager.AUDITOP_BEGIN, quotaDirectory.getLabel(), quotaDirectory.getId().toString(), fs.getId().toString());
fs = _dbClient.queryObject(FileShare.class, id);
_log.debug("FileService::QuotaDirectory Before sending response, FS ID : {}, Tasks : {} ; Status {}", fs.getOpStatus().get(task), fs.getOpStatus().get(task).getStatus());
return toTask(quotaDirectory, task, op);
}
use of com.emc.storageos.volumecontroller.FileShareQuotaDirectory in project coprhd-controller by CoprHD.
the class FileQuotaDirectoryService method updateQuotaDirectory.
/**
* Update Quota Directory for a file share
* <p>
* NOTE: This is an asynchronous operation.
*
* @param id
* the URN of a ViPR Quota directory
* @param param
* File system Quota directory update parameters
* @brief Update file system quota directory
* @return Task resource representation
* @throws com.emc.storageos.svcs.errorhandling.resources.InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateQuotaDirectory(@PathParam("id") URI id, QuotaDirectoryUpdateParam param) throws InternalException {
_log.info("FileService::Update Quota directory Request recieved {}", id);
QuotaDirectory quotaDirNew = new QuotaDirectory();
if (param.getSecurityStyle() != null) {
ArgValidator.checkFieldValueFromEnum(param.getSecurityStyle(), "security_style", EnumSet.allOf(QuotaDirectory.SecurityStyles.class));
}
// Get the FileSystem object
QuotaDirectory quotaDir = queryResource(id);
FileShare fs = queryFileShareResource(quotaDir.getParent().getURI());
ArgValidator.checkFieldNotNull(fs, "filesystem");
// Set all other optional parameters too.
quotaDirNew.setName(quotaDir.getName());
quotaDirNew.setId(id);
quotaDirNew.setNativeGuid(quotaDir.getNativeGuid());
if (param.getOpLock() != null) {
quotaDirNew.setOpLock(param.getOpLock());
}
if (param.getSecurityStyle() != null) {
quotaDirNew.setSecurityStyle(param.getSecurityStyle());
}
if (param.getSize() != null) {
// converts the input string in format "<value>GB" to Bytes
Long quotaSize = SizeUtil.translateSize(param.getSize());
if (quotaSize > 0) {
ArgValidator.checkFieldMaximum(quotaSize, fs.getCapacity(), SizeUtil.SIZE_B, "size", true);
quotaDirNew.setSize(quotaSize);
}
}
ArgValidator.checkFieldMaximum(param.getSoftLimit(), 100, "softLimit");
ArgValidator.checkFieldMaximum(param.getNotificationLimit(), 100, "notificationLimit");
if (param.getSoftLimit() != 0L) {
ArgValidator.checkFieldMinimum(param.getSoftGrace(), 1L, "softGrace");
}
int fsSoftLimit = -1;
if (null != fs.getSoftLimit()) {
fsSoftLimit = fs.getSoftLimit().intValue();
}
int fsNotifiLimit = -1;
if (null != fs.getNotificationLimit()) {
fsNotifiLimit = fs.getNotificationLimit().intValue();
}
int fsGraceLimit = -1;
if (null != fs.getSoftGracePeriod()) {
fsGraceLimit = fs.getSoftGracePeriod().intValue();
}
String task = UUID.randomUUID().toString();
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UPDATE_FILE_SYSTEM_QUOTA_DIR);
// Update the quota directory object to store in ViPR database
quotaDir.setOpStatus(new OpStatusMap());
quotaDir.getOpStatus().createTaskStatus(task, op);
fs.setOpStatus(new OpStatusMap());
fs.getOpStatus().createTaskStatus(task, op);
_dbClient.updateObject(fs);
_dbClient.updateObject(quotaDir);
quotaDirNew.setSoftLimit(param.getSoftLimit() > 0 ? param.getSoftLimit() : quotaDir.getSoftLimit() > 0 ? quotaDir.getSoftLimit() : fsSoftLimit > 0 ? fsSoftLimit : 0);
quotaDirNew.setSoftGrace(param.getSoftGrace() > 0 ? param.getSoftGrace() : quotaDir.getSoftGrace() > 0 ? quotaDir.getSoftGrace() : fsGraceLimit > 0 ? fsGraceLimit : 0);
quotaDirNew.setNotificationLimit(param.getNotificationLimit() > 0 ? param.getNotificationLimit() : quotaDir.getNotificationLimit() > 0 ? quotaDir.getNotificationLimit() : fsNotifiLimit > 0 ? fsNotifiLimit : 0);
// Create an object of type "FileShareQtree" to be passed into the
// south-bound layers.
FileShareQuotaDirectory qt = new FileShareQuotaDirectory(quotaDirNew);
// Now get ready to make calls into the controller
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
FileController controller = getController(FileController.class, device.getSystemType());
try {
controller.updateQuotaDirectory(device.getId(), qt, fs.getId(), task);
} catch (InternalException e) {
_log.error("Error during update of Quota Directory {}", e);
// errors
throw e;
}
auditOp(OperationTypeEnum.UPDATE_FILE_SYSTEM_QUOTA_DIR, true, AuditLogManager.AUDITOP_BEGIN, quotaDirNew.getLabel(), quotaDirNew.getId().toString(), fs.getId().toString());
fs = _dbClient.queryObject(FileShare.class, fs.getId());
_log.debug("FileService::Quota directory Before sending response, FS ID : {}, Taks : {} ; Status {}", fs.getOpStatus().get(task), fs.getOpStatus().get(task).getStatus());
return toTask(quotaDir, task, op);
}
Aggregations