Search in sources :

Example 66 with Project

use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.

the class StorageScheduler method prepareFullCopyVolumeFromVolume.

private static Volume prepareFullCopyVolumeFromVolume(DbClient dbClient, String name, Volume sourceVolume, VolumeRecommendation recommendation, int volumeCounter, VirtualPoolCapabilityValuesWrapper capabilities, Boolean createInactive) {
    long size = sourceVolume.getCapacity();
    long preAllocateSize = 0;
    if (null != sourceVolume.getThinVolumePreAllocationSize()) {
        preAllocateSize = sourceVolume.getThinVolumePreAllocationSize();
    }
    NamedURI projectUri = sourceVolume.getProject();
    Project project = dbClient.queryObject(Project.class, projectUri);
    URI vArrayUri = sourceVolume.getVirtualArray();
    VirtualArray vArray = dbClient.queryObject(VirtualArray.class, vArrayUri);
    URI vPoolUri = sourceVolume.getVirtualPool();
    VirtualPool vPool = dbClient.queryObject(VirtualPool.class, vPoolUri);
    String label = name + (volumeCounter > 0 ? ("-" + volumeCounter) : "");
    Volume volume = prepareVolume(dbClient, null, size, preAllocateSize, project, vArray, vPool, recommendation, label, null, capabilities, createInactive);
    // Since this is a full copy, update it with URI of the source volume
    volume.setAssociatedSourceVolume(sourceVolume.getId());
    StringSet associatedFullCopies = sourceVolume.getFullCopies();
    if (associatedFullCopies == null) {
        associatedFullCopies = new StringSet();
        sourceVolume.setFullCopies(associatedFullCopies);
    }
    associatedFullCopies.add(volume.getId().toString());
    dbClient.persistObject(volume);
    dbClient.persistObject(sourceVolume);
    addVolumeCapacityToReservedCapacityMap(dbClient, volume);
    return volume;
}
Also used : Project(com.emc.storageos.db.client.model.Project) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) NamedURI(com.emc.storageos.db.client.model.NamedURI) Volume(com.emc.storageos.db.client.model.Volume) StringSet(com.emc.storageos.db.client.model.StringSet) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 67 with Project

use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.

the class RPBlockServiceApiImpl method upgradeToMetroPointVolume.

/**
 * Upgrade a local block volume to a protected RP volume
 *
 * @param volume the existing volume being protected.
 * @param newVpool the requested virtual pool
 * @param taskId the task identifier
 * @throws InternalException
 */
private void upgradeToMetroPointVolume(Volume volume, VirtualPool newVpool, VirtualPoolChangeParam vpoolChangeParam, String taskId) throws InternalException {
    _log.info(String.format("Upgrade [%s] to MetroPoint", volume.getLabel()));
    Project project = _dbClient.queryObject(Project.class, volume.getProject());
    // Now that we have a handle on the current vpool, let's set the new vpool on the volume.
    // The volume will not be persisted just yet but we need to have the new vpool to
    // properly make placement decisions and to add reference to the new vpool to the
    // recommendation objects that will be created.
    URI currentVpool = volume.getVirtualPool();
    volume.setVirtualPool(newVpool.getId());
    List<Recommendation> recommendations = getRecommendationsForVirtualPoolChangeRequest(volume, newVpool, vpoolChangeParam, null);
    volume.setVirtualPool(currentVpool);
    if (recommendations.isEmpty()) {
        throw APIException.badRequests.noStorageFoundForVolume();
    }
    // Get the volume's varray
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, volume.getVirtualArray());
    // Generate a VolumeCreate object that contains the information that createVolumes likes to consume.
    VolumeCreate param = new VolumeCreate(volume.getLabel(), String.valueOf(volume.getCapacity()), 1, newVpool.getId(), volume.getVirtualArray(), volume.getProject().getURI());
    VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
    capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, 1);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.BLOCK_CONSISTENCY_GROUP, volume.getConsistencyGroup());
    TaskList taskList = new TaskList();
    createTaskForVolume(volume, ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VPOOL, taskList, taskId);
    Map<VpoolUse, List<Recommendation>> recommendationMap = new HashMap<VpoolUse, List<Recommendation>>();
    recommendationMap.put(VpoolUse.ROOT, recommendations);
    createVolumes(param, project, varray, newVpool, recommendationMap, taskList, taskId, capabilities);
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) Project(com.emc.storageos.db.client.model.Project) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) VpoolUse(com.emc.storageos.api.service.impl.placement.VpoolUse) HashMap(java.util.HashMap) TaskList(com.emc.storageos.model.TaskList) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) VolumeGroupVolumeList(com.emc.storageos.model.application.VolumeGroupUpdateParam.VolumeGroupVolumeList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystemConnectivityList(com.emc.storageos.model.systems.StorageSystemConnectivityList) List(java.util.List) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Recommendation(com.emc.storageos.volumecontroller.Recommendation) RPRecommendation(com.emc.storageos.volumecontroller.RPRecommendation) RPProtectionRecommendation(com.emc.storageos.volumecontroller.RPProtectionRecommendation) VolumeCreate(com.emc.storageos.model.block.VolumeCreate)

Example 68 with Project

use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.

the class TenantsService method createProject.

/**
 * Worker method for create project. Allows external requests (REST) as well as
 * internal requests that may not have a security context.
 *
 * @param id tenant id
 * @param param project params
 * @param owner name of owner of the request
 * @param ownerTenantId tenant id of the owner
 * @return project details
 */
public ProjectElement createProject(URI id, ProjectParam param, String owner, String ownerTenantId) {
    TenantOrg tenant = getTenantById(id, true);
    if (param.getName() != null && !param.getName().isEmpty()) {
        checkForDuplicateName(param.getName(), Project.class, id, "tenantOrg", _dbClient);
    }
    Project project = new Project();
    project.setId(URIUtil.createId(Project.class));
    project.setLabel(param.getName());
    project.setTenantOrg(new NamedURI(tenant.getId(), project.getLabel()));
    project.setOwner(owner);
    // set owner acl
    project.addAcl(new PermissionsKey(PermissionsKey.Type.SID, owner, ownerTenantId).toString(), ACL.OWN.toString());
    _dbClient.createObject(project);
    recordTenantEvent(OperationTypeEnum.CREATE_PROJECT, tenant.getId(), project.getId());
    return new ProjectElement(project.getId(), toLink(ResourceTypeEnum.PROJECT, project.getId()), project.getLabel());
}
Also used : Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) ProjectElement(com.emc.storageos.model.project.ProjectElement) PermissionsKey(com.emc.storageos.security.authorization.PermissionsKey) TenantOrg(com.emc.storageos.db.client.model.TenantOrg)

Example 69 with Project

use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.

the class TenantsService method listProjects.

/**
 * List projects the user is authorized to see
 *
 * @param id the URN of a ViPR Tenant/Subtenant
 * @prereq none
 * @brief List projects
 * @return List of projects
 */
@GET
@Path("/{id}/projects")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ProjectList listProjects(@PathParam("id") URI id) {
    TenantOrg tenant = getTenantById(id, false);
    StorageOSUser user = getUserFromContext();
    NamedElementQueryResultList projects = new NamedElementQueryResultList();
    if (_permissionsHelper.userHasGivenRole(user, tenant.getId(), Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN)) {
        // list all
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgProjectConstraint(tenant.getId()), projects);
    } else {
        // list only projects that the user has access to
        if (!id.equals(URI.create(user.getTenantId()))) {
            throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
        }
        Map<URI, Set<String>> allMyProjects = _permissionsHelper.getAllPermissionsForUser(user, tenant.getId(), null, false);
        if (!allMyProjects.keySet().isEmpty()) {
            List<Project> project_list = _dbClient.queryObjectField(Project.class, "label", new ArrayList<URI>(allMyProjects.keySet()));
            List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(project_list.size());
            for (Project p : project_list) {
                elements.add(NamedElementQueryResultList.NamedElement.createElement(p.getId(), p.getLabel()));
            }
            projects.setResult(elements.iterator());
        } else {
            // empty list
            projects.setResult(new ArrayList<NamedElementQueryResultList.NamedElement>().iterator());
        }
    }
    ProjectList list = new ProjectList();
    for (NamedElementQueryResultList.NamedElement el : projects) {
        list.getProjects().add(toNamedRelatedResource(ResourceTypeEnum.PROJECT, el.getId(), el.getName()));
    }
    return list;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Project(com.emc.storageos.db.client.model.Project) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) ProjectList(com.emc.storageos.model.project.ProjectList) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 70 with Project

use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.

the class VPlexDeviceController method addStepsForMigrateVolumes.

/**
 * Adds steps in the passed workflow to migrate a volume.
 *
 * @param workflow
 * @param vplexURI
 * @param virtualVolumeURI
 * @param targetVolumeURIs
 * @param migrationsMap
 * @param poolVolumeMap
 * @param newVpoolURI
 * @param newVarrayURI
 * @param suspendBeforeCommit
 * @param suspendBeforeDeleteSource
 * @param opId
 * @param waitFor
 * @return
 * @throws InternalException
 */
public String addStepsForMigrateVolumes(Workflow workflow, URI vplexURI, URI virtualVolumeURI, List<URI> targetVolumeURIs, Map<URI, URI> migrationsMap, Map<URI, URI> poolVolumeMap, URI newVpoolURI, URI newVarrayURI, boolean suspendBeforeCommit, boolean suspendBeforeDeleteSource, String opId, String waitFor) throws InternalException {
    try {
        _log.info("VPlex controller migrate volume {} on VPlex {}", virtualVolumeURI, vplexURI);
        String volumeUserLabel = "Label Unknown";
        Volume virtualVolume = getDataObject(Volume.class, virtualVolumeURI, _dbClient);
        if (virtualVolume != null && virtualVolume.getDeviceLabel() != null && virtualVolume.getLabel() != null) {
            volumeUserLabel = virtualVolume.getLabel() + " (" + virtualVolume.getDeviceLabel() + ")";
        }
        // Get the VPlex storage system
        StorageSystem vplexSystem = getDataObject(StorageSystem.class, vplexURI, _dbClient);
        _log.info("Got VPlex system");
        // Create a step to validate the volume and prevent migration if the
        // the ViPR DB does not properly reflect the actual backend volumes.
        // A successful migration will delete the backend source volumes. If
        // the ViPR DB does not correctly reflect the actual backend volume,
        // we could delete a backend volume used by some other VPLEX volume.
        waitFor = createWorkflowStepToValidateVPlexVolume(workflow, vplexSystem, virtualVolumeURI, waitFor);
        Map<URI, Volume> volumeMap = new HashMap<URI, Volume>();
        Map<URI, StorageSystem> storageSystemMap = new HashMap<URI, StorageSystem>();
        for (URI volumeURI : targetVolumeURIs) {
            Volume volume = getDataObject(Volume.class, volumeURI, _dbClient);
            volumeMap.put(volumeURI, volume);
            StorageSystem storageSystem = getDataObject(StorageSystem.class, volume.getStorageController(), _dbClient);
            storageSystemMap.put(volume.getStorageController(), storageSystem);
        }
        // Set the project and tenant.
        Volume firstVolume = volumeMap.values().iterator().next();
        Project vplexProject = VPlexUtil.lookupVplexProject(firstVolume, vplexSystem, _dbClient);
        URI tenantURI = vplexProject.getTenantOrg().getURI();
        _log.info("Project is {}, Tenant is {}", vplexProject.getId(), tenantURI);
        waitFor = createWorkflowStepsForBlockVolumeExport(workflow, vplexSystem, storageSystemMap, volumeMap, vplexProject.getId(), tenantURI, waitFor);
        _log.info("Created workflow steps for volume export.");
        // Now make a migration Step for each passed target to which data
        // for the passed virtual volume will be migrated. The migrations
        // will be done from this controller.
        Iterator<URI> targetVolumeIter = targetVolumeURIs.iterator();
        while (targetVolumeIter.hasNext()) {
            URI targetVolumeURI = targetVolumeIter.next();
            _log.info("Target volume is {}", targetVolumeURI);
            URI migrationURI = migrationsMap.get(targetVolumeURI);
            _log.info("Migration is {}", migrationURI);
            String stepId = workflow.createStepId();
            _log.info("Migration opId is {}", stepId);
            Workflow.Method vplexExecuteMethod = new Workflow.Method(MIGRATE_VIRTUAL_VOLUME_METHOD_NAME, vplexURI, virtualVolumeURI, targetVolumeURI, migrationURI, newVarrayURI);
            Workflow.Method vplexRollbackMethod = new Workflow.Method(RB_MIGRATE_VIRTUAL_VOLUME_METHOD_NAME, vplexURI, migrationURI, stepId);
            _log.info("Creating workflow migration step");
            workflow.createStep(MIGRATION_CREATE_STEP, String.format("VPlex %s migrating to target volume %s.", vplexSystem.getId().toString(), targetVolumeURI.toString()), waitFor, vplexSystem.getId(), vplexSystem.getSystemType(), getClass(), vplexExecuteMethod, vplexRollbackMethod, stepId);
            _log.info("Created workflow migration step");
        }
        // Once the migrations complete, we will commit the migrations.
        // So, now we create the steps to commit the migrations.
        String waitForStep = MIGRATION_CREATE_STEP;
        List<URI> migrationURIs = new ArrayList<URI>(migrationsMap.values());
        List<URI> migrationSources = new ArrayList<URI>();
        Iterator<URI> migrationsIter = migrationsMap.values().iterator();
        while (migrationsIter.hasNext()) {
            URI migrationURI = migrationsIter.next();
            _log.info("Migration is {}", migrationURI);
            Migration migration = getDataObject(Migration.class, migrationURI, _dbClient);
            // The migration source volume may be null for ingested volumes
            // for which we do not know anything about the backend volumes.
            // If we don't know the source, we know we are migrating an
            // ingested volume and we will not want to do any renaming
            // after the commit as we do when migration ViPR create volumes,
            // which adhere to a standard naming convention.
            Boolean rename = Boolean.TRUE;
            if (migration.getSource() != null) {
                migrationSources.add(migration.getSource());
            } else {
                rename = Boolean.FALSE;
            }
            _log.info("Added migration source {}", migration.getSource());
            String stepId = workflow.createStepId();
            _log.info("Commit operation id is {}", stepId);
            Workflow.Method vplexExecuteMethod = new Workflow.Method(COMMIT_MIGRATION_METHOD_NAME, vplexURI, virtualVolumeURI, migrationURI, rename, newVpoolURI, newVarrayURI);
            Workflow.Method vplexRollbackMethod = new Workflow.Method(RB_COMMIT_MIGRATION_METHOD_NAME, migrationURIs, newVpoolURI, newVarrayURI, stepId);
            _log.info("Creating workflow step to commit migration");
            String stepDescription = String.format("migration commit step on VPLEX %s of volume %s", vplexSystem.getSerialNumber(), volumeUserLabel);
            waitForStep = workflow.createStep(MIGRATION_COMMIT_STEP, stepDescription, waitForStep, vplexSystem.getId(), vplexSystem.getSystemType(), getClass(), vplexExecuteMethod, vplexRollbackMethod, suspendBeforeCommit, stepId);
            workflow.setSuspendedStepMessage(stepId, COMMIT_MIGRATION_SUSPEND_MESSAGE);
            _log.info("Created workflow step to commit migration");
        }
        // Create a step that creates a sub workflow to delete the old
        // migration source volumes, which are no longer used by the
        // virtual volume. We also update the virtual volume CoS. If
        // we make it to this step, then all migrations were committed.
        // We do this in a sub workflow because we don't won't to
        // initiate rollback regardless of success or failure.
        String stepId = workflow.createStepId();
        Workflow.Method vplexExecuteMethod = new Workflow.Method(DELETE_MIGRATION_SOURCES_METHOD, vplexURI, virtualVolumeURI, newVpoolURI, newVarrayURI, migrationSources);
        List<String> migrationSourceLabels = new ArrayList<>();
        Iterator<Volume> volumeIter = _dbClient.queryIterativeObjects(Volume.class, migrationSources);
        while (volumeIter.hasNext()) {
            migrationSourceLabels.add(volumeIter.next().getNativeGuid());
        }
        String stepDescription = String.format("post-migration delete of original source backing volumes [%s] associated with virtual volume %s", Joiner.on(',').join(migrationSourceLabels), volumeUserLabel);
        workflow.createStep(DELETE_MIGRATION_SOURCES_STEP, stepDescription, waitForStep, vplexSystem.getId(), vplexSystem.getSystemType(), getClass(), vplexExecuteMethod, null, suspendBeforeDeleteSource, stepId);
        workflow.setSuspendedStepMessage(stepId, DELETE_MIGRATION_SOURCES_SUSPEND_MESSAGE);
        _log.info("Created workflow step to create sub workflow for source deletion");
        return DELETE_MIGRATION_SOURCES_STEP;
    } catch (Exception e) {
        throw VPlexApiException.exceptions.addStepsForChangeVirtualPoolFailed(e);
    }
}
Also used : HashMap(java.util.HashMap) Migration(com.emc.storageos.db.client.model.Migration) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) 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) Volume(com.emc.storageos.db.client.model.Volume) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

Project (com.emc.storageos.db.client.model.Project)191 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)66 Volume (com.emc.storageos.db.client.model.Volume)58 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)55 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)35 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)33 Test (org.junit.Test)31 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)28 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)27 Operation (com.emc.storageos.db.client.model.Operation)27 Consumes (javax.ws.rs.Consumes)27