Search in sources :

Example 1 with TimeLimitExceededException

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;
}
Also used : LdapEntryAlreadyExistsException(org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException) LdapOperationErrorException(org.apache.directory.api.ldap.model.exception.LdapOperationErrorException) LdapAttributeInUseException(org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException) AuthenticationException(javax.naming.AuthenticationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) LdapAuthenticationNotSupportedException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationNotSupportedException) AuthenticationNotSupportedException(javax.naming.AuthenticationNotSupportedException) LdapServiceUnavailableException(org.apache.directory.api.ldap.model.exception.LdapServiceUnavailableException) LdapInvalidAttributeTypeException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeTypeException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) LdapServiceUnavailableException(org.apache.directory.api.ldap.model.exception.LdapServiceUnavailableException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) LdapTimeLimitExceededException(org.apache.directory.api.ldap.model.exception.LdapTimeLimitExceededException) LdapAliasException(org.apache.directory.api.ldap.model.exception.LdapAliasException) LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) LdapPartialResultException(org.apache.directory.api.ldap.model.exception.LdapPartialResultException) LdapSchemaViolationException(org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException) LdapAuthenticationNotSupportedException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationNotSupportedException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) LdapLoopDetectedException(org.apache.directory.api.ldap.model.exception.LdapLoopDetectedException) InvalidNameException(javax.naming.InvalidNameException) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) LdapReferralException(org.apache.directory.api.ldap.model.exception.LdapReferralException) NamingException(javax.naming.NamingException) SchemaViolationException(javax.naming.directory.SchemaViolationException) LdapSchemaViolationException(org.apache.directory.api.ldap.model.exception.LdapSchemaViolationException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) LdapAliasDereferencingException(org.apache.directory.api.ldap.model.exception.LdapAliasDereferencingException) InvalidAttributeIdentifierException(javax.naming.directory.InvalidAttributeIdentifierException) CommunicationException(javax.naming.CommunicationException) InvalidSearchFilterException(javax.naming.directory.InvalidSearchFilterException) LdapInvalidSearchFilterException(org.apache.directory.api.ldap.model.exception.LdapInvalidSearchFilterException) NameNotFoundException(javax.naming.NameNotFoundException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) LdapAffectMultipleDsaException(org.apache.directory.api.ldap.model.exception.LdapAffectMultipleDsaException) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) InvalidAttributeValueException(javax.naming.directory.InvalidAttributeValueException) LdapContextNotEmptyException(org.apache.directory.api.ldap.model.exception.LdapContextNotEmptyException) NoSuchAttributeException(javax.naming.directory.NoSuchAttributeException) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) ContextNotEmptyException(javax.naming.ContextNotEmptyException) LdapContextNotEmptyException(org.apache.directory.api.ldap.model.exception.LdapContextNotEmptyException) NoPermissionException(javax.naming.NoPermissionException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapTimeLimitExceededException(org.apache.directory.api.ldap.model.exception.LdapTimeLimitExceededException) TimeLimitExceededException(javax.naming.TimeLimitExceededException) AttributeInUseException(javax.naming.directory.AttributeInUseException) LdapAttributeInUseException(org.apache.directory.api.ldap.model.exception.LdapAttributeInUseException) LdapInvalidSearchFilterException(org.apache.directory.api.ldap.model.exception.LdapInvalidSearchFilterException) LdapNoSuchAttributeException(org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException)

Example 2 with TimeLimitExceededException

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;
        }
    }
}
Also used : EngineSSHDialog(org.ovirt.engine.core.bll.utils.EngineSSHDialog) SSHDialog(org.ovirt.engine.core.uutils.ssh.SSHDialog) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TimeLimitExceededException(javax.naming.TimeLimitExceededException) File(java.io.File) IOException(java.io.IOException) TimeLimitExceededException(javax.naming.TimeLimitExceededException)

Example 3 with TimeLimitExceededException

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;
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TimeLimitExceededException(javax.naming.TimeLimitExceededException) FileInputStream(java.io.FileInputStream) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) TimeLimitExceededException(javax.naming.TimeLimitExceededException)

Example 4 with TimeLimitExceededException

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TimeLimitExceededException(javax.naming.TimeLimitExceededException) IOException(java.io.IOException) ClientChannel(org.apache.sshd.ClientChannel)

Example 5 with TimeLimitExceededException

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());
}
Also used : ConnectFuture(org.apache.sshd.client.future.ConnectFuture) TimeLimitExceededException(javax.naming.TimeLimitExceededException) IOException(java.io.IOException) AuthenticationException(javax.naming.AuthenticationException) DecoderException(org.apache.commons.codec.DecoderException) IOException(java.io.IOException) TimeLimitExceededException(javax.naming.TimeLimitExceededException)

Aggregations

TimeLimitExceededException (javax.naming.TimeLimitExceededException)7 IOException (java.io.IOException)5 AuthenticationException (javax.naming.AuthenticationException)3 InputStream (java.io.InputStream)2 CommunicationException (javax.naming.CommunicationException)2 NameNotFoundException (javax.naming.NameNotFoundException)2 NamingException (javax.naming.NamingException)2 DecoderException (org.apache.commons.codec.DecoderException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1 KeyStoreException (java.security.KeyStoreException)1 AuthenticationNotSupportedException (javax.naming.AuthenticationNotSupportedException)1 ContextNotEmptyException (javax.naming.ContextNotEmptyException)1 InvalidNameException (javax.naming.InvalidNameException)1 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)1 NoPermissionException (javax.naming.NoPermissionException)1 OperationNotSupportedException (javax.naming.OperationNotSupportedException)1 ServiceUnavailableException (javax.naming.ServiceUnavailableException)1