in polaris-synchronizer/api/src/main/java/org/apache/polaris/tools/sync/polaris/PolarisSynchronizer.java [97:190]
public void syncPrincipals() {
List<Principal> principalsSource;
try {
principalsSource = source.listPrincipals();
clientLogger.info("Listed {} principals from source.", principalsSource.size());
} catch (Exception e) {
if (haltOnFailure) throw e;
clientLogger.info("Failed to list principals from source.", e);
return;
}
List<Principal> principalsTarget;
try {
principalsTarget = target.listPrincipals();
clientLogger.info("Listed {} principals from target.", principalsTarget.size());
} catch (Exception e) {
if (haltOnFailure) throw e;
clientLogger.info("Failed to list principals from target.", e);
return;
}
SynchronizationPlan<Principal> principalSyncPlan =
syncPlanner.planPrincipalSync(principalsSource, principalsTarget);
principalSyncPlan
.entitiesToSkipAndSkipChildren()
.forEach(
principal ->
clientLogger.info("Skipping principal {}.", principal.getName()));
principalSyncPlan
.entitiesNotModified()
.forEach(
principal ->
clientLogger.info(
"No change detected for principal {}, skipping.",
principal.getName()));
int syncsCompleted = 0;
final int totalSyncsToComplete = totalSyncsToComplete(principalSyncPlan);
for (Principal principal : principalSyncPlan.entitiesToCreate()) {
try {
PrincipalWithCredentials createdPrincipal = target.createPrincipal(principal);
clientLogger.info("Created principal {} on target. Target credentials: {}:{} - {}/{}",
principal.getName(),
createdPrincipal.getCredentials().getClientId(),
createdPrincipal.getCredentials().getClientSecret(),
++syncsCompleted,
totalSyncsToComplete
);
} catch (Exception e) {
if (haltOnFailure) throw e;
clientLogger.error("Failed to create principal {} on target. - {}/{}",
principal.getName(), ++syncsCompleted, totalSyncsToComplete, e);
}
}
for (Principal principal : principalSyncPlan.entitiesToOverwrite()) {
try {
target.dropPrincipal(principal.getName());
PrincipalWithCredentials overwrittenPrincipal = target.createPrincipal(principal);
clientLogger.info("Overwrote principal {} on target. Target credentials: {}:{} - {}/{}",
principal.getName(),
overwrittenPrincipal.getCredentials().getClientId(),
overwrittenPrincipal.getCredentials().getClientSecret(),
++syncsCompleted,
totalSyncsToComplete
);
} catch (Exception e) {
if (haltOnFailure) throw e;
clientLogger.error("Failed to overwrite principal {} on target. - {}/{}",
principal.getName(), ++syncsCompleted, totalSyncsToComplete, e);
}
}
for (Principal principal : principalSyncPlan.entitiesToRemove()) {
try {
target.dropPrincipal(principal.getName());
clientLogger.info("Removed principal {} on target. - {}/{}",
principal.getName(), ++syncsCompleted, totalSyncsToComplete);
} catch (Exception e) {
if (haltOnFailure) throw e;
clientLogger.error("Failed to remove principal {} ont target. - {}/{}",
principal.getName(), ++syncsCompleted, totalSyncsToComplete, e);
}
}
for (Principal principal : principalSyncPlan.entitiesToSyncChildren()) {
syncAssignedPrincipalRolesForPrincipal(principal.getName());
}
}