Search in sources :

Example 11 with Blob

use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.

the class AbstractExternalStoreManagerTest method testUncachedFile.

@Test
public void testUncachedFile() throws Exception {
    ParsedMessage pm = ThreaderTest.getRootMessage();
    byte[] mimeBytes = TestUtil.readInputStream(pm.getRawInputStream());
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    StoreManager sm = StoreManager.getInstance();
    Blob blob = sm.storeIncoming(pm.getRawInputStream());
    StagedBlob staged = sm.stage(blob, mbox);
    MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
    mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
    Blob localBlob = mblob.getLocalBlob();
    InputStream stream = sm.getContent(localBlob);
    Assert.assertTrue("input stream external", stream instanceof BlobInputStream);
    if (sm instanceof ExternalStoreManager) {
        ((ExternalStoreManager) sm).clearCache();
    }
    blob.getFile().delete();
    Assert.assertFalse(blob.getFile().exists());
    //now get it again. this would bomb if it only looked in cache
    stream = sm.getContent(mblob.getLocalBlob());
    Assert.assertTrue("input stream external", stream instanceof ExternalBlobInputStream);
    ExternalBlobInputStream extStream = (ExternalBlobInputStream) stream;
    File file = extStream.getRootFile();
    Assert.assertTrue(file.exists());
    Assert.assertTrue("stream content = mime content", TestUtil.bytesEqual(mimeBytes, stream));
}
Also used : Blob(com.zimbra.cs.store.Blob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BlobInputStream(com.zimbra.cs.store.BlobInputStream) InputStream(java.io.InputStream) BlobInputStream(com.zimbra.cs.store.BlobInputStream) File(java.io.File) StoreManager(com.zimbra.cs.store.StoreManager) Test(org.junit.Test) AbstractStoreManagerTest(com.zimbra.cs.store.AbstractStoreManagerTest) ThreaderTest(com.zimbra.cs.mailbox.ThreaderTest)

Example 12 with Blob

use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.

the class ExternalBlobInputStream method getRootFile.

@Override
protected File getRootFile() throws IOException {
    File file = super.getRootFile();
    if (file != null && file.exists()) {
        return file;
    } else {
        ZimbraLog.store.debug("blob file no longer on disk, fetching from remote store");
        ExternalStoreManager sm = (ExternalStoreManager) StoreManager.getInstance();
        Blob blob = sm.getLocalBlob(mbox, locator, false);
        return blob.getFile();
    }
}
Also used : Blob(com.zimbra.cs.store.Blob) File(java.io.File)

Example 13 with Blob

use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.

the class ExternalMailboxBlob method getLocalBlob.

@Override
public Blob getLocalBlob() throws IOException {
    ExternalStoreManager sm = (ExternalStoreManager) StoreManager.getInstance();
    Blob blob = sm.getLocalBlob(getMailbox(), getLocator());
    setSize(blob.getRawSize());
    if (digest != null) {
        setDigest(blob.getDigest());
    }
    return blob;
}
Also used : Blob(com.zimbra.cs.store.Blob) MailboxBlob(com.zimbra.cs.store.MailboxBlob)

Example 14 with Blob

use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.

the class ExternalStoreManager method stage.

@Override
public StagedBlob stage(InputStream in, long actualSize, Mailbox mbox) throws ServiceException, IOException {
    if (actualSize < 0) {
        Blob blob = storeIncoming(in);
        try {
            return stage(blob, mbox);
        } finally {
            quietDelete(blob);
        }
    }
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        throw ServiceException.FAILURE("SHA-256 digest not found", e);
    }
    ByteUtil.PositionInputStream pin = new ByteUtil.PositionInputStream(new DigestInputStream(in, digest));
    try {
        String locator = writeStreamToStore(pin, actualSize, mbox);
        if (locator != null) {
            ZimbraLog.store.debug("wrote to locator %s", locator);
        } else {
            ZimbraLog.store.warn("blob staging returned null locator");
        }
        return new ExternalStagedBlob(mbox, ByteUtil.encodeFSSafeBase64(digest.digest()), pin.getPosition(), locator);
    } catch (IOException e) {
        throw ServiceException.FAILURE("unable to stage blob", e);
    }
}
Also used : Blob(com.zimbra.cs.store.Blob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) ByteUtil(com.zimbra.common.util.ByteUtil) DigestInputStream(java.security.DigestInputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest)

Example 15 with Blob

use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.

the class ExternalBlobConsistencyChecker method checkExternalBlob.

private void checkExternalBlob(Mailbox mbox, boolean checkSize, BlobInfo blobInfo, ExternalStoreManager sm) throws ServiceException {
    MailboxBlob mblob = sm.getMailboxBlob(mbox, blobInfo.itemId, blobInfo.version, blobInfo.path, false);
    if (mblob == null) {
        results.missingBlobs.put(blobInfo.itemId, blobInfo);
    } else {
        try {
            unexpectedBlobPaths.remove(mblob.getLocator());
            Blob blob = sm.getLocalBlob(mbox, mblob.getLocator(), false);
            if (blob == null) {
                results.missingBlobs.put(blobInfo.itemId, blobInfo);
            } else {
                //blob exists for the locator
                blobInfo.fileModContent = blobInfo.modContent;
                if (reportUsedBlobs) {
                    results.usedBlobs.put(blobInfo.itemId, blobInfo);
                }
                if (checkSize) {
                    blobInfo.fileSize = blob.getFile().length();
                    blobInfo.fileDataSize = getDataSize(blob.getFile(), blobInfo.dbSize);
                    if (blobInfo.dbSize != blobInfo.fileDataSize) {
                        results.incorrectSize.put(blobInfo.itemId, blobInfo);
                    }
                }
            }
        } catch (Exception e) {
            blobInfo.fetchException = e instanceof IOException ? (IOException) e : new IOException("Exception fetching blob", e);
            results.missingBlobs.put(blobInfo.itemId, blobInfo);
        }
    }
}
Also used : Blob(com.zimbra.cs.store.Blob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) IOException(java.io.IOException) IOException(java.io.IOException) ServiceException(com.zimbra.common.service.ServiceException)

Aggregations

Blob (com.zimbra.cs.store.Blob)27 MailboxBlob (com.zimbra.cs.store.MailboxBlob)18 Mailbox (com.zimbra.cs.mailbox.Mailbox)14 StagedBlob (com.zimbra.cs.store.StagedBlob)13 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)12 IOException (java.io.IOException)11 StoreManager (com.zimbra.cs.store.StoreManager)10 ServiceException (com.zimbra.common.service.ServiceException)9 InputStream (java.io.InputStream)7 Test (org.junit.Test)6 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)4 StoreIncomingBlob (com.zimbra.cs.redolog.op.StoreIncomingBlob)4 Rfc822ValidationInputStream (com.zimbra.common.mime.Rfc822ValidationInputStream)3 CopyInputStream (com.zimbra.common.util.CopyInputStream)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)3 ParsedMessageOptions (com.zimbra.cs.mime.ParsedMessageOptions)3 AbstractStoreManagerTest (com.zimbra.cs.store.AbstractStoreManagerTest)3 BlobInputStream (com.zimbra.cs.store.BlobInputStream)3