Skip to content

Commit

Permalink
dcache-spacemanager: fix NPE when link-group-file-name is not set
Browse files Browse the repository at this point in the history
Motivation:
Modification:
Result:
Fixes NPE that occurs on startup of space manager when `spacemanager.authz.link-group-file-name` is not set.

Target: master
Request: 8.2
Fixes: #6817
Requires-notes: yes
Requires-book: no
Patch: https://rb.dcache.org/r/13703/
Acked-by: Albert Rossi
  • Loading branch information
lemora committed Oct 10, 2022
1 parent b41eca3 commit 12b41e0
Showing 1 changed file with 16 additions and 10 deletions.
Expand Up @@ -10,9 +10,9 @@
import dmg.util.command.DelayedCommand;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.Collection;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -40,7 +40,7 @@ public class LinkGroupLoader

private long updateLinkGroupsPeriod;

private ParsableFile<Map<String,LinkGroupAuthorizationRecord>> authorizationFile;
private Optional<ParsableFile<Map<String, LinkGroupAuthorizationRecord>>> authorizationFile;
private long latestUpdateTime = System.currentTimeMillis();

private RemotePoolMonitor poolMonitor;
Expand All @@ -65,9 +65,13 @@ public void setPoolMonitor(RemotePoolMonitor poolMonitor) {

@Required
public void setAuthorizationFileName(Path authorizationFileName) {
authorizationFile = new ParsableFile(
new LineByLineParser(LinkGroupAuthorizationFileParser::new),
authorizationFileName);
if (authorizationFileName == null) {
authorizationFile = Optional.empty();
return;
}
authorizationFile = Optional.of(new ParsableFile(
new LineByLineParser(LinkGroupAuthorizationFileParser::new),
authorizationFileName));
}

public long getLatestUpdateTime() {
Expand All @@ -92,7 +96,8 @@ public void stop() {
@Override
public void getInfo(PrintWriter printWriter) {
printWriter.append("updateLinkGroupsPeriod = ").println(updateLinkGroupsPeriod);
printWriter.append("authorizationFileName = ").println(authorizationFile.getPath());
printWriter.append("authorizationFileName = ")
.println(authorizationFile.isPresent() ? authorizationFile.get().getPath() : "-");
}

@Override
Expand Down Expand Up @@ -139,10 +144,11 @@ private void saveLinkGroup(long currentTime, PoolLinkGroupInfo info)
boolean replicaAllowed = info.isReplicaAllowed();
boolean outputAllowed = info.isOutputAllowed();
boolean custodialAllowed = info.isCustodialAllowed();
VOInfo[] vos = authorizationFile.get().getSuccess()
.flatMap(f -> Optional.ofNullable(f.get(linkGroupName)))
.map(LinkGroupAuthorizationRecord::getVOInfoArray)
.orElse(null);
VOInfo[] vos = authorizationFile.isEmpty() ? null :
authorizationFile.get().get().getSuccess()
.flatMap(f -> Optional.ofNullable(f.get(linkGroupName)))
.map(LinkGroupAuthorizationRecord::getVOInfoArray)
.orElse(null);

while (true) {
try {
Expand Down

0 comments on commit 12b41e0

Please sign in to comment.