当前位置:   article > 正文

云存储服务broker系统(四)——基本桶操作2_enable bucket quota

enable bucket quota

新增桶的基本操作:

设置桶策略,输入桶的名称及策略名称
获取桶策略,如果桶没有被设置过策略,则返回没有策略
删除桶策略
桶存量信息storageInfo,含有对象数和总大小两个信息,通过get()方法获取
桶配额为long型变量,可以对桶的总配额进行设置
存储类型:标准、归档、低频 将storagePolicy型处理,只返回STANDARD、COLD、WARM字符串

代码如下

  /* 设置桶策略 */
    public void setBucketPolicy(String bucketName,String policy)
    {
        ObsClient obsClient = new ObsClient(ak, sk, endPoint);
        obsClient.setBucketPolicy(bucketName, policy);
    }

    /* 获取桶策略 */
    public String getBucketPolicy(String bucketName)
    {
        try{
            String policy = obsClient.getBucketPolicy(bucketName);
            System.out.println("\t" + policy);
            return policy;
        }catch (ObsException e){
            return "no policy";
        }

    }

    /* 删除桶策略 */
    public void deleteBucketPolicy(String bucketName){
        obsClient.deleteBucketPolicy(bucketName);
    }

    /* 获取桶的区域位置 */
    public String getlocation(String bucketName){
        String location = obsClient.getBucketLocation(bucketName);
        System.out.println("\t:" + location);
        return location;
    }

    /* 获取桶存量信息 */
    public BucketStorageInfo getBucketStorageInfo(String bucketName){
        BucketStorageInfo storageInfo = obsClient.getBucketStorageInfo(bucketName);
        System.out.println("\t" + storageInfo.getObjectNumber());
        System.out.println("\t" + storageInfo.getSize());
        return storageInfo;
    }

    /* 设置桶配额 */
    public void setBucketQuota(String bucketName,long size){
        BucketQuota quota = new BucketQuota(size);
        obsClient.setBucketQuota(bucketName, quota);
        System.out.println("set quota success");
    }

    /* 获取桶配额 */
    public long getBucketQuota(String bucketName){
        BucketQuota quota = obsClient.getBucketQuota(bucketName);
//        System.out.println("\t" + quota.getBucketQuota());

        return quota.getBucketQuota();
    }

    /* 设置桶存储类型 */
    public void setBucketStoragePolicy(String bucketName,int policy){
        BucketStoragePolicyConfiguration storgePolicy = new BucketStoragePolicyConfiguration();
        switch (policy){
            case 0:{
                storgePolicy.setBucketStorageClass(StorageClassEnum.STANDARD);
            }
            case 1:{
                storgePolicy.setBucketStorageClass(StorageClassEnum.WARM);
            }
            case 2:{
                storgePolicy.setBucketStorageClass(StorageClassEnum.COLD);
            }
        }
        obsClient.setBucketStoragePolicy(bucketName, storgePolicy);
    }

    /* 获取桶存储类型 */
    public String getBucketStorageClass(String bucketName){
        BucketStoragePolicyConfiguration storagePolicy = obsClient.getBucketStoragePolicy(bucketName);
//        System.out.println("\t" + storagePolicy.getBucketStorageClass());
        return storagePolicy.getBucketStorageClass().toString();
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/135132
推荐阅读
相关标签
  

闽ICP备14008679号