Search in sources :

Example 1 with Upload

use of com.pspace.ifs.ksan.gw.object.multipart.Upload in project ksan by infinistor.

the class MysqlDataRepository method getUploads.

// TO BE
@Override
public ResultUploads getUploads(String bucket, String delimiter, String prefix, String keyMarker, String uploadIdMarker, int maxUploads) throws SQLException, GWException {
    ResultUploads resultUploads = new ResultUploads();
    resultUploads.setList(new ArrayList<Upload>());
    // need to make query with delimiter, prefix, keyMarker
    pstGetUploads.clearParameters();
    this.pstGetUploads.setString(1, bucket);
    this.pstGetUploads.setInt(2, maxUploads + 1);
    ResultSet rs = this.pstGetUploads.executeQuery();
    resultUploads.setTruncated(false);
    int count = 0;
    while (rs.next()) {
        count++;
        if (count > maxUploads) {
            resultUploads.setKeyMarker(rs.getString(1));
            resultUploads.setUploadIdMarker(rs.getString(3));
            resultUploads.setTruncated(true);
            break;
        }
        Upload upload = new Upload(rs.getString(1), (Date) rs.getObject(2), rs.getString(3), rs.getString(4));
        resultUploads.getList().add(upload);
    }
    return resultUploads;
}
Also used : Upload(com.pspace.ifs.ksan.gw.object.multipart.Upload) ResultUploads(com.pspace.ifs.ksan.gw.object.multipart.ResultUploads)

Example 2 with Upload

use of com.pspace.ifs.ksan.gw.object.multipart.Upload in project ksan by infinistor.

the class ListMultipartUploads method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_LIST_MULTIPART_UPLOADS_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);
    }
    checkGrantBucket(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
    DataListMultipartUploads dataListMultipartUploads = new DataListMultipartUploads(s3Parameter);
    dataListMultipartUploads.extract();
    String delimiter = dataListMultipartUploads.getDelimiter();
    String encodingType = dataListMultipartUploads.getEncodingType();
    String prefix = dataListMultipartUploads.getPrefix();
    String keyMarker = dataListMultipartUploads.getKeyMarker();
    String uploadIdMarker = dataListMultipartUploads.getUploadIdMarker();
    String maxUploads = dataListMultipartUploads.getMaxUploads();
    if (Strings.isNullOrEmpty(maxUploads)) {
        maxUploads = GWConstants.DEFAULT_MAX_KEYS;
    } else {
        if (Integer.valueOf(maxUploads) < 0) {
            throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
        }
    }
    ResultUploads resultUploads = null;
    ObjMultipart objMultipart = null;
    try {
        objMultipart = new ObjMultipart(bucket);
        resultUploads = objMultipart.getUploads(bucket, delimiter, prefix, keyMarker, uploadIdMarker, Integer.valueOf(maxUploads));
    } catch (UnknownHostException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
    } catch (Exception e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.INTERNAL_SERVER_ERROR, s3Parameter);
    }
    s3Parameter.getResponse().setCharacterEncoding(GWConstants.CHARSET_UTF_8);
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    try (Writer writer = s3Parameter.getResponse().getWriter()) {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(GWConstants.LIST_MULTIPART_UPLOADS_RESULT);
        xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
        writeSimpleElement(xmlStreamWriter, GWConstants.BUCKET, bucket);
        if (prefix == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_PREFIX);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeBlob(encodingType, prefix));
        }
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_MAX_UPLOADS, String.valueOf(maxUploads));
        if (keyMarker == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_KEY_MARKER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_KEY_MARKER, GWUtils.encodeBlob(encodingType, keyMarker));
        }
        if (uploadIdMarker == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_UPLOADID_MARKER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_UPLOADID_MARKER, GWUtils.encodeBlob(encodingType, uploadIdMarker));
        }
        if (delimiter != null) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_DELIMITER, GWUtils.encodeBlob(encodingType, delimiter));
        }
        if (encodingType != null && encodingType.equals(GWConstants.URL)) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_ENCODING_TYPE, encodingType);
        }
        if (resultUploads.isTruncated()) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_TRUE);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_KEY_MARKER, GWUtils.encodeBlob(encodingType, resultUploads.getKeyMarker()));
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_UPLOADID_MARKER, GWUtils.encodeBlob(encodingType, resultUploads.getUploadIdMarker()));
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_FALSE);
        }
        for (Upload upload : resultUploads.getList()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_UPLOAD);
            writeSimpleElement(xmlStreamWriter, GWConstants.KEY, upload.getObject());
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_UPLOADID, upload.getUploadId());
            writeInitiatorStanza(xmlStreamWriter);
            writeOwnerInfini(xmlStreamWriter, upload.getOwnerID(), upload.getOwnerName());
            writeSimpleElement(xmlStreamWriter, GWConstants.STORAGE_CLASS, GWConstants.AWS_TIER_STANTARD);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_INITIATED, formatDate(upload.getChangeTime()));
            xmlStreamWriter.writeEndElement();
            logger.debug(GWConstants.LOG_LIST_MULTIPART_UPLOADS_KEY, upload.getObject());
            logger.debug(GWConstants.LOG_LIST_MULTIPART_UPLOADS_UPLOADID, upload.getUploadId());
            logger.debug(GWConstants.LOG_LIST_MULTIPART_UPLOADS_CHANGE_TIME, formatDate(upload.getChangeTime()));
        }
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.flush();
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } catch (XMLStreamException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
}
Also used : ObjMultipart(com.pspace.ifs.ksan.objmanager.ObjMultipart) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) UnknownHostException(java.net.UnknownHostException) Upload(com.pspace.ifs.ksan.gw.object.multipart.Upload) IOException(java.io.IOException) ResultUploads(com.pspace.ifs.ksan.gw.object.multipart.ResultUploads) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) XMLStreamException(javax.xml.stream.XMLStreamException) DataListMultipartUploads(com.pspace.ifs.ksan.gw.data.DataListMultipartUploads) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Writer(java.io.Writer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 3 with Upload

use of com.pspace.ifs.ksan.gw.object.multipart.Upload in project ksan by infinistor.

the class MongoDataRepository method getUploads.

// SELECT objKey, changeTime, uploadid, meta FROM MULTIPARTS WHERE bucket=? AND partNo = 0 AND completed=false ORDER BY partNo LIMIT ?
@Override
public ResultUploads getUploads(String bucket, String delimiter, String prefix, String keyMarker, String uploadIdMarker, int maxUploads) throws SQLException, GWException {
    ResultUploads resultUploads = new ResultUploads();
    resultUploads.setList(new ArrayList<>());
    resultUploads.setTruncated(false);
    MongoCollection<Document> multip = getMultiPartUploadCollection();
    if (multip == null)
        return resultUploads;
    BasicDBObject sortList = new BasicDBObject(PARTNO, 1);
    FindIterable fit = multip.find(Filters.and(Filters.eq(BUCKETNAME, bucket), Filters.eq(PARTNO, 0), Filters.eq(COMPLETED, false))).limit(maxUploads + 1).sort(sortList);
    int count = 0;
    Iterator it = fit.iterator();
    resultUploads.setTruncated(false);
    while (it.hasNext()) {
        Document doc = (Document) it.next();
        count++;
        if (count > maxUploads) {
            resultUploads.setKeyMarker(doc.getString(OBJKEY));
            resultUploads.setUploadIdMarker(doc.getString(UPLOADID));
            resultUploads.setTruncated(true);
            break;
        }
        Upload upload = new Upload(doc.getString(OBJKEY), (Date) doc.getDate(CHANGETIME), doc.getString(UPLOADID), doc.getString(META));
        resultUploads.getList().add(upload);
    }
    return resultUploads;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) Iterator(java.util.Iterator) Upload(com.pspace.ifs.ksan.gw.object.multipart.Upload) FindIterable(com.mongodb.client.FindIterable) Document(org.bson.Document) ResultUploads(com.pspace.ifs.ksan.gw.object.multipart.ResultUploads)

Aggregations

ResultUploads (com.pspace.ifs.ksan.gw.object.multipart.ResultUploads)3 Upload (com.pspace.ifs.ksan.gw.object.multipart.Upload)3 BasicDBObject (com.mongodb.BasicDBObject)1 FindIterable (com.mongodb.client.FindIterable)1 DataListMultipartUploads (com.pspace.ifs.ksan.gw.data.DataListMultipartUploads)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1 ObjMultipart (com.pspace.ifs.ksan.objmanager.ObjMultipart)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 UnknownHostException (java.net.UnknownHostException)1 Iterator (java.util.Iterator)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 Document (org.bson.Document)1