Search in sources :

Example 26 with KeyNotFoundException

use of org.apache.storm.generated.KeyNotFoundException in project storm by apache.

the class AsyncLocalizer method getBlobs.

/**
 * This function either returns the blobs in the existing cache or if they don't exist in the cache, it downloads them in parallel (up
 * to SUPERVISOR_BLOBSTORE_DOWNLOAD_THREAD_COUNT) and will block until all of them have been downloaded.
 */
List<LocalizedResource> getBlobs(List<LocalResource> localResources, PortAndAssignment pna, BlobChangingCallback cb) throws AuthorizationException, KeyNotFoundException, IOException {
    if ((boolean) conf.getOrDefault(Config.DISABLE_SYMLINKS, false)) {
        throw new WrappedKeyNotFoundException("symlinks are disabled so blobs cannot be downloaded.");
    }
    String user = pna.getOwner();
    ArrayList<LocalizedResource> results = new ArrayList<>();
    List<CompletableFuture<?>> futures = new ArrayList<>();
    try {
        for (LocalResource localResource : localResources) {
            String key = localResource.getBlobName();
            boolean uncompress = localResource.shouldUncompress();
            LocalizedResource lrsrc = uncompress ? getUserArchive(user, key) : getUserFile(user, key);
            // go off to blobstore and get it
            // assume dir passed in exists and has correct permission
            LOG.debug("fetching blob: {}", key);
            lrsrc.addReference(pna, localResource.needsCallback() ? cb : null);
            futures.add(downloadOrUpdate(lrsrc));
            results.add(lrsrc);
        }
        for (CompletableFuture<?> futureRsrc : futures) {
            futureRsrc.get();
        }
    } catch (ExecutionException e) {
        Utils.unwrapAndThrow(AuthorizationException.class, e);
        Utils.unwrapAndThrow(KeyNotFoundException.class, e);
        throw new IOException("Error getting blobs", e);
    } catch (RejectedExecutionException re) {
        throw new IOException("RejectedExecutionException: ", re);
    } catch (InterruptedException ie) {
        throw new IOException("Interrupted Exception", ie);
    }
    return results;
}
Also used : WrappedKeyNotFoundException(org.apache.storm.utils.WrappedKeyNotFoundException) AuthorizationException(org.apache.storm.generated.AuthorizationException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) CompletableFuture(java.util.concurrent.CompletableFuture) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) WrappedKeyNotFoundException(org.apache.storm.utils.WrappedKeyNotFoundException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException)

Example 27 with KeyNotFoundException

use of org.apache.storm.generated.KeyNotFoundException in project storm by apache.

the class LeaderListenerCallback method getTopologyDependencyKeys.

private Set<String> getTopologyDependencyKeys(Set<String> activeTopologyCodeKeys) {
    Set<String> activeTopologyDependencies = new TreeSet<>();
    Subject subject = ReqContext.context().subject();
    for (String activeTopologyCodeKey : activeTopologyCodeKeys) {
        try (InputStreamWithMeta blob = blobStore.getBlob(activeTopologyCodeKey, subject)) {
            byte[] blobContent = IOUtils.readFully(blob, new Long(blob.getFileLength()).intValue());
            StormTopology stormCode = Utils.deserialize(blobContent, StormTopology.class);
            if (stormCode.is_set_dependency_jars()) {
                activeTopologyDependencies.addAll(stormCode.get_dependency_jars());
            }
            if (stormCode.is_set_dependency_artifacts()) {
                activeTopologyDependencies.addAll(stormCode.get_dependency_artifacts());
            }
        } catch (AuthorizationException | KeyNotFoundException | IOException e) {
            LOG.error("Exception occurs while reading blob for key: " + activeTopologyCodeKey + ", exception: " + e, e);
            throw new RuntimeException("Exception occurs while reading blob for key: " + activeTopologyCodeKey + ", exception: " + e, e);
        }
    }
    return activeTopologyDependencies;
}
Also used : AuthorizationException(org.apache.storm.generated.AuthorizationException) StormTopology(org.apache.storm.generated.StormTopology) IOException(java.io.IOException) Subject(javax.security.auth.Subject) InputStreamWithMeta(org.apache.storm.blobstore.InputStreamWithMeta) TreeSet(java.util.TreeSet) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException)

Example 28 with KeyNotFoundException

use of org.apache.storm.generated.KeyNotFoundException in project storm by apache.

the class Nimbus method getResourcesForTopology.

private TopologyResources getResourcesForTopology(String topoId, StormBase base) throws NotAliveException, AuthorizationException, InvalidTopologyException, IOException {
    TopologyResources ret = idToResources.get().get(topoId);
    if (ret == null) {
        try {
            IStormClusterState state = stormClusterState;
            TopologyDetails details = readTopologyDetails(topoId, base);
            Assignment assignment = state.assignmentInfo(topoId, null);
            ret = new TopologyResources(details, assignment);
        } catch (KeyNotFoundException e) {
            // This can happen when a topology is first coming up
            // It's thrown by the blobstore code
            LOG.error("Failed to get topology details", e);
            ret = new TopologyResources();
        }
    }
    return ret;
}
Also used : Assignment(org.apache.storm.generated.Assignment) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) IStormClusterState(org.apache.storm.cluster.IStormClusterState) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException)

Aggregations

KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)28 AuthorizationException (org.apache.storm.generated.AuthorizationException)15 IOException (java.io.IOException)14 File (java.io.File)8 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)8 WrappedKeyNotFoundException (org.apache.storm.utils.WrappedKeyNotFoundException)8 KeeperException (org.apache.storm.shade.org.apache.zookeeper.KeeperException)5 Test (org.junit.Test)5 FileNotFoundException (java.io.FileNotFoundException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Subject (javax.security.auth.Subject)4 InputStreamWithMeta (org.apache.storm.blobstore.InputStreamWithMeta)4 IStormClusterState (org.apache.storm.cluster.IStormClusterState)4 NimbusInfo (org.apache.storm.nimbus.NimbusInfo)4 InterruptedIOException (java.io.InterruptedIOException)3 BindException (java.net.BindException)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 TreeSet (java.util.TreeSet)3