use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.
the class CoordinatorBasicAuthorizerMetadataStorageUpdater method tryUpdateGroupMappingMap.
private boolean tryUpdateGroupMappingMap(String prefix, Map<String, BasicAuthorizerGroupMapping> groupMappingMap, byte[] oldGroupMappingMapValue, byte[] newGroupMappingMapValue) {
try {
List<MetadataCASUpdate> updates = new ArrayList<>();
if (groupMappingMap != null) {
updates.add(createMetadataCASUpdate(prefix, oldGroupMappingMapValue, newGroupMappingMapValue, GROUP_MAPPINGS));
boolean succeeded = connector.compareAndSwap(updates);
if (succeeded) {
cachedGroupMappingMaps.put(prefix, new BasicAuthorizerGroupMappingMapBundle(groupMappingMap, newGroupMappingMapValue));
byte[] serializedGroupMappingAndRoleMap = getCurrentGroupMappingAndRoleMapSerialized(prefix);
cacheNotifier.addUpdateGroupMapping(prefix, serializedGroupMappingAndRoleMap);
return true;
} else {
return false;
}
}
return false;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.
the class CoordinatorBasicAuthenticatorMetadataStorageUpdater method tryUpdateUserMap.
private boolean tryUpdateUserMap(String prefix, Map<String, BasicAuthenticatorUser> userMap, byte[] oldValue, byte[] newValue) {
try {
MetadataCASUpdate update = new MetadataCASUpdate(connectorConfig.getConfigTable(), MetadataStorageConnector.CONFIG_TABLE_KEY_COLUMN, MetadataStorageConnector.CONFIG_TABLE_VALUE_COLUMN, getPrefixedKeyColumn(prefix, USERS), oldValue, newValue);
boolean succeeded = connector.compareAndSwap(Collections.singletonList(update));
if (succeeded) {
cachedUserMaps.put(prefix, new BasicAuthenticatorUserMapBundle(userMap, newValue));
cacheNotifier.addUserUpdate(prefix, newValue);
return true;
} else {
return false;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.
the class CoordinatorBasicAuthorizerMetadataStorageUpdater method tryUpdateGroupMappingAndRoleMap.
private boolean tryUpdateGroupMappingAndRoleMap(String prefix, Map<String, BasicAuthorizerGroupMapping> groupMappingMap, byte[] oldGroupMappingMapValue, byte[] newGroupMappingMapValue, Map<String, BasicAuthorizerRole> roleMap, byte[] oldRoleMapValue, byte[] newRoleMapValue) {
try {
List<MetadataCASUpdate> updates = new ArrayList<>();
if (groupMappingMap != null && roleMap != null) {
updates.add(createMetadataCASUpdate(prefix, oldGroupMappingMapValue, newGroupMappingMapValue, GROUP_MAPPINGS));
updates.add(createMetadataCASUpdate(prefix, oldRoleMapValue, newRoleMapValue, ROLES));
}
boolean succeeded = connector.compareAndSwap(updates);
if (succeeded) {
cachedGroupMappingMaps.put(prefix, new BasicAuthorizerGroupMappingMapBundle(groupMappingMap, newGroupMappingMapValue));
cachedRoleMaps.put(prefix, new BasicAuthorizerRoleMapBundle(roleMap, newRoleMapValue));
byte[] serializedGroupMappingAndRoleMap = getCurrentGroupMappingAndRoleMapSerialized(prefix);
cacheNotifier.addUpdateGroupMapping(prefix, serializedGroupMappingAndRoleMap);
return true;
} else {
return false;
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.
the class CoordinatorBasicAuthorizerMetadataStorageUpdater method tryUpdateRoleMap.
private boolean tryUpdateRoleMap(String prefix, Map<String, BasicAuthorizerRole> roleMap, byte[] oldRoleMapValue, byte[] newRoleMapValue) {
try {
List<MetadataCASUpdate> updates = new ArrayList<>();
if (roleMap != null) {
updates.add(createMetadataCASUpdate(prefix, oldRoleMapValue, newRoleMapValue, ROLES));
boolean succeeded = connector.compareAndSwap(updates);
if (succeeded) {
cachedRoleMaps.put(prefix, new BasicAuthorizerRoleMapBundle(roleMap, newRoleMapValue));
byte[] serializedUserAndRoleMap = getCurrentUserAndRoleMapSerialized(prefix);
cacheNotifier.addUpdateUser(prefix, serializedUserAndRoleMap);
byte[] serializedGroupMappingAndRoleMap = getCurrentGroupMappingAndRoleMapSerialized(prefix);
cacheNotifier.addUpdateGroupMapping(prefix, serializedGroupMappingAndRoleMap);
return true;
} else {
return false;
}
}
return false;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.metadata.MetadataCASUpdate in project druid by druid-io.
the class CoordinatorBasicAuthorizerMetadataStorageUpdater method tryUpdateUserAndRoleMap.
private boolean tryUpdateUserAndRoleMap(String prefix, Map<String, BasicAuthorizerUser> userMap, byte[] oldUserMapValue, byte[] newUserMapValue, Map<String, BasicAuthorizerRole> roleMap, byte[] oldRoleMapValue, byte[] newRoleMapValue) {
try {
List<MetadataCASUpdate> updates = new ArrayList<>();
if (userMap != null && roleMap != null) {
updates.add(createMetadataCASUpdate(prefix, oldUserMapValue, newUserMapValue, USERS));
updates.add(createMetadataCASUpdate(prefix, oldRoleMapValue, newRoleMapValue, ROLES));
boolean succeeded = connector.compareAndSwap(updates);
if (succeeded) {
cachedUserMaps.put(prefix, new BasicAuthorizerUserMapBundle(userMap, newUserMapValue));
cachedRoleMaps.put(prefix, new BasicAuthorizerRoleMapBundle(roleMap, newRoleMapValue));
byte[] serializedUserAndRoleMap = getCurrentUserAndRoleMapSerialized(prefix);
cacheNotifier.addUpdateUser(prefix, serializedUserAndRoleMap);
return true;
} else {
return false;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
return false;
}
Aggregations