Search in sources :

Example 16 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.

the class S3Backend method touchAsync.

@Override
public void touchAsync(final DataIdentifier identifier, final long minModifiedDate, final AsyncTouchCallback callback) throws DataStoreException {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        if (callback == null) {
            throw new IllegalArgumentException("callback parameter cannot be null in touchAsync");
        }
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        asyncWriteExecuter.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    touch(identifier, minModifiedDate);
                    callback.onSuccess(new AsyncTouchResult(identifier));
                } catch (DataStoreException e) {
                    AsyncTouchResult result = new AsyncTouchResult(identifier);
                    result.setException(e);
                    callback.onFailure(result);
                }
            }
        });
    } catch (Exception e) {
        if (callback != null) {
            callback.onAbort(new AsyncTouchResult(identifier));
        }
        throw new DataStoreException("Cannot touch the record " + identifier.toString(), e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) AsyncTouchResult(org.apache.jackrabbit.core.data.AsyncTouchResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) IOException(java.io.IOException)

Example 17 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.

the class S3Backend method write.

private void write(DataIdentifier identifier, File file, boolean asyncUpload, AsyncUploadCallback callback) throws DataStoreException {
    String key = getKeyName(identifier);
    ObjectMetadata objectMetaData = null;
    long start = System.currentTimeMillis();
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        // check if the same record already exists
        try {
            objectMetaData = s3service.getObjectMetadata(bucket, key);
        } catch (AmazonServiceException ase) {
            if (!(ase.getStatusCode() == 404 || ase.getStatusCode() == 403)) {
                throw ase;
            }
        }
        if (objectMetaData != null) {
            long l = objectMetaData.getContentLength();
            if (l != file.length()) {
                throw new DataStoreException("Collision: " + key + " new length: " + file.length() + " old length: " + l);
            }
            LOG.debug("[{}]'s exists, lastmodified = [{}]", key, objectMetaData.getLastModified().getTime());
            CopyObjectRequest copReq = new CopyObjectRequest(bucket, key, bucket, key);
            copReq.setNewObjectMetadata(objectMetaData);
            Copy copy = tmx.copy(s3ReqDecorator.decorate(copReq));
            try {
                copy.waitForCopyResult();
                LOG.debug("lastModified of [{}] updated successfully.", identifier);
                if (callback != null) {
                    callback.onSuccess(new AsyncUploadResult(identifier, file));
                }
            } catch (Exception e2) {
                AsyncUploadResult asyncUpRes = new AsyncUploadResult(identifier, file);
                asyncUpRes.setException(e2);
                if (callback != null) {
                    callback.onAbort(asyncUpRes);
                }
                throw new DataStoreException("Could not upload " + key, e2);
            }
        }
        if (objectMetaData == null) {
            try {
                // start multipart parallel upload using amazon sdk
                Upload up = tmx.upload(s3ReqDecorator.decorate(new PutObjectRequest(bucket, key, file)));
                // wait for upload to finish
                if (asyncUpload) {
                    up.addProgressListener(new S3UploadProgressListener(up, identifier, file, callback));
                    LOG.debug("added upload progress listener to identifier [{}]", identifier);
                } else {
                    up.waitForUploadResult();
                    LOG.debug("synchronous upload to identifier [{}] completed.", identifier);
                    if (callback != null) {
                        callback.onSuccess(new AsyncUploadResult(identifier, file));
                    }
                }
            } catch (Exception e2) {
                AsyncUploadResult asyncUpRes = new AsyncUploadResult(identifier, file);
                asyncUpRes.setException(e2);
                if (callback != null) {
                    callback.onAbort(asyncUpRes);
                }
                throw new DataStoreException("Could not upload " + key, e2);
            }
        }
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
    LOG.debug("write of [{}], length=[{}], in async mode [{}], in [{}]ms", new Object[] { identifier, file.length(), asyncUpload, (System.currentTimeMillis() - start) });
}
Also used : AsyncUploadResult(org.apache.jackrabbit.core.data.AsyncUploadResult) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) Upload(com.amazonaws.services.s3.transfer.Upload) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonClientException(com.amazonaws.AmazonClientException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) IOException(java.io.IOException) CopyObjectRequest(com.amazonaws.services.s3.model.CopyObjectRequest) Copy(com.amazonaws.services.s3.transfer.Copy) AmazonServiceException(com.amazonaws.AmazonServiceException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 18 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.

the class AzureBlobStoreBackend method addMetadataRecord.

@Override
public void addMetadataRecord(File input, String name) throws DataStoreException {
    if (null == input) {
        throw new NullPointerException("input");
    }
    if (Strings.isNullOrEmpty(name)) {
        throw new IllegalArgumentException("name");
    }
    long start = System.currentTimeMillis();
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        addMetadataRecordImpl(new FileInputStream(input), name, input.length());
        LOG.debug("Metadata record added. metadataName={} duration={}", name, (System.currentTimeMillis() - start));
    } catch (FileNotFoundException e) {
        throw new DataStoreException(e);
    } finally {
        if (null != contextClassLoader) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream)

Example 19 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.

the class AzureBlobStoreBackend method deleteRecord.

@Override
public void deleteRecord(DataIdentifier identifier) throws DataStoreException {
    if (null == identifier)
        throw new NullPointerException("identifier");
    String key = getKeyName(identifier);
    long start = System.currentTimeMillis();
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        boolean result = getAzureContainer().getBlockBlobReference(key).deleteIfExists();
        LOG.debug("Blob {}. identifier={} duration={}", result ? "deleted" : "delete requested, but it does not exist (perhaps already deleted)", key, (System.currentTimeMillis() - start));
    } catch (StorageException e) {
        LOG.info("Error deleting blob. identifier={}", key, e);
        throw new DataStoreException(e);
    } catch (URISyntaxException e) {
        throw new DataStoreException(e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) URISyntaxException(java.net.URISyntaxException) StorageException(com.microsoft.azure.storage.StorageException)

Example 20 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.

the class S3Backend method getLength.

@Override
public long getLength(DataIdentifier identifier) throws DataStoreException {
    long start = System.currentTimeMillis();
    String key = getKeyName(identifier);
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        ObjectMetadata object = s3service.getObjectMetadata(bucket, key);
        long length = object.getContentLength();
        LOG.debug("Identifier [{}]'s length = [{}] took [{}]ms.", new Object[] { identifier, length, (System.currentTimeMillis() - start) });
        return length;
    } catch (AmazonServiceException e) {
        throw new DataStoreException("Could not length of dataIdentifier " + identifier, e);
    } finally {
        if (contextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) AmazonServiceException(com.amazonaws.AmazonServiceException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)85 IOException (java.io.IOException)35 AmazonServiceException (com.amazonaws.AmazonServiceException)28 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)18 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)15 File (java.io.File)14 AmazonClientException (com.amazonaws.AmazonClientException)12 StorageException (com.microsoft.azure.storage.StorageException)11 InputStream (java.io.InputStream)9 URISyntaxException (java.net.URISyntaxException)9 RepositoryException (javax.jcr.RepositoryException)9 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)7 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)7 Copy (com.amazonaws.services.s3.transfer.Copy)7 Upload (com.amazonaws.services.s3.transfer.Upload)7 FileObject (org.apache.commons.vfs2.FileObject)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)7 BufferedInputStream (java.io.BufferedInputStream)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 S3Object (com.amazonaws.services.s3.model.S3Object)5