Search in sources :

Example 21 with NetworkACLItemVO

use of com.cloud.network.vpc.NetworkACLItemVO in project cloudstack by apache.

the class ResourceIconManagerImpl method getAccountDomain.

private Pair<Long, Long> getAccountDomain(long resourceId, ResourceTag.ResourceObjectType resourceType) {
    Class<?> clazz = ResourceManagerUtilImpl.s_typeMap.get(resourceType);
    Object entity = entityMgr.findById(clazz, resourceId);
    Long accountId = null;
    Long domainId = null;
    // if the resource type is a security group rule, get the accountId and domainId from the security group itself
    if (resourceType == ResourceTag.ResourceObjectType.SecurityGroupRule) {
        SecurityGroupRuleVO rule = (SecurityGroupRuleVO) entity;
        Object SecurityGroup = entityMgr.findById(ResourceManagerUtilImpl.s_typeMap.get(ResourceTag.ResourceObjectType.SecurityGroup), rule.getSecurityGroupId());
        accountId = ((SecurityGroupVO) SecurityGroup).getAccountId();
        domainId = ((SecurityGroupVO) SecurityGroup).getDomainId();
    }
    if (resourceType == ResourceTag.ResourceObjectType.Account) {
        AccountVO account = (AccountVO) entity;
        accountId = account.getId();
        domainId = account.getDomainId();
    }
    // if the resource type is network acl, get the accountId and domainId from VPC following: NetworkACLItem -> NetworkACL -> VPC
    if (resourceType == ResourceTag.ResourceObjectType.NetworkACL) {
        NetworkACLItemVO aclItem = (NetworkACLItemVO) entity;
        Object networkACL = entityMgr.findById(ResourceManagerUtilImpl.s_typeMap.get(ResourceTag.ResourceObjectType.NetworkACLList), aclItem.getAclId());
        Long vpcId = ((NetworkACLVO) networkACL).getVpcId();
        if (vpcId != null && vpcId != 0) {
            Object vpc = entityMgr.findById(ResourceManagerUtilImpl.s_typeMap.get(ResourceTag.ResourceObjectType.Vpc), vpcId);
            accountId = ((VpcVO) vpc).getAccountId();
            domainId = ((VpcVO) vpc).getDomainId();
        }
    }
    if (resourceType == ResourceTag.ResourceObjectType.Project) {
        accountId = ((ProjectVO) entity).getProjectAccountId();
    }
    if (resourceType == ResourceTag.ResourceObjectType.SnapshotPolicy) {
        accountId = entityMgr.findById(VolumeVO.class, ((SnapshotPolicyVO) entity).getVolumeId()).getAccountId();
    }
    if (entity instanceof OwnedBy) {
        accountId = ((OwnedBy) entity).getAccountId();
    }
    if (entity instanceof PartOf) {
        domainId = ((PartOf) entity).getDomainId();
    }
    if (accountId == null) {
        accountId = Account.ACCOUNT_ID_SYSTEM;
    }
    if ((domainId == null) || ((accountId != null) && (domainId.longValue() == -1))) {
        domainId = accountDao.getDomainIdForGivenAccountId(accountId);
    }
    return new Pair<>(accountId, domainId);
}
Also used : NetworkACLVO(com.cloud.network.vpc.NetworkACLVO) OwnedBy(com.cloud.user.OwnedBy) SecurityGroupRuleVO(com.cloud.network.security.SecurityGroupRuleVO) PartOf(com.cloud.domain.PartOf) AccountVO(com.cloud.user.AccountVO) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) Pair(com.cloud.utils.Pair)

Example 22 with NetworkACLItemVO

use of com.cloud.network.vpc.NetworkACLItemVO in project cloudstack by apache.

the class TaggedResourceManagerImpl method getAccountDomain.

private Pair<Long, Long> getAccountDomain(long resourceId, ResourceObjectType resourceType) {
    Class<?> clazz = ResourceManagerUtilImpl.s_typeMap.get(resourceType);
    Object entity = _entityMgr.findById(clazz, resourceId);
    Long accountId = null;
    Long domainId = null;
    // if the resource type is a security group rule, get the accountId and domainId from the security group itself
    if (resourceType == ResourceObjectType.SecurityGroupRule) {
        SecurityGroupRuleVO rule = (SecurityGroupRuleVO) entity;
        Object SecurityGroup = _entityMgr.findById(ResourceManagerUtilImpl.s_typeMap.get(ResourceObjectType.SecurityGroup), rule.getSecurityGroupId());
        accountId = ((SecurityGroupVO) SecurityGroup).getAccountId();
        domainId = ((SecurityGroupVO) SecurityGroup).getDomainId();
    }
    if (resourceType == ResourceObjectType.Account) {
        AccountVO account = (AccountVO) entity;
        accountId = account.getId();
        domainId = account.getDomainId();
    }
    // if the resource type is network acl, get the accountId and domainId from VPC following: NetworkACLItem -> NetworkACL -> VPC
    if (resourceType == ResourceObjectType.NetworkACL) {
        NetworkACLItemVO aclItem = (NetworkACLItemVO) entity;
        Object networkACL = _entityMgr.findById(ResourceManagerUtilImpl.s_typeMap.get(ResourceObjectType.NetworkACLList), aclItem.getAclId());
        Long vpcId = ((NetworkACLVO) networkACL).getVpcId();
        if (vpcId != null && vpcId != 0) {
            Object vpc = _entityMgr.findById(ResourceManagerUtilImpl.s_typeMap.get(ResourceObjectType.Vpc), vpcId);
            accountId = ((VpcVO) vpc).getAccountId();
            domainId = ((VpcVO) vpc).getDomainId();
        }
    }
    if (resourceType == ResourceObjectType.Project) {
        accountId = ((ProjectVO) entity).getProjectAccountId();
    }
    if (resourceType == ResourceObjectType.SnapshotPolicy) {
        accountId = _entityMgr.findById(VolumeVO.class, ((SnapshotPolicyVO) entity).getVolumeId()).getAccountId();
    }
    if (entity instanceof OwnedBy) {
        accountId = ((OwnedBy) entity).getAccountId();
    }
    if (entity instanceof PartOf) {
        domainId = ((PartOf) entity).getDomainId();
    }
    if (accountId == null) {
        accountId = Account.ACCOUNT_ID_SYSTEM;
    }
    if ((domainId == null) || ((accountId != null) && (domainId.longValue() == -1))) {
        domainId = _accountDao.getDomainIdForGivenAccountId(accountId);
    }
    return new Pair<>(accountId, domainId);
}
Also used : NetworkACLVO(com.cloud.network.vpc.NetworkACLVO) OwnedBy(com.cloud.user.OwnedBy) SecurityGroupRuleVO(com.cloud.network.security.SecurityGroupRuleVO) PartOf(com.cloud.domain.PartOf) AccountVO(com.cloud.user.AccountVO) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) Pair(com.cloud.utils.Pair)

Example 23 with NetworkACLItemVO

use of com.cloud.network.vpc.NetworkACLItemVO in project cloudstack by apache.

the class OvsTunnelManagerImpl method prepareVpcRoutingPolicyUpdate.

private OvsVpcRoutingPolicyConfigCommand prepareVpcRoutingPolicyUpdate(long vpcId) {
    List<OvsVpcRoutingPolicyConfigCommand.Acl> acls = new ArrayList<>();
    List<OvsVpcRoutingPolicyConfigCommand.Tier> tiers = new ArrayList<>();
    VpcVO vpc = _vpcDao.findById(vpcId);
    List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
    assert (vpc != null && (vpcNetworks != null && !vpcNetworks.isEmpty())) : "invalid vpc id";
    for (Network network : vpcNetworks) {
        Long networkAclId = network.getNetworkACLId();
        if (networkAclId == null)
            continue;
        NetworkACLVO networkAcl = _networkACLDao.findById(networkAclId);
        List<OvsVpcRoutingPolicyConfigCommand.AclItem> aclItems = new ArrayList<>();
        List<NetworkACLItemVO> aclItemVos = _networkACLItemDao.listByACL(networkAclId);
        for (NetworkACLItemVO aclItem : aclItemVos) {
            String[] sourceCidrs = aclItem.getSourceCidrList().toArray(new String[aclItem.getSourceCidrList().size()]);
            aclItems.add(new OvsVpcRoutingPolicyConfigCommand.AclItem(aclItem.getNumber(), aclItem.getUuid(), aclItem.getAction().name(), aclItem.getTrafficType().name(), ((aclItem.getSourcePortStart() != null) ? aclItem.getSourcePortStart().toString() : null), ((aclItem.getSourcePortEnd() != null) ? aclItem.getSourcePortEnd().toString() : null), aclItem.getProtocol(), sourceCidrs));
        }
        OvsVpcRoutingPolicyConfigCommand.Acl acl = new OvsVpcRoutingPolicyConfigCommand.Acl(networkAcl.getUuid(), aclItems.toArray(new OvsVpcRoutingPolicyConfigCommand.AclItem[aclItems.size()]));
        acls.add(acl);
        OvsVpcRoutingPolicyConfigCommand.Tier tier = new OvsVpcRoutingPolicyConfigCommand.Tier(network.getUuid(), network.getCidr(), networkAcl.getUuid());
        tiers.add(tier);
    }
    OvsVpcRoutingPolicyConfigCommand cmd = new OvsVpcRoutingPolicyConfigCommand(vpc.getUuid(), vpc.getCidr(), acls.toArray(new OvsVpcRoutingPolicyConfigCommand.Acl[acls.size()]), tiers.toArray(new OvsVpcRoutingPolicyConfigCommand.Tier[tiers.size()]));
    return cmd;
}
Also used : ArrayList(java.util.ArrayList) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) OvsVpcRoutingPolicyConfigCommand(com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand) NetworkACLVO(com.cloud.network.vpc.NetworkACLVO) VpcVO(com.cloud.network.vpc.VpcVO) Network(com.cloud.network.Network)

Example 24 with NetworkACLItemVO

use of com.cloud.network.vpc.NetworkACLItemVO in project cloudstack by apache.

the class NetworkACLItemDaoImpl method findByAclAndNumber.

@Override
public NetworkACLItemVO findByAclAndNumber(long aclId, int number) {
    SearchCriteria<NetworkACLItemVO> sc = AllFieldsSearch.create();
    sc.setParameters("aclId", aclId);
    sc.setParameters("number", number);
    NetworkACLItemVO vo = findOneBy(sc);
    if (vo != null) {
        loadCidrs(vo);
    }
    return vo;
}
Also used : NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO)

Example 25 with NetworkACLItemVO

use of com.cloud.network.vpc.NetworkACLItemVO in project cloudstack by apache.

the class NetworkACLItemDaoImpl method listByACL.

@Override
public List<NetworkACLItemVO> listByACL(Long aclId) {
    if (aclId == null) {
        return Lists.newArrayList();
    }
    SearchCriteria<NetworkACLItemVO> sc = AllFieldsSearch.create();
    sc.setParameters("aclId", aclId);
    List<NetworkACLItemVO> list = listBy(sc);
    for (NetworkACLItemVO item : list) {
        loadCidrs(item);
    }
    return list;
}
Also used : NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO)

Aggregations

NetworkACLItemVO (com.cloud.network.vpc.NetworkACLItemVO)25 VpcVO (com.cloud.network.vpc.VpcVO)9 Network (com.cloud.network.Network)7 ArrayList (java.util.ArrayList)6 Vpc (com.cloud.network.vpc.Vpc)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 NetworkACLVO (com.cloud.network.vpc.NetworkACLVO)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 DomainRouterVO (com.cloud.vm.DomainRouterVO)4 Test (org.junit.Test)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)3 AccountVO (com.cloud.user.AccountVO)3 Pair (com.cloud.utils.Pair)3 Command (com.cloud.agent.api.Command)2 NetworkUsageCommand (com.cloud.agent.api.NetworkUsageCommand)2 PlugNicCommand (com.cloud.agent.api.PlugNicCommand)2 AggregationControlCommand (com.cloud.agent.api.routing.AggregationControlCommand)2 PartOf (com.cloud.domain.PartOf)2 InternalErrorException (com.cloud.exception.InternalErrorException)2