private String findHostByUuid(String uuid) { return sql("select uuid from HostVO where uuid = :uuid", String.class).param("uuid", uuid).find(); }
@Transactional(readOnly = true) private long getUsedVxlan(String accountUuid) { long cnt = SQL.New("select count(vxlan) from L2NetworkVO vxlan, AccountResourceRefVO ref where vxlan.uuid = ref.resourceUuid and " + "ref.accountUuid = :auuid and vxlan.type = :rtype", Long.class).param("auuid", accountUuid).param("rtype", VxlanNetworkConstant.VXLAN_NETWORK_TYPE).find(); return cnt; }
@Override protected void scripts() { for (Field field : encryptedFields) { String className = field.getDeclaringClass().getSimpleName(); List<String> uuids = sql(String.format("select uuid from %s", className)).list(); for (String uuid : uuids) { String value = sql(String.format("select %s from %s where uuid = '%s'", field.getName(), className, uuid)).find(); try { String encryptedString = rsa.encrypt1(value); String sql = String.format("update %s set %s = :encrypted where uuid = :uuid", className, field.getName()); Query query = dbf.getEntityManager().createQuery(sql); query.setParameter("encrypted", encryptedString); query.setParameter("uuid", uuid); query.executeUpdate(); } catch (Exception e) { logger.debug(String.format("encrypt error because : %s",e.getMessage())); } } } } }.execute();
@Override protected void scripts() { for (Field field : encryptedFields) { String className = field.getDeclaringClass().getSimpleName(); List<String> uuids = sql(String.format("select uuid from %s", className)).list(); for (String uuid : uuids) { String encryptedString = sql(String.format("select %s from %s where uuid = '%s'", field.getName(), className, uuid)).find(); try { String decryptString = (String) rsa.decrypt1(encryptedString); String sql = String.format("update %s set %s = :decrypted where uuid = :uuid", className, field.getName()); Query query = dbf.getEntityManager().createQuery(sql); query.setParameter("decrypted", decryptString); query.setParameter("uuid", uuid); query.executeUpdate(); } catch (Exception e) { logger.debug(String.format("decrypt password error because : %s",e.getMessage())); } } } } }.execute();
@Override protected void scripts() { for (Field field : encryptedFields) { String className = field.getDeclaringClass().getSimpleName(); List<String> uuids = sql(String.format("select uuid from %s", className)).list(); for (String uuid : uuids) { String encryptedString = sql(String.format("select %s from %s where uuid = '%s'", field.getName(), className, uuid)).find(); try { String decryptString = (String) rsa.decrypt1(encryptedString); encryptedString = rsa.encrypt(decryptString, key); String sql = String.format("update %s set %s = :encrypted where uuid = :uuid", className, field.getName()); Query query = dbf.getEntityManager().createQuery(sql); query.setParameter("encrypted", encryptedString); query.setParameter("uuid", uuid); query.executeUpdate(); } catch (Exception e) { logger.debug(String.format("decrypt origin password error because : %s",e.getMessage())); } } } } }.execute();
@Override protected void scripts() { long count = sql("select count(bs) from BackupStorageVO bs", Long.class).find(); sql("select bs.uuid from BackupStorageVO bs", String.class).limit(1000).paginate(count, (List<String> bsUuids) -> { List<String> byUs = bsUuids.stream() .filter(bsUuid -> destMaker.isManagedByUs(bsUuid)) .collect(Collectors.toList()); track(byUs); }); } }.execute();
@Override protected void scripts() { long count = sql("select count(ps) from PrimaryStorageVO ps", Long.class).find(); sql("select ps.uuid from PrimaryStorageVO ps", String.class).limit(1000).paginate(count, (List<String> psUuids) -> { List<String> byUs = psUuids.stream() .filter(psUuid -> destMaker.isManagedByUs(psUuid)) .collect(Collectors.toList()); track(byUs); }); } }.execute();
@Override protected void scripts() { long count = sql("select count(h) from HostVO h", Long.class).find(); sql("select h.uuid from HostVO h", String.class).limit(1000).paginate(count, (List<String> hostUuids) -> { List<String> byUs = hostUuids.stream().filter(huuid -> { if (skipExisting) { return destMaker.isManagedByUs(huuid) && !trackers.containsKey(huuid); } else { return destMaker.isManagedByUs(huuid); } }).collect(Collectors.toList()); trackHost(byUs); }); } }.execute();
@Transactional(readOnly = true) private void checkVmState(String vmNicUuid){ VmInstanceState state = SQL.New( "select vm.state from VmInstanceVO vm, VmNicVO nic" + " where nic.uuid =:vmNicUuid" + " and vm.uuid = nic.vmInstanceUuid", VmInstanceState.class) .param("vmNicUuid", vmNicUuid).find(); if (!EipConstant.attachableVmStates.contains(state)){ throw new ApiMessageInterceptionException(operr( "vm state[%s] is not allowed to operate eip, maybe you should wait the vm process complete", state.toString())); } } }
private boolean isThereOtherNonLocalStoragePrimaryStorageForTheHost(String hostUuid, String localStorageUuid) { long count = SQL.New( "select count(pri)" + " from PrimaryStorageVO pri, PrimaryStorageClusterRefVO ref, HostVO host" + " where pri.uuid = ref.primaryStorageUuid" + " and ref.clusterUuid = host.clusterUuid" + " and host.uuid = :huuid" + " and pri.uuid != :puuid" + " and pri.type != :pstype", Long.class) .param("huuid", hostUuid) .param("puuid", localStorageUuid) .param("pstype", LocalStorageConstants.LOCAL_STORAGE_TYPE).find(); return count > 0; }
@Transactional(readOnly = true) private List<VmNicInventory> getEipAttachableVmNics(APIGetEipAttachableVmNicsMsg msg){ VipVO vipvo = msg.getEipUuid() == null ? Q.New(VipVO.class).eq(VipVO_.uuid, msg.getVipUuid()).find() : SQL.New("select vip" + " from VipVO vip, EipVO eip" + " where eip.uuid = :eipUuid" + " and eip.vipUuid = vip.uuid") .param("eipUuid", msg.getEipUuid()) .find(); VipInventory vipInv = VipInventory.valueOf(vipvo); List<VmNicInventory> nics = getAttachableVmNicForEip(vipInv); if (nics == null || nics.isEmpty()) { return nics; } logger.debug(String.format("get eip[uuid:%s] attachable vm nics[%s] before filter extension point", msg.getEipUuid(), nics.stream().map(VmNicInventory::getUuid).collect(Collectors.toList()))); nics = filterVmNicsForEipInVirtualRouterExtensionPoint(vipInv, nics); if (nics != null && !nics.isEmpty()) { logger.debug(String.format("get eip[uuid:%s] attachable vm nics[%s] after filter extension point", msg.getEipUuid(), nics.stream().map(VmNicInventory::getUuid).collect(Collectors.toList()))); } return nics; }
@Transactional(readOnly = true) private void checkVipPublicL3Network(String vmNicUuid, String pubL3Uuid){ boolean isPublicL2NetworkAttachedVmCluster = (Long) SQL.New("select count(l3)" + " from VmInstanceVO vm, VmNicVO nic, L2NetworkClusterRefVO ref, L3NetworkVO l3" + " where nic.uuid = :nicUuid" + " and vm.uuid = nic.vmInstanceUuid" + " and ref.clusterUuid = vm.clusterUuid" + " and ref.l2NetworkUuid = l3.l2NetworkUuid" + " and l3.uuid = :publicL3Uuid", Long.class) .param("nicUuid", vmNicUuid) .param("publicL3Uuid", pubL3Uuid) .find() > 0; if (!isPublicL2NetworkAttachedVmCluster){ throw new ApiMessageInterceptionException(argerr("L2Network where vip's L3Network based hasn't attached" + " the cluster where vmNic[uuid:%s] located", vmNicUuid)); } } }
@VmAttachVolumeValidatorMethod static void vmAttachVolumeValidator(String vmUuid, String volumeUuid) { PrimaryStorageState state = SQL.New("select pri.state from PrimaryStorageVO pri " + "where pri.uuid = (select vol.primaryStorageUuid from VolumeVO vol where vol.uuid = :volUuid)", PrimaryStorageState.class) .param("volUuid", volumeUuid) .find(); if(state == PrimaryStorageState.Maintenance){ throw new OperationFailureException( operr("cannot attach volume[uuid:%s] whose primary storage is Maintenance", volumeUuid)); } } }
@Override public void before() { Tuple tuple = SQL.New("select nic.ip, nic.vmInstanceUuid, nic.uuid from VmNicVO nic, PortForwardingRuleVO pfr" + " where pfr.vmNicUuid = nic.uuid and pfr.uuid = :uuid", Tuple.class) .param("uuid", getUuid()).find(); ip = tuple.get(0, String.class); vmUuid = tuple.get(1, String.class); vmNicUuid = tuple.get(2, String.class); }
@Override @Deferred public boolean run() { // get current progress Tuple res = SQL.New("SELECT content, timeToDelete FROM TaskProgressVO" + " WHERE apiId = :apiId" + " ORDER BY CAST(content AS int) DESC", Tuple.class) .param("apiId", apiId) .limit(1) .find(); if (res != null && res.get(1) != null) { // FIXME: race condition here. return true; } int currentPercent = res == null ? 0 : new Double(res.get(0, String.class)).intValue(); Runnable cleanup = saveThreadContext(); Defer.defer(cleanup); ThreadContext.put(THREAD_CONTEXT_API, apiId); ThreadContext.put(THREAD_CONTEXT_TASK_NAME, taskName); if (endPercent <= currentPercent) { reportProgress(String.valueOf(endPercent)); return true; } else { reportProgress(String.valueOf(currentPercent + 1)); return false; } }
@Override public void before() { Tuple tuple = SQL.New("select nic.ip, nic.vmInstanceUuid, nic.uuid, eip.vipIp from VmNicVO nic, EipVO eip" + " where eip.vmNicUuid = nic.uuid and eip.uuid = :uuid", Tuple.class) .param("uuid", getEipUuid()).find(); ip = tuple.get(0, String.class); vmUuid = tuple.get(1, String.class); vmNicUuid = tuple.get(2, String.class); eip = tuple.get(3, String.class); }
@Transactional(readOnly = true) protected void validate(APIAttachEipMsg msg) { String privateL3Uuid = Q.New(VmNicVO.class).select(VmNicVO_.l3NetworkUuid).eq(VmNicVO_.uuid, msg.getVmNicUuid()).findValue(); NetworkServiceProviderType providerType = nwServiceMgr.getTypeOfNetworkServiceProviderForService(privateL3Uuid, EipConstant.EIP_TYPE); if (!providerType.toString().equals(FlatNetworkServiceConstant.FLAT_NETWORK_SERVICE_TYPE_STRING)) { return; } String pubL3Uuid = SQL.New("select vip.l3NetworkUuid from EipVO eip, VipVO vip" + " where eip.uuid = :eipUuid" + " and eip.vipUuid = vip.uuid", String.class) .param("eipUuid", msg.getEipUuid()) .find(); checkVipPublicL3Network(msg.getVmNicUuid(), pubL3Uuid); }
" from LocalStorageResourceRefVO ref" + " where ref.primaryStorageUuid = :psUuid") .param("psUuid", psUuid).find();
@Override protected String scripts() { String uuid = sql("select hostUuid from LocalStorageResourceRefVO where resourceUuid = :resUuid", String.class) .param("resUuid", resUuid) .find(); if (uuid == null) { ResourceVO vo = dbf.findByUuid(resUuid,ResourceVO.class); if (vo != null) { throw new OperationFailureException(operr("cannot find any host which has resource[uuid:%s], name :[%s], type :[%s]" , resUuid, vo.getResourceName(), vo.getResourceType())); } else { throw new OperationFailureException(operr("cannot find any host which has resource[uuid:%s]", resUuid)); } } else if (findHostByUuid(uuid) == null) { throw new OperationFailureException( operr("Resource[uuid:%s] can only be operated on host[uuid:%s], but the host has been deleted", resUuid, uuid)); } return uuid; } }.execute();
.param("l3Uuid", forwardDnsStruct.getL3Network().getUuid()) .param("ttype", L2NetworkVO.class.getSimpleName()) .find(); cmd.setBridgeName(KVMSystemTags.L2_BRIDGE_NAME.getTokenByTag(bridgeName, KVMSystemTags.L2_BRIDGE_NAME_TOKEN)); cmd.setNameSpace(makeNamespaceName(