use of javax.naming.TimeLimitExceededException in project directory-ldap-api by apache.
the class WrappedPartialResultException method wrap.
/**
* Wraps a LDAP exception into a NaingException
*
* @param t The original exception
* @throws NamingException The wrapping JNDI exception
*/
public static void wrap(Throwable t) throws NamingException {
if (t instanceof NamingException) {
throw (NamingException) t;
}
NamingException ne;
if ((t instanceof LdapAffectMultipleDsaException) || (t instanceof LdapAliasDereferencingException) || (t instanceof LdapLoopDetectedException) || (t instanceof LdapAliasException) || (t instanceof LdapOperationErrorException) || (t instanceof LdapOtherException)) {
ne = new NamingException(t.getLocalizedMessage());
} else if (t instanceof LdapAttributeInUseException) {
ne = new AttributeInUseException(t.getLocalizedMessage());
} else if (t instanceof LdapAuthenticationException) {
ne = new AuthenticationException(t.getLocalizedMessage());
} else if (t instanceof LdapAuthenticationNotSupportedException) {
ne = new AuthenticationNotSupportedException(t.getLocalizedMessage());
} else if (t instanceof LdapContextNotEmptyException) {
ne = new ContextNotEmptyException(t.getLocalizedMessage());
} else if (t instanceof LdapEntryAlreadyExistsException) {
ne = new NameAlreadyBoundException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidAttributeTypeException) {
ne = new InvalidAttributeIdentifierException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidAttributeValueException) {
ne = new InvalidAttributeValueException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidDnException) {
ne = new InvalidNameException(t.getLocalizedMessage());
} else if (t instanceof LdapInvalidSearchFilterException) {
ne = new InvalidSearchFilterException(t.getLocalizedMessage());
} else if (t instanceof LdapNoPermissionException) {
ne = new NoPermissionException(t.getLocalizedMessage());
} else if (t instanceof LdapNoSuchAttributeException) {
ne = new NoSuchAttributeException(t.getLocalizedMessage());
} else if (t instanceof LdapNoSuchObjectException) {
ne = new NameNotFoundException(t.getLocalizedMessage());
} else if (t instanceof LdapProtocolErrorException) {
ne = new CommunicationException(t.getLocalizedMessage());
} else if (t instanceof LdapReferralException) {
ne = new WrappedReferralException((LdapReferralException) t);
} else if (t instanceof LdapPartialResultException) {
ne = new WrappedPartialResultException((LdapPartialResultException) t);
} else if (t instanceof LdapSchemaViolationException) {
ne = new SchemaViolationException(t.getLocalizedMessage());
} else if (t instanceof LdapServiceUnavailableException) {
ne = new ServiceUnavailableException(t.getLocalizedMessage());
} else if (t instanceof LdapTimeLimitExceededException) {
ne = new TimeLimitExceededException(t.getLocalizedMessage());
} else if (t instanceof LdapUnwillingToPerformException) {
ne = new OperationNotSupportedException(t.getLocalizedMessage());
} else {
ne = new NamingException(t.getLocalizedMessage());
}
ne.setRootCause(t);
throw ne;
}
use of javax.naming.TimeLimitExceededException in project ovirt-engine by oVirt.
the class OVirtNodeUpgrade method execute.
/**
* Main method.
* Execute the command and initiate the dialog.
*/
public void execute() throws Exception {
try {
_dialog.setVds(_vds);
_dialog.useDefaultKeyPair();
_dialog.connect();
_messages.post(InstallerMessages.Severity.INFO, String.format("Connected to host %1$s with SSH key fingerprint: %2$s", _vds.getHostName(), _dialog.getHostFingerprint()));
_dialog.authenticate();
String dest = Config.getValue(ConfigValues.oVirtUploadPath);
_messages.post(InstallerMessages.Severity.INFO, String.format("Sending file %1$s to %2$s", _iso, dest));
/*
* Create the directory where
* file is stored, in the past
* it was done by vdsm, then vdsm-reg
* well, as we use hard coded path
* we can as well do this, until we
* have proper node upgrade script
* that can take the image from stdin.
*/
_dialog.executeCommand(new SSHDialog.Sink() {
@Override
public void setControl(SSHDialog.Control control) {
}
@Override
public void setStreams(InputStream incoming, OutputStream outgoing) {
}
@Override
public void start() {
}
@Override
public void stop() {
}
}, String.format("mkdir -p '%1$s'", new File(dest).getParent()), null);
if (_failException != null) {
throw _failException;
}
_dialog.sendFile(_iso.getAbsolutePath(), dest);
String command = Config.getValue(ConfigValues.oVirtUpgradeScriptName);
_messages.post(InstallerMessages.Severity.INFO, String.format("Executing %1$s", command));
_dialog.executeCommand(this, command, null);
if (_failException != null) {
throw _failException;
}
_deployStatus = DeployStatus.Reboot;
} catch (TimeLimitExceededException e) {
log.error("Timeout during node '{}' upgrade: {}", _vds.getHostName(), e.getMessage());
log.debug("Exception", e);
_messages.post(InstallerMessages.Severity.ERROR, "Processing stopped due to timeout");
throw e;
} catch (Exception e) {
log.error("Error during node '{}' upgrade: {}", _vds.getHostName(), e.getMessage());
log.error("Exception", e);
if (_failException == null) {
throw e;
} else {
log.error("Error during node '{}' upgrade, prefering first exception: {}", _vds.getHostName(), _failException.getMessage());
throw _failException;
}
}
}
use of javax.naming.TimeLimitExceededException in project ovirt-engine by oVirt.
the class VdsDeployBase method execute.
/**
* Main method.
* Execute the command and initiate the dialog.
*/
public void execute() throws Exception {
_customizationDialog.addAll(CUSTOMIZATION_DIALOG_PROLOG);
for (VdsDeployUnit unit : _units) {
unit.init();
}
_customizationDialog.addAll(CUSTOMIZATION_DIALOG_EPILOG);
_terminationDialog.addAll(TERMINATION_DIALOG_EPILOG);
try {
_dialog.setVds(_vds);
_dialog.connect();
userVisibleLog(Level.INFO, String.format("Connected to host %1$s with SSH key fingerprint: %2$s", _vds.getHostName(), _dialog.getHostFingerprint()));
_dialog.authenticate();
String command = Config.<String>getValue(ConfigValues.BootstrapCommand).replace(BOOTSTRAP_ENTRY_PLACE_HOLDER, _entryPoint).replace(// in future we should set here LANG, LC_ALL
BOOTSTRAP_CUSTOM_ENVIRONMENT_PLACE_HOLDER, "");
log.info("Installation of {}. Executing command via SSH {} < {}", _vds.getHostName(), command, s_deployPackage.getFileNoUse());
try (final InputStream in = new FileInputStream(s_deployPackage.getFile())) {
_dialog.executeCommand(this, command, new InputStream[] { in });
}
if (_failException != null) {
throw _failException;
}
if (_resultError) {
// This is unlikeley as the ssh command will exit with failure.
throw new RuntimeException("Installation failed, please refer to installation logs");
}
} catch (TimeLimitExceededException e) {
log.error("Timeout during host {} install: {}", _vds.getHostName(), e.getMessage());
log.debug("Exception", e);
userVisibleLog(Level.SEVERE, "Processing stopped due to timeout");
throw e;
} catch (Exception e) {
log.error("Error during host {} install", _vds.getHostName(), ExceptionUtils.getRootCauseMessage(e));
log.debug("Exception", e);
if (_failException == null) {
throw e;
} else {
userVisibleLog(Level.SEVERE, e.getMessage());
log.error("Error during host {} install, preferring first exception: {}", _vds.getHostName(), _failException.getMessage());
log.debug("Exception", _failException);
throw _failException;
}
}
}
use of javax.naming.TimeLimitExceededException in project ovirt-engine by oVirt.
the class SSHClient method executeCommand.
/**
* Execute generic command.
*
* @param command
* command to execute.
* @param in
* stdin.
* @param out
* stdout.
* @param err
* stderr.
*/
public void executeCommand(String command, InputStream in, OutputStream out, OutputStream err) throws Exception {
log.debug("Executing: '{}'", command);
if (in == null) {
in = new ByteArrayInputStream(new byte[0]);
}
if (out == null) {
out = new ConstraintByteArrayOutputStream(CONSTRAINT_BUFFER_SIZE);
}
if (err == null) {
err = new ConstraintByteArrayOutputStream(CONSTRAINT_BUFFER_SIZE);
}
/*
* Redirect streams into indexed streams.
*/
ClientChannel channel = null;
try (final ProgressInputStream iin = new ProgressInputStream(in);
final ProgressOutputStream iout = new ProgressOutputStream(out);
final ProgressOutputStream ierr = new ProgressOutputStream(err)) {
channel = session.createExecChannel(command);
channel.setIn(iin);
channel.setOut(iout);
channel.setErr(ierr);
channel.open();
long hardEnd = 0;
if (hardTimeout != 0) {
hardEnd = System.currentTimeMillis() + hardTimeout;
}
boolean hardTimeout = false;
int stat;
boolean activity;
do {
stat = channel.waitFor(ClientChannel.CLOSED | ClientChannel.EOF | ClientChannel.TIMEOUT, softTimeout);
hardTimeout = hardEnd != 0 && System.currentTimeMillis() >= hardEnd;
/*
* Notice that we should visit all so do not cascade statement.
*/
activity = iin.wasProgress();
activity = iout.wasProgress() || activity;
activity = ierr.wasProgress() || activity;
} while (!hardTimeout && (stat & ClientChannel.TIMEOUT) != 0 && activity);
if (hardTimeout) {
throw new TimeLimitExceededException(String.format("SSH session hard timeout host '%1$s'", this.getDisplayHost()));
}
if ((stat & ClientChannel.TIMEOUT) != 0) {
throw new TimeLimitExceededException(String.format("SSH session timeout host '%1$s'", this.getDisplayHost()));
}
stat = channel.waitFor(ClientChannel.CLOSED | ClientChannel.EXIT_STATUS | ClientChannel.EXIT_SIGNAL | ClientChannel.TIMEOUT, softTimeout);
if ((stat & ClientChannel.EXIT_SIGNAL) != 0) {
throw new IOException(String.format("Signal received during SSH session host '%1$s'", this.getDisplayHost()));
}
if ((stat & ClientChannel.EXIT_STATUS) != 0 && channel.getExitStatus() != 0) {
throw new IOException(String.format("Command returned failure code %2$d during SSH session '%1$s'", this.getDisplayHost(), channel.getExitStatus()));
}
if ((stat & ClientChannel.TIMEOUT) != 0) {
throw new TimeLimitExceededException(String.format("SSH session timeout waiting for status host '%1$s'", this.getDisplayHost()));
}
// the PipedOutputStream does not
// flush streams at close
// this leads other side of pipe
// to miss last bytes
// not sure why it is required as
// FilteredOutputStream does flush
// on close.
out.flush();
err.flush();
} catch (RuntimeException e) {
log.error("Execute failed", ExceptionUtils.getRootCauseMessage(e));
log.debug("Exception", e);
throw e;
} finally {
if (channel != null) {
int stat = channel.waitFor(ClientChannel.CLOSED | ClientChannel.TIMEOUT, 1);
if ((stat & ClientChannel.CLOSED) != 0) {
channel.close(true);
}
}
}
log.debug("Executed: '{}'", command);
}
use of javax.naming.TimeLimitExceededException in project ovirt-engine by oVirt.
the class SSHClient method connect.
/**
* Connect to host.
*/
public void connect() throws Exception {
log.debug("Connecting '{}'", this.getDisplayHost());
try {
client = createSshClient();
client.setServerKeyVerifier((sshClientSession, remoteAddress, serverKey) -> {
hostKey = serverKey;
return true;
});
client.start();
ConnectFuture cfuture = client.connect(host, port);
if (!cfuture.await(softTimeout)) {
throw new TimeLimitExceededException(String.format("SSH connection timed out connecting to '%1$s'", this.getDisplayHost()));
}
session = cfuture.getSession();
/*
* Wait for authentication phase so we have host key.
*/
int stat = session.waitFor(ClientSession.CLOSED | ClientSession.WAIT_AUTH | ClientSession.TIMEOUT, softTimeout);
if ((stat & ClientSession.CLOSED) != 0) {
throw new IOException(String.format("SSH session closed during connection '%1$s'", this.getDisplayHost()));
}
if ((stat & ClientSession.TIMEOUT) != 0) {
throw new TimeLimitExceededException(String.format("SSH timed out waiting for authentication request '%1$s'", this.getDisplayHost()));
}
} catch (Exception e) {
log.debug("Connect error", e);
throw e;
}
log.debug("Connected: '{}'", this.getDisplayHost());
}
Aggregations