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);
}
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;
}
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;
}
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);
}
}
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));
}
Aggregations