@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; }
@PostConstruct protected void init() { AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("trafficType", AllFieldsSearch.entity().getTrafficType(), Op.EQ); AllFieldsSearch.and("cidr", AllFieldsSearch.entity().getCidr(), Op.EQ); AllFieldsSearch.and("broadcastType", AllFieldsSearch.entity().getBroadcastDomainType(), Op.EQ); AllFieldsSearch.and("offering", AllFieldsSearch.entity().getNetworkOfferingId(), Op.EQ); AllFieldsSearch.and("datacenter", AllFieldsSearch.entity().getDataCenterId(), Op.EQ); AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), Op.EQ); AllFieldsSearch.and("related", AllFieldsSearch.entity().getRelated(), Op.EQ); AllFieldsSearch.and("guestType", AllFieldsSearch.entity().getGuestType(), Op.EQ); AllFieldsSearch.and("physicalNetwork", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ); AllFieldsSearch.and("broadcastUri", AllFieldsSearch.entity().getBroadcastUri(), Op.EQ); AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); AllFieldsSearch.and("aclId", AllFieldsSearch.entity().getNetworkACLId(), Op.EQ); SearchBuilder<NetworkOfferingVO> join1 = _ntwkOffDao.createSearchBuilder(); join1.and("isSystem", join1.entity().isSystemOnly(), Op.EQ); join1.and("isRedundant", join1.entity().getRedundantRouter(), Op.EQ); AllFieldsSearch.join( "offerings", join1, AllFieldsSearch.entity().getNetworkOfferingId(), join1.entity().getId(), JoinBuilder.JoinType.INNER); AllFieldsSearch.done(); AccountSearch = createSearchBuilder(); AccountSearch.and("offering", AccountSearch.entity().getNetworkOfferingId(), Op.EQ); SearchBuilder<NetworkAccountVO> join = _accountsDao.createSearchBuilder(); join.and("account", join.entity().getAccountId(), Op.EQ); AccountSearch.join( "accounts", join, AccountSearch.entity().getId(), join.entity().getNetworkId(), JoinBuilder.JoinType.INNER); AccountSearch.and("datacenter", AccountSearch.entity().getDataCenterId(), Op.EQ); AccountSearch.and("cidr", AccountSearch.entity().getCidr(), Op.EQ); AccountSearch.and("vpcId", AccountSearch.entity().getVpcId(), Op.EQ); AccountSearch.done(); RelatedConfigSearch = createSearchBuilder(); RelatedConfigSearch.and("offering", RelatedConfigSearch.entity().getNetworkOfferingId(), Op.EQ); RelatedConfigSearch.and("datacenter", RelatedConfigSearch.entity().getDataCenterId(), Op.EQ); SearchBuilder<NetworkAccountVO> join2 = _accountsDao.createSearchBuilder(); join2.and("account", join2.entity().getAccountId(), Op.EQ); RelatedConfigSearch.join( "account", join2, join2.entity().getNetworkId(), RelatedConfigSearch.entity().getId(), JoinType.INNER); RelatedConfigSearch.done(); AccountNetworkSearch = createSearchBuilder(); AccountNetworkSearch.and("networkId", AccountNetworkSearch.entity().getId(), Op.EQ); SearchBuilder<NetworkAccountVO> mapJoin = _accountsDao.createSearchBuilder(); mapJoin.and("accountId", mapJoin.entity().getAccountId(), Op.EQ); AccountNetworkSearch.join( "networkSearch", mapJoin, AccountNetworkSearch.entity().getId(), mapJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER); AccountNetworkSearch.done(); ZoneBroadcastUriSearch = createSearchBuilder(); ZoneBroadcastUriSearch.and( "dataCenterId", ZoneBroadcastUriSearch.entity().getDataCenterId(), Op.EQ); ZoneBroadcastUriSearch.and( "broadcastUri", ZoneBroadcastUriSearch.entity().getBroadcastUri(), Op.EQ); ZoneBroadcastUriSearch.and("guestType", ZoneBroadcastUriSearch.entity().getGuestType(), Op.EQ); ZoneBroadcastUriSearch.done(); CountByZoneAndURI = createSearchBuilder(Long.class); CountByZoneAndURI.select(null, Func.COUNT, null); CountByZoneAndURI.and("dataCenterId", CountByZoneAndURI.entity().getDataCenterId(), Op.EQ); CountByZoneAndURI.and("broadcastUri", CountByZoneAndURI.entity().getBroadcastUri(), Op.EQ); CountByZoneAndURI.and("guestType", CountByZoneAndURI.entity().getGuestType(), Op.EQ); CountByZoneAndURI.done(); ZoneSecurityGroupSearch = createSearchBuilder(); ZoneSecurityGroupSearch.and( "dataCenterId", ZoneSecurityGroupSearch.entity().getDataCenterId(), Op.EQ); SearchBuilder<NetworkServiceMapVO> offJoin = _ntwkSvcMap.createSearchBuilder(); offJoin.and("service", offJoin.entity().getService(), Op.EQ); ZoneSecurityGroupSearch.join( "services", offJoin, ZoneSecurityGroupSearch.entity().getId(), offJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER); ZoneSecurityGroupSearch.done(); CountBy = createSearchBuilder(Integer.class); CountBy.select(null, Func.COUNT, CountBy.entity().getId()); CountBy.and("offeringId", CountBy.entity().getNetworkOfferingId(), Op.EQ); CountBy.and("vpcId", CountBy.entity().getVpcId(), Op.EQ); CountBy.and("removed", CountBy.entity().getRemoved(), Op.NULL); SearchBuilder<NetworkOfferingVO> ntwkOffJoin = _ntwkOffDao.createSearchBuilder(); ntwkOffJoin.and("isSystem", ntwkOffJoin.entity().isSystemOnly(), Op.EQ); CountBy.join( "offerings", ntwkOffJoin, CountBy.entity().getNetworkOfferingId(), ntwkOffJoin.entity().getId(), JoinBuilder.JoinType.INNER); CountBy.done(); PhysicalNetworkSearch = createSearchBuilder(); PhysicalNetworkSearch.and( "physicalNetworkId", PhysicalNetworkSearch.entity().getPhysicalNetworkId(), Op.EQ); PhysicalNetworkSearch.done(); SecurityGroupSearch = createSearchBuilder(); SearchBuilder<NetworkServiceMapVO> join3 = _ntwkSvcMap.createSearchBuilder(); join3.and("service", join3.entity().getService(), Op.EQ); SecurityGroupSearch.join( "services", join3, SecurityGroupSearch.entity().getId(), join3.entity().getNetworkId(), JoinBuilder.JoinType.INNER); SecurityGroupSearch.done(); NetworksCount = createSearchBuilder(Integer.class); NetworksCount.select(null, Func.COUNT, NetworksCount.entity().getId()); NetworksCount.and( "networkOfferingId", NetworksCount.entity().getNetworkOfferingId(), SearchCriteria.Op.EQ); NetworksCount.done(); NetworksRegularUserCanCreateSearch = createSearchBuilder(Long.class); NetworksRegularUserCanCreateSearch.and( "aclType", NetworksRegularUserCanCreateSearch.entity().getAclType(), Op.EQ); NetworksRegularUserCanCreateSearch.select( null, Func.COUNT, NetworksRegularUserCanCreateSearch.entity().getId()); SearchBuilder<NetworkAccountVO> join4 = _accountsDao.createSearchBuilder(); join4.and("account", join4.entity().getAccountId(), Op.EQ); join4.and("isOwner", join4.entity().isOwner(), Op.EQ); NetworksRegularUserCanCreateSearch.join( "accounts", join4, NetworksRegularUserCanCreateSearch.entity().getId(), join4.entity().getNetworkId(), JoinBuilder.JoinType.INNER); SearchBuilder<NetworkOfferingVO> join5 = _ntwkOffDao.createSearchBuilder(); join5.and("specifyVlan", join5.entity().getSpecifyVlan(), Op.EQ); NetworksRegularUserCanCreateSearch.join( "ntwkOff", join5, NetworksRegularUserCanCreateSearch.entity().getNetworkOfferingId(), join5.entity().getId(), JoinBuilder.JoinType.INNER); NetworksRegularUserCanCreateSearch.done(); _tgMacAddress = _tgs.get("macAddress"); SourceNATSearch = createSearchBuilder(); SourceNATSearch.and("account", SourceNATSearch.entity().getAccountId(), Op.EQ); SourceNATSearch.and("datacenter", SourceNATSearch.entity().getDataCenterId(), Op.EQ); SourceNATSearch.and("guestType", SourceNATSearch.entity().getGuestType(), Op.EQ); SearchBuilder<NetworkServiceMapVO> join6 = _ntwkSvcMap.createSearchBuilder(); join6.and("service", join6.entity().getService(), Op.EQ); SourceNATSearch.join( "services", join6, SourceNATSearch.entity().getId(), join6.entity().getNetworkId(), JoinBuilder.JoinType.INNER); SourceNATSearch.done(); VpcNetworksCount = createSearchBuilder(Long.class); VpcNetworksCount.and("vpcId", VpcNetworksCount.entity().getVpcId(), Op.EQ); VpcNetworksCount.select(null, Func.COUNT, VpcNetworksCount.entity().getId()); SearchBuilder<NetworkOfferingVO> join9 = _ntwkOffDao.createSearchBuilder(); join9.and("isSystem", join9.entity().isSystemOnly(), Op.EQ); VpcNetworksCount.join( "offerings", join9, VpcNetworksCount.entity().getNetworkOfferingId(), join9.entity().getId(), JoinBuilder.JoinType.INNER); VpcNetworksCount.done(); OfferingAccountNetworkSearch = createSearchBuilder(); OfferingAccountNetworkSearch.select( null, Func.DISTINCT, OfferingAccountNetworkSearch.entity().getId()); SearchBuilder<NetworkOfferingVO> ntwkOfferingJoin = _ntwkOffDao.createSearchBuilder(); ntwkOfferingJoin.and("isSystem", ntwkOfferingJoin.entity().isSystemOnly(), Op.EQ); OfferingAccountNetworkSearch.join( "ntwkOfferingSearch", ntwkOfferingJoin, OfferingAccountNetworkSearch.entity().getNetworkOfferingId(), ntwkOfferingJoin.entity().getId(), JoinBuilder.JoinType.LEFT); SearchBuilder<NetworkAccountVO> ntwkAccountJoin = _accountsDao.createSearchBuilder(); ntwkAccountJoin.and("accountId", ntwkAccountJoin.entity().getAccountId(), Op.EQ); OfferingAccountNetworkSearch.join( "ntwkAccountSearch", ntwkAccountJoin, OfferingAccountNetworkSearch.entity().getId(), ntwkAccountJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER); OfferingAccountNetworkSearch.and( "zoneId", OfferingAccountNetworkSearch.entity().getDataCenterId(), Op.EQ); OfferingAccountNetworkSearch.and( "type", OfferingAccountNetworkSearch.entity().getGuestType(), Op.EQ); OfferingAccountNetworkSearch.done(); GarbageCollectedSearch = createSearchBuilder(Long.class); GarbageCollectedSearch.selectFields(GarbageCollectedSearch.entity().getId()); SearchBuilder<NetworkOpVO> join7 = _ntwkOpDao.createSearchBuilder(); join7.and("activenics", join7.entity().getActiveNicsCount(), Op.EQ); join7.and("gc", join7.entity().isGarbageCollected(), Op.EQ); join7.and("check", join7.entity().isCheckForGc(), Op.EQ); GarbageCollectedSearch.join( "ntwkOpGC", join7, GarbageCollectedSearch.entity().getId(), join7.entity().getId(), JoinBuilder.JoinType.INNER); SearchBuilder<NetworkOfferingVO> join8 = _ntwkOffDao.createSearchBuilder(); join8.and("isPersistent", join8.entity().getIsPersistent(), Op.EQ); GarbageCollectedSearch.join( "ntwkOffGC", join8, GarbageCollectedSearch.entity().getNetworkOfferingId(), join8.entity().getId(), JoinBuilder.JoinType.INNER); GarbageCollectedSearch.done(); }
@PostConstruct public void init() { AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ); AllFieldsSearch.and("dataCenterId", AllFieldsSearch.entity().getDataCenterId(), Op.EQ); AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getAddress(), Op.EQ); AllFieldsSearch.and("vlan", AllFieldsSearch.entity().getVlanId(), Op.EQ); AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAllocatedToAccountId(), Op.EQ); AllFieldsSearch.and("sourceNat", AllFieldsSearch.entity().isSourceNat(), Op.EQ); AllFieldsSearch.and("network", AllFieldsSearch.entity().getAssociatedWithNetworkId(), Op.EQ); AllFieldsSearch.and( "associatedWithVmId", AllFieldsSearch.entity().getAssociatedWithVmId(), Op.EQ); AllFieldsSearch.and("oneToOneNat", AllFieldsSearch.entity().isOneToOneNat(), Op.EQ); AllFieldsSearch.and("sourcenetwork", AllFieldsSearch.entity().getSourceNetworkId(), Op.EQ); AllFieldsSearch.and( "physicalNetworkId", AllFieldsSearch.entity().getPhysicalNetworkId(), Op.EQ); AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ); AllFieldsSearch.and("associatedVmIp", AllFieldsSearch.entity().getVmIp(), Op.EQ); AllFieldsSearch.done(); VlanDbIdSearchUnallocated = createSearchBuilder(); VlanDbIdSearchUnallocated.and( "allocated", VlanDbIdSearchUnallocated.entity().getAllocatedTime(), Op.NULL); VlanDbIdSearchUnallocated.and( "vlanDbId", VlanDbIdSearchUnallocated.entity().getVlanId(), Op.EQ); VlanDbIdSearchUnallocated.done(); AllIpCount = createSearchBuilder(Integer.class); AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getAddress()); AllIpCount.and("dc", AllIpCount.entity().getDataCenterId(), Op.EQ); AllIpCount.and("vlan", AllIpCount.entity().getVlanId(), Op.EQ); AllIpCount.done(); AllocatedIpCount = createSearchBuilder(Integer.class); AllocatedIpCount.select(null, Func.COUNT, AllocatedIpCount.entity().getAddress()); AllocatedIpCount.and("dc", AllocatedIpCount.entity().getDataCenterId(), Op.EQ); AllocatedIpCount.and("vlan", AllocatedIpCount.entity().getVlanId(), Op.EQ); AllocatedIpCount.and("allocated", AllocatedIpCount.entity().getAllocatedTime(), Op.NNULL); AllocatedIpCount.done(); AllIpCountForDashboard = createSearchBuilder(Integer.class); AllIpCountForDashboard.select(null, Func.COUNT, AllIpCountForDashboard.entity().getAddress()); AllIpCountForDashboard.and("dc", AllIpCountForDashboard.entity().getDataCenterId(), Op.EQ); AllIpCountForDashboard.and( "state", AllIpCountForDashboard.entity().getState(), SearchCriteria.Op.NEQ); SearchBuilder<VlanVO> virtaulNetworkVlan = _vlanDao.createSearchBuilder(); virtaulNetworkVlan.and( "vlanType", virtaulNetworkVlan.entity().getVlanType(), SearchCriteria.Op.EQ); AllIpCountForDashboard.join( "vlan", virtaulNetworkVlan, virtaulNetworkVlan.entity().getId(), AllIpCountForDashboard.entity().getVlanId(), JoinBuilder.JoinType.INNER); virtaulNetworkVlan.done(); AllIpCountForDashboard.done(); AllocatedIpCountForAccount = createSearchBuilder(Long.class); AllocatedIpCountForAccount.select( null, Func.COUNT, AllocatedIpCountForAccount.entity().getAddress()); AllocatedIpCountForAccount.and( "account", AllocatedIpCountForAccount.entity().getAllocatedToAccountId(), Op.EQ); AllocatedIpCountForAccount.and( "allocated", AllocatedIpCountForAccount.entity().getAllocatedTime(), Op.NNULL); AllocatedIpCountForAccount.and( "network", AllocatedIpCountForAccount.entity().getAssociatedWithNetworkId(), Op.NNULL); AllocatedIpCountForAccount.done(); CountFreePublicIps = createSearchBuilder(Long.class); CountFreePublicIps.select(null, Func.COUNT, null); CountFreePublicIps.and("state", CountFreePublicIps.entity().getState(), SearchCriteria.Op.EQ); CountFreePublicIps.and( "networkId", CountFreePublicIps.entity().getSourceNetworkId(), SearchCriteria.Op.EQ); SearchBuilder<VlanVO> join = _vlanDao.createSearchBuilder(); join.and("vlanType", join.entity().getVlanType(), Op.EQ); CountFreePublicIps.join( "vlans", join, CountFreePublicIps.entity().getVlanId(), join.entity().getId(), JoinBuilder.JoinType.INNER); CountFreePublicIps.done(); DeleteAllExceptGivenIp = createSearchBuilder(); DeleteAllExceptGivenIp.and("vlanDbId", DeleteAllExceptGivenIp.entity().getVlanId(), Op.EQ); DeleteAllExceptGivenIp.and("ip", DeleteAllExceptGivenIp.entity().getAddress(), Op.NEQ); }