Search in sources :

Example 11 with ReadableBlobMeta

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

the class DependencyUploaderTest method uploadArtifactsWhichOneOfThemIsFailedToBeUploaded.

@Test
public void uploadArtifactsWhichOneOfThemIsFailedToBeUploaded() throws Exception {
    String artifact = "group:artifact:1.0.0";
    String expectedBlobKeyForArtifact = "group-artifact-1.0.0.jar";
    File mockFile = createTemporaryDummyFile();
    String artifact2 = "group:artifact2:2.0.0";
    String expectedBlobKeyForArtifact2 = "group-artifact2-2.0.0.jar";
    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!"));
    // we skip uploading first one since we don't test upload for now
    when(mockBlobStore.getBlobMeta(contains(expectedBlobKeyForArtifact))).thenReturn(new ReadableBlobMeta());
    // we try uploading second one and it should be failed throwing RuntimeException
    when(mockBlobStore.getBlobMeta(contains(expectedBlobKeyForArtifact2))).thenThrow(new KeyNotFoundException());
    Map<String, File> artifacts = new LinkedHashMap<>();
    artifacts.put(artifact, mockFile);
    artifacts.put(artifact2, mockFile2);
    try {
        sut.uploadArtifacts(artifacts);
        fail("Should pass RuntimeException");
    } catch (RuntimeException e) {
    // intended behavior
    }
    verify(mockBlobStore).getBlobMeta(contains(expectedBlobKeyForArtifact));
    verify(mockBlobStore).getBlobMeta(contains(expectedBlobKeyForArtifact2));
    // never rollback
    verify(mockBlobStore, never()).deleteBlob(contains(expectedBlobKeyForArtifact));
    verify(mockBlobStore, never()).deleteBlob(contains(expectedBlobKeyForArtifact2));
}
Also used : ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 12 with ReadableBlobMeta

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

the class HdfsBlobStore method getBlobMeta.

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

Example 13 with ReadableBlobMeta

use of org.apache.storm.generated.ReadableBlobMeta 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;
    InputStreamWithMeta in;
    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);
            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) TTransportException(org.apache.thrift.transport.TTransportException) KeeperException(org.apache.zookeeper.KeeperException) KeyAlreadyExistsException(org.apache.storm.generated.KeyAlreadyExistsException) IOException(java.io.IOException) AuthorizationException(org.apache.storm.generated.AuthorizationException) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NimbusInfo(org.apache.storm.nimbus.NimbusInfo) KeyNotFoundException(org.apache.storm.generated.KeyNotFoundException)

Example 14 with ReadableBlobMeta

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

the class Utils method nimbusVersionOfBlob.

public static long nimbusVersionOfBlob(String key, ClientBlobStore cb) throws AuthorizationException, KeyNotFoundException {
    long nimbusBlobVersion = 0;
    ReadableBlobMeta metadata = cb.getBlobMeta(key);
    nimbusBlobVersion = metadata.get_version();
    return nimbusBlobVersion;
}
Also used : ReadableBlobMeta(org.apache.storm.generated.ReadableBlobMeta)

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