Skip to content

Commit

Permalink
Merge pull request #585 from pdowler/master
Browse files Browse the repository at this point in the history
vault: lazy init of root node
  • Loading branch information
pdowler authored Jul 8, 2024
2 parents 78dfde7 + 9676bec commit 905fa47
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 44 deletions.
2 changes: 1 addition & 1 deletion vault/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# tags with and without build number so operators use the versioned
# tag but we always keep a timestamped tag in case a semantic tag gets
# replaced accidentally
VER=1.0.6
VER=1.0.7
TAGS="${VER} ${VER}-$(date -u +"%Y%m%dT%H%M%S")"
unset VER
112 changes: 69 additions & 43 deletions vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public class NodePersistenceImpl implements NodePersistence {
private final Map<String,Object> kpDaoConfig;
private final boolean singlePool;

private final ContainerNode root;
private ContainerNode root;
private final List<ContainerNode> allocationParents = new ArrayList<>();
private final Namespace storageNamespace;

Expand All @@ -187,52 +187,13 @@ public NodePersistenceImpl(URI resourceID, String appName) {
this.invDaoConfig = VaultInitAction.getInvConfig(config);
this.kpDaoConfig = VaultInitAction.getKeyPairConfig(config);
this.singlePool = nodeDaoConfig.get("jndiDataSourceName").equals(invDaoConfig.get("jndiDataSourceName"));
this.localGroupsOnly = false;

// root node
IdentityManager identityManager = AuthenticationUtil.getIdentityManager();
UUID rootID = new UUID(0L, 0L);
this.root = new ContainerNode(rootID, "");
root.owner = getRootOwner(config, identityManager);
root.ownerDisplay = identityManager.toDisplayString(root.owner);
log.info("ROOT owner: " + root.owner);
root.ownerID = identityManager.toOwner(root.owner);
root.isPublic = true;
root.inheritPermissions = false;

// allocations
for (String ap : VaultInitAction.getAllocationParents(config)) {
if (ap.isEmpty()) {
// allocations are in root
allocationParents.add(root);
log.info("allocationParent: /");
} else {
try {

// simple top-level names only
ContainerNode cn = (ContainerNode) get(root, ap);
String str = "";
if (cn == null) {
cn = new ContainerNode(ap);
cn.parent = root;
str = "created/";
}
cn.isPublic = true;
cn.owner = root.owner;
cn.inheritPermissions = false;
put(cn);
allocationParents.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);
}
}
}
initRootNode();

String ns = config.getFirstPropertyValue(VaultInitAction.STORAGE_NAMESPACE_KEY);
this.storageNamespace = new Namespace(ns);

this.localGroupsOnly = false;


String pnf = config.getFirstPropertyValue(VaultInitAction.PREVENT_NOT_FOUND_KEY);
if (pnf != null) {
this.preventNotFound = Boolean.valueOf(pnf);
Expand All @@ -252,6 +213,70 @@ private Subject getRootOwner(MultiValuedProperties mvp, IdentityManager im) {
return im.augment(ret);
}

private void initRootNode() {
if (root != null) {
return;
}

// 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);
}
}
}

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

}
}
}

@Override
public Views getViews() {
return new Views();
Expand Down Expand Up @@ -298,6 +323,7 @@ public URI getResourceID() {
*/
@Override
public ContainerNode getRootNode() {
initRootNode();
return root;
}

Expand Down

0 comments on commit 905fa47

Please sign in to comment.