Cleanup the codestyle and project structure.
Change-Id: I6a54daff68a43dda7d31edfddac20657c6651510
Signed-off-by: jensenzhang <hack@jensen-zhang.site>
yang-gen-config
yang-gen-sal
.ensime
+.vscode
private static final Logger LOG = LoggerFactory.getLogger(AltoAutoMapsProvider.class);
- private final DataBroker dataBroker;
- private AltoAutoMapsUpdateListener m_listener;
+ private AltoAutoMapsUpdateListener listener;
public AltoAutoMapsProvider(final DataBroker dataBroker) {
- this.dataBroker = dataBroker;
- this.m_listener = new AltoAutoMapsUpdateListener(dataBroker);
+ this.listener = new AltoAutoMapsUpdateListener(dataBroker);
}
/**
/**
* Method called when the blueprint container is destroyed.
*/
- public void close() {
+ public void close() throws Exception {
+ closeListener();
LOG.info("AltoAutoMapsProvider Closed");
}
+
+ private void closeListener() throws Exception {
+ if (listener != null) {
+ this.listener.close();
+ }
+ }
}
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+
import org.opendaylight.alto.basic.manual.maps.ManualMapsUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
private static final String TOPOLOGY_NAME = "flow:1";
private static final String DEFAULT_AUTO_NETWORKMAP = "default-auto-networkmap";
- private static final String DEFAULT_AUTO_COSTMAP = "default-auto-costmap";
- private static final String DEFAULT_PID = "PID0";
+ // private static final String DEFAULT_AUTO_COSTMAP = "default-auto-costmap";
+ // private static final String DEFAULT_PID = "PID0";
public AltoAutoMapsUpdateListener(final DataBroker dataBroker) {
this.dataBroker = dataBroker;
@Override
public void onDataTreeChanged(Collection<DataTreeModification<Topology>> changes) {
WriteTransaction writeTx = null;
- for (DataTreeModification<Topology> change: changes) {
+ for (DataTreeModification<Topology> change : changes) {
final DataObjectModification<Topology> rootNode = change.getRootNode();
switch (rootNode.getModificationType()) {
case WRITE:
- if (writeTx == null) {
- writeTx = dataBroker.newWriteOnlyTransaction();
- }
-
- if (rootNode.getDataBefore() == null) {
- createDefaultAutoNetworkMap(rootNode.getDataAfter(), writeTx);
- LOG.info("Create default auto networkmap");
- } else {
- updateDefaultAutoNetworkMap(rootNode.getDataAfter(), writeTx);
- LOG.info("Update default auto networkmap");
- }
+ writeTx = handleDataWrite(rootNode, writeTx);
break;
case DELETE:
- if (writeTx == null) {
- writeTx = dataBroker.newWriteOnlyTransaction();
- }
-
- emptyDefaultAutoNetworkMap(writeTx);
+ writeTx = handleDataDelete(writeTx);
LOG.info("Empty default auto networkmap");
break;
default:
}
}
+ private WriteTransaction handleDataWrite(DataObjectModification<Topology> rootNode, WriteTransaction writeTx) {
+ if (writeTx == null) {
+ writeTx = dataBroker.newWriteOnlyTransaction();
+ }
+
+ if (rootNode.getDataBefore() == null) {
+ createDefaultAutoNetworkMap(rootNode.getDataAfter(), writeTx);
+ LOG.info("Create default auto networkmap");
+ } else {
+ updateDefaultAutoNetworkMap(rootNode.getDataAfter(), writeTx);
+ LOG.info("Update default auto networkmap");
+ }
+ return writeTx;
+ }
+
+ private WriteTransaction handleDataDelete(WriteTransaction writeTx) {
+ if (writeTx == null) {
+ writeTx = dataBroker.newWriteOnlyTransaction();
+ }
+
+ emptyDefaultAutoNetworkMap(writeTx);
+ return writeTx;
+ }
+
private void createDefaultAutoNetworkMap(Topology topology, final WriteTransaction wx) {
for (Node node : topology.getNode()) {
HostNode hostNode = node.getAugmentation(HostNode.class);
@Override
public void close() throws Exception {
- registration.close();
+ closeRegistration();
LOG.info("AltoAutoMapsUpdateListener Closed");
}
+
+ private void closeRegistration() {
+ if (registration != null) {
+ registration.close();
+ }
+ }
}
}
public static InstanceIdentifier<ConfigContext> getContextIID(String cid) {
- Uuid _cid = new Uuid(cid);
- return getContextIID(_cid);
+ return getContextIID(new Uuid(cid));
}
public static InstanceIdentifier<ConfigContext> getContextIID(Uuid cid) {
- ConfigContextKey key = new ConfigContextKey(cid);
- return getContextIID(key);
+ return getContextIID(new ConfigContextKey(cid));
}
public static InstanceIdentifier<ConfigContext> getContextIID(ConfigContextKey key) {
}
public static InstanceIdentifier<ResourceNetworkMap> getResourceNetworkMapIID(String cid, String rid) {
- Uuid _cid = new Uuid(cid);
- ResourceId _rid = new ResourceId(rid);
- return getResourceNetworkMapIID(_cid, _rid);
+ return getResourceNetworkMapIID(new Uuid(cid), new ResourceId(rid));
}
public static InstanceIdentifier<ResourceNetworkMap> getResourceNetworkMapIID(Uuid cid, ResourceId rid) {
- ConfigContextKey ckey = new ConfigContextKey(cid);
- ResourceNetworkMapKey rkey = new ResourceNetworkMapKey(rid);
- return getResourceIID(ckey, rkey, ResourceNetworkMap.class);
+ return getResourceIID(new ConfigContextKey(cid), new ResourceNetworkMapKey(rid),
+ ResourceNetworkMap.class);
}
public static InstanceIdentifier<ResourceCostMap> getResourceCostMapIID(String rid) {
}
public static InstanceIdentifier<ResourceCostMap> getResourceCostMapIID(String cid, String rid) {
- Uuid _cid = new Uuid(cid);
- ResourceId _rid = new ResourceId(rid);
- return getResourceCostMapIID(_cid, _rid);
+ return getResourceCostMapIID(new Uuid(cid), new ResourceId(rid));
}
public static InstanceIdentifier<ResourceCostMap> getResourceCostMapIID(Uuid cid, ResourceId rid) {
ConfigContextKey ckey = new ConfigContextKey(cid);
ResourceCostMapKey rkey = new ResourceCostMapKey(rid);
- return getResourceIID(ckey, rkey, ResourceCostMap.class);
+ return getResourceIID(new ConfigContextKey(cid), new ResourceCostMapKey(rid),
+ ResourceCostMap.class);
}
public static <T extends Identifiable<K> & ChildOf<? super ConfigContext>, K extends Identifier<T>>
public static Uuid createContext(Uuid cid, final WriteTransaction wx) {
ConfigContextBuilder builder = new ConfigContextBuilder();
builder.setContextId(cid);
- builder.setResourceNetworkMap(new LinkedList<ResourceNetworkMap>());
- builder.setResourceCostMap(new LinkedList<ResourceCostMap>());
+ builder.setResourceNetworkMap(new LinkedList<>());
+ builder.setResourceCostMap(new LinkedList<>());
wx.put(LogicalDatastoreType.CONFIGURATION, getContextIID(cid), builder.build());
return cid;
List<Map> networkMap,
WriteTransaction wx) {
InstanceIdentifier<ResourceNetworkMap> iid = getResourceNetworkMapIID(rid);
- ResourceNetworkMapBuilder builder = new ResourceNetworkMapBuilder();
- builder.setTag(new Tag(UUID.nameUUIDFromBytes(rid.getBytes()).toString().replaceAll("-", "")));
- builder.setResourceId(new ResourceId(rid));
- builder.setMap(networkMap);
+ ResourceNetworkMapBuilder builder = new ResourceNetworkMapBuilder()
+ .setTag(new Tag(UUID.nameUUIDFromBytes(rid.getBytes())
+ .toString()
+ .replaceAll("-", "")))
+ .setResourceId(new ResourceId(rid))
+ .setMap(networkMap);
wx.put(LogicalDatastoreType.CONFIGURATION, iid, builder.build());
return iid;
}
List<org.opendaylight.yang.gen.v1.urn.alto.manual.maps.costmap.rev151021.cost.map.Map> costMap,
WriteTransaction wx) {
InstanceIdentifier<ResourceCostMap> iid = getResourceCostMapIID(rid);
- ResourceCostMapBuilder builder = new ResourceCostMapBuilder();
- builder.setTag(new Tag(UUID.nameUUIDFromBytes(rid.getBytes()).toString().replaceAll("-", "")));
- builder.setResourceId(new ResourceId(rid));
- builder.setMap(costMap);
- builder.setMeta(meta);
+ ResourceCostMapBuilder builder = new ResourceCostMapBuilder()
+ .setTag(new Tag(UUID.nameUUIDFromBytes(rid.getBytes())
+ .toString()
+ .replaceAll("-", "")))
+ .setResourceId(new ResourceId(rid))
+ .setMap(costMap)
+ .setMeta(meta);
wx.put(LogicalDatastoreType.CONFIGURATION, iid, builder.build());
return iid;
}
deleteResourceNetworkMap(new Uuid(cid), new ResourceId(cid), wx);
}
- public static void deleteResourceNetworkMap(Uuid cid, ResourceId rid, final WriteTransaction wx) {
+ public static void deleteResourceNetworkMap(Uuid cid, ResourceId rid,
+ final WriteTransaction wx) {
wx.delete(LogicalDatastoreType.CONFIGURATION, getResourceNetworkMapIID(cid, rid));
}
import java.util.LinkedList;
import java.util.List;
+import java.util.concurrent.ExecutionException;
+
import org.opendaylight.alto.basic.manual.maps.ManualMapsUtils;
import org.opendaylight.alto.core.northbound.api.AltoNorthboundRoute;
import org.opendaylight.alto.core.northbound.api.AltoNorthboundRouter;
private final BindingAwareBroker.RoutedRpcRegistration<AltoModelNetworkmapService> altoModelNetworkmapService;
private final BindingAwareBroker.RoutedRpcRegistration<AltoModelCostmapService> altoModelCostmapService;
- private AltoNorthboundRouter m_router = null;
- private List<Uuid> m_contexts = null;
+ private List<Uuid> contextList = null;
public AltoManualMapsProvider(DataBroker dataBroker,
AltoNorthboundRouter router,
manualMapsListener.close();
}
- protected void initializeConfigContext() throws Exception {
- m_contexts = new LinkedList<>();
+ protected void initializeConfigContext() throws ExecutionException, InterruptedException {
+ contextList = new LinkedList<>();
WriteTransaction wx = dataBroker.newWriteOnlyTransaction();
- m_contexts.add(ManualMapsUtils.createContext(wx));
+ contextList.add(ManualMapsUtils.createContext(wx));
wx.submit().get();
}
- protected void clearConfigContext() throws Exception {
+ protected void clearConfigContext() throws ExecutionException, InterruptedException {
WriteTransaction wx = dataBroker.newWriteOnlyTransaction();
- for (Uuid context : m_contexts) {
+ for (Uuid context : contextList) {
ManualMapsUtils.deleteContext(context, wx);
}
wx.submit().get();
@Override
public void close() throws Exception {
try {
- if (m_router != null) {
- m_router.removeRoute(RESOURCE_CONFIG_ROUTE_NAME);
+ if (router != null) {
+ router.removeRoute(RESOURCE_CONFIG_ROUTE_NAME);
}
clearConfigContext();
closeListener();
} catch (Exception e) {
- LOG.error("Failed to remove route");
+ LOG.error("Failed to remove route", e);
}
LOG.info("AltoManualMapsProvider Closed");
private void setupRoute() {
AltoNorthboundRoute route = new ManualMapsRoute(this);
- String base_url = router.addRoute(RESOURCE_CONFIG_ROUTE_NAME, route);
- if (base_url == null) {
+ String baseUrl = router.addRoute(RESOURCE_CONFIG_ROUTE_NAME, route);
+ if (baseUrl == null) {
LOG.error("Failed to register route for AltoManualMaps");
return;
}
-
- try {
- m_router = router;
- } catch (Exception e) {
- LOG.error("Failed to reigster route");
- }
}
}
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
+
import org.opendaylight.alto.basic.manual.maps.ManualMapsUtils;
import org.opendaylight.alto.basic.simpleird.SimpleIrdUtils;
import org.opendaylight.alto.core.northbound.route.costmap.AltoNbrCostmapUtils;
private static final Logger LOG = LoggerFactory.getLogger(ManualMapsListener.class);
- private DataBroker m_dataBroker = null;
- private final List<ListenerRegistration<?>> m_regs = new ArrayList<>();;
- private BindingAwareBroker.RoutedRpcRegistration<AltoModelNetworkmapService> m_networkmapServiceReg = null;
- private BindingAwareBroker.RoutedRpcRegistration<AltoModelCostmapService> m_costmapServiceReg = null;
-
- public ManualMapsListener() {
- }
+ private DataBroker dataBroker = null;
+ private final List<ListenerRegistration<?>> listenerRegs = new ArrayList<>();
+ private BindingAwareBroker.RoutedRpcRegistration<AltoModelNetworkmapService> networkmapServiceReg = null;
+ private BindingAwareBroker.RoutedRpcRegistration<AltoModelCostmapService> costmapServiceReg = null;
public void register(DataBroker dataBroker) {
- m_dataBroker = dataBroker;
+ this.dataBroker = dataBroker;
final InstanceIdentifier<ConfigContext> contextListIID = ManualMapsUtils.getContextListIID();
- m_regs.add(m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ listenerRegs.add(dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
LogicalDatastoreType.CONFIGURATION, contextListIID), changes -> onConfigContextChanged(changes)));
- m_regs.add(m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
- LogicalDatastoreType.CONFIGURATION, contextListIID.child(ResourceNetworkMap.class)),
- changes -> onNetworkMapChanged(changes)));
+ listenerRegs.add(dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, contextListIID.child(ResourceNetworkMap.class)),
+ changes -> onNetworkMapChanged(changes)));
- m_regs.add(m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
- LogicalDatastoreType.CONFIGURATION, contextListIID.child(ResourceCostMap.class)),
- changes -> onCostMapChanged(changes)));
+ listenerRegs.add(dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, contextListIID.child(ResourceCostMap.class)),
+ changes -> onCostMapChanged(changes)));
}
public void setNetworkmapServiceReg(BindingAwareBroker.RoutedRpcRegistration<AltoModelNetworkmapService> reg) {
- this.m_networkmapServiceReg = reg;
+ this.networkmapServiceReg = reg;
}
public void setCostmapServiceReg(BindingAwareBroker.RoutedRpcRegistration<AltoModelCostmapService> reg) {
- this.m_costmapServiceReg = reg;
+ this.costmapServiceReg = reg;
}
@Override
public void close() throws Exception {
- for (ListenerRegistration<?> reg: m_regs) {
+ for (ListenerRegistration<?> reg : listenerRegs) {
reg.close();
}
}
private void onConfigContextChanged(Collection<DataTreeModification<ConfigContext>> changes) {
- final ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
+ final ReadWriteTransaction rwx = dataBroker.newReadWriteTransaction();
- for (DataTreeModification<ConfigContext> change: changes) {
+ for (DataTreeModification<ConfigContext> change : changes) {
final DataObjectModification<ConfigContext> rootNode = change.getRootNode();
final InstanceIdentifier<ConfigContext> identifier = change.getRootPath().getRootIdentifier();
switch (rootNode.getModificationType()) {
}
private void onCostMapChanged(Collection<DataTreeModification<ResourceCostMap>> changes) {
- final ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
+ final ReadWriteTransaction rwx = dataBroker.newReadWriteTransaction();
- for (DataTreeModification<ResourceCostMap> change: changes) {
+ for (DataTreeModification<ResourceCostMap> change : changes) {
final DataObjectModification<ResourceCostMap> rootNode = change.getRootNode();
final InstanceIdentifier<ResourceCostMap> identifier = change.getRootPath().getRootIdentifier();
switch (rootNode.getModificationType()) {
case SUBTREE_MODIFIED:
final ResourceCostMap original = rootNode.getDataBefore();
final ResourceCostMap updated = rootNode.getDataAfter();
- if (original == null) {
- createCostMap(updated, identifier, rwx);
- LOG.info("Create new CostMap data into OPERATIONAL");
- } else {
- updateCostMap(original, updated, identifier, rwx);
- LOG.info("Update CostMap data from OPERATIONAL");
- }
+ handleCostMapModified(identifier, original, updated, rwx);
break;
case DELETE:
removeCostMap(identifier, rootNode.getDataBefore(), rwx);
rwx.submit();
}
+ private void handleCostMapModified(InstanceIdentifier<ResourceCostMap> identifier, ResourceCostMap original, ResourceCostMap updated, ReadWriteTransaction rwx) {
+ if (original == null) {
+ createCostMap(updated, identifier, rwx);
+ LOG.info("Create new CostMap data into OPERATIONAL");
+ } else {
+ updateCostMap(original, updated, identifier, rwx);
+ LOG.info("Update CostMap data from OPERATIONAL");
+ }
+ }
+
private void onNetworkMapChanged(Collection<DataTreeModification<ResourceNetworkMap>> changes) {
- final ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
+ final ReadWriteTransaction rwx = dataBroker.newReadWriteTransaction();
- for (DataTreeModification<ResourceNetworkMap> change: changes) {
+ for (DataTreeModification<ResourceNetworkMap> change : changes) {
final DataObjectModification<ResourceNetworkMap> rootNode = change.getRootNode();
final InstanceIdentifier<ResourceNetworkMap> identifier = change.getRootPath().getRootIdentifier();
switch (rootNode.getModificationType()) {
case SUBTREE_MODIFIED:
final ResourceNetworkMap original = rootNode.getDataBefore();
final ResourceNetworkMap updated = rootNode.getDataAfter();
- if (original == null) {
- createNetworkMap(updated, identifier, rwx);
- LOG.info("Create new NetworkMap data into OPERATIONAL");
- } else {
- updateNetworkMap(original, updated, identifier, rwx);
- LOG.info("Update NetworkMap data from OPERATIONAL");
- }
+ handleNetworkMapModified(identifier, original, updated, rwx);
break;
case DELETE:
removeNetworkMap(identifier, rootNode.getDataBefore(), rwx);
rwx.submit();
}
- private <T extends NetworkMap> void updateNetworkMap(T origin, T updated, InstanceIdentifier<T> updatedIID,
- final WriteTransaction wx) {
+ private void handleNetworkMapModified(InstanceIdentifier<ResourceNetworkMap> identifier,
+ ResourceNetworkMap original, ResourceNetworkMap updated, ReadWriteTransaction rwx) {
+ if (original == null) {
+ createNetworkMap(updated, identifier, rwx);
+ LOG.info("Create new NetworkMap data into OPERATIONAL");
+ } else {
+ updateNetworkMap(original, updated, identifier, rwx);
+ LOG.info("Update NetworkMap data from OPERATIONAL");
+ }
+ }
+
+ private <T extends NetworkMap> void createNetworkMap(T created,
+ InstanceIdentifier<T> createdIID, final WriteTransaction wx) {
+ ResourcepoolUtils.createResource(ManualMapsUtils.DEFAULT_CONTEXT,
+ created.getResourceId().getValue(),
+ ResourceTypeNetworkmap.class, wx);
+ ResourcepoolUtils.updateResource(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
+ created.getResourceId(), created.getTag(), null, wx);
+ networkmapServiceReg.registerPath(ServiceContext.class,
+ ResourcepoolUtils.getContextTagIID(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
+ created.getResourceId(), created.getTag()));
+ wx.put(LogicalDatastoreType.OPERATIONAL, createdIID, created);
+
+ String path = created.getResourceId().getValue();
+ AltoNbrNetworkmapUtils.createRecord(path, created.getResourceId(), wx);
+ SimpleIrdUtils.createConfigEntry(AltoNbrNetworkmapUtils.BASE_URL + "/" + path,
+ created.getResourceId(), new Uuid(ManualMapsUtils.DEFAULT_CONTEXT), wx);
+ }
+
+ private <T extends CostMap> void createCostMap(T created, InstanceIdentifier<T> createdIID,
+ final WriteTransaction wx) {
+ ResourcepoolUtils.createResource(ManualMapsUtils.DEFAULT_CONTEXT,
+ created.getResourceId().getValue(),
+ ResourceTypeCostmap.class, wx);
+ List<InstanceIdentifier<?>> dependencies = new LinkedList<>();
+ dependencies.add(
+ ResourcepoolUtils.getContextTagIID(
+ new Uuid(ResourcepoolUtils.DEFAULT_CONTEXT),
+ created.getMeta().getDependentVtags().get(0).getResourceId(),
+ created.getMeta().getDependentVtags().get(0).getTag())
+ );
+ ResourcepoolUtils.updateResource(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
+ created.getResourceId(), created.getTag(), dependencies, wx);
+ costmapServiceReg.registerPath(ServiceContext.class,
+ ResourcepoolUtils.getContextTagIID(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
+ created.getResourceId(), created.getTag()));
+ wx.put(LogicalDatastoreType.OPERATIONAL, createdIID, created);
+
+ String path = created.getResourceId().getValue();
+ AltoNbrCostmapUtils.createRecord(path, created.getResourceId(), wx);
+ SimpleIrdUtils.createConfigEntry(AltoNbrCostmapUtils.BASE_URL + "/" + path,
+ created.getResourceId(), new Uuid(ManualMapsUtils.DEFAULT_CONTEXT), wx);
+ }
+
+ private <T extends NetworkMap> void updateNetworkMap(T origin, T updated,
+ InstanceIdentifier<T> updatedIID, final WriteTransaction wx) {
+ // TODO: origin is unused now
ResourceId rid = updated.getResourceId();
LOG.info("Updating NetworkMap: " + "\n\tResource ID: " + rid.getValue());
createNetworkMap(updated, updatedIID, wx);
}
- private <T extends CostMap> void updateCostMap(T origin, T updated, InstanceIdentifier<T> updatedIID,
- final WriteTransaction wx) {
+ private <T extends CostMap> void updateCostMap(T origin, T updated,
+ InstanceIdentifier<T> updatedIID, final WriteTransaction wx) {
+ // TODO: origin is unused now
ResourceId rid = updated.getResourceId();
LOG.info("Updating CostMap: " + "\n\tResource ID: " + rid.getValue());
createCostMap(updated, updatedIID, wx);
}
- private <T extends NetworkMap> void removeNetworkMap(InstanceIdentifier<T> mapIID, T removed, final WriteTransaction wx) {
+ private <T extends NetworkMap> void removeNetworkMap(InstanceIdentifier<T> mapIID, T removed,
+ final WriteTransaction wx) {
SimpleIrdUtils.deleteConfigEntry(removed.getResourceId(), wx);
String path = removed.getResourceId().getValue();
AltoNbrNetworkmapUtils.deleteRecord(path, wx);
ResourcepoolUtils.deleteResource(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT), removed.getResourceId(), wx);
- m_networkmapServiceReg.unregisterPath(ServiceContext.class,
+ networkmapServiceReg.unregisterPath(ServiceContext.class,
ResourcepoolUtils.getContextTagIID(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
removed.getResourceId(), removed.getTag()));
removeMap(mapIID, wx);
}
- private <T extends CostMap> void removeCostMap(InstanceIdentifier<T> mapIID, T removed, final WriteTransaction wx) {
+ private <T extends CostMap> void removeCostMap(InstanceIdentifier<T> mapIID, T removed,
+ final WriteTransaction wx) {
SimpleIrdUtils.deleteConfigEntry(removed.getResourceId(), wx);
ManualMapsUtils.deleteResourceCostMap(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT), removed.getResourceId(), wx);
- m_costmapServiceReg.unregisterPath(ServiceContext.class,
+ costmapServiceReg.unregisterPath(ServiceContext.class,
ResourcepoolUtils.getContextTagIID(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
removed.getResourceId(), removed.getTag()));
removeMap(mapIID, wx);
}
- private void removeConfigContext(InstanceIdentifier<ConfigContext> iid, ConfigContext removed, final WriteTransaction wx) {
+ private void removeConfigContext(InstanceIdentifier<ConfigContext> iid, ConfigContext removed,
+ final WriteTransaction wx) {
ManualMapsUtils.deleteContext(removed.getContextId(), wx);
removeMap(iid, wx);
// TODO: Consistency with SimpleIrd and NrbRecord
wx.delete(LogicalDatastoreType.OPERATIONAL, mapIID);
}
- private <T extends NetworkMap> void createNetworkMap(T created, InstanceIdentifier<T> createdIID, final WriteTransaction wx) {
- ResourcepoolUtils.createResource(ManualMapsUtils.DEFAULT_CONTEXT,
- created.getResourceId().getValue(),
- ResourceTypeNetworkmap.class, wx);
- ResourcepoolUtils.updateResource(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
- created.getResourceId(), created.getTag(), null, wx);
- m_networkmapServiceReg.registerPath(ServiceContext.class,
- ResourcepoolUtils.getContextTagIID(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
- created.getResourceId(), created.getTag()));
- wx.put(LogicalDatastoreType.OPERATIONAL, createdIID, created);
-
- String path = created.getResourceId().getValue();
- AltoNbrNetworkmapUtils.createRecord(path, created.getResourceId(), wx);
- SimpleIrdUtils.createConfigEntry(AltoNbrNetworkmapUtils.BASE_URL + "/" + path,
- created.getResourceId(), new Uuid(ManualMapsUtils.DEFAULT_CONTEXT), wx);
- }
-
- private <T extends CostMap> void createCostMap(T created, InstanceIdentifier<T> createdIID, final WriteTransaction wx) {
- ResourcepoolUtils.createResource(ManualMapsUtils.DEFAULT_CONTEXT,
- created.getResourceId().getValue(),
- ResourceTypeCostmap.class, wx);
- List<InstanceIdentifier<?>> dependencies = new LinkedList<>();
- dependencies.add(
- ResourcepoolUtils.getContextTagIID(
- new Uuid(ResourcepoolUtils.DEFAULT_CONTEXT),
- created.getMeta().getDependentVtags().get(0).getResourceId(),
- created.getMeta().getDependentVtags().get(0).getTag())
- );
- ResourcepoolUtils.updateResource(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
- created.getResourceId(), created.getTag(), dependencies, wx);
- m_costmapServiceReg.registerPath(ServiceContext.class,
- ResourcepoolUtils.getContextTagIID(new Uuid(ManualMapsUtils.DEFAULT_CONTEXT),
- created.getResourceId(), created.getTag()));
- wx.put(LogicalDatastoreType.OPERATIONAL, createdIID, created);
-
- String path = created.getResourceId().getValue();
- AltoNbrCostmapUtils.createRecord(path, created.getResourceId(), wx);
- SimpleIrdUtils.createConfigEntry(AltoNbrCostmapUtils.BASE_URL + "/" + path,
- created.getResourceId(), new Uuid(ManualMapsUtils.DEFAULT_CONTEXT), wx);
- }
-
private void createConfigContext(ConfigContext created, InstanceIdentifier<ConfigContext> createdIID, final ReadWriteTransaction rwx) {
try {
if (!ResourcepoolUtils.contextExists(created.getContextId(), rwx)) {
ResourcepoolUtils.createContext(created.getContextId(), rwx);
}
} catch (InterruptedException | ExecutionException e) {
+ LOG.error("Fail to create config context!", e);
return;
}
rwx.put(LogicalDatastoreType.OPERATIONAL, createdIID, created);
@Override
protected Cost computeCost(TypedAddressData src, TypedAddressData dst, CostTypeData costType) {
- NumericalBuilder numericalBuilder = new NumericalBuilder();
if (validSourceAndDest(src, dst)) {
if (isAddressEqual(src,dst)) {
- return numericalBuilder.setCost(new BigDecimal(0)).build();
+ return new NumericalBuilder().setCost(new BigDecimal(0)).build();
}
MatchFields matchFields = createMatchField(src,dst);
LinkNode head = routingService.buildRoutePath(matchFields);
if (hasLoop(head, new HashMap<LinkNode, Integer>())) {
return null;
}
- if(costMetric.getValue().toString().equals(new String("hopcount"))){
+ if (costMetric.getValue().toString().equals(new String("hopcount"))) {
log.info("hopcpunt");
Numerical cost = computeHopCountECS(head);
return (cost == null) ? null : cost;
- }else if(costMetric.getValue().toString().equals(new String("routingcost"))){
+ } else if(costMetric.getValue().toString().equals(new String("routingcost"))) {
log.info("routingcost");
-// Numerical cost = computeRoutingcostECS(head);
-// return (cost == null) ? null : cost;
+ // TODO: Any issue?
+ // Numerical cost = computeRoutingcostECS(head);
+ // return (cost == null) ? null : cost;
return null;
- }else if(costMetric.getValue().toString().equals(new String("bandwidth"))){
+ } else if(costMetric.getValue().toString().equals(new String("bandwidth"))) {
log.info("bandwidth");
Numerical cost = computeBandwidthECS(head);
return (cost == null) ? null : cost;
package org.opendaylight.alto.basic.endpointcostservice.impl;
import java.util.concurrent.ExecutionException;
+
import org.opendaylight.alto.core.resourcepool.ResourcepoolUtils;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.Resource;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
-import org.opendaylight.yang.gen.v1.urn.alto.types.rev150921.ResourceId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.AltoModelEndpointcostService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.endpointcost.rev151021.ResourceTypeEndpointcost;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
private static final Logger LOG = LoggerFactory.getLogger(EndpointcostserviceProvider.class);
- private final DataBroker m_dataBroker;
- private final BindingAwareBroker.RoutedRpcRegistration<AltoModelEndpointcostService> m_serviceReg;
- private ListenerRegistration<?> m_listener;
+ private final DataBroker dataBroker;
+ private final BindingAwareBroker.RoutedRpcRegistration<AltoModelEndpointcostService> serviceReg;
+ private ListenerRegistration<?> listenerReg;
private static final String SERVICE_ENDPOINTCOST_NAME = "service-endpointcost";
- private static final ResourceId SERVICE_ENDPOINTCOST_RID = new ResourceId(SERVICE_ENDPOINTCOST_NAME);
- private final InstanceIdentifier<Resource> m_testIID = ResourcepoolUtils.getResourceIID(ResourcepoolUtils.DEFAULT_CONTEXT,
+ // private static final ResourceId SERVICE_ENDPOINTCOST_RID = new ResourceId(SERVICE_ENDPOINTCOST_NAME);
+ private final InstanceIdentifier<Resource> testIID = ResourcepoolUtils.getResourceIID(ResourcepoolUtils.DEFAULT_CONTEXT,
SERVICE_ENDPOINTCOST_NAME);
- public EndpointcostserviceProvider(DataBroker m_dataBroker,
- RoutedRpcRegistration<AltoModelEndpointcostService> m_serviceReg) {
- this.m_dataBroker = m_dataBroker;
- this.m_serviceReg = m_serviceReg;
+ public EndpointcostserviceProvider(DataBroker dataBroker,
+ RoutedRpcRegistration<AltoModelEndpointcostService> serviceReg) {
+ this.dataBroker = dataBroker;
+ this.serviceReg = serviceReg;
}
protected void createContextTag()
throws InterruptedException, ExecutionException, TransactionCommitFailedException {
- WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
+ WriteTransaction wx = dataBroker.newWriteOnlyTransaction();
ResourcepoolUtils.createResourceWithCapabilities(ResourcepoolUtils.DEFAULT_CONTEXT,
SERVICE_ENDPOINTCOST_NAME,
protected void removeContextTag()
throws InterruptedException, ExecutionException, TransactionCommitFailedException {
- WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
+ WriteTransaction wx = dataBroker.newWriteOnlyTransaction();
ResourcepoolUtils.deleteResource(ResourcepoolUtils.DEFAULT_CONTEXT,
SERVICE_ENDPOINTCOST_NAME, wx);
}
protected void setupListener() {
- ResourcepoolUtils.ContextTagListener listener = new ResourcepoolUtils.ContextTagListener(m_testIID, m_serviceReg);
- m_listener = m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
- m_testIID.child(ContextTag.class)), listener);
+ ResourcepoolUtils.ContextTagListener listener = new ResourcepoolUtils.ContextTagListener(testIID, serviceReg);
+ listenerReg = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL,
+ testIID.child(ContextTag.class)), listener);
- assert m_listener != null;
+ assert listenerReg != null;
+ LOG.info("Setup listener for Endpointcostservice successfully!");
}
public void init() {
/**
* @param input is the input of ECS.
- * @return true if input is validate.
+ * @return true if input is valid.
*/
public boolean checkInput(QueryInput input) {
request = (EndpointcostRequest)input.getRequest();
import org.slf4j.LoggerFactory;
public class NetworkFlowCapableNodeImpl implements NetworkFlowCapableNodeService{
- private static final Logger log = LoggerFactory
- .getLogger(NetworkFlowCapableNodeImpl.class);
+ private static final Logger LOG = LoggerFactory.getLogger(NetworkFlowCapableNodeImpl.class);
private DataBroker dataBroker;
private NetworkPortStatisticsService portStatistics;
@Override
public FlowCapableNode getFlowCapableNode(String nodeId) {
- log.info("Reading flow capable node for " + nodeId);
+ LOG.debug("Reading flow capable node for {}", nodeId);
try {
return DataStoreHelper.readOperational(dataBroker,
InstanceIdentifierUtils.flowCapableNode(nodeId));
} catch (ReadDataFailedException e) {
- e.printStackTrace();
+ LOG.info("Error occurs when reading flow capable node!", e);
}
return null;
}
@Override
public FlowCapableNodeConnector getFlowCapableNodeConnector(String tpId) {
- log.info("Reading flow capable node connector for " + tpId);
+ LOG.debug("Reading flow capable node connector for {}", tpId);
try {
return DataStoreHelper.readOperational(dataBroker,
InstanceIdentifierUtils.flowCapableNodeConnector(tpId));
} catch (ReadDataFailedException e) {
- e.printStackTrace();
+ LOG.info("Error occurs when reading flow capable node connector!", e);
}
return null;
}
@Override
public FlowCapableNodeConnectorStatistics getFlowCapableNodeConnectorStatistics(String tpId) {
- log.info("Reading flow capable node connector statistics data for + " + tpId);
+ LOG.debug("Reading flow capable node connector statistics data for {}", tpId);
try {
return DataStoreHelper.readOperational(dataBroker,
InstanceIdentifierUtils.flowCapableNodeConnectorStatisticsData(tpId))
.getFlowCapableNodeConnectorStatistics();
} catch (ReadDataFailedException e) {
- e.printStackTrace();
+ LOG.info("Error occurs when reading flow capable node connector statistics data!", e);
}
return null;
}
FlowCapableNodeConnector nodeConnector = getFlowCapableNodeConnector(tpId);
Long capacity = getCapacity(nodeConnector, readMeter(tpId, meterId));
Long consumedBandwidth = getConsumedBandwidth(tpId, isHalfDuplex(nodeConnector));
- log.info("capacity: " + capacity);
- log.info("consumedBandwidth: " + consumedBandwidth);
+ LOG.info("capacity: " + capacity);
+ LOG.info("consumedBandwidth: " + consumedBandwidth);
if (capacity == null || consumedBandwidth == null) return null;
return capacity - consumedBandwidth;
}
private Long getConsumedBandwidth(String tpId, boolean isHalfDuplex) {
Long transmitted,received;
- if(portStatistics.getCurrentRxSpeed(tpId,NetworkPortStatisticsService.Metric.BITSPERSECOND) != null){
+ if (portStatistics.getCurrentRxSpeed(tpId,NetworkPortStatisticsService.Metric.BITSPERSECOND) != null) {
transmitted = portStatistics.getCurrentTxSpeed(tpId, NetworkPortStatisticsService.Metric.BITSPERSECOND)
/ 1000;
}
else {
transmitted = 0L;
}
- if(portStatistics.getCurrentRxSpeed(tpId, NetworkPortStatisticsService.Metric.BITSPERSECOND) != null){
+ if (portStatistics.getCurrentRxSpeed(tpId, NetworkPortStatisticsService.Metric.BITSPERSECOND) != null) {
received = portStatistics.getCurrentRxSpeed(tpId, NetworkPortStatisticsService.Metric.BITSPERSECOND)
/ 1000;
}
private NetworkFlowCapableNodeService flowCapableNodeService;
private FlowTableMatcher flowTableMatcher = new FlowTableMatcher();
- private List<LinkNode> pathStack = new ArrayList<LinkNode>();
- private Map<String, LinkNode> visitedInPort = new HashMap<String, LinkNode>();
+ private List<LinkNode> pathStack = new ArrayList<>();
+ private Map<String, LinkNode> visitedInPort = new HashMap<>();
public RoutingServiceImpl(NetworkElementService networkService) {
this.linkService = networkService.getLinkService();
private static final Logger LOG = LoggerFactory.getLogger(AltoSimpleIrdProvider.class);
- private final DataBroker m_dataBroker;
+ private final DataBroker dataBroker;
- InstanceIdentifier<IrdInstanceConfiguration> m_iid = null;
- InstanceIdentifier<IrdInstance> m_rootIID = null;
+ InstanceIdentifier<IrdInstanceConfiguration> iid = null;
+ InstanceIdentifier<IrdInstance> rootIid = null;
- private String m_context = null;
- private SimpleIrdListener m_listener = null;
- private AltoNorthboundRouter m_router = null;
- private AltoNorthboundRoute m_route = null;
+ private String context = null;
+ private SimpleIrdListener listener = null;
+ private AltoNorthboundRouter router = null;
protected void createContext() throws InterruptedException, ExecutionException {
- WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
+ WriteTransaction wx = dataBroker.newWriteOnlyTransaction();
- m_context = ResourcepoolUtils.getUUID(SIMPLE_IRD_ROUTE_NAME);
- ResourcepoolUtils.createContext(m_context, wx);
+ context = ResourcepoolUtils.getUUID(SIMPLE_IRD_ROUTE_NAME);
+ ResourcepoolUtils.createContext(context, wx);
InformationBuilder builder = new InformationBuilder();
- builder.setContextId(new Uuid(m_context));
+ builder.setContextId(new Uuid(context));
InstanceIdentifier<Information> infoIID;
infoIID = InstanceIdentifier.builder(Information.class).build();
wx.put(LogicalDatastoreType.OPERATIONAL, infoIID, builder.build());
wx.submit().get();
- LOG.info("Registered context {} for SimpleIrd", m_context);
+ LOG.info("Registered context {} for SimpleIrd", context);
}
protected void setupListener() {
- m_listener = new SimpleIrdListener(new Uuid(m_context));
- m_listener.register(m_dataBroker, m_iid);
+ listener = new SimpleIrdListener(new Uuid(context));
+ listener.register(dataBroker, iid);
}
protected void createDefaultIrd() throws InterruptedException, ExecutionException {
- WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
+ WriteTransaction wx = dataBroker.newWriteOnlyTransaction();
IrdInstanceConfigurationBuilder builder = new IrdInstanceConfigurationBuilder();
builder.setEntryContext(ResourcepoolUtils.getDefaultContextIID())
}
protected void deleteContext() throws InterruptedException, ExecutionException {
- WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
- ResourcepoolUtils.deleteContext(m_context, wx);
+ WriteTransaction wx = dataBroker.newWriteOnlyTransaction();
+ ResourcepoolUtils.deleteContext(context, wx);
wx.submit().get();
}
protected void closeListener() throws Exception {
- if (m_listener != null) {
- m_listener.close();
+ if (listener != null) {
+ listener.close();
}
}
public AltoSimpleIrdProvider(final DataBroker dataBroker, final AltoNorthboundRouter router) {
- this.m_dataBroker = dataBroker;
- this.m_router = router;
+ this.dataBroker = dataBroker;
+ this.router = router;
}
/**
* Method called when the blueprint container is created.
*/
public void init() {
- m_iid = SimpleIrdUtils.getInstanceConfigurationListIID();
- m_rootIID = SimpleIrdUtils.getInstanceIID(ROOT_INSTANCE);
+ iid = SimpleIrdUtils.getInstanceConfigurationListIID();
+ rootIid = SimpleIrdUtils.getInstanceIID(ROOT_INSTANCE);
try {
createContext();
setupListener();
createDefaultIrd();
- setupRoute(m_router);
+ setupRoute(router);
} catch (Exception e) {
LOG.error("Failed to create top-level containers");
e.printStackTrace();
*/
public void close() {
try {
- if (m_router != null) {
- m_router.removeRoute(SIMPLE_IRD_ROUTE_NAME);
+ if (router != null) {
+ router.removeRoute(SIMPLE_IRD_ROUTE_NAME);
}
closeListener();
}
IrdInstance getInstance(ResourceId rid) {
- ReadTransaction rx = m_dataBroker.newReadOnlyTransaction();
+ ReadTransaction rx = dataBroker.newReadOnlyTransaction();
try {
return SimpleIrdUtils.readInstance(rid, rx);
}
try {
- WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
+ WriteTransaction wx = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<Information> infoIID;
infoIID = InstanceIdentifier.builder(Information.class).build();
wx.merge(LogicalDatastoreType.OPERATIONAL, infoIID, builder.build());
wx.submit().get();
-
- m_route = route;
} catch (Exception e) {
LOG.error("Failed to reigster route");
}
private static final Logger LOG = LoggerFactory.getLogger(SimpleIrdEntryListener.class);
- private DataBroker m_dataBroker = null;
- private ListenerRegistration<?> m_reg = null;
- private InstanceIdentifier<IrdConfigurationEntry> m_iid = null;
+ private DataBroker dataBroker = null;
+ private ListenerRegistration<?> listenerReg = null;
+ private InstanceIdentifier<IrdConfigurationEntry> irdConfigEntryIid = null;
- private Uuid m_context = null;
- private ResourceId m_resource = null;
+ private Uuid context = null;
+ private ResourceId resourceId = null;
- private Uuid m_entryContext = null;
+ private Uuid entryContext = null;
public SimpleIrdEntryListener(InstanceIdentifier<Resource> instance, Uuid entryContext) {
- m_context = instance.firstKeyOf(Context.class).getContextId();
- m_resource = instance.firstKeyOf(Resource.class).getResourceId();
- m_entryContext = entryContext;
+ context = instance.firstKeyOf(Context.class).getContextId();
+ resourceId = instance.firstKeyOf(Resource.class).getResourceId();
+ this.entryContext = entryContext;
}
public void register(DataBroker dataBroker, InstanceIdentifier<IrdConfigurationEntry> iid) {
- m_dataBroker = dataBroker;
- m_iid = iid;
+ this.dataBroker = dataBroker;
+ irdConfigEntryIid = iid;
- m_reg = m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
- LogicalDatastoreType.CONFIGURATION, m_iid), this);
+ listenerReg = dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, irdConfigEntryIid), this);
LOG.info("SimpleIrdEntryListener registered");
}
protected boolean isAcceptableContext(Uuid context) {
- if (m_entryContext.equals(context) || m_context.equals(context)) {
+ if (entryContext.equals(context) || this.context.equals(context)) {
return true;
}
return false;
protected Future<Optional<Resource>> getValidResource(ResourceId rid,
InstanceIdentifier<Resource> iid,
ReadTransaction rx) {
- ContextKey contextKey = new ContextKey(m_context);
- ContextKey entryContextKey = new ContextKey(m_entryContext);
+ ContextKey contextKey = new ContextKey(context);
+ ContextKey entryContextKey = new ContextKey(entryContext);
ResourceKey resourceKey = new ResourceKey(rid);
ContextKey iidContextKey = iid.firstKeyOf(Context.class);
* We examine the dependencies and check whether the services are self-contained
*/
- ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction();
+ ReadWriteTransaction rwx = dataBroker.newReadWriteTransaction();
- InstanceIdentifier<IrdInstanceConfiguration> configIID = SimpleIrdUtils.getInstanceConfigurationIID(m_resource);
+ InstanceIdentifier<IrdInstanceConfiguration> configIID = SimpleIrdUtils.getInstanceConfigurationIID(
+ resourceId);
Optional<IrdInstanceConfiguration> config;
try {
return;
}
- LOG.info("Finished reading data for {}", m_resource.getValue());
+ LOG.info("Finished reading data for {}", resourceId.getValue());
if (config.isPresent()) {
IrdInstanceConfiguration cfg = config.get();
builder.fieldsFrom(cfg);
builder.setIrdEntry(entries);
- InstanceIdentifier<IrdInstance> iid = SimpleIrdUtils.getInstanceIID(m_resource);
+ InstanceIdentifier<IrdInstance> iid = SimpleIrdUtils.getInstanceIID(resourceId);
rwx.put(LogicalDatastoreType.OPERATIONAL, iid, builder.build());
- ResourcepoolUtils.updateResource(m_context, m_resource, dependencies, rwx);
+ ResourcepoolUtils.updateResource(context, resourceId, dependencies, rwx);
}
protected void cleanupIrdInstance(IrdInstanceConfiguration cfg,
rwx.put(LogicalDatastoreType.OPERATIONAL, iid, builder.build());
- ResourcepoolUtils.updateResource(m_context, m_resource, null, rwx);
+ ResourcepoolUtils.updateResource(context, resourceId, null, rwx);
}
@Override
public synchronized void close() throws Exception {
try {
- if (m_reg != null) {
- m_reg.close();
+ if (listenerReg != null) {
+ listenerReg.close();
}
} catch (Exception e) {
LOG.info("Error while closing the registration");
private static final Logger LOG = LoggerFactory.getLogger(SimpleIrdListener.class);
- private DataBroker m_dataBroker = null;
- private ListenerRegistration<?> m_reg = null;
- private InstanceIdentifier<IrdInstanceConfiguration> m_iid = null;
- private Uuid m_context = null;
+ private DataBroker mDataBroker = null;
+ private ListenerRegistration<?> mReg = null;
+ private InstanceIdentifier<IrdInstanceConfiguration> mIID = null;
+ private Uuid mContext = null;
- private Map<ResourceId, SimpleIrdEntryListener> m_listeners = null;
- private Map<ResourceId, SimpleIrdRfc7285DefaultNetworkMapListener> m_rfcListeners = null;
- private Map<ResourceId, SimpleIrdRfc7285CostTypeListener> m_ctListeners = null;
+ private Map<ResourceId, SimpleIrdEntryListener> mListeners = null;
+ private Map<ResourceId, SimpleIrdRfc7285DefaultNetworkMapListener> mRfcListeners = null;
+ private Map<ResourceId, SimpleIrdRfc7285CostTypeListener> mCostTypeListeners = null;
public SimpleIrdListener(Uuid context) {
- m_listeners = new HashMap<>();
- m_rfcListeners = new HashMap<>();
- m_ctListeners = new HashMap<>();
- m_context = context;
+ mListeners = new HashMap<>();
+ mRfcListeners = new HashMap<>();
+ mCostTypeListeners = new HashMap<>();
+ mContext = context;
}
public void register(DataBroker dataBroker, InstanceIdentifier<IrdInstanceConfiguration> iid) {
- m_dataBroker = dataBroker;
- m_iid = iid;
+ mDataBroker = dataBroker;
+ mIID = iid;
- m_reg = m_dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
- LogicalDatastoreType.CONFIGURATION, m_iid), this);
+ mReg = mDataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(
+ LogicalDatastoreType.CONFIGURATION, mIID), this);
LOG.info("SimpleIrdListener registered");
}
*
*/
- WriteTransaction wx = m_dataBroker.newWriteOnlyTransaction();
+ WriteTransaction wx = mDataBroker.newWriteOnlyTransaction();
for (DataTreeModification<IrdInstanceConfiguration> change: changes) {
final DataObjectModification<IrdInstanceConfiguration> rootNode = change.getRootNode();
case SUBTREE_MODIFIED:
final IrdInstanceConfiguration original = rootNode.getDataBefore();
final IrdInstanceConfiguration updated = rootNode.getDataAfter();
- if (original == null) {
- createIrd(updated, wx);
- } else {
- updateIrd(original, updated, wx);
- }
+ handleSubtreeModefication(original, updated, wx);
break;
case DELETE:
removeIrd(rootNode.getDataBefore(), wx);
wx.submit();
}
+ protected void handleSubtreeModefication(IrdInstanceConfiguration original,
+ IrdInstanceConfiguration updated, WriteTransaction wx) {
+ if (original == null) {
+ createIrd(updated, wx);
+ } else {
+ updateIrd(original, updated, wx);
+ }
+ }
+
protected void updateIrd(IrdInstanceConfiguration original,
IrdInstanceConfiguration updated, WriteTransaction wx) {
ResourceId rid = updated.getInstanceId();
LOG.info("Updating Ird: " + "\n\tResource ID: " + rid.getValue());
- SimpleIrdEntryListener listener = m_listeners.get(rid);
+ SimpleIrdEntryListener listener = mListeners.get(rid);
if (listener != null) {
if (original.getEntryContext().equals(updated.getEntryContext())) {
// Changes in resources is managed by another listener
LOG.info("Removing Ird: " + "\n\tResource ID: " + rid.getValue());
- SimpleIrdEntryListener listener = m_listeners.get(rid);
+ SimpleIrdEntryListener listener = mListeners.get(rid);
if (listener == null) {
LOG.error("{} is not a valid Ird instance", rid.getValue());
return;
}
- m_listeners.remove(rid);
+ mListeners.remove(rid);
- SimpleIrdRfc7285DefaultNetworkMapListener rfcListener = m_rfcListeners.get(rid);
- m_rfcListeners.remove(rid);
+ SimpleIrdRfc7285DefaultNetworkMapListener rfcListener = mRfcListeners.get(rid);
+ mRfcListeners.remove(rid);
- SimpleIrdRfc7285CostTypeListener ctListener = m_ctListeners.get(rid);
- m_ctListeners.remove(rid);
+ SimpleIrdRfc7285CostTypeListener ctListener = mCostTypeListeners.get(rid);
+ mCostTypeListeners.remove(rid);
try {
listener.close();
rfcListener.close();
ctListener.close();
} catch (Exception e) {
- LOG.error("Error while closing listener");
+ LOG.error("Error while closing listener", e);
}
- ResourcepoolUtils.deleteResource(m_context, rid, wx);
+ ResourcepoolUtils.deleteResource(mContext, rid, wx);
InstanceIdentifier<IrdInstance> iid = SimpleIrdUtils.getInstanceIID(rid);
wx.delete(LogicalDatastoreType.OPERATIONAL, iid);
ContextKey key = entryContextIID.firstKeyOf(Context.class);
if (key == null) {
LOG.error("Failed to create Ird: The entry-context must point to a certain context");
+ return;
}
Uuid entryContext = key.getContextId();
wx.put(LogicalDatastoreType.OPERATIONAL, iid, builder.build());
- ResourcepoolUtils.createResource(m_context, rid, ResourceTypeIrd.class, wx);
- ResourcepoolUtils.lazyUpdateResource(m_context, rid, wx);
+ ResourcepoolUtils.createResource(mContext, rid, ResourceTypeIrd.class, wx);
+ ResourcepoolUtils.lazyUpdateResource(mContext, rid, wx);
- InstanceIdentifier<Resource> resourceIID = ResourcepoolUtils.getResourceIID(m_context, rid);
+ InstanceIdentifier<Resource> resourceIID = ResourcepoolUtils.getResourceIID(mContext, rid);
SimpleIrdEntryListener listener;
listener = new SimpleIrdEntryListener(resourceIID, entryContext);
- listener.register(m_dataBroker, SimpleIrdUtils.getConfigEntryListIID(rid));
- m_listeners.put(rid, listener);
+ listener.register(mDataBroker, SimpleIrdUtils.getConfigEntryListIID(rid));
+ mListeners.put(rid, listener);
SimpleIrdRfc7285DefaultNetworkMapListener rfcListener;
rfcListener = new SimpleIrdRfc7285DefaultNetworkMapListener();
- rfcListener.register(m_dataBroker, rid);
- m_rfcListeners.put(rid, rfcListener);
+ rfcListener.register(mDataBroker, rid);
+ mRfcListeners.put(rid, rfcListener);
SimpleIrdRfc7285CostTypeListener ctListener;
ctListener = new SimpleIrdRfc7285CostTypeListener();
- ctListener.register(m_dataBroker, rid);
- m_ctListeners.put(rid, ctListener);
+ ctListener.register(mDataBroker, rid);
+ mCostTypeListeners.put(rid, ctListener);
}
@Override
public synchronized void close() throws Exception {
try {
- if (m_reg != null) {
- m_reg.close();
+ if (mReg != null) {
+ mReg.close();
}
} catch (Exception e) {
- LOG.info("Error while closing the registration");
+ LOG.info("Error while closing the registration", e);
}
try {
- for (SimpleIrdEntryListener listener: m_listeners.values()) {
+ for (SimpleIrdEntryListener listener: mListeners.values()) {
listener.close();
}
- m_listeners.clear();
+ mListeners.clear();
} catch (Exception e) {
- LOG.info("Error while closing the registration");
+ LOG.info("Error while closing the registration", e);
}
LOG.info("SimpleIrdListener closed");
}
public static final String ALTO_IRD = "application/alto-directory+json";
- private AltoSimpleIrdProvider m_provider = null;
+ private AltoSimpleIrdProvider provider = null;
public SimpleIrdRoute(AltoSimpleIrdProvider provider) {
- m_provider = provider;
+ this.provider = provider;
}
@Path("{path:.+}")
@GET
@Produces({ALTO_IRD, ALTO_ERROR})
public Response route(@Context HttpServletRequest req, @PathParam("path") String path) {
- if (m_provider == null) {
+ if (provider == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
- IrdInstance ird = m_provider.getInstance(new ResourceId(path));
+ IrdInstance ird = provider.getInstance(new ResourceId(path));
if (ird == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
public class RFC7285VersionTag {
+ private final static char ILLEGAL = '$';
+
@JsonProperty("resource-id")
public String rid;
return (rid == null) || (tag == null) || (rid == "") || (tag == "");
}
- private static char ILLEGAL = '$';
-
@Override
public int hashCode() {
return (rid + ILLEGAL + tag).hashCode();
@Override
public boolean equals(Object obj) {
- if (this == obj)
- return true;
if (obj == null)
return false;
+ if (this.getClass() != obj.getClass())
+ return false;
+
+ if (this == obj)
+ return true;
+
RFC7285VersionTag other = (RFC7285VersionTag)obj;
- boolean _rid = (rid == null ? (other.rid == null) : rid.equals(other.rid));
- boolean _tag = (tag == null ? (other.tag == null) : tag.equals(other.tag));
- return (_rid && _tag);
+ boolean ridTest = (rid == null ? (other.rid == null) : rid.equals(other.rid));
+ boolean tagTest = (tag == null ? (other.tag == null) : tag.equals(other.tag));
+ return (ridTest && tagTest);
}
}
--- /dev/null
+We are going to replace the northbound-route by Swagger/OpenAPI specification
+in the next release.
private DataBroker dataBroker = null;
- private AltoNorthboundRouter m_router = null;
+ private AltoNorthboundRouter router = null;
+
+ private static AltoModelCostmapService mapService = null;
- private static AltoModelCostmapService mapService = null;
public void setDataBroker(DataBroker dataBroker) {
this.dataBroker = dataBroker;
}
}
public void register(AltoNorthboundRouter router) {
- m_router = router;
- m_router.addRoute("costmap", new AltoNorthboundRouteCostmap());
+ this.router = router;
+ this.router.addRoute(COSTMAP_ROUTE, new AltoNorthboundRouteCostmap());
}
public void close() {
- m_router.removeRoute("costmap");
+ router.removeRoute(COSTMAP_ROUTE);
}
@Path("{path}")
odl:use-default-for-reference-types="true">
<odl:rpc-service id='altoModelCostmapService'
interface='org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.model.costmap.rev151021.AltoModelCostmapService' />
- <reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
<bean id="provider"
class="org.opendaylight.alto.core.northbound.route.costmap.impl.AltoNorthboundRouteCostmap"
init-method="init" destroy-method="close">
<property name='mapService' ref='altoModelCostmapService' />
- <property name="dataBroker" ref="dataBroker" />
</bean>
</blueprint>