use of com.emc.storageos.db.client.model.NamedURI 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.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class FileService method prepareFileSystem.
/**
* Allocate, initialize and persist state of the fileSystem being created.
*
* @param param
* @param project
* @param tenantOrg
* @param neighborhood
* @param vpool
* @param flags
* @param placement
* @param token
* @return
*/
private FileShare prepareFileSystem(FileSystemParam param, Project project, TenantOrg tenantOrg, VirtualArray neighborhood, VirtualPool vpool, DataObject.Flag[] flags, FileRecommendation placement, String token) {
_log.info("prepareFile System");
StoragePool pool = null;
FileShare fs = new FileShare();
fs.setId(URIUtil.createId(FileShare.class));
fs.setLabel(param.getLabel());
// No need to generate any name -- Since the requirement is to use the customizing label we should use the same.
// Stripping out the special characters like ; /-+!@#$%^&())";:[]{}\ | but allow underscore character _
String convertedName = param.getLabel().replaceAll("[^\\dA-Za-z\\_]", "");
_log.info("Original name {} and converted name {}", param.getLabel(), convertedName);
fs.setName(convertedName);
Long fsSize = SizeUtil.translateSize(param.getSize());
fs.setCapacity(fsSize);
fs.setVirtualPool(param.getVpool());
if (project != null) {
fs.setProject(new NamedURI(project.getId(), fs.getLabel()));
}
fs.setTenant(new NamedURI(tenantOrg.getId(), param.getLabel()));
fs.setVirtualArray(neighborhood.getId());
if (null != placement.getSourceStoragePool()) {
pool = _dbClient.queryObject(StoragePool.class, placement.getSourceStoragePool());
if (null != pool) {
fs.setProtocol(new StringSet());
fs.getProtocol().addAll(VirtualPoolUtil.getMatchingProtocols(vpool.getProtocols(), pool.getProtocols()));
}
}
fs.setStorageDevice(placement.getSourceStorageSystem());
fs.setPool(placement.getSourceStoragePool());
if (param.getSoftLimit() != 0) {
fs.setSoftLimit(new Long(param.getSoftLimit()));
}
if (param.getNotificationLimit() != 0) {
fs.setNotificationLimit(new Long(param.getNotificationLimit()));
}
if (param.getSoftGrace() > 0) {
fs.setSoftGracePeriod(new Integer(param.getSoftGrace()));
}
if (placement.getStoragePorts() != null && !placement.getStoragePorts().isEmpty()) {
fs.setStoragePort(placement.getStoragePorts().get(0));
}
// When a VPool supports "thin" provisioning
if (VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vpool.getSupportedProvisioningType())) {
fs.setThinlyProvisioned(Boolean.TRUE);
}
if (placement.getvNAS() != null) {
fs.setVirtualNAS(placement.getvNAS());
}
fs.setOpStatus(new OpStatusMap());
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM);
fs.getOpStatus().createTaskStatus(token, op);
if (flags != null) {
fs.addInternalFlags(flags);
}
_dbClient.createObject(fs);
return fs;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class AbstractBlockServiceApiImpl method prepareSnapshotFromVolume.
/**
* Creates and returns a new ViPR BlockSnapshot instance with the passed
* name for the passed volume.
*
* @param volume
* The volume for which the snapshot is being created.
* @param snapsetLabel
* The snapset label for grouping this snapshot
* @param label
* The label for the new snapshot
* @return A reference to the new BlockSnapshot instance.
*/
protected BlockSnapshot prepareSnapshotFromVolume(Volume volume, String snapsetLabel, String label) {
BlockSnapshot snapshot = new BlockSnapshot();
snapshot.setId(URIUtil.createId(BlockSnapshot.class));
URI cgUri = volume.getConsistencyGroup();
if (cgUri != null) {
snapshot.setConsistencyGroup(cgUri);
}
snapshot.setSourceNativeId(volume.getNativeId());
snapshot.setParent(new NamedURI(volume.getId(), volume.getLabel()));
snapshot.setLabel(label);
snapshot.setStorageController(volume.getStorageController());
snapshot.setSystemType(volume.getSystemType());
snapshot.setVirtualArray(volume.getVirtualArray());
snapshot.setProtocol(new StringSet());
snapshot.getProtocol().addAll(volume.getProtocol());
snapshot.setProject(new NamedURI(volume.getProject().getURI(), volume.getProject().getName()));
snapshot.setSnapsetLabel(ResourceOnlyNameGenerator.removeSpecialCharsForName(snapsetLabel, SmisConstants.MAX_SNAPSHOT_NAME_LENGTH));
return snapshot;
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method createConsistencyGroup.
/**
* Create a new consistency group
*
* You can create a consistency group, but adding volumes into it will be done using in the
* volume create operations:
*
* 1. Create CG object in Bourne 2. Operation will be synchronous
*
* @prereq none
*
* @param param
*
* @brief Create consistency group
* @return Consistency Group created
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public BlockConsistencyGroupRestRep createConsistencyGroup(final BlockConsistencyGroupCreate param) {
checkForDuplicateName(param.getName(), BlockConsistencyGroup.class);
ArgValidator.checkIsAlphaNumeric(param.getName());
// Validate name
ArgValidator.checkFieldNotEmpty(param.getName(), "name");
// Validate name not greater than 64 characters
ArgValidator.checkFieldLengthMaximum(param.getName(), CG_MAX_LIMIT, "name");
// Validate project
ArgValidator.checkFieldUriType(param.getProject(), Project.class, "project");
final Project project = _dbClient.queryObject(Project.class, param.getProject());
ArgValidator.checkEntity(project, param.getProject(), isIdEmbeddedInURL(param.getProject()));
// Verify the user is authorized.
verifyUserIsAuthorizedForRequest(project);
// Create Consistency Group in db
final BlockConsistencyGroup consistencyGroup = new BlockConsistencyGroup();
consistencyGroup.setId(URIUtil.createId(BlockConsistencyGroup.class));
consistencyGroup.setLabel(param.getName());
consistencyGroup.setProject(new NamedURI(project.getId(), project.getLabel()));
consistencyGroup.setTenant(project.getTenantOrg());
// disable array consistency if user has selected not to create backend replication group
consistencyGroup.setArrayConsistency(param.getArrayConsistency());
_dbClient.createObject(consistencyGroup);
return map(consistencyGroup, null, _dbClient);
}
use of com.emc.storageos.db.client.model.NamedURI in project coprhd-controller by CoprHD.
the class FileMirrorServiceApiImpl method setMirrorFileShareAttributes.
/**
* Set mirror object information
*
* @param sourceFileShare
* @param targetFileShare
*/
private void setMirrorFileShareAttributes(FileShare sourceFileShare, FileShare targetFileShare) {
if (sourceFileShare != null) {
if (sourceFileShare.getMirrorfsTargets() == null) {
sourceFileShare.setMirrorfsTargets(new StringSet());
}
sourceFileShare.getMirrorfsTargets().add(targetFileShare.getId().toString());
targetFileShare.setParentFileShare(new NamedURI(sourceFileShare.getId(), sourceFileShare.getLabel()));
setMirrorFileShareConfigAttributes(sourceFileShare, targetFileShare);
_dbClient.updateObject(sourceFileShare);
_dbClient.updateObject(targetFileShare);
}
}
Aggregations