コード例 #1
0
ファイル: BucketMetaDataHelper.java プロジェクト: barnyard/pi
  public void addBucket(final BucketMetaData bucketMetaData) {
    LOG.debug(String.format("addBucketMetaDataEntity(%s)", bucketMetaData));

    PId bucketId = piIdBuilder.getPId(bucketMetaData);

    // create BucketMetaData

    blockingDhtCache.update(
        bucketId,
        new UpdateResolver<BucketMetaData>() {
          @Override
          public BucketMetaData update(
              BucketMetaData existingEntity, BucketMetaData requestedEntity) {
            if (existingEntity == null) return bucketMetaData;

            if (!existingEntity.isDeleted()) {
              throw new BucketAlreadyExistsException();
            }
            // TODO create a copy constructor in BucketMetaData
            existingEntity.setCannedAccessPolicy(bucketMetaData.getCannedAclPolicy());
            existingEntity.setLocation(bucketMetaData.getLocation());
            existingEntity.setUsername(bucketMetaData.getUsername());
            existingEntity.resetCreationDate();
            existingEntity.setDeleted(false);
            existingEntity.setName(bucketMetaData.getName());

            return existingEntity;
          }
        });
  }
コード例 #2
0
ファイル: AlertsControllerTest.java プロジェクト: barnyard/pi
  @Before
  public void setup() {
    when(piIdBuilder.getAvailabilityZonesId()).thenReturn(availabilityZonesId);
    when(piIdBuilder.getRegionsId()).thenReturn(regionsId);

    Regions regions = new Regions();
    regions.addRegion(new Region("r1", regionCode, null, null));

    AvailabilityZones availabilityZones = new AvailabilityZones();
    availabilityZones.addAvailabilityZone(
        new AvailabilityZone("av1", availabilityZoneCode, regionCode, null));

    when(blockingDhtCache.get(availabilityZonesId)).thenReturn(availabilityZones);
    when(blockingDhtCache.get(regionsId)).thenReturn(regions);

    when(koalaJsonParser.getJson(logMessageEntityCollection)).thenReturn(json);
  }
コード例 #3
0
ファイル: BucketMetaDataHelper.java プロジェクト: barnyard/pi
  private BucketMetaData getBucketMetaData(final String bucketName) {
    LOG.debug(String.format("getBucketMetaData(%s)", bucketName));

    PId bucketId =
        piIdBuilder.getPId(BucketMetaData.getUrl(bucketName.toLowerCase(Locale.getDefault())));
    BucketMetaData result = (BucketMetaData) blockingDhtCache.get(bucketId);
    if (result != null && result.isDeleted()) {
      LOG.debug("Returning null as the bucket is deleted:" + bucketId);
      return null;
    }

    LOG.debug("Returning bucket:" + result);
    return result;
  }
コード例 #4
0
ファイル: BucketMetaDataHelper.java プロジェクト: barnyard/pi
  public void removeBucketFromUser(final String userName, final String bucketName) {
    LOG.debug(String.format("removeBucketFromUser(%s, %s)", userName, bucketName));
    PId userId = piIdBuilder.getPId(User.getUrl(userName));

    blockingDhtCache.update(
        userId,
        new UpdateResolver<User>() {
          @Override
          public User update(User existingEntity, User requestedEntity) {
            existingEntity.getBucketNames().remove(bucketName);
            return existingEntity;
          }
        });
  }
コード例 #5
0
ファイル: BucketMetaDataHelper.java プロジェクト: barnyard/pi
  public void deleteBucket(final String bucketName) {
    LOG.debug(String.format("deleteBucket(%s)", bucketName));
    PId id = piIdBuilder.getPId(BucketMetaData.getUrl(bucketName.toLowerCase(Locale.getDefault())));

    blockingDhtCache.update(
        id,
        new UpdateResolver<BucketMetaData>() {
          @Override
          public BucketMetaData update(
              BucketMetaData existingEntity, BucketMetaData requestedEntity) {
            existingEntity.setDeleted(true);
            return existingEntity;
          }
        });
  }
コード例 #6
0
  private InstanceTypeConfiguration checkInstanceType(Reservation reservation) {
    if (null == reservation.getInstanceType()) return null;

    PId instanceTypesId = getPiIdBuilder().getPId(InstanceTypes.URL_STRING);
    InstanceTypes instanceTypes = instanceTypeCache.get(instanceTypesId);

    InstanceTypeConfiguration result =
        instanceTypes.getInstanceTypeConfiguration(reservation.getInstanceType());
    if (null == result)
      throw new IllegalStateException(
          "Unable to find instance type:" + reservation.getInstanceType());
    if (result.isDeprecated())
      throw new IllegalStateException(
          String.format("Instance type %s is deprecated", reservation.getInstanceType()));
    return result;
  }
コード例 #7
0
ファイル: BucketMetaDataHelper.java プロジェクト: barnyard/pi
  public void addBucketToUser(
      final String userName, final String bucketName, final CannedAclPolicy cannedAclPolicy) {
    LOG.debug(String.format("addBucketToUser(%s, %s, %s)", userName, bucketName, cannedAclPolicy));

    // update user record

    PId userId = piIdBuilder.getPId(User.getUrl(userName));
    blockingDhtCache.update(
        userId,
        new UpdateResolver<User>() {
          @Override
          public User update(User existingEntity, User requestedEntity) {
            existingEntity.getBucketNames().add(bucketName);
            return existingEntity;
          }
        });
  }
コード例 #8
0
ファイル: BucketMetaDataHelper.java プロジェクト: barnyard/pi
  public boolean updateCannedAcl(final String bucketName, final CannedAclPolicy cannedAclPolicy) {
    LOG.debug(String.format("updateCannedAcl(%s, %s)", bucketName, cannedAclPolicy));

    PId bucketId =
        piIdBuilder.getPId(BucketMetaData.getUrl(bucketName.toLowerCase(Locale.getDefault())));

    blockingDhtCache.update(
        bucketId,
        new UpdateResolver<BucketMetaData>() {
          @Override
          public BucketMetaData update(
              BucketMetaData existingEntity, BucketMetaData requestedEntity) {
            existingEntity.setCannedAccessPolicy(cannedAclPolicy);
            return existingEntity;
          }
        });

    return true;
  }
コード例 #9
0
ファイル: BucketMetaDataHelper.java プロジェクト: barnyard/pi
 public Regions getRegions() {
   return (Regions) blockingDhtCache.get(piIdBuilder.getRegionsId());
 }