Example usage for org.apache.hadoop.ipc RemoteException unwrapRemoteException

List of usage examples for org.apache.hadoop.ipc RemoteException unwrapRemoteException

Introduction

In this page you can find the example usage for org.apache.hadoop.ipc RemoteException unwrapRemoteException.

Prototype

public IOException unwrapRemoteException() 

Source Link

Document

Instantiate and return the exception wrapped up by this remote exception.

Usage

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

public void modifyCacheDirective(CacheDirectiveInfo info, EnumSet<CacheFlag> flags) throws IOException {
    checkOpen();/*from  w  ww.j  av a 2  s  .co m*/
    TraceScope scope = Trace.startSpan("modifyCacheDirective", traceSampler);
    try {
        namenode.modifyCacheDirective(info, flags);
    } catch (RemoteException re) {
        throw re.unwrapRemoteException();
    } finally {
        scope.close();
    }
}

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

public void removeCacheDirective(long id) throws IOException {
    checkOpen();// w  w w  . java 2  s  . c om
    TraceScope scope = Trace.startSpan("removeCacheDirective", traceSampler);
    try {
        namenode.removeCacheDirective(id);
    } catch (RemoteException re) {
        throw re.unwrapRemoteException();
    } finally {
        scope.close();
    }
}

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

public void addCachePool(CachePoolInfo info) throws IOException {
    checkOpen();//from www . j  av  a 2  s.  com
    TraceScope scope = Trace.startSpan("addCachePool", traceSampler);
    try {
        namenode.addCachePool(info);
    } catch (RemoteException re) {
        throw re.unwrapRemoteException();
    } finally {
        scope.close();
    }
}

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

public void modifyCachePool(CachePoolInfo info) throws IOException {
    checkOpen();/*from w  ww. ja  va 2s.  c o  m*/
    TraceScope scope = Trace.startSpan("modifyCachePool", traceSampler);
    try {
        namenode.modifyCachePool(info);
    } catch (RemoteException re) {
        throw re.unwrapRemoteException();
    } finally {
        scope.close();
    }
}

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

public void removeCachePool(String poolName) throws IOException {
    checkOpen();/* w ww .  j a  v  a  2 s  .  com*/
    TraceScope scope = Trace.startSpan("removeCachePool", traceSampler);
    try {
        namenode.removeCachePool(poolName);
    } catch (RemoteException re) {
        throw re.unwrapRemoteException();
    } finally {
        scope.close();
    }
}

From source file:common.DataNode.java

License:Apache License

/**
 * Convenience method, which unwraps RemoteException.
 * @throws IOException not a RemoteException.
 *//*w  w w  .  ja  va2  s. c  o m*/
private static ReplicaRecoveryInfo callInitReplicaRecovery(InterDatanodeProtocol datanode,
        RecoveringBlock rBlock) throws IOException {
    try {
        return datanode.initReplicaRecovery(rBlock);
    } catch (RemoteException re) {
        throw re.unwrapRemoteException();
    }
}

From source file:org.apache.storm.hdfs.spout.TestHdfsSemantics.java

License:Apache License

@Test
public void testAppendSemantics() throws Exception {
    //1 try to append to an open file
    Path file1 = new Path(dir.toString() + Path.SEPARATOR_CHAR + "file1");
    FSDataOutputStream os1 = fs.create(file1, false);
    try {//  w w w .  j  av a  2s  .  c  o  m
        fs.append(file1); // should fail
        Assert.assertTrue("Append did not throw an exception", false);
    } catch (RemoteException e) {
        // expecting AlreadyBeingCreatedException inside RemoteException
        Assert.assertEquals(AlreadyBeingCreatedException.class, e.unwrapRemoteException().getClass());
    }

    //2 try to append to a closed file
    os1.close();
    FSDataOutputStream os2 = fs.append(file1); // should pass
    os2.close();
}

From source file:org.apache.storm.hdfs.spout.TestHdfsSemantics.java

License:Apache License

@Test
public void testDoubleCreateSemantics() throws Exception {
    //1 create an already existing open file w/o override flag
    Path file1 = new Path(dir.toString() + Path.SEPARATOR_CHAR + "file1");
    FSDataOutputStream os1 = fs.create(file1, false);
    try {/*w w w . ja va 2  s .c o m*/
        fs.create(file1, false); // should fail
        Assert.assertTrue("Create did not throw an exception", false);
    } catch (RemoteException e) {
        Assert.assertEquals(AlreadyBeingCreatedException.class, e.unwrapRemoteException().getClass());
    }
    //2 close file and retry creation
    os1.close();
    try {
        fs.create(file1, false); // should still fail
    } catch (FileAlreadyExistsException e) {
        // expecting this exception
    }

    //3 delete file and retry creation
    fs.delete(file1, false);
    FSDataOutputStream os2 = fs.create(file1, false); // should pass
    Assert.assertNotNull(os2);
    os2.close();
}

From source file:rpc.TestRPC.java

License:Apache License

@Test
public void testErrorMsgForInsecureClient() throws IOException {
    Configuration serverConf = new Configuration(conf);
    SecurityUtil.setAuthenticationMethod(AuthenticationMethod.KERBEROS, serverConf);
    UserGroupInformation.setConfiguration(serverConf);

    final Server server = new RPC.Builder(serverConf).setProtocol(TestProtocol.class)
            .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true)
            .build();/*www  .  ja va 2  s  .  co m*/
    server.start();

    UserGroupInformation.setConfiguration(conf);
    boolean succeeded = false;
    final InetSocketAddress addr = NetUtils.getConnectAddress(server);
    TestProtocol proxy = null;
    try {
        proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf);
        proxy.echo("");
    } catch (RemoteException e) {
        LOG.info("LOGGING MESSAGE: " + e.getLocalizedMessage());
        assertTrue(e.unwrapRemoteException() instanceof AccessControlException);
        succeeded = true;
    } finally {
        server.stop();
        if (proxy != null) {
            RPC.stopProxy(proxy);
        }
    }
    assertTrue(succeeded);

    conf.setInt(CommonConfigurationKeys.IPC_SERVER_RPC_READ_THREADS_KEY, 2);

    UserGroupInformation.setConfiguration(serverConf);
    final Server multiServer = new RPC.Builder(serverConf).setProtocol(TestProtocol.class)
            .setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0).setNumHandlers(5).setVerbose(true)
            .build();
    multiServer.start();
    succeeded = false;
    final InetSocketAddress mulitServerAddr = NetUtils.getConnectAddress(multiServer);
    proxy = null;
    try {
        UserGroupInformation.setConfiguration(conf);
        proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, mulitServerAddr, conf);
        proxy.echo("");
    } catch (RemoteException e) {
        LOG.info("LOGGING MESSAGE: " + e.getLocalizedMessage());
        assertTrue(e.unwrapRemoteException() instanceof AccessControlException);
        succeeded = true;
    } finally {
        multiServer.stop();
        if (proxy != null) {
            RPC.stopProxy(proxy);
        }
    }
    assertTrue(succeeded);
}