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

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

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

Q.list介绍

暂无

代码示例

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

private void deleteListenersForLoadBalancer(String lbUuid) {
  List<LoadBalancerListenerVO> listenerVOS = Q.New(LoadBalancerListenerVO.class)
      .eq(LoadBalancerListenerVO_.loadBalancerUuid, lbUuid)
      .list();
  if (listenerVOS != null && !listenerVOS.isEmpty()) {
    logger.debug(String.format("delete loadBalancerListeners[%s] for loadBalancer[uuid:%s]",
        listenerVOS.stream().map(vo -> vo.getUuid()).collect(Collectors.toList()), lbUuid));
    listenerVOS.forEach(vo -> dbf.remove(vo));
  }
}

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

private String getOverlapVniRangePool(String l2NetworkUuid, String clusterUuid) {
  List<VniRangeVO> checkRanges = Q.New(VniRangeVO.class).eq(VniRangeVO_.l2NetworkUuid, l2NetworkUuid).list();
  List<String> l2Uuids = Q.New(L2NetworkClusterRefVO.class).select(L2NetworkClusterRefVO_.l2NetworkUuid).eq(L2NetworkClusterRefVO_.clusterUuid, clusterUuid).listValues();
  for (String l2Uuid : l2Uuids) {
    List<VniRangeVO> ranges = Q.New(VniRangeVO.class).eq(VniRangeVO_.l2NetworkUuid, l2Uuid).list();
    for (VniRangeVO range : ranges) {
      Boolean result = checkRanges.stream()
          .map(r -> isVniRangeOverlap(r.getStartVni(), r.getEndVni(), range.getStartVni(), range.getEndVni()))
          .reduce(true, (l, r) -> l && r);
      if (result.equals(true)) {
        return l2Uuid;
      }
    }
  }
  return null;
}

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

@Override
  public void call() {
    List<WebhookVO> vos = Q.New(WebhookVO.class).eq(WebhookVO_.type, EventFacade.WEBHOOK_TYPE).list();
    vos = vos.stream().filter(
        vo -> event.getPath().matches(
            createRegexFromGlob(vo.getOpaque().replaceAll("\\{.*\\}", ".*"))
        )).collect(Collectors.toList());
    if (!vos.isEmpty()) {
      postToWebhooks(WebhookInventory.valueOf(vos), JSONObjectUtil.toJsonString(event));
    }
  }
}.call();

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

private List<HostRouteInfo> getL3NetworkHostRoute(String l3NetworkUuid){
  List<L3NetworkHostRouteVO> vos = Q.New(L3NetworkHostRouteVO.class).eq(L3NetworkHostRouteVO_.l3NetworkUuid, l3NetworkUuid).list();
  if (vos == null || vos.isEmpty()) {
    return new ArrayList<>();
  }
  List<HostRouteInfo> res = new ArrayList<>();
  for (L3NetworkHostRouteVO vo : vos) {
    HostRouteInfo info = new HostRouteInfo();
    info.prefix = vo.getPrefix();
    info.nexthop = vo.getNexthop();
    res.add(info);
  }
  return res;
}

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

@Override
public void iJoin(ManagementNodeInventory inv) {
  List<ManagementNodeVO> lst = Q.New(ManagementNodeVO.class).list();
  lst.forEach((ManagementNodeVO node) -> {
    nodeHash.add(node.getUuid());
    nodes.put(node.getUuid(), new NodeInfo(node));
  });
}

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

@Override
  public void run(FlowTrigger trigger, Map data) {
    final String vrUuid = (String) data.get(Param.VR_UUID.toString());
    List<VirtualRouterLoadBalancerRefVO> refs = Q.New(VirtualRouterLoadBalancerRefVO.class).eq(VirtualRouterLoadBalancerRefVO_.virtualRouterVmUuid, vrUuid).list();
    if (!refs.isEmpty()){
      dbf.removeCollection(refs, VirtualRouterLoadBalancerRefVO.class);
    }
    trigger.next();
  }
}

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

@Override
public void updateIpAllocationMsg(AllocateIpMsg msg, String mac) {
  if (msg.getRequiredIp() != null) {
    return;
  }
  List<IpRangeVO> iprs = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, msg.getL3NetworkUuid()).list();
  if (iprs.get(0).getIpVersion() == IPv6Constants.IPv4) {
    return;
  }
  if (!iprs.get(0).getAddressMode().equals(IPv6Constants.Stateful_DHCP)) {
    msg.setRequiredIp(IPv6NetworkUtils.getIPv6AddresFromMac(iprs.get(0).getNetworkCidr(), mac));
  }
}

代码示例来源: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

private void validateIpRangeOverlapWithVm(String l3NetworkUuid, String vmInstanceUuid) {
  List<VmNicVO> vmNicVOS = Q.New(VmNicVO.class).eq(VmNicVO_.vmInstanceUuid, vmInstanceUuid).list();
  List<IpRangeVO> newIpRangeVOS = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, l3NetworkUuid).list();
  if (newIpRangeVOS == null || newIpRangeVOS.isEmpty()) {
    throw new ApiMessageInterceptionException(operr("no ip ranges attached with l3 network[uuid:%s]", l3NetworkUuid));
  }
  for (VmNicVO vmNicVO: vmNicVOS) {
    List<IpRangeVO> ipRangeVOS = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, vmNicVO.getL3NetworkUuid()).limit(1).list();
    if (ipRangeVOS != null && !ipRangeVOS.isEmpty()) {
      if (NetworkUtils.isCidrOverlap(ipRangeVOS.get(0).getNetworkCidr(), newIpRangeVOS.get(0).getNetworkCidr())) {
        throw new ApiMessageInterceptionException(operr("unable to attach a L3 network. The cidr of l3[%s] to attach overlapped with l3[%s] already attached to vm", l3NetworkUuid, vmNicVO.getL3NetworkUuid()));
      }
    }
  }
}

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

@Override
  public void prepareDbInitialValue() {
    List<VipVO> vipVOS = Q.New(VipVO.class).isNull(VipVO_.prefixLen).list();
    for (VipVO vip : vipVOS) {
      vip.setPrefixLen(NetworkUtils.getPrefixLengthFromNetwork(vip.getNetmask()));
    }
    if (!vipVOS.isEmpty()) {
      dbf.updateCollection(vipVOS);
    }
  }
}

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

public void clearPeerL3Network() {
    List<VipPeerL3NetworkRefVO> vos = Q.New(VipPeerL3NetworkRefVO.class)
        .eq(VipPeerL3NetworkRefVO_.vipUuid, self.getUuid())
        .list();
    if (vos != null && !vos.isEmpty()) {
      dbf.removeCollection(vos, VipPeerL3NetworkRefVO.class);
    }
    self.setPeerL3NetworkRefs(null);
    refresh();
  }
}

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

@Override
  public void run(FlowTrigger trigger, Map data) {
    StringSimilarity.refreshErrorTemplates();
    eliminateErrors();
    List<ElaborationVO> vos = Q.New(ElaborationVO.class).gte(ElaborationVO_.repeats, 1).eq(ElaborationVO_.matched, false).orderBy(ElaborationVO_.lastOpDate, SimpleQuery.Od.DESC).list();
    if (!vos.isEmpty()) {
      List<String> messages = StringSimilarity.getElaborations().stream().map(ErrorCodeElaboration::getMessage_cn).collect(Collectors.toList());
      for (ElaborationVO vo: vos) {
        if (messages.contains(vo.getErrorInfo())) {
          vo.setMatched(true);
          dbf.updateAndRefresh(vo);
        }
      }
    }
    StringSimilarity.resetCachedErrors();
    trigger.next();
  }
}).done(new FlowDoneHandler(completion) {

代码示例来源: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

public List<SystemTagInventory> getTagInventories(String resourceUuid) {
  return SystemTagInventory.valueOf(Q.New(SystemTagVO.class).eq(SystemTagVO_.resourceType, getResourceClass().getSimpleName()).
      eq(SystemTagVO_.resourceUuid, resourceUuid).like(SystemTagVO_.tag, useTagFormat()).list());
}

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

private void loadOrphanJobs() {
  List<GarbageCollectorVO> vos = Q.New(GarbageCollectorVO.class)
      .eq(GarbageCollectorVO_.status, GCStatus.Idle)
      .isNull(GarbageCollectorVO_.managementNodeUuid)
      .list();
  int count = 0;
  for (GarbageCollectorVO vo : vos) {
    if (!destinationMaker.isManagedByUs(vo.getUuid())) {
      continue;
    }
    loadGCJob(vo);
    count ++;
  }
  logger.debug(String.format("[GC] loaded %s orphan jobs", count));
}

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

@Override
public Map<String, StorageTrashSpec> getTrashList(String storageUuid, List<TrashType> types) {
  Map<String, StorageTrashSpec> specs = new HashMap<>();
  for (TrashType type: types) {
    List<JsonLabelVO> labels = Q.New(JsonLabelVO.class).eq(JsonLabelVO_.resourceUuid, storageUuid).like(JsonLabelVO_.labelKey, type.toString() + "-%").list();
    labels.forEach(l -> {
      StorageTrashSpec spec = JSONObjectUtil.toObject(l.getLabelValue(), StorageTrashSpec.class);
      spec.setTrashId(l.getId());
      spec.setCreateDate(l.getCreateDate());
      if (spec.getTrashType() == null) {
        spec.setTrashType(type.toString());
      }
      specs.put(l.getLabelKey(), spec);
    });
  }
  return specs;
}

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

private void updateLdapUidToLdapDn() {
  if(!isLdapServerExist()){
    return;
  }
  if(!isBindingExist()){
    return;
  }
  try {
    LdapTemplateContextSource ldapTemplateContextSource = readLdapServerConfiguration();
    LdapTemplate ldapTemplate = ldapTemplateContextSource.getLdapTemplate();
    List<LdapAccountRefVO> refs = Q.New(LdapAccountRefVO.class).list();
    for(LdapAccountRefVO ref : refs){
      update(ldapTemplate, ref);
    }
  }catch (Throwable t){
    logger.error("update ldapUid to ldapDn An error occurred", t);
  }
}

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

@MessageSafe
private void dealMessage(FlatDhcpAcquireDhcpServerIpMsg msg) {
  FlatDhcpAcquireDhcpServerIpReply reply = new FlatDhcpAcquireDhcpServerIpReply();
  String ip = allocateDhcpIp(msg.getL3NetworkUuid());
  if (ip != null) {
    List<IpRangeVO> iprs = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, msg.getL3NetworkUuid()).list();
    if (iprs == null || iprs.isEmpty()) {
      reply.setError(operr("L3 network[uuid:%s] does not have any iprange", msg.getL3NetworkUuid()));
      bus.reply(msg, reply);
      return;
    }
    reply.setIp(ip);
    reply.setNetmask(iprs.get(0).getNetmask());
    reply.setIpr(IpRangeInventory.valueOf(iprs.get(0)));
  }
  bus.reply(msg, reply);
}

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

private void handle(final APIGetL3NetworkRouterInterfaceIpMsg msg) {
  APIGetL3NetworkRouterInterfaceIpReply reply = new APIGetL3NetworkRouterInterfaceIpReply();
  if (L3NetworkSystemTags.ROUTER_INTERFACE_IP.hasTag(msg.getL3NetworkUuid())) {
    reply.setRouterInterfaceIp(L3NetworkSystemTags.ROUTER_INTERFACE_IP.getTokenByResourceUuid(msg.getL3NetworkUuid(), L3NetworkSystemTags.ROUTER_INTERFACE_IP_TOKEN));
    bus.reply(msg, reply);
    return;
  }
  List<IpRangeVO> ipRangeVOS = Q.New(IpRangeVO.class).eq(IpRangeVO_.l3NetworkUuid, msg.getL3NetworkUuid()).list();
  if (ipRangeVOS == null || ipRangeVOS.isEmpty()) {
    reply.setRouterInterfaceIp(null);
    bus.reply(msg, reply);
  } else {
    reply.setRouterInterfaceIp(ipRangeVOS.get(0).getGateway());
    bus.reply(msg, reply);
  }
}

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

private void validate(APICreateVniRangeMsg msg) {
  if (msg.getStartVni() > msg.getEndVni()) {
    throw new ApiMessageInterceptionException(Platform.err(SysErrors.INVALID_ARGUMENT_ERROR,
        String.format("start number [%s] of vni range is bigger than end number [%s]",
            msg.getStartVni(), msg.getStartVni())
    ));
  }
  List<VniRangeVO> exists = Q.New(VniRangeVO.class).eq(VniRangeVO_.l2NetworkUuid, msg.getL2NetworkUuid()).list();
  for (VniRangeVO e : exists) {
    if (checkOverlap(msg.getStartVni(), msg.getEndVni(), e.getStartVni(), e.getEndVni()) == true) {
      throw new ApiMessageInterceptionException(Platform.err(SysErrors.INVALID_ARGUMENT_ERROR,
          String.format("this vni range[start:%s, end:%s] has overlapped with vni range [%s], which start vni is [%s], end vni is [%s]",
              msg.getStartVni(), msg.getEndVni(), e.getUuid(), e.getStartVni(), e.getEndVni())
      ));
    }
  }
}

相关文章