use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class FileDeviceController method createFS.
@Override
public void createFS(URI storage, URI pool, URI fs, String nativeId, String opId) throws ControllerException {
FileObject fileObject = null;
FileShare fsObj = null;
StorageSystem storageObj = null;
try {
ControllerUtils.setThreadLocalLogData(fs, opId);
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
String[] params = { storage.toString(), pool.toString(), fs.toString() };
_log.info("Create FS: {}, {}, {}", params);
StoragePool poolObj = _dbClient.queryObject(StoragePool.class, pool);
fsObj = _dbClient.queryObject(FileShare.class, fs);
VirtualPool vPool = _dbClient.queryObject(VirtualPool.class, fsObj.getVirtualPool());
fileObject = fsObj;
FileDeviceInputOutput args = new FileDeviceInputOutput();
args.addFileShare(fsObj);
args.addStoragePool(poolObj);
args.setVPool(vPool);
args.setNativeDeviceFsId(nativeId);
args.setOpId(opId);
Project proj = _dbClient.queryObject(Project.class, fsObj.getProject());
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, fsObj.getTenant());
setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
args.setTenantOrg(tenant);
args.setProject(proj);
// work flow and we need to add TaskCompleter(TBD for vnxfile)
WorkflowStepCompleter.stepExecuting(opId);
acquireStepLock(storageObj, opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).doCreateFS(storageObj, args);
if (!result.getCommandPending()) {
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
} else {
// we need to add task completer
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
}
if (result.isCommandSuccess()) {
fsObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, fsObj));
fsObj.setInactive(false);
WorkflowStepCompleter.stepSucceded(opId);
} else if (!result.getCommandPending()) {
fsObj.setInactive(true);
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
_dbClient.updateObject(fsObj);
if (!result.getCommandPending()) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM, result.isCommandSuccess(), "", "", fsObj);
}
} catch (Exception e) {
String[] params = { storage.toString(), pool.toString(), fs.toString(), e.getMessage() };
_log.error("Unable to create file system: storage {}, pool {}, FS {}: {}", params);
// work flow fail
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
if ((fsObj != null) && (storageObj != null)) {
fsObj.setInactive(true);
_dbClient.updateObject(fsObj);
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM, false, e.getMessage(), "", fsObj, storageObj);
}
updateTaskStatus(opId, fileObject, e);
}
}
use of com.emc.storageos.db.client.model.Project 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.Project in project coprhd-controller by CoprHD.
the class ControllerUtils method getProjectTenantOrgURI.
/**
* Gets the URI of the tenant organization for the project with the passed
* URI.
*
* @param dbClient A reference to the database client.
* @param projectURI The URI for the project.
*
* @return The URI of the tenant organization.
*/
public static URI getProjectTenantOrgURI(DbClient dbClient, URI projectURI) {
URI tenantOrgURI = null;
try {
s_logger.debug("Getting the URI of the tenant for project {}.", projectURI);
// Get the Project with the passed URI from the database and extract
// the tenant organization for the project.
Project project = dbClient.queryObject(Project.class, projectURI);
if (project != null) {
tenantOrgURI = project.getTenantOrg().getURI();
if (tenantOrgURI == null) {
s_logger.warn("The tenant URI is null for project {}.", projectURI);
}
} else {
s_logger.warn("The database returned a null project for URI {}.", projectURI);
}
} catch (Exception e) {
s_logger.warn("Exception fetching project {} from the database.", projectURI, e);
}
// Use the default provider tenant if the tenant cannot be determined.
if (tenantOrgURI == null) {
tenantOrgURI = URI.create(TenantOrg.PROVIDER_TENANT_ORG);
}
s_logger.debug("Returning tenant {} for project {}.", new Object[] { tenantOrgURI, projectURI });
return tenantOrgURI;
}
use of com.emc.storageos.db.client.model.Project 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.Project 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);
}
}
Aggregations