Пример #1
0
 static void createDefault(final OwnerFullName ownerFullName) throws MetadataException {
   try {
     try {
       NetworkGroup net =
           Transactions.find(
               new NetworkGroup(
                   AccountFullName.getInstance(ownerFullName.getAccountNumber()),
                   NETWORK_DEFAULT_NAME));
       if (net == null) {
         create(ownerFullName, NETWORK_DEFAULT_NAME, "default group");
       }
     } catch (NoSuchElementException ex) {
       try {
         create(ownerFullName, NETWORK_DEFAULT_NAME, "default group");
       } catch (ConstraintViolationException ex1) {
       }
     } catch (TransactionException ex) {
       try {
         create(ownerFullName, NETWORK_DEFAULT_NAME, "default group");
       } catch (ConstraintViolationException ex1) {
       }
     }
   } catch (DuplicateMetadataException ex) {
   }
 }
Пример #2
0
  public CreateVolumeResponseType CreateVolume(final CreateVolumeType request)
      throws EucalyptusCloudException, AuthException {
    Context ctx = Contexts.lookup();
    Long volSize = request.getSize() != null ? Long.parseLong(request.getSize()) : null;
    final String snapId = request.getSnapshotId();
    String partition = request.getAvailabilityZone();

    if ((request.getSnapshotId() == null && request.getSize() == null)) {
      throw new EucalyptusCloudException("One of size or snapshotId is required as a parameter.");
    }

    if (snapId != null) {
      try {
        Transactions.find(Snapshot.named(null, snapId));
      } catch (ExecutionException ex) {
        throw new EucalyptusCloudException(
            "Failed to create volume because the referenced snapshot id is invalid: " + snapId);
      }
    }
    final Integer newSize = new Integer(request.getSize() != null ? request.getSize() : "-1");
    Exception lastEx = null;
    for (int i = 0; i < VOL_CREATE_RETRIES; i++) {
      try {
        final ServiceConfiguration sc =
            Topology.lookup(Storage.class, Partitions.lookupByName(partition));
        final UserFullName owner = ctx.getUserFullName();
        Function<Long, Volume> allocator =
            new Function<Long, Volume>() {

              @Override
              public Volume apply(Long size) {
                try {
                  return Volumes.createStorageVolume(
                      sc, owner, snapId, Ints.checkedCast(size), request);
                } catch (ExecutionException ex) {
                  throw Exceptions.toUndeclared(ex);
                }
              }
            };
        Volume newVol = RestrictedTypes.allocateMeasurableResource(newSize.longValue(), allocator);
        CreateVolumeResponseType reply = request.getReply();
        reply.setVolume(newVol.morph(new edu.ucsb.eucalyptus.msgs.Volume()));
        return reply;
      } catch (RuntimeException ex) {
        LOG.error(ex, ex);
        if (!(ex.getCause() instanceof ExecutionException)) {
          throw ex;
        } else {
          lastEx = ex;
        }
      }
    }
    throw new EucalyptusCloudException(
        "Failed to create volume after " + VOL_CREATE_RETRIES + " because of: " + lastEx, lastEx);
  }