private void generateDownloadManifests(final String imageId) {
   // lookup all reservations that reference the newly available image id
   final List<VmInstance> pendingInstances =
       VmInstances.list(
           new Predicate<VmInstance>() {
             @Override
             public boolean apply(VmInstance arg0) {
               return imageId.equals(arg0.getBootRecord().getMachineImageId())
                   && VmState.PENDING.equals(arg0.getState());
             }
           });
   for (final VmInstance instance : pendingInstances) {
     final String reservationId = instance.getReservationId();
     final String partitionName = instance.getPartition();
     final Partition partition = Partitions.lookupByName(partitionName);
     final MachineImageInfo machineImage = LookupMachine.INSTANCE.apply(imageId);
     try {
       final String manifestLocation =
           DownloadManifestFactory.generateDownloadManifest(
               new ImageManifestFile(
                   machineImage.getRunManifestLocation(), BundleImageManifest.INSTANCE),
               partition.getNodeCertificate().getPublicKey(),
               reservationId);
       LOG.debug(
           String.format(
               "Generated download manifest for instance %s", instance.getDisplayName()));
     } catch (final Exception ex) {
       LOG.error(
           String.format(
               "Failed to generate download manifest for instance %s", instance.getDisplayName()),
           ex);
     }
   }
 }
 private void clearState() {
   EventRecord.here(
           AssignAddressCallback.class,
           EventType.ADDRESS_ASSIGNING,
           Transition.assigning.toString(),
           "FAILED",
           this.address.toString())
       .debug();
   if (this.address.isPending()) {
     try {
       this.address.clearPending();
     } catch (Exception ex) {
     }
   }
   if (this.address.isSystemOwned()) {
     Addresses.release(this.address);
   } else if (this.address.isAssigned() && this.vm != null) {
     AddressingDispatcher.dispatch(
         AsyncRequests.newRequest(this.address.unassign().getCallback()), vm.getPartition());
   } else if (this.address.isAssigned() && this.vm == null) {
     this.address.unassign().clearPending();
   }
 }
示例#3
0
  public DetachVolumeResponseType detach(DetachVolumeType request) throws EucalyptusCloudException {
    DetachVolumeResponseType reply = (DetachVolumeResponseType) request.getReply();
    Context ctx = Contexts.lookup();

    Volume vol;
    try {
      vol = Volumes.lookup(ctx.getUserFullName().asAccountFullName(), request.getVolumeId());
    } catch (Exception ex1) {
      throw new EucalyptusCloudException("Volume does not exist: " + request.getVolumeId());
    }
    if (!RestrictedTypes.filterPrivileged().apply(vol)) {
      throw new EucalyptusCloudException(
          "Not authorized to detach volume "
              + request.getVolumeId()
              + " by "
              + ctx.getUser().getName());
    }

    VmInstance vm = null;
    AttachedVolume volume = null;
    try {
      VmVolumeAttachment vmVolAttach = VmInstances.lookupVolumeAttachment(request.getVolumeId());
      volume = VmVolumeAttachment.asAttachedVolume(vmVolAttach.getVmInstance()).apply(vmVolAttach);
      vm = vmVolAttach.getVmInstance();
    } catch (NoSuchElementException ex) {
      /** no such attachment * */
    }
    if (volume == null) {
      throw new EucalyptusCloudException("Volume is not attached: " + request.getVolumeId());
    }
    if (!RestrictedTypes.filterPrivileged().apply(vm)) {
      throw new EucalyptusCloudException(
          "Not authorized to detach volume from instance "
              + request.getInstanceId()
              + " by "
              + ctx.getUser().getName());
    }
    if (!vm.getInstanceId().equals(request.getInstanceId())
        && request.getInstanceId() != null
        && !request.getInstanceId().equals("")) {
      throw new EucalyptusCloudException(
          "Volume is not attached to instance: " + request.getInstanceId());
    }
    if (request.getDevice() != null
        && !request.getDevice().equals("")
        && !volume.getDevice().equals(request.getDevice())) {
      throw new EucalyptusCloudException(
          "Volume is not attached to device: " + request.getDevice());
    }

    Cluster cluster = null;
    ServiceConfiguration ccConfig = null;
    try {
      ccConfig = Topology.lookup(ClusterController.class, vm.lookupPartition());
      cluster = Clusters.lookup(ccConfig);
    } catch (NoSuchElementException e) {
      LOG.debug(e, e);
      throw new EucalyptusCloudException(
          "Cluster does not exist in partition: " + vm.getPartition());
    }
    ServiceConfiguration scVm;
    try {
      scVm = Topology.lookup(Storage.class, vm.lookupPartition());
    } catch (Exception ex) {
      LOG.error(ex, ex);
      throw new EucalyptusCloudException(
          "Failed to lookup SC for partition: " + vm.getPartition(), ex);
    }
    request.setVolumeId(volume.getVolumeId());
    request.setRemoteDevice(volume.getRemoteDevice());
    request.setDevice(volume.getDevice().replaceAll("unknown,requested:", ""));
    request.setInstanceId(vm.getInstanceId());
    VolumeDetachCallback ncDetach = new VolumeDetachCallback(request);
    try {
      AsyncRequests.sendSync(scVm, new DetachStorageVolumeType(volume.getVolumeId()));
    } catch (Exception e) {
      LOG.debug(e);
      Logs.extreme().debug(e, e);
      // GRZE: attach is idempotent, failure here is ok.      throw new EucalyptusCloudException(
      // e.getMessage( ) );
    }
    AsyncRequests.newRequest(ncDetach).dispatch(cluster.getConfiguration());
    EventRecord.here(VolumeManager.class, EventClass.VOLUME, EventType.VOLUME_DETACH)
        .withDetails(vm.getOwner().toString(), volume.getVolumeId(), "instance", vm.getInstanceId())
        .withDetails("cluster", ccConfig.getFullName().toString())
        .info();
    volume.setStatus("detaching");
    reply.setDetachedVolume(volume);
    return reply;
  }
示例#4
0
  public AttachVolumeResponseType AttachVolume(AttachVolumeType request)
      throws EucalyptusCloudException {
    AttachVolumeResponseType reply = (AttachVolumeResponseType) request.getReply();
    final String deviceName = request.getDevice();
    final String volumeId = request.getVolumeId();
    final Context ctx = Contexts.lookup();

    if (request.getDevice() == null
        || request.getDevice().endsWith("sda")
        || request.getDevice().endsWith("sdb")) {
      throw new EucalyptusCloudException("Invalid device name specified: " + request.getDevice());
    }
    VmInstance vm = null;
    try {
      vm = RestrictedTypes.doPrivileged(request.getInstanceId(), VmInstance.class);
    } catch (NoSuchElementException ex) {
      LOG.debug(ex, ex);
      throw new EucalyptusCloudException("Instance does not exist: " + request.getInstanceId(), ex);
    } catch (Exception ex) {
      LOG.debug(ex, ex);
      throw new EucalyptusCloudException(ex.getMessage(), ex);
    }
    AccountFullName ownerFullName = ctx.getUserFullName().asAccountFullName();
    Volume volume = Volumes.lookup(ownerFullName, volumeId);
    if (!RestrictedTypes.filterPrivileged().apply(volume)) {
      throw new EucalyptusCloudException(
          "Not authorized to attach volume "
              + request.getVolumeId()
              + " by "
              + ctx.getUser().getName());
    }
    try {
      vm.lookupVolumeAttachmentByDevice(deviceName);
      throw new EucalyptusCloudException(
          "Already have a device attached to: " + request.getDevice());
    } catch (NoSuchElementException ex1) {
      /** no attachment * */
    }
    try {
      VmInstances.lookupVolumeAttachment(volumeId);
      throw new EucalyptusCloudException("Volume already attached: " + request.getVolumeId());
    } catch (NoSuchElementException ex1) {
      /** no attachment * */
    }

    Partition volPartition = Partitions.lookupByName(volume.getPartition());
    ServiceConfiguration sc = Topology.lookup(Storage.class, volPartition);
    ServiceConfiguration scVm = Topology.lookup(Storage.class, vm.lookupPartition());
    if (!sc.equals(scVm)) {
      throw new EucalyptusCloudException(
          "Can only attach volumes in the same zone: " + request.getVolumeId());
    }
    ServiceConfiguration ccConfig = Topology.lookup(ClusterController.class, vm.lookupPartition());
    AttachStorageVolumeResponseType scAttachResponse;
    try {
      AttachStorageVolumeType req =
          new AttachStorageVolumeType(Nodes.lookupIqn(vm), volume.getDisplayName());
      scAttachResponse = AsyncRequests.sendSync(sc, req);
    } catch (Exception e) {
      LOG.debug(e, e);
      throw new EucalyptusCloudException(e.getMessage(), e);
    }
    request.setRemoteDevice(scAttachResponse.getRemoteDeviceString());

    AttachedVolume attachVol =
        new AttachedVolume(
            volume.getDisplayName(),
            vm.getInstanceId(),
            request.getDevice(),
            request.getRemoteDevice());
    vm.addTransientVolume(deviceName, scAttachResponse.getRemoteDeviceString(), volume);
    AsyncRequests.newRequest(new VolumeAttachCallback(request)).dispatch(ccConfig);

    EventRecord.here(VolumeManager.class, EventClass.VOLUME, EventType.VOLUME_ATTACH)
        .withDetails(
            volume.getOwner().toString(), volume.getDisplayName(), "instance", vm.getInstanceId())
        .withDetails("partition", vm.getPartition().toString())
        .info();
    reply.setAttachedVolume(attachVol);
    return reply;
  }