Search in sources :

Example 26 with Project

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

the class BlockService method getVolumesForVirtualArrayChange.

/**
 * Get Volumes For Virtual Array Change
 *
 * @param projectURI
 * 			the URI of a ViPR project
 *
 * @param varrayURI
 * 			the URI of a ViPR vArray
 *
 * @brief Show potential volumes for virtual array change
 *
 * @return Get Volume for Virtual Array Change
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/varray-change")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public NamedVolumesList getVolumesForVirtualArrayChange(@QueryParam("project") URI projectURI, @QueryParam("targetVarray") URI varrayURI) {
    NamedVolumesList volumeList = new NamedVolumesList();
    // Get the project.
    ArgValidator.checkFieldUriType(projectURI, Project.class, "project");
    Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
    ArgValidator.checkEntity(project, projectURI, false);
    _log.info("Found project {}:{}", projectURI);
    // Verify the user is authorized for the project.
    BlockServiceUtils.verifyUserIsAuthorizedForRequest(project, getUserFromContext(), _permissionsHelper);
    _log.info("User is authorized for project");
    // Get the target virtual array.
    ArgValidator.checkFieldUriType(varrayURI, VirtualArray.class, "targetVarray");
    VirtualArray tgtVarray = _permissionsHelper.getObjectById(varrayURI, VirtualArray.class);
    ArgValidator.checkEntity(tgtVarray, varrayURI, false);
    _log.info("Found target virtual array {}:{}", tgtVarray.getLabel(), varrayURI);
    // Determine all volumes in the project that could potentially
    // be moved to the target virtual array.
    URIQueryResultList volumeIds = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(projectURI), volumeIds);
    Iterator<Volume> volumeItr = _dbClient.queryIterativeObjects(Volume.class, volumeIds);
    while (volumeItr.hasNext()) {
        Volume volume = volumeItr.next();
        try {
            // Don't operate on VPLEX backend, RP Journal volumes,
            // or other internal volumes.
            BlockServiceUtils.validateNotAnInternalBlockObject(volume, false);
            // Don't operate on ingested volumes.
            VolumeIngestionUtil.checkOperationSupportedOnIngestedVolume(volume, ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VARRAY, _dbClient);
            // Can't change to the same varray.
            if (volume.getVirtualArray().equals(varrayURI)) {
                _log.info("Virtual array change not supported for volume {} already in the target varray", volume.getId());
                continue;
            }
            // Get the appropriate block service implementation.
            BlockServiceApi blockServiceAPI = getBlockServiceImpl(volume);
            // Verify that the virtual array change is allowed for the
            // volume and target virtual array.
            blockServiceAPI.verifyVarrayChangeSupportedForVolumeAndVarray(volume, tgtVarray);
            // If so, add it to the list.
            volumeList.getVolumes().add(toNamedRelatedResource(volume));
        } catch (Exception e) {
            _log.info("Virtual array change not supported for volume {}:{}", volume.getId(), e.getMessage());
        }
    }
    return volumeList;
}
Also used : Project(com.emc.storageos.db.client.model.Project) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) NamedVolumesList(com.emc.storageos.model.block.NamedVolumesList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) ServiceCodeException(com.emc.storageos.svcs.errorhandling.resources.ServiceCodeException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) SOURCE_TO_TARGET(com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 27 with Project

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

the class BlockSnapshotService method getTenantOwner.

@Override
protected URI getTenantOwner(URI id) {
    BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
    URI projectUri = snapshot.getProject().getURI();
    ArgValidator.checkUri(projectUri);
    Project project = _permissionsHelper.getObjectById(projectUri, Project.class);
    ArgValidator.checkEntityNotNull(project, projectUri, isIdEmbeddedInURL(projectUri));
    return project.getTenantOrg().getURI();
}
Also used : Project(com.emc.storageos.db.client.model.Project) MapBlockSnapshot(com.emc.storageos.api.mapper.functions.MapBlockSnapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 28 with Project

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

the class BucketService method createBucket.

/**
 * Creates bucket.
 *
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param param Bucket parameters
 * @param id the URN of a ViPR Project
 * @brief Create bucket
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep createBucket(BucketParam param, @QueryParam("project") URI id) throws InternalException {
    // check project
    ArgValidator.checkFieldUriType(id, Project.class, "project");
    // Check for all mandatory field
    ArgValidator.checkFieldNotNull(param.getLabel(), "name");
    Project project = _permissionsHelper.getObjectById(id, Project.class);
    ArgValidator.checkEntity(project, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldNotNull(project.getTenantOrg(), "project");
    TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
    final String namespace = tenant.getNamespace();
    if (null == namespace || namespace.isEmpty()) {
        throw APIException.badRequests.objNoNamespaceForTenant(tenant.getId());
    }
    // Check if there already exist a bucket with same name in a Project.
    checkForDuplicateName(param.getLabel().replaceAll(SPECIAL_CHAR_REGEX, ""), Bucket.class, id, "project", _dbClient);
    return initiateBucketCreation(param, project, tenant, null);
}
Also used : Project(com.emc.storageos.db.client.model.Project) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 29 with Project

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

the class ExportGroupService method validateInitiatorsData.

/**
 * Validates that the host belongs to same tenant org and/or project as the export group.
 * Also validates that the host has connectivity to all the storage systems that the
 * export group has block objects in.
 *
 * @param host the host being validated
 * @param exportGroup the export group where the host will be added
 * @param storageSystems the storage systems the export group has block objects in.
 * @param project the export group project
 * @param initiators the list of initiators to be updated with the host initiators.
 */
private void validateInitiatorsData(List<Initiator> initiators, Set<URI> initiatorsHosts, ExportGroup exportGroup) {
    if (initiatorsHosts.size() != 1) {
        throw APIException.badRequests.initiatorExportGroupInitiatorsBelongToSameHost();
    }
    Host host = queryObject(Host.class, initiatorsHosts.iterator().next(), true);
    // if the host is in a project
    if (!NullColumnValueGetter.isNullURI(host.getProject())) {
        // validate it is in the same project as the as the export group,
        if (!host.getProject().equals(exportGroup.getProject().getURI())) {
            throw APIException.badRequests.invalidParameterExportGroupHostAssignedToDifferentProject(host.getHostName(), exportGroup.getProject().getName());
        }
    } else {
        // validate the host is in the same tenant Org as the as the export group,
        Project project = queryObject(Project.class, exportGroup.getProject().getURI(), true);
        if (!host.getTenant().equals(project.getTenantOrg().getURI())) {
            throw APIException.badRequests.invalidParameterExportGroupHostAssignedToDifferentTenant(host.getHostName(), project.getLabel());
        }
    }
    validatePortConnectivity(exportGroup, initiators);
    _log.info("The initiators were validated successfully.");
}
Also used : Project(com.emc.storageos.db.client.model.Project) Host(com.emc.storageos.db.client.model.Host)

Example 30 with Project

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

the class FilePolicyService method assignFilePolicyToProjects.

/**
 * Assign policy at project level
 *
 * @param param
 * @param filepolicy
 */
private TaskResourceRep assignFilePolicyToProjects(FilePolicyAssignParam param, FilePolicy filePolicy) {
    StringBuilder errorMsg = new StringBuilder();
    StringBuilder recommendationErrorMsg = new StringBuilder();
    ArgValidator.checkFieldNotNull(param.getProjectAssignParams(), "project_assign_param");
    ArgValidator.checkFieldUriType(param.getProjectAssignParams().getVpool(), VirtualPool.class, "vpool");
    URI vpoolURI = param.getProjectAssignParams().getVpool();
    VirtualPool vpool = null;
    if (NullColumnValueGetter.isNullURI(filePolicy.getFilePolicyVpool())) {
        ArgValidator.checkFieldUriType(vpoolURI, VirtualPool.class, "vpool");
        vpool = _permissionsHelper.getObjectById(vpoolURI, VirtualPool.class);
        ArgValidator.checkEntity(vpool, vpoolURI, false);
        // Check if the vpool supports provided policy type..
        FilePolicyServiceUtils.validateVpoolSupportPolicyType(filePolicy, vpool);
        // Check if the vpool supports policy at project level..
        if (!vpool.getAllowFilePolicyAtProjectLevel()) {
            errorMsg.append("Provided vpool :" + vpool.getLabel() + " doesn't support policy at project level");
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
    } else if (vpoolURI != null) {
        vpool = _dbClient.queryObject(VirtualPool.class, filePolicy.getFilePolicyVpool());
        if (!vpoolURI.equals(filePolicy.getFilePolicyVpool())) {
            errorMsg.append("File policy: " + filePolicy.getFilePolicyName() + " is already assigned at project level under the vpool: " + vpool.getLabel());
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
    }
    ArgValidator.checkFieldNotEmpty(param.getProjectAssignParams().getAssigntoProjects(), "assign_to_projects");
    Set<URI> projectURIs = param.getProjectAssignParams().getAssigntoProjects();
    List<URI> filteredProjectURIs = new ArrayList<URI>();
    for (URI projectURI : projectURIs) {
        ArgValidator.checkFieldUriType(projectURI, Project.class, "project");
        Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
        ArgValidator.checkEntity(project, projectURI, false);
        if (filePolicy.getAssignedResources() != null && filePolicy.getAssignedResources().contains(project.getId().toString())) {
            _log.info("Policy {} is already assigned to project {} ", filePolicy.getFilePolicyName(), project.getLabel());
            continue;
        }
        // only single replication policy per vpool-project combination.
        if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && FilePolicyServiceUtils.projectHasReplicationPolicy(_dbClient, projectURI, vpool.getId())) {
            errorMsg.append("Virtual pool " + vpool.getLabel() + " project " + project.getLabel() + "pair is already assigned with replication policy.");
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
        if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_snapshot.name()) && FilePolicyServiceUtils.projectHasSnapshotPolicyWithSameSchedule(_dbClient, projectURI, vpool.getId(), filePolicy)) {
            errorMsg.append("Snapshot policy with similar schedule is already present on project " + project.getLabel());
            _log.error(errorMsg.toString());
            throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
        }
        filteredProjectURIs.add(projectURI);
    }
    if (param.getApplyOnTargetSite() != null) {
        filePolicy.setApplyOnTargetSite(param.getApplyOnTargetSite());
    }
    // Verify the virtual pool has storage pools!!!
    List<URI> storageSystems = getAssociatedStorageSystemsByVPool(vpool);
    if (storageSystems == null || storageSystems.isEmpty()) {
        String errorMessage = "No matching storage pools exists for given vpools ";
        _log.error(errorMessage);
        throw APIException.badRequests.noStoragePoolsExists(vpool.getLabel());
    }
    String task = UUID.randomUUID().toString();
    TaskResourceRep taskResponse = createAssignFilePolicyTask(filePolicy, task);
    FileServiceApi fileServiceApi = getDefaultFileServiceApi();
    FilePolicyType policyType = FilePolicyType.valueOf(filePolicy.getFilePolicyType());
    switch(policyType) {
        case file_snapshot:
            Map<URI, List<URI>> vpoolToStorageSystemMap = new HashMap<URI, List<URI>>();
            vpoolToStorageSystemMap.put(vpoolURI, getAssociatedStorageSystemsByVPool(vpool));
            AssignFileSnapshotPolicyToProjectSchedulingThread.executeApiTask(this, _asyncTaskService.getExecutorService(), _dbClient, filePolicy.getId(), vpoolToStorageSystemMap, filteredProjectURIs, fileServiceApi, taskResponse, task);
            break;
        case file_replication:
            if (filteredProjectURIs.isEmpty()) {
                throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), "No projects to assign to policy.");
            }
            // update replication topology info
            updateFileReplicationTopologyInfo(param, filePolicy);
            List<URI> validRecommendationProjects = new ArrayList<URI>();
            List<FileStorageSystemAssociation> associations = new ArrayList<FileStorageSystemAssociation>();
            VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
            StringSet sourceVArraysSet = getSourceVArraySet(vpool, filePolicy);
            updatePolicyCapabilities(_dbClient, sourceVArraysSet, vpool, filePolicy, capabilities, errorMsg);
            // Replication policy has to be created on each applicable source storage system!!
            if (storageSystems != null && !storageSystems.isEmpty()) {
                for (Iterator<String> iterator = sourceVArraysSet.iterator(); iterator.hasNext(); ) {
                    String vArrayURI = iterator.next();
                    for (URI projectURI : filteredProjectURIs) {
                        List<FileStorageSystemAssociation> projectAssociations = new ArrayList<FileStorageSystemAssociation>();
                        Project project = _dbClient.queryObject(Project.class, projectURI);
                        VirtualArray srcVarray = _dbClient.queryObject(VirtualArray.class, URI.create(vArrayURI));
                        for (URI storageSystem : storageSystems) {
                            capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_PROTECTION_SOURCE_STORAGE_SYSTEM, storageSystem);
                            try {
                                List<FileRecommendation> newRecs = _filePlacementManager.getRecommendationsForFileCreateRequest(srcVarray, project, vpool, capabilities);
                                if (newRecs != null && !newRecs.isEmpty()) {
                                    projectAssociations.addAll(convertRecommendationsToStorageSystemAssociations(newRecs, filePolicy.getApplyAt(), vpool.getId(), projectURI));
                                }
                            } catch (Exception ex) {
                                _log.error("No recommendations found for storage system {} and virtualArray {} with error {} ", storageSystem, srcVarray.getLabel(), ex.getMessage());
                                if (ex.getMessage() != null) {
                                    recommendationErrorMsg.append(ex.getMessage());
                                }
                                // Continue to get the recommedations for next storage system!!
                                continue;
                            }
                        }
                        if (!projectAssociations.isEmpty()) {
                            associations.addAll(projectAssociations);
                            validRecommendationProjects.add(projectURI);
                        }
                    }
                }
            } else {
                String errorMessage = "No matching storage pools exists for vpool " + vpool.getLabel();
                _log.error(errorMessage);
                recommendationErrorMsg.append(errorMessage);
            }
            // Throw an exception!!
            if (associations == null || associations.isEmpty()) {
                // If no other resources are assigned to replication policy
                // Remove the replication topology from the policy
                FileOrchestrationUtils.removeTopologyInfo(filePolicy, _dbClient);
                _log.error("No matching storage pools recommendations found for policy {} with due to {}", filePolicy.getFilePolicyName(), recommendationErrorMsg.toString());
                throw APIException.badRequests.noFileStorageRecommendationsFound(filePolicy.getFilePolicyName());
            }
            fileServiceApi.assignFileReplicationPolicyToProjects(associations, vpoolURI, validRecommendationProjects, filePolicy.getId(), task);
            break;
        default:
            break;
    }
    auditOp(OperationTypeEnum.ASSIGN_FILE_POLICY, true, AuditLogManager.AUDITOP_BEGIN, filePolicy.getLabel());
    if (taskResponse != null) {
        // As the action done by system admin
        // Set system uri as task's tenant!!!
        Task taskObj = _dbClient.queryObject(Task.class, taskResponse.getId());
        StorageOSUser user = getUserFromContext();
        URI userTenantUri = URI.create(user.getTenantId());
        FilePolicyServiceUtils.updateTaskTenant(_dbClient, filePolicy, "assign", taskObj, userTenantUri);
    }
    return taskResponse;
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) FileStorageSystemAssociation(com.emc.storageos.fileorchestrationcontroller.FileStorageSystemAssociation) FilePolicyType(com.emc.storageos.db.client.model.FilePolicy.FilePolicyType) FileRecommendation(com.emc.storageos.api.service.impl.placement.FileRecommendation) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Project(com.emc.storageos.db.client.model.Project)

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