use of com.pspace.ifs.ksan.objmanager.Metadata in project ksan by infinistor.
the class TestTrashSender method main.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int i = 0;
// String queueName = "osdThrashQueue";
String exchange = "OSDExchange";
String option = "";
String msg;
String fileName;
Metadata mt;
int idx = 0;
try {
MQSender mq1ton = new MQSender("192.168.11.76", exchange, option, "");
ObjManager om = new ObjManager();
while (true) {
Date dt = new Date();
fileName = "testfile" + idx + ".txt";
mt = om.create("testv1", fileName);
msg = "{id : " + dt.getTime() + " path: " + fileName + " diskpath1 : " + mt.getPrimaryDisk().getPath() + " diskpath2 : " + mt.getReplicaDisk().getPath() + "}";
mq1ton.send(msg, "");
System.out.format("Sent Message (to %s) :-> %s\n", mq1ton.getExchangeName(), msg);
Thread.sleep(10000);
idx++;
}
} catch (Exception ex) {
System.out.println("--->Error : " + ex.getMessage() + " L. msg :" + ex.getLocalizedMessage());
}
}
use of com.pspace.ifs.ksan.objmanager.Metadata in project ksan by infinistor.
the class GetObject method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_GET_OBJECT_START);
String bucket = s3Parameter.getBucketName();
initBucketInfo(bucket);
String object = s3Parameter.getObjectName();
logger.debug(GWConstants.LOG_BUCKET_OBJECT, bucket, object);
S3Bucket s3Bucket = new S3Bucket();
s3Bucket.setCors(getBucketInfo().getCors());
s3Bucket.setAccess(getBucketInfo().getAccess());
s3Parameter.setBucket(s3Bucket);
GWUtils.checkCors(s3Parameter);
if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
}
DataGetObject dataGetObject = new DataGetObject(s3Parameter);
dataGetObject.extract();
String versionId = dataGetObject.getVersionId();
String range = dataGetObject.getRange();
String ifMatch = dataGetObject.getIfMatch();
String ifNoneMatch = dataGetObject.getIfNoneMatch();
String ifModifiedSince = dataGetObject.getIfModifiedSince();
String ifUnmodifiedSince = dataGetObject.getIfUnmodifiedSince();
String versioningStatus = getBucketVersioning(bucket);
Metadata objMeta = null;
if (Strings.isNullOrEmpty(versionId)) {
objMeta = open(bucket, object);
versionId = objMeta.getVersionId();
} else {
objMeta = open(bucket, object, versionId);
}
logger.debug(GWConstants.LOG_OBJECT_META, objMeta.toString());
objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
checkGrantObject(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
S3Metadata s3Metadata = null;
// meta info
ObjectMapper objectMapper = new ObjectMapper();
try {
logger.debug(GWConstants.LOG_META, objMeta.getMeta());
s3Metadata = objectMapper.readValue(objMeta.getMeta(), S3Metadata.class);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
// check customer-key
if (!Strings.isNullOrEmpty(s3Metadata.getCustomerKey())) {
if (!Strings.isNullOrEmpty(dataGetObject.getServerSideEncryptionCustomerKey())) {
if (!s3Metadata.getCustomerKey().equals(dataGetObject.getServerSideEncryptionCustomerKey())) {
logger.warn(GWConstants.LOG_GET_OBJECT_CUSTOMER_KEY_NO_MATCH);
throw new GWException(GWErrorCode.KEY_DOES_NOT_MATCH, s3Parameter);
}
} else {
logger.warn(GWConstants.ENCRYPTION_CUSTOMER_KEY_IS_NULL);
throw new GWException(GWErrorCode.BAD_REQUEST, s3Parameter);
}
}
// Check match
if (!Strings.isNullOrEmpty(ifMatch)) {
logger.debug(GWConstants.LOG_GET_OBJECT_IF_MATCH_ETAG, s3Metadata.getETag(), ifMatch.replace(GWConstants.DOUBLE_QUOTE, ""));
if (!s3Metadata.getETag().equals(ifMatch.replace(GWConstants.DOUBLE_QUOTE, ""))) {
logger.error(GWConstants.LOG_GET_OBJECT_ETAG_DIFFERENT);
throw new GWException(GWErrorCode.PRECONDITION_FAILED, s3Parameter);
}
}
if (!Strings.isNullOrEmpty(ifNoneMatch)) {
logger.debug(GWConstants.LOG_GET_OBJECT_IF_NONE_MATCH_ETAG, s3Metadata.getETag(), ifNoneMatch.replace(GWConstants.DOUBLE_QUOTE, ""));
if (s3Metadata.getETag().equals(ifNoneMatch.replace(GWConstants.DOUBLE_QUOTE, ""))) {
logger.error(GWConstants.LOG_GET_OBJECT_ETAG_SAME);
throw new GWException(GWErrorCode.DOES_NOT_MATCH, String.format(GWConstants.LOG_ETAG_IS_MISMATCH), s3Parameter);
}
}
if (!Strings.isNullOrEmpty(ifModifiedSince)) {
Date modifiedSince = new Date(ifModifiedSince);
if (s3Metadata.getLastModified().before(modifiedSince)) {
throw new GWException(GWErrorCode.DOES_NOT_MATCH, String.format(GWConstants.LOG_MATCH_BEFORE, s3Metadata.getLastModified(), modifiedSince), s3Parameter);
}
}
if (!Strings.isNullOrEmpty(ifUnmodifiedSince)) {
Date unmodifiedSince = new Date(ifUnmodifiedSince);
if (s3Metadata.getLastModified().after(unmodifiedSince)) {
throw new GWException(GWErrorCode.PRECONDITION_FAILED, String.format(GWConstants.LOG_MATCH_AFTER, s3Metadata.getLastModified(), unmodifiedSince), s3Parameter);
}
}
ResultRange resultRange = new ResultRange(range, s3Metadata, s3Parameter);
addMetadataToResponse(s3Parameter.getResponse(), s3Metadata, resultRange.getContentLengthHeaders(), resultRange.getStreamSize());
S3ObjectOperation objectOperation = new S3ObjectOperation(objMeta, s3Metadata, s3Parameter, versionId, null);
try {
objectOperation.getObject(resultRange.getS3Range());
} catch (Exception e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
s3Parameter.getResponse().setStatus(resultRange.getStatus());
}
use of com.pspace.ifs.ksan.objmanager.Metadata in project ksan by infinistor.
the class GetObjectRetention method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_GET_OBJECT_RETENTION_START);
String bucket = s3Parameter.getBucketName();
initBucketInfo(bucket);
String object = s3Parameter.getObjectName();
logger.debug(GWConstants.LOG_BUCKET_OBJECT, bucket, object);
S3Bucket s3Bucket = new S3Bucket();
s3Bucket.setCors(getBucketInfo().getCors());
s3Bucket.setAccess(getBucketInfo().getAccess());
s3Parameter.setBucket(s3Bucket);
GWUtils.checkCors(s3Parameter);
if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
}
DataGetObjectRetention dataGetObjectRetention = new DataGetObjectRetention(s3Parameter);
dataGetObjectRetention.extract();
String versionId = dataGetObjectRetention.getVersionId();
Metadata objMeta = null;
if (Strings.isNullOrEmpty(versionId)) {
objMeta = open(bucket, object);
} else {
objMeta = open(bucket, object, versionId);
}
logger.debug(GWConstants.LOG_OBJECT_META, objMeta.toString());
objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
checkGrantObjectOwner(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
String meta = objMeta.getMeta();
S3Metadata s3Metadata;
try {
s3Metadata = new ObjectMapper().readValue(meta, S3Metadata.class);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
if (!Strings.isNullOrEmpty(s3Metadata.getLockMode())) {
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
javax.xml.stream.XMLStreamWriter xml;
try {
xml = xmlOutputFactory.createXMLStreamWriter(s3Parameter.getResponse().getOutputStream());
xml.writeStartDocument();
xml.writeStartElement(GWConstants.RETENTION);
writeSimpleElement(xml, GWConstants.XML_MODE, s3Metadata.getLockMode());
writeSimpleElement(xml, GWConstants.RETAIN_UNTIL_DATE, s3Metadata.getLockExpires());
xml.writeEndElement();
xml.flush();
} catch (XMLStreamException | IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
} else {
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.pspace.ifs.ksan.objmanager.Metadata in project ksan by infinistor.
the class GetObjectTagging method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_GET_OBJECT_TAGGING_START);
String bucket = s3Parameter.getBucketName();
initBucketInfo(bucket);
S3Bucket s3Bucket = new S3Bucket();
s3Bucket.setCors(getBucketInfo().getCors());
s3Bucket.setAccess(getBucketInfo().getAccess());
s3Parameter.setBucket(s3Bucket);
GWUtils.checkCors(s3Parameter);
if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
}
DataGetObjectTagging dataGetObjectTagging = new DataGetObjectTagging(s3Parameter);
dataGetObjectTagging.extract();
String object = s3Parameter.getObjectName();
String versionId = dataGetObjectTagging.getVersionId();
Metadata objMeta = null;
if (Strings.isNullOrEmpty(versionId)) {
objMeta = open(bucket, object);
} else {
objMeta = open(bucket, object, versionId);
}
objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
checkGrantObjectOwner(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
String taggingInfo = objMeta.getTag();
logger.info(GWConstants.LOG_TAGGING, taggingInfo);
if (Strings.isNullOrEmpty(taggingInfo)) {
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
javax.xml.stream.XMLStreamWriter xml;
try {
xml = xmlOutputFactory.createXMLStreamWriter(s3Parameter.getResponse().getOutputStream());
xml.writeStartDocument();
xml.writeStartElement(GWConstants.TAGGING);
xml.writeDefaultNamespace(GWConstants.AWS_XMLNS);
xml.writeStartElement(GWConstants.TAG_SET);
xml.writeEndElement();
xml.writeEndElement();
xml.flush();
} catch (XMLStreamException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
} else {
try {
if (!Strings.isNullOrEmpty(taggingInfo)) {
s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
s3Parameter.getResponse().getOutputStream().write(taggingInfo.getBytes());
}
} catch (IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
}
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
use of com.pspace.ifs.ksan.objmanager.Metadata in project ksan by infinistor.
the class PutObjectAcl method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_PUT_OBJECT_ACL_START);
String bucket = s3Parameter.getBucketName();
String object = s3Parameter.getObjectName();
initBucketInfo(bucket);
S3Bucket s3Bucket = new S3Bucket();
s3Bucket.setCors(getBucketInfo().getCors());
s3Bucket.setAccess(getBucketInfo().getAccess());
s3Parameter.setBucket(s3Bucket);
GWUtils.checkCors(s3Parameter);
if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
}
DataPutObjectAcl dataPutObjectAcl = new DataPutObjectAcl(s3Parameter);
dataPutObjectAcl.extract();
String versionId = dataPutObjectAcl.getVersionId();
Metadata objMeta = null;
if (Strings.isNullOrEmpty(versionId)) {
objMeta = open(bucket, object);
} else {
objMeta = open(bucket, object, versionId);
}
objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
checkGrantObjectOwner(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE_ACP);
accessControlPolicy = new AccessControlPolicy();
accessControlPolicy.aclList = new AccessControlList();
accessControlPolicy.aclList.grants = new ArrayList<Grant>();
accessControlPolicy.owner = new Owner();
accessControlPolicy.owner.id = String.valueOf(s3Parameter.getUser().getUserId());
accessControlPolicy.owner.displayName = s3Parameter.getUser().getUserName();
String xml = GWUtils.makeAclXml(accessControlPolicy, null, dataPutObjectAcl.hasAclKeyword(), dataPutObjectAcl.getAclXml(), dataPutObjectAcl.getAcl(), getBucketInfo(), String.valueOf(s3Parameter.getUser().getUserId()), s3Parameter.getUser().getUserName(), dataPutObjectAcl.getGrantRead(), dataPutObjectAcl.getGrantWrite(), dataPutObjectAcl.getGrantFullControl(), dataPutObjectAcl.getGrantReadAcp(), dataPutObjectAcl.getGrantWriteAcp(), s3Parameter);
logger.debug(GWConstants.LOG_ACL, xml);
objMeta.setAcl(xml);
updateObjectAcl(objMeta);
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Aggregations