private void handle(final ConnectPrimaryStorageMsg msg) { final ConnectPrimaryStorageReply reply = new ConnectPrimaryStorageReply(); self.setStatus(PrimaryStorageStatus.Connecting); self = dbf.updateAndRefresh(self); connectHook( msg, new Completion(msg) { @Override public void success() { self = dbf.reload(self); self.setStatus(PrimaryStorageStatus.Connected); self = dbf.updateAndRefresh(self); reply.setConnected(true); logger.debug( String.format("successfully connected primary storage[uuid:%s]", self.getUuid())); bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { if (msg.isNewAdded()) { reply.setError(errorCode); } else { self.setStatus(PrimaryStorageStatus.Disconnected); self = dbf.updateAndRefresh(self); logger.debug( String.format( "failed to connect primary storage[uuid:%s], %s", self.getUuid(), errorCode)); reply.setConnected(false); } bus.reply(msg, reply); } }); }
private void handle(final APIAttachDataVolumeToVmMsg msg) { self.setVmInstanceUuid(msg.getVmInstanceUuid()); self = dbf.updateAndRefresh(self); AttachDataVolumeToVmMsg amsg = new AttachDataVolumeToVmMsg(); amsg.setVolume(getSelfInventory()); amsg.setVmInstanceUuid(msg.getVmInstanceUuid()); bus.makeTargetServiceIdByResourceUuid( amsg, VmInstanceConstant.SERVICE_ID, amsg.getVmInstanceUuid()); bus.send( amsg, new CloudBusCallBack(msg) { @Override public void run(MessageReply reply) { final APIAttachDataVolumeToVmEvent evt = new APIAttachDataVolumeToVmEvent(msg.getId()); self = dbf.reload(self); if (reply.isSuccess()) { AttachDataVolumeToVmReply ar = reply.castReply(); self.setVmInstanceUuid(msg.getVmInstanceUuid()); self.setFormat( VolumeFormat.getVolumeFormatByMasterHypervisorType(ar.getHypervisorType()) .toString()); self = dbf.updateAndRefresh(self); evt.setInventory(getSelfInventory()); } else { self.setVmInstanceUuid(null); dbf.update(self); evt.setErrorCode(reply.getError()); } bus.publish(evt); } }); }
private void handle(APIUpdateBackupStorageMsg msg) { BackupStorageVO vo = updateBackupStorage(msg); if (vo != null) { self = dbf.updateAndRefresh(vo); } APIUpdateBackupStorageEvent evt = new APIUpdateBackupStorageEvent(msg.getId()); evt.setInventory(getSelfInventory()); bus.publish(evt); }
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); }
private void handle(APIChangeVolumeStateMsg msg) { VolumeStateEvent sevt = VolumeStateEvent.valueOf(msg.getStateEvent()); if (sevt == VolumeStateEvent.enable) { self.setState(VolumeState.Enabled); } else { self.setState(VolumeState.Disabled); } self = dbf.updateAndRefresh(self); VolumeInventory inv = VolumeInventory.valueOf(self); APIChangeVolumeStateEvent evt = new APIChangeVolumeStateEvent(msg.getId()); evt.setInventory(inv); bus.publish(evt); }
private void handle(APIChangeDiskOfferingStateMsg msg) { DiskOfferingStateEvent sevt = DiskOfferingStateEvent.valueOf(msg.getStateEvent()); if (sevt == DiskOfferingStateEvent.disable) { self.setState(DiskOfferingState.Disabled); } else { self.setState(DiskOfferingState.Enabled); } self = dbf.updateAndRefresh(self); DiskOfferingInventory inv = DiskOfferingInventory.valueOf(self); APIChangeDiskOfferingStateEvent evt = new APIChangeDiskOfferingStateEvent(msg.getId()); evt.setInventory(inv); bus.publish(evt); }
private void handle(APIUpdateVolumeMsg msg) { boolean update = false; if (msg.getName() != null) { self.setName(msg.getName()); update = true; } if (msg.getDescription() != null) { self.setDescription(msg.getDescription()); update = true; } if (update) { self = dbf.updateAndRefresh(self); } APIUpdateVolumeEvent evt = new APIUpdateVolumeEvent(msg.getId()); evt.setInventory(getSelfInventory()); bus.publish(evt); }
private void handle(APIUpdateDiskOfferingMsg msg) { boolean update = false; if (msg.getName() != null) { self.setName(msg.getName()); update = true; } if (msg.getDescription() != null) { self.setDescription(msg.getDescription()); update = true; } if (update) { self = dbf.updateAndRefresh(self); } APIUpdateDiskOfferingEvent evt = new APIUpdateDiskOfferingEvent(msg.getId()); evt.setInventory(DiskOfferingInventory.valueOf(self)); bus.publish(evt); }
protected void recoverVolume(Completion completion) { final VolumeInventory vol = getSelfInventory(); List<RecoverDataVolumeExtensionPoint> exts = pluginRgty.getExtensionList(RecoverDataVolumeExtensionPoint.class); for (RecoverDataVolumeExtensionPoint ext : exts) { ext.preRecoverDataVolume(vol); } CollectionUtils.safeForEach( exts, new ForEachFunction<RecoverDataVolumeExtensionPoint>() { @Override public void run(RecoverDataVolumeExtensionPoint ext) { ext.beforeRecoverDataVolume(vol); } }); VolumeStatus oldStatus = self.getStatus(); if (self.getInstallPath() != null) { self.setStatus(VolumeStatus.Ready); } else { self.setStatus(VolumeStatus.NotInstantiated); } self = dbf.updateAndRefresh(self); new FireVolumeCanonicalEvent().fireVolumeStatusChangedEvent(oldStatus, getSelfInventory()); CollectionUtils.safeForEach( exts, new ForEachFunction<RecoverDataVolumeExtensionPoint>() { @Override public void run(RecoverDataVolumeExtensionPoint ext) { ext.afterRecoverDataVolume(vol); } }); completion.success(); }
private void handle(APIUpdateImageMsg msg) { boolean update = false; if (msg.getName() != null) { self.setName(msg.getName()); update = true; } if (msg.getDescription() != null) { self.setDescription(msg.getDescription()); update = true; } if (msg.getSystem() != null) { self.setSystem(msg.getSystem()); update = true; } if (msg.getGuestOsType() != null) { self.setGuestOsType(msg.getGuestOsType()); update = true; } if (msg.getMediaType() != null) { self.setMediaType(ImageMediaType.valueOf(msg.getMediaType())); update = true; } if (msg.getFormat() != null) { self.setFormat(msg.getFormat()); update = true; } if (msg.getPlatform() != null) { self.setPlatform(ImagePlatform.valueOf(msg.getPlatform())); update = true; } if (update) { self = dbf.updateAndRefresh(self); } APIUpdateImageEvent evt = new APIUpdateImageEvent(msg.getId()); evt.setInventory(getSelfInventory()); bus.publish(evt); }
protected void handle(APIChangeBackupStorageStateMsg msg) { APIChangeBackupStorageStateEvent evt = new APIChangeBackupStorageStateEvent(msg.getId()); BackupStorageState currState = self.getState(); BackupStorageStateEvent event = BackupStorageStateEvent.valueOf(msg.getStateEvent()); BackupStorageState nextState = AbstractBackupStorage.getNextState(currState, event); try { extpEmitter.preChange(self, event); } catch (BackupStorageException e) { evt.setErrorCode( errf.instantiateErrorCode(SysErrors.CHANGE_RESOURCE_STATE_ERROR, e.getMessage())); bus.publish(evt); return; } extpEmitter.beforeChange(self, event); changeStateHook(event, nextState); self.setState(nextState); self = dbf.updateAndRefresh(self); extpEmitter.afterChange(self, event, currState); evt.setInventory(getSelfInventory()); bus.publish(evt); }
private void handle(APIRecoverImageMsg msg) { List<String> toRecoverBsUuids; if (msg.getBackupStorageUuids() == null || msg.getBackupStorageUuids().isEmpty()) { toRecoverBsUuids = CollectionUtils.transformToList( self.getBackupStorageRefs(), new Function<String, ImageBackupStorageRefVO>() { @Override public String call(ImageBackupStorageRefVO arg) { return arg.getStatus() == ImageStatus.Deleted ? arg.getBackupStorageUuid() : null; } }); if (toRecoverBsUuids.isEmpty()) { throw new OperationFailureException( errf.stringToOperationError( String.format( "the image[uuid:%s, name:%s] is not deleted on any backup storage", self.getUuid(), self.getName()))); } } else { toRecoverBsUuids = new ArrayList<String>(); for (final String bsUuid : msg.getBackupStorageUuids()) { ImageBackupStorageRefVO ref = CollectionUtils.find( self.getBackupStorageRefs(), new Function<ImageBackupStorageRefVO, ImageBackupStorageRefVO>() { @Override public ImageBackupStorageRefVO call(ImageBackupStorageRefVO arg) { return bsUuid.equals(arg.getBackupStorageUuid()) ? arg : null; } }); if (ref == null) { throw new OperationFailureException( errf.stringToInvalidArgumentError( String.format( "the image[uuid:%s, name:%s] is not on the backup storage[uuid:%s]", self.getUuid(), self.getName(), bsUuid))); } if (ref.getStatus() != ImageStatus.Deleted) { throw new OperationFailureException( errf.stringToInvalidArgumentError( String.format( "the image[uuid:%s, name:%s]'s status[%s] is not Deleted on the backup storage[uuid:%s]", self.getUuid(), self.getName(), ref.getStatus(), bsUuid))); } toRecoverBsUuids.add(bsUuid); } } for (ImageBackupStorageRefVO ref : self.getBackupStorageRefs()) { if (toRecoverBsUuids.contains(ref.getBackupStorageUuid())) { ref.setStatus(ImageStatus.Ready); dbf.update(ref); } } self.setStatus(ImageStatus.Ready); self = dbf.updateAndRefresh(self); logger.debug( String.format( "successfully recovered the image[uuid:%s, name:%s] on the backup storage%s", self.getUuid(), self.getName(), toRecoverBsUuids)); APIRecoverImageEvent evt = new APIRecoverImageEvent(msg.getId()); evt.setInventory(getSelfInventory()); bus.publish(evt); }