Search in sources :

Example 1 with TTransportException

use of org.apache.storm.thrift.transport.TTransportException in project storm by apache.

the class ReturnResults method execute.

@Override
public void execute(Tuple input) {
    String result = (String) input.getValue(0);
    String returnInfo = (String) input.getValue(1);
    if (returnInfo != null) {
        Map<String, Object> retMap;
        try {
            retMap = (Map<String, Object>) JSONValue.parseWithException(returnInfo);
        } catch (ParseException e) {
            LOG.error("Parseing returnInfo failed", e);
            collector.fail(input);
            return;
        }
        final String host = (String) retMap.get("host");
        final int port = ObjectReader.getInt(retMap.get("port"));
        String id = (String) retMap.get("id");
        DistributedRPCInvocations.Iface client;
        if (local) {
            client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host);
        } else {
            List server = new ArrayList() {

                {
                    add(host);
                    add(port);
                }
            };
            if (!clients.containsKey(server)) {
                try {
                    clients.put(server, new DRPCInvocationsClient(conf, host, port));
                } catch (TTransportException ex) {
                    throw new RuntimeException(ex);
                }
            }
            client = clients.get(server);
        }
        int retryCnt = 0;
        int maxRetries = 3;
        while (retryCnt < maxRetries) {
            retryCnt++;
            try {
                client.result(id, result);
                collector.ack(input);
                break;
            } catch (AuthorizationException aze) {
                LOG.error("Not authorized to return results to DRPC server", aze);
                collector.fail(input);
                throw new RuntimeException(aze);
            } catch (TException tex) {
                if (retryCnt >= maxRetries) {
                    LOG.error("Failed to return results to DRPC server", tex);
                    collector.fail(input);
                }
                reconnectClient((DRPCInvocationsClient) client);
            }
        }
    }
}
Also used : TException(org.apache.storm.thrift.TException) AuthorizationException(org.apache.storm.generated.AuthorizationException) ArrayList(java.util.ArrayList) DistributedRPCInvocations(org.apache.storm.generated.DistributedRPCInvocations) TTransportException(org.apache.storm.thrift.transport.TTransportException) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(org.apache.storm.shade.org.json.simple.parser.ParseException)

Example 2 with TTransportException

use of org.apache.storm.thrift.transport.TTransportException in project storm by apache.

the class TBackoffConnect method doConnectWithRetry.

public TTransport doConnectWithRetry(ITransportPlugin transportPlugin, TTransport underlyingTransport, String host, String asUser) throws IOException {
    boolean connected = false;
    TTransport transportResult = null;
    while (!connected) {
        try {
            transportResult = transportPlugin.connect(underlyingTransport, host, asUser);
            connected = true;
        } catch (TTransportException ex) {
            retryNext(ex);
        }
    }
    return transportResult;
}
Also used : TTransportException(org.apache.storm.thrift.transport.TTransportException) TTransport(org.apache.storm.thrift.transport.TTransport)

Example 3 with TTransportException

use of org.apache.storm.thrift.transport.TTransportException in project storm by apache.

the class NimbusClient method getConfiguredClientAs.

/**
 * Get a nimbus client as configured by conf.
 * @param conf the configuration to use.
 * @param asUser the user to impersonate (this does not always work).
 * @param timeout the timeout to use when connecting.
 * @return the client, don't forget to close it when done.
 */
public static NimbusClient getConfiguredClientAs(Map<String, Object> conf, String asUser, Integer timeout) {
    Nimbus.Iface override = _localOverrideClient;
    if (override != null) {
        return new NimbusClient(override);
    }
    Map<String, Object> fullConf = Utils.readStormConfig();
    fullConf.putAll(Utils.readCommandLineOpts());
    fullConf.putAll(conf);
    conf = fullConf;
    if (conf.containsKey(Config.STORM_DO_AS_USER)) {
        if (asUser != null && !asUser.isEmpty()) {
            LOG.warn("You have specified a doAsUser as param {} and a doAsParam as config, config will take precedence.", asUser, conf.get(Config.STORM_DO_AS_USER));
        }
        asUser = (String) conf.get(Config.STORM_DO_AS_USER);
    }
    if (asUser == null || asUser.isEmpty()) {
        // The user is not set so lets see what the request context is.
        ReqContext context = ReqContext.context();
        Principal principal = context.principal();
        asUser = principal == null ? null : principal.getName();
        LOG.debug("Will impersonate {} based off of request context.", asUser);
    }
    List<String> seeds = (List<String>) conf.get(Config.NIMBUS_SEEDS);
    for (String host : seeds) {
        int port = Integer.parseInt(conf.get(Config.NIMBUS_THRIFT_PORT).toString());
        NimbusSummary nimbusSummary;
        NimbusClient client = null;
        try {
            client = new NimbusClient(conf, host, port, timeout, asUser);
            nimbusSummary = client.getClient().getLeader();
            if (nimbusSummary != null) {
                String leaderNimbus = nimbusSummary.get_host() + ":" + nimbusSummary.get_port();
                if (shouldLogLeader(leaderNimbus)) {
                    LOG.info("Found leader nimbus : {}", leaderNimbus);
                }
                if (nimbusSummary.get_host().equals(host) && nimbusSummary.get_port() == port) {
                    NimbusClient ret = client;
                    client = null;
                    return ret;
                }
                try {
                    return new NimbusClient(conf, nimbusSummary.get_host(), nimbusSummary.get_port(), timeout, asUser);
                } catch (TTransportException e) {
                    throw new RuntimeException("Failed to create a nimbus client for the leader " + leaderNimbus, e);
                }
            }
        } catch (Exception e) {
            LOG.warn("Ignoring exception while trying to get leader nimbus info from " + host + ". will retry with a different seed host.", e);
            continue;
        } finally {
            if (client != null) {
                client.close();
            }
        }
        throw new NimbusLeaderNotFoundException("Could not find a nimbus leader, please try again after some time.");
    }
    throw new NimbusLeaderNotFoundException("Could not find leader nimbus from seed hosts " + seeds + ". " + "Did you specify a valid list of nimbus hosts for config " + Config.NIMBUS_SEEDS + "?");
}
Also used : TTransportException(org.apache.storm.thrift.transport.TTransportException) ReqContext(org.apache.storm.security.auth.ReqContext) NimbusSummary(org.apache.storm.generated.NimbusSummary) TTransportException(org.apache.storm.thrift.transport.TTransportException) Nimbus(org.apache.storm.generated.Nimbus) List(java.util.List) Principal(java.security.Principal)

Example 4 with TTransportException

use of org.apache.storm.thrift.transport.TTransportException in project storm by apache.

the class BlobStoreUtils method downloadMissingBlob.

// Download missing blobs from potential nimbodes
public static boolean downloadMissingBlob(Map<String, Object> conf, BlobStore blobStore, String key, Set<NimbusInfo> nimbusInfos) throws TTransportException {
    ReadableBlobMeta rbm;
    ClientBlobStore remoteBlobStore;
    boolean isSuccess = false;
    LOG.debug("Download blob NimbusInfos {}", nimbusInfos);
    for (NimbusInfo nimbusInfo : nimbusInfos) {
        if (isSuccess) {
            break;
        }
        LOG.debug("Download blob key: {}, NimbusInfo {}", key, nimbusInfo);
        try (NimbusClient client = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort(), null)) {
            rbm = client.getClient().getBlobMeta(key);
            remoteBlobStore = new NimbusBlobStore();
            remoteBlobStore.setClient(conf, client);
            try (InputStreamWithMeta in = remoteBlobStore.getBlob(key)) {
                blobStore.createBlob(key, in, rbm.get_settable(), getNimbusSubject());
            }
            // if key already exists while creating the blob else update it
            Iterator<String> keyIterator = blobStore.listKeys();
            while (keyIterator.hasNext()) {
                if (keyIterator.next().equals(key)) {
                    LOG.debug("Success creating key, {}", key);
                    isSuccess = true;
                    break;
                }
            }
        } catch (IOException | AuthorizationException exception) {
            throw new RuntimeException(exception);
        } catch (KeyAlreadyExistsException kae) {
            LOG.info("KeyAlreadyExistsException Key: {} {}", key, kae);
        } catch (KeyNotFoundException knf) {
            // Catching and logging KeyNotFoundException because, if
            // there is a subsequent update and delete, the non-leader
            // nimbodes might throw an exception.
            LOG.info("KeyNotFoundException Key: {} {}", key, knf);
        } catch (Exception exp) {
            // Logging an exception while client is connecting
            LOG.error("Exception {}", exp);
        }
    }
    if (!isSuccess) {
        LOG.error("Could not download the blob with key: {}", key);
    }
    return isSuccess;
}
Also used : AuthorizationException(org.apache.storm.generated.AuthorizationException) ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) NimbusClient(org.apache.storm.utils.NimbusClient) IOException(java.io.IOException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) WrappedKeyNotFoundException(org.apache.storm.utils.WrappedKeyNotFoundException) KeeperException(org.apache.storm.shade.org.apache.zookeeper.KeeperException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AuthorizationException(org.apache.storm.generated.AuthorizationException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) TTransportException(org.apache.storm.thrift.transport.TTransportException) NimbusInfo(org.apache.storm.nimbus.NimbusInfo) WrappedKeyNotFoundException(org.apache.storm.utils.WrappedKeyNotFoundException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException)

Example 5 with TTransportException

use of org.apache.storm.thrift.transport.TTransportException in project storm by apache.

the class BlobStoreUtils method downloadUpdatedBlob.

// Download updated blobs from potential nimbodes
public static boolean downloadUpdatedBlob(Map<String, Object> conf, BlobStore blobStore, String key, Set<NimbusInfo> nimbusInfos) throws TTransportException {
    ClientBlobStore remoteBlobStore;
    AtomicOutputStream out = null;
    boolean isSuccess = false;
    LOG.debug("Download blob NimbusInfos {}", nimbusInfos);
    for (NimbusInfo nimbusInfo : nimbusInfos) {
        if (isSuccess) {
            break;
        }
        try (NimbusClient client = new NimbusClient(conf, nimbusInfo.getHost(), nimbusInfo.getPort(), null)) {
            remoteBlobStore = new NimbusBlobStore();
            remoteBlobStore.setClient(conf, client);
            try (InputStreamWithMeta in = remoteBlobStore.getBlob(key)) {
                out = blobStore.updateBlob(key, getNimbusSubject());
                byte[] buffer = new byte[2048];
                int len = 0;
                while ((len = in.read(buffer)) > 0) {
                    out.write(buffer, 0, len);
                }
                out.close();
                out = null;
            }
            isSuccess = true;
        } catch (FileNotFoundException fnf) {
            LOG.warn("Blobstore file for key '{}' does not exist or got deleted before it could be downloaded.", key, fnf);
        } catch (IOException | AuthorizationException exception) {
            throw new RuntimeException(exception);
        } catch (KeyNotFoundException knf) {
            // Catching and logging KeyNotFoundException because, if
            // there is a subsequent update and delete, the non-leader
            // nimbodes might throw an exception.
            LOG.info("KeyNotFoundException", knf);
        } catch (Exception exp) {
            // Logging an exception while client is connecting
            LOG.error("Exception", exp);
        } finally {
            if (out != null) {
                try {
                    out.cancel();
                } catch (IOException e) {
                // Ignore.
                }
            }
        }
    }
    if (!isSuccess) {
        LOG.error("Could not update the blob with key: {}", key);
    }
    return isSuccess;
}
Also used : AuthorizationException(org.apache.storm.generated.AuthorizationException) FileNotFoundException(java.io.FileNotFoundException) NimbusClient(org.apache.storm.utils.NimbusClient) IOException(java.io.IOException) WrappedKeyNotFoundException(org.apache.storm.utils.WrappedKeyNotFoundException) KeeperException(org.apache.storm.shade.org.apache.zookeeper.KeeperException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AuthorizationException(org.apache.storm.generated.AuthorizationException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) TTransportException(org.apache.storm.thrift.transport.TTransportException) NimbusInfo(org.apache.storm.nimbus.NimbusInfo) WrappedKeyNotFoundException(org.apache.storm.utils.WrappedKeyNotFoundException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException)

Aggregations

TTransportException (org.apache.storm.thrift.transport.TTransportException)6 AuthorizationException (org.apache.storm.generated.AuthorizationException)4 List (java.util.List)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DistributedRPCInvocations (org.apache.storm.generated.DistributedRPCInvocations)2 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)2 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)2 NimbusInfo (org.apache.storm.nimbus.NimbusInfo)2 KeeperException (org.apache.storm.shade.org.apache.zookeeper.KeeperException)2 ParseException (org.apache.storm.shade.org.json.simple.parser.ParseException)2 TException (org.apache.storm.thrift.TException)2 NimbusClient (org.apache.storm.utils.NimbusClient)2 WrappedKeyNotFoundException (org.apache.storm.utils.WrappedKeyNotFoundException)2 Principal (java.security.Principal)1 DRPCInvocationsClient (org.apache.storm.drpc.DRPCInvocationsClient)1 Nimbus (org.apache.storm.generated.Nimbus)1 NimbusSummary (org.apache.storm.generated.NimbusSummary)1 ReadableBlobMeta (org.apache.storm.generated.ReadableBlobMeta)1