Skip to content

Commit

Permalink
pool: 'queue' admin commands not the log stack-trace on bad arguments
Browse files Browse the repository at this point in the history
Motivation:

Fix following stack-trace:

16 Aug 2018 11:39:05 (dcache-xfel04-08) [admin] Command failed due to a bug, please contact support@dcache.org.
dmg.util.CommandPanicException: (1) Command failed: java.lang.IllegalArgumentException: Storage class not found : xfel:FXE-2018@osm
        at org.dcache.util.cli.AnnotatedCommandExecutor.execute(AnnotatedCommandExecutor.java:156) ~[common-cli-4.0.5.jar:4.0.5]
        at dmg.cells.nucleus.CellAdapter.executeCommand(CellAdapter.java:238) ~[cells-4.0.5.jar:4.0.5]
        at org.dcache.cells.UniversalSpringCell.executeCommand(UniversalSpringCell.java:195) ~[dcache-core-4.0.5.jar:4.0.5]
        at dmg.cells.nucleus.CellAdapter$1.doExecute(CellAdapter.java:104) ~[cells-4.0.5.jar:4.0.5]
        at org.dcache.util.cli.CommandInterpreter.command(CommandInterpreter.java:129) ~[common-cli-4.0.5.jar:4.0.5]
        at dmg.cells.nucleus.CellAdapter$1.command(CellAdapter.java:121) ~[cells-4.0.5.jar:4.0.5]
        at dmg.cells.nucleus.CellAdapter.command(CellAdapter.java:223) ~[cells-4.0.5.jar:4.0.5]
        at dmg.cells.nucleus.CellAdapter.executeLocalCommand(CellAdapter.java:915) ~[cells-4.0.5.jar:4.0.5]
        at dmg.cells.nucleus.CellAdapter.messageArrived(CellAdapter.java:855) ~[cells-4.0.5.jar:4.0.5]
        at dmg.cells.nucleus.CellNucleus$DeliverMessageTask.run(CellNucleus.java:1218) [cells-4.0.5.jar:4.0.5]
        at org.dcache.util.BoundedExecutor$Worker.run(BoundedExecutor.java:251) [dcache-common-4.0.5.jar:4.0.5]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_162]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_162]
        at dmg.cells.nucleus.CellNucleus.lambda$wrapLoggingContext$4(CellNucleus.java:754) [cells-4.0.5.jar:4.0.5]
        at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_162]
Caused by: java.lang.IllegalArgumentException: Storage class not found : xfel:FXE-2018@osm
        at org.dcache.pool.classic.StorageClassContainer.suspendStorageClass(StorageClassContainer.java:138) ~[dcache-core-4.0.5.jar:4.0.5]
        at org.dcache.pool.classic.StorageClassContainer.access$400(StorageClassContainer.java:49) ~[dcache-core-4.0.5.jar:4.0.5]
        at org.dcache.pool.classic.StorageClassContainer$ResumeQueueCommand.call(StorageClassContainer.java:519) ~[dcache-core-4.0.5.jar:4.0.5]
        at org.dcache.pool.classic.StorageClassContainer$ResumeQueueCommand.call(StorageClassContainer.java:503) ~[dcache-core-4.0.5.jar:4.0.5]
        at org.dcache.util.cli.AnnotatedCommandExecutor.execute(AnnotatedCommandExecutor.java:145) ~[common-cli-4.0.5.jar:4.0.5]
        ... 14 common frames omitted

Modification:

Don't use a RuntimeException to report bad input, but a
CommandException.  This is reported back without logging a stack-trace.

Result:

Bad admin input for the following admin commands no longer results in a
stack-trace being logged:

    queue activate
    queue activate class
    queue remove class
    queue suspend class
    queue resume class
    queue remove pnfsid

Target: master
Require-notes: yes
Require-book: no
Request: 4.2
Request: 4.1
Request: 4.0
Request: 3.2
Patch: https://rb.dcache.org/r/11112/
Acked-by: Tigran Mkrtchyan
  • Loading branch information
paulmillar committed Aug 20, 2018
1 parent 7eca970 commit 81f9ce5
Showing 1 changed file with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@
import diskCacheV111.util.CacheException;
import diskCacheV111.util.FileNotInCacheException;
import diskCacheV111.util.PnfsId;

import dmg.cells.nucleus.CellCommandListener;
import dmg.cells.nucleus.CellInfoProvider;
import dmg.cells.nucleus.CellSetupProvider;
import dmg.util.CommandException;
import dmg.util.Formats;
import dmg.util.command.Argument;
import dmg.util.command.Command;
import dmg.util.command.Option;

import org.dcache.pool.PoolDataBeanProvider;
import org.dcache.pool.classic.json.HSMFlushQManagerData;
import org.dcache.pool.nearline.NearlineStorageHandler;
import org.dcache.pool.repository.CacheEntry;
import org.dcache.pool.repository.Repository;
import org.dcache.vehicles.FileAttributes;
import org.dcache.pool.classic.json.HSMFlushQManagerData;

import static java.util.stream.Collectors.partitioningBy;
import static java.util.stream.Collectors.toCollection;
Expand Down Expand Up @@ -118,24 +121,24 @@ StorageClassInfo defineStorageClass(String hsmName, String storageClass)
return info;
}

private synchronized
void removeStorageClass(String hsmName, String storageClass)
private synchronized void removeStorageClass(String hsmName, String storageClass)
throws CommandException
{
StorageClassInfo info = getStorageClassInfo(hsmName, storageClass);
if (info != null) {
if (info.size() > 0) {
throw new IllegalArgumentException("Class not empty");
throw new CommandException(1, "Class not empty");
}
_storageClasses.remove(info.getFullName());
}
}

private synchronized
void suspendStorageClass(String hsmName, String storageClass, boolean suspend)
private synchronized void suspendStorageClass(String hsmName,
String storageClass, boolean suspend) throws CommandException
{
StorageClassInfo info = getStorageClassInfo(hsmName, storageClass);
if (info == null) {
throw new IllegalArgumentException("Storage class not found : " + storageClass + "@" + hsmName);
throw new CommandException(1, "Storage class not found : " + storageClass + "@" + hsmName);
}
info.setSuspended(suspend);
}
Expand Down Expand Up @@ -304,11 +307,11 @@ class ActivateFileCommand implements Callable<String>
PnfsId pnfsId;

@Override
public String call() throws IllegalArgumentException, CacheException
public String call() throws CommandException, CacheException
{
StorageClassInfo info = getStorageClassInfo(pnfsId);
if (info == null) {
throw new IllegalArgumentException("Not found : " + pnfsId);
throw new CommandException(1, "Not found : " + pnfsId);
}
info.activate(pnfsId);
return "";
Expand All @@ -323,18 +326,18 @@ class ActivateClassCommand implements Callable<String>
String className;

@Override
public String call() throws IllegalArgumentException, NoSuchElementException
public String call() throws CommandException, NoSuchElementException
{
int pos = className.indexOf('@');
if (pos <= 0 || pos + 1 == className.length()) {
throw new IllegalArgumentException("Illegal storage class syntax : class@hsm");
throw new CommandException(1, "Illegal storage class syntax : class@hsm");
}
StorageClassInfo classInfo =
getStorageClassInfo(
className.substring(pos + 1),
className.substring(0, pos));
if (classInfo == null) {
throw new IllegalArgumentException("No such storage class: " + className);
throw new CommandException(1, "No such storage class: " + className);
}
classInfo.activateAll();
return "";
Expand All @@ -349,11 +352,11 @@ class DeactivateFileCommand implements Callable<String>
PnfsId pnfsId;

@Override
public String call() throws IllegalArgumentException, CacheException
public String call() throws CommandException, CacheException
{
StorageClassInfo info = getStorageClassInfo(pnfsId);
if (info == null) {
throw new IllegalArgumentException("Not found : " + pnfsId);
throw new CommandException(1, "Not found : " + pnfsId);
}
info.deactivate(pnfsId);
return "";
Expand Down Expand Up @@ -471,7 +474,7 @@ class RemoveQueueCommand implements Callable<String>
String storageClass;

@Override
public String call()
public String call() throws CommandException
{
removeStorageClass(hsm.toLowerCase(), storageClass);
return "";
Expand All @@ -489,7 +492,7 @@ class SuspendQueueCommand implements Callable<String>
String storageClass;

@Override
public String call()
public String call() throws CommandException
{
if (hsm.equals("*")) {
suspendStorageClasses(true);
Expand All @@ -511,7 +514,7 @@ class ResumeQueueCommand implements Callable<String>
String storageClass;

@Override
public String call()
public String call() throws CommandException
{
if (hsm.equals("*")) {
suspendStorageClasses(false);
Expand Down Expand Up @@ -576,10 +579,10 @@ class RemoveFileCommand implements Callable<String>
PnfsId pnfsId;

@Override
public String call()
public String call() throws CommandException
{
if (!removeCacheEntry(pnfsId)) {
throw new IllegalArgumentException("Not found : " + pnfsId);
throw new CommandException(1, "Not found : " + pnfsId);
}
return "Removed : " + pnfsId;
}
Expand Down

0 comments on commit 81f9ce5

Please sign in to comment.