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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations