org.zstack.core.db.Q.in()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(14.0k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中org.zstack.core.db.Q.in方法的一些代码示例,展示了Q.in的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Q.in方法的具体详情如下:
包路径:org.zstack.core.db.Q
类名称:Q
方法名:in

Q.in介绍

暂无

代码示例

代码示例来源:origin: zstackio/zstack

private void validate(APIAddMonToCephBackupStorageMsg msg) {
  checkMonUrls(msg.getMonUrls());
  List<String> hostnames = msg.getMonUrls().stream()
      .map(MonUri::new)
      .map(MonUri::getHostname)
      .collect(Collectors.toList());
  if (Q.New(CephBackupStorageMonVO.class).in(CephBackupStorageMonVO_.hostname, hostnames).isExists()){
    throw new ApiMessageInterceptionException(argerr("Adding the same Mon node is not allowed"));
  }
}
private void validate(APIUpdateCephBackupStorageMonMsg msg) {

代码示例来源:origin: zstackio/zstack

private void validate(APIAddMonToCephPrimaryStorageMsg msg) {
  checkMonUrls(msg.getMonUrls());
  List<String> hostnames = msg.getMonUrls().stream()
      .map(MonUri::new)
      .map(MonUri::getHostname)
      .collect(Collectors.toList());
  if (Q.New(CephPrimaryStorageMonVO.class).in(CephPrimaryStorageMonVO_.hostname, hostnames).isExists()){
    throw new ApiMessageInterceptionException(argerr("Adding the same Mon node is not allowed"));
  }
}

代码示例来源:origin: zstackio/zstack

private List<String> getNeedRefreshSizeVolumeUuids(){
    Set<String> volUuids = new HashSet<>();
    for (RefreshVolumeSizeExtensionPoint ext : pluginRgty.getExtensionList(RefreshVolumeSizeExtensionPoint.class)) {
      volUuids.addAll(ext.getNeedRefreshVolumeSizeVolume());
    }
    return volUuids.isEmpty() ? new ArrayList<>() : Q.New(VolumeVO.class).in(VolumeVO_.uuid, volUuids)
        .eq(VolumeVO_.state, VolumeState.Enabled)
        .eq(VolumeVO_.status, VolumeStatus.Ready)
        .select(VolumeVO_.uuid)
        .listValues();
  }
}

代码示例来源:origin: zstackio/zstack

private Map<String, String> getUuidTypeMapByResourceUuids(List<String> resourceUuids) {
  List<Tuple> ts = Q.New(AccountResourceRefVO.class)
      .select(AccountResourceRefVO_.resourceUuid, AccountResourceRefVO_.resourceType)
      .in(AccountResourceRefVO_.resourceUuid, resourceUuids)
      .listTuple();
  Map<String, String> uuidType = new HashMap<String, String>();
  for (Tuple t : ts) {
    String resUuid = t.get(0, String.class);
    String resType = t.get(1, String.class);
    uuidType.put(resUuid, resType);
  }
  return uuidType;
}

代码示例来源:origin: zstackio/zstack

@Override
  protected List<SecurityGroupDeletionMsg> scripts() {
    List<String> uuids = q(AccountResourceRefVO.class)
        .select(AccountResourceRefVO_.resourceUuid)
        .eq(AccountResourceRefVO_.resourceType, SecurityGroupVO.class.getSimpleName())
        .in(AccountResourceRefVO_.ownerAccountUuid, accountUuids)
        .listValues();
    if (uuids.isEmpty()) {
      return null;
    }
    return uuids.stream().map(auuid -> {
      SecurityGroupDeletionMsg msg = new SecurityGroupDeletionMsg();
      msg.setUuid(auuid);
      bus.makeTargetServiceIdByResourceUuid(msg, SecurityGroupConstant.SERVICE_ID, auuid);
      return msg;
    }).collect(Collectors.toList());
  }
}.execute();

代码示例来源:origin: zstackio/zstack

@Transactional(readOnly = true)
private VirtualRouterVmInventory findVirtualRouterVm(String lbUuid, List<String> vmNics) {
  String sql = "select vr from VirtualRouterVmVO vr, VirtualRouterLoadBalancerRefVO ref where ref.virtualRouterVmUuid =" +
      " vr.uuid and ref.loadBalancerUuid = :lbUuid";
  TypedQuery<VirtualRouterVmVO> q = dbf.getEntityManager().createQuery(sql, VirtualRouterVmVO.class);
  q.setParameter("lbUuid", lbUuid);
  List<VirtualRouterVmVO> vrs = q.getResultList();
  if (LoadBalancerSystemTags.SEPARATE_VR.hasTag(lbUuid)) {
    Optional<VirtualRouterVmVO> vr = vrs.stream()
        .filter(v -> VirtualRouterSystemTags.DEDICATED_ROLE_VR.hasTag(v.getUuid()))
        .findFirst();
    if (!vr.isPresent()) {
      return null;
    }
    List<String> vmNicL3NetworkUuids = Q.New(VmNicVO.class).select(VmNicVO_.l3NetworkUuid).in(VmNicVO_.uuid, vmNics).listValues();
    VirtualRouterVmInventory vrInventory = VirtualRouterVmInventory.valueOf(vr.get());
    vmNicL3NetworkUuids.removeAll(vrInventory.getGuestL3Networks());
    if (!vmNicL3NetworkUuids.isEmpty()) {
      logger.debug(String.format("found l3 networks[uuids:%s] not attached to separate vr[uuid:%s] for loadbalancer[uuid:%s]",
          vmNicL3NetworkUuids, vr.get().getUuid(), lbUuid));
      throw new CloudRuntimeException(String.format("not support separate vr with multiple networks vpc!"));
    }
  }
  DebugUtils.Assert(vrs.size() <= 1, String.format("multiple virtual routers[uuids:%s] found",
      vrs.stream().map(v -> v.getUuid()).collect(Collectors.toList())));
  return vrs.isEmpty() ? null : VirtualRouterVmInventory.valueOf(vrs.get(0));
}

代码示例来源:origin: zstackio/zstack

private List<EipInventory> eipFromAction(CascadeAction action) {
    if (VipVO.class.getSimpleName().equals(action.getParentIssuer())) {
      List<String> vipUuids = CollectionUtils.transformToList((List<VipInventory>) action.getParentIssuerContext(), new Function<String, VipInventory>() {
        @Override
        public String call(VipInventory arg) {
          return arg.getUuid();
        }
      });
      if (vipUuids.isEmpty()) {
        return null;
      }

      List<EipVO> eipVOS = Q.New(EipVO.class).in(EipVO_.vipUuid, vipUuids).list();

      return EipInventory.valueOf(eipVOS);
    } else if (EipVO.class.getSimpleName().equals(action.getParentIssuer())) {
      return action.getParentIssuerContext();
    }
    return null;
  }
}

代码示例来源:origin: zstackio/zstack

.in(NetworkServiceL3NetworkRefVO_.l3NetworkUuid, l3Uuids)
.eq(NetworkServiceL3NetworkRefVO_.networkServiceType, LoadBalancerConstants.LB_NETWORK_SERVICE_TYPE_STRING)
.listValues());

代码示例来源:origin: zstackio/zstack

private List<String> getTargetVmUuids() {
    List<String> result = new ArrayList<>();

    List<String> allVmUuids = Q.New(VmInstanceVO.class)
        .select(VmInstanceVO_.uuid)
        .eq(VmInstanceVO_.type, VmInstanceConstant.USER_VM_TYPE)
        .eq(VmInstanceVO_.hypervisorType, VmInstanceConstant.KVM_HYPERVISOR_TYPE)
        .listValues();

    for (String vmUuid : allVmUuids) {
      if (destinationMaker.isManagedByUs(vmUuid)) {
        result.add(vmUuid);
      }
    }

    if (result.isEmpty()) {
      return result;
    }

    List<String> hasCdRomVmUuids = Q.New(VmCdRomVO.class)
        .select(VmCdRomVO_.vmInstanceUuid)
        .in(VmCdRomVO_.vmInstanceUuid, result)
        .listValues();

    result.removeAll(hasCdRomVmUuids);
    return result;
  }
}

代码示例来源:origin: zstackio/zstack

private List<VtepInventory> vtepFromAction(CascadeAction action) {
  List<VtepInventory> ret = null;
  if (L2NetworkVO.class.getSimpleName().equals(action.getParentIssuer())) {
    List<String> l2uuids = CollectionUtils.transformToList((List<L2NetworkInventory>)action.getParentIssuerContext(), new Function<String, L2NetworkInventory>() {
      @Override
      public String call(L2NetworkInventory arg) {
        return arg.getUuid();
      }
    });
    List<VtepVO> vos = Q.New(VtepVO.class).in(VtepVO_.poolUuid, l2uuids).list();
    if (!vos.isEmpty()) {
      ret = VtepInventory.valueOf(vos);
    }
  }  else if (NAME.equals(action.getParentIssuer())) {
    ret = action.getParentIssuerContext();
  }
  return ret;
}

代码示例来源:origin: zstackio/zstack

@Transactional(readOnly = true)
private boolean noStorageAccessible(String hostUuid){
  // detach ps will delete PrimaryStorageClusterRefVO first.
  List<String> attachedPsUuids = SQL.New("select distinct ref.primaryStorageUuid" +
      " from PrimaryStorageClusterRefVO ref, HostVO h" +
      " where h.uuid =:hostUuid" +
      " and ref.clusterUuid = h.clusterUuid", String.class)
      .param("hostUuid", hostUuid)
      .list();
  long attachedPsCount = attachedPsUuids.size();
  long inaccessiblePsCount = attachedPsCount == 0 ? 0 : Q.New(PrimaryStorageHostRefVO.class)
      .eq(PrimaryStorageHostRefVO_.hostUuid, hostUuid)
      .eq(PrimaryStorageHostRefVO_.status, PrimaryStorageHostStatus.Disconnected)
      .in(PrimaryStorageHostRefVO_.primaryStorageUuid, attachedPsUuids)
      .count();
  return inaccessiblePsCount == attachedPsCount && attachedPsCount > 0;
}

代码示例来源:origin: zstackio/zstack

private void checkIfTheAccountOwnTheResource(APIMessage.FieldParam param) throws IllegalAccessException {
  List<String> uuids = getResourceUuids(param);
  if (uuids.isEmpty()) {
    return;
  }
  Class resourceType = param.param.resourceType();
  List<Tuple> ts = q(AccountResourceRefVO.class).select(AccountResourceRefVO_.accountUuid, AccountResourceRefVO_.resourceUuid)
      .in(AccountResourceRefVO_.resourceUuid, uuids)
      //.eq(AccountResourceRefVO_.resourceType, acntMgr.getBaseResourceType(resourceType).getSimpleName())
      .listTuple();
  ts.addAll(
      q(SharedResourceVO.class).select(SharedResourceVO_.receiverAccountUuid, SharedResourceVO_.resourceUuid)
          .in(SharedResourceVO_.resourceUuid, uuids)
          .eq(SharedResourceVO_.permission, SharedResourceVO.PERMISSION_WRITE)
          .eq(SharedResourceVO_.receiverAccountUuid, rbacEntity.getApiMessage().getSession().getAccountUuid())
          //.eq(SharedResourceVO_.resourceType, acntMgr.getBaseResourceType(resourceType).getSimpleName())
          .listTuple()
  );
  Collection<AccountResourceBundle> bundles = toAccountResourceBundles(uuids, ts);
  uuids.forEach(uuid -> {
    Optional<AccountResourceBundle> opt = bundles.stream().filter(b -> b.accountUuid.equals(rbacEntity.getApiMessage().getSession().getAccountUuid()) && b.resourceUuid.equals(uuid)).findFirst();
    if (!opt.isPresent()) {
      throw new OperationFailureException(operr("permission denied, the account[uuid:%s] is not the owner of the resource[uuid:%s, type:%s]",
          rbacEntity.getApiMessage().getSession().getAccountUuid(), uuid, resourceType.getSimpleName()));
    }
  });
}

代码示例来源:origin: zstackio/zstack

.in(SharedResourceVO_.resourceUuid, checkAccountResourceUuids)
    .eq(SharedResourceVO_.toPublic, true).listValues();
checkAccountResourceUuids.removeAll(shared);

代码示例来源:origin: zstackio/zstack

private void pingAll(PrimaryStorageInventory inv, int limit, final Completion completion){
  List<String> huuids = Q.New(HostVO.class).select(HostVO_.uuid)
                .in(HostVO_.clusterUuid, inv.getAttachedClusterUuids())
                .eq(HostVO_.status, HostStatus.Connected)
                .eq(HostVO_.state, HostState.Enabled)
                .listValues();
  if(huuids.size() == 0){
    completion.fail(operr("no host in is Connected or primary storage[uuid:%s] attach no cluster", inv.getUuid()));
    return;
  }
  Collections.shuffle(huuids);
  doPing(huuids.subList(0, min(limit,huuids.size())), inv, new Completion(completion) {
    @Override
    public void success() {
      completion.success();
    }
    @Override
    public void fail(ErrorCode errorCode) {
      completion.fail(errorCode);
    }
  });
}

代码示例来源:origin: zstackio/zstack

@Transactional(readOnly = true)
private boolean noStorageAccessible(){
  // detach ps will delete PrimaryStorageClusterRefVO first.
  List<String> attachedPsUuids = Q.New(PrimaryStorageClusterRefVO.class)
      .select(PrimaryStorageClusterRefVO_.primaryStorageUuid)
      .eq(PrimaryStorageClusterRefVO_.clusterUuid, self.getClusterUuid())
      .listValues();
  long attachedPsCount = attachedPsUuids.size();
  long inaccessiblePsCount = attachedPsCount == 0 ? 0 : Q.New(PrimaryStorageHostRefVO.class)
      .eq(PrimaryStorageHostRefVO_.hostUuid, self.getUuid())
      .eq(PrimaryStorageHostRefVO_.status, PrimaryStorageHostStatus.Disconnected)
      .in(PrimaryStorageHostRefVO_.primaryStorageUuid, attachedPsUuids)
      .count();
  return inaccessiblePsCount == attachedPsCount && attachedPsCount > 0;
}

代码示例来源:origin: zstackio/zstack

private void addCdRomToHistoricalVm() {
  if (!VmCdRomGlobalProperty.addCdRomToHistoricalVm) {
    return;
  }
  List<String> vmUuids = getTargetVmUuids();
  if (vmUuids.isEmpty()){
    return;
  }
  List<Tuple> vmUuidPlatforms = Q.New(VmInstanceVO.class)
      .select(VmInstanceVO_.uuid, VmInstanceVO_.platform)
      .in(VmInstanceVO_.uuid, vmUuids)
      .listTuple();
  for (Tuple vmTuple : vmUuidPlatforms) {
    String vmUuid = vmTuple.get(0, String.class);
    String vmPlatform = vmTuple.get(1, String.class);
    if (vmPlatform != null && ImagePlatform.Windows.toString().equalsIgnoreCase(vmPlatform)) {
      addCdRomForWindowsVm(vmUuid);
      continue;
    }
    addCdRomForLinuxAndOthersVm(vmUuid);
  }
}

代码示例来源:origin: zstackio/zstack

@Override
public void releaseResourceOnDetachingNic(VmInstanceSpec spec, VmNicInventory nic, NoErrorCompletion completion) {
  // Todo(WeiW): Need to check router rather than not only user vm
  if (spec.getVmInventory().getType().equals(VmInstanceConstant.USER_VM_TYPE)) {
    completion.done();
    return;
  }
  /* FIXME shixin: nic.getL3NetworkUuid() should be change to nic.getUesedIp for appliancevm */
  logger.debug(String.format("check detaching nic[uuid:%s] in peer l3 of vip", nic.getUuid()));
  List<VipPeerL3NetworkRefVO> refVOS = Q.New(VipPeerL3NetworkRefVO.class).eq(VipPeerL3NetworkRefVO_.l3NetworkUuid,
      nic.getL3NetworkUuid()).list();
  if (refVOS == null || refVOS.isEmpty()) {
    completion.done();
    return;
  }
  Set<String> refUuids = refVOS.stream().map(r -> r.getVipUuid()).collect(Collectors.toSet());
  logger.debug(String.format("release peer l3[uuid:%s] from vips[uuid:%s] for detaching nic[uuid:%s]",
      nic.getL3NetworkUuid(), refUuids, nic.getUuid()));
  List<VipVO> vipVOS = Q.New(VipVO.class).in(VipVO_.uuid, refUuids).list();
  for (VipVO vipVO : vipVOS) {
    VipBase v = new VipBase(vipVO);
    v.deletePeerL3NetworkUuid(nic.getL3NetworkUuid());
  }
  completion.done();
}

代码示例来源:origin: zstackio/zstack

private void validate(APIUpdateRoleMsg msg) {
  if (Q.New(RoleVO.class).in(RoleVO_.type, list(RoleType.Predefined, RoleType.System)).eq(RoleVO_.uuid, msg.getUuid()).isExists()) {
    throw new ApiMessageInterceptionException(argerr("cannot update a system or predefined role"));
  }
}

代码示例来源:origin: zstackio/zstack

private void validate(APIDeleteRoleMsg msg) {
    if (Q.New(RoleVO.class).in(RoleVO_.type, list(RoleType.Predefined, RoleType.System)).eq(RoleVO_.uuid, msg.getUuid()).isExists()) {
      throw new ApiMessageInterceptionException(argerr("cannot delete a system or predefined role"));
    }
  }
}

代码示例来源:origin: zstackio/zstack

private void validate(AddVmNicToSecurityGroupMsg msg) {
  String securityGroupUuid = msg.getSecurityGroupUuid();
  List<String> uuids = Q.New(VmNicVO.class)
      .select(VmNicVO_.uuid)
      .in(VmNicVO_.uuid, msg.getVmNicUuids())
      .listValues();
  if (!uuids.containsAll(msg.getVmNicUuids())) {
    msg.getVmNicUuids().removeAll(uuids);
    throw new OperationFailureException(err(SysErrors.RESOURCE_NOT_FOUND,
        "cannot find vm nics[uuids:%s]", msg.getVmNicUuids()
    ));
  }
  List<String> nicUuids = SQL.New("select nic.uuid from SecurityGroupL3NetworkRefVO ref, VmNicVO nic, UsedIpVO ip" +
      " where ref.l3NetworkUuid = ip.l3NetworkUuid and ip.vmNicUuid = nic.uuid" +
      " and ref.securityGroupUuid = :sgUuid and nic.uuid in (:nicUuids)")
      .param("nicUuids", uuids)
      .param("sgUuid", securityGroupUuid)
      .list();
  List<String> wrongUuids = new ArrayList<>();
  for (String uuid : uuids) {
    if (!nicUuids.contains(uuid)) {
      wrongUuids.add(uuid);
    }
  }
  if (!wrongUuids.isEmpty()) {
    throw new OperationFailureException(argerr("VM nics[uuids:%s] are not on L3 networks that have been attached to the security group[uuid:%s]",
        wrongUuids, securityGroupUuid));
  }
  msg.setVmNicUuids(uuids);
}

相关文章