コード例 #1
0
 @Override
 public Long getMaxGuestsLimit(HypervisorType hypervisorType, String hypervisorVersion) {
   Long defaultLimit = new Long(50);
   Long result = null;
   boolean useDefault = false;
   if (hypervisorVersion != null) {
     SearchCriteria<Long> sc = MaxGuestLimitByHypervisorSearch.create();
     sc.setParameters("hypervisorType", hypervisorType);
     sc.setParameters("hypervisorVersion", hypervisorVersion);
     List<Long> limitList = customSearch(sc, null);
     if (!limitList.isEmpty()) {
       result = limitList.get(0);
     } else {
       useDefault = true;
     }
   } else {
     useDefault = true;
   }
   if (useDefault) {
     SearchCriteria<Long> sc = MaxGuestLimitByHypervisorSearch.create();
     sc.setParameters("hypervisorType", hypervisorType);
     sc.setParameters("hypervisorVersion", DEFAULT_VERSION);
     List<Long> limitList = customSearch(sc, null);
     if (!limitList.isEmpty()) {
       result = limitList.get(0);
     }
   }
   if (result == null) {
     return defaultLimit;
   }
   return result;
 }
コード例 #2
0
  @Override
  public int countIPs(long dcId, long vlanId, boolean onlyCountAllocated) {
    SearchCriteria<Integer> sc =
        onlyCountAllocated ? AllocatedIpCount.create() : AllIpCount.create();
    sc.setParameters("dc", dcId);
    sc.setParameters("vlan", vlanId);

    return customSearch(sc, null).get(0);
  }
コード例 #3
0
  protected StoragePoolDaoImpl() {
    AllFieldSearch = createSearchBuilder();
    AllFieldSearch.and("name", AllFieldSearch.entity().getName(), SearchCriteria.Op.EQ);
    AllFieldSearch.and("uuid", AllFieldSearch.entity().getUuid(), SearchCriteria.Op.EQ);
    AllFieldSearch.and(
        "datacenterId", AllFieldSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    AllFieldSearch.and(
        "hostAddress", AllFieldSearch.entity().getHostAddress(), SearchCriteria.Op.EQ);
    AllFieldSearch.and("status", AllFieldSearch.entity().getStatus(), SearchCriteria.Op.EQ);
    AllFieldSearch.and("path", AllFieldSearch.entity().getPath(), SearchCriteria.Op.EQ);
    AllFieldSearch.and("podId", AllFieldSearch.entity().getPodId(), Op.EQ);
    AllFieldSearch.done();

    DcPodSearch = createSearchBuilder();
    DcPodSearch.and("datacenterId", DcPodSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    DcPodSearch.and().op("nullpod", DcPodSearch.entity().getPodId(), SearchCriteria.Op.NULL);
    DcPodSearch.or("podId", DcPodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
    DcPodSearch.cp();
    DcPodSearch.and()
        .op("nullcluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.NULL);
    DcPodSearch.or("cluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
    DcPodSearch.cp();
    DcPodSearch.done();

    DcPodAnyClusterSearch = createSearchBuilder();
    DcPodAnyClusterSearch.and(
        "datacenterId", DcPodAnyClusterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    DcPodAnyClusterSearch.and()
        .op("nullpod", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.NULL);
    DcPodAnyClusterSearch.or(
        "podId", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.EQ);
    DcPodAnyClusterSearch.cp();
    DcPodAnyClusterSearch.done();

    DeleteLvmSearch = createSearchBuilder();
    DeleteLvmSearch.and("ids", DeleteLvmSearch.entity().getId(), SearchCriteria.Op.IN);
    DeleteLvmSearch.and().op("LVM", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ);
    DeleteLvmSearch.or("Filesystem", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ);
    DeleteLvmSearch.cp();
    DeleteLvmSearch.done();

    StatusCountSearch = createSearchBuilder(Long.class);
    StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN);
    StatusCountSearch.select(null, Func.COUNT, null);
    StatusCountSearch.done();

    _detailsDao = ComponentLocator.inject(StoragePoolDetailsDaoImpl.class);
  }
コード例 #4
0
 @Override
 public long countFreeIPsInNetwork(long networkId) {
   SearchCriteria<Long> sc = CountFreePublicIps.create();
   sc.setParameters("state", State.Free);
   sc.setParameters("networkId", networkId);
   return customSearch(sc, null).get(0);
 }
コード例 #5
0
 @Override
 public long countFreePublicIPs() {
   SearchCriteria<Long> sc = CountFreePublicIps.create();
   sc.setParameters("state", State.Free);
   sc.setJoinParameters("vlans", "vlanType", VlanType.VirtualNetwork);
   return customSearch(sc, null).get(0);
 }
コード例 #6
0
 @Override
 public Long getNetworkCountByOfferingId(long offeringId) {
   SearchCriteria<Long> sc = CountByOfferingId.create();
   sc.setParameters("offeringId", offeringId);
   List<Long> results = customSearch(sc, null);
   return results.get(0);
 }
コード例 #7
0
 @Override
 public int getNetworkCountByVpcId(long vpcId) {
   SearchCriteria<Integer> sc = CountBy.create();
   sc.setParameters("vpcId", vpcId);
   List<Integer> results = customSearch(sc, null);
   return results.get(0);
 }
コード例 #8
0
 @Override
 public List<Long> listAdministratedProjectIds(long adminAccountId) {
   SearchCriteria<Long> sc = AdminSearch.create();
   sc.setParameters("role", ProjectAccount.Role.Admin);
   sc.setParameters("accountId", adminAccountId);
   return customSearch(sc, null);
 }
コード例 #9
0
 @Override
 public Long countByAccountIdAndRole(long accountId, ProjectAccount.Role role) {
   SearchCriteria<Long> sc = CountByRoleSearch.create();
   sc.setParameters("accountId", accountId);
   sc.setParameters("role", role);
   return customSearch(sc, null).get(0);
 }
コード例 #10
0
 @Override
 public int getNetworkCountByNetworkOffId(long networkOfferingId) {
   SearchCriteria<Integer> sc = NetworksCount.create();
   sc.setParameters("networkOfferingId", networkOfferingId);
   List<Integer> count = customSearch(sc, null);
   return count.get(0);
 }
コード例 #11
0
 @Override
 public Long countSnapshotsForAccount(long accountId) {
   SearchCriteria<Long> sc = CountSnapshotsByAccount.create();
   sc.setParameters("account", accountId);
   sc.setParameters("status", State.Error, State.Destroyed);
   return customSearch(sc, null).get(0);
 }
コード例 #12
0
 @Override
 public List<String> getDistinctProviders(long vpcId) {
   SearchCriteria<String> sc = DistinctProvidersSearch.create();
   sc.setParameters("vpcId", vpcId);
   List<String> results = customSearch(sc, null);
   return results;
 }
コード例 #13
0
 @Override
 public long countNetworksUserCanCreate(long ownerId) {
   SearchCriteria<Long> sc = NetworksRegularUserCanCreateSearch.create();
   sc.setParameters("aclType", ACLType.Account);
   sc.setJoinParameters("accounts", "account", ownerId);
   sc.setJoinParameters("ntwkOff", "specifyVlan", false);
   return customSearch(sc, null).get(0);
 }
コード例 #14
0
 @Override
 public long countByZoneUriAndGuestType(long zoneId, String broadcastUri, GuestType guestType) {
   SearchCriteria<Long> sc = CountByZoneAndURI.create();
   sc.setParameters("dataCenterId", zoneId);
   sc.setParameters("broadcastUri", broadcastUri);
   sc.setParameters("guestType", guestType);
   return customSearch(sc, null).get(0);
 }
コード例 #15
0
 @Override
 public Long countAllocatedVMsForAccount(long accountId) {
   SearchCriteria<Long> sc = CountByAccount.create();
   sc.setParameters("account", accountId);
   sc.setParameters("type", VirtualMachine.Type.User);
   sc.setParameters("state", new Object[] {State.Destroyed, State.Error, State.Expunging});
   return customSearch(sc, null).get(0);
 }
コード例 #16
0
 @Override
 public long countVpcNetworks(long vpcId) {
   SearchCriteria<Long> sc = VpcNetworksCount.create();
   sc.setParameters("vpcId", vpcId);
   // offering shouldn't be system (the one used by the private gateway)
   sc.setJoinParameters("offerings", "isSystem", false);
   return customSearch(sc, null).get(0);
 }
コード例 #17
0
 @Override
 public int getNonSystemNetworkCountByVpcId(long vpcId) {
   SearchCriteria<Integer> sc = CountBy.create();
   sc.setParameters("vpcId", vpcId);
   sc.setJoinParameters("offerings", "isSystem", false);
   List<Integer> results = customSearch(sc, null);
   return results.get(0);
 }
コード例 #18
0
  protected VpcServiceMapDaoImpl() {
    super();
    AllFieldsSearch = createSearchBuilder();
    AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
    AllFieldsSearch.and("service", AllFieldsSearch.entity().getService(), SearchCriteria.Op.EQ);
    AllFieldsSearch.and("provider", AllFieldsSearch.entity().getProvider(), SearchCriteria.Op.EQ);
    AllFieldsSearch.done();

    MultipleServicesSearch = createSearchBuilder();
    MultipleServicesSearch.and(
        "vpcId", MultipleServicesSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
    MultipleServicesSearch.and(
        "service", MultipleServicesSearch.entity().getService(), SearchCriteria.Op.IN);
    MultipleServicesSearch.and(
        "provider", MultipleServicesSearch.entity().getProvider(), SearchCriteria.Op.EQ);
    MultipleServicesSearch.done();

    DistinctProvidersSearch = createSearchBuilder(String.class);
    DistinctProvidersSearch.and(
        "vpcId", DistinctProvidersSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
    DistinctProvidersSearch.and(
        "provider", DistinctProvidersSearch.entity().getProvider(), SearchCriteria.Op.EQ);
    DistinctProvidersSearch.selectFields(DistinctProvidersSearch.entity().getProvider());
    DistinctProvidersSearch.done();
  }
コード例 #19
0
  protected HypervisorCapabilitiesDaoImpl() {
    HypervisorTypeSearch = createSearchBuilder();
    HypervisorTypeSearch.and(
        "hypervisorType", HypervisorTypeSearch.entity().getHypervisorType(), SearchCriteria.Op.EQ);
    HypervisorTypeSearch.done();

    HypervisorTypeAndVersionSearch = createSearchBuilder();
    HypervisorTypeAndVersionSearch.and(
        "hypervisorType",
        HypervisorTypeAndVersionSearch.entity().getHypervisorType(),
        SearchCriteria.Op.EQ);
    HypervisorTypeAndVersionSearch.and(
        "hypervisorVersion",
        HypervisorTypeAndVersionSearch.entity().getHypervisorVersion(),
        SearchCriteria.Op.EQ);
    HypervisorTypeAndVersionSearch.done();

    MaxGuestLimitByHypervisorSearch = createSearchBuilder(Long.class);
    MaxGuestLimitByHypervisorSearch.selectField(
        MaxGuestLimitByHypervisorSearch.entity().getMaxGuestsLimit());
    MaxGuestLimitByHypervisorSearch.and(
        "hypervisorType",
        MaxGuestLimitByHypervisorSearch.entity().getHypervisorType(),
        SearchCriteria.Op.EQ);
    MaxGuestLimitByHypervisorSearch.and(
        "hypervisorVersion",
        MaxGuestLimitByHypervisorSearch.entity().getHypervisorVersion(),
        SearchCriteria.Op.EQ);
    MaxGuestLimitByHypervisorSearch.done();
  }
コード例 #20
0
  @Override
  public String getNetworkTag(
      long physicalNetworkId, TrafficType trafficType, HypervisorType hType) {
    SearchCriteria<String> sc = null;
    if (hType == HypervisorType.XenServer) {
      sc = xenAllFieldsSearch.create();
    } else if (hType == HypervisorType.KVM) {
      sc = kvmAllFieldsSearch.create();
    } else if (hType == HypervisorType.VMware) {
      sc = vmWareAllFieldsSearch.create();
    } else if (hType == HypervisorType.Simulator) {
      sc = simulatorAllFieldsSearch.create();
    } else if (hType == HypervisorType.Ovm) {
      sc = ovmAllFieldsSearch.create();
    } else if (hType == HypervisorType.BareMetal) {
      return null;
    } else if (hType == HypervisorType.Hyperv) {
      sc = hypervAllFieldsSearch.create();
    } else if (hType == HypervisorType.Ovm3) {
      sc = ovm3AllFieldsSearch.create();
    } else {
      assert (false) : "We don't handle this hypervisor type";
      return null;
    }

    sc.setParameters("physicalNetworkId", physicalNetworkId);
    sc.setParameters("trafficType", trafficType);
    List<String> tag = customSearch(sc, null);

    return tag.size() == 0 ? null : tag.get(0);
  }
コード例 #21
0
  protected SecurityGroupVMMapDaoImpl() {
    ListByIpAndVmId = createSearchBuilder();
    ListByIpAndVmId.and(
        "ipAddress", ListByIpAndVmId.entity().getGuestIpAddress(), SearchCriteria.Op.EQ);
    ListByIpAndVmId.and(
        "instanceId", ListByIpAndVmId.entity().getInstanceId(), SearchCriteria.Op.EQ);
    ListByIpAndVmId.done();

    ListVmIdBySecurityGroup = createSearchBuilder(Long.class);
    ListVmIdBySecurityGroup.and(
        "securityGroupId",
        ListVmIdBySecurityGroup.entity().getSecurityGroupId(),
        SearchCriteria.Op.EQ);
    ListVmIdBySecurityGroup.selectFields(ListVmIdBySecurityGroup.entity().getInstanceId());
    ListVmIdBySecurityGroup.done();

    ListBySecurityGroup = createSearchBuilder();
    ListBySecurityGroup.and(
        "securityGroupId", ListBySecurityGroup.entity().getSecurityGroupId(), SearchCriteria.Op.EQ);
    ListBySecurityGroup.done();

    ListByIp = createSearchBuilder();
    ListByIp.and("ipAddress", ListByIp.entity().getGuestIpAddress(), SearchCriteria.Op.EQ);
    ListByIp.done();

    ListByVmId = createSearchBuilder();
    ListByVmId.and("instanceId", ListByVmId.entity().getInstanceId(), SearchCriteria.Op.EQ);
    ListByVmId.done();

    ListBySecurityGroupAndStates = createSearchBuilder();
    ListBySecurityGroupAndStates.and(
        "securityGroupId",
        ListBySecurityGroupAndStates.entity().getSecurityGroupId(),
        SearchCriteria.Op.EQ);
    ListBySecurityGroupAndStates.and(
        "states", ListBySecurityGroupAndStates.entity().getVmState(), SearchCriteria.Op.IN);
    ListBySecurityGroupAndStates.done();

    ListByVmIdGroupId = createSearchBuilder();
    ListByVmIdGroupId.and(
        "instanceId", ListByVmIdGroupId.entity().getInstanceId(), SearchCriteria.Op.EQ);
    ListByVmIdGroupId.and(
        "securityGroupId", ListByVmIdGroupId.entity().getSecurityGroupId(), SearchCriteria.Op.EQ);
    ListByVmIdGroupId.done();

    CountSGForVm = createSearchBuilder(Long.class);
    CountSGForVm.select(null, Func.COUNT, null);
    CountSGForVm.and("vmId", CountSGForVm.entity().getInstanceId(), SearchCriteria.Op.EQ);
    CountSGForVm.done();
  }
コード例 #22
0
 @Override
 public List<Long> findNetworksToGarbageCollect() {
   SearchCriteria<Long> sc = GarbageCollectedSearch.create();
   sc.setJoinParameters("ntwkOffGC", "isPersistent", false);
   sc.setJoinParameters("ntwkOpGC", "activenics", 0);
   sc.setJoinParameters("ntwkOpGC", "gc", true);
   sc.setJoinParameters("ntwkOpGC", "check", true);
   return customSearch(sc, null);
 }
コード例 #23
0
 @Override
 public int countIPsForNetwork(long dcId, boolean onlyCountAllocated, VlanType vlanType) {
   SearchCriteria<Integer> sc = AllIpCountForDashboard.create();
   sc.setParameters("dc", dcId);
   if (onlyCountAllocated) {
     sc.setParameters("state", State.Free);
   }
   sc.setJoinParameters("vlan", "vlanType", vlanType.toString());
   return customSearch(sc, null).get(0);
 }
コード例 #24
0
  protected StaticRouteDaoImpl() {
    super();

    AllFieldsSearch = createSearchBuilder();
    AllFieldsSearch.and("gatewayId", AllFieldsSearch.entity().getVpcGatewayId(), Op.EQ);
    AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ);
    AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
    AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ);
    AllFieldsSearch.done();

    NotRevokedSearch = createSearchBuilder();
    NotRevokedSearch.and("gatewayId", NotRevokedSearch.entity().getVpcGatewayId(), Op.EQ);
    NotRevokedSearch.and("state", NotRevokedSearch.entity().getState(), Op.NEQ);
    NotRevokedSearch.done();

    RoutesByGatewayCount = createSearchBuilder(Long.class);
    RoutesByGatewayCount.select(null, Func.COUNT, RoutesByGatewayCount.entity().getId());
    RoutesByGatewayCount.and("gatewayId", RoutesByGatewayCount.entity().getVpcGatewayId(), Op.EQ);
    RoutesByGatewayCount.done();
  }
コード例 #25
0
  @Override
  public long countPoolsByStatus(StoragePoolStatus... statuses) {
    SearchCriteria<Long> sc = StatusCountSearch.create();

    sc.setParameters("status", (Object[]) statuses);

    List<Long> rs = customSearchIncludingRemoved(sc, null);
    if (rs.size() == 0) {
      return 0;
    }

    return rs.get(0);
  }
コード例 #26
0
  @Override
  public long countBy(long primaryStorageId, Status... statuses) {
    SearchCriteria<Long> sc = MaintenanceCountSearch.create();

    sc.setParameters("status", (Object[]) statuses);
    sc.setParameters("pool", primaryStorageId);

    List<Long> rs = customSearchIncludingRemoved(sc, null);
    if (rs.size() == 0) {
      return 0;
    }

    return rs.get(0);
  }
コード例 #27
0
  protected NicIpAliasDaoImpl() {
    super();
    AllFieldsSearch = createSearchBuilder();
    AllFieldsSearch.and("instanceId", AllFieldsSearch.entity().getVmId(), Op.EQ);
    AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
    AllFieldsSearch.and("address", AllFieldsSearch.entity().getIp4Address(), Op.EQ);
    AllFieldsSearch.and("nicId", AllFieldsSearch.entity().getNicId(), Op.EQ);
    AllFieldsSearch.and("gateway", AllFieldsSearch.entity().getGateway(), Op.EQ);
    AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ);
    AllFieldsSearch.done();

    IpSearch = createSearchBuilder(String.class);
    IpSearch.select(null, Func.DISTINCT, IpSearch.entity().getIp4Address());
    IpSearch.and("network", IpSearch.entity().getNetworkId(), Op.EQ);
    IpSearch.and("address", IpSearch.entity().getIp4Address(), Op.NNULL);
    IpSearch.done();
  }
コード例 #28
0
  @SuppressWarnings("unchecked")
  @Override
  public List<IAMPolicy> listIAMPolicies(long accountId) {

    // static policies of the account
    SearchBuilder<IAMGroupAccountMapVO> groupSB = _aclGroupAccountMapDao.createSearchBuilder();
    groupSB.and("account", groupSB.entity().getAccountId(), Op.EQ);

    GenericSearchBuilder<IAMGroupPolicyMapVO, Long> policySB =
        _aclGroupPolicyMapDao.createSearchBuilder(Long.class);
    policySB.selectFields(policySB.entity().getAclPolicyId());
    policySB.join(
        "accountgroupjoin",
        groupSB,
        groupSB.entity().getAclGroupId(),
        policySB.entity().getAclGroupId(),
        JoinType.INNER);
    policySB.done();
    SearchCriteria<Long> policySc = policySB.create();
    policySc.setJoinParameters("accountgroupjoin", "account", accountId);

    List<Long> policyIds = _aclGroupPolicyMapDao.customSearch(policySc, null);
    // add policies directly attached to the account
    List<IAMAccountPolicyMapVO> acctPolicies = _aclAccountPolicyMapDao.listByAccountId(accountId);
    for (IAMAccountPolicyMapVO p : acctPolicies) {
      policyIds.add(p.getIamPolicyId());
    }
    if (policyIds.size() == 0) {
      return new ArrayList<IAMPolicy>();
    }
    SearchBuilder<IAMPolicyVO> sb = _aclPolicyDao.createSearchBuilder();
    sb.and("ids", sb.entity().getId(), Op.IN);
    SearchCriteria<IAMPolicyVO> sc = sb.create();
    sc.setParameters("ids", policyIds.toArray(new Object[policyIds.size()]));
    @SuppressWarnings("rawtypes")
    List policies = _aclPolicyDao.customSearch(sc, null);

    return policies;
  }
コード例 #29
0
  @SuppressWarnings("unchecked")
  @Override
  public List<IAMGroup> listIAMGroups(long accountId) {

    GenericSearchBuilder<IAMGroupAccountMapVO, Long> groupSB =
        _aclGroupAccountMapDao.createSearchBuilder(Long.class);
    groupSB.selectFields(groupSB.entity().getAclGroupId());
    groupSB.and("account", groupSB.entity().getAccountId(), Op.EQ);
    SearchCriteria<Long> groupSc = groupSB.create();
    groupSc.setParameters("account", accountId);

    List<Long> groupIds = _aclGroupAccountMapDao.customSearch(groupSc, null);

    SearchBuilder<IAMGroupVO> sb = _aclGroupDao.createSearchBuilder();
    sb.and("ids", sb.entity().getId(), Op.IN);
    SearchCriteria<IAMGroupVO> sc = sb.create();
    sc.setParameters("ids", groupIds.toArray(new Object[groupIds.size()]));
    @SuppressWarnings("rawtypes")
    List groups = _aclGroupDao.search(sc, null);
    return groups;
  }
コード例 #30
0
 @Override
 public long countRoutesByGateway(long gatewayId) {
   SearchCriteria<Long> sc = RoutesByGatewayCount.create();
   sc.setParameters("gatewayId", gatewayId);
   return customSearch(sc, null).get(0);
 }