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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations