Search in sources :

Example 31 with ListProjectResourcesCriteria

use of com.cloud.projects.Project.ListProjectResourcesCriteria in project cosmic by MissionCriticalCloud.

the class Site2SiteVpnManagerImpl method searchForCustomerGateways.

@Override
public Pair<List<? extends Site2SiteCustomerGateway>, Integer> searchForCustomerGateways(final ListVpnCustomerGatewaysCmd cmd) {
    final Long id = cmd.getId();
    Long domainId = cmd.getDomainId();
    boolean isRecursive = cmd.isRecursive();
    final String accountName = cmd.getAccountName();
    final boolean listAll = cmd.listAll();
    final long startIndex = cmd.getStartIndex();
    final long pageSizeVal = cmd.getPageSizeVal();
    String keyword = cmd.getKeyword();
    final Account caller = CallContext.current().getCallingAccount();
    final List<Long> permittedAccounts = new ArrayList<>();
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, id, accountName, cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
    domainId = domainIdRecursiveListProject.first();
    isRecursive = domainIdRecursiveListProject.second();
    final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    final Filter searchFilter = new Filter(Site2SiteCustomerGatewayVO.class, "id", false, startIndex, pageSizeVal);
    final SearchBuilder<Site2SiteCustomerGatewayVO> sb = _customerGatewayDao.createSearchBuilder();
    _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE);
    final SearchCriteria<Site2SiteCustomerGatewayVO> sc = sb.create();
    _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (keyword != null && !keyword.isEmpty()) {
        sc.setParameters("name", "%" + keyword + "%");
    }
    final Pair<List<Site2SiteCustomerGatewayVO>, Integer> result = _customerGatewayDao.searchAndCount(sc, searchFilter);
    return new Pair<>(result.first(), result.second());
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) ArrayList(java.util.ArrayList) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Pair(com.cloud.utils.Pair)

Example 32 with ListProjectResourcesCriteria

use of com.cloud.projects.Project.ListProjectResourcesCriteria in project cosmic by MissionCriticalCloud.

the class Site2SiteVpnManagerImpl method searchForVpnConnections.

@Override
public Pair<List<? extends Site2SiteVpnConnection>, Integer> searchForVpnConnections(final ListVpnConnectionsCmd cmd) {
    final Long id = cmd.getId();
    final Long vpcId = cmd.getVpcId();
    final Boolean display = cmd.getDisplay();
    Long domainId = cmd.getDomainId();
    boolean isRecursive = cmd.isRecursive();
    final String accountName = cmd.getAccountName();
    final boolean listAll = cmd.listAll();
    final long startIndex = cmd.getStartIndex();
    final long pageSizeVal = cmd.getPageSizeVal();
    final Account caller = CallContext.current().getCallingAccount();
    final List<Long> permittedAccounts = new ArrayList<>();
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, id, accountName, cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
    domainId = domainIdRecursiveListProject.first();
    isRecursive = domainIdRecursiveListProject.second();
    final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    final Filter searchFilter = new Filter(Site2SiteVpnConnectionVO.class, "id", false, startIndex, pageSizeVal);
    final SearchBuilder<Site2SiteVpnConnectionVO> sb = _vpnConnectionDao.createSearchBuilder();
    _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("display", sb.entity().isDisplay(), SearchCriteria.Op.EQ);
    if (vpcId != null) {
        final SearchBuilder<Site2SiteVpnGatewayVO> gwSearch = _vpnGatewayDao.createSearchBuilder();
        gwSearch.and("vpcId", gwSearch.entity().getVpcId(), SearchCriteria.Op.EQ);
        sb.join("gwSearch", gwSearch, sb.entity().getVpnGatewayId(), gwSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    }
    final SearchCriteria<Site2SiteVpnConnectionVO> sc = sb.create();
    _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (display != null) {
        sc.setParameters("display", display);
    }
    if (id != null) {
        sc.addAnd("id", SearchCriteria.Op.EQ, id);
    }
    if (vpcId != null) {
        sc.setJoinParameters("gwSearch", "vpcId", vpcId);
    }
    final Pair<List<Site2SiteVpnConnectionVO>, Integer> result = _vpnConnectionDao.searchAndCount(sc, searchFilter);
    return new Pair<>(result.first(), result.second());
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Pair(com.cloud.utils.Pair)

Example 33 with ListProjectResourcesCriteria

use of com.cloud.projects.Project.ListProjectResourcesCriteria in project cosmic by MissionCriticalCloud.

the class RulesManagerImpl method searchStaticNatRules.

@Override
public Pair<List<? extends FirewallRule>, Integer> searchStaticNatRules(final Long ipId, final Long id, final Long vmId, final Long start, final Long size, final String accountName, Long domainId, final Long projectId, boolean isRecursive, final boolean listAll) {
    final Account caller = CallContext.current().getCallingAccount();
    final List<Long> permittedAccounts = new ArrayList<>();
    if (ipId != null) {
        final IPAddressVO ipAddressVO = _ipAddressDao.findById(ipId);
        if (ipAddressVO == null || !ipAddressVO.readyToUse()) {
            throw new InvalidParameterValueException("Ip address id=" + ipId + " not ready for port forwarding rules yet");
        }
        _accountMgr.checkAccess(caller, null, true, ipAddressVO);
    }
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
    domainId = domainIdRecursiveListProject.first();
    isRecursive = domainIdRecursiveListProject.second();
    final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    final Filter filter = new Filter(PortForwardingRuleVO.class, "id", false, start, size);
    final SearchBuilder<FirewallRuleVO> sb = _firewallDao.createSearchBuilder();
    _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sb.and("ip", sb.entity().getSourceIpAddressId(), Op.EQ);
    sb.and("purpose", sb.entity().getPurpose(), Op.EQ);
    sb.and("id", sb.entity().getId(), Op.EQ);
    if (vmId != null) {
        final SearchBuilder<IPAddressVO> ipSearch = _ipAddressDao.createSearchBuilder();
        ipSearch.and("associatedWithVmId", ipSearch.entity().getAssociatedWithVmId(), Op.EQ);
        sb.join("ipSearch", ipSearch, sb.entity().getSourceIpAddressId(), ipSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    }
    final SearchCriteria<FirewallRuleVO> sc = sb.create();
    _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sc.setParameters("purpose", Purpose.StaticNat);
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (ipId != null) {
        sc.setParameters("ip", ipId);
    }
    if (vmId != null) {
        sc.setJoinParameters("ipSearch", "associatedWithVmId", vmId);
    }
    final Pair<List<FirewallRuleVO>, Integer> result = _firewallDao.searchAndCount(sc, filter);
    return new Pair<>(result.first(), result.second());
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Filter(com.cloud.utils.db.Filter) IPAddressVO(com.cloud.network.dao.IPAddressVO) List(java.util.List) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair)

Example 34 with ListProjectResourcesCriteria

use of com.cloud.projects.Project.ListProjectResourcesCriteria in project cosmic by MissionCriticalCloud.

the class NetworkACLServiceImpl method listNetworkACLs.

@Override
public Pair<List<? extends NetworkACL>, Integer> listNetworkACLs(final ListNetworkACLListsCmd cmd) {
    final Long id = cmd.getId();
    final String name = cmd.getName();
    final Long networkId = cmd.getNetworkId();
    final Long vpcId = cmd.getVpcId();
    final String keyword = cmd.getKeyword();
    final Boolean display = cmd.getDisplay();
    final SearchBuilder<NetworkACLVO> sb = _networkACLDao.createSearchBuilder();
    sb.and("id", sb.entity().getId(), Op.EQ);
    sb.and("name", sb.entity().getName(), Op.EQ);
    sb.and("vpcId", sb.entity().getVpcId(), Op.IN);
    sb.and("display", sb.entity().isDisplay(), Op.EQ);
    final Account caller = CallContext.current().getCallingAccount();
    if (networkId != null) {
        final SearchBuilder<NetworkVO> network = _networkDao.createSearchBuilder();
        network.and("networkId", network.entity().getId(), Op.EQ);
        sb.join("networkJoin", network, sb.entity().getId(), network.entity().getNetworkACLId(), JoinBuilder.JoinType.INNER);
    }
    final SearchCriteria<NetworkACLVO> sc = sb.create();
    if (keyword != null) {
        final SearchCriteria<NetworkACLVO> ssc = _networkACLDao.createSearchCriteria();
        ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        ssc.addOr("description", SearchCriteria.Op.LIKE, "%" + keyword + "%");
        sc.addAnd("name", SearchCriteria.Op.SC, ssc);
    }
    if (display != null) {
        sc.setParameters("display", display);
    }
    if (id != null) {
        sc.setParameters("id", id);
    }
    if (name != null) {
        sc.setParameters("name", name);
    }
    if (vpcId != null) {
        final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
        if (vpc == null) {
            throw new InvalidParameterValueException("Unable to find VPC");
        }
        _accountMgr.checkAccess(caller, null, true, vpc);
        // Include vpcId 0 to list default ACLs
        sc.setParameters("vpcId", vpcId, 0);
    } else {
        // ToDo: Add accountId to network_acl table for permission check
        // VpcId is not specified. Find permitted VPCs for the caller
        // and list ACLs belonging to the permitted VPCs
        final List<Long> permittedAccounts = new ArrayList<>();
        Long domainId = cmd.getDomainId();
        boolean isRecursive = cmd.isRecursive();
        final String accountName = cmd.getAccountName();
        final Long projectId = cmd.getProjectId();
        final boolean listAll = cmd.listAll();
        final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
        _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
        domainId = domainIdRecursiveListProject.first();
        isRecursive = domainIdRecursiveListProject.second();
        final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
        final SearchBuilder<VpcVO> sbVpc = _vpcDao.createSearchBuilder();
        _accountMgr.buildACLSearchBuilder(sbVpc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
        final SearchCriteria<VpcVO> scVpc = sbVpc.create();
        _accountMgr.buildACLSearchCriteria(scVpc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
        final List<VpcVO> vpcs = _vpcDao.search(scVpc, null);
        final List<Long> vpcIds = new ArrayList<>();
        for (final VpcVO vpc : vpcs) {
            vpcIds.add(vpc.getId());
        }
        // Add vpc_id 0 to list default ACLs
        vpcIds.add(0L);
        sc.setParameters("vpcId", vpcIds.toArray());
    }
    if (networkId != null) {
        sc.setJoinParameters("networkJoin", "networkId", networkId);
    }
    final Filter filter = new Filter(NetworkACLVO.class, "id", false, null, null);
    final Pair<List<NetworkACLVO>, Integer> acls = _networkACLDao.searchAndCount(sc, filter);
    return new Pair<>(acls.first(), acls.second());
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair) NetworkVO(com.cloud.network.dao.NetworkVO) Ternary(com.cloud.utils.Ternary) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter)

Example 35 with ListProjectResourcesCriteria

use of com.cloud.projects.Project.ListProjectResourcesCriteria in project cosmic by MissionCriticalCloud.

the class VpcManagerImpl method listStaticRoutes.

@Override
public Pair<List<? extends StaticRoute>, Integer> listStaticRoutes(final ListStaticRoutesCmd cmd) {
    final Long id = cmd.getId();
    final String nextHop = cmd.getNextHop();
    final String cidr = cmd.getCidr();
    final Long vpcId = cmd.getVpcId();
    Long domainId = cmd.getDomainId();
    Boolean isRecursive = cmd.isRecursive();
    final Boolean listAll = cmd.listAll();
    final String accountName = cmd.getAccountName();
    final Account caller = CallContext.current().getCallingAccount();
    final List<Long> permittedAccounts = new ArrayList<>();
    final Map<String, String> tags = cmd.getTags();
    final Long projectId = cmd.getProjectId();
    final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
    _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
    domainId = domainIdRecursiveListProject.first();
    isRecursive = domainIdRecursiveListProject.second();
    final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
    final Filter searchFilter = new Filter(StaticRouteVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
    final SearchBuilder<StaticRouteVO> sb = _staticRouteDao.createSearchBuilder();
    _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ);
    sb.and("gwIpAddress", sb.entity().getGwIpAddress(), SearchCriteria.Op.EQ);
    sb.and("cidr", sb.entity().getCidr(), SearchCriteria.Op.EQ);
    if (tags != null && !tags.isEmpty()) {
        final SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
        for (int count = 0; count < tags.size(); count++) {
            tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
            tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
            tagSearch.cp();
        }
        tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
        sb.groupBy(sb.entity().getId());
        sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
    }
    final SearchCriteria<StaticRouteVO> sc = sb.create();
    _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    if (id != null) {
        sc.addAnd("id", Op.EQ, id);
    }
    if (vpcId != null) {
        sc.addAnd("vpcId", Op.EQ, vpcId);
    }
    if (nextHop != null) {
        sc.addAnd("gwIpAddress", Op.EQ, nextHop);
    }
    if (cidr != null) {
        sc.addAnd("cidr", Op.EQ, cidr);
    }
    if (tags != null && !tags.isEmpty()) {
        int count = 0;
        sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.StaticRoute.toString());
        for (final String key : tags.keySet()) {
            sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
            sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
            count++;
        }
    }
    final Pair<List<StaticRouteVO>, Integer> result = _staticRouteDao.searchAndCount(sc, searchFilter);
    return new Pair<>(result.first(), result.second());
}
Also used : Account(com.cloud.user.Account) Ternary(com.cloud.utils.Ternary) ArrayList(java.util.ArrayList) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) ResourceTagVO(com.cloud.tags.ResourceTagVO) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(com.cloud.utils.Pair)

Aggregations

ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)62 Ternary (com.cloud.utils.Ternary)62 ArrayList (java.util.ArrayList)62 Account (com.cloud.user.Account)61 Filter (com.cloud.utils.db.Filter)57 List (java.util.List)49 Pair (com.cloud.utils.Pair)48 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)24 ResourceTagVO (com.cloud.tags.ResourceTagVO)19 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)15 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)11 IPAddressVO (com.cloud.network.dao.IPAddressVO)10 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)8 DomainVO (com.cloud.domain.DomainVO)6 Date (java.util.Date)6 LinkedList (java.util.LinkedList)6 UserVmVO (com.cloud.vm.UserVmVO)5 AffinityGroupJoinVO (com.cloud.api.query.vo.AffinityGroupJoinVO)4 AsyncJobJoinVO (com.cloud.api.query.vo.AsyncJobJoinVO)4 DomainRouterJoinVO (com.cloud.api.query.vo.DomainRouterJoinVO)4