Search in sources :

Example 1 with S3ObjectList

use of com.pspace.ifs.ksan.gw.identity.S3ObjectList in project ksan by infinistor.

the class ListObjectVersions method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_LIST_OBJECT_VERSIONS_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);
    DataListObjectVersions dataListObjectVersions = new DataListObjectVersions(s3Parameter);
    dataListObjectVersions.extract();
    String delimiter = dataListObjectVersions.getDelimiter();
    String encodingType = dataListObjectVersions.getEncodingType();
    String keyMarker = dataListObjectVersions.getKeyMarker();
    String maxKeys = dataListObjectVersions.getMaxKeys();
    String prefix = dataListObjectVersions.getPrefix();
    String versionIdMarker = dataListObjectVersions.getVersionIdMarker();
    S3ObjectList s3ObjectList = new S3ObjectList();
    s3ObjectList.setDelimiter(delimiter);
    s3ObjectList.setEncodingType(encodingType);
    s3ObjectList.setKeyMarker(keyMarker);
    s3ObjectList.setMaxKeys(maxKeys);
    if (Strings.isNullOrEmpty(s3ObjectList.getMaxKeys())) {
        s3ObjectList.setMaxKeys(GWConstants.DEFAULT_MAX_KEYS);
    }
    logger.debug(GWConstants.LOG_LIST_OBJECT_VERSIONS_MAXKEYS, s3ObjectList.getMaxKeys());
    if (Integer.valueOf(s3ObjectList.getMaxKeys()) < 0) {
        throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
    }
    s3ObjectList.setPrefix(prefix);
    s3ObjectList.setVersionIdMarker(versionIdMarker);
    s3Parameter.getResponse().setCharacterEncoding(GWConstants.CHARSET_UTF_8);
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    ObjectListParameter objectListParameter = listObjectVersions(bucket, s3ObjectList);
    try (Writer writer = s3Parameter.getResponse().getWriter()) {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(GWConstants.LIST_VERSIONS_RESULT);
        xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_NAME, bucket);
        if (prefix == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_PREFIX);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeBlob(encodingType, prefix));
        }
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_MAX_KEYS, String.valueOf(s3ObjectList.getMaxKeys()));
        if (keyMarker == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_KEY_MARKER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_KEY_MARKER, GWUtils.encodeBlob(encodingType, keyMarker));
        }
        if (versionIdMarker == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_VERSIONID_MARKER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_VERSIONID_MARKER, GWUtils.encodeBlob(encodingType, versionIdMarker));
        }
        logger.debug(GWConstants.LOG_LIST_OBJECT_VERSIONS_PARAMETER_INFO, objectListParameter, objectListParameter.getObjects());
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_KEY_COUNT, String.valueOf(objectListParameter.getObjects().size()));
        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 (objectListParameter.isTruncated()) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_TRUE);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_KEY_MARKER, GWUtils.encodeBlob(encodingType, objectListParameter.getNextMarker()));
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_VERSIONID_MARKER, GWUtils.encodeBlob(encodingType, objectListParameter.getNextVersion()));
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_FALSE);
        }
        for (S3Metadata s3Metadata : objectListParameter.getObjects()) {
            if (s3Metadata != null) {
                if (s3Metadata.getDeleteMarker() != null) {
                    if (s3Metadata.getDeleteMarker().compareTo(GWConstants.OBJECT_TYPE_MARK) == 0) {
                        xmlStreamWriter.writeStartElement(GWConstants.XML_DELETE_MARKER);
                    } else {
                        xmlStreamWriter.writeStartElement(GWConstants.VERSION);
                    }
                    writeSimpleElement(xmlStreamWriter, GWConstants.KEY, GWUtils.encodeBlob(encodingType, s3Metadata.getName()));
                    if (s3Metadata.getLastModified() != null) {
                        writeSimpleElement(xmlStreamWriter, GWConstants.LAST_MODIFIED, formatDate(s3Metadata.getLastModified()));
                    }
                    if (s3Metadata.getETag() != null) {
                        writeSimpleElement(xmlStreamWriter, GWConstants.ETAG, GWUtils.maybeQuoteETag(s3Metadata.getETag()));
                    }
                    writeSimpleElement(xmlStreamWriter, GWConstants.XML_SIZE, s3Metadata.getSize().toString());
                    writeSimpleElement(xmlStreamWriter, GWConstants.STORAGE_CLASS, s3Metadata.getTier());
                    writeSimpleElement(xmlStreamWriter, GWConstants.VERSIONID, s3Metadata.getVersionId());
                    writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_LATEST, s3Metadata.getIsLatest());
                    writeOwnerInfini(xmlStreamWriter, s3Metadata.getOwnerId(), s3Metadata.getOwnerName());
                    xmlStreamWriter.writeEndElement();
                    logger.debug(GWConstants.LOG_LIST_OBJECT_VERSIONS_INFO, s3Metadata.getName(), s3Metadata.getVersionId());
                }
            }
        }
        for (Entry<String, String> entry : objectListParameter.getCommonPrefixes().entrySet()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_COMMON_PREFIXES);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeBlob(encodingType, entry.getValue()));
            xmlStreamWriter.writeEndElement();
        }
        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 : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DataListObjectVersions(com.pspace.ifs.ksan.gw.data.DataListObjectVersions) IOException(java.io.IOException) S3ObjectList(com.pspace.ifs.ksan.gw.identity.S3ObjectList) ObjectListParameter(com.pspace.ifs.ksan.gw.identity.ObjectListParameter) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Writer(java.io.Writer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 2 with S3ObjectList

use of com.pspace.ifs.ksan.gw.identity.S3ObjectList in project ksan by infinistor.

the class ListObjects method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_LIST_OBJECT_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);
    DataListBuckets dataListBuckets = new DataListBuckets(s3Parameter);
    dataListBuckets.extract();
    S3ObjectList s3ObjectList = new S3ObjectList();
    if (!Strings.isNullOrEmpty(dataListBuckets.getMaxkeys())) {
        if (Integer.valueOf(dataListBuckets.getMaxkeys()) < 0) {
            throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
        }
        s3ObjectList.setMaxKeys(dataListBuckets.getMaxkeys());
    } else {
        s3ObjectList.setMaxKeys(GWConstants.DEFAULT_MAX_KEYS);
    }
    s3ObjectList.setDelimiter(dataListBuckets.getDelimiter());
    s3ObjectList.setEncodingType(dataListBuckets.getEncodingType());
    s3ObjectList.setMarker(dataListBuckets.getMarker());
    s3ObjectList.setPrefix(dataListBuckets.getPrefix());
    logger.debug("delimiter : {}", dataListBuckets.getDelimiter());
    logger.debug("marker : {}", dataListBuckets.getMarker());
    logger.debug("prefix : {}", dataListBuckets.getPrefix());
    logger.debug("maxKeys : {}", dataListBuckets.getMaxkeys());
    s3Parameter.getResponse().setCharacterEncoding(GWConstants.CHARSET_UTF_8);
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    ObjectListParameter objectListParameter = listObject(bucket, s3ObjectList);
    try (Writer writer = s3Parameter.getResponse().getWriter()) {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(GWConstants.LIST_BUCKET_RESULT);
        xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_NAME, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), bucket));
        if (s3ObjectList.getPrefix() == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_PREFIX);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), s3ObjectList.getPrefix()));
        }
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_MAX_KEYS, String.valueOf(s3ObjectList.getMaxKeys()));
        if (s3ObjectList.getMarker() == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_MARKER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_MARKER, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), s3ObjectList.getMarker()));
        }
        if (s3ObjectList.getDelimiter() != null) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_DELIMITER, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), s3ObjectList.getDelimiter()));
        }
        if (s3ObjectList.getEncodingType() != null && s3ObjectList.getEncodingType().equals(GWConstants.URL)) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_ENCODING_TYPE, s3ObjectList.getEncodingType());
        }
        if (objectListParameter.isTruncated()) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_TRUE);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_MARKER, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), objectListParameter.getNextMarker()));
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_FALSE);
        }
        for (S3Metadata s3Metadata : objectListParameter.getObjects()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_CONTENTS);
            logger.debug(s3Metadata.getName());
            writeSimpleElement(xmlStreamWriter, GWConstants.KEY, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), s3Metadata.getName()));
            if (s3Metadata.getLastModified() != null) {
                writeSimpleElement(xmlStreamWriter, GWConstants.LAST_MODIFIED, formatDate(s3Metadata.getLastModified()));
            }
            if (s3Metadata.getETag() != null) {
                writeSimpleElement(xmlStreamWriter, GWConstants.ETAG, GWUtils.maybeQuoteETag(s3Metadata.getETag()));
            }
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_SIZE, s3Metadata.getSize().toString());
            writeSimpleElement(xmlStreamWriter, GWConstants.STORAGE_CLASS, s3Metadata.getTier());
            writeOwnerInfini(xmlStreamWriter, s3Metadata.getOwnerId(), s3Metadata.getOwnerName());
            xmlStreamWriter.writeEndElement();
        }
        for (Entry<String, String> prefix : objectListParameter.getCommonPrefixes().entrySet()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_COMMON_PREFIXES);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeObjectName(s3ObjectList.getEncodingType(), prefix.getValue()));
            xmlStreamWriter.writeEndElement();
            logger.debug(GWConstants.LOG_LIST_OBJECT_PREFIX_ENCODING, s3ObjectList.getEncodingType(), prefix.getValue());
        }
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.flush();
    } catch (IOException | XMLStreamException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) IOException(java.io.IOException) S3ObjectList(com.pspace.ifs.ksan.gw.identity.S3ObjectList) DataListBuckets(com.pspace.ifs.ksan.gw.data.DataListBuckets) ObjectListParameter(com.pspace.ifs.ksan.gw.identity.ObjectListParameter) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Writer(java.io.Writer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 3 with S3ObjectList

use of com.pspace.ifs.ksan.gw.identity.S3ObjectList in project ksan by infinistor.

the class ListObjectsV2 method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_LIST_OBJECT_V2_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);
    DataListObjectV2 dataListObjectV2 = new DataListObjectV2(s3Parameter);
    dataListObjectV2.extract();
    // read header
    S3ObjectList s3ObjectList = new S3ObjectList();
    if (!Strings.isNullOrEmpty(dataListObjectV2.getMaxKeys())) {
        if (Integer.valueOf(dataListObjectV2.getMaxKeys()) < 0) {
            throw new GWException(GWErrorCode.INVALID_ARGUMENT, s3Parameter);
        }
        s3ObjectList.setMaxKeys(dataListObjectV2.getMaxKeys());
    } else {
        s3ObjectList.setMaxKeys(GWConstants.DEFAULT_MAX_KEYS);
    }
    s3ObjectList.setContinuationToken(dataListObjectV2.getContinuationToken());
    s3ObjectList.setDelimiter(dataListObjectV2.getDelimiter());
    s3ObjectList.setEncodingType(dataListObjectV2.getEncodingType());
    s3ObjectList.setPrefix(dataListObjectV2.getPrefix());
    s3ObjectList.setStartAfter(dataListObjectV2.getStartAfter());
    s3ObjectList.setFetchOwner(dataListObjectV2.getFetchOwner());
    s3Parameter.getResponse().setCharacterEncoding(GWConstants.CHARSET_UTF_8);
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    ObjectListParameter objectListParameter = listObjectV2(bucket, s3ObjectList);
    try (Writer writer = s3Parameter.getResponse().getWriter()) {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(GWConstants.LIST_BUCKET_RESULT);
        xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_NAME, bucket);
        String encodingType = s3ObjectList.getEncodingType();
        String prefix = s3ObjectList.getPrefix();
        if (prefix == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_PREFIX);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeObjectName(encodingType, prefix));
        }
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_MAX_KEYS, String.valueOf(s3ObjectList.getMaxKeys()));
        if (s3ObjectList.getStartAfter() == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_START_AFTER);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_START_AFTER, GWUtils.encodeObjectName(encodingType, s3ObjectList.getStartAfter()));
        }
        if (s3ObjectList.getContinuationToken() == null) {
            xmlStreamWriter.writeEmptyElement(GWConstants.XML_CONTINUEATION_TOKEN);
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_CONTINUEATION_TOKEN, GWUtils.encodeObjectName(encodingType, s3ObjectList.getContinuationToken()));
        }
        writeSimpleElement(xmlStreamWriter, GWConstants.XML_KEY_COUNT, String.valueOf(objectListParameter.getObjects().size()));
        if (s3ObjectList.getDelimiter() != null) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_DELIMITER, GWUtils.encodeObjectName(encodingType, s3ObjectList.getDelimiter()));
        }
        if (encodingType != null && encodingType.equals(GWConstants.URL)) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_ENCODING_TYPE, encodingType);
        }
        if (objectListParameter.isTruncated()) {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_TRUE);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_NEXT_CONTINUATION_TOKEN, GWUtils.encodeObjectName(encodingType, objectListParameter.getNextMarker()));
        } else {
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_IS_TRUNCATED, GWConstants.XML_FALSE);
        }
        for (S3Metadata s3Metadata : objectListParameter.getObjects()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_CONTENTS);
            writeSimpleElement(xmlStreamWriter, GWConstants.KEY, GWUtils.encodeObjectName(encodingType, s3Metadata.getName()));
            if (s3Metadata.getLastModified() != null) {
                writeSimpleElement(xmlStreamWriter, GWConstants.LAST_MODIFIED, formatDate(s3Metadata.getLastModified()));
            }
            if (s3Metadata.getETag() != null) {
                writeSimpleElement(xmlStreamWriter, GWConstants.ETAG, GWUtils.maybeQuoteETag(s3Metadata.getETag()));
            }
            if (!Strings.isNullOrEmpty(s3ObjectList.getFetchOwner()) && s3ObjectList.getFetchOwner().equals(GWConstants.XML_TRUE)) {
                writeOwnerInfini(xmlStreamWriter, s3Metadata.getOwnerId(), s3Metadata.getOwnerName());
            }
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_SIZE, s3Metadata.getContentLength().toString());
            writeSimpleElement(xmlStreamWriter, GWConstants.STORAGE_CLASS, s3Metadata.getTier());
            xmlStreamWriter.writeEndElement();
        }
        for (Entry<String, String> entry : objectListParameter.getCommonPrefixes().entrySet()) {
            xmlStreamWriter.writeStartElement(GWConstants.XML_COMMON_PREFIXES);
            writeSimpleElement(xmlStreamWriter, GWConstants.XML_PREFIX, GWUtils.encodeObjectName(encodingType, entry.getValue()));
            xmlStreamWriter.writeEndElement();
        }
        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 : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) IOException(java.io.IOException) S3ObjectList(com.pspace.ifs.ksan.gw.identity.S3ObjectList) DataListObjectV2(com.pspace.ifs.ksan.gw.data.DataListObjectV2) ObjectListParameter(com.pspace.ifs.ksan.gw.identity.ObjectListParameter) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) Writer(java.io.Writer) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 4 with S3ObjectList

use of com.pspace.ifs.ksan.gw.identity.S3ObjectList in project ksan by infinistor.

the class Objmanagertest method testVersiong.

static void testVersiong() throws Exception {
    String path;
    String bucket = "testvol3vers";
    String tmp = "parentD1/subDir/test";
    String etag = "etag_sample";
    String tag = "tag_sample";
    String meta = "meta_sample";
    String acl = "acl_sample";
    String vers;
    int ret;
    ObjManager om;
    om = new ObjManager();
    S3ObjectList s3ObjectList = new S3ObjectList();
    try {
        sleep(3);
    } catch (InterruptedException ex) {
        Logger.getLogger(Objmanagertest.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        try {
            om.createBucket(bucket, "legesse1", "legesse1", "acl", "", "");
        } catch (ResourceAlreadyExistException ex) {
            System.out.println("Bucket already exist!");
        }
        try {
            vers = om.getBucketVersioning(bucket);
            if (vers.isEmpty())
                om.putBucketVersioning(bucket, "Enabled");
            System.out.println("111Versioin ret :> " + vers);
        } catch (ResourceNotFoundException | SQLException ex) {
            try {
                ret = om.putBucketVersioning(bucket, "Enabled");
                System.out.println("222Versioin ret :> " + ret);
            } catch (SQLException ex1) {
                Logger.getLogger(Objmanagertest.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
        long startTime = System.nanoTime();
        long startTime1m = System.nanoTime();
        long diff = 0;
        int mcount = 1;
        int idx;
        Metadata mt;
        for (idx = 0; idx < 200; idx++) {
            path = tmp + idx;
            // to create on round robin osd disk
            mt = om.create(bucket, path);
            om.close(bucket, path, etag, meta, tag, 0L, acl, mt.getPrimaryDisk().getPath(), mt.isReplicaExist() ? mt.getReplicaDisk().getPath() : "", Long.toString(startTime), "file");
            if ((idx + 1) % 1000000 == 0) {
                diff = System.nanoTime() - startTime1m;
                System.out.println(mcount + ": Millon create excution time  : " + diff + "nanosecond");
                startTime1m = System.nanoTime();
                mcount++;
            }
        }
        diff = System.nanoTime() - startTime;
        System.out.println("Total " + idx + " create excution time  : " + diff + "nanosecond");
        String delimiter = "/";
        String startAfter = "";
        int maxKeys = 10;
        String prefix = "parentD1/subDir";
        s3ObjectList.setMaxKeys(String.valueOf(maxKeys));
        s3ObjectList.setDelimiter(delimiter);
        s3ObjectList.setPrefix(prefix);
        s3ObjectList.setStartAfter(startAfter);
        s3ObjectList.setVersionIdMarker("");
        s3ObjectList.setMarker(prefix);
        try {
            // om.listObjectsVersion(bucket, delimiter, startAfter, "", maxKeys, prefix);
            ObjectListParameter res = om.listObjectVersions(bucket, s3ObjectList);
            System.out.println("res >>" + res);
        } catch (SQLException ex) {
            Logger.getLogger(Objmanagertest.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (IOException | InvalidParameterException | AllServiceOfflineException | ResourceNotFoundException ex) {
        System.out.println("Error : " + ex.getMessage());
    // Logger.getLogger(Objmanagertest.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : SQLException(java.sql.SQLException) AllServiceOfflineException(com.pspace.ifs.ksan.objmanager.ObjManagerException.AllServiceOfflineException) IOException(java.io.IOException) S3ObjectList(com.pspace.ifs.ksan.gw.identity.S3ObjectList) InvalidParameterException(java.security.InvalidParameterException) ObjectListParameter(com.pspace.ifs.ksan.gw.identity.ObjectListParameter) ResourceAlreadyExistException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)

Aggregations

ObjectListParameter (com.pspace.ifs.ksan.gw.identity.ObjectListParameter)4 S3ObjectList (com.pspace.ifs.ksan.gw.identity.S3ObjectList)4 IOException (java.io.IOException)4 GWException (com.pspace.ifs.ksan.gw.exception.GWException)3 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)3 S3Metadata (com.pspace.ifs.ksan.gw.identity.S3Metadata)3 Writer (java.io.Writer)3 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)3 DataListBuckets (com.pspace.ifs.ksan.gw.data.DataListBuckets)1 DataListObjectV2 (com.pspace.ifs.ksan.gw.data.DataListObjectV2)1 DataListObjectVersions (com.pspace.ifs.ksan.gw.data.DataListObjectVersions)1 AllServiceOfflineException (com.pspace.ifs.ksan.objmanager.ObjManagerException.AllServiceOfflineException)1 ResourceAlreadyExistException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException)1 ResourceNotFoundException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)1 InvalidParameterException (java.security.InvalidParameterException)1 SQLException (java.sql.SQLException)1