@Test public void testUpdateTenant_nullTenant() throws Exception { Tenant tenant = new TenantBuilder().setId(TENANT_ID_1).build(); InstanceIdentifier<Tenant> tenantIid = IidFactory.tenantIid(TENANT_ID_1); WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.OPERATIONAL, tenantIid, tenant); policyResolver.updateTenant(TENANT_ID_1, null); ReadOnlyTransaction rTx = getDataBroker().newReadOnlyTransaction(); Optional<Tenant> potentialTenant = rTx.read(LogicalDatastoreType.OPERATIONAL, tenantIid).get(); Assert.assertFalse(potentialTenant.isPresent()); }
@VisibleForTesting void updateTenant(final TenantId tenantId, final Tenant unresolvedTenant) { if (dataProvider == null) { LOG.error("Tenant {} will not be resolved because because dataProvider is NULL", tenantId.getValue()); return; } if (unresolvedTenant == null) { LOG.info("Tenant {} not found in CONF; check&delete from OPER", tenantId); resolvedTenants.remove(tenantId); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), rwTx); updateResolvedPolicy(rwTx); if (DataStoreHelper.submitToDs(rwTx)) { LOG.debug("Removed resolved tenant {} and wrote resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to remove resolved tenant {} and to write resolved policies to Datastore.", tenantId.getValue()); } } else { LOG.debug("Resolving of tenant inheritance and policy triggered by a change in tenant {}", tenantId); Tenant resolvedTenant = InheritanceUtils.resolveTenant(unresolvedTenant); if (isPolicyValid(resolvedTenant.getPolicy())) { resolvedTenants.put(tenantId, new IndexedTenant(resolvedTenant)); WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), resolvedTenant, true); updateResolvedPolicy(wTx); if (DataStoreHelper.submitToDs(wTx)) { LOG.debug("Wrote resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to write resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } } } }
PolicyResolver implements PolicyValidatorRegistry, AutoCloseable { @VisibleForTesting void updateTenant(final TenantId tenantId, final Tenant unresolvedTenant) { if (dataProvider == null) { LOG.error("Tenant {} will not be resolved because because dataProvider is NULL", tenantId.getValue()); return; } if (unresolvedTenant == null) { LOG.info("Tenant {} not found in CONF; check&delete from OPER", tenantId); resolvedTenants.remove(tenantId); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), rwTx); updateResolvedPolicy(rwTx); if (DataStoreHelper.submitToDs(rwTx)) { LOG.debug("Removed resolved tenant {} and wrote resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to remove resolved tenant {} and to write resolved policies to Datastore.", tenantId.getValue()); } } else { LOG.debug("Resolving of tenant inheritance and policy triggered by a change in tenant {}", tenantId); Tenant resolvedTenant = InheritanceUtils.resolveTenant(unresolvedTenant); if (isPolicyValid(resolvedTenant.getPolicy())) { resolvedTenants.put(tenantId, new IndexedTenant(resolvedTenant)); WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), resolvedTenant, true); updateResolvedPolicy(wTx); if (DataStoreHelper.submitToDs(wTx)) { LOG.debug("Wrote resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to write resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } } } } }
PolicyResolver implements PolicyValidatorRegistry, AutoCloseable { @VisibleForTesting void updateTenant(final TenantId tenantId, final Tenant unresolvedTenant) { if (dataProvider == null) { LOG.error("Tenant {} will not be resolved because because dataProvider is NULL", tenantId.getValue()); return; } if (unresolvedTenant == null) { LOG.info("Tenant {} not found in CONF; check&delete from OPER", tenantId); resolvedTenants.remove(tenantId); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), rwTx); updateResolvedPolicy(rwTx); if (DataStoreHelper.submitToDs(rwTx)) { LOG.debug("Removed resolved tenant {} and wrote resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to remove resolved tenant {} and to write resolved policies to Datastore.", tenantId.getValue()); } } else { LOG.debug("Resolving of tenant inheritance and policy triggered by a change in tenant {}", tenantId); Tenant resolvedTenant = InheritanceUtils.resolveTenant(unresolvedTenant); if (isPolicyValid(resolvedTenant.getPolicy())) { resolvedTenants.put(tenantId, new IndexedTenant(resolvedTenant)); WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), resolvedTenant, true); updateResolvedPolicy(wTx); if (DataStoreHelper.submitToDs(wTx)) { LOG.debug("Wrote resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to write resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } } } } PolicyResolver(DataBroker dataProvider); }
PolicyResolver implements PolicyValidatorRegistry, AutoCloseable { @VisibleForTesting void updateTenant(final TenantId tenantId, final Tenant unresolvedTenant) { if (dataProvider == null) { LOG.error("Tenant {} will not be resolved because because dataProvider is NULL", tenantId.getValue()); return; } if (unresolvedTenant == null) { LOG.info("Tenant {} not found in CONF; check&delete from OPER", tenantId); resolvedTenants.remove(tenantId); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), rwTx); updateResolvedPolicy(rwTx); if (DataStoreHelper.submitToDs(rwTx)) { LOG.debug("Removed resolved tenant {} and wrote resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to remove resolved tenant {} and to write resolved policies to Datastore.", tenantId.getValue()); } } else { LOG.debug("Resolving of tenant inheritance and policy triggered by a change in tenant {}", tenantId); Tenant resolvedTenant = InheritanceUtils.resolveTenant(unresolvedTenant); if (isPolicyValid(resolvedTenant.getPolicy())) { resolvedTenants.put(tenantId, new IndexedTenant(resolvedTenant)); WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), resolvedTenant, true); updateResolvedPolicy(wTx); if (DataStoreHelper.submitToDs(wTx)) { LOG.debug("Wrote resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to write resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } } } } PolicyResolver(DataBroker dataProvider); @Override void close(); @Override void register(ActionDefinitionId actionDefinitionId, Validator<ActionInstance> validator); @Override void unregister(ActionDefinitionId actionDefinitionId, Validator<ActionInstance> validator); @Override void register(ClassifierDefinitionId classifierDefinitionId, Validator<ClassifierInstance> validator); @Override void unregister(ClassifierDefinitionId classifierDefinitionId, Validator<ClassifierInstance> validator); }
PolicyResolver implements PolicyValidatorRegistry, AutoCloseable { @VisibleForTesting void updateTenant(final TenantId tenantId, final Tenant unresolvedTenant) { if (dataProvider == null) { LOG.error("Tenant {} will not be resolved because because dataProvider is NULL", tenantId.getValue()); return; } if (unresolvedTenant == null) { LOG.info("Tenant {} not found in CONF; check&delete from OPER", tenantId); resolvedTenants.remove(tenantId); ReadWriteTransaction rwTx = dataProvider.newReadWriteTransaction(); DataStoreHelper.removeIfExists(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), rwTx); updateResolvedPolicy(rwTx); if (DataStoreHelper.submitToDs(rwTx)) { LOG.debug("Removed resolved tenant {} and wrote resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to remove resolved tenant {} and to write resolved policies to Datastore.", tenantId.getValue()); } } else { LOG.debug("Resolving of tenant inheritance and policy triggered by a change in tenant {}", tenantId); Tenant resolvedTenant = InheritanceUtils.resolveTenant(unresolvedTenant); if (isPolicyValid(resolvedTenant.getPolicy())) { resolvedTenants.put(tenantId, new IndexedTenant(resolvedTenant)); WriteTransaction wTx = dataProvider.newWriteOnlyTransaction(); wTx.put(LogicalDatastoreType.OPERATIONAL, IidFactory.tenantIid(tenantId), resolvedTenant, true); updateResolvedPolicy(wTx); if (DataStoreHelper.submitToDs(wTx)) { LOG.debug("Wrote resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } else { LOG.error("Failed to write resolved tenant {} and resolved policies to Datastore.", tenantId.getValue()); } } } } PolicyResolver(DataBroker dataProvider); @Override void close(); @Override void register(ActionDefinitionId actionDefinitionId, Validator<ActionInstance> validator); @Override void unregister(ActionDefinitionId actionDefinitionId, Validator<ActionInstance> validator); @Override void register(ClassifierDefinitionId classifierDefinitionId, Validator<ClassifierInstance> validator); @Override void unregister(ClassifierDefinitionId classifierDefinitionId, Validator<ClassifierInstance> validator);  }