SimpleIrdEntryListener implements AutoCloseable, DataTreeChangeListener<IrdConfigurationEntry> { protected void updateIrdInstance(IrdInstanceConfiguration cfg, Map<IrdConfigurationEntry, Resource> resources, Map<ResourceId, List<ResourceId>> dependencyMap, ReadWriteTransaction rwx) { List<IrdEntry> entries = new LinkedList<>(); List<InstanceIdentifier<?>> dependencies = new LinkedList(); for (Map.Entry<IrdConfigurationEntry, Resource> entry: resources.entrySet()) { IrdConfigurationEntry config = entry.getKey(); Resource resource = entry.getValue(); IrdEntryBuilder entryBuilder = new IrdEntryBuilder(); entryBuilder.fieldsFrom(config); entryBuilder.setUses(dependencyMap.get(config.getEntryId())); if (resource.getType().equals(ResourceTypeIrd.class)) { entryBuilder.setMediaType(SimpleIrdRoute.ALTO_IRD); } else if (resource.getType().equals(ResourceTypeNetworkmap.class)) { entryBuilder.setMediaType("application/alto-networkmap+json"); } else if (resource.getType().equals(ResourceTypeFilteredNetworkmap.class)) { entryBuilder.setAccepts("application/alto-networkmapfilter+json"); entryBuilder.setMediaType("application/alto-networkmap+json"); } else if (resource.getType().equals(ResourceTypeEndpointcost.class)) { entryBuilder.setAccepts("application/alto-endpointcostparams+json"); entryBuilder.setMediaType("application/alto-endpointcost+json"); } else if (resource.getType().equals(ResourceTypeCostmap.class)) { entryBuilder.setMediaType("application/alto-costmap+json"); } else if (resource.getType().equals(ResourceTypeFilteredCostmap.class)) { entryBuilder.setAccepts("application/alto-costmapfilter+json"); entryBuilder.setMediaType("application/alto-costmap+json"); } else { LOG.warn("Haven't implemented yet, skipping"); continue; } entries.add(entryBuilder.build()); InstanceIdentifier<Resource> resourceIID; InstanceIdentifier<ContextTag> dependencyIID; ContextTagKey key = new ContextTagKey(resource.getDefaultTag()); resourceIID = (InstanceIdentifier<Resource>)config.getInstance(); dependencyIID = resourceIID.child(ContextTag.class, key); dependencies.add(dependencyIID); } IrdInstanceBuilder builder = new IrdInstanceBuilder(); builder.fieldsFrom(cfg); builder.setIrdEntry(entries); InstanceIdentifier<IrdInstance> iid = SimpleIrdUtils.getInstanceIID(resourceId); rwx.put(LogicalDatastoreType.OPERATIONAL, iid, builder.build()); ResourcepoolUtils.updateResource(context, resourceId, dependencies, rwx); } SimpleIrdEntryListener(InstanceIdentifier<Resource> instance, Uuid entryContext); void register(DataBroker dataBroker, InstanceIdentifier<IrdConfigurationEntry> iid); @Override synchronized void onDataTreeChanged(Collection<DataTreeModification<IrdConfigurationEntry>> changes); @Override synchronized void close();  }
@Test public void updateIrdInstance() throws Exception { IrdInstanceConfigurationBuilder iicb = new IrdInstanceConfigurationBuilder(); Map<IrdConfigurationEntry, Resource> resources = new HashMap<>(); ContextKey ck = new ContextKey(new Uuid(DEFAULT_CONTEXT_UUID)); ResourceKey ik = new ResourceKey(new ResourceId("FIRST_INSTANCE")); InstanceIdentifier<Resource> instanceIID = InstanceIdentifier.builder(Context.class, ck) .child(Resource.class, ik).build(); IrdConfigurationEntryBuilder iceb = new IrdConfigurationEntryBuilder() .setEntryId(new ResourceId("test-ird-configuration-entry")) .setInstance(instanceIID); ResourceBuilder rb = new ResourceBuilder() .setKey(new ResourceKey(new ResourceId("test-resource-id"))) .setType(ResourceTypeIrd.class); resources.put(iceb.build(), rb.build()); rb.setType(ResourceTypeNetworkmap.class); resources.put(iceb.build(), rb.build()); rb.setType(ResourceTypeFilteredNetworkmap.class); resources.put(iceb.build(), rb.build()); rb.setType(ResourceTypeEndpointcost.class); resources.put(iceb.build(), rb.build()); rb.setType(ResourceTypeFilteredCostmap.class); resources.put(iceb.build(), rb.build()); Map<ResourceId, List<ResourceId>> dependencyMap = new HashMap<>(); simpleIrdEntryListener.updateIrdInstance(iicb.build(), resources, dependencyMap, rwx); }