Search in sources :

Example 11 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class GetBucketPolicy method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_BUCKET_POLICY_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);
    }
    checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ_ACP);
    String policy = getBucketInfo().getPolicy();
    logger.debug(GWConstants.LOG_GET_BUCKET_POLICY, policy);
    if (Strings.isNullOrEmpty(policy)) {
        throw new GWException(GWErrorCode.NO_SUCH_POLICY_CONFIGURATION, s3Parameter);
    }
    try {
        if (!Strings.isNullOrEmpty(policy)) {
            s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
            s3Parameter.getResponse().getOutputStream().write(policy.getBytes());
        }
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Example 12 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class GetBucketTagging method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_BUCKET_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);
    }
    checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ_ACP);
    String tag = getBucketInfo().getTagging();
    logger.debug(GWConstants.LOG_TAGGING, tag);
    if (Strings.isNullOrEmpty(tag)) {
        throw new GWException(GWErrorCode.NO_SUCH_TAG_SET_ERROR, s3Parameter);
    }
    try {
        if (!Strings.isNullOrEmpty(tag)) {
            s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
            s3Parameter.getResponse().getOutputStream().write(tag.getBytes());
        }
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Example 13 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class GetBucketVersioning method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_GET_BUCKET_VERSIONING_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);
    }
    checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ_ACP);
    String versioningStatus = getBucketInfo().getVersioning();
    logger.debug(GWConstants.LOG_GET_BUCKET_VERSIONING, bucket, versioningStatus);
    String xml = null;
    if (Strings.isNullOrEmpty(versioningStatus)) {
        xml = GWConstants.VERSION_CONFIGURATION_XMLNS_DISABLE;
    } else {
        if (GWConstants.VERSIONING_ENABLED.equals(versioningStatus)) {
            xml = GWConstants.VERSION_CONFIGURATION_XMLNS_ENABLED;
        } else if (GWConstants.VERSIONING_SUSPENDED.equals(versioningStatus)) {
            xml = GWConstants.VERSION_CONFIGURATION_XMLNS_SUSPENDED;
        } else {
            logger.error(GWConstants.LOG_GET_BUCKET_VERSIONING_WRONG, versioningStatus);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    logger.debug(GWConstants.LOG_GET_BUCKET_VERSIONING_XML, xml);
    try {
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        s3Parameter.getResponse().getOutputStream().write(xml.getBytes());
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException) IOException(java.io.IOException)

Example 14 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class S3ObjectOperation method putObjectNormal.

private S3Object putObjectNormal(long length, InputStream is) throws GWException {
    S3Object s3Object = new S3Object();
    File filePrimary = null;
    File tmpFilePrimary = null;
    FileOutputStream fosPrimary = null;
    File fileReplica = null;
    File tmpFileReplica = null;
    FileOutputStream fosReplica = null;
    File trashPrimary = null;
    File trashReplica = null;
    OSDClient clientPrimary = null;
    OSDClient clientReplica = null;
    long totalReads = 0L;
    long existFileSize = 0L;
    long putSize = 0L;
    long calSize = 0L;
    try {
        MessageDigest md5er = MessageDigest.getInstance(GWConstants.MD5);
        byte[] buffer = new byte[GWConstants.MAXBUFSIZE];
        int readLength = 0;
        existFileSize = objMeta.getSize();
        putSize = length;
        boolean isPrimaryCache = false;
        boolean isReplicaCache = false;
        logger.debug("performance mode : {}", GWConfig.getPerformanceMode());
        logger.debug("objMeta - replicaCount : {}", objMeta.getReplicaCount());
        // No option
        if (GWConfig.isNoOption()) {
            if (objMeta.getReplicaCount() > 1) {
                existFileSize *= objMeta.getReplicaCount();
                putSize *= objMeta.getReplicaCount();
                logger.debug("bucket : {}, object : {}", objMeta.getBucket(), objMeta.getPath());
                logger.debug("primary disk id : {}, osd ip : {}", objMeta.getPrimaryDisk().getId(), objMeta.getPrimaryDisk().getOsdIp());
                logger.debug("replica disk id : {}, osd ip : {}", objMeta.getReplicaDisk().getId(), objMeta.getReplicaDisk().getOsdIp());
                if (GWUtils.getLocalIP().equals(objMeta.getPrimaryDisk().getOsdIp())) {
                    if (!Strings.isNullOrEmpty(GWConfig.getCacheDisk()) && length <= (GWConfig.getCacheFileSize() * GWConstants.MEGABYTES)) {
                        filePrimary = new File(makeCachePath(makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId)));
                        tmpFilePrimary = new File(makeCachePath(makeTempPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId)));
                        trashPrimary = new File(makeTrashPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                        File file = new File(makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                        com.google.common.io.Files.createParentDirs(file);
                        com.google.common.io.Files.createParentDirs(filePrimary);
                        com.google.common.io.Files.createParentDirs(tmpFilePrimary);
                        logger.debug("filePrimary path : {}", filePrimary.getAbsolutePath());
                        logger.debug("tmpFilePrimary path : {}", tmpFilePrimary.getAbsolutePath());
                        fosPrimary = new FileOutputStream(tmpFilePrimary, false);
                        isPrimaryCache = true;
                    } else {
                        filePrimary = new File(makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                        tmpFilePrimary = new File(makeTempPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                        trashPrimary = new File(makeTrashPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                        com.google.common.io.Files.createParentDirs(filePrimary);
                        com.google.common.io.Files.createParentDirs(tmpFilePrimary);
                        fosPrimary = new FileOutputStream(tmpFilePrimary, false);
                    }
                } else {
                    clientPrimary = OSDClientManager.getInstance().getOSDClient(objMeta.getPrimaryDisk().getOsdIp());
                    clientPrimary.putInit(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId, length, GWConstants.FILE_ATTRUBUTE_REPLICATION_PRIMARY, objMeta.getReplicaDisk().getId(), GWConfig.getPerformanceMode());
                }
                if (GWUtils.getLocalIP().equals(objMeta.getReplicaDisk().getOsdIp())) {
                    if (!Strings.isNullOrEmpty(GWConfig.getCacheDisk()) && length <= GWConfig.getCacheFileSize() * GWConstants.MEGABYTES) {
                        fileReplica = new File(makeCachePath(makeObjPath(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId)));
                        tmpFileReplica = new File(makeCachePath(makeTempPath(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId)));
                        trashReplica = new File(makeCachePath(makeTrashPath(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId)));
                        File file = new File(makeObjPath(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId));
                        com.google.common.io.Files.createParentDirs(file);
                        com.google.common.io.Files.createParentDirs(fileReplica);
                        com.google.common.io.Files.createParentDirs(tmpFileReplica);
                        logger.debug("fileReplica path : {}", fileReplica.getAbsolutePath());
                        logger.debug("tmpFileReplica path : {}", tmpFileReplica.getAbsolutePath());
                        fosReplica = new FileOutputStream(tmpFileReplica, false);
                        isReplicaCache = true;
                    } else {
                        fileReplica = new File(makeObjPath(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId));
                        tmpFileReplica = new File(makeTempPath(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId));
                        trashReplica = new File(makeTrashPath(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId));
                        com.google.common.io.Files.createParentDirs(fileReplica);
                        com.google.common.io.Files.createParentDirs(tmpFileReplica);
                        fosReplica = new FileOutputStream(tmpFileReplica, false);
                    }
                } else {
                    clientReplica = OSDClientManager.getInstance().getOSDClient(objMeta.getReplicaDisk().getOsdIp());
                    clientReplica.putInit(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId, length, GWConstants.FILE_ATTRIBUTE_REPLICATION_REPLICA, GWConstants.FILE_ATTRIBUTE_REPLICA_DISK_ID_NULL, GWConfig.getPerformanceMode());
                }
                while ((readLength = is.read(buffer, 0, GWConstants.BUFSIZE)) >= 0) {
                    totalReads += readLength;
                    if (filePrimary == null) {
                        clientPrimary.put(buffer, 0, readLength);
                    } else {
                        fosPrimary.write(buffer, 0, readLength);
                    }
                    if (fileReplica == null) {
                        clientReplica.put(buffer, 0, readLength);
                    } else {
                        fosReplica.write(buffer, 0, readLength);
                    }
                    md5er.update(buffer, 0, readLength);
                }
                if (filePrimary == null) {
                    clientPrimary.putFlush();
                    OSDClientManager.getInstance().returnOSDClient(clientPrimary);
                } else {
                    fosPrimary.flush();
                    if (filePrimary.exists()) {
                        retryRenameTo(filePrimary, trashPrimary);
                    }
                    setAttributeFileReplication(tmpFilePrimary, GWConstants.FILE_ATTRUBUTE_REPLICATION_PRIMARY, objMeta.getReplicaDisk().getId());
                    retryRenameTo(tmpFilePrimary, filePrimary);
                    if (isPrimaryCache) {
                        String path = makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId);
                        Files.createSymbolicLink(Paths.get(path), Paths.get(filePrimary.getAbsolutePath()));
                    }
                }
                if (fileReplica == null) {
                    clientReplica.putFlush();
                    OSDClientManager.getInstance().returnOSDClient(clientReplica);
                } else {
                    fosReplica.flush();
                    if (fileReplica.exists()) {
                        retryRenameTo(fileReplica, trashReplica);
                    }
                    setAttributeFileReplication(tmpFileReplica, GWConstants.FILE_ATTRIBUTE_REPLICATION_REPLICA, GWConstants.FILE_ATTRIBUTE_REPLICA_DISK_ID_NULL);
                    retryRenameTo(tmpFileReplica, fileReplica);
                    if (isReplicaCache) {
                        String path = makeObjPath(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId);
                        Files.createSymbolicLink(Paths.get(path), Paths.get(fileReplica.getAbsolutePath()));
                    }
                }
            } else {
                File file = null;
                File tmpFile = null;
                File trashFile = null;
                if (GWUtils.getLocalIP().equals(objMeta.getPrimaryDisk().getOsdIp())) {
                    if (!Strings.isNullOrEmpty(GWConfig.getCacheDisk()) && length <= GWConfig.getCacheFileSize() * GWConstants.MEGABYTES) {
                        file = new File(makeCachePath(makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId)));
                        tmpFile = new File(makeCachePath(makeTempPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId)));
                        trashFile = new File(makeCachePath(makeTrashPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId)));
                        File link = new File(makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                        com.google.common.io.Files.createParentDirs(file);
                        com.google.common.io.Files.createParentDirs(tmpFile);
                        com.google.common.io.Files.createParentDirs(link);
                        fosPrimary = new FileOutputStream(tmpFile, false);
                        isPrimaryCache = true;
                    } else {
                        file = new File(makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                        tmpFile = new File(makeTempPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                        trashFile = new File(makeTrashPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                        com.google.common.io.Files.createParentDirs(file);
                        com.google.common.io.Files.createParentDirs(tmpFile);
                        fosPrimary = new FileOutputStream(tmpFile, false);
                    }
                } else {
                    clientPrimary = OSDClientManager.getInstance().getOSDClient(objMeta.getPrimaryDisk().getOsdIp());
                    clientPrimary.putInit(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId, length, GWConstants.FILE_ATTRUBUTE_REPLICATION_PRIMARY, objMeta.getReplicaDisk().getId(), GWConfig.getPerformanceMode());
                }
                while ((readLength = is.read(buffer, 0, GWConstants.BUFSIZE)) >= 0) {
                    totalReads += readLength;
                    if (file == null) {
                        clientPrimary.put(buffer, 0, readLength);
                    } else {
                        fosPrimary.write(buffer, 0, readLength);
                    }
                    md5er.update(buffer, 0, readLength);
                }
                if (file == null) {
                    clientPrimary.putFlush();
                    OSDClientManager.getInstance().returnOSDClient(clientPrimary);
                } else {
                    fosPrimary.flush();
                    if (file.exists()) {
                        retryRenameTo(file, trashFile);
                    }
                    if (objMeta.getReplicaDisk() != null) {
                        setAttributeFileReplication(tmpFile, GWConstants.FILE_ATTRUBUTE_REPLICATION_PRIMARY, objMeta.getReplicaDisk().getId());
                    }
                    retryRenameTo(tmpFile, file);
                    if (isPrimaryCache) {
                        String path = makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId);
                        Files.createSymbolicLink(Paths.get(path), Paths.get(file.getAbsolutePath()));
                    }
                }
            }
        } else // No replication option
        if (GWConfig.isNoReplica()) {
            File file = null;
            File tmpFile = null;
            File trashFile = null;
            if (GWUtils.getLocalIP().equals(objMeta.getPrimaryDisk().getOsdIp())) {
                if (!Strings.isNullOrEmpty(GWConfig.getCacheDisk()) && length <= GWConfig.getCacheFileSize() * GWConstants.MEGABYTES) {
                    file = new File(makeCachePath(makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId)));
                    tmpFile = new File(makeCachePath(makeTempPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId)));
                    trashFile = new File(makeCachePath(makeTrashPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId)));
                    File link = new File(makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                    com.google.common.io.Files.createParentDirs(file);
                    com.google.common.io.Files.createParentDirs(tmpFile);
                    com.google.common.io.Files.createParentDirs(link);
                    fosPrimary = new FileOutputStream(tmpFile, false);
                    isPrimaryCache = true;
                } else {
                    file = new File(makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                    tmpFile = new File(makeTempPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                    trashFile = new File(makeTrashPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId));
                    com.google.common.io.Files.createParentDirs(file);
                    com.google.common.io.Files.createParentDirs(tmpFile);
                    fosPrimary = new FileOutputStream(tmpFile, false);
                }
            } else {
                clientPrimary = OSDClientManager.getInstance().getOSDClient(objMeta.getPrimaryDisk().getOsdIp());
                clientPrimary.putInit(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId, length, GWConstants.FILE_ATTRUBUTE_REPLICATION_PRIMARY, objMeta.getReplicaDisk().getId(), GWConfig.getPerformanceMode());
            }
            while ((readLength = is.read(buffer, 0, GWConstants.BUFSIZE)) >= 0) {
                totalReads += readLength;
                if (file == null) {
                    clientPrimary.put(buffer, 0, readLength);
                } else {
                    fosPrimary.write(buffer, 0, readLength);
                }
                md5er.update(buffer, 0, readLength);
            }
            if (file == null) {
                clientPrimary.putFlush();
                OSDClientManager.getInstance().returnOSDClient(clientPrimary);
            } else {
                fosPrimary.flush();
                if (file.exists()) {
                    retryRenameTo(file, trashFile);
                }
                if (objMeta.getReplicaDisk() != null) {
                    setAttributeFileReplication(tmpFile, GWConstants.FILE_ATTRUBUTE_REPLICATION_PRIMARY, objMeta.getReplicaDisk().getId());
                }
                retryRenameTo(tmpFile, file);
                if (isPrimaryCache) {
                    String path = makeObjPath(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId);
                    Files.createSymbolicLink(Paths.get(path), Paths.get(file.getAbsolutePath()));
                }
            }
        } else // No IO option
        if (GWConfig.isNoIO()) {
            while ((readLength = is.read(buffer, 0, GWConstants.BUFSIZE)) > 0) {
                totalReads += readLength;
                md5er.update(buffer, 0, readLength);
            }
        } else // No disk option
        if (GWConfig.isNoDisk()) {
            if (!GWUtils.getLocalIP().equals(objMeta.getPrimaryDisk().getOsdIp())) {
                clientPrimary = OSDClientManager.getInstance().getOSDClient(objMeta.getPrimaryDisk().getOsdIp());
                clientPrimary.putInit(objMeta.getPrimaryDisk().getPath(), objMeta.getObjId(), versionId, length, GWConstants.FILE_ATTRUBUTE_REPLICATION_PRIMARY, objMeta.getReplicaDisk().getId(), GWConfig.getPerformanceMode());
            }
            if (objMeta.getReplicaDisk() != null && !GWUtils.getLocalIP().equals(objMeta.getReplicaDisk().getOsdIp())) {
                clientReplica = OSDClientManager.getInstance().getOSDClient(objMeta.getReplicaDisk().getOsdIp());
                clientReplica.putInit(objMeta.getReplicaDisk().getPath(), objMeta.getObjId(), versionId, length, GWConstants.FILE_ATTRIBUTE_REPLICATION_REPLICA, GWConstants.FILE_ATTRIBUTE_REPLICA_DISK_ID_NULL, GWConfig.getPerformanceMode());
            }
            while ((readLength = is.read(buffer, 0, GWConstants.BUFSIZE)) >= 0) {
                totalReads += readLength;
                if (clientPrimary != null) {
                    clientPrimary.put(buffer, 0, readLength);
                }
                if (clientReplica != null) {
                    clientReplica.put(buffer, 0, readLength);
                }
                md5er.update(buffer, 0, readLength);
            }
            if (clientPrimary != null) {
                clientPrimary.putFlush();
                OSDClientManager.getInstance().returnOSDClient(clientPrimary);
            }
            if (clientReplica != null) {
                clientReplica.putFlush();
                OSDClientManager.getInstance().returnOSDClient(clientReplica);
            }
        } else {
            logger.error(GWConstants.LOG_S3OBJECT_OPERATION_OPTION_NO_CASE, GWConfig.getPerformanceMode());
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
        byte[] digest = md5er.digest();
        String eTag = base16().lowerCase().encode(digest);
        s3Object.setEtag(eTag);
        s3Object.setLastModified(new Date());
        s3Object.setFileSize(totalReads);
        s3Object.setVersionId(versionId);
        s3Object.setDeleteMarker(GWConstants.OBJECT_TYPE_FILE);
        calSize = putSize - existFileSize;
        if (GWConfig.isNoOption()) {
            updateBucketUsed(objMeta.getBucket(), calSize);
        }
    } catch (NoSuchAlgorithmException | IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } catch (ResourceNotFoundException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.NO_SUCH_KEY, s3Parameter);
    } catch (Exception e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } finally {
        if (objMeta.getReplicaCount() > 1) {
            if (fosPrimary != null) {
                try {
                    fosPrimary.close();
                } catch (IOException e) {
                    PrintStack.logging(logger, e);
                    throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
                }
            }
            if (fosReplica != null) {
                try {
                    fosReplica.close();
                } catch (IOException e) {
                    PrintStack.logging(logger, e);
                    throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
                }
            }
        }
    }
    return s3Object;
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) Date(java.util.Date) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) OSDClient(com.pspace.ifs.ksan.gw.object.osdclient.OSDClient) FileOutputStream(java.io.FileOutputStream) GWException(com.pspace.ifs.ksan.gw.exception.GWException) MessageDigest(java.security.MessageDigest) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) File(java.io.File)

Example 15 with GWException

use of com.pspace.ifs.ksan.gw.exception.GWException in project ksan by infinistor.

the class S3ObjectOperation method updateBucketUsed.

private void updateBucketUsed(String bucketName, long size) throws GWException {
    try {
        setObjManager();
        objManager.updateBucketUsed(bucketName, size);
    } 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);
        }
    }
}
Also used : GWException(com.pspace.ifs.ksan.gw.exception.GWException) GWException(com.pspace.ifs.ksan.gw.exception.GWException) ResourceNotFoundException(com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

GWException (com.pspace.ifs.ksan.gw.exception.GWException)130 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)61 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)58 XMLStreamException (javax.xml.stream.XMLStreamException)48 IOException (java.io.IOException)46 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)45 ResourceNotFoundException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceNotFoundException)43 ResourceAlreadyExistException (com.pspace.ifs.ksan.objmanager.ObjManagerException.ResourceAlreadyExistException)32 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)23 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)23 S3Metadata (com.pspace.ifs.ksan.gw.identity.S3Metadata)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)15 AccessControlPolicy (com.pspace.ifs.ksan.gw.format.AccessControlPolicy)14 Writer (java.io.Writer)13 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 Grant (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant)10 S3ObjectOperation (com.pspace.ifs.ksan.gw.object.S3ObjectOperation)10 Date (java.util.Date)8