Search in sources :

Example 51 with ConnectException

use of java.net.ConnectException in project k-9 by k9mail.

the class ImapConnection method connect.

private Socket connect() throws GeneralSecurityException, MessagingException, IOException {
    Exception connectException = null;
    InetAddress[] inetAddresses = InetAddress.getAllByName(settings.getHost());
    for (InetAddress address : inetAddresses) {
        try {
            return connectToAddress(address);
        } catch (IOException e) {
            Log.w(LOG_TAG, "Could not connect to " + address, e);
            connectException = e;
        }
    }
    throw new MessagingException("Cannot connect to host", connectException);
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) IOException(java.io.IOException) InetAddress(java.net.InetAddress) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) GeneralSecurityException(java.security.GeneralSecurityException) KeyManagementException(java.security.KeyManagementException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SocketException(java.net.SocketException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 52 with ConnectException

use of java.net.ConnectException in project hadoop by apache.

the class TestTimelineClient method mockEntityClientResponse.

public static ClientResponse mockEntityClientResponse(TimelineWriter spyTimelineWriter, ClientResponse.Status status, boolean hasError, boolean hasRuntimeError) {
    ClientResponse response = mock(ClientResponse.class);
    if (hasRuntimeError) {
        doThrow(new ClientHandlerException(new ConnectException())).when(spyTimelineWriter).doPostingObject(any(TimelineEntities.class), any(String.class));
        return response;
    }
    doReturn(response).when(spyTimelineWriter).doPostingObject(any(TimelineEntities.class), any(String.class));
    when(response.getStatusInfo()).thenReturn(status);
    TimelinePutResponse.TimelinePutError error = new TimelinePutResponse.TimelinePutError();
    error.setEntityId("test entity id");
    error.setEntityType("test entity type");
    error.setErrorCode(TimelinePutResponse.TimelinePutError.IO_EXCEPTION);
    TimelinePutResponse putResponse = new TimelinePutResponse();
    if (hasError) {
        putResponse.addError(error);
    }
    when(response.getEntity(TimelinePutResponse.class)).thenReturn(putResponse);
    return response;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) ConnectException(java.net.ConnectException)

Example 53 with ConnectException

use of java.net.ConnectException in project hadoop by apache.

the class HistoryFileManager method tryCreatingHistoryDirs.

/**
   * Returns TRUE if the history dirs were created, FALSE if they could not
   * be created because the FileSystem is not reachable or in safe mode and
   * throws and exception otherwise.
   */
@VisibleForTesting
boolean tryCreatingHistoryDirs(boolean logWait) throws IOException {
    boolean succeeded = true;
    String doneDirPrefix = JobHistoryUtils.getConfiguredHistoryServerDoneDirPrefix(conf);
    try {
        doneDirPrefixPath = FileContext.getFileContext(conf).makeQualified(new Path(doneDirPrefix));
        doneDirFc = FileContext.getFileContext(doneDirPrefixPath.toUri(), conf);
        doneDirFc.setUMask(JobHistoryUtils.HISTORY_DONE_DIR_UMASK);
        mkdir(doneDirFc, doneDirPrefixPath, new FsPermission(JobHistoryUtils.HISTORY_DONE_DIR_PERMISSION));
    } catch (ConnectException ex) {
        if (logWait) {
            LOG.info("Waiting for FileSystem at " + doneDirPrefixPath.toUri().getAuthority() + "to be available");
        }
        succeeded = false;
    } catch (IOException e) {
        if (isNameNodeStillNotStarted(e)) {
            succeeded = false;
            if (logWait) {
                LOG.info("Waiting for FileSystem at " + doneDirPrefixPath.toUri().getAuthority() + "to be out of safe mode");
            }
        } else {
            throw new YarnRuntimeException("Error creating done directory: [" + doneDirPrefixPath + "]", e);
        }
    }
    if (succeeded) {
        String intermediateDoneDirPrefix = JobHistoryUtils.getConfiguredHistoryIntermediateDoneDirPrefix(conf);
        try {
            intermediateDoneDirPath = FileContext.getFileContext(conf).makeQualified(new Path(intermediateDoneDirPrefix));
            intermediateDoneDirFc = FileContext.getFileContext(intermediateDoneDirPath.toUri(), conf);
            mkdir(intermediateDoneDirFc, intermediateDoneDirPath, new FsPermission(JobHistoryUtils.HISTORY_INTERMEDIATE_DONE_DIR_PERMISSIONS.toShort()));
        } catch (ConnectException ex) {
            succeeded = false;
            if (logWait) {
                LOG.info("Waiting for FileSystem at " + intermediateDoneDirPath.toUri().getAuthority() + "to be available");
            }
        } catch (IOException e) {
            if (isNameNodeStillNotStarted(e)) {
                succeeded = false;
                if (logWait) {
                    LOG.info("Waiting for FileSystem at " + intermediateDoneDirPath.toUri().getAuthority() + "to be out of safe mode");
                }
            } else {
                throw new YarnRuntimeException("Error creating intermediate done directory: [" + intermediateDoneDirPath + "]", e);
            }
        }
    }
    return succeeded;
}
Also used : Path(org.apache.hadoop.fs.Path) YarnRuntimeException(org.apache.hadoop.yarn.exceptions.YarnRuntimeException) FsPermission(org.apache.hadoop.fs.permission.FsPermission) IOException(java.io.IOException) ConnectException(java.net.ConnectException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 54 with ConnectException

use of java.net.ConnectException in project hbase by apache.

the class ServerManager method checkForRSznode.

/**
   * Check for an odd state, where we think an RS is up but it is not. Do it on OPEN.
   * This is only case where the check makes sense.
   *
   * <p>We are checking for instance of HBASE-9593 where a RS registered but died before it put
   * up its znode in zk. In this case, the RS made it into the list of online servers but it
   * is not actually UP. We do the check here where there is an evident problem rather
   * than do some crazy footwork where we'd have master check zk after a RS had reported
   * for duty with provisional state followed by a confirmed state; that'd be a mess.
   * Real fix is HBASE-17733.
   */
private void checkForRSznode(final ServerName serverName, final ServiceException se) {
    if (se.getCause() == null)
        return;
    Throwable t = se.getCause();
    if (t instanceof ConnectException) {
    // If this, proceed to do cleanup.
    } else {
        // Look for FailedServerException
        if (!(t instanceof IOException))
            return;
        if (t.getCause() == null)
            return;
        if (!(t.getCause() instanceof FailedServerException))
            return;
    // Ok, found FailedServerException -- continue.
    }
    if (!isServerOnline(serverName))
        return;
    // We think this server is online. Check it has a znode up. Currently, a RS
    // registers an ephereral znode in zk. If not present, something is up. Maybe
    // HBASE-9593 where RS crashed AFTER reportForDuty but BEFORE it put up an ephemeral
    // znode.
    List<String> servers = null;
    try {
        servers = getRegionServersInZK(this.master.getZooKeeper());
    } catch (KeeperException ke) {
        LOG.warn("Failed to list regionservers", ke);
    // ZK is malfunctioning, don't hang here
    }
    boolean found = false;
    if (servers != null) {
        for (String serverNameAsStr : servers) {
            ServerName sn = ServerName.valueOf(serverNameAsStr);
            if (sn.equals(serverName)) {
                // Found a server up in zk.
                found = true;
                break;
            }
        }
    }
    if (!found) {
        LOG.warn("Online server " + serverName.toString() + " has no corresponding " + "ephemeral znode (Did it die before registering in zk?); " + "calling expire to clean it up!");
        expireServer(serverName);
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) IOException(java.io.IOException) FailedServerException(org.apache.hadoop.hbase.ipc.FailedServerException) KeeperException(org.apache.zookeeper.KeeperException) ConnectException(java.net.ConnectException)

Example 55 with ConnectException

use of java.net.ConnectException in project hbase by apache.

the class TestMetaTableLocator method testVerifyMetaRegionLocationFails.

/**
   * Test get of meta region fails properly if nothing to connect to.
   * @throws IOException
   * @throws InterruptedException
   * @throws KeeperException
   * @throws ServiceException
   */
@Test
public void testVerifyMetaRegionLocationFails() throws IOException, InterruptedException, KeeperException, ServiceException {
    ClusterConnection connection = Mockito.mock(ClusterConnection.class);
    ServiceException connectException = new ServiceException(new ConnectException("Connection refused"));
    final AdminProtos.AdminService.BlockingInterface implementation = Mockito.mock(AdminProtos.AdminService.BlockingInterface.class);
    Mockito.when(implementation.getRegionInfo((RpcController) Mockito.any(), (GetRegionInfoRequest) Mockito.any())).thenThrow(connectException);
    Mockito.when(connection.getAdmin(Mockito.any(ServerName.class))).thenReturn(implementation);
    RpcControllerFactory controllerFactory = Mockito.mock(RpcControllerFactory.class);
    Mockito.when(controllerFactory.newController()).thenReturn(Mockito.mock(HBaseRpcController.class));
    Mockito.when(connection.getRpcControllerFactory()).thenReturn(controllerFactory);
    ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis());
    MetaTableLocator.setMetaLocation(this.watcher, sn, RegionState.State.OPENING);
    assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, 100));
    MetaTableLocator.setMetaLocation(this.watcher, sn, RegionState.State.OPEN);
    assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, 100));
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) RpcControllerFactory(org.apache.hadoop.hbase.ipc.RpcControllerFactory) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Aggregations

ConnectException (java.net.ConnectException)253 IOException (java.io.IOException)110 Socket (java.net.Socket)57 Test (org.junit.Test)43 InetSocketAddress (java.net.InetSocketAddress)41 SocketTimeoutException (java.net.SocketTimeoutException)35 UnknownHostException (java.net.UnknownHostException)30 InetAddress (java.net.InetAddress)24 FileNotFoundException (java.io.FileNotFoundException)22 InterruptedIOException (java.io.InterruptedIOException)20 SocketException (java.net.SocketException)20 NoRouteToHostException (java.net.NoRouteToHostException)19 InputStreamReader (java.io.InputStreamReader)18 URL (java.net.URL)16 InputStream (java.io.InputStream)14 HttpURLConnection (java.net.HttpURLConnection)14 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)13 BufferedReader (java.io.BufferedReader)12 OutputStream (java.io.OutputStream)12 Exchange (org.apache.camel.Exchange)12