public VmInstanceBase(VmInstanceVO vo) { this.self = vo; this.syncThreadName = "Vm-" + vo.getUuid(); this.originalCopy = ObjectUtils.newAndCopy(vo, vo.getClass()); }
public static <T> List<T> serializableCopyList(List<T> sourceList) throws IOException, ClassNotFoundException { if(sourceList == null){ return null; } List<T> copyList = new ArrayList<>(); for(T o : sourceList){ copyList.add(serializableCopy(o)); } return copyList; } }
private void updateEO(Object entity, DataIntegrityViolationException de) { if (!MySQLIntegrityConstraintViolationException.class.isAssignableFrom(de.getRootCause().getClass())) { throw de; } MySQLIntegrityConstraintViolationException me = (MySQLIntegrityConstraintViolationException) de.getRootCause(); if (!(me.getErrorCode() == 1062 && "23000".equals(me.getSQLState()) && me.getMessage().contains("PRIMARY"))) { throw de; } if (!hasEO()) { throw de; } // at this point, the error is caused by a update tried on VO entity which has been soft deleted. This is mostly // caused by a deletion cascade(e.g deleting host will cause vm running on it to be deleted, and deleting vm is trying to return capacity // to host which has been soft deleted, because vm deletion is executed in async manner). In this case, we make the update to EO table Object idval = getEOPrimaryKeyValue(entity); Object eo = getEntityManager().find(eoClass, idval); final Object deo = ObjectUtils.copy(eo, entity); new Runnable() { @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public void run() { getEntityManager().merge(deo); } }.run(); logger.debug(String.format("A EO[%s] update has been made", eoClass.getName())); }
protected VmInstanceVO refreshVO(boolean noException) { VmInstanceVO vo = self; self = dbf.findByUuid(self.getUuid(), VmInstanceVO.class); if (self == null && noException) { return null; } if (self == null) { throw new OperationFailureException(operr("vm[uuid:%s, name:%s] has been deleted", vo.getUuid(), vo.getName())); } originalCopy = ObjectUtils.newAndCopy(vo, vo.getClass()); return self; }
private void diskOfferingPassThrough(DiskOfferingMessage msg) { DiskOfferingVO vo = dbf.findByUuid(msg.getDiskOfferingUuid(), DiskOfferingVO.class); if (vo == null && allowedInstanceOfferingMessageAfterSoftDeletion.contains(msg.getClass())) { DiskOfferingEO eo = dbf.findByUuid(msg.getDiskOfferingUuid(), DiskOfferingEO.class); vo = ObjectUtils.newAndCopy(eo, DiskOfferingVO.class); } if (vo == null) { bus.replyErrorByMessageType((Message) msg, String.format("cannot find DiskOffering[uuid:%s]," + " it may have been deleted", msg.getDiskOfferingUuid())); return; } DiskOfferingFactory factory = getDiskOfferingFactory(vo.getType()); DiskOffering offering = factory.getDiskOffering(vo); offering.handleMessage((Message) msg); }
private void instanceOfferingPassThrough(InstanceOfferingMessage msg) { InstanceOfferingVO vo = dbf.findByUuid(msg.getInstanceOfferingUuid(), InstanceOfferingVO.class); if (vo == null && allowedInstanceOfferingMessageAfterSoftDeletion.contains(msg.getClass())) { InstanceOfferingEO eo = dbf.findByUuid(msg.getInstanceOfferingUuid(), InstanceOfferingEO.class); vo = ObjectUtils.newAndCopy(eo, InstanceOfferingVO.class); } if (vo == null) { bus.replyErrorByMessageType((Message) msg, String.format("cannot find InstanceOffering[uuid:%s]," + " it may have been deleted", msg.getInstanceOfferingUuid())); return; } InstanceOfferingFactory factory = getInstanceOfferingFactory(vo.getType()); InstanceOffering offering = factory.getInstanceOffering(vo); offering.handleMessage((Message) msg); }
void passThrough(VmInstanceMessage msg) { VmInstanceVO vo = dbf.findByUuid(msg.getVmInstanceUuid(), VmInstanceVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(msg.getClass())) { VmInstanceEO eo = dbf.findByUuid(msg.getVmInstanceUuid(), VmInstanceEO.class); vo = ObjectUtils.newAndCopy(eo, VmInstanceVO.class); } if (vo == null) { String err = String.format("Cannot find VmInstance[uuid:%s], it may have been deleted", msg.getVmInstanceUuid()); bus.replyErrorByMessageType((Message) msg, err); return; } VmInstanceFactory factory = getVmInstanceFactory(VmInstanceType.valueOf(vo.getType())); VmInstance vm = factory.getVmInstance(vo); vm.handleMessage((Message) msg); }
private void passThrough(ClusterMessage msg) { ClusterVO vo = dbf.findByUuid(msg.getClusterUuid(), ClusterVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(msg.getClass())) { ClusterEO eo = dbf.findByUuid(msg.getClusterUuid(), ClusterEO.class); vo = ObjectUtils.newAndCopy(eo, ClusterVO.class); } if (vo == null) { String err = String.format("Cannot find cluster: %s, it may have been deleted", msg.getClusterUuid()); bus.replyErrorByMessageType((Message) msg, err); return; } ClusterFactory factory = this.getClusterFactory(ClusterType.valueOf(vo.getType())); Cluster cluster = factory.getCluster(vo); cluster.handleMessage((Message) msg); }
private void passThrough(String l3NetworkUuid, Message msg) { L3NetworkVO vo = dbf.findByUuid(l3NetworkUuid, L3NetworkVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(msg.getClass())) { L3NetworkEO eo = dbf.findByUuid(l3NetworkUuid, L3NetworkEO.class); vo = ObjectUtils.newAndCopy(eo, L3NetworkVO.class); } if (vo == null) { ErrorCode err = err(SysErrors.RESOURCE_NOT_FOUND, "Unable to find L3Network[uuid:%s], it may have been deleted", l3NetworkUuid); bus.replyErrorByMessageType(msg, err); return; } L3NetworkFactory factory = getL3NetworkFactory(L3NetworkType.valueOf(vo.getType())); L3Network nw = factory.getL3Network(vo); nw.handleMessage(msg); }
private void passThrough(BackupStorageMessage pmsg) { BackupStorageVO vo = dbf.findByUuid(pmsg.getBackupStorageUuid(), BackupStorageVO.class); if (vo == null && allowedMessageAfterDeletion.contains(pmsg.getClass())) { BackupStorageEO eo = dbf.findByUuid(pmsg.getBackupStorageUuid(), BackupStorageEO.class); vo = ObjectUtils.newAndCopy(eo, BackupStorageVO.class); } Message msg = (Message) pmsg; if (vo == null) { String err = String.format("Cannot find backup storage[uuid:%s], it may have been deleted", pmsg.getBackupStorageUuid()); bus.replyErrorByMessageType(msg, err); return; } BackupStorageFactory factory = getBackupStorageFactory(BackupStorageType.valueOf(vo.getType())); BackupStorageVO finalVo = vo; BackupStorage ss = New(()-> factory.getBackupStorage(finalVo)); ss.handleMessage(msg); }
private void passThrough(HostMessage msg) { HostVO vo = dbf.findByUuid(msg.getHostUuid(), HostVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(msg.getClass())) { HostEO eo = dbf.findByUuid(msg.getHostUuid(), HostEO.class); vo = ObjectUtils.newAndCopy(eo, HostVO.class); } if (vo == null) { ErrorCode err = Platform.err(SysErrors.RESOURCE_NOT_FOUND, "cannot find host[uuid:%s], it may have been deleted", msg.getHostUuid()); throw new OperationFailureException(err); } HypervisorFactory factory = this.getHypervisorFactory(HypervisorType.valueOf(vo.getHypervisorType())); Host host = factory.getHost(vo); host.handleMessage((Message) msg); }
private void passThrough(ZoneMessage msg) { ZoneVO vo = dbf.findByUuid(msg.getZoneUuid(), ZoneVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(msg.getClass())) { ZoneEO eo = dbf.findByUuid(msg.getZoneUuid(), ZoneEO.class); vo = ObjectUtils.newAndCopy(eo, ZoneVO.class); } if (vo == null) { ErrorCode err = err(SysErrors.RESOURCE_NOT_FOUND, "unable to find zone[uuid:%s], it may have been deleted", msg.getZoneUuid()); bus.replyErrorByMessageType((Message)msg, err); return; } ZoneFactory factory = this.getZoneFactory(ZoneType.valueOf(vo.getType())); Zone zone = factory.getZone(vo); zone.handleMessage((Message)msg); }
private void passThrough(L2NetworkMessage msg) { Message amsg = (Message) msg; L2NetworkVO vo = dbf.findByUuid(msg.getL2NetworkUuid(), L2NetworkVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(msg.getClass())) { L2NetworkEO eo = dbf.findByUuid(msg.getL2NetworkUuid(), L2NetworkEO.class); vo = ObjectUtils.newAndCopy(eo, L2NetworkVO.class); } if (vo == null) { ErrorCode errCode = err(SysErrors.RESOURCE_NOT_FOUND, "unable to find L2Network[uuid:%s], it may have been deleted", msg.getL2NetworkUuid()); bus.replyErrorByMessageType((Message)msg, errCode); return; } L2NetworkFactory factory = getL2NetworkFactory(L2NetworkType.valueOf(vo.getType())); L2Network nw = factory.getL2Network(vo); nw.handleMessage(amsg); }
private void passThrough(PrimaryStorageMessage pmsg) { PrimaryStorageVO vo = dbf.findByUuid(pmsg.getPrimaryStorageUuid(), PrimaryStorageVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(pmsg.getClass())) { PrimaryStorageEO eo = dbf.findByUuid(pmsg.getPrimaryStorageUuid(), PrimaryStorageEO.class); vo = ObjectUtils.newAndCopy(eo, PrimaryStorageVO.class); } Message msg = (Message) pmsg; if (vo == null) { bus.replyErrorByMessageType(msg, err(SysErrors.RESOURCE_NOT_FOUND, "Cannot find primary storage[uuid:%s], it may have been deleted", pmsg.getPrimaryStorageUuid())); return; } PrimaryStorageFactory factory = getPrimaryStorageFactory(PrimaryStorageType.valueOf(vo.getType())); PrimaryStorageVO finalVo = vo; PrimaryStorage ps = Platform.New(()-> factory.getPrimaryStorage(finalVo)); ps.handleMessage(msg); }
private void passThrough(ImageMessage msg) { ImageVO vo = dbf.findByUuid(msg.getImageUuid(), ImageVO.class); if (vo == null && allowedMessageAfterDeletion.contains(msg.getClass())) { ImageEO eo = dbf.findByUuid(msg.getImageUuid(), ImageEO.class); vo = ObjectUtils.newAndCopy(eo, ImageVO.class); } if (vo == null) { ErrorCode err = err(SysErrors.RESOURCE_NOT_FOUND, "Cannot find image[uuid:%s], it may have been deleted", msg.getImageUuid()); logger.warn(err.getDetails()); bus.replyErrorByMessageType((Message) msg, err); return; } ImageFactory factory = getImageFacotry(ImageType.valueOf(vo.getType())); Image img = factory.getImage(vo); img.handleMessage((Message) msg); }