Search in sources :

Example 81 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class SchedulePolicyService method deleteSchedulePolicy.

/**
 * Delete schedule policy from CoprHD DB.
 *
 * @param policyId the URN of a schedule policy
 * @brief Delete schedule policy from CoprHD DB
 * @return No data returned in response body
 * @throws BadRequestException
 */
@DELETE
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN })
public Response deleteSchedulePolicy(@PathParam("id") URI policyId) {
    ArgValidator.checkFieldUriType(policyId, SchedulePolicy.class, "policyId");
    SchedulePolicy schedulePolicy = getPolicyById(policyId, true);
    ArgValidator.checkReference(SchedulePolicy.class, policyId, checkForDelete(schedulePolicy));
    // Check policy is associated with FS before delete
    StringSet resources = schedulePolicy.getAssignedResources();
    if (resources != null && !resources.isEmpty()) {
        _log.error("Unable to delete schedule policy {} as it is already associated with resources", schedulePolicy.getPolicyName());
        throw APIException.badRequests.unableToDeleteSchedulePolicy(schedulePolicy.getPolicyName());
    }
    _dbClient.markForDeletion(schedulePolicy);
    _log.info("Schedule policy {} deleted successfully", schedulePolicy.getPolicyName());
    return Response.ok().build();
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) MapSchedulePolicy(com.emc.storageos.api.mapper.functions.MapSchedulePolicy) SchedulePolicy(com.emc.storageos.db.client.model.SchedulePolicy) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 82 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class StoragePoolService method getStoragePools.

/**
 * Gets the ids and self links for all storage pools.
 *
 * @brief List storage pools
 * @return A StoragePoolList reference specifying the ids and self links for
 *         the storage pools.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StoragePoolList getStoragePools() {
    StoragePoolList storagePools = new StoragePoolList();
    List<URI> ids = _dbClient.queryByType(StoragePool.class, true);
    for (URI id : ids) {
        StoragePool storagePool = _dbClient.queryObject(StoragePool.class, id);
        if (storagePool != null) {
            storagePools.getPools().add(toNamedRelatedResource(storagePool, storagePool.getNativeGuid()));
        }
    }
    return storagePools;
}
Also used : StoragePoolList(com.emc.storageos.model.pools.StoragePoolList) StoragePool(com.emc.storageos.db.client.model.StoragePool) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 83 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class StoragePoolService method getStorageTiers.

/**
 * Get Storage tiers associated with given Pool
 * Vmax pools, only one tier will be present always
 * Vnx pools can have multiple tiers.
 *
 * @param id the URN of a ViPR storage pool.
 *
 * @brief List storage pool storage tiers
 * @return A StorageTierList reference specifying the data for the
 *         storage tier with the passed id.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-tiers")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StorageTierList getStorageTiers(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, StoragePool.class, "id");
    StoragePool storagePool = queryRegisteredResource(id);
    ArgValidator.checkEntity(storagePool, id, isIdEmbeddedInURL(id));
    if (storagePool.getTiers() == null) {
        throw APIException.badRequests.invalidParameterStoragePoolHasNoTiers(id);
    }
    StorageTierList storageTierList = new StorageTierList();
    for (String tierUri : storagePool.getTiers()) {
        StorageTier tier = _dbClient.queryObject(StorageTier.class, URI.create(tierUri));
        if (null != tier) {
            storageTierList.getStorageTiers().add(toNamedRelatedResource(tier, tier.getNativeGuid()));
        }
    }
    return storageTierList;
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) StorageTier(com.emc.storageos.db.client.model.StorageTier) StorageTierList(com.emc.storageos.model.block.tier.StorageTierList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 84 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class StoragePoolService method getStoragePool.

/**
 * Gets the data for a storage pool.
 *
 * @param id the URN of a ViPR storage pool.
 *
 * @brief Show storage pool
 * @return A StoragePoolRestRep reference specifying the data for the
 *         storage pool with the passed id.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StoragePoolRestRep getStoragePool(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, StoragePool.class, "id");
    StoragePool storagePool = queryResource(id);
    ArgValidator.checkEntity(storagePool, id, isIdEmbeddedInURL(id));
    StoragePoolRestRep restRep = toStoragePoolRep(storagePool, _dbClient, _coordinator);
    restRep.setNumResources(getNumResources(storagePool, _dbClient));
    return restRep;
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) StoragePoolRestRep(com.emc.storageos.model.pools.StoragePoolRestRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 85 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class StoragePoolService method updateStoragePool.

/**
 * This API call only allows user to update virtual array & virtual pool
 * assignments for the registered storage pool.
 * <p>
 * A pool can be associated with a virtual array either implicitly or explicitly. A pool is implicitly associated with a virtual array
 * when the pool's storage system has one or more ports in the virtual array (see {@link StoragePool#getConnectedVirtualArrays()}). the
 * pool's implicit virtual arrays are the union of all the tagged virtual arrays of the storage array ports. This implicit association
 * cannot be changed or removed, it can only be overridden by an explicit assignment (see {@link StoragePool#getAssignedVirtualArrays()}
 * ). A pool's effective virtual array association is {@link StoragePool#getTaggedVirtualArrays()})
 * <p>
 * Managing pools associated virtual arrays requires planning. In general, pools should be assigned to virtual arrays only when it is
 * desired to limit the virtual arrays where they can be used.
 *
 * @param id the URN of a ViPR storage pool.
 * @param storagePoolUpdates Specifies the updates to be made to the storage
 *            pool.
 *
 * @brief Update storage pool
 * @return A StoragePoolRestRep specifying the updated storage pool info.
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StoragePoolRestRep updateStoragePool(@PathParam("id") URI id, StoragePoolUpdate storagePoolUpdates) {
    // Get the storage pool with the passed id.
    ArgValidator.checkFieldUriType(id, StoragePool.class, "id");
    StoragePool storagePool = queryRegisteredResource(id);
    ArgValidator.checkEntity(storagePool, id, isIdEmbeddedInURL(id));
    boolean neighborhoodChange = false;
    // the storage pool.
    if (storagePoolUpdates.getVarrayChanges() != null) {
        VirtualArrayAssignments addedNH = storagePoolUpdates.getVarrayChanges().getAdd();
        if ((addedNH != null) && (!addedNH.getVarrays().isEmpty())) {
            VirtualArrayService.checkVirtualArrayURIs(addedNH.getVarrays(), _dbClient);
            storagePool.addAssignedVirtualArrays(addedNH.getVarrays());
        }
        // Validate that the neighborhoods to be unassigned from the storage
        // pool reference existing neighborhoods in the database and remove
        // them from the storage pool.
        VirtualArrayAssignments removedNH = storagePoolUpdates.getVarrayChanges().getRemove();
        if ((removedNH != null) && (!removedNH.getVarrays().isEmpty())) {
            VirtualArrayService.checkVirtualArrayURIs(removedNH.getVarrays(), _dbClient);
            storagePool.removeAssignedVirtualArrays(removedNH.getVarrays());
        }
        verifyPoolNoInUseInVarrays(storagePool);
        neighborhoodChange = true;
    }
    // for all VirtualPool.
    if (neighborhoodChange) {
        StringBuffer errorMessage = new StringBuffer();
        ImplicitPoolMatcher.matchModifiedStoragePoolsWithAllVirtualPool(Arrays.asList(storagePool), _dbClient, _coordinator, errorMessage);
    }
    Integer currentMaxSubscriptionPercentFromArray = storagePool.getMaxThinPoolSubscriptionPercentageFromArray();
    _logger.info(String.format("Current maximum subscription percent in storage pool from array : %s ", currentMaxSubscriptionPercentFromArray));
    if (null != storagePoolUpdates.getMaxPoolUtilizationPercentage()) {
        if (storagePoolUpdates.getMaxPoolUtilizationPercentage() < 0 || storagePoolUpdates.getMaxPoolUtilizationPercentage() > 100) {
            throw APIException.badRequests.invalidParameterPercentageExpected("max_pool_utilization_percentage", storagePoolUpdates.getMaxPoolUtilizationPercentage());
        }
        // check that a new value does not exceed array limit
        if (currentMaxSubscriptionPercentFromArray != null && storagePoolUpdates.getMaxPoolUtilizationPercentage() > currentMaxSubscriptionPercentFromArray) {
            throw APIException.badRequests.invalidParameterValueExceedsArrayLimit("max_pool_utilization_percentage", storagePoolUpdates.getMaxPoolUtilizationPercentage(), currentMaxSubscriptionPercentFromArray);
        }
        storagePool.setMaxPoolUtilizationPercentage(storagePoolUpdates.getMaxPoolUtilizationPercentage());
    }
    if (null != storagePoolUpdates.getMaxThinPoolSubscriptionPercentage()) {
        ArgValidator.checkFieldMinimum(storagePoolUpdates.getMaxThinPoolSubscriptionPercentage(), 0, "max_thin_pool_subscription_percentage");
        if (!validateMaxThinPoolSubscriptionInput(storagePool, storagePoolUpdates.getMaxThinPoolSubscriptionPercentage())) {
            throw APIException.badRequests.parameterIsOnlyApplicableTo("max_thin_pool_subscription_percentage", "Thin Pool");
        }
        // check that a new value does not exceed array limit
        if (currentMaxSubscriptionPercentFromArray != null && storagePoolUpdates.getMaxThinPoolSubscriptionPercentage() > currentMaxSubscriptionPercentFromArray) {
            throw APIException.badRequests.invalidParameterValueExceedsArrayLimit("max_thin_pool_subscription_percentage", storagePoolUpdates.getMaxThinPoolSubscriptionPercentage(), currentMaxSubscriptionPercentFromArray);
        }
        storagePool.setMaxThinPoolSubscriptionPercentage(storagePoolUpdates.getMaxThinPoolSubscriptionPercentage());
    }
    // If unlimited resources is set to false, then max resources should also be specified. If not specified, throw error
    if (null != storagePoolUpdates.getIsUnlimitedResourcesSet()) {
        if (storagePoolUpdates.getIsUnlimitedResourcesSet()) {
            storagePool.setIsResourceLimitSet(false);
        } else {
            if (null != storagePoolUpdates.getMaxResources()) {
                storagePool.setIsResourceLimitSet(true);
                storagePool.setMaxResources(storagePoolUpdates.getMaxResources());
            } else {
                throw APIException.badRequests.parameterMaxResourcesMissing();
            }
        }
    } else if (null != storagePoolUpdates.getMaxResources()) {
        storagePool.setMaxResources(storagePoolUpdates.getMaxResources());
        storagePool.setIsResourceLimitSet(true);
    }
    // Persist the changes and return a successful response.
    _dbClient.updateAndReindexObject(storagePool);
    // Record the storage pool update event.
    recordStoragePoolEvent(OperationTypeEnum.STORAGE_POOL_UPDATE, STORAGEPOOL_UPDATED_DESCRIPTION, storagePool.getId());
    auditOp(OperationTypeEnum.UPDATE_STORAGE_POOL, true, null, id.toString());
    return toStoragePoolRep(storagePool, _dbClient, _coordinator);
}
Also used : BigInteger(java.math.BigInteger) StoragePool(com.emc.storageos.db.client.model.StoragePool) VirtualArrayAssignments(com.emc.storageos.model.pools.VirtualArrayAssignments) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

CheckPermission (com.emc.storageos.security.authorization.CheckPermission)566 Produces (javax.ws.rs.Produces)512 Path (javax.ws.rs.Path)487 POST (javax.ws.rs.POST)240 Consumes (javax.ws.rs.Consumes)215 GET (javax.ws.rs.GET)194 URI (java.net.URI)185 Operation (com.emc.storageos.db.client.model.Operation)105 ArrayList (java.util.ArrayList)97 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)93 PUT (javax.ws.rs.PUT)85 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)69 Volume (com.emc.storageos.db.client.model.Volume)68 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)65 TaskList (com.emc.storageos.model.TaskList)61 FileShare (com.emc.storageos.db.client.model.FileShare)56 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)54 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)53 NamedURI (com.emc.storageos.db.client.model.NamedURI)47 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)46