Search in sources :

Example 1 with AuthorizationException

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

the class BlobStoreAPIWordCountTopology method main.

public static void main(String[] args) {
    prepare();
    BlobStoreAPIWordCountTopology wc = new BlobStoreAPIWordCountTopology();
    try {
        File file = createFile(fileName);
        // Creating blob again before launching topology
        createBlobWithContent(key, store, file);
        // Blostore launch command with topology blobstore map
        // Here we are giving it a local name so that we can read from the file
        // bin/storm jar examples/storm-starter/storm-starter-topologies-0.11.0-SNAPSHOT.jar
        // org.apache.storm.starter.BlobStoreAPIWordCountTopology bl -c
        // topology.blobstore.map='{"key":{"localname":"blacklist.txt", "uncompress":"false"}}'
        wc.buildAndLaunchWordCountTopology(args);
        // Updating file few times every 5 seconds
        for (int i = 0; i < 10; i++) {
            updateBlobWithContent(key, store, updateFile(file));
            Utils.sleep(5000);
        }
    } catch (KeyAlreadyExistsException kae) {
        LOG.info("Key already exists {}", kae);
    } catch (AuthorizationException | KeyNotFoundException | IOException exp) {
        throw new RuntimeException(exp);
    }
}
Also used : AuthorizationException(org.apache.storm.generated.AuthorizationException) IOException(java.io.IOException) File(java.io.File) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException)

Example 2 with AuthorizationException

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

the class BlobStoreAclHandler method hasAnyPermissions.

/**
     * Validates if the user has any of the permissions
     * mentioned in the mask.
     * @param acl ACL for the key.
     * @param mask mask holds the cumulative value of
     * READ = 1, WRITE = 2 or ADMIN = 4 permissions.
     * mask = 1 implies READ privilege.
     * mask = 5 implies READ and ADMIN privileges.
     * @param who Is the user against whom the permissions
     * are validated for a key using the ACL and the mask.
     * @param key Key used to identify the blob.
     * @throws AuthorizationException
     */
public void hasAnyPermissions(List<AccessControl> acl, int mask, Subject who, String key) throws AuthorizationException {
    if (!doAclValidation) {
        return;
    }
    Set<String> user = constructUserFromPrincipals(who);
    LOG.debug("user {}", user);
    if (checkForValidUsers(who, mask)) {
        return;
    }
    for (AccessControl ac : acl) {
        int allowed = getAllowed(ac, user);
        LOG.debug(" user: {} allowed: {} key: {}", user, allowed, key);
        if ((allowed & mask) > 0) {
            return;
        }
    }
    throw new AuthorizationException(user + " does not have access to " + key);
}
Also used : AuthorizationException(org.apache.storm.generated.AuthorizationException) AccessControl(org.apache.storm.generated.AccessControl)

Example 3 with AuthorizationException

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

the class Nimbus method uploadChunk.

@SuppressWarnings("deprecation")
@Override
public void uploadChunk(String location, ByteBuffer chunk) throws AuthorizationException, TException {
    try {
        uploadChunkCalls.mark();
        checkAuthorization(null, null, "fileUpload");
        WritableByteChannel channel = uploaders.get(location);
        if (channel == null) {
            throw new RuntimeException("File for that location does not exist (or timed out)");
        }
        channel.write(chunk);
        uploaders.put(location, channel);
    } catch (Exception e) {
        LOG.warn("uploadChunk exception.", e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) WritableByteChannel(java.nio.channels.WritableByteChannel) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) InterruptedIOException(java.io.InterruptedIOException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Example 4 with AuthorizationException

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

the class Nimbus method uploadNewCredentials.

@Override
public void uploadNewCredentials(String topoName, Credentials credentials) throws NotAliveException, InvalidTopologyException, AuthorizationException, TException {
    try {
        uploadNewCredentialsCalls.mark();
        IStormClusterState state = stormClusterState;
        String topoId = toTopoId(topoName);
        if (topoId == null) {
            throw new NotAliveException(topoName + " is not alive");
        }
        Map<String, Object> topoConf = tryReadTopoConf(topoId, blobStore);
        if (credentials == null) {
            credentials = new Credentials(Collections.emptyMap());
        }
        checkAuthorization(topoName, topoConf, "uploadNewCredentials");
        synchronized (credUpdateLock) {
            state.setCredentials(topoId, credentials, topoConf);
        }
    } catch (Exception e) {
        LOG.warn("Upload Creds topology exception. (topology name='{}')", topoName, e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) NotAliveException(org.apache.storm.generated.NotAliveException) IStormClusterState(org.apache.storm.cluster.IStormClusterState) Credentials(org.apache.storm.generated.Credentials) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) InterruptedIOException(java.io.InterruptedIOException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Example 5 with AuthorizationException

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

the class Nimbus method downloadBlobChunk.

@SuppressWarnings("deprecation")
@Override
public ByteBuffer downloadBlobChunk(String session) throws AuthorizationException, TException {
    try {
        BufferInputStream is = blobDownloaders.get(session);
        if (is == null) {
            throw new RuntimeException("Blob for session " + session + " does not exist (or timed out)");
        }
        byte[] ret = is.read();
        if (ret.length == 0) {
            is.close();
            blobDownloaders.remove(session);
        } else {
            blobDownloaders.put(session, is);
        }
        LOG.debug("Sending {} bytes", ret.length);
        return ByteBuffer.wrap(ret);
    } catch (Exception e) {
        LOG.warn("download blob chunk exception.", e);
        if (e instanceof TException) {
            throw (TException) e;
        }
        throw new RuntimeException(e);
    }
}
Also used : BufferInputStream(org.apache.storm.utils.BufferInputStream) TException(org.apache.thrift.TException) AuthorizationException(org.apache.storm.generated.AuthorizationException) NotAliveException(org.apache.storm.generated.NotAliveException) InterruptedIOException(java.io.InterruptedIOException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlreadyAliveException(org.apache.storm.generated.AlreadyAliveException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) InvalidTopologyException(org.apache.storm.generated.InvalidTopologyException) BindException(java.net.BindException)

Aggregations

AuthorizationException (org.apache.storm.generated.AuthorizationException)36 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)26 IOException (java.io.IOException)25 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)21 TException (org.apache.thrift.TException)21 AlreadyAliveException (org.apache.storm.generated.AlreadyAliveException)20 InvalidTopologyException (org.apache.storm.generated.InvalidTopologyException)20 InterruptedIOException (java.io.InterruptedIOException)18 BindException (java.net.BindException)18 NotAliveException (org.apache.storm.generated.NotAliveException)18 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 List (java.util.List)8 Map (java.util.Map)8 IStormClusterState (org.apache.storm.cluster.IStormClusterState)7 ImmutableMap (com.google.common.collect.ImmutableMap)4 File (java.io.File)4 NodeInfo (org.apache.storm.generated.NodeInfo)4 BufferInputStream (org.apache.storm.utils.BufferInputStream)4 TimeCacheMap (org.apache.storm.utils.TimeCacheMap)4