use of com.pspace.ifs.ksan.objmanager.Bucket in project ksan by infinistor.
the class CBalance method moveWithSize.
public long moveWithSize(String bucketName, String srcDiskId, long amountToMove, String dstDiskId) throws ResourceNotFoundException, AllServiceOfflineException {
int ret;
int retry = 3;
long offset = 0;
long size;
long size_counter = 0;
List<Metadata> list;
List<Bucket> bList;
bList = getBucketList(bucketName);
do {
size = amountToMove / bList.size();
for (Bucket bucket : bList) {
list = getListOfObjects(bucket.getName(), srcDiskId, size, offset, dstDiskId);
Iterator<Metadata> it = list.iterator();
while (it.hasNext()) {
Metadata mt = it.next();
if (dstDiskId.isEmpty())
ret = moveSingleObject(bucket.getName(), mt.getObjId(), srcDiskId);
else
ret = moveSingleObject(bucket.getName(), mt.getObjId(), srcDiskId, dstDiskId);
if (ret > 0)
size_counter = size_counter + mt.getSize();
if (size_counter >= amountToMove)
return size_counter;
}
}
offset = offset + 100;
retry--;
} while (retry > 0);
return size_counter;
}
use of com.pspace.ifs.ksan.objmanager.Bucket in project ksan by infinistor.
the class PutBucketReplication method checkBucketReplication.
private void checkBucketReplication(String replicationXml) throws GWException {
XmlMapper xmlMapper = new XmlMapper();
ReplicationConfiguration rc;
try {
rc = xmlMapper.readValue(replicationXml, ReplicationConfiguration.class);
} catch (JsonMappingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
}
Map<String, String> id = new HashMap<String, String>();
if (rc.rules != null) {
logger.warn(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULES, rc.rules.toString());
for (Rule rl : rc.rules) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_ID, rl.id);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_PREFIX, rl.prefix);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_PRIORITY, rl.priority);
if (rl.id != null) {
if (rl.id.length() > 255) {
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
id.put(rl.id, rl.id);
} else {
// length is bounded by 7
byte[] array = new byte[7];
new Random().nextBytes(array);
String generatedString = new String(array, Charset.forName(GWConstants.CHARSET_UTF_8));
id.put(generatedString, generatedString);
}
if (rl.existingObjectReplication != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_EXISTING_OBJECT_REPLICATION, rl.existingObjectReplication);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_EXISTING_OBJECT_REPLICATION_STATUS, rl.existingObjectReplication.status);
}
if (rl.filter != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER, rl.filter);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND, rl.filter.and);
if (rl.filter.and != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_PREFIX, rl.filter.and.prefix);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_TAG, rl.filter.and.tag);
if (rl.filter.and.tag != null) {
for (Tag r : rl.filter.and.tag) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_TAG_KEY, r.key);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_FILTER_AND_TAG_VALUE, r.value);
}
}
}
}
if (rl.sourceSelectionCriteria != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA, rl.sourceSelectionCriteria);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_REPLICA_MODIFICATIONS, rl.sourceSelectionCriteria.replicaModifications);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_REPLICA_MODIFICATIONS_STATUS, rl.sourceSelectionCriteria.replicaModifications.status);
if (rl.sourceSelectionCriteria.sseKmsEncryptedObjects != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_SSE_KMS_ENCRYPTED_OBJECTS, rl.sourceSelectionCriteria.sseKmsEncryptedObjects);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_SOURCE_SELECTION_CRITERIA_SSE_KMS_ENCRYPTED_OBJECTS_STATUS, rl.sourceSelectionCriteria.sseKmsEncryptedObjects.status);
}
}
if (rl.deleteMarkerReplication != null && rl.deleteMarkerReplication.Status != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DELETE_MARKER_REPLICATION, rl.deleteMarkerReplication);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DELETE_MARKER_REPLICATION_STATUS, rl.deleteMarkerReplication.Status);
if (rl.deleteMarkerReplication.Status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.deleteMarkerReplication.Status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
}
if (rl.destination == null) {
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
} else {
if (rl.destination.bucket != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_BUCKET, rl.destination.bucket);
String[] arnPath = rl.destination.bucket.split(GWConstants.COLON, -1);
if (arnPath.length != 6) {
logger.error(GWErrorCode.INVALID_REQUEST.getMessage());
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
if (Strings.isNullOrEmpty(arnPath[5])) {
logger.error(GWErrorCode.INVALID_REQUEST.getMessage());
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
if (Strings.isNullOrEmpty(arnPath[3])) {
if (isExistBucket(arnPath[5])) {
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
Bucket destBucket = getSomeBucket(arnPath[5]);
if (destBucket.getVersioning() != null) {
if (!GWConstants.STATUS_ENABLED.equalsIgnoreCase(destBucket.getVersioning())) {
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
} else {
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
}
} else {
logger.error(GWErrorCode.INVALID_REQUEST.getMessage());
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
if (rl.destination.accessControlTranslation != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ACCESS_CONTROL_TRANSLATION, rl.destination.accessControlTranslation);
if (rl.destination.accessControlTranslation.owner != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ACCESS_CONTROL_TRANSLATION_OWNER, rl.destination.accessControlTranslation.owner);
}
if (rl.destination.encryptionConfiguration != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ENCRYPTION_CONFIGURATION, rl.destination.encryptionConfiguration);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_ENCRYPTION_CONFIGURATION_REPLICAT_KMS_KEY_ID, rl.destination.encryptionConfiguration.replicaKmsKeyID);
}
if (rl.destination.metrics != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS, rl.destination.metrics);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS_EVENT_THRESHOLD, rl.destination.metrics.eventThreshold);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS_EVENT_THRESHOLD_MINUTES, rl.destination.metrics.eventThreshold.minutes);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_METRICS_STATUS, rl.destination.metrics.status);
}
if (rl.destination.replicationTime != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_REPLICATION_TIME, rl.destination.replicationTime);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_REPLICATION_TIME_STATUS, rl.destination.replicationTime.status);
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_REPLICATION_TIME_TIME, rl.destination.replicationTime.time);
}
}
if (rl.destination.storageClass != null) {
logger.info(GWConstants.LOG_PUT_BUCKET_REPLICATION_RULE_DESTINATION_STORAGE_CLASS, rl.destination.storageClass);
logger.error(GWErrorCode.NOT_IMPLEMENTED.getMessage());
throw new GWException(GWErrorCode.NOT_IMPLEMENTED, s3Parameter);
}
}
if (rl.existingObjectReplication != null && rl.existingObjectReplication.status != null) {
if (rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
}
if (rl.existingObjectReplication != null && rl.existingObjectReplication.status != null) {
if (rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.existingObjectReplication.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
}
if (rl.sourceSelectionCriteria != null) {
logger.error(GWErrorCode.NOT_IMPLEMENTED.getMessage());
throw new GWException(GWErrorCode.NOT_IMPLEMENTED, s3Parameter);
}
if (rl.status != null && rl.status.compareTo(GWConstants.STATUS_ENABLED) != 0 && rl.status.compareTo(GWConstants.STATUS_DISABLED) != 0) {
logger.error(GWErrorCode.MALFORMED_X_M_L.getMessage());
throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
}
}
if (rc.rules.size() > id.size()) {
logger.error(GWErrorCode.INVALID_ARGUMENT.getMessage());
throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
}
}
}
use of com.pspace.ifs.ksan.objmanager.Bucket in project ksan by infinistor.
the class CBalance method getBucketList.
private List<Bucket> getBucketList(String bucketName) {
List<Bucket> bList;
if (bucketName.isEmpty())
bList = bukList;
else {
bList = new ArrayList();
bukList.stream().filter(bucket -> (bucket.getName().equals(bucketName))).forEachOrdered(bucket -> {
bList.add(bucket);
});
}
return bList;
}
use of com.pspace.ifs.ksan.objmanager.Bucket in project ksan by infinistor.
the class S3Request method getSomeBucket.
protected Bucket getSomeBucket(String bucket) throws GWException {
checkBucket(bucket);
Bucket bucketInfo = null;
try {
setObjManager();
bucketInfo = objManager.getBucket(bucket);
if (bucketInfo != null) {
if (!bucketInfo.getAcl().startsWith(GWConstants.XML_VERSION)) {
bucketInfo.setAcl(GWUtils.makeOriginalXml(bucketInfo.getAcl(), s3Parameter));
}
}
} catch (ResourceNotFoundException 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);
}
}
if (bucketInfo == null) {
logger.info(GWConstants.LOG_BUCKET_IS_NOT_EXIST, bucket);
throw new GWException(GWErrorCode.NO_SUCH_BUCKET, s3Parameter);
}
return bucketInfo;
}
use of com.pspace.ifs.ksan.objmanager.Bucket 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;
}
Aggregations