Search in sources :

Example 31 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class S3Signing method publicvalidation.

public S3Parameter publicvalidation() throws GWException {
    String uri = s3Parameter.getRequest().getRequestURI();
    String hostHeader = s3Parameter.getRequest().getHeader(HttpHeaders.HOST);
    String preuri = uriReconstructer(uri, hostHeader, Optional.fromNullable(s3Parameter.getVirtualHost()));
    String bucket;
    String[] path = null;
    if (preuri.startsWith(GWConstants.SLASH_WEBSITE)) {
        path = preuri.split(GWConstants.SLASH, 4);
        bucket = path[2];
        s3Parameter.setWebsite(true);
    } else {
        path = preuri.split(GWConstants.SLASH, 3);
        bucket = path[1];
        s3Parameter.setWebsite(false);
    }
    for (int i = 0; i < path.length; i++) {
        try {
            path[i] = URLDecoder.decode(path[i], GWConstants.CHARSET_UTF_8);
        } catch (UnsupportedEncodingException e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, GWConstants.LOG_S3SIGNING_UNSUPPORT_ENCODING_LANGUAGE, s3Parameter);
        }
    }
    if (preuri.startsWith(GWConstants.SLASH_WEBSITE)) {
        path = preuri.split(GWConstants.SLASH, 4);
    } else {
        path = preuri.split(GWConstants.SLASH, 3);
    }
    Bucket bucketInfo = null;
    ObjManager objManager = null;
    try {
        objManager = ObjManagerHelper.getInstance().getObjManager();
        bucketInfo = objManager.getBucket(bucket);
    } catch (ResourceNotFoundException e) {
        logger.info("bucket({}) is not fount in the db", bucket);
        throw new GWException(GWErrorCode.NO_SUCH_BUCKET, s3Parameter);
    } catch (SQLException e) {
        PrintStack.logging(logger, e);
    } catch (Exception e) {
        PrintStack.logging(logger, e);
    } finally {
        try {
            ObjManagerHelper.getInstance().returnObjManager(objManager);
        } catch (Exception e) {
            PrintStack.logging(logger, e);
        }
    }
    if (bucketInfo == null) {
        throw new GWException(GWErrorCode.INVALID_ACCESS_KEY_ID, s3Parameter);
    }
    S3User user = GWUtils.getDBInstance().getIdentityByID(bucketInfo.getUserId(), s3Parameter);
    if (user == null) {
        throw new GWException(GWErrorCode.INVALID_ACCESS_KEY_ID, s3Parameter);
    }
    s3Parameter.setUser(user);
    if (s3Parameter.isWebsite()) {
        String[] enhancepath = new String[path.length - 1];
        for (int i = 0; i < path.length; i++) {
            if (i == 0) {
                enhancepath[i] = path[i];
                continue;
            }
            if (i == 1) {
                continue;
            }
            enhancepath[i - 1] = path[i];
            logger.debug(GWConstants.LOG_S3SIGNING_ENHANCE_PATH, i, enhancepath[i]);
        }
    // s3Parameter.path = enhancepath;
    } else {
    // s3Parameter.path = path;
    }
    return s3Parameter;
}
Also used : S3User(com.pspace.ifs.ksan.gw.identity.S3User) Bucket(com.pspace.ifs.ksan.objmanager.Bucket) SQLException(java.sql.SQLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ObjManager(com.pspace.ifs.ksan.objmanager.ObjManager) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) SQLException(java.sql.SQLException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 32 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class MongoDataRepository method getObjectWithUploadIdPart.

@Override
public Metadata getObjectWithUploadIdPart(String diskPoolId, String uploadId, int partNo) throws SQLException {
    MongoCollection<Document> multip;
    multip = getMultiPartUploadCollection();
    if (multip == null)
        return null;
    FindIterable fit = multip.find(Filters.eq(UPLOADID, uploadId));
    Iterator it = fit.iterator();
    if (!(it.hasNext()))
        return null;
    Metadata mt;
    DISK pdsk;
    Document doc = (Document) it.next();
    String bucketName = doc.getString(BUCKETNAME);
    String objkey = doc.getString(OBJKEY);
    String acl = doc.getString(ACL);
    String meta = doc.getString(META);
    String etag = doc.getString(ETAG);
    long size = doc.getLong(SIZE);
    String pdiskId = doc.getString(PDISKID);
    try {
        pdsk = pdiskId != null ? obmCache.getDiskWithId(diskPoolId, pdiskId) : new DISK();
    } catch (ResourceNotFoundException ex) {
        pdsk = new DISK();
    }
    mt = new Metadata(bucketName, objkey);
    mt.set(etag, "", meta, acl, size);
    mt.setPrimaryDisk(pdsk);
    mt.setReplicaDISK(new DISK());
    return mt;
}
Also used : Iterator(java.util.Iterator) FindIterable(com.mongodb.client.FindIterable) Document(org.bson.Document) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Example 33 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class ObjManager method createBucket.

/**
 * @param bucketName  name of the bucket containing the objects.
 * @param delimiter   A string used to group objects keys
 * @param startAfter  key to start with when listing objects in a bucket.
 * @param maxKeys     maximum number of keys returned.
 * @param prefix      return keys that begin with the prefix
 * @return
 */
/*public Document listObjects(String bucketName, String delimiter, String startAfter, int maxKeys, String prefix){
        Document res;
        ListObject lo = new ListObject(dbm, bucketName, delimiter, startAfter, maxKeys, prefix);
        res = lo.excute();
        //Element root = res.getDocumentElement();
        //logger.debug("res : >" + root.getTagName());
        logger.debug("result : >" + lo);
        return res;
    }*/
/**
 * @param bucketName  name of the bucket containing the objects.
 * @param delimiter   A string used to group objects keys
 * @param startAfter  key to start with when listing objects in a bucket.
 * @param maxKeys     maximum number of keys returned.
 * @param prefix      return keys that begin with the prefix
 * @return
 */
/*public ObjectListParameter getListObjects(String bucketName, String delimiter, String startAfter, int maxKeys, String prefix) {
        ObjectListParameter objectListParameter = null;
        
        ListObject lo = new ListObject(dbm, bucketName, delimiter, startAfter, maxKeys, prefix);
        objectListParameter = lo.executeDirect();
        
        return objectListParameter;
    }*/
/**
 * @param bucketName  name of the bucket containing the objects.
 * @param delimiter   A string used to group objects keys
 * @param startAfter  key to start with when listing objects in a bucket.
 * @param maxKeys     maximum number of keys returned.
 * @param prefix      return keys that begin with the prefix
 * @return
 */
/*public ObjectListParameter getListObjectsVersions(String bucketName, String delimiter, String startAfter, String startAfterVersionId, int maxKeys, String prefix) {
        ObjectListParameter objectListParameter = null;
        
        ListObject lo = new ListObject(dbm, bucketName, delimiter, startAfter, startAfterVersionId, maxKeys, prefix);
        objectListParameter = lo.executeDirect();
        
        return objectListParameter;
    }*/
/**
 * Create bucket if it is not exist
 * @param bucketName bucket name
 * @param userId the user uniquely identifying name
 * @param acl
 * @return 0 for success or negative number for error
 * @throws ResourceAlreadyExistException
 * @throws ResourceNotFoundException
 */
public int createBucket(String bucketName, String userName, String userId, String acl, String encryption, String objectlock) throws ResourceAlreadyExistException, ResourceNotFoundException {
    Bucket bt;
    try {
        bt = getBucket(bucketName);
        if (bt != null)
            throw new ResourceAlreadyExistException("Bucket (" + bucketName + ") already exist in the system!");
        bt = dbm.selectBucket(bucketName);
        if (bt != null) {
            obmCache.setBucketInCache(bt);
            throw new ResourceAlreadyExistException("Bucket (" + bucketName + ") already exist in the system!");
        }
    } catch (SQLException | ResourceNotFoundException ex) {
        bt = new Bucket();
        bt.setName(bucketName);
        bt.setUserId(userId);
        bt.setAcl(acl);
        bt.setEncryption(encryption);
        bt.setObjectLock(objectlock);
        try {
            bt = dbm.getUserDiskPool(bt);
        } catch (SQLException ex1) {
            throw new ResourceNotFoundException("User(" + userId + ") not assocated with diskpool. Please create user to diskpool assocation first!");
        }
        bt = dbm.insertBucket(bt);
        obmCache.setBucketInCache(bt);
    }
    return 0;
}
Also used : ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) SQLException(java.sql.SQLException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Example 34 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class S3Request method getBucket.

protected Bucket getBucket(String bucket) throws GWException {
    Bucket bucketInfo = null;
    try {
        setObjManager();
        bucketInfo = objManager.getBucket(bucket);
    } catch (ResourceNotFoundException e) {
        return null;
    } catch (Exception e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        try {
            releaseObjManager();
        } catch (Exception e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    return bucketInfo;
}
Also used : Bucket(com.pspace.ifs.ksan.objmanager.Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) XMLStreamException(javax.xml.stream.XMLStreamException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 35 with ResourceNotFoundException

use of com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException in project ksan by infinistor.

the class S3Request method getBucketVersioning.

protected String getBucketVersioning(String bucket) throws GWException {
    String versioningStatus = null;
    try {
        setObjManager();
        versioningStatus = objManager.getBucketVersioning(bucket);
    } catch (ResourceNotFoundException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.NO_SUCH_BUCKET, s3Parameter);
    } catch (Exception e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        try {
            releaseObjManager();
        } catch (Exception e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    return versioningStatus;
}
Also used : GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) XMLStreamException(javax.xml.stream.XMLStreamException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Aggregations

ResourceNotFoundException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)36 ResourceAlreadyExistException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException)11 SQLException (java.sql.SQLException)11 GWException (com.pspace.ifs.ksan.gw.exception.GWException)10 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)8 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)8 XMLStreamException (javax.xml.stream.XMLStreamException)8 IOException (java.io.IOException)6 InvalidParameterException (java.security.InvalidParameterException)5 Document (org.bson.Document)5 AllServiceOfflineException (com.pspace.ifs.ksan.objmanager.ObjManagerException.AllServiceOfflineException)4 Iterator (java.util.Iterator)4 Bucket (com.pspace.ifs.ksan.objmanager.Bucket)3 ArrayList (java.util.ArrayList)3 FindIterable (com.mongodb.client.FindIterable)2 MQResponse (com.pspace.ifs.ksan.mq.MQResponse)2 ObjManager (com.pspace.ifs.ksan.objmanager.ObjManager)2 ObjManagerUtil (com.pspace.ifs.ksan.objmanager.ObjManagerUtil)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2