Search in sources :

Example 6 with ReadableBlobMeta

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

the class DependencyUploaderTest method uploadFilesWhichOneOfThemIsFailedToBeUploaded.

@Test
public void uploadFilesWhichOneOfThemIsFailedToBeUploaded() throws Exception {
    File mockFile = createTemporaryDummyFile();
    File mockFile2 = mock(File.class);
    when(mockFile2.getName()).thenReturn("dummy.jar");
    when(mockFile2.isFile()).thenReturn(true);
    when(mockFile2.exists()).thenReturn(true);
    when(mockFile2.getPath()).thenThrow(new RuntimeException("just for test!"));
    when(mockFile2.toPath()).thenThrow(new RuntimeException("just for test!"));
    String mockFileFileNameWithoutExtension = Files.getNameWithoutExtension(mockFile.getName());
    String mockFile2FileNameWithoutExtension = Files.getNameWithoutExtension(mockFile2.getName());
    // we skip uploading first one since we want to test rollback, not upload
    when(mockBlobStore.getBlobMeta(contains(mockFileFileNameWithoutExtension))).thenReturn(new ReadableBlobMeta());
    // we try uploading second one and it should be failed throwing RuntimeException
    when(mockBlobStore.getBlobMeta(contains(mockFile2FileNameWithoutExtension))).thenThrow(new KeyNotFoundException());
    List<File> dependencies = Lists.newArrayList(mockFile, mockFile2);
    try {
        sut.uploadFiles(dependencies, true);
        fail("Should pass RuntimeException");
    } catch (RuntimeException e) {
    // intended behavior
    }
    verify(mockBlobStore).getBlobMeta(contains(mockFileFileNameWithoutExtension));
    verify(mockBlobStore).getBlobMeta(contains(mockFile2FileNameWithoutExtension));
    verify(mockBlobStore).deleteBlob(contains(mockFileFileNameWithoutExtension));
    verify(mockBlobStore, never()).deleteBlob(contains(mockFile2FileNameWithoutExtension));
}
Also used : ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) Test(org.junit.Test)

Example 7 with ReadableBlobMeta

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

the class ClientBlobStoreTest method validatedBlobAcls.

private void validatedBlobAcls(String testKey) throws KeyNotFoundException, AuthorizationException {
    ReadableBlobMeta blobMeta = client.getBlobMeta(testKey);
    Assert.assertNotNull("The blob" + testKey + "does not have any readable blobMeta.", blobMeta);
    SettableBlobMeta settableBlob = blobMeta.get_settable();
    Assert.assertNotNull("The blob" + testKey + "does not have any settable blobMeta.", settableBlob);
}
Also used : ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Example 8 with ReadableBlobMeta

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

the class LocalFsBlobStore method getBlobMeta.

@Override
public ReadableBlobMeta getBlobMeta(String key, Subject who) throws AuthorizationException, KeyNotFoundException {
    validateKey(key);
    if (!checkForBlobOrDownload(key)) {
        checkForBlobUpdate(key);
    }
    SettableBlobMeta meta = getStoredBlobMeta(key);
    _aclHandler.validateUserCanReadMeta(meta.get_acl(), who, key);
    ReadableBlobMeta rbm = new ReadableBlobMeta();
    rbm.set_settable(meta);
    try {
        LocalFsBlobStoreFile pf = fbs.read(DATA_PREFIX + key);
        rbm.set_version(pf.getModTime());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return rbm;
}
Also used : ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) IOException(java.io.IOException) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Example 9 with ReadableBlobMeta

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

the class Blobstore method setAclCli.

private static void setAclCli(String[] args) throws Exception {
    Map<String, Object> cl = CLI.opt("s", "set", Collections.emptyList(), new AsAclParser()).arg("key", CLI.FIRST_WINS).parse(args);
    final String key = (String) cl.get("key");
    final List<AccessControl> setAcl = (List<AccessControl>) cl.get("s");
    ClientBlobStore.withConfiguredClient(new ClientBlobStore.WithBlobstore() {

        @Override
        public void run(ClientBlobStore blobStore) throws Exception {
            ReadableBlobMeta meta = blobStore.getBlobMeta(key);
            List<AccessControl> acl = meta.get_settable().get_acl();
            List<AccessControl> newAcl;
            if (setAcl != null && !setAcl.isEmpty()) {
                newAcl = setAcl;
            } else {
                newAcl = acl;
            }
            SettableBlobMeta newMeta = new SettableBlobMeta(newAcl);
            LOG.info("Setting ACL for {} to {}", key, generateAccessControlsInfo(newAcl));
            blobStore.setBlobMeta(key, newMeta);
        }
    });
}
Also used : ClientBlobStore(org.apache.storm.blobstore.ClientBlobStore) ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) AccessControl(org.apache.storm.generated.AccessControl) IOException(java.io.IOException) AuthorizationException(org.apache.storm.generated.AuthorizationException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta)

Example 10 with ReadableBlobMeta

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

the class LocalizerTest method testFailAcls.

@Test(expected = AuthorizationException.class)
public void testFailAcls() throws Exception {
    Map conf = new HashMap();
    // set clean time really high so doesn't kick in
    conf.put(Config.SUPERVISOR_LOCALIZER_CACHE_CLEANUP_INTERVAL_MS, 60 * 60 * 1000);
    String topo1 = "topo1";
    String key1 = "key1";
    Localizer localizer = new TestLocalizer(conf, baseDir.toString());
    ReadableBlobMeta rbm = new ReadableBlobMeta();
    // set acl so user doesn't have read access
    AccessControl acl = new AccessControl(AccessControlType.USER, BlobStoreAclHandler.ADMIN);
    acl.set_name(user1);
    rbm.set_settable(new SettableBlobMeta(Arrays.asList(acl)));
    when(mockblobstore.getBlobMeta(anyString())).thenReturn(rbm);
    when(mockblobstore.getBlob(key1)).thenReturn(new TestInputStreamWithMeta());
    File user1Dir = localizer.getLocalUserFileCacheDir(user1);
    assertTrue("failed to create user dir", user1Dir.mkdirs());
    // This should throw AuthorizationException because auth failed
    localizer.getBlob(new LocalResource(key1, false), user1, topo1, user1Dir);
}
Also used : ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) SettableBlobMeta(org.apache.storm.generated.SettableBlobMeta) File(java.io.File) AccessControl(org.apache.storm.generated.AccessControl) Test(org.junit.Test)

Aggregations

ReadableBlobMeta (org.apache.storm.generated.ReadableBlobMeta)14 SettableBlobMeta (org.apache.storm.generated.SettableBlobMeta)10 File (java.io.File)8 Test (org.junit.Test)7 IOException (java.io.IOException)4 KeyNotFoundException (org.apache.storm.generated.KeyNotFoundException)4 AccessControl (org.apache.storm.generated.AccessControl)2 AuthorizationException (org.apache.storm.generated.AuthorizationException)2 Matchers.anyString (org.mockito.Matchers.anyString)2 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 BlobStoreFile (org.apache.storm.blobstore.BlobStoreFile)1 ClientBlobStore (org.apache.storm.blobstore.ClientBlobStore)1 KeyAlreadyExistsException (org.apache.storm.generated.KeyAlreadyExistsException)1 NimbusInfo (org.apache.storm.nimbus.NimbusInfo)1 NimbusClient (org.apache.storm.utils.NimbusClient)1 TTransportException (org.apache.thrift.transport.TTransportException)1 KeeperException (org.apache.zookeeper.KeeperException)1