use of com.emc.storageos.db.client.model.VirtualPool in project coprhd-controller by CoprHD.
the class FileDeviceController method assignFileSnapshotPolicyToProjects.
@Override
public void assignFileSnapshotPolicyToProjects(URI storageSystemURI, URI vNASURI, URI filePolicyToAssign, URI vpoolURI, URI projectURI, String opId) throws InternalException {
try {
WorkflowStepCompleter.stepExecuting(opId);
FileDeviceInputOutput args = new FileDeviceInputOutput();
StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
Project project = _dbClient.queryObject(Project.class, projectURI);
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg());
if (vNASURI != null) {
VirtualNAS vNAS = _dbClient.queryObject(VirtualNAS.class, vNASURI);
args.setvNAS(vNAS);
}
args.setFileProtectionPolicy(filePolicy);
args.setVPool(vpool);
args.setProject(project);
args.setTenantOrg(tenant);
_log.info("Assigning file snapshot policy: {} to vpool {} and project: {}", filePolicyToAssign, vpoolURI, projectURI);
BiosCommandResult result = getDevice(storageObj.getSystemType()).checkFilePolicyExistsOrCreate(storageObj, args);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
}
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
}
}
use of com.emc.storageos.db.client.model.VirtualPool in project coprhd-controller by CoprHD.
the class FileDeviceController method assignFileReplicationPolicyToVirtualPools.
@Override
public void assignFileReplicationPolicyToVirtualPools(URI storageSystemURI, URI targetSystemURI, URI sourceVNasURI, URI targetVArrayURI, URI targetVNasURI, URI filePolicyToAssign, URI vpoolURI, String opId) throws ControllerException {
try {
WorkflowStepCompleter.stepExecuting(opId);
StorageSystem sourceSystem = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
StorageSystem targetSystem = _dbClient.queryObject(StorageSystem.class, targetSystemURI);
FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
VirtualArray targetVarray = _dbClient.queryObject(VirtualArray.class, targetVArrayURI);
VirtualNAS sourceVNAS = null;
VirtualNAS targetVNAS = null;
FileDeviceInputOutput sourceArgs = new FileDeviceInputOutput();
FileDeviceInputOutput targetArgs = new FileDeviceInputOutput();
targetArgs.setVarray(targetVarray);
sourceArgs.setFileProtectionPolicy(filePolicy);
sourceArgs.setVPool(vpool);
if (sourceVNasURI != null) {
sourceVNAS = _dbClient.queryObject(VirtualNAS.class, sourceVNasURI);
sourceArgs.setvNAS(sourceVNAS);
targetArgs.setSourceVNAS(sourceVNAS);
}
targetArgs.setSourceSystem(sourceSystem);
targetArgs.setVPool(vpool);
targetArgs.setTarget(true);
if (targetVNasURI != null) {
targetVNAS = _dbClient.queryObject(VirtualNAS.class, targetVNasURI);
targetArgs.setvNAS(targetVNAS);
}
_log.info("Assigning file replication policy: {} to vpool: {}", filePolicyToAssign, vpoolURI);
BiosCommandResult result = getDevice(sourceSystem.getSystemType()).checkFileReplicationPolicyExistsOrCreate(sourceSystem, targetSystem, sourceArgs, targetArgs);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
}
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
}
}
use of com.emc.storageos.db.client.model.VirtualPool in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method addStepsForApplyingPolicies.
public String addStepsForApplyingPolicies(Workflow workflow, String waitFor, List<FileDescriptor> fileDescriptors) {
FileDescriptor sourceDescriptors = FileDescriptor.filterByType(fileDescriptors, FileDescriptor.Type.FILE_DATA, FileDescriptor.Type.FILE_MIRROR_SOURCE).get(0);
FileShare sourceFS = s_dbClient.queryObject(FileShare.class, sourceDescriptors.getFsURI());
StorageSystem system = s_dbClient.queryObject(StorageSystem.class, sourceFS.getStorageDevice());
// applying policy is only supported by isilon
if (system != null && system.getSystemType().equalsIgnoreCase(Type.isilon.toString())) {
URI nasServer = null;
if (sourceFS.getVirtualNAS() != null) {
nasServer = sourceFS.getVirtualNAS();
} else {
// Get the physical NAS for the storage system!!
PhysicalNAS pNAS = FileOrchestrationUtils.getSystemPhysicalNAS(s_dbClient, system);
if (pNAS != null) {
nasServer = pNAS.getId();
}
}
if (nasServer == null) {
s_logger.error(String.format("Adding steps to apply policies failed : No Nas server found on system {}", system.getLabel()));
throw DeviceControllerException.exceptions.noNasServerFoundToAddStepsToApplyPolicy(system.getLabel());
}
// Add all the vpool and project level policies to the workflow steps.
// Verify the policy is already applied or not at device control level.
// Create storage device policy only if the policy was not applied for policy path on storage system!!
// Fail to create policy and/or file system, if any policy to be applied at path is invalid!!
VirtualPool vpool = s_dbClient.queryObject(VirtualPool.class, sourceFS.getVirtualPool());
List<FilePolicy> fileVpoolPolicies = getVpoolLevelPolices(vpool);
if (fileVpoolPolicies != null && !fileVpoolPolicies.isEmpty()) {
for (FilePolicy fileVpoolPolicy : fileVpoolPolicies) {
String stepDescription = String.format("creating file policy : %s at : %s level", fileVpoolPolicy.getId(), vpool.getLabel());
String applyFilePolicyStep = workflow.createStepId();
Object[] args = new Object[] { sourceFS.getStorageDevice(), sourceFS.getId(), fileVpoolPolicy.getId() };
waitFor = _fileDeviceController.createMethod(workflow, waitFor, APPLY_FILE_POLICY_METHOD, applyFilePolicyStep, stepDescription, system.getId(), args);
}
}
Project project = s_dbClient.queryObject(Project.class, sourceFS.getProject());
List<FilePolicy> fileProjectPolicies = getProjectLevelPolices(vpool, project);
if (fileProjectPolicies != null && !fileProjectPolicies.isEmpty()) {
for (FilePolicy fileProjectPolicy : fileProjectPolicies) {
String stepDescription = String.format("creating file policy : %s at : %s level", fileProjectPolicy.getId(), project.getLabel());
String applyFilePolicyStep = workflow.createStepId();
Object[] args = new Object[] { sourceFS.getStorageDevice(), sourceFS.getId(), fileProjectPolicy.getId() };
waitFor = _fileDeviceController.createMethod(workflow, waitFor, APPLY_FILE_POLICY_METHOD, applyFilePolicyStep, stepDescription, system.getId(), args);
}
}
}
return waitFor;
}
use of com.emc.storageos.db.client.model.VirtualPool in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method updateUnAssignedResource.
public static void updateUnAssignedResource(FilePolicy filePolicy, URI unassignRes, DbClient dbClient) {
FilePolicyApplyLevel applyLevel = FilePolicyApplyLevel.valueOf(filePolicy.getApplyAt());
switch(applyLevel) {
case vpool:
VirtualPool vpool = dbClient.queryObject(VirtualPool.class, unassignRes);
vpool.removeFilePolicy(filePolicy.getId());
dbClient.updateObject(vpool);
break;
case project:
Project project = dbClient.queryObject(Project.class, unassignRes);
project.removeFilePolicy(project, filePolicy.getId());
dbClient.updateObject(project);
break;
case file_system:
FileShare fs = dbClient.queryObject(FileShare.class, unassignRes);
fs.removeFilePolicy(filePolicy.getId());
dbClient.updateObject(fs);
break;
default:
_log.error("Not a valid policy apply level: " + applyLevel);
}
}
use of com.emc.storageos.db.client.model.VirtualPool in project coprhd-controller by CoprHD.
the class InternalFileResource method releaseFileSystemInternal.
/**
* Release a file system from its current tenant & project for internal object usage
*
* @param id the URN of a ViPR file system to be released
* @return the updated file system
* @throws InternalException
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/release")
public FileShareRestRep releaseFileSystemInternal(@PathParam("id") URI id) throws InternalException {
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = _fileService.queryResource(id);
// and just return success down at the bottom
if (!fs.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
URI tenantURI = fs.getTenant().getURI();
if (!_permissionsHelper.userHasGivenRole(getUserFromContext(), tenantURI, Role.TENANT_ADMIN)) {
throw APIException.forbidden.onlyAdminsCanReleaseFileSystems(Role.TENANT_ADMIN.toString());
}
// we can't release a fs that has exports
FSExportMap exports = fs.getFsExports();
if ((exports != null) && (!exports.isEmpty())) {
throw APIException.badRequests.cannotReleaseFileSystemExportExists(exports.keySet().toString());
}
// we can't release a fs that has shares
SMBShareMap shares = fs.getSMBFileShares();
if ((shares != null) && (!shares.isEmpty())) {
throw APIException.badRequests.cannotReleaseFileSystemSharesExists(shares.keySet().toString());
}
// files systems with pending operations can't be released
if (fs.getOpStatus() != null) {
for (String opId : fs.getOpStatus().keySet()) {
Operation op = fs.getOpStatus().get(opId);
if (Operation.Status.pending.name().equals(op.getStatus())) {
throw APIException.badRequests.cannotReleaseFileSystemWithTasksPending();
}
}
}
// file systems with snapshots can't be released
Integer snapCount = _fileService.getNumSnapshots(fs);
if (snapCount > 0) {
throw APIException.badRequests.cannotReleaseFileSystemSnapshotExists(snapCount);
}
TenantOrg rootTenant = _permissionsHelper.getRootTenant();
// we can't release the file system to the root tenant if the root tenant has no access
// to the filesystem's virtual pool
ArgValidator.checkFieldNotNull(fs.getVirtualPool(), "virtualPool");
VirtualPool virtualPool = _permissionsHelper.getObjectById(fs.getVirtualPool(), VirtualPool.class);
ArgValidator.checkEntity(virtualPool, fs.getVirtualPool(), false);
if (!_permissionsHelper.tenantHasUsageACL(rootTenant.getId(), virtualPool)) {
throw APIException.badRequests.cannotReleaseFileSystemRootTenantLacksVPoolACL(virtualPool.getId().toString());
}
fs.setOriginalProject(fs.getProject().getURI());
fs.setTenant(new NamedURI(rootTenant.getId(), fs.getLabel()));
fs.setProject(new NamedURI(_internalProject.getId(), fs.getLabel()));
fs.addInternalFlags(INTERNAL_FILESHARE_FLAGS);
_dbClient.updateAndReindexObject(fs);
// audit against the source project, not the new dummy internal project
auditOp(OperationTypeEnum.RELEASE_FILE_SYSTEM, true, null, fs.getId().toString(), fs.getOriginalProject().toString());
}
return map(fs);
}
Aggregations