Search in sources :

Example 1 with Project

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Project(com.emc.storageos.db.client.model.Project) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 2 with Project

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);
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 3 with Project

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;
}
Also used : Project(com.emc.storageos.db.client.model.Project) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 4 with Project

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;
}
Also used : Project(com.emc.storageos.db.client.model.Project) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileObject(com.emc.storageos.db.client.model.FileObject) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) PhysicalNAS(com.emc.storageos.db.client.model.PhysicalNAS) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 5 with Project

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);
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FilePolicyApplyLevel(com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel) FileShare(com.emc.storageos.db.client.model.FileShare)

Aggregations

Project (com.emc.storageos.db.client.model.Project)190 URI (java.net.URI)98 NamedURI (com.emc.storageos.db.client.model.NamedURI)93 ArrayList (java.util.ArrayList)67 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)65 Volume (com.emc.storageos.db.client.model.Volume)57 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)54 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)50 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)47 StringSet (com.emc.storageos.db.client.model.StringSet)43 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)40 List (java.util.List)37 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)36 Produces (javax.ws.rs.Produces)34 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)33 Test (org.junit.Test)31 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)27 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)27 Operation (com.emc.storageos.db.client.model.Operation)26 Consumes (javax.ws.rs.Consumes)26