Example #1
0
  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;
          }
        });
  }
Example #2
0
  @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);
  }
Example #3
0
  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;
  }
Example #4
0
  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;
          }
        });
  }
Example #5
0
  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;
          }
        });
  }
  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;
  }
Example #7
0
  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;
          }
        });
  }
Example #8
0
  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;
  }
Example #9
0
 public Regions getRegions() {
   return (Regions) blockingDhtCache.get(piIdBuilder.getRegionsId());
 }