示例#1
0
  private void handle(APIChangeImageStateMsg msg) {
    ImageStateEvent sevt = ImageStateEvent.valueOf(msg.getStateEvent());
    if (sevt == ImageStateEvent.disable) {
      self.setState(ImageState.Disabled);
    } else {
      self.setState(ImageState.Enabled);
    }
    self = dbf.updateAndRefresh(self);

    APIChangeImageStateEvent evt = new APIChangeImageStateEvent(msg.getId());
    evt.setInventory(ImageInventory.valueOf(self));
    bus.publish(evt);
  }
示例#2
0
 protected ImageInventory getSelfInventory() {
   return ImageInventory.valueOf(getSelf());
 }
示例#3
0
  private void handle(APIDeleteImageMsg msg) {
    final APIDeleteImageEvent evt = new APIDeleteImageEvent(msg.getId());

    final String issuer = ImageVO.class.getSimpleName();
    ImageDeletionStruct struct = new ImageDeletionStruct();
    struct.setImage(ImageInventory.valueOf(self));
    struct.setBackupStorageUuids(msg.getBackupStorageUuids());
    final List<ImageDeletionStruct> ctx = Arrays.asList(struct);
    FlowChain chain = FlowChainBuilder.newSimpleFlowChain();
    chain.setName(String.format("delete-image-%s", msg.getUuid()));
    if (msg.getDeletionMode() == APIDeleteMessage.DeletionMode.Permissive) {
      chain
          .then(
              new NoRollbackFlow() {
                @Override
                public void run(final FlowTrigger trigger, Map data) {
                  casf.asyncCascade(
                      CascadeConstant.DELETION_CHECK_CODE,
                      issuer,
                      ctx,
                      new Completion(trigger) {
                        @Override
                        public void success() {
                          trigger.next();
                        }

                        @Override
                        public void fail(ErrorCode errorCode) {
                          trigger.fail(errorCode);
                        }
                      });
                }
              })
          .then(
              new NoRollbackFlow() {
                @Override
                public void run(final FlowTrigger trigger, Map data) {
                  casf.asyncCascade(
                      CascadeConstant.DELETION_DELETE_CODE,
                      issuer,
                      ctx,
                      new Completion(trigger) {
                        @Override
                        public void success() {
                          trigger.next();
                        }

                        @Override
                        public void fail(ErrorCode errorCode) {
                          trigger.fail(errorCode);
                        }
                      });
                }
              });
    } else {
      chain.then(
          new NoRollbackFlow() {
            @Override
            public void run(final FlowTrigger trigger, Map data) {
              casf.asyncCascade(
                  CascadeConstant.DELETION_FORCE_DELETE_CODE,
                  issuer,
                  ctx,
                  new Completion(trigger) {
                    @Override
                    public void success() {
                      trigger.next();
                    }

                    @Override
                    public void fail(ErrorCode errorCode) {
                      trigger.fail(errorCode);
                    }
                  });
            }
          });
    }

    chain
        .done(
            new FlowDoneHandler(msg) {
              @Override
              public void handle(Map data) {
                casf.asyncCascadeFull(
                    CascadeConstant.DELETION_CLEANUP_CODE, issuer, ctx, new NopeCompletion());
                bus.publish(evt);
              }
            })
        .error(
            new FlowErrorHandler(msg) {
              @Override
              public void handle(ErrorCode errCode, Map data) {
                evt.setErrorCode(
                    errf.instantiateErrorCode(SysErrors.DELETE_RESOURCE_ERROR, errCode));
                bus.publish(evt);
              }
            })
        .start();
  }