use of javax.naming.ServiceUnavailableException in project hbase by apache.
the class TestJMXConnectorServer method testRSConnectorServerWhenStopRegionServer.
/**
* This tests to validate the RegionServer's ConnectorServer after unauthorised stopRegionServer
* call.
*/
@Test(timeout = 180000)
public void testRSConnectorServerWhenStopRegionServer() throws Exception {
conf.set(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY, JMXListener.class.getName() + "," + MyAccessController.class.getName());
conf.setInt("regionserver.rmi.registry.port", rmiRegistryPort);
UTIL.startMiniCluster();
admin = UTIL.getConnection().getAdmin();
hasAccess = false;
ServerName serverName = UTIL.getHBaseCluster().getRegionServer(0).getServerName();
LOG.info("Stopping Region Server...");
admin.stopRegionServer(serverName.getHostname() + ":" + serverName.getPort());
// Check whether Region Sever JMX Connector server can be connected
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
} catch (IOException e) {
if (e.getCause() instanceof ServiceUnavailableException) {
Assert.fail("Can't connect to Region Server ConnectorServer.");
}
}
Assert.assertNotNull("JMXConnector should not be null.", connector);
connector.close();
}
use of javax.naming.ServiceUnavailableException in project hbase by apache.
the class TestJMXConnectorServer method testHMConnectorServerWhenShutdownCluster.
/**
* This tests to validate the HMaster's ConnectorServer after unauthorised shutdown call.
*/
@Test(timeout = 180000)
public void testHMConnectorServerWhenShutdownCluster() throws Exception {
conf.set(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, JMXListener.class.getName() + "," + MyAccessController.class.getName());
conf.setInt("master.rmi.registry.port", rmiRegistryPort);
UTIL.startMiniCluster();
admin = UTIL.getConnection().getAdmin();
boolean accessDenied = false;
try {
hasAccess = false;
LOG.info("Stopping HMaster...");
admin.shutdown();
} catch (AccessDeniedException e) {
LOG.error("Exception occured while stopping HMaster. ", e);
accessDenied = true;
}
Assert.assertTrue(accessDenied);
// Check whether HMaster JMX Connector server can be connected
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(JMXListener.buildJMXServiceURL(rmiRegistryPort, rmiRegistryPort));
} catch (IOException e) {
if (e.getCause() instanceof ServiceUnavailableException) {
Assert.fail("Can't connect to HMaster ConnectorServer.");
}
}
Assert.assertNotNull("JMXConnector should not be null.", connector);
connector.close();
}
use of javax.naming.ServiceUnavailableException in project tdi-studio-se by Talend.
the class DynamicsCRMClient method getAccessToken.
protected AuthenticationResult getAccessToken() throws ServiceUnavailableException {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(clientConfiguration.getAuthoryEndpoint(), false, service);
Proxy proxy = getProxy();
if (proxy != null) {
context.setProxy(proxy);
}
Future<AuthenticationResult> future = context.acquireToken(clientConfiguration.getResource(), clientConfiguration.getClientId(), clientConfiguration.getUserName(), clientConfiguration.getPassword(), null);
result = future.get();
} catch (Exception e) {
throw new ServiceUnavailableException(e.getMessage());
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException("Authenticated failed! Please check your configuration!");
}
return result;
}
use of javax.naming.ServiceUnavailableException in project tdi-studio-se by Talend.
the class DynamicsCRMClient method createAndExecuteRequest.
/**
* Created and executes a request
*
* @param uri the request URI
* @param httpEntity the entity to send.
* @param method HTTP method
*
* @return the response to the request.
* @throws ServiceUnavailableException
*/
protected HttpResponse createAndExecuteRequest(URI uri, HttpEntity httpEntity, HttpMethod method) throws ServiceUnavailableException {
boolean hasRetried = false;
while (true) {
try {
httpClient = (DefaultHttpClient) httpClientFactory.create(null, null);
HttpRequestBase request = null;
if (method == HttpMethod.POST) {
request = new HttpPost(uri);
} else if (method == HttpMethod.PATCH) {
request = new HttpPatch(uri);
} else if (method == HttpMethod.DELETE) {
request = new HttpDelete(uri);
} else {
throw new HttpClientException("Unsupported operation:" + method);
}
request.addHeader(HttpHeader.AUTHORIZATION, "Bearer " + authResult.getAccessToken());
if (request instanceof HttpEntityEnclosingRequestBase) {
((HttpEntityEnclosingRequestBase) request).setEntity(httpEntity);
}
HttpResponse response = httpClient.execute(request);
if (isResponseSuccess(response.getStatusLine().getStatusCode())) {
request.releaseConnection();
EntityUtils.consume(response.getEntity());
return response;
} else {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED && !hasRetried) {
refreshToken();
hasRetried = true;
continue;
}
HttpEntity entity = response.getEntity();
String message = null;
if (entity != null) {
message = odataClient.getDeserializer(ContentType.JSON).toError(entity.getContent()).getMessage();
} else {
message = response.getStatusLine().getReasonPhrase();
}
throw new HttpClientException(message);
}
} catch (Exception e) {
throw new HttpClientException(e);
}
}
}
use of javax.naming.ServiceUnavailableException in project jdk8u_jdk by JetBrains.
the class Connection method readReply.
/**
* Reads a reply; waits until one is ready.
*/
BerDecoder readReply(LdapRequest ldr) throws IOException, NamingException {
BerDecoder rber;
// Track down elapsed time to workaround spurious wakeups
long elapsedMilli = 0;
long elapsedNano = 0;
while (((rber = ldr.getReplyBer()) == null) && (readTimeout <= 0 || elapsedMilli < readTimeout)) {
try {
// If socket closed, don't even try
synchronized (this) {
if (sock == null) {
throw new ServiceUnavailableException(host + ":" + port + "; socket closed");
}
}
synchronized (ldr) {
// check if condition has changed since our last check
rber = ldr.getReplyBer();
if (rber == null) {
if (readTimeout > 0) {
// Socket read timeout is specified
long beginNano = System.nanoTime();
// will be woken up before readTimeout if reply is
// available
ldr.wait(readTimeout - elapsedMilli);
elapsedNano += (System.nanoTime() - beginNano);
elapsedMilli += elapsedNano / 1000_000;
elapsedNano %= 1000_000;
} else {
// no timeout is set so we wait infinitely until
// a response is received
// https://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-ldap.html#PROP
ldr.wait();
}
} else {
break;
}
}
} catch (InterruptedException ex) {
throw new InterruptedNamingException("Interrupted during LDAP operation");
}
}
if ((rber == null) && (elapsedMilli >= readTimeout)) {
abandonRequest(ldr, null);
throw new NamingException("LDAP response read timed out, timeout used:" + readTimeout + "ms.");
}
return rber;
}
Aggregations