Search in sources :

Example 36 with TException

use of org.apache.thrift.TException in project hive by apache.

the class TUGIBasedProcessor method handleSetUGI.

private void handleSetUGI(TUGIContainingTransport ugiTrans, set_ugi<Iface> fn, TMessage msg, TProtocol iprot, TProtocol oprot) throws TException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    UserGroupInformation clientUgi = ugiTrans.getClientUGI();
    if (null != clientUgi) {
        throw new TException(new IllegalStateException("UGI is already set. Resetting is not " + "allowed. Current ugi is: " + clientUgi.getUserName()));
    }
    set_ugi_args args = fn.getEmptyArgsInstance();
    try {
        args.read(iprot);
    } catch (TProtocolException e) {
        iprot.readMessageEnd();
        TApplicationException x = new TApplicationException(TApplicationException.PROTOCOL_ERROR, e.getMessage());
        oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
        x.write(oprot);
        oprot.writeMessageEnd();
        oprot.getTransport().flush();
        return;
    }
    iprot.readMessageEnd();
    set_ugi_result result = fn.getResult(iface, args);
    List<String> principals = result.getSuccess();
    // Store the ugi in transport and then continue as usual.
    ugiTrans.setClientUGI(UserGroupInformation.createRemoteUser(principals.remove(principals.size() - 1)));
    oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.REPLY, msg.seqid));
    result.write(oprot);
    oprot.writeMessageEnd();
    oprot.getTransport().flush();
}
Also used : TException(org.apache.thrift.TException) ThriftHiveMetastore.set_ugi_result(org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.set_ugi_result) TMessage(org.apache.thrift.protocol.TMessage) ThriftHiveMetastore.set_ugi_args(org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore.set_ugi_args) TProtocolException(org.apache.thrift.protocol.TProtocolException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) TApplicationException(org.apache.thrift.TApplicationException)

Example 37 with TException

use of org.apache.thrift.TException in project storm by apache.

the class Utils method downloadResourcesAsSupervisorAttempt.

private static boolean downloadResourcesAsSupervisorAttempt(ClientBlobStore cb, String key, String localFile) {
    boolean isSuccess = false;
    try (FileOutputStream out = new FileOutputStream(localFile);
        InputStreamWithMeta in = cb.getBlob(key)) {
        long fileSize = in.getFileLength();
        byte[] buffer = new byte[1024];
        int len;
        int downloadFileSize = 0;
        while ((len = in.read(buffer)) >= 0) {
            out.write(buffer, 0, len);
            downloadFileSize += len;
        }
        isSuccess = (fileSize == downloadFileSize);
    } catch (TException | IOException e) {
        LOG.error("An exception happened while downloading {} from blob store.", localFile, e);
    }
    if (!isSuccess) {
        try {
            Files.deleteIfExists(Paths.get(localFile));
        } catch (IOException ex) {
            LOG.error("Failed trying to delete the partially downloaded {}", localFile, ex);
        }
    }
    return isSuccess;
}
Also used : TException(org.apache.thrift.TException) InputStreamWithMeta(org.apache.storm.blobstore.InputStreamWithMeta) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 38 with TException

use of org.apache.thrift.TException in project hive by apache.

the class TempletonControllerJob method buildHcatDelegationToken.

private String buildHcatDelegationToken(String user) throws IOException, InterruptedException, TException {
    final HiveConf c = new HiveConf();
    LOG.debug("Creating hive metastore delegation token for user " + user);
    final UserGroupInformation ugi = UgiFactory.getUgi(user);
    UserGroupInformation real = ugi.getRealUser();
    return real.doAs(new PrivilegedExceptionAction<String>() {

        @Override
        public String run() throws IOException, TException, InterruptedException {
            final IMetaStoreClient client = HCatUtil.getHiveMetastoreClient(c);
            return ugi.doAs(new PrivilegedExceptionAction<String>() {

                @Override
                public String run() throws IOException, TException, InterruptedException {
                    String u = ugi.getUserName();
                    return client.getDelegationToken(c.getUser(), u);
                }
            });
        }
    });
}
Also used : TException(org.apache.thrift.TException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) IOException(java.io.IOException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 39 with TException

use of org.apache.thrift.TException in project zeppelin by apache.

the class RemoteAngularObjectRegistry method removeAndNotifyRemoteProcess.

/**
   * When ZeppelinServer side code want to remove angularObject from the registry,
   * this method should be used instead of remove()
   * @param name
   * @param noteId
   * @param paragraphId
   * @return
   */
public AngularObject removeAndNotifyRemoteProcess(String name, String noteId, String paragraphId) {
    RemoteInterpreterProcess remoteInterpreterProcess = getRemoteInterpreterProcess();
    if (remoteInterpreterProcess == null || !remoteInterpreterProcess.isRunning()) {
        return super.remove(name, noteId, paragraphId);
    }
    Client client = null;
    boolean broken = false;
    try {
        client = remoteInterpreterProcess.getClient();
        client.angularObjectRemove(name, noteId, paragraphId);
        return super.remove(name, noteId, paragraphId);
    } catch (TException e) {
        broken = true;
        logger.error("Error", e);
    } catch (Exception e) {
        logger.error("Error", e);
    } finally {
        if (client != null) {
            remoteInterpreterProcess.releaseClient(client, broken);
        }
    }
    return null;
}
Also used : TException(org.apache.thrift.TException) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

Example 40 with TException

use of org.apache.thrift.TException in project zeppelin by apache.

the class RemoteAngularObjectRegistry method addAndNotifyRemoteProcess.

/**
   * When ZeppelinServer side code want to add angularObject to the registry,
   * this method should be used instead of add()
   * @param name
   * @param o
   * @param noteId
   * @return
   */
public AngularObject addAndNotifyRemoteProcess(String name, Object o, String noteId, String paragraphId) {
    Gson gson = new Gson();
    RemoteInterpreterProcess remoteInterpreterProcess = getRemoteInterpreterProcess();
    if (!remoteInterpreterProcess.isRunning()) {
        return super.add(name, o, noteId, paragraphId, true);
    }
    Client client = null;
    boolean broken = false;
    try {
        client = remoteInterpreterProcess.getClient();
        client.angularObjectAdd(name, noteId, paragraphId, gson.toJson(o));
        return super.add(name, o, noteId, paragraphId, true);
    } catch (TException e) {
        broken = true;
        logger.error("Error", e);
    } catch (Exception e) {
        logger.error("Error", e);
    } finally {
        if (client != null) {
            remoteInterpreterProcess.releaseClient(client, broken);
        }
    }
    return null;
}
Also used : TException(org.apache.thrift.TException) Gson(com.google.gson.Gson) Client(org.apache.zeppelin.interpreter.thrift.RemoteInterpreterService.Client) TException(org.apache.thrift.TException)

Aggregations

TException (org.apache.thrift.TException)381 IOException (java.io.IOException)164 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)57 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)48 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)40 Table (org.apache.hadoop.hive.metastore.api.Table)38 Map (java.util.Map)30 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)29 AuthorizationException (org.apache.storm.generated.AuthorizationException)27 Test (org.junit.Test)26 List (java.util.List)25 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)24 UnknownHostException (java.net.UnknownHostException)23 TProtocol (org.apache.thrift.protocol.TProtocol)23 FileNotFoundException (java.io.FileNotFoundException)22 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)22 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)21 LoginException (javax.security.auth.login.LoginException)21 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)20