private void handle(APIGetNetworkServiceProviderMsg msg) { GetQuery q = new GetQuery(); String res = q.getAsString(msg, NetworkServiceProviderInventory.class); APIGetNetworkServiceProviderReply reply = new APIGetNetworkServiceProviderReply(); reply.setInventory(res); bus.reply(msg, reply); }
private void handle(APIListZonesMsg msg) { APIListZonesReply reply = new APIListZonesReply(); List<ZoneVO> vos = dl.listByApiMessage(msg, ZoneVO.class); List<ZoneInventory> invs = ZoneInventory.valueOf(vos); reply.setInventories(invs); bus.reply(msg, reply); }
private void handle(APIGetZoneMsg msg) { GetQuery query = new GetQuery(); String inv = query.getAsString(msg.getUuid(), ZoneInventory.class); APIGetZoneReply reply = new APIGetZoneReply(); reply.setInventory(inv); bus.reply(msg, reply); }
private void handle(APISearchZoneMsg msg) { SearchQuery<ZoneInventory> query = SearchQuery.create(msg, ZoneInventory.class); String res = query.listAsString(); APISearchZoneReply reply = new APISearchZoneReply(); reply.setContent(res); bus.reply(msg, reply); }
private void handle(APIQueryNetworkServiceProviderMsg msg) { List<NetworkServiceProviderInventory> invs = qf.query(msg, NetworkServiceProviderInventory.class); APIQueryNetworkServiceProviderReply reply = new APIQueryNetworkServiceProviderReply(); reply.setInventories(invs); bus.reply(msg, reply); }
private void handle(APIListNetworkServiceProviderMsg msg) { List<NetworkServiceProviderVO> vos = dl.listByApiMessage(msg, NetworkServiceProviderVO.class); List<NetworkServiceProviderInventory> invs = NetworkServiceProviderInventory.valueOf(vos); APIListNetworkServiceProviderReply reply = new APIListNetworkServiceProviderReply(); reply.setInventories(invs); bus.reply(msg, reply); }
private void handle(final ExpungeImageMsg msg) { final ExpungeImageReply reply = new ExpungeImageReply(); final ImageBackupStorageRefVO ref = CollectionUtils.find( self.getBackupStorageRefs(), new Function<ImageBackupStorageRefVO, ImageBackupStorageRefVO>() { @Override public ImageBackupStorageRefVO call(ImageBackupStorageRefVO arg) { return arg.getBackupStorageUuid().equals(msg.getBackupStorageUuid()) ? arg : null; } }); if (ref == null) { logger.debug( String.format( "cannot find reference for the image[uuid:%s] on the backup storage[uuid:%s], assume it's been deleted", self.getUuid(), msg.getBackupStorageUuid())); bus.reply(msg, reply); return; } DeleteBitsOnBackupStorageMsg dmsg = new DeleteBitsOnBackupStorageMsg(); dmsg.setBackupStorageUuid(ref.getBackupStorageUuid()); dmsg.setInstallPath(ref.getInstallPath()); bus.makeTargetServiceIdByResourceUuid( dmsg, BackupStorageConstant.SERVICE_ID, dmsg.getBackupStorageUuid()); bus.send( dmsg, new CloudBusCallBack(msg) { @Override public void run(MessageReply r) { if (!r.isSuccess()) { // TODO logger.warn( String.format( "failed to delete image[uuid:%s, name:%s] from backup storage[uuid:%s] because %s, need to garbage collect it", self.getUuid(), self.getName(), r.getError(), ref.getBackupStorageUuid())); reply.setError(r.getError()); } else { returnBackupStorageCapacity(ref.getBackupStorageUuid(), self.getSize()); dbf.remove(ref); logger.debug( String.format( "successfully expunged the image[uuid: %s, name: %s] on the backup storage[uuid: %s]", self.getUuid(), self.getName(), ref.getBackupStorageUuid())); self = dbf.findByUuid(self.getUuid(), ImageVO.class); if (self.getBackupStorageRefs().isEmpty()) { logger.debug( String.format( "the image[uuid:%s, name:%s] has been expunged on all backup storage, remove it from database", self.getUuid(), self.getName())); dbf.remove(self); } } bus.reply(msg, reply); } }); }
private void handle(APISearchNetworkServiceProviderMsg msg) { SearchQuery<NetworkServiceProviderInventory> q = SearchQuery.create(msg, NetworkServiceProviderInventory.class); APISearchNetworkServiceProviderReply reply = new APISearchNetworkServiceProviderReply(); String res = q.listAsString(); reply.setContent(res); bus.reply(msg, reply); }
private void handle(PrimaryStorageDeletionMsg msg) { PrimaryStorageInventory inv = PrimaryStorageInventory.valueOf(self); extpEmitter.beforeDelete(inv); deleteHook(); extpEmitter.afterDelete(inv); PrimaryStorageDeletionReply reply = new PrimaryStorageDeletionReply(); bus.reply(msg, reply); }
private void handle(BackupStorageDeletionMsg msg) { BackupStorageInventory inv = BackupStorageInventory.valueOf(self); extpEmitter.beforeDelete(inv); deleteHook(); extpEmitter.afterDelete(inv); BackupStorageDeletionReply reply = new BackupStorageDeletionReply(); tracker.untrackHook(self.getUuid()); bus.reply(msg, reply); }
@Transactional private void handle(TakePrimaryStorageCapacityMsg msg) { PrimaryStorageCapacityVO vo = dbf.getEntityManager() .find(PrimaryStorageCapacityVO.class, self.getUuid(), LockModeType.PESSIMISTIC_WRITE); vo.setAvailableCapacity(vo.getAvailableCapacity() - msg.getSize()); if (vo.getAvailableCapacity() < 0) { vo.setAvailableCapacity(0); } dbf.getEntityManager().merge(vo); TakePrimaryStorageCapacityReply reply = new TakePrimaryStorageCapacityReply(); bus.reply(msg, reply); }
@Transactional private void handle(ReturnBackupStorageMsg msg) { self = dbf.getEntityManager() .find(BackupStorageVO.class, self.getUuid(), LockModeType.PESSIMISTIC_WRITE); long availSize = self.getAvailableCapacity() + msg.getSize(); if (availSize > self.getTotalCapacity()) { availSize = self.getTotalCapacity(); } self.setAvailableCapacity(availSize); dbf.getEntityManager().merge(self); bus.reply(msg, new ReturnBackupStorageReply()); }
@Transactional private void handle(PrimaryStorageReportCapacityMsg msg) { PrimaryStorageCapacityVO vo = dbf.getEntityManager() .find(PrimaryStorageCapacityVO.class, self.getUuid(), LockModeType.PESSIMISTIC_WRITE); if (vo.getTotalCapacity() == 0) { vo.setTotalCapacity(msg.getTotalCapacity()); vo.setAvailableCapacity(msg.getAvailableCapacity()); dbf.getEntityManager().merge(vo); } PrimaryStorageReportCapacityReply reply = new PrimaryStorageReportCapacityReply(); bus.reply(msg, reply); }
private void handle(APIGetNetworkServiceTypesMsg msg) { Map<String, List<String>> ret = new HashMap<String, List<String>>(); List<NetworkServiceTypeVO> types = dbf.listAll(NetworkServiceTypeVO.class); for (NetworkServiceTypeVO vo : types) { List<String> providers = ret.get(vo.getType()); if (providers == null) { providers = new ArrayList<String>(); ret.put(vo.getType(), providers); } providers.add(vo.getNetworkServiceProviderUuid()); } APIGetNetworkServiceTypesReply reply = new APIGetNetworkServiceTypesReply(); reply.setServiceAndProviderTypes(ret); bus.reply(msg, reply); }
private void handle(final ImageDeletionMsg msg) { final ImageDeletionReply reply = new ImageDeletionReply(); if (self.getBackupStorageRefs().isEmpty()) { // the image is not on any backup storage; mostly likely the image is not in the status of // Ready, for example // it's still downloading // in this case, we directly delete it from the database dbf.remove(self); bus.reply(msg, reply); return; } final ImageDeletionPolicy deletionPolicy = msg.getDeletionPolicy() == null ? deletionPolicyMgr.getDeletionPolicy(self.getUuid()) : ImageDeletionPolicy.valueOf(msg.getDeletionPolicy()); FlowChain chain = FlowChainBuilder.newSimpleFlowChain(); chain.setName(String.format("delete-image-%s", self.getUuid())); Collection<ImageBackupStorageRefVO> toDelete = msg.getBackupStorageUuids() == null ? self.getBackupStorageRefs() : CollectionUtils.transformToList( self.getBackupStorageRefs(), new Function<ImageBackupStorageRefVO, ImageBackupStorageRefVO>() { @Override public ImageBackupStorageRefVO call(ImageBackupStorageRefVO arg) { return msg.getBackupStorageUuids().contains(arg.getBackupStorageUuid()) ? arg : null; } }); for (final ImageBackupStorageRefVO ref : toDelete) { chain.then( new NoRollbackFlow() { String __name__ = String.format( "delete-image-%s-from-backup-storage-%s", self.getUuid(), ref.getBackupStorageUuid()); @Override public void run(final FlowTrigger trigger, Map data) { if (deletionPolicy == ImageDeletionPolicy.Direct) { DeleteBitsOnBackupStorageMsg dmsg = new DeleteBitsOnBackupStorageMsg(); dmsg.setBackupStorageUuid(ref.getBackupStorageUuid()); dmsg.setInstallPath(ref.getInstallPath()); bus.makeTargetServiceIdByResourceUuid( dmsg, BackupStorageConstant.SERVICE_ID, dmsg.getBackupStorageUuid()); bus.send( dmsg, new CloudBusCallBack(trigger) { @Override public void run(MessageReply reply) { if (!reply.isSuccess()) { // TODO logger.warn( String.format( "failed to delete image[uuid:%s, name:%s] from backup storage[uuid:%s] because %s, need to garbage collect it", self.getUuid(), self.getName(), reply.getError(), ref.getBackupStorageUuid())); } else { returnBackupStorageCapacity(ref.getBackupStorageUuid(), self.getSize()); dbf.remove(ref); } trigger.next(); } }); } else if (deletionPolicy == ImageDeletionPolicy.DeleteReference) { dbf.remove(ref); logger.debug( String.format( "delete the image[uuid: %s, name:%s]'s reference of the backup storage[uuid:%s]", self.getUuid(), self.getName(), ref.getBackupStorageUuid())); trigger.next(); } else { ref.setStatus(ImageStatus.Deleted); dbf.update(ref); trigger.next(); } } }); } chain .done( new FlowDoneHandler(msg) { @Override public void handle(Map data) { self = dbf.reload(self); if (self.getBackupStorageRefs().isEmpty()) { dbf.remove(self); if (deletionPolicy == ImageDeletionPolicy.DeleteReference) { logger.debug( String.format( "successfully directly deleted the image[uuid:%s, name:%s] from the database," + " as the policy is DeleteReference, it's still on the physical backup storage", self.getUuid(), self.getName())); } else { logger.debug( String.format( "successfully directly deleted the image[uuid:%s, name:%s]", self.getUuid(), self.getName())); } } else { int deleteCount = 0; for (ImageBackupStorageRefVO ref : self.getBackupStorageRefs()) { if (ref.getStatus() == ImageStatus.Deleted) { deleteCount++; } } if (deleteCount == self.getBackupStorageRefs().size()) { self.setStatus(ImageStatus.Deleted); self = dbf.updateAndRefresh(self); logger.debug( String.format( "successfully deleted the image[uuid:%s, name:%s] with deletion policy[%s]", self.getUuid(), self.getName(), deletionPolicy)); } } bus.reply(msg, reply); } }) .error( new FlowErrorHandler(msg) { @Override public void handle(ErrorCode errCode, Map data) { reply.setError(errCode); bus.reply(msg, reply); } }) .start(); }
private void handle(APIGetDataVolumeAttachableVmMsg msg) { APIGetDataVolumeAttachableVmReply reply = new APIGetDataVolumeAttachableVmReply(); reply.setInventories( VmInstanceInventory.valueOf(getCandidateVmForAttaching(msg.getSession().getAccountUuid()))); bus.reply(msg, reply); }
private void handle(PrimaryStorageReportPhysicalCapacityMsg msg) { updateCapacity(msg.getTotalCapacity(), msg.getAvailableCapacity()); bus.reply(msg, new MessageReply()); }
private void handle(DiskOfferingDeletionMsg msg) { DiskOfferingDeletionReply reply = new DiskOfferingDeletionReply(); dbf.remove(self); logger.debug(String.format("deleted disk offering [uuid:%s]", self.getUuid())); bus.reply(msg, reply); }