Пример #1
0
 public static PartInfo generateManifest(String bucketName, String objectKey) {
   PartInfo part = new PartInfo(bucketName, objectKey);
   part.setUploadId(Crypto.generateAlphanumericId(64));
   part.setSize(0L);
   // Not setting part number and object name on purpose
   return part;
 }
Пример #2
0
 NetworkGroup(
     final OwnerFullName ownerFullName, final String groupName, final String groupDescription) {
   this(ownerFullName, groupName);
   checkParam(groupDescription, notNullValue());
   this.description = groupDescription;
   this.groupId = Crypto.generateId(Integer.toHexString(groupName.hashCode()), "sg");
 }
  private void createBuckets(final List<ImageInfo> images) throws Exception {
    Set<String> systemBuckets = null;
    if (images.size() > 0) {
      try {
        final ListBucketsTask task = new ListBucketsTask();
        final CheckedListenableFuture<Boolean> result = task.dispatch();
        if (result.get()) {
          final List<String> bucketNames = task.getBuckets();
          systemBuckets = Sets.newHashSet();
          systemBuckets.addAll(bucketNames);
        }
      } catch (final Exception ex) {
        throw new Exception("Failed to check the existing buckets", ex);
      }
    }

    String newBucket = null;
    for (final ImageInfo image : images) {
      try {
        if (!(image instanceof MachineImageInfo)) continue;
        final MachineImageInfo machineImage = (MachineImageInfo) image;

        final String manifestLocation = machineImage.getManifestLocation();
        final String[] tokens = manifestLocation.split("/");
        final String bucketName = tokens[0];
        final String prefix = tokens[1].replace(".manifest.xml", "");
        do {
          newBucket =
              String.format(
                  "%s-%s-%s", BUCKET_PREFIX, Crypto.generateAlphanumericId(5, ""), bucketName);
          if (newBucket.length() > 63) {
            newBucket = String.format("%s-%s", BUCKET_PREFIX, Crypto.generateAlphanumericId(8, ""));
          }
          newBucket = newBucket.toLowerCase();
        } while (systemBuckets.contains(newBucket));

        try {
          final CreateBucketTask task = new CreateBucketTask(newBucket);
          final CheckedListenableFuture<Boolean> result = task.dispatch();
          if (result.get()) {;
          }
        } catch (final Exception ex) {
          throw new Exception("Failed to create a system-owned bucket for converted image", ex);
        }

        // set run manifest path
        final String runManifestPath = String.format("%s/%s.manifest.xml", newBucket, prefix);
        try {
          machineImage.setRunManifestLocation(runManifestPath);
          Images.setRunManifestLocation(machineImage.getDisplayName(), runManifestPath);
        } catch (final Exception ex) {
          throw new Exception("Failed to update run manifest location");
        }
      } catch (final Exception ex) {
        LOG.error(
            String.format(
                "Unable to create the bucket %s for image %s", newBucket, image.getDisplayName()));
        resetImagePendingAvailable(image.getDisplayName(), "Failed to create bucket");
        throw ex;
      }
    }
  }