DBService implements RolesProvider { void executeDeleteQuota(ResourceContext ctx, String domainName, String auditRef, String caller) { for (int retryCount = defaultRetryCount; ; retryCount--) { try (ObjectStoreConnection con = store.getConnection(true, true)) { if (!con.deleteQuota(domainName)) { throw ZMSUtils.notFoundError(caller + ": unable to delete quota: " + domainName, caller); } auditLogRequest(ctx, domainName, auditRef, caller, ZMSConsts.HTTP_DELETE, domainName, null); return; } catch (ResourceException ex) { if (!shouldRetryOperation(ex, retryCount)) { throw ex; } } } } DBService(ObjectStore store, AuditLogger auditLogger, ZMSConfig zmsConfig, AuditReferenceValidator auditReferenceValidator); DomainRoleMembers listOverdueReviewRoleMembers(String domainName); @Override List<Role> getRolesByDomain(String domain); ResourceAccessList getResourceAccessList(String principal, String action); AthenzDomain getAthenzDomain(final String domainName, boolean masterCopy); Quota getQuota(String domainName); void executePutRoleSystemMeta(ResourceContext ctx, final String domainName, final String roleName,
           RoleSystemMeta meta, final String attribute, final String auditRef, final String caller); void executePutGroupSystemMeta(ResourceContext ctx, final String domainName, final String groupName,
                                          GroupSystemMeta meta, final String attribute, final String auditRef); void executePutServiceIdentitySystemMeta(ResourceContext ctx, String domainName, String serviceName,
            ServiceIdentitySystemMeta meta, String attribute, String auditRef, String caller); void executePutRoleMeta(ResourceContext ctx, String domainName, String roleName, Role originalRole,
                                   RoleMeta meta, String auditRef, String caller); void executePutGroupMeta(ResourceContext ctx, final String domainName, final String groupName,
                                    GroupMeta meta, final String auditRef); Set<String> getPendingMembershipApproverRoles(int delayDays); Set<String> getPendingGroupMembershipApproverRoles(int delayDays); Map<String, DomainRoleMember> getRoleExpiryMembers(int delayDays); Map<String, DomainRoleMember> getRoleReviewMembers(int delayDays); Map<String, DomainGroupMember> getGroupExpiryMembers(int delayDays); void processExpiredPendingMembers(int pendingRoleMemberLifespan, final String monitorIdentity); void processExpiredPendingGroupMembers(int pendingGroupMemberLifespan, final String monitorIdentity); static int AUDIT_TYPE_ROLE; static int AUDIT_TYPE_POLICY; static int AUDIT_TYPE_SERVICE; static int AUDIT_TYPE_DOMAIN; static int AUDIT_TYPE_ENTITY; static int AUDIT_TYPE_TENANCY; static int AUDIT_TYPE_TEMPLATE; static int AUDIT_TYPE_GROUP; }
@Test public void testExecuteDeleteQuotaFailureRetry() { String domainName = "putquota"; Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn); Mockito.when(mockJdbcConn.deleteQuota(domainName)) .thenThrow(new ResourceException(ResourceException.CONFLICT, "conflict")); ObjectStore saveStore = zms.dbService.store; zms.dbService.store = mockObjStore; int saveRetryCount = zms.dbService.defaultRetryCount; zms.dbService.defaultRetryCount = 2; try { zms.dbService.executeDeleteQuota(mockDomRsrcCtx, domainName, auditRef, "deleteQuota"); fail(); } catch (ResourceException ex) { assertEquals(ResourceException.CONFLICT, ex.getCode()); } zms.dbService.defaultRetryCount = saveRetryCount; zms.dbService.store = saveStore; }
@Test public void testExecuteDeleteQuota() { String domainName = "executedeletequota"; TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser); zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1); Quota quota = new Quota().setName(domainName) .setAssertion(10).setEntity(11) .setPolicy(12).setPublicKey(13) .setRole(14).setRoleMember(15) .setService(16).setServiceHost(17) .setSubdomain(18).setGroupMember(19).setGroup(20); zms.dbService.executePutQuota(mockDomRsrcCtx, domainName, quota, auditRef, "testExecuteDeleteQuota"); Quota quotaCheck = zms.getQuota(mockDomRsrcCtx, domainName); assertNotNull(quotaCheck); assertEquals(domainName, quotaCheck.getName()); assertEquals(quotaCheck.getAssertion(), 10); assertEquals(quotaCheck.getRole(), 14); assertEquals(quotaCheck.getPolicy(), 12); zms.dbService.executeDeleteQuota(mockDomRsrcCtx, domainName, auditRef, "testExecuteDeleteQuota"); quotaCheck = zms.getQuota(mockDomRsrcCtx, domainName); assertEquals("server-default", quotaCheck.getName()); assertEquals(quotaCheck.getAssertion(), 100); assertEquals(quotaCheck.getRole(), 1000); assertEquals(quotaCheck.getPolicy(), 1000); zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef); }
@Test public void testExecuteDeleteQuotaException() { String domainName = "executedeletequotaexception"; try { zms.dbService.executeDeleteQuota(mockDomRsrcCtx, domainName, auditRef, "testExecuteDeleteQuota"); fail(); } catch (ResourceException ignored) { } }