Alon Bar-Lev has uploaded a new change for review. Change subject: utils: ssh: move to member '_' convention ......................................................................
utils: ssh: move to member '_' convention We had several discussion over this. Convention for members/static/globals is very helpful when dealing with patch hunk and review, as every variable can be assigned to proper context without reading the whole code. It also avoid naming clashes between the different scope level. I am aware that some people are not used to variable name convention, however it is much easier to maintain and review patches in this mode. I am enforcing this convention on bootstrap and ssh sources, and I hope that others will see the benefit in this method as well. Change-Id: I1bca20cec1e309105805d2c741c56abf04ab33d5 Signed-off-by: Alon Bar-Lev <alo...@redhat.com> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ConstraintByteArrayOutputStream.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressInputStream.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressOutputStream.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/SSHClient.java 4 files changed, 76 insertions(+), 76 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/71/9171/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ConstraintByteArrayOutputStream.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ConstraintByteArrayOutputStream.java index 6751307..a4601db 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ConstraintByteArrayOutputStream.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ConstraintByteArrayOutputStream.java @@ -6,8 +6,8 @@ * Soft constraint byte array output stream. */ public class ConstraintByteArrayOutputStream extends ByteArrayOutputStream { - int max; - boolean truncated = false; + private int _max; + private boolean _truncated = false; /** * Constructor. @@ -16,7 +16,7 @@ */ public ConstraintByteArrayOutputStream(int max) { super(); - this.max = max; + _max = max; } /** @@ -25,16 +25,16 @@ * @return true if truncated. */ public boolean wasTruncated() { - return this.truncated; + return _truncated; } @Override public void write(int b) { - if (count < this.max) { + if (count < _max) { super.write(b); } else { - this.truncated = true; + _truncated = true; } } @@ -45,11 +45,11 @@ @Override public void write(byte[] b, int off, int len) { - if (count < this.max) { + if (count < _max) { super.write(b, off, len); } else { - this.truncated = true; + _truncated = true; } } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressInputStream.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressInputStream.java index b9ca26b..efa3919 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressInputStream.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressInputStream.java @@ -11,11 +11,11 @@ * any mean of monitoring progress. */ public class ProgressInputStream extends FilterInputStream { - int index; + private int _index; public ProgressInputStream(InputStream in) { super(in); - this.index = 0; + _index = 0; } @Override @@ -23,7 +23,7 @@ throws IOException { int ret = in.read(b, off, len); if (ret != -1) { - this.index += ret; + _index += ret; } return ret; } @@ -33,17 +33,17 @@ throws IOException { int ret = in.read(); if (ret != -1) { - this.index++; + _index++; } return ret; } public boolean wasProgress() { - if (this.index == 0) { + if (_index == 0) { return false; } else { - this.index = 0; + _index = 0; return true; } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressOutputStream.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressOutputStream.java index 2aa0c4d..4b64575 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressOutputStream.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/ProgressOutputStream.java @@ -11,33 +11,33 @@ * any mean of monitoring progress. */ class ProgressOutputStream extends FilterOutputStream { - int index; + private int _index; public ProgressOutputStream(OutputStream out) { super(out); - this.index = 0; + _index = 0; } @Override public void write(byte[] b, int off, int len) throws IOException { out.write(b, off, len); - this.index += len; + _index += len; } @Override public void write(int b) throws IOException { out.write(b); - this.index++; + _index++; } public boolean wasProgress() { - if (this.index == 0) { + if (_index == 0) { return false; } else { - this.index = 0; + _index = 0; return true; } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/SSHClient.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/SSHClient.java index ff1494b..3e6d97f 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/SSHClient.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ssh/SSHClient.java @@ -42,16 +42,16 @@ private static Log log = LogFactory.getLog(SSHClient.class); - private SshClient client; - private ClientSession session; - private long softTimeout = 10000; - private long hardTimeout = 0; - private String user; - private String password; - private KeyPair keyPair; - private String host; - private int port = DEFAULT_SSH_PORT; - private PublicKey serverKey; + private SshClient _client; + private ClientSession _session; + private long _softTimeout = 10000; + private long _hardTimeout = 0; + private String _user; + private String _password; + private KeyPair _keyPair; + private String _host; + private int _port = DEFAULT_SSH_PORT; + private PublicKey _serverKey; /** * Create the client. @@ -122,7 +122,7 @@ * default is 10 seconds. */ public void setSoftTimeout(long softTimeout) { - this.softTimeout = softTimeout; + _softTimeout = softTimeout; } /** @@ -134,7 +134,7 @@ * The timeout is evaluate at softTimeout intervals. */ public void setHardTimeout(long hardTimeout) { - this.hardTimeout = hardTimeout; + _hardTimeout = hardTimeout; } /** @@ -142,7 +142,7 @@ * @param user user. */ public void setUser(String user) { - this.user = user; + _user = user; } /** @@ -150,7 +150,7 @@ * @param password password. */ public void setPassword(String password) { - this.password = password; + _password = password; } /** @@ -158,7 +158,7 @@ * @param keyPair key pair. */ public void setKeyPair(KeyPair keyPair) { - this.keyPair = keyPair; + _keyPair = keyPair; } /** @@ -167,9 +167,9 @@ * @param port port. */ public void setHost(String host, int port) { - this.host = host; - this.port = port; - this.serverKey = null; + _host = host; + _port = port; + _serverKey = null; } /** @@ -185,7 +185,7 @@ * @return host as set by setHost() */ public String getHost() { - return this.host; + return _host; } /** @@ -193,7 +193,7 @@ * @return port. */ public int getPort() { - return this.port; + return _port; } /** @@ -201,7 +201,7 @@ * @return timeout. */ public long getHardTimeout() { - return this.hardTimeout; + return _hardTimeout; } /** @@ -209,7 +209,7 @@ * @return timeout. */ public long getSoftTimeout() { - return this.softTimeout; + return _softTimeout; } /** @@ -217,23 +217,23 @@ * @return user. */ public String getUser() { - return this.user; + return _user; } public String getDisplayHost() { StringBuilder ret = new StringBuilder(100); - if (this.host == null) { + if (_host == null) { ret.append("N/A"); } else { - if (this.user != null) { - ret.append(this.user); + if (_user != null) { + ret.append(_user); ret.append("@"); } - ret.append(this.host); - if (this.port != DEFAULT_SSH_PORT) { + ret.append(_host); + if (_port != DEFAULT_SSH_PORT) { ret.append(":"); - ret.append(this.port); + ret.append(_port); } } return ret.toString(); @@ -244,7 +244,7 @@ * @return server key. */ public PublicKey getServerKey() { - return this.serverKey; + return _serverKey; } /** @@ -255,9 +255,9 @@ log.debug(String.format("Connecting: '%1$s'", this.getDisplayHost())); try { - this.client = _createSshClient(); + _client = _createSshClient(); - this.client.setServerKeyVerifier( + _client.setServerKeyVerifier( new ServerKeyVerifier() { @Override public boolean verifyServerKey( @@ -265,16 +265,16 @@ SocketAddress remoteAddress, PublicKey serverKey ) { - SSHClient.this.serverKey = serverKey; + _serverKey = serverKey; return true; } } ); - this.client.start(); + _client.start(); - ConnectFuture cfuture = this.client.connect(this.host, this.port); - if (!cfuture.await(this.softTimeout)) { + ConnectFuture cfuture = _client.connect(_host, _port); + if (!cfuture.await(_softTimeout)) { throw new TimeLimitExceededException( String.format( "SSH connection timed out connecting to '%1$s'", @@ -283,19 +283,19 @@ ); } - this.session = cfuture.getSession(); + _session = cfuture.getSession(); /* * Wait for authentication phase so * we have serverKey. */ - int stat = this.session.waitFor( + int stat = _session.waitFor( ( ClientSession.CLOSED | ClientSession.WAIT_AUTH | ClientSession.TIMEOUT ), - this.softTimeout + _softTimeout ); if ((stat & ClientSession.CLOSED) != 0) { throw new IOException( @@ -331,11 +331,11 @@ try { AuthFuture afuture; - if (this.keyPair != null) { - afuture = this.session.authPublicKey(this.user, this.keyPair); + if (_keyPair != null) { + afuture = _session.authPublicKey(_user, _keyPair); } - else if (this.password != null) { - afuture = this.session.authPassword(this.user, this.password); + else if (_password != null) { + afuture = _session.authPassword(_user, _password); } else { throw new AuthenticationException( @@ -345,7 +345,7 @@ ) ); } - if (!afuture.await(this.softTimeout)) { + if (!afuture.await(_softTimeout)) { throw new TimeLimitExceededException( String.format( "SSH authentication timed out connecting to '%1$s'", @@ -359,7 +359,7 @@ "SSH authentication to '%1$s' failed%2$s", this.getDisplayHost(), ( - this.keyPair == null ? + _keyPair == null ? " make sure host is configured for password authentication" : " make sure key is authorized at host" ) @@ -381,13 +381,13 @@ * Must be called when done with client. */ public void disconnect() { - if (this.session != null) { - this.session.close(true); - this.session = null; + if (_session != null) { + _session.close(true); + _session = null; } - if (this.client != null) { - this.client.stop(); - this.client = null; + if (_client != null) { + _client.stop(); + _client = null; } } @@ -424,7 +424,7 @@ ProgressOutputStream iout = new ProgressOutputStream(out); ProgressOutputStream ierr = new ProgressOutputStream(err); - ClientChannel channel = this.session.createExecChannel(command); + ClientChannel channel = _session.createExecChannel(command); try { channel.setIn(iin); @@ -433,8 +433,8 @@ channel.open(); long hardEnd = 0; - if (this.hardTimeout != 0) { - hardEnd = System.currentTimeMillis() + this.hardTimeout; + if (_hardTimeout != 0) { + hardEnd = System.currentTimeMillis() + _hardTimeout; } boolean hardTimeout = false; @@ -447,7 +447,7 @@ ClientChannel.EOF | ClientChannel.TIMEOUT ), - this.softTimeout + _softTimeout ); hardTimeout = (hardEnd != 0 && System.currentTimeMillis() >= hardEnd); @@ -490,7 +490,7 @@ ClientChannel.EXIT_SIGNAL | ClientChannel.TIMEOUT ), - this.softTimeout + _softTimeout ); if ((stat & ClientChannel.EXIT_SIGNAL) != 0) { -- To view, visit http://gerrit.ovirt.org/9171 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1bca20cec1e309105805d2c741c56abf04ab33d5 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <alo...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches