Add yang generated packages in .gitignore
[groupbasedpolicy.git] / groupbasedpolicy / src / main / java / org / opendaylight / groupbasedpolicy / resolver / PolicyResolverUtils.java
1 package org.opendaylight.groupbasedpolicy.resolver;
2
3 import java.util.HashMap;
4 import java.util.List;
5 import java.util.Map;
6 import java.util.Set;
7
8 import org.opendaylight.groupbasedpolicy.resolver.ContractResolverUtils.ContractMatch;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.Table;
12
13 public class PolicyResolverUtils {
14
15     private PolicyResolverUtils() {
16         throw new UnsupportedOperationException("Cannot create an instance");
17     }
18
19     /**
20      * Resolve the policy in three phases: <br>
21      * (1) select contracts that in scope based on contract selectors. <br>
22      * (2) select subjects that are in scope for each contract based on matchers in clauses <br>
23      * (3) resolve the set of in-scope contracts into a list of subjects that apply for each pair of
24      * endpoint groups and the conditions that can apply for for each endpoint in those groups.
25      */
26     public static Table<EgKey, EgKey, Policy> resolvePolicy(Set<IndexedTenant> tenants) {
27         return resolvePolicy(tenants, new HashMap<EgKey, Set<ConditionSet>>());
28     }
29
30     /**
31      * Resolve the policy in three phases: <br>
32      * (1) select contracts that in scope based on contract selectors. <br>
33      * (2) select subjects that are in scope for each contract based on matchers in clauses <br>
34      * (3) resolve the set of in-scope contracts into a list of subjects that apply for each pair of
35      * endpoint groups and the conditions that can apply for for each endpoint in those groups.
36      */
37     protected static Table<EgKey, EgKey, Policy> resolvePolicy(Set<IndexedTenant> tenants,
38             Map<EgKey, Set<ConditionSet>> egConditions) {
39         Preconditions.checkNotNull(tenants);
40         Preconditions.checkNotNull(egConditions);
41         // select contracts that apply for the given tenant
42         Table<EgKey, EgKey, List<ContractMatch>> contractMatches = ContractResolverUtils.selectContracts(tenants);
43
44         // select subjects for the matching contracts and resolve the policy
45         // for endpoint group pairs. This does phase (2) and (3) as one step
46         return SubjectResolverUtils.selectSubjects(contractMatches, egConditions);
47     }
48
49 }