@Test public void testBuildResolvedRules() { List<ResolvedRule> res = PolicyInfoUtils.buildResolvedRules(ImmutableList.of(rule1), tenant1); assertNotNull(res); assertEquals(1, res.size()); assertEquals(rule1.getName(), res.get(0).getName()); }
@VisibleForTesting static List<ResolvedRule> buildResolvedRules(List<Rule> rules, Tenant tenant) { if (rules == null) { return null; } List<ResolvedRule> resolvedRules = new ArrayList<>(); for (Rule rule : rules) { ResolvedRuleBuilder resolvedRuleBuilder = new ResolvedRuleBuilder(); resolvedRuleBuilder.setOrder(rule.getOrder()); resolvedRuleBuilder.setName(rule.getName()); resolvedRuleBuilder.setKey(new ResolvedRuleKey(rule.getName())); List<Classifier> classifiers = new ArrayList<>(); for (ClassifierRef cls : rule.getClassifierRef()) { ClassifierBuilder classifierBuilder = new ClassifierBuilder(); classifierBuilder.setConnectionTracking(convertConnectionTracking(cls.getConnectionTracking())); classifierBuilder.setDirection(cls.getDirection()); classifierBuilder.setKey(new ClassifierKey(cls.getName())); classifierBuilder.setName(cls.getName()); ClassifierInstance classifierInstance = readClassifierInstance(tenant, cls.getInstanceName()); if (classifierInstance != null) { classifierBuilder.setClassifierDefinitionId(classifierInstance.getClassifierDefinitionId()); classifierBuilder.setParameterValue(classifierInstance.getParameterValue()); } classifiers.add(classifierBuilder.build()); } resolvedRuleBuilder.setClassifier(classifiers); List<Action> actions = new ArrayList<>(); for (ActionRef act : rule.getActionRef()) { ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setName(act.getName()); actionBuilder.setKey(new ActionKey(act.getName())); actionBuilder.setOrder(act.getOrder()); ActionInstance actionInstance = readActionInstance(tenant, act.getName()); if (actionInstance != null) { actionBuilder.setActionDefinitionId(actionInstance.getActionDefinitionId()); actionBuilder.setParameterValue(actionInstance.getParameterValue()); } actions.add(actionBuilder.build()); } resolvedRuleBuilder.setAction(actions); resolvedRules.add(resolvedRuleBuilder.build()); } return resolvedRules; }
PolicyInfoUtils { @VisibleForTesting static List<ResolvedRule> buildResolvedRules(List<Rule> rules, Tenant tenant) { if (rules == null) { return null; } List<ResolvedRule> resolvedRules = new ArrayList<>(); for (Rule rule : rules) { ResolvedRuleBuilder resolvedRuleBuilder = new ResolvedRuleBuilder(); resolvedRuleBuilder.setOrder(rule.getOrder()); resolvedRuleBuilder.setName(rule.getName()); resolvedRuleBuilder.setKey(new ResolvedRuleKey(rule.getName())); List<Classifier> classifiers = new ArrayList<>(); for (ClassifierRef cls : rule.getClassifierRef()) { ClassifierBuilder classifierBuilder = new ClassifierBuilder(); classifierBuilder.setConnectionTracking(convertConnectionTracking(cls.getConnectionTracking())); classifierBuilder.setDirection(cls.getDirection()); classifierBuilder.setKey(new ClassifierKey(cls.getName())); classifierBuilder.setName(cls.getName()); ClassifierInstance classifierInstance = readClassifierInstance(tenant, cls.getInstanceName()); if (classifierInstance != null) { classifierBuilder.setClassifierDefinitionId(classifierInstance.getClassifierDefinitionId()); classifierBuilder.setParameterValue(classifierInstance.getParameterValue()); } classifiers.add(classifierBuilder.build()); } resolvedRuleBuilder.setClassifier(classifiers); List<Action> actions = new ArrayList<>(); for (ActionRef act : rule.getActionRef()) { ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setName(act.getName()); actionBuilder.setKey(new ActionKey(act.getName())); actionBuilder.setOrder(act.getOrder()); ActionInstance actionInstance = readActionInstance(tenant, act.getName()); if (actionInstance != null) { actionBuilder.setActionDefinitionId(actionInstance.getActionDefinitionId()); actionBuilder.setParameterValue(actionInstance.getParameterValue()); } actions.add(actionBuilder.build()); } resolvedRuleBuilder.setAction(actions); resolvedRules.add(resolvedRuleBuilder.build()); } return resolvedRules; } }
PolicyInfoUtils { @VisibleForTesting static List<ResolvedRule> buildResolvedRules(List<Rule> rules, Tenant tenant) { if (rules == null) { return null; } List<ResolvedRule> resolvedRules = new ArrayList<>(); for (Rule rule : rules) { ResolvedRuleBuilder resolvedRuleBuilder = new ResolvedRuleBuilder(); resolvedRuleBuilder.setOrder(rule.getOrder()); resolvedRuleBuilder.setName(rule.getName()); resolvedRuleBuilder.setKey(new ResolvedRuleKey(rule.getName())); List<Classifier> classifiers = new ArrayList<>(); for (ClassifierRef cls : rule.getClassifierRef()) { ClassifierBuilder classifierBuilder = new ClassifierBuilder(); classifierBuilder.setConnectionTracking(convertConnectionTracking(cls.getConnectionTracking())); classifierBuilder.setDirection(cls.getDirection()); classifierBuilder.setKey(new ClassifierKey(cls.getName())); classifierBuilder.setName(cls.getName()); ClassifierInstance classifierInstance = readClassifierInstance(tenant, cls.getInstanceName()); if (classifierInstance != null) { classifierBuilder.setClassifierDefinitionId(classifierInstance.getClassifierDefinitionId()); classifierBuilder.setParameterValue(classifierInstance.getParameterValue()); } classifiers.add(classifierBuilder.build()); } resolvedRuleBuilder.setClassifier(classifiers); List<Action> actions = new ArrayList<>(); for (ActionRef act : rule.getActionRef()) { ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setName(act.getName()); actionBuilder.setKey(new ActionKey(act.getName())); actionBuilder.setOrder(act.getOrder()); ActionInstance actionInstance = readActionInstance(tenant, act.getName()); if (actionInstance != null) { actionBuilder.setActionDefinitionId(actionInstance.getActionDefinitionId()); actionBuilder.setParameterValue(actionInstance.getParameterValue()); } actions.add(actionBuilder.build()); } resolvedRuleBuilder.setAction(actions); resolvedRules.add(resolvedRuleBuilder.build()); } return resolvedRules; } private  PolicyInfoUtils(); }
PolicyInfoUtils { @VisibleForTesting static List<ResolvedRule> buildResolvedRules(List<Rule> rules, Tenant tenant) { if (rules == null) { return null; } List<ResolvedRule> resolvedRules = new ArrayList<>(); for (Rule rule : rules) { ResolvedRuleBuilder resolvedRuleBuilder = new ResolvedRuleBuilder(); resolvedRuleBuilder.setOrder(rule.getOrder()); resolvedRuleBuilder.setName(rule.getName()); resolvedRuleBuilder.setKey(new ResolvedRuleKey(rule.getName())); List<Classifier> classifiers = new ArrayList<>(); for (ClassifierRef cls : rule.getClassifierRef()) { ClassifierBuilder classifierBuilder = new ClassifierBuilder(); classifierBuilder.setConnectionTracking(convertConnectionTracking(cls.getConnectionTracking())); classifierBuilder.setDirection(cls.getDirection()); classifierBuilder.setKey(new ClassifierKey(cls.getName())); classifierBuilder.setName(cls.getName()); ClassifierInstance classifierInstance = readClassifierInstance(tenant, cls.getInstanceName()); if (classifierInstance != null) { classifierBuilder.setClassifierDefinitionId(classifierInstance.getClassifierDefinitionId()); classifierBuilder.setParameterValue(classifierInstance.getParameterValue()); } classifiers.add(classifierBuilder.build()); } resolvedRuleBuilder.setClassifier(classifiers); List<Action> actions = new ArrayList<>(); for (ActionRef act : rule.getActionRef()) { ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setName(act.getName()); actionBuilder.setKey(new ActionKey(act.getName())); actionBuilder.setOrder(act.getOrder()); ActionInstance actionInstance = readActionInstance(tenant, act.getName()); if (actionInstance != null) { actionBuilder.setActionDefinitionId(actionInstance.getActionDefinitionId()); actionBuilder.setParameterValue(actionInstance.getParameterValue()); } actions.add(actionBuilder.build()); } resolvedRuleBuilder.setAction(actions); resolvedRules.add(resolvedRuleBuilder.build()); } return resolvedRules; } private  PolicyInfoUtils(); static List<ResolvedPolicy> buildResolvedPolicy(Table<EgKey, EgKey, Policy> policyMap,
            ConcurrentMap<TenantId, IndexedTenant> resolvedTenants); }
PolicyInfoUtils { @VisibleForTesting static List<ResolvedRule> buildResolvedRules(List<Rule> rules, Tenant tenant) { if (rules == null) { return null; } List<ResolvedRule> resolvedRules = new ArrayList<>(); for (Rule rule : rules) { ResolvedRuleBuilder resolvedRuleBuilder = new ResolvedRuleBuilder(); resolvedRuleBuilder.setOrder(rule.getOrder()); resolvedRuleBuilder.setName(rule.getName()); resolvedRuleBuilder.setKey(new ResolvedRuleKey(rule.getName())); List<Classifier> classifiers = new ArrayList<>(); for (ClassifierRef cls : rule.getClassifierRef()) { ClassifierBuilder classifierBuilder = new ClassifierBuilder(); classifierBuilder.setConnectionTracking(convertConnectionTracking(cls.getConnectionTracking())); classifierBuilder.setDirection(cls.getDirection()); classifierBuilder.setKey(new ClassifierKey(cls.getName())); classifierBuilder.setName(cls.getName()); ClassifierInstance classifierInstance = readClassifierInstance(tenant, cls.getInstanceName()); if (classifierInstance != null) { classifierBuilder.setClassifierDefinitionId(classifierInstance.getClassifierDefinitionId()); classifierBuilder.setParameterValue(classifierInstance.getParameterValue()); } classifiers.add(classifierBuilder.build()); } resolvedRuleBuilder.setClassifier(classifiers); List<Action> actions = new ArrayList<>(); for (ActionRef act : rule.getActionRef()) { ActionBuilder actionBuilder = new ActionBuilder(); actionBuilder.setName(act.getName()); actionBuilder.setKey(new ActionKey(act.getName())); actionBuilder.setOrder(act.getOrder()); ActionInstance actionInstance = readActionInstance(tenant, act.getName()); if (actionInstance != null) { actionBuilder.setActionDefinitionId(actionInstance.getActionDefinitionId()); actionBuilder.setParameterValue(actionInstance.getParameterValue()); } actions.add(actionBuilder.build()); } resolvedRuleBuilder.setAction(actions); resolvedRules.add(resolvedRuleBuilder.build()); } return resolvedRules; } private  PolicyInfoUtils(); static List<ResolvedPolicy> buildResolvedPolicy(Table<EgKey, EgKey, Policy> policyMap,
            ConcurrentMap<TenantId, IndexedTenant> resolvedTenants);  }