use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.UserAccessIdInfo in project ozone by apache.
the class TestOMMultiTenantManagerImpl method testListUsersInTenant.
@Test
public void testListUsersInTenant() throws Exception {
tenantManager.getCacheOp().assignUserToTenant("user1", TENANT_ID, "accessId1");
TenantUserList tenantUserList = tenantManager.listUsersInTenant(TENANT_ID, "");
List<UserAccessIdInfo> userAccessIds = tenantUserList.getUserAccessIds();
assertEquals(2, userAccessIds.size());
for (final UserAccessIdInfo userAccessId : userAccessIds) {
String user = userAccessId.getUserPrincipal();
if (user.equals("user1")) {
assertEquals("accessId1", userAccessId.getAccessId());
} else if (user.equals("seed-user1")) {
assertEquals("seed-accessId1", userAccessId.getAccessId());
} else {
Assert.fail();
}
}
LambdaTestUtils.intercept(IOException.class, "Tenant 'tenant2' not found", () -> {
tenantManager.listUsersInTenant("tenant2", null);
});
assertTrue(tenantManager.listUsersInTenant(TENANT_ID, "abc").getUserAccessIds().isEmpty());
}
use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.UserAccessIdInfo in project ozone by apache.
the class OMMultiTenantManagerImpl method listUsersInTenant.
@Override
public TenantUserList listUsersInTenant(String tenantID, String prefix) throws IOException {
List<UserAccessIdInfo> userAccessIds = new ArrayList<>();
tenantCacheLock.readLock().lock();
try {
if (!omMetadataManager.getTenantStateTable().isExist(tenantID)) {
throw new IOException("Tenant '" + tenantID + "' not found!");
}
CachedTenantState cachedTenantState = tenantCache.get(tenantID);
if (cachedTenantState == null) {
throw new IOException("Inconsistent in memory Tenant cache '" + tenantID + "' not found in cache, but present in OM DB!");
}
cachedTenantState.getAccessIdInfoMap().entrySet().stream().filter(// Include if user principal matches the prefix
k -> StringUtils.isEmpty(prefix) || k.getValue().getUserPrincipal().startsWith(prefix)).forEach(k -> {
final String accessId = k.getKey();
final CachedAccessIdInfo cacheEntry = k.getValue();
userAccessIds.add(UserAccessIdInfo.newBuilder().setUserPrincipal(cacheEntry.getUserPrincipal()).setAccessId(accessId).build());
});
} finally {
tenantCacheLock.readLock().unlock();
}
return new TenantUserList(userAccessIds);
}
Aggregations