Search in sources :

Example 1 with ServiceUnavailableException

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();
}
Also used : JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) Test(org.junit.Test)

Example 2 with ServiceUnavailableException

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();
}
Also used : AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) Test(org.junit.Test)

Example 3 with ServiceUnavailableException

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;
}
Also used : Proxy(java.net.Proxy) AuthenticationContext(com.microsoft.aad.adal4j.AuthenticationContext) ExecutorService(java.util.concurrent.ExecutorService) ServiceUnavailableException(javax.naming.ServiceUnavailableException) URISyntaxException(java.net.URISyntaxException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) ODataClientErrorException(org.apache.olingo.client.api.communication.ODataClientErrorException) HttpClientException(org.apache.olingo.client.api.http.HttpClientException) AuthenticationResult(com.microsoft.aad.adal4j.AuthenticationResult)

Example 4 with ServiceUnavailableException

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);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) HttpClientException(org.apache.olingo.client.api.http.HttpClientException) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) HttpPatch(org.apache.olingo.client.core.http.HttpPatch) URISyntaxException(java.net.URISyntaxException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) ODataClientErrorException(org.apache.olingo.client.api.communication.ODataClientErrorException) HttpClientException(org.apache.olingo.client.api.http.HttpClientException)

Example 5 with ServiceUnavailableException

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;
}
Also used : InterruptedNamingException(javax.naming.InterruptedNamingException) NamingException(javax.naming.NamingException) InterruptedNamingException(javax.naming.InterruptedNamingException) ServiceUnavailableException(javax.naming.ServiceUnavailableException)

Aggregations

ServiceUnavailableException (javax.naming.ServiceUnavailableException)17 NamingException (javax.naming.NamingException)9 IOException (java.io.IOException)7 URISyntaxException (java.net.URISyntaxException)5 JMXConnector (javax.management.remote.JMXConnector)4 AuthenticationException (javax.naming.AuthenticationException)4 InvalidNameException (javax.naming.InvalidNameException)4 NameNotFoundException (javax.naming.NameNotFoundException)4 File (java.io.File)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ConnectException (java.net.ConnectException)3 Properties (java.util.Properties)3 CommunicationException (javax.naming.CommunicationException)3 InitialContext (javax.naming.InitialContext)3 OperationNotSupportedException (javax.naming.OperationNotSupportedException)3 CommandLine (org.apache.commons.cli.CommandLine)3 CommandLineParser (org.apache.commons.cli.CommandLineParser)3 Options (org.apache.commons.cli.Options)3 ParseException (org.apache.commons.cli.ParseException)3 PosixParser (org.apache.commons.cli.PosixParser)3