Skip to content

Commit

Permalink
ssh2 admin: Add history size
Browse files Browse the repository at this point in the history
User complained that history size is harcoded.

No it is configurable.

Release Notes:

The admin shell allows to set the maximun history size in number of lines in the history file. This can
be setting the property admin.history.size to an integer number > 0.

Ticket: 8877
Acked-by:
Target: master
Require-book: yes
Require-notes: yes
Patch: http://rb.dcache.org/r/<id>/
  • Loading branch information
Christian Bernardt committed Jan 28, 2016
1 parent 715f69b commit 5a34e31
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class AnsiTerminalCommand implements Command, Runnable {

private static final Logger _logger =
LoggerFactory.getLogger(AnsiTerminalCommand.class);
private static final int HISTORY_SIZE = 50;
private UserAdminShell _userAdminShell;
private ExitCallback _exitCallback;
private InputStream _in;
Expand All @@ -68,14 +67,14 @@ public class AnsiTerminalCommand implements Command, Runnable {
private PipedInputStream _pipedIn;
private Thread _pipeThread;

public AnsiTerminalCommand(File historyFile, boolean useColor, UserAdminShell shell)
public AnsiTerminalCommand(File historyFile, int historySize, boolean useColor, UserAdminShell shell)
{
_useColors = useColor;
_userAdminShell = shell;
if (historyFile != null && (!historyFile.exists() || historyFile.isFile())) {
try {
_history = new FileHistory(historyFile);
_history.setMaxSize(HISTORY_SIZE);
_history.setMaxSize(historySize);
} catch (IOException e) {
_logger.warn("History creation failed: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class LegacyAdminShellCommand implements Command, Runnable
{
private static final Logger _logger =
LoggerFactory.getLogger(LegacyAdminShellCommand.class);
private static final int HISTORY_SIZE = 50;
private LegacyAdminShell _shell;
private InputStream _in;
private ExitCallback _exitCallback;
Expand All @@ -55,15 +54,15 @@ public class LegacyAdminShellCommand implements Command, Runnable
private final CellEndpoint _endpoint;
private String _prompt;

public LegacyAdminShellCommand(CellEndpoint endpoint, File historyFile, String prompt, boolean useColor)
public LegacyAdminShellCommand(CellEndpoint endpoint, File historyFile, int historySize, String prompt, boolean useColor)
{
_useColors = useColor;
_endpoint = endpoint;
_prompt = prompt;
if (historyFile != null && (!historyFile.exists() || historyFile.isFile())) {
try {
_history = new FileHistory(historyFile);
_history.setMaxSize(HISTORY_SIZE);
_history.setMaxSize(historySize);
} catch (IOException e) {
_logger.warn("History creation failed: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class LegacySubsystemFactory implements NamedFactory<Command>, CellMessag
private CellEndpoint _endpoint;

private File _historyFile;
private int _historySize;
private boolean _useColor;
private String _prompt;

Expand All @@ -29,6 +30,11 @@ public void setHistoryFile(File historyFile)
_historyFile = historyFile;
}

@Required
public void setHistorySize(int historySize) {
_historySize = historySize;
}

@Required
public void setUseColor(boolean useColor)
{
Expand All @@ -49,6 +55,6 @@ public String getName()
@Override
public Command create()
{
return new LegacyAdminShellCommand(_endpoint, _historyFile, _prompt, _useColor);
return new LegacyAdminShellCommand(_endpoint, _historyFile, _historySize, _prompt, _useColor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
public class ShellCommand implements Command
{
private final File historyFile;
private final int historySize;
private final boolean useColor;
private final UserAdminShell shell;
private InputStream in;
Expand All @@ -40,9 +41,10 @@ public class ShellCommand implements Command

private Command delegate;

public ShellCommand(File historyFile, boolean useColor, UserAdminShell shell)
public ShellCommand(File historyFile, int historySize, boolean useColor, UserAdminShell shell)
{
this.historyFile = historyFile;
this.historySize = historySize;
this.useColor = useColor;
this.shell = shell;
}
Expand Down Expand Up @@ -75,7 +77,7 @@ public void setExitCallback(ExitCallback callback)
public void start(Environment env) throws IOException
{
if (env.getEnv().get(Environment.ENV_TERM) != null) {
delegate = new AnsiTerminalCommand(historyFile, useColor, shell);
delegate = new AnsiTerminalCommand(historyFile, historySize, useColor, shell);
} else {
delegate = new NoTerminalCommand(shell);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ShellFactory implements Factory<Command>, CellMessageSender
{
private CellEndpoint _endpoint;
private File _historyFile;
private int _historySize;
private boolean _useColor;
private CellStub _pnfsManager;
private CellStub _poolManager;
Expand All @@ -31,6 +32,11 @@ public void setHistoryFile(File historyFile)
_historyFile = historyFile;
}

@Required
public void setHistorySize(int size) {
_historySize = size;
}

@Required
public void setUseColor(boolean useColor)
{
Expand Down Expand Up @@ -76,7 +82,7 @@ public void setCellEndpoint(CellEndpoint endpoint)
@Override
public Command create()
{
return new ShellCommand(_historyFile, _useColor, createShell());
return new ShellCommand(_historyFile, _historySize, _useColor, createShell());
}

private UserAdminShell createShell()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

<bean id="shell-factory" class="org.dcache.services.ssh2.ShellFactory">
<property name="historyFile" value="${admin.paths.history}"/>
<property name="historySize" value="${admin.history.size}"/>
<property name="useColor" value="${admin.enable.colors}"/>
<property name="pnfsManager" ref="pnfsmanager"/>
<property name="poolManager" ref="poolmanager"/>
Expand All @@ -78,6 +79,7 @@

<bean id="legacy-factory" class="org.dcache.services.ssh2.LegacySubsystemFactory">
<property name="historyFile" value="${admin.paths.history}"/>
<property name="historySize" value="${admin.history.size}"/>
<property name="useColor" value="${admin.enable.colors}"/>
<property name="prompt" value="${admin.prompt}"/>
</bean>
Expand Down
14 changes: 12 additions & 2 deletions skel/share/defaults/admin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ admin.authz.gid = 0
# the history persistent over multiple logins. To enable this
# feature, set admin.paths.history to the path of the file that
# should be used to store the history. The recommended path is
# '/var/lib/dcache/admin/history'. Notice that missing directories
# are not created automatically.
# '/var/lib/dcache/admin/', so your admin history file path could be:
#
# admin.paths.history = /var/lib/dcache/admin/history
#
# Notice that missing directories are not created automatically.
admin.paths.history =

# ---- Admin door history size
#
# The size of the history in lines and thereby the history can be
# limited by setting admin.history.size to an integer value. The
# standard size is 500.
#
admin.history.size = 500

# ---- Whether to use ANSI colors or not
#
# When set to true ANSI codes will be used to add colors to the
Expand Down
1 change: 1 addition & 0 deletions skel/share/services/admin.batch
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

check -strong admin.cell.name
check admin.cell.subscribe
check -strong admin.history.size
check -strong admin.net.port
check -strong admin.paths.dsa-host-key.private
check -strong admin.paths.dsa-host-key.public
Expand Down

0 comments on commit 5a34e31

Please sign in to comment.