Skip to content

Commit

Permalink
Merge pull request #3 from EMCECS/feature-log-exception-cleanup
Browse files Browse the repository at this point in the history
Moved all info logs to debug or warn, removed exceptions when closing files
  • Loading branch information
DavidASeibert authored Nov 11, 2016
2 parents a3000c2 + 729dc46 commit 81104e8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public InetSocketAddress getRemoteAddress() {
* org.jboss.netty.channel.ChannelStateEvent)
*/
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
LOG.info("Connected to: {}", getRemoteAddress());
if (LOG.isDebugEnabled()) {
LOG.debug("Connected to: {}", getRemoteAddress());
}
}

/*
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/emc/ecs/nfsclient/network/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public Xdr sendAndWait(int timeout, Xdr xdrRequest) throws RpcException {

if (timeoutFuture.isSuccess() == false) {

LOG.info("cause:", timeoutFuture.getCause());
LOG.warn("cause:", timeoutFuture.getCause());

if (timeoutFuture.isDone()) {
String msg = String.format("tcp IO error on the connection: %s", getRemoteAddress());
Expand All @@ -296,8 +296,10 @@ protected void connect() throws RpcException {

final ChannelFuture oldChannelFuture = _channelFuture;

String logPrefix = _usePrivilegedPort ? "usePrivilegedPort " : "";
LOG.info(logPrefix + "connecting to {}", getRemoteAddress());
if (LOG.isDebugEnabled()) {
String logPrefix = _usePrivilegedPort ? "usePrivilegedPort " : "";
LOG.debug("{}connecting to {}", logPrefix, getRemoteAddress());
}
_state = State.CONNECTING;

if (_usePrivilegedPort) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ public int available() throws IOException {
* @see java.io.InputStream#close()
*/
public void close() throws IOException {
checkForClosed();
_closed = true;
super.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The NFS equivalent of <code>java.io.FileOutputStream</code>.
*
* @author seibed
*/
public class NfsFileOutputStream extends OutputStream {

/**
* The usual logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(NfsFileOutputStream.class);

private NfsFile<?, ?> _nfsFile;

/**
Expand Down Expand Up @@ -185,9 +193,15 @@ public NfsFileOutputStream(NfsFile<?, ?> nfsFile, long offset, int syncType) thr
* @see java.io.OutputStream#close()
*/
public void close() throws IOException {
flush();
_closed = true;
super.close();
if (!_closed) {
try {
flush();
} catch (Throwable t) {
LOG.debug(t.getMessage(), t);
}
_closed = true;
super.close();
}
}

/*
Expand Down
26 changes: 6 additions & 20 deletions src/main/java/com/emc/ecs/nfsclient/nfs/nfs3/Nfs3.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,6 @@ public class Nfs3 implements Nfs<Nfs3File> {
*/
private Credential _credential = new CredentialUnix();

/**
* <ul><li>
* If <code>true</code>, include extra diagnostic and informational log entries.
* </li><li>
* If <code>false</code>, omit non-critical log entries.
* </li></ul>
*/
private boolean _verbose = false;

/**
* The helper instance used to wrap RPC calls.
*/
Expand Down Expand Up @@ -261,7 +252,7 @@ public Nfs3(String server, String exportedPath, byte[] rootFileHandle, Credentia
if (credential != null) {
_credential = credential;
}
_rpcWrapper = new RpcWrapper<NfsRequestBase, NfsResponseBase>(_server, _port, _retryWait, _maximumRetries, MAXIMUM_NFS_REQUEST_SIZE, NFS_TIMEOUT, _verbose);
_rpcWrapper = new RpcWrapper<NfsRequestBase, NfsResponseBase>(_server, _port, _retryWait, _maximumRetries, MAXIMUM_NFS_REQUEST_SIZE, NFS_TIMEOUT);

if (rootFileHandle == null) {
prepareRootFhAndNfsPort();
Expand All @@ -270,12 +261,6 @@ public Nfs3(String server, String exportedPath, byte[] rootFileHandle, Credentia
_port = getNfsPortFromServer();
_rpcWrapper.setPort(_port);
}

if (_verbose) {
LOG.info("nfs rpc verbose is enabled");
} else {
LOG.info("nfs rpc verbose is NOT enabled");
}
}

/**
Expand Down Expand Up @@ -382,10 +367,11 @@ byte[] lookupRootHandle()
// If this gets here, the response cannot be null.
// log the security mode that NFS supports, though we just
// support AUTH_UNIX now
int[] authenticationFlavors = response.getAuthenticationFlavors();
String msg = String.format("nfs server %s:%s support auth mode %s", _server, _exportedPath,
Arrays.toString(authenticationFlavors));
LOG.info(msg);
if (LOG.isDebugEnabled()) {
int[] authenticationFlavors = response.getAuthenticationFlavors();
LOG.debug("nfs server {}:{} supports auth mode {}", _server, _exportedPath,
Arrays.toString(authenticationFlavors));
}

return response.getRootFileHandle();
}
Expand Down
42 changes: 12 additions & 30 deletions src/main/java/com/emc/ecs/nfsclient/rpc/RpcWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,6 @@ public class RpcWrapper<S extends NfsRequestBase, T extends NfsResponseBase> {
*/
private final int _rpcTimeout;

/**
* <ul>
* <li>If <code>true</code>, include extra diagnostic and informational log
* entries.</li>
* <li>If <code>false</code>, omit non-critical log entries.</li>
* </ul>
*/
private final boolean _verbose;

/**
* Discovered IP addresses for the remote server.
*/
Expand All @@ -100,22 +91,15 @@ public class RpcWrapper<S extends NfsRequestBase, T extends NfsResponseBase> {
* The maximum request size in bytes.
* @param rpcTimeout
* The timeout in seconds.
* @param verbose
* <ul>
* <li>If <code>true</code>, include extra diagnostic and
* informational log entries.</li>
* <li>If <code>false</code>, omit non-critical log entries.</li>
* </ul>
*/
public RpcWrapper(String server, int port, int retryWait, int maximumRetries,
int maximumRequestSize, int rpcTimeout, boolean verbose) {
int maximumRequestSize, int rpcTimeout) {
_server = server;
_port = port;
_retryWait = retryWait;
_maximumRetries = maximumRetries;
_maximumRequestSize = maximumRequestSize;
_rpcTimeout = rpcTimeout;
_verbose = verbose;
}

/**
Expand Down Expand Up @@ -281,16 +265,12 @@ public String chooseIP(byte[] key) throws IOException {
*/
private void callRpcChecked(S request, RpcResponseHandler<? extends T> responseHandler, String ipAddress)
throws IOException {
if (_verbose) {
LOG.info("server: %s port: %s %s", new Object[] { _server, _port, request.toString() });
}
LOG.debug("server {}, port {}, request {}", _server, _port, request);

callRpcNaked(request, responseHandler.getNewResponse(), ipAddress);

if (_verbose) {
String msg = String.format("server: %s port: %s %s", _server, _port,
responseHandler.getResponse().toString());
LOG.info(msg);
if (LOG.isDebugEnabled()) {
LOG.debug("server {}, port {}, response {}", _server, _port, responseHandler.getResponse());
}

responseHandler.checkResponse(request);
Expand Down Expand Up @@ -320,7 +300,7 @@ private void handleRpcException(RpcException e, int attemptNumber) throws IOExce
// restore the interrupt status
Thread.currentThread().interrupt();
}
LOG.info("network error happens, server {}, attemptNumber {}", new Object[] { _server, attemptNumber });
LOG.warn("network error happens, server {}, attemptNumber {}", new Object[] { _server, attemptNumber });
return;
}

Expand All @@ -343,12 +323,14 @@ private String[] probeIps() {
ips.add(sa.getAddress().getHostAddress());
}

StringBuffer sb = new StringBuffer();
for (String ip : ips) {
sb.append(ip);
sb.append(" ");
if (LOG.isDebugEnabled()) {
StringBuffer sb = new StringBuffer();
for (String ip : ips) {
sb.append(ip);
sb.append(" ");
}
LOG.debug(sb.toString());
}
LOG.info(sb.toString());

return (String[]) ips.toArray(new String[0]);
}
Expand Down

0 comments on commit 81104e8

Please sign in to comment.