Skip to content

Commit

Permalink
vault: synchronize root not initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
pdowler committed Jun 24, 2024
1 parent e1f1258 commit 9676bec
Showing 1 changed file with 53 additions and 44 deletions.
97 changes: 53 additions & 44 deletions vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,54 +217,63 @@ private void initRootNode() {
if (root != null) {
return;
}
try {
MultiValuedProperties config = VaultInitAction.getConfig();
IdentityManager identityManager = AuthenticationUtil.getIdentityManager();
UUID rootID = new UUID(0L, 0L);
ContainerNode rn = new ContainerNode(rootID, "");
rn.owner = getRootOwner(config, identityManager);
rn.ownerDisplay = identityManager.toDisplayString(rn.owner);
log.info("ROOT owner: " + rn.owner);
rn.ownerID = identityManager.toOwner(rn.owner);
rn.isPublic = true;
rn.inheritPermissions = false;

// allocations
List<ContainerNode> aps = new ArrayList<>();
for (String ap : VaultInitAction.getAllocationParents(config)) {
if (ap.isEmpty()) {
// allocations are in root
aps.add(rn);
log.info("allocationParent: /");
} else {
try {

// simple top-level names only
ContainerNode cn = (ContainerNode) get(rn, ap);
String str = "";
if (cn == null) {
cn = new ContainerNode(ap);
cn.parent = rn;
cn.isPublic = true;
cn.inheritPermissions = false;
cn.owner = rn.owner;
str = "created/";
put(cn);

// if the init from VaultInitAction failed, this could be called by multiple threads in parallel
// so let's not make a mess of the state
synchronized (this) {
// recheck
if (root != null) {
return;
}
try {
MultiValuedProperties config = VaultInitAction.getConfig();
IdentityManager identityManager = AuthenticationUtil.getIdentityManager();
UUID rootID = new UUID(0L, 0L);
ContainerNode rn = new ContainerNode(rootID, "");
rn.owner = getRootOwner(config, identityManager);
rn.ownerDisplay = identityManager.toDisplayString(rn.owner);
log.info("ROOT owner: " + rn.owner);
rn.ownerID = identityManager.toOwner(rn.owner);
rn.isPublic = true;
rn.inheritPermissions = false;

// allocations
List<ContainerNode> aps = new ArrayList<>();
for (String ap : VaultInitAction.getAllocationParents(config)) {
if (ap.isEmpty()) {
// allocations are in root
aps.add(rn);
log.info("allocationParent: /");
} else {
try {

// simple top-level names only
ContainerNode cn = (ContainerNode) get(rn, ap);
String str = "";
if (cn == null) {
cn = new ContainerNode(ap);
cn.parent = rn;
cn.isPublic = true;
cn.inheritPermissions = false;
cn.owner = rn.owner;
str = "created/";
put(cn);
}
aps.add(cn);
log.info(str + "loaded allocationParent: /" + cn.getName());
} catch (NodeNotSupportedException bug) {
throw new RuntimeException("BUG: failed to update isPublic=true on allocationParent " + ap, bug);
}
aps.add(cn);
log.info(str + "loaded allocationParent: /" + cn.getName());
} catch (NodeNotSupportedException bug) {
throw new RuntimeException("BUG: failed to update isPublic=true on allocationParent " + ap, bug);
}
}
}

// success
this.root = rn;
this.allocationParents.addAll(aps);
} catch (Exception ex) {
log.error("failed to init ROOT ContainerNode", ex);

// success
this.root = rn;
this.allocationParents.addAll(aps);
} catch (Exception ex) {
log.error("failed to init ROOT ContainerNode", ex);

}
}
}

Expand Down

0 comments on commit 9676bec

Please sign in to comment.