@Transactional public void cleanTaskProgress(String apiId) { if (apiId == null) { return; } Query query = dbf.getEntityManager().createNativeQuery("select unix_timestamp()"); Long current = ((BigInteger) query.getSingleResult()).longValue() * 1000; SQL.New(TaskProgressVO.class).eq(TaskProgressVO_.apiId, apiId).set(TaskProgressVO_.timeToDelete, current + TimeUnit.SECONDS.toMillis(DELETE_DELAY)).update(); }
@Override protected void scripts() { List<DiskOfferingInventory> diskOfferingInventories = action.getParentIssuerContext(); sql(VolumeVO.class).set(VolumeVO_.diskOfferingUuid, null) .in(VolumeVO_.uuid, diskOfferingInventories.stream().map(DiskOfferingInventory::getUuid).collect(Collectors.toList())) .update(); } }.execute();
protected void success() { assert uuid != null; assert canceller != null; logger.debug(String.format("[GC] a job[name:%s, id:%s] completes successfully", NAME, uuid)); canceller.run(); SQL.New(GarbageCollectorVO.class) .eq(GarbageCollectorVO_.uuid, uuid) .set(GarbageCollectorVO_.status, GCStatus.Done).update(); gcMgr.deregisterGC(this); }
@Override protected void scripts() { sql(VmInstanceVO.class) .eq(VmInstanceVO_.uuid, vmInstanceUuid) .set(VmInstanceVO_.hostUuid, replyHostUuid) .update(); } }.execute();
protected void cancel() { assert uuid != null; assert canceller != null; logger.debug(String.format("[GC] a job[name:%s, id:%s] is cancelled by itself", NAME, uuid)); canceller.run(); SQL.New(GarbageCollectorVO.class) .eq(GarbageCollectorVO_.uuid, uuid) .set(GarbageCollectorVO_.status, GCStatus.Done).update(); gcMgr.deregisterGC(this); }
@Override protected SessionInventory scripts() { Timestamp expiredDate = new Timestamp(TimeUnit.SECONDS.toMillis(finalExtendPeriod) + getCurrentSqlDate().getTime()); SessionInventory s = getSession(uuid); s.setExpiredDate(expiredDate); sql(SessionVO.class).eq(SessionVO_.uuid, uuid).set(SessionVO_.expiredDate, expiredDate).update(); return s; } }.execute();
@Override protected void success() { assert uuid != null; unlock(); logger.debug(String.format("[GC] a job[name:%s, id:%s] completes successfully", NAME, uuid)); SQL.New(GarbageCollectorVO.class) .eq(GarbageCollectorVO_.uuid, uuid) .set(GarbageCollectorVO_.status, GCStatus.Idle).update(); super.setupTimer(); } }
@Override public void vmStateChanged(VmInstanceInventory vm, VmInstanceState oldState, VmInstanceState newState) { if (newState == VmInstanceState.Destroyed && vm != null && vm.getRootVolumeUuid() != null) { SQL.New(VolumeVO.class).eq(VolumeVO_.uuid, vm.getRootVolumeUuid()) .set(VolumeVO_.status, VolumeStatus.Deleted) .update(); } } }
@Override public void handle(Map data) { /* update vm last host uuid */ SQL.New(VmInstanceVO.class).eq(VmInstanceVO_.uuid, struct.getVmUuid()).set(VmInstanceVO_.lastHostUuid, msg.getDestHostUuid()) .set(VmInstanceVO_.hostUuid, msg.getDestHostUuid()).update(); bus.publish(evt); } }).error(new FlowErrorHandler(msg) {
private void doLoadLongJob(LongJobVO vo, LongJobOperation operation) { if (operation == null) { operation = getLoadOperation(vo); } if (operation == LongJobOperation.Start) { // launch the waiting jobs ThreadContext.put(Constants.THREAD_CONTEXT_API, vo.getApiId()); LongJob job = longJobFactory.getLongJob(vo.getJobName()); ThreadContext.put(Constants.THREAD_CONTEXT_TASK_NAME, job.getClass().toString()); doStartJob(job, vo, null); SQL.New(LongJobVO.class).eq(LongJobVO_.uuid, vo.getUuid()).set(LongJobVO_.state, LongJobState.Running).update(); } else if (operation == LongJobOperation.Resume) { ThreadContext.put(Constants.THREAD_CONTEXT_API, vo.getApiId()); LongJob job = longJobFactory.getLongJob(vo.getJobName()); ThreadContext.put(Constants.THREAD_CONTEXT_TASK_NAME, job.getClass().toString()); logger.info(String.format("start to resume longjob [uuid:%s, name:%s]", vo.getUuid(), vo.getName())); job.resume(vo); dbf.update(vo); } }
private void handle(APIUpdateNotificationsStatusMsg msg) { APIUpdateNotificationsStatusEvent evt = new APIUpdateNotificationsStatusEvent(msg.getId()); SQL.New(NotificationVO.class).set(NotificationVO_.status, NotificationStatus.valueOf(msg.getStatus())) .in(NotificationVO_.uuid, msg.getUuids()).update(); bus.publish(evt); }
@Override public void afterAddIpAddress(String vmNicUUid, String usedIpUuid) { /* update UsedIpVO */ SQL.New(UsedIpVO.class).eq(UsedIpVO_.uuid, usedIpUuid).set(UsedIpVO_.vmNicUuid, vmNicUUid).update(); VmNicVO nic = Q.New(VmNicVO.class).eq(VmNicVO_.uuid, vmNicUUid).find(); UsedIpVO temp = null; /* if there is ipv4 addresses, we put the first attached ipv4 address to VmNic.ip * or we put the first attached ipv6 address to vmNic.Ip */ List<UsedIpVO> refs = Q.New(UsedIpVO.class).eq(UsedIpVO_.ipVersion, IPv6Constants.IPv4) .eq(UsedIpVO_.vmNicUuid, vmNicUUid).orderBy(UsedIpVO_.createDate, SimpleQuery.Od.ASC).list(); if (refs != null && !refs.isEmpty()) { temp = refs.get(0); } else { refs = Q.New(UsedIpVO.class).eq(UsedIpVO_.ipVersion, IPv6Constants.IPv6) .eq(UsedIpVO_.vmNicUuid, vmNicUUid).orderBy(UsedIpVO_.createDate, SimpleQuery.Od.ASC).list(); if (refs != null && !refs.isEmpty()) { temp = refs.get(0); } } if (!temp.getUuid().equals(nic.getUsedIpUuid())) { SQL.New(VmNicVO.class).eq(VmNicVO_.uuid, vmNicUUid) .set(VmNicVO_.ip, temp.getIp()) .set(VmNicVO_.netmask, temp.getNetmask()) .set(VmNicVO_.gateway, temp.getGateway()) .set(VmNicVO_.usedIpUuid, temp.getUuid()) .set(VmNicVO_.ipVersion, temp.getIpVersion()) .set(VmNicVO_.l3NetworkUuid, temp.getL3NetworkUuid()).update(); } }
.set(VmInstanceVO_.rootVolumeUuid, inv.getUuid()) .condAnd(VmInstanceVO_.uuid, Op.EQ, spec.getVmInventory().getUuid()) .update(); } else { spec.getDestDataVolumes().add(inv);
@Override protected void scripts() { if (!q(AccountVO.class) .eq(AccountVO_.name, AccountConstant.INITIAL_SYSTEM_ADMIN_NAME) .eq(AccountVO_.type, AccountType.SystemAdmin).isExists()) { AccountVO vo = new AccountVO(); vo.setUuid(AccountConstant.INITIAL_SYSTEM_ADMIN_UUID); vo.setName(AccountConstant.INITIAL_SYSTEM_ADMIN_NAME); vo.setPassword(AccountConstant.INITIAL_SYSTEM_ADMIN_PASSWORD); vo.setType(AccountType.SystemAdmin); persist(vo); flush(); logger.debug(String.format("Created initial system admin account[name:%s]", AccountConstant.INITIAL_SYSTEM_ADMIN_NAME)); } sql(PolicyVO.class).eq(PolicyVO_.name, "DEFAULT-READ").set(PolicyVO_.data, readAPIsForNormalAccountJSONStatement).update(); } }.execute();
@Override public void success() { List<Tuple> eips = findEipTuplesOnVmNic(nic);; if (eips == null || eips.isEmpty()) { completion.success(); } else { for (Tuple eipTuple : eips) { VirtualRouterEipRefVO ref = Q.New(VirtualRouterEipRefVO.class) .eq(VirtualRouterEipRefVO_.eipUuid, eipTuple.get(5, String.class)) .eq(VirtualRouterEipRefVO_.virtualRouterVmUuid, nic.getVmInstanceUuid()) .find(); if (ref != null) { dbf.remove(ref); UpdateQuery q = UpdateQuery.New(EipVO.class); q.condAnd(EipVO_.uuid, Op.EQ, eipTuple.get(5, String.class)); q.set(EipVO_.vmNicUuid, null); q.set(EipVO_.guestIp, null); q.update(); } } completion.success(); } }
@Override public void afterDelIpAddress(String vmNicUUid, String usedIpUuid) { VmNicVO nic = Q.New(VmNicVO.class).eq(VmNicVO_.uuid, vmNicUUid).find(); if (nic.getUsedIpUuid() != null && !nic.getUsedIpUuid().equals(usedIpUuid)) { return; } UsedIpVO temp = null; /* if there is ipv4 addresses, we put the first attached ipv4 address to VmNic.ip * or we put the first attached ipv6 address to vmNic.Ip */ List<UsedIpVO> refs = Q.New(UsedIpVO.class).eq(UsedIpVO_.ipVersion, IPv6Constants.IPv4) .eq(UsedIpVO_.vmNicUuid, vmNicUUid).orderBy(UsedIpVO_.createDate, SimpleQuery.Od.ASC).list(); if (refs != null && !refs.isEmpty()) { temp = refs.get(0); } else { refs = Q.New(UsedIpVO.class).eq(UsedIpVO_.ipVersion, IPv6Constants.IPv6) .eq(UsedIpVO_.vmNicUuid, vmNicUUid).orderBy(UsedIpVO_.createDate, SimpleQuery.Od.ASC).list(); if (refs != null && !refs.isEmpty()) { temp = refs.get(0); } } if (temp != null) { SQL.New(VmNicVO.class).eq(VmNicVO_.uuid, vmNicUUid) .set(VmNicVO_.ip, temp.getIp()) .set(VmNicVO_.netmask, temp.getNetmask()) .set(VmNicVO_.gateway, temp.getGateway()) .set(VmNicVO_.usedIpUuid, temp.getUuid()) .set(VmNicVO_.ipVersion, temp.getIpVersion()) .set(VmNicVO_.l3NetworkUuid, temp.getL3NetworkUuid()).update(); } }
@Override @Deferred public void run(SyncTaskChain chain) { refreshVO(); Defer.defer(() -> { ChangeVolumeStatusReply reply = new ChangeVolumeStatusReply(); bus.reply(msg, reply); }); if (self == null) { // volume has been deleted by previous request // this happens when delete vm request queued before // migrating trigger not by api // in this case, ignore change state request logger.debug(String.format("volume[uuid:%s] has been deleted, ignore change volume state request", msg.getVolumeUuid())); chain.next(); return; } VolumeStatus bs = self.getStatus(); SQL.New(VolumeVO.class).eq(VolumeVO_.uuid, msg.getVolumeUuid()).set(VolumeVO_.status, msg.getStatus()).update(); refreshVO(); logger.debug(String.format("volume[uuid:%s] status changed from %s to %s in db", self.getUuid(), bs, self.getStatus())); chain.next(); }
@Override protected void scripts() { VirtualRouterOfferingVO offering = findByUuid(offeringUuid, VirtualRouterOfferingVO.class); if (!Q.New(VirtualRouterOfferingVO.class).eq(VirtualRouterOfferingVO_.zoneUuid, zoneUuid) .notEq(VirtualRouterOfferingVO_.uuid, offeringUuid).isExists() && created) { // the first offering is always the default one offering.setDefault(true); merge(offering); return; } if (preferToBeDefault != null && preferToBeDefault) { sql(VirtualRouterOfferingVO.class).set(VirtualRouterOfferingVO_.isDefault, false) .eq(VirtualRouterOfferingVO_.zoneUuid, zoneUuid).update(); reload(offering); offering.setDefault(true); merge(offering); } else if (preferToBeDefault != null) { offering.setDefault(false); merge(offering); } flush(); } }.execute();
.eq(PrimaryStorageHostRefVO_.hostUuid, huuid) .set(PrimaryStorageHostRefVO_.status, newStatus) .update();
@Override protected void scripts() { String acntUuid = Account.getAccountUuidOfResource(spec.getVmInventory().getUuid()); spec.getDestNics().forEach(nic -> { VmNicVO nvo = new VmNicVO(); nvo.setUuid(nic.getUuid()); nvo.setDeviceId(nic.getDeviceId()); nvo.setIp(nic.getIp()); nvo.setL3NetworkUuid(nic.getL3NetworkUuid()); nvo.setMac(nic.getMac()); nvo.setHypervisorType(nic.getHypervisorType()); nvo.setUsedIpUuid(nic.getUsedIpUuid()); nvo.setGateway(nic.getGateway()); nvo.setNetmask(nic.getNetmask()); nvo.setVmInstanceUuid(nic.getVmInstanceUuid()); nvo.setMetaData(nic.getMetaData()); nvo.setInternalName(nic.getInternalName()); nvo.setAccountUuid(acntUuid); nvo.setIpVersion(nic.getIpVersion()); persist(nvo); if (nic.getUsedIpUuid() != null) { SQL.New(UsedIpVO.class).eq(UsedIpVO_.uuid, nic.getUsedIpUuid()).set(UsedIpVO_.vmNicUuid, nvo.getUuid()).update(); } }); ApplianceVmVO apvm = findByUuid(spec.getVmInventory().getUuid(), ApplianceVmVO.class); apvm.setManagementNetworkUuid(mgmtNic.getL3NetworkUuid()); merge(apvm); } }.execute();