Search in sources :

Example 21 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class DbStatRetrieverTest method xmlStatEmptyTimeBucketArgumentTest.

@Test
public void xmlStatEmptyTimeBucketArgumentTest() throws WebApplicationException, IOException, JAXBException {
    deleteIfExists(XmlTestOutputFile);
    DummyDBClient dbClient = new DummyDBClient();
    MeteringService statResource = new MeteringService();
    statResource.setDbClient(dbClient);
    DummyHttpHeaders header = new DummyHttpHeaders(MediaType.APPLICATION_XML_TYPE);
    try {
        statResource.getStats("", header);
        Assert.fail("Expected a BadRequestException");
    } catch (BadRequestException e) {
        Assert.assertEquals(ServiceCode.API_PARAMETER_INVALID_TIME_FORMAT, e.getServiceCode());
    }
}
Also used : DummyHttpHeaders(com.emc.storageos.api.service.utils.DummyHttpHeaders) MeteringService(com.emc.storageos.api.service.impl.resource.MeteringService) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DummyDBClient(com.emc.storageos.api.service.utils.DummyDBClient) Test(org.junit.Test)

Example 22 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class SRDFBlockServiceApiImpl method prepareRecommendedVolumes.

/**
 * Prepare Recommended Volumes for SRDF scenarios only.
 *
 * This method is responsible for acting the same as the unprotected "prepareRecommendedVolumes"
 * call, however it needs to create multiple volumes per single volume requests in order to
 * generate SRDF protection.
 *
 * Those most typical scenario is, that for any one volume requested in an SRDF configuration,
 * we create: 1. One Source Volume 3. One Target Volume on target varrays
 *
 * @param param
 *            volume create request
 * @param task
 *            task from request or generated
 * @param taskList
 *            task list
 * @param project
 *            project from request
 * @param varray
 *            varray from request
 * @param vpool
 *            vpool from request
 * @param volumeCount
 *            volume count from the request
 * @param recommendations
 *            list of resulting recommendations from placement
 * @param consistencyGroup
 *            consistency group ID
 * @return list of volume URIs created
 */
private List<URI> prepareRecommendedVolumes(final String task, final TaskList taskList, final Project project, final VirtualArray varray, final VirtualPool vpool, final Integer volumeCount, final List<Recommendation> recommendations, final BlockConsistencyGroup consistencyGroup, final String volumeLabel, final String size) {
    List<URI> volumeURIs = new ArrayList<URI>();
    try {
        // Create an entire Protection object for each recommendation result.
        Iterator<Recommendation> recommendationsIter = recommendations.iterator();
        while (recommendationsIter.hasNext()) {
            SRDFRecommendation recommendation = (SRDFRecommendation) recommendationsIter.next();
            // until we (later) fix creating volumes while in SWAPPED state.
            for (SRDFRecommendation.Target target : recommendation.getVirtualArrayTargetMap().values()) {
                if (target != null && SRDFScheduler.rdfGroupHasSwappedVolumes(_dbClient, project.getId(), target.getSourceRAGroup())) {
                    RemoteDirectorGroup rdg = _dbClient.queryObject(RemoteDirectorGroup.class, target.getSourceRAGroup());
                    throw BadRequestException.badRequests.cannotAddVolumesToSwappedReplicationGroup(rdg.getLabel());
                }
            }
            StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, recommendation.getSourceStorageSystem());
            // operation for each volume to be created.
            for (int i = 0; i < volumeCount; i++) {
                // get generated volume name
                String newVolumeLabel = generateDefaultVolumeLabel(volumeLabel, i, volumeCount);
                // Grab the existing volume and task object from the incoming task list
                Volume srcVolume = StorageScheduler.getPrecreatedVolume(_dbClient, taskList, newVolumeLabel);
                boolean volumePrecreated = false;
                if (srcVolume != null) {
                    volumePrecreated = true;
                }
                // number of targets.
                if (recommendation.getVpoolChangeVolume() == null) {
                    srcVolume = prepareVolume(srcVolume, project, varray, vpool, size, recommendation, newVolumeLabel, consistencyGroup, task, false, Volume.PersonalityTypes.SOURCE, null, null, null);
                    volumeURIs.add(srcVolume.getId());
                    if (!volumePrecreated) {
                        taskList.getTaskList().add(toTask(srcVolume, task));
                    }
                } else {
                    srcVolume = _dbClient.queryObject(Volume.class, recommendation.getVpoolChangeVolume());
                    Operation op = _dbClient.createTaskOpStatus(Volume.class, srcVolume.getId(), task, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
                    // Fill in additional information that prepare would've filled in that's specific to SRDF.
                    // Best to only fill in information here that isn't harmful if a rollback occurred,
                    // and the protection never got set up.
                    volumeURIs.add(srcVolume.getId());
                    taskList.getTaskList().add(toTask(srcVolume, task, op));
                }
                // Remove "-source" designation in the label if found
                if (newVolumeLabel.contains("-source")) {
                    newVolumeLabel = newVolumeLabel.replaceAll("-source", "");
                }
                Map<URI, VpoolRemoteCopyProtectionSettings> settingMap = VirtualPool.getRemoteProtectionSettings(vpool, _dbClient);
                for (VirtualArray protectionVirtualArray : SRDFScheduler.getTargetVirtualArraysForVirtualPool(project, vpool, _dbClient, _permissionsHelper)) {
                    VpoolRemoteCopyProtectionSettings settings = settingMap.get(protectionVirtualArray.getId());
                    // COP-16363 Create target BCG in controllersvc
                    // Prepare and populate CG request for the SRDF targets
                    volumeURIs.addAll(prepareTargetVolumes(project, vpool, recommendation, new StringBuilder(newVolumeLabel), protectionVirtualArray, settings, srcVolume, task, taskList, size));
                }
            }
        }
    } catch (InternalException e) {
        _log.error("Rolling back the created CGs if any.");
        throw e;
    } catch (BadRequestException e) {
        _log.info("Bad request exception: " + e.getMessage());
        throw e;
    } catch (Exception e) {
        _log.error("Rolling back the created CGs if any.");
        throw APIException.badRequests.srdfInternalError(e);
    }
    return volumeURIs;
}
Also used : VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) MetaVolumeRecommendation(com.emc.storageos.volumecontroller.impl.smis.MetaVolumeRecommendation) SRDFCopyRecommendation(com.emc.storageos.volumecontroller.SRDFCopyRecommendation) Recommendation(com.emc.storageos.volumecontroller.Recommendation) SRDFRecommendation(com.emc.storageos.volumecontroller.SRDFRecommendation) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) SRDFRecommendation(com.emc.storageos.volumecontroller.SRDFRecommendation) Volume(com.emc.storageos.db.client.model.Volume) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) RemoteDirectorGroup(com.emc.storageos.db.client.model.RemoteDirectorGroup) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 23 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class FileService method createContinuousCopies.

/**
 * Create Continuous Copies
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param param
 *            File Replication Create parameter
 * @brief Define continuous copies
 * @return TaskResponse
 * @throws InternalException
 * @throws APIException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/create")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep createContinuousCopies(@PathParam("id") URI id, FileReplicationCreateParam param) throws InternalException, APIException {
    _log.info("Request to create replication copies for filesystem {}", id);
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    FileShare orgFs = queryResource(id);
    String task = UUID.randomUUID().toString();
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    TaskList taskList = new TaskList();
    // Make sure that we don't have some pending
    // operation against the file system!!!
    checkForPendingTasks(Arrays.asList(fs.getTenant().getURI()), Arrays.asList(fs));
    // Get the project.
    URI projectURI = fs.getProject().getURI();
    Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
    ArgValidator.checkEntity(project, projectURI, false);
    _log.info("Found filesystem project {}", projectURI);
    VirtualPool currentVpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    StringBuffer notSuppReasonBuff = new StringBuffer();
    // Verify the file system and its vPool are capable of doing replication!!!
    if (!FileSystemReplicationUtils.isSupportedFileReplicationCreate(fs, currentVpool, notSuppReasonBuff)) {
        _log.error("create mirror copies is not supported for file system {} due to {}", fs.getId().toString(), notSuppReasonBuff.toString());
        throw APIException.badRequests.unableToCreateMirrorCopies(fs.getId(), notSuppReasonBuff.toString());
    }
    // Get the virtual array!!!
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, fs.getVirtualArray());
    // New operation
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_MIRROR_COPIES);
    op.setDescription("Create file system mirror operation");
    op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, op);
    TaskResourceRep fileSystemTask = toTask(fs, task, op);
    taskList.getTaskList().add(fileSystemTask);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    // prepare vpool capability values
    VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
    capabilities.put(VirtualPoolCapabilityValuesWrapper.SIZE, fs.getCapacity());
    capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, new Integer(1));
    if (VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(currentVpool.getSupportedProvisioningType())) {
        capabilities.put(VirtualPoolCapabilityValuesWrapper.THIN_PROVISIONING, Boolean.TRUE);
    }
    // Set the source file system details
    // source fs details used in finding recommendations for target fs!!
    capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_SYSTEM_CREATE_MIRROR_COPY, Boolean.TRUE);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.EXISTING_SOURCE_FILE_SYSTEM, fs);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.SOURCE_STORAGE_SYSTEM, device);
    StringBuilder errorMsg = new StringBuilder();
    if (!FilePolicyServiceUtils.updatePolicyCapabilities(_dbClient, varray, currentVpool, project, null, capabilities, errorMsg)) {
        _log.error("File system can not be created, ", errorMsg.toString());
        throw APIException.badRequests.unableToProcessRequest(errorMsg.toString());
    }
    if (param.getCopyName() != null && !param.getCopyName().isEmpty()) {
        // No need to generate any name -- Since the requirement is to use the customizing label we should use the
        // same.
        // Stripping out the special characters like ; /-+!@#$%^&())";:[]{}\ | but allow underscore character _
        String convertedName = param.getCopyName().replaceAll("[^\\dA-Za-z\\_]", "");
        _log.info("Original copy name {} and converted copy name {}", param.getCopyName(), convertedName);
        capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_TARGET_COPY_NAME, convertedName);
    }
    FileServiceApi fileServiceApi = getFileShareServiceImpl(capabilities, _dbClient);
    try {
        // Call out placementManager to get the recommendation for placement.
        List recommendations = _filePlacementManager.getRecommendationsForFileCreateRequest(varray, project, currentVpool, capabilities);
        // Verify the source virtual pool recommendations meets source fs storage!!!
        fileServiceApi.createTargetsForExistingSource(fs, project, currentVpool, varray, taskList, task, recommendations, capabilities);
    } catch (BadRequestException e) {
        // Revert the file system to original state!!!
        restoreFromOriginalFs(orgFs, fs);
        _dbClient.updateObject(fs);
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Create file system mirror copy failed {}, {}", e.getMessage(), e);
        throw e;
    } catch (InternalException e) {
        // Revert the file system to original state!!!
        restoreFromOriginalFs(orgFs, fs);
        _dbClient.updateObject(fs);
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Create file system mirror copy failed {}, {}", e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        _log.error("Create file system mirror copy failed  {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    auditOp(OperationTypeEnum.CREATE_MIRROR_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getLabel(), currentVpool.getLabel(), fs.getLabel(), project == null ? null : project.getId().toString());
    return taskList.getTaskList().get(0);
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) 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) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) FilePolicyList(com.emc.storageos.model.file.FilePolicyList) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) QuotaDirectoryList(com.emc.storageos.model.file.QuotaDirectoryList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) FileSystemShareList(com.emc.storageos.model.file.FileSystemShareList) List(java.util.List) FileSystemExportList(com.emc.storageos.model.file.FileSystemExportList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) MirrorList(com.emc.storageos.model.block.MirrorList) SnapshotList(com.emc.storageos.model.SnapshotList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 24 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class FileService method assignFileReplicationPolicyToFS.

private TaskResourceRep assignFileReplicationPolicyToFS(FileShare fs, FilePolicy filePolicy, FilePolicyFileSystemAssignParam param, String task) {
    StringBuffer notSuppReasonBuff = new StringBuffer();
    // Verify the fs has replication attributes!!!
    if (fs.getPersonality() != null && PersonalityTypes.SOURCE.name().equalsIgnoreCase(fs.getPersonality()) && fs.getMirrorfsTargets() != null && !fs.getMirrorfsTargets().isEmpty()) {
        notSuppReasonBuff.append(String.format("File system %s has active target file systems", fs.getLabel()));
        _log.error(notSuppReasonBuff.toString());
        throw APIException.badRequests.unableToProcessRequest(notSuppReasonBuff.toString());
    }
    // File system should not be the target file system..
    if (fs.getPersonality() != null && fs.getPersonality().equalsIgnoreCase(PersonalityTypes.TARGET.name())) {
        notSuppReasonBuff.append(String.format("File system - %s given in request is an active Target file system.", fs.getLabel()));
        _log.error(notSuppReasonBuff.toString());
        throw APIException.badRequests.unableToProcessRequest(notSuppReasonBuff.toString());
    }
    ArgValidator.checkFieldNotNull(param.getTargetVArrays(), "target_varrays");
    Set<URI> targertVarrayURIs = param.getTargetVArrays();
    for (URI targertVarrayURI : targertVarrayURIs) {
        ArgValidator.checkFieldUriType(targertVarrayURI, VirtualArray.class, "target_varray");
        VirtualArray targetVarray = _permissionsHelper.getObjectById(targertVarrayURI, VirtualArray.class);
        ArgValidator.checkEntity(targetVarray, targertVarrayURI, false);
    }
    VirtualArray sourceVarray = _dbClient.queryObject(VirtualArray.class, fs.getVirtualArray());
    // Get the project.
    URI projectURI = fs.getProject().getURI();
    Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    // New operation
    TaskList taskList = new TaskList();
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.ASSIGN_FILE_POLICY_TO_FILE_SYSTEM);
    op.setDescription("assign file policy to file system");
    // As the action done by tenant admin
    // Set current tenant as task's tenant!!!
    Task taskObj = op.getTask(fs.getId());
    FilePolicyServiceUtils.updateTaskTenant(_dbClient, filePolicy, "assign", taskObj, fs.getTenant().getURI());
    TaskResourceRep fileShareTask = toTask(fs, task, op);
    taskList.getTaskList().add(fileShareTask);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    // prepare vpool capability values
    VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
    capabilities.put(VirtualPoolCapabilityValuesWrapper.SIZE, fs.getCapacity());
    capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, new Integer(1));
    if (VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vpool.getSupportedProvisioningType())) {
        capabilities.put(VirtualPoolCapabilityValuesWrapper.THIN_PROVISIONING, Boolean.TRUE);
    }
    // Set the source file system details
    // source fs details used in finding recommendations for target fs!!
    capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_SYSTEM_CREATE_MIRROR_COPY, Boolean.TRUE);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.EXISTING_SOURCE_FILE_SYSTEM, fs);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.SOURCE_STORAGE_SYSTEM, device);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TYPE, filePolicy.getFileReplicationType());
    capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_COPY_MODE, filePolicy.getFileReplicationCopyMode());
    Set<String> targetVArrys = new HashSet<String>();
    if (filePolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
        for (URI targertVarrayURI : targertVarrayURIs) {
            targetVArrys.add(targertVarrayURI.toString());
        }
    } else {
        targetVArrys.add(sourceVarray.getId().toString());
    }
    URI targetvPool = null;
    // Get the existing topologies for the policy
    if (filePolicy.getReplicationTopologies() != null && !filePolicy.getReplicationTopologies().isEmpty()) {
        for (String strTopology : filePolicy.getReplicationTopologies()) {
            FileReplicationTopology dbTopology = _dbClient.queryObject(FileReplicationTopology.class, URI.create(strTopology));
            Set<String> dbTargetVArrys = new HashSet<String>();
            if (dbTopology != null && sourceVarray.getId().toString().equalsIgnoreCase(dbTopology.getSourceVArray().toString())) {
                dbTargetVArrys.addAll(dbTopology.getTargetVArrays());
                if (dbTargetVArrys.containsAll(targetVArrys)) {
                    // which are created from older release remote replication vpool
                    for (String targetVarray : targetVArrys) {
                        if (dbTopology.getTargetVAVPool() != null && !dbTopology.getTargetVAVPool().isEmpty()) {
                            String[] vavPool = dbTopology.getTargetVAVPool().split(SEPARATOR);
                            if (vavPool != null && vavPool.length > 1 && targetVarray.equalsIgnoreCase(vavPool[0])) {
                                String strvPool = vavPool[1];
                                VirtualPool vPool = _dbClient.queryObject(VirtualPool.class, URI.create(strvPool));
                                if (vPool != null && !vPool.getInactive()) {
                                    targetvPool = vPool.getId();
                                }
                            }
                        }
                    }
                }
                break;
            }
        }
    }
    capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VARRAYS, targetVArrys);
    if (targetvPool != null) {
        capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VPOOL, targetvPool);
    } else {
        capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VPOOL, vpool.getId());
    }
    FileServiceApi fileServiceApi = getFileShareServiceImpl(capabilities, _dbClient);
    try {
        // Call out placementManager to get the recommendation for placement.
        List recommendations = _filePlacementManager.getRecommendationsForFileCreateRequest(sourceVarray, project, vpool, capabilities);
        fileServiceApi.assignFilePolicyToFileSystem(fs, filePolicy, project, vpool, sourceVarray, taskList, task, recommendations, capabilities);
    } catch (BadRequestException e) {
        _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Error Assigning Filesystem policy {}, {}", e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        _log.error("Error Assigning Filesystem policy  {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return fileShareTask;
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) 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) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Project(com.emc.storageos.db.client.model.Project) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) FilePolicyList(com.emc.storageos.model.file.FilePolicyList) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) QuotaDirectoryList(com.emc.storageos.model.file.QuotaDirectoryList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) FileSystemShareList(com.emc.storageos.model.file.FileSystemShareList) List(java.util.List) FileSystemExportList(com.emc.storageos.model.file.FileSystemExportList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) MirrorList(com.emc.storageos.model.block.MirrorList) SnapshotList(com.emc.storageos.model.SnapshotList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology)

Example 25 with BadRequestException

use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.

the class FileService method assignFilePolicyToFS.

private TaskResourceRep assignFilePolicyToFS(FileShare fs, FilePolicy filePolicy, String task) {
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.ASSIGN_FILE_POLICY_TO_FILE_SYSTEM);
    op.setDescription("assign file policy to file system");
    // As the action done by tenant admin
    // Set current tenant as task's tenant!!!
    Task taskObj = op.getTask(fs.getId());
    FilePolicyServiceUtils.updateTaskTenant(_dbClient, filePolicy, "assign", taskObj, fs.getTenant().getURI());
    try {
        _log.info("No Errors found proceeding further {}, {}, {}", new Object[] { _dbClient, fs, filePolicy });
        List<FileDescriptor> fileDescriptors = new ArrayList<>();
        FileDescriptor desc = new FileDescriptor(Type.FILE_EXISTING_SOURCE, fs.getId());
        fileDescriptors.add(desc);
        controller.assignFilePolicyToFileSystem(filePolicy, fileDescriptors, task);
        auditOp(OperationTypeEnum.ASSIGN_FILE_POLICY, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), filePolicy.getId());
    } catch (BadRequestException e) {
        _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Error Assigning Filesystem policy {}, {}", e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        _log.error("Error Assigning Filesystem policy {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return toTask(fs, task, op);
}
Also used : TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task) FileOrchestrationController(com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController) ArrayList(java.util.ArrayList) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) FileDescriptor(com.emc.storageos.fileorchestrationcontroller.FileDescriptor) 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) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)30 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)15 Operation (com.emc.storageos.db.client.model.Operation)14 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)13 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)13 URISyntaxException (java.net.URISyntaxException)13 FileShare (com.emc.storageos.db.client.model.FileShare)12 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)11 ControllerException (com.emc.storageos.volumecontroller.ControllerException)11 Path (javax.ws.rs.Path)11 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)10 Test (org.junit.Test)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 Produces (javax.ws.rs.Produces)8 NamedURI (com.emc.storageos.db.client.model.NamedURI)7 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)7 Consumes (javax.ws.rs.Consumes)7