Beispiel #1
0
  private void expunge(final Completion completion) {
    if (self.getStatus() != VolumeStatus.Deleted) {
      throw new OperationFailureException(
          errf.stringToOperationError(
              String.format(
                  "the volume[uuid:%s, name:%s] is not deleted yet, can't expunge it",
                  self.getUuid(), self.getName())));
    }

    final VolumeInventory inv = getSelfInventory();
    CollectionUtils.safeForEach(
        pluginRgty.getExtensionList(VolumeBeforeExpungeExtensionPoint.class),
        new ForEachFunction<VolumeBeforeExpungeExtensionPoint>() {
          @Override
          public void run(VolumeBeforeExpungeExtensionPoint arg) {
            arg.volumeBeforeExpunge(inv);
          }
        });

    if (self.getPrimaryStorageUuid() != null) {
      DeleteVolumeOnPrimaryStorageMsg dmsg = new DeleteVolumeOnPrimaryStorageMsg();
      dmsg.setVolume(getSelfInventory());
      dmsg.setUuid(self.getPrimaryStorageUuid());
      bus.makeTargetServiceIdByResourceUuid(
          dmsg, PrimaryStorageConstant.SERVICE_ID, self.getPrimaryStorageUuid());
      bus.send(
          dmsg,
          new CloudBusCallBack(completion) {
            @Override
            public void run(MessageReply r) {
              if (!r.isSuccess()) {
                completion.fail(r.getError());
              } else {
                ReturnPrimaryStorageCapacityMsg msg = new ReturnPrimaryStorageCapacityMsg();
                msg.setPrimaryStorageUuid(self.getPrimaryStorageUuid());
                msg.setDiskSize(self.getSize());
                bus.makeTargetServiceIdByResourceUuid(
                    msg, PrimaryStorageConstant.SERVICE_ID, self.getPrimaryStorageUuid());
                bus.send(msg);

                CollectionUtils.safeForEach(
                    pluginRgty.getExtensionList(VolumeAfterExpungeExtensionPoint.class),
                    new ForEachFunction<VolumeAfterExpungeExtensionPoint>() {
                      @Override
                      public void run(VolumeAfterExpungeExtensionPoint arg) {
                        arg.volumeAfterExpunge(inv);
                      }
                    });

                dbf.remove(self);
                completion.success();
              }
            }
          });
    } else {
      CollectionUtils.safeForEach(
          pluginRgty.getExtensionList(VolumeAfterExpungeExtensionPoint.class),
          new ForEachFunction<VolumeAfterExpungeExtensionPoint>() {
            @Override
            public void run(VolumeAfterExpungeExtensionPoint arg) {
              arg.volumeAfterExpunge(inv);
            }
          });

      dbf.remove(self);
      completion.success();
    }
  }