public void loadAll(List<Contract> contracts, List<MappedContract> mpContracts) { if (mpContracts != null) { for (MappedContract mpContract : mpContracts) { mappedContracts.putIfAbsent(mpContract.getGbpContractId(), mpContract.getFaasSecurityRulesId()); } } if (contracts != null) { for (Contract contract : contracts) { LOG.debug("Loading Contract {}", contract.getId().getValue()); UlnDatastoreApi.submitSecurityGroupsToDs(initSecurityGroupBuilder(contract).build()); } } }
public static String createFlowCacheName(InstanceIdentifier<Classifier> classifierIid, FlowCacheCons.Value value) { PolicyRuleGroupKey policyRuleGroup = classifierIid.firstKeyOf(PolicyRuleGroup.class); ResolvedRuleKey resolvedRule = classifierIid.firstKeyOf(ResolvedRule.class); ClassifierKey classifier = classifierIid.firstKeyOf(Classifier.class); StringBuilder sb = new StringBuilder(); sb.append(createStringFromCompositeKey(policyRuleGroup.getTenantId().getValue(), policyRuleGroup.getContractId().getValue(), policyRuleGroup.getSubjectName().getValue())) .append(DELIMETER) .append(resolvedRule.getName().getValue()) .append(DELIMETER) .append(classifier.getName().getValue()) .append(DELIMETER) .append(value.get()); return sb.toString(); }
private Uuid getFaasSecurityRulesId(ContractId contractId) { Uuid val = mappedContracts.get(contractId); if (val != null) { return val; } Uuid faasContractId = null; if (FaasPolicyManager.isUUid(contractId.getValue())) { faasContractId = new Uuid(contractId.getValue()); } else { faasContractId = new Uuid(UUID.randomUUID().toString()); } mappedContracts.putIfAbsent(contractId, faasContractId); val = mappedContracts.get(contractId); MappedContractBuilder builder = new MappedContractBuilder(); builder.setFaasSecurityRulesId(val); builder.setGbpContractId(contractId); WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); MappedContract result = builder.build(); wTx.put(LogicalDatastoreType.OPERATIONAL, FaasIidFactory.mappedContractIid(gbpTenantId, contractId), result); if (DataStoreHelper.submitToDs(wTx)) { LOG.debug("Cached in Datastore Mapped Contract {}", result); } else { LOG.error("Couldn't Cache in Datastore Mapped Contract {}", result); } return val; }
private List<SecurityRuleGroup> buildSecurityRuleGroup(Contract contract) { LOG.trace("Start buildSecurityRuleGroup for contract {}", contract.getId().getValue()); List<SecurityRuleGroup> securityRuleGroups = new ArrayList<>(); if (contract.getClause() == null) { LOG.debug("contract {} has no Clause", contract.getId().getValue()); return null; if (clause.getSubjectRefs() == null) { LOG.debug("Clause {} in contract {} has no Subject Ref", clause.getName().getValue(), contract.getId() .getValue()); continue; LOG.warn("Couldn't find in Contract {} the expected subject references", contract.getId().getValue()); continue; LOG.trace("Start Parsing Subject Ref {} in Contract {}", subjectRef, contract.getId().getValue()); for (Subject sub : contract.getSubject()) { if (subjectRef.equals(sub.getName())) { if (subRules == null) { LOG.warn("Subject {} in Contract {} doesn't have rules", subjectRef.getValue(), contract.getId().getValue()); } else { List<SecurityRule> securityRules = getSecurityRules(contract, subjectRef, subRules); LOG.debug("Subject {} in Contract {} has {} rules", subjectRef.getValue(), contract.getId() .getValue(), securityRules.size()); securityRuleGroupBuilder.setSecurityRule(securityRules); .getValue(), subjectRef.getValue(), contract.getId().getValue()); securityRuleGroups.add(securityRuleGroupBuilder.build());
if (dao instanceof Contract) { Contract contract = (Contract) dao; LOG.debug("Contract {} is Created.", contract.getId().getValue()); UlnDatastoreApi.submitSecurityGroupsToDs(initSecurityGroupBuilder(contract).build()); if (entry.getValue() instanceof Contract) { Contract contract = (Contract) entry.getValue(); LOG.debug("Contract {} is Updated.", contract.getId().getValue()); UlnDatastoreApi.submitSecurityGroupsToDs(initSecurityGroupBuilder(contract).build()); LOG.debug("Contract {} is removed.", contract.getId().getValue()); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); Optional<MappedContract> op = DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL,
protected SecurityRuleGroupsBuilder initSecurityGroupBuilder(Contract contract) { LOG.trace("Start initSecurityGroupBuilder"); SecurityRuleGroupsBuilder builder = new SecurityRuleGroupsBuilder(); builder.setUuid(getFaasSecurityRulesId(contract.getId())); builder.setName(new Text(contract.getId().getValue())); if (contract.getDescription() != null) builder.setDescription(new Text("gbp-contract: " + contract.getDescription().getValue())); else builder.setDescription(new Text("gbp-contract")); builder.setTenantId(faasTenantId); builder.setSecurityRuleGroup(buildSecurityRuleGroup(contract)); LOG.trace("Contract {} is mapped to Faas Security Rules {} ", contract.getId().getValue(), builder.getUuid() .getValue()); return builder; }
private List<RuleAction> getActions(Contract contract, List<ActionRef> actionRefs) { LOG.trace("Start Parsing Actions for actionRefs count {} in Contract {}", actionRefs.size(), contract.getId() .getValue()); List<RuleAction> pActions = new ArrayList<>(); for (ActionRef actionRef : actionRefs) { if (actionRef.getName() == null) { LOG.warn("Couldn't find an Action in Contract {} -- ignored Action", contract.getId().getValue()); continue;
for (ClassifierRef classifierRef : classifierRefs) { if (classifierRef.getName() == null) { LOG.warn("Found a Classifer without name in Contract {} ", contract.getId().getValue()); continue;
contractId.getValue(), provEpg.getId().getValue());
contractId.getValue(), provEpg.getId().getValue());