public interface AltoNorthboundRoute {
- public static final String ALTO_ERROR = "application/alto-error+json";
+ String ALTO_ERROR = "application/alto-error+json";
}
/*
* @return The relative path of the route if successful or null if failing */
- public String addRoute(String routeName, AltoNorthboundRoute route);
+ String addRoute(String routeName, AltoNorthboundRoute route);
- public void removeRoute(String routeName);
+ void removeRoute(String routeName);
- public AltoNorthboundRoute getRoute(String routeName);
+ AltoNorthboundRoute getRoute(String routeName);
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
-Copyright © 2015 Yale University and others. All rights reserved.
-
-This program and the accompanying materials are made available under the
-terms of the Eclipse Public License v1.0 which accompanies this distribution,
-and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<snapshot>
- <required-capabilities>
- <capability>urn:alto:northbound?module=alto-northbound&revision=2015-10-21</capability>
- <capability>urn:alto:northbound:impl?module=alto-northbound-impl&revision=2015-10-21</capability>
- <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28</capability>
- </required-capabilities>
- <configuration>
-
- <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
- <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
- <module>
- <type xmlns:prefix="urn:alto:northbound:impl">prefix:alto-northbound</type>
- <name>alto-northbound-default</name>
- <broker>
- <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
- <name>binding-osgi-broker</name>
- </broker>
- </module>
- </modules>
-
- <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
- <service>
- <type xmlns:alto-northbound="urn:alto:northbound">alto-northbound:alto-northbound-router</type>
- <instance>
- <name>alto-northbound-router</name>
- <provider>/modules/module[type='alto-northbound'][name='alto-northbound-default']</provider>
- </instance>
- </service>
- </services>
- </data>
- </configuration>
-</snapshot>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<metadata modelVersion="1.1.0">
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-impl</artifactId>
- <version>0.2.1-SNAPSHOT</version>
- <versioning>
- <snapshot>
- <localCopy>true</localCopy>
- </snapshot>
- <lastUpdated>20151105030453</lastUpdated>
- <snapshotVersions>
- <snapshotVersion>
- <classifier>config</classifier>
- <extension>xml</extension>
- <value>0.2.1-SNAPSHOT</value>
- <updated>20151105030453</updated>
- </snapshotVersion>
- </snapshotVersions>
- </versioning>
-</metadata>
import org.opendaylight.alto.core.northbound.api.AltoNorthboundRoute;
import org.opendaylight.alto.core.northbound.api.AltoNorthboundRouter;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class AltoNorthboundProvider implements BindingAwareProvider, AutoCloseable, AltoNorthboundRouter{
+public class AltoNorthboundProvider implements AltoNorthboundRouter{
private static final Logger LOG = LoggerFactory.getLogger(AltoNorthboundProvider.class);
private AltoNorthboundRouterImpl router = AltoNorthboundRouterImpl.getInstance();
- @Override
- public void onSessionInitiated(ProviderContext session) {
+ public void init() {
LOG.info("AltoNorthboundProvider Session Initiated");
}
- @Override
public void close() throws Exception {
LOG.info("AltoNorthboundProvider Closed");
}
+++ /dev/null
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.impl.rev151021;
-
-import org.opendaylight.alto.core.northbound.impl.AltoNorthboundProvider;
-
-public class AltoNorthboundModule extends org.opendaylight.yang.gen.v1.urn.alto.northbound.impl.rev151021.AbstractAltoNorthboundModule {
- public AltoNorthboundModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public AltoNorthboundModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.alto.northbound.impl.rev151021.AltoNorthboundModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void customValidation() {
- // add custom validation form module attributes here.
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- AltoNorthboundProvider provider = new AltoNorthboundProvider();
-
- getBrokerDependency().registerProvider(provider);
- return provider;
- }
-
-}
+++ /dev/null
-/*
-* Generated file
-*
-* Generated from: yang module name: northbound-impl yang module local name: alto-northbound
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Thu Nov 05 10:05:41 CST 2015
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.impl.rev151021;
-public class AltoNorthboundModuleFactory extends org.opendaylight.yang.gen.v1.urn.alto.northbound.impl.rev151021.AbstractAltoNorthboundModuleFactory {
-
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright © 2016 SNLab and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+ <bean id="provider"
+ class="org.opendaylight.alto.core.northbound.impl.AltoNorthboundProvider"
+ init-method="init" destroy-method="close">
+ </bean>
+</blueprint>
+++ /dev/null
-module alto-northbound-impl {
- yang-version 1;
- namespace "urn:alto:northbound:impl";
- prefix "alto-northbound-impl";
-
- import alto-northbound { prefix alto-northbound; revision-date 2015-10-21; }
- import config { prefix config; revision-date 2013-04-05; }
- import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
-
- description
- "Service definition for northbound project";
-
- revision "2015-10-21" {
- description
- "Initial revision";
- }
-
- identity alto-northbound {
- base config:module-type;
- config:provided-service alto-northbound:alto-northbound-router;
- config:java-name-prefix AltoNorthbound;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- case alto-northbound {
- when "/config:modules/config:module/config:type = 'alto-northbound'";
- container broker {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity md-sal-binding:binding-broker-osgi-registry;
- }
- }
- }
- }
- }
-}
+++ /dev/null
-/*
- * Copyright © 2015 Yale University and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.impl.rev151021;
-
-import org.junit.Test;
-
-public class AltoNorthboundModuleFactoryTest {
- @Test
- public void testFactoryConstructor() {
- // ensure no exceptions on construction
- new AltoNorthboundModuleFactory();
- }
-}
+++ /dev/null
-/*
- * Copyright © 2015 Yale University and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.impl.rev151021;
-
-import org.junit.Test;
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.JmxAttribute;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.alto.core.northbound.impl.AltoNorthboundProvider;
-
-import javax.management.ObjectName;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class AltoNorthboundModuleTest {
- @Test
- public void testCustomValidation() {
- AltoNorthboundModule module = new AltoNorthboundModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
-
- // ensure no exceptions on validation
- // currently this method is empty
- module.customValidation();
- }
-
- @Test
- public void testCreateInstance() throws Exception {
- // configure mocks
- DependencyResolver dependencyResolver = mock(DependencyResolver.class);
- BindingAwareBroker broker = mock(BindingAwareBroker.class);
- when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker);
-
- // create instance of module with injected mocks
- AltoNorthboundModule module = new AltoNorthboundModule(mock(ModuleIdentifier.class), dependencyResolver);
-
- // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
- AutoCloseable closeable = module.getInstance();
-
- // verify that the module registered the returned provider with the broker
- verify(broker).registerProvider((AltoNorthboundProvider)closeable);
-
- // ensure no exceptions on close
- closeable.close();
- }
-}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
-Copyright © 2015 Yale University and others. All rights reserved.
-
-This program and the accompanying materials are made available under the
-terms of the Eclipse Public License v1.0 which accompanies this distribution,
-and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<snapshot>
- <required-capabilities>
- <capability>urn:alto:northbound:route:costmap:impl?module=alto-northbound-route-costmap-impl&revision=2015-10-21</capability>
- <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28</capability>
- <capability>urn:alto:northbound?module=alto-northbound&revision=2015-10-21</capability>
- </required-capabilities>
- <configuration>
-
- <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
- <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
- <module>
- <type xmlns:prefix="urn:alto:northbound:route:costmap:impl">prefix:alto-northbound-route-costmap-impl</type>
- <name>alto-northbound-route-costmap</name>
- <broker>
- <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
- <name>binding-osgi-broker</name>
- </broker>
- <alto-northbound-router>
- <type xmlns:alto-northbound-router="urn:alto:northbound">alto-northbound-router:alto-northbound-router</type>
- <name>alto-northbound-router</name>
- </alto-northbound-router>
- </module>
- </modules>
- </data>
- </configuration>
-</snapshot>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<metadata modelVersion="1.1.0">
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-impl</artifactId>
- <version>0.2.1-SNAPSHOT</version>
- <versioning>
- <snapshot>
- <localCopy>true</localCopy>
- </snapshot>
- <lastUpdated>20151105030453</lastUpdated>
- <snapshotVersions>
- <snapshotVersion>
- <classifier>config</classifier>
- <extension>xml</extension>
- <value>0.2.1-SNAPSHOT</value>
- <updated>20151105030453</updated>
- </snapshotVersion>
- </snapshotVersions>
- </versioning>
-</metadata>
package org.opendaylight.alto.core.northbound.route.costmap.impl;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285CostMap;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285CostType;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285VersionTag;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import java.util.Map;
import java.util.concurrent.Future;
-public class AltoNorthboundRouteCostmap implements BindingAwareProvider, AutoCloseable, AltoNorthboundRoute {
+public class AltoNorthboundRouteCostmap implements AltoNorthboundRoute {
public static final String COSTMAP_ROUTE = "costmap";
public static final String ALTO_COSTMAP_FILTER = "application/alto-costmapfilter+json";
private ObjectMapper mapper = new ObjectMapper();
private static final Logger LOG = LoggerFactory.getLogger(AltoNorthboundRouteCostmap.class);
- private static DataBroker m_dataBroker = null;
+
+ private DataBroker dataBroker = null;
+
private AltoNorthboundRouter m_router = null;
private static AltoModelCostmapService mapService = null;
- @Override
- public void onSessionInitiated(ProviderContext session) {
- m_dataBroker = session.getSALService(DataBroker.class);
- if (m_dataBroker == null) {
+ public void setDataBroker(DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
+ }
+
+ public void setMapService(final AltoModelCostmapService mapService) {
+ this.mapService = mapService;
+ }
+
+ public void init() {
+
+ if (dataBroker == null) {
LOG.error("Failed to init: data broker is null");
}
- mapService = session.getRpcService(AltoModelCostmapService.class);
+
LOG.info("AltoNorthboundRouteCostmap initiated");
}
m_router.addRoute("costmap", new AltoNorthboundRouteCostmap());
}
- @Override
public void close() {
m_router.removeRoute("costmap");
}
costmapRequestBuilder.setCostmapParams(costmapParamsBuilder.build());
- ReadOnlyTransaction rtx = m_dataBroker.newReadOnlyTransaction();
+ ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
InstanceIdentifier<ContextTag> ctagIID = getResourceByPath(path, rtx);
if(ctagIID == null){
return null;
+++ /dev/null
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.costmap.impl.rev151021;
-
-import org.opendaylight.alto.core.northbound.route.costmap.impl.AltoNorthboundRouteCostmap;
-
-public class AltoNorthboundRouteCostmapModule extends org.opendaylight.yang.gen.v1.urn.alto.northbound.route.costmap.impl.rev151021.AbstractAltoNorthboundRouteCostmapModule {
- public AltoNorthboundRouteCostmapModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public AltoNorthboundRouteCostmapModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.alto.northbound.route.costmap.impl.rev151021.AltoNorthboundRouteCostmapModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void customValidation() {
- // add custom validation form module attributes here.
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- AltoNorthboundRouteCostmap costmap = new AltoNorthboundRouteCostmap();
- getBrokerDependency().registerProvider(costmap);
- costmap.register(getAltoNorthboundRouterDependency());
- return costmap;
- }
-
-}
+++ /dev/null
-/*
-* Generated file
-*
-* Generated from: yang module name: alto-northbound-route-costmap-impl yang module local name: alto-northbound-route-costmap-impl
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Tue Dec 08 16:37:14 CST 2015
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.costmap.impl.rev151021;
-public class AltoNorthboundRouteCostmapModuleFactory extends org.opendaylight.yang.gen.v1.urn.alto.northbound.route.costmap.impl.rev151021.AbstractAltoNorthboundRouteCostmapModuleFactory {
-
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright © 2016 SNLab and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+ <odl:rpc-service id='altoModelCostmapService'
+ interface='org.opendaylight.alto.core.northbound.route.costmap.impl.AltoModelCostmapService' />
+ <bean id="provider"
+ class="org.opendaylight.alto.core.northbound.route.costmap.impl.AltoNorthboundRouteCostmap"
+ init-method="init" destroy-method="close">
+ <property name='mapService' ref='altoModelCostmapService' />
+ </bean>
+</blueprint>
+++ /dev/null
-module alto-northbound-route-costmap-impl {
- yang-version 1;
- namespace "urn:alto:northbound:route:costmap:impl";
- prefix "alto-northbound-router-costmap-impl";
-
- import alto-northbound { prefix alto-northbound; revision-date 2015-10-21; }
- import config { prefix config; revision-date 2013-04-05; }
- import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
-
- description
- "Service definition for northbound project";
-
- revision "2015-10-21" {
- description
- "Initial revision";
- }
-
- identity alto-northbound-route-costmap-impl {
- base config:module-type;
- config:java-name-prefix AltoNorthboundRouteCostmap;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- case alto-northbound-route-costmap {
- when "/config:modules/config:module/config:type = 'alto-northbound-route-costmap-impl'";
- container broker {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity md-sal-binding:binding-broker-osgi-registry;
- }
- }
- }
-
- container alto-northbound-router {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity alto-northbound:alto-northbound-router;
- }
- }
- }
- }
- }
-}
AltoNorthboundRouteCostmap costmap = new AltoNorthboundRouteCostmap();
AltoNorthboundRouteCostmap costmapSpy = spy(costmap);
AltoModelCostmapService mapService = mock(AltoModelCostmapService.class);
- BindingAwareBroker.ProviderContext session = mock(BindingAwareBroker.ProviderContext.class);
InstanceIdentifier<ContextTag> ctagIID = InstanceIdentifier.create(ContextTag.class);
-// doReturn("").when(mapService).query()
//configure mock
doReturn(ctagIID).when(costmapSpy).getResourceByPath(eq(path),(ReadOnlyTransaction) anyObject());
- when(session.getSALService(DataBroker.class)).thenReturn(new DataBroker() {
+ costmapSpy.setDataBroker(new DataBroker() {
@Override
public ReadOnlyTransaction newReadOnlyTransaction() {
return null;
return null;
}
});
- when(session.getRpcService(AltoModelCostmapService.class)).thenReturn(new AltoModelCostmapService() {
+ costmapSpy.setMapService(new AltoModelCostmapService() {
@Override
public Future<RpcResult<QueryOutput>> query(QueryInput queryInput) {
return null;
});
//start test
- costmapSpy.onSessionInitiated(session);
+ costmapSpy.init();
QueryInput input = costmapSpy.prepareInput(path,costmode,costmetri,pid_source,pid_destination);
CostmapRequest request = (CostmapRequest)input.getRequest();
//mock config
final AltoNorthboundRouteCostmap costmap = new AltoNorthboundRouteCostmap();
AltoNorthboundRouteCostmap costmapSpy = spy(costmap);
- BindingAwareBroker.ProviderContext session = mock(BindingAwareBroker.ProviderContext.class);
InstanceIdentifier<ContextTag> ctagIID = InstanceIdentifier.create(ContextTag.class);
AltoModelCostmapService costmapService = mock(AltoModelCostmapService.class);
when(future.get()).thenReturn(rpcResult);
when(costmapService.query((QueryInput) anyObject())).thenReturn(future);
- when(session.getRpcService(AltoModelCostmapService.class)).thenReturn(costmapService);
+ costmapSpy.setMapService(costmapService);
- when(session.getSALService(DataBroker.class)).thenReturn(new DataBroker() {
+ costmapSpy.setDataBroker(new DataBroker() {
@Override
public ReadOnlyTransaction newReadOnlyTransaction() {
return null;
doReturn(meta).when(costmapSpy).buildMeta((InstanceIdentifier<?>) anyObject(), (RFC7285CostType)anyObject());
//start test
- costmapSpy.onSessionInitiated(session);
+ costmapSpy.init();
Response response = costmapSpy.getFilteredMap(path,filter);
String responseStr = response.getEntity().toString();
ObjectMapper mapper = new ObjectMapper();
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
-Copyright © 2015 Yale University and others. All rights reserved.
-
-This program and the accompanying materials are made available under the
-terms of the Eclipse Public License v1.0 which accompanies this distribution,
-and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<snapshot>
- <required-capabilities>
- <capability>urn:alto:northbound:route:endpointcost:impl?module=alto-northbound-route-endpointcost-impl&revision=2015-10-21</capability>
- <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28</capability>
- <capability>urn:alto:northbound?module=alto-northbound&revision=2015-10-21</capability>
- </required-capabilities>
- <configuration>
-
- <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
- <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
- <module>
- <type xmlns:prefix="urn:alto:northbound:route:endpointcost:impl">prefix:alto-northbound-route-endpointcost-impl</type>
- <name>alto-northbound-route-endpointcost</name>
- <broker>
- <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
- <name>binding-osgi-broker</name>
- </broker>
- <alto-northbound-router>
- <type xmlns:alto-northbound-router="urn:alto:northbound">alto-northbound-router:alto-northbound-router</type>
- <name>alto-northbound-router</name>
- </alto-northbound-router>
- </module>
- </modules>
- </data>
- </configuration>
-</snapshot>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<metadata modelVersion="1.1.0">
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-impl</artifactId>
- <version>0.3.0-SNAPSHOT</version>
- <versioning>
- <snapshot>
- <localCopy>true</localCopy>
- </snapshot>
- <lastUpdated>20151105030453</lastUpdated>
- <snapshotVersions>
- <snapshotVersion>
- <classifier>config</classifier>
- <extension>xml</extension>
- <value>0.3.0-SNAPSHOT</value>
- <updated>20151105030453</updated>
- </snapshotVersion>
- </snapshotVersions>
- </versioning>
-</metadata>
package org.opendaylight.alto.core.northbound.route.endpointcost.impl;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opendaylight.alto.core.northbound.api.AltoNorthboundRouter;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285CostType;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285Endpoint;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import java.util.Map;
import java.util.concurrent.Future;
-public class AltoNorthboundRouteEndpointcost implements BindingAwareProvider, AutoCloseable, AltoNorthboundRoute {
+public class AltoNorthboundRouteEndpointcost implements AltoNorthboundRoute {
public static final String ENDPOINTCOST_ROUTE = "endpointcost";
public static final String ALTO_ENDPOINTCOST_FILTER = "application/alto-endpointcostfilter+json";
private ObjectMapper mapper = new ObjectMapper();
private static final Logger LOG = LoggerFactory.getLogger(AltoNorthboundRouteEndpointcost.class);
- private static DataBroker m_dataBroker = null;
+
+ private DataBroker dataBroker = null;
+
private AltoNorthboundRouter m_router = null;
private static AltoModelEndpointcostService mapService = null;
- @Override
- public void onSessionInitiated(ProviderContext session) {
- m_dataBroker = session.getSALService(DataBroker.class);
- if (m_dataBroker == null) {
+ public void setDataBroker(DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
+ }
+
+ public void setMapService(final AltoModelEndpointcostService mapService) {
+ this.mapService = mapService;
+ }
+
+ public void init() {
+
+ if (dataBroker == null) {
LOG.error("Failed to init: data broker is null");
}
- mapService = session.getRpcService(AltoModelEndpointcostService.class);
+
LOG.info("AltoNorthboundRouteEndpointcost initiated");
}
m_router.addRoute("endpointcost", new AltoNorthboundRouteEndpointcost());
}
- @Override
public void close() {
m_router.removeRoute("endpointcost");
}
endpointcostRequestBuilder.setEndpointcostParams(endpointcostParamsBuilder.build());
//create servicereference by getting contexttag from resourcepool
- ReadOnlyTransaction rtx = m_dataBroker.newReadOnlyTransaction();
+ ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
InstanceIdentifier<ContextTag> ctagIID = getResourceByPath(path, rtx);
if(ctagIID == null){
return null;
+++ /dev/null
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointcost.impl.rev151021;
-
-import org.opendaylight.alto.core.northbound.route.endpointcost.impl.AltoNorthboundRouteEndpointcost;
-
-public class AltoNorthboundRouteEndpointcostModule extends org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointcost.impl.rev151021.AbstractAltoNorthboundRouteEndpointcostModule {
- public AltoNorthboundRouteEndpointcostModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public AltoNorthboundRouteEndpointcostModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointcost.impl.rev151021.AltoNorthboundRouteEndpointcostModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void customValidation() {
- // add custom validation form module attributes here.
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- AltoNorthboundRouteEndpointcost endpointcost = new AltoNorthboundRouteEndpointcost();
- getBrokerDependency().registerProvider(endpointcost);
- endpointcost.register(getAltoNorthboundRouterDependency());
- return endpointcost;
- }
-
-}
+++ /dev/null
-/*
-* Generated file
-*
-* Generated from: yang module name: alto-northbound-route-endpointcost-impl yang module local name: alto-northbound-route-endpointcost-impl
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Sat Jan 02 16:06:35 CST 2016
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointcost.impl.rev151021;
-public class AltoNorthboundRouteEndpointcostModuleFactory extends org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointcost.impl.rev151021.AbstractAltoNorthboundRouteEndpointcostModuleFactory {
-
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright © 2016 SNLab and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+ <odl:rpc-service id='altoModelEndpointcostService'
+ interface='org.opendaylight.alto.core.northbound.route.endpointcost.impl.AltoModelEndpointcostService' />
+ <bean id="provider"
+ class="org.opendaylight.alto.core.northbound.route.endpointcost.impl.AltoNorthboundRouteEndpointcost"
+ init-method="init" destroy-method="close">
+ <property name='mapService' ref='altoModelEndpointcostService' />
+ </bean>
+</blueprint>
+++ /dev/null
-module alto-northbound-route-endpointcost-impl {
- yang-version 1;
- namespace "urn:alto:northbound:route:endpointcost:impl";
- prefix "alto-northbound-router-endpointcost-impl";
-
- import alto-northbound { prefix alto-northbound; revision-date 2015-10-21; }
- import config { prefix config; revision-date 2013-04-05; }
- import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
-
- description
- "Service definition for northbound project";
-
- revision "2015-10-21" {
- description
- "Initial revision";
- }
-
- identity alto-northbound-route-endpointcost-impl {
- base config:module-type;
- config:java-name-prefix AltoNorthboundRouteEndpointcost;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- case alto-northbound-route-endpointcost {
- when "/config:modules/config:module/config:type = 'alto-northbound-route-endpointcost-impl'";
- container broker {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity md-sal-binding:binding-broker-osgi-registry;
- }
- }
- }
-
- container alto-northbound-router {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity alto-northbound:alto-northbound-router;
- }
- }
- }
- }
- }
-}
AltoNorthboundRouteEndpointcost endpointcost = new AltoNorthboundRouteEndpointcost();
AltoNorthboundRouteEndpointcost endpointcostSpy = spy(endpointcost);
- BindingAwareBroker.ProviderContext session = mock(BindingAwareBroker.ProviderContext.class);
InstanceIdentifier<ContextTag> ctagIID = InstanceIdentifier.create(ContextTag.class);
//configure mock
doReturn(ctagIID).when(endpointcostSpy).getResourceByPath(eq(path),(ReadOnlyTransaction) anyObject());
- when(session.getSALService(DataBroker.class)).thenReturn(new DataBroker() {
+ endpointcostSpy.setDataBroker(new DataBroker() {
@Override
public ReadOnlyTransaction newReadOnlyTransaction() {
return null;
return null;
}
});
- when(session.getRpcService(AltoModelEndpointcostService.class)).thenReturn(new AltoModelEndpointcostService() {
+ endpointcostSpy.setMapService(new AltoModelEndpointcostService() {
@Override
public Future<RpcResult<QueryOutput>> query(QueryInput queryInput) {
return null;
});
//start test
- endpointcostSpy.onSessionInitiated(session);
+ endpointcostSpy.init();
QueryInput input = endpointcostSpy.prepareInput(path,costmode,costmetri,endpoints_source,endpoints_destination);
EndpointcostRequest request = (EndpointcostRequest)input.getRequest();
EndpointcostParams params = request.getEndpointcostParams();
//mock config
AltoNorthboundRouteEndpointcost endpointcost = new AltoNorthboundRouteEndpointcost();
AltoNorthboundRouteEndpointcost endpointcostSpy = spy(endpointcost);
- BindingAwareBroker.ProviderContext session = mock(BindingAwareBroker.ProviderContext.class);
InstanceIdentifier<ContextTag> ctagIID = InstanceIdentifier.create(ContextTag.class);
AltoModelEndpointcostService endpointcostService = mock(AltoModelEndpointcostService.class);
when(future.get()).thenReturn(rpcResult);
when(endpointcostService.query((QueryInput)anyObject())).thenReturn(future);
- when(session.getSALService(DataBroker.class)).thenReturn(new DataBroker() {
+ endpointcostSpy.setDataBroker(new DataBroker() {
@Override
public ReadOnlyTransaction newReadOnlyTransaction() {
return null;
return null;
}
});
- when(session.getRpcService(AltoModelEndpointcostService.class)).thenReturn(endpointcostService);
+ endpointcostSpy.setMapService(endpointcostService);
doReturn(ctagIID).when(endpointcostSpy).getResourceByPath(eq(path), (ReadOnlyTransaction)anyObject());
//start test
- endpointcostSpy.onSessionInitiated(session);
+ endpointcostSpy.init();
Response response = endpointcostSpy.getFilteredMap(path, filter);
String surex = response.getEntity().toString();
ObjectMapper mapper = new ObjectMapper();
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
-Copyright © 2015 Yale University and others. All rights reserved.
-
-This program and the accompanying materials are made available under the
-terms of the Eclipse Public License v1.0 which accompanies this distribution,
-and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<snapshot>
- <required-capabilities>
- <capability>urn:alto:northbound:route:endpointproperty:impl?module=alto-northbound-route-endpointproperty-impl&revision=2015-10-21</capability>
- <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28</capability>
- <capability>urn:alto:northbound?module=alto-northbound&revision=2015-10-21</capability>
- </required-capabilities>
- <configuration>
-
- <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
- <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
- <module>
- <type xmlns:prefix="urn:alto:northbound:route:endpointproperty:impl">prefix:alto-northbound-route-endpointproperty-impl</type>
- <name>alto-northbound-route-endpointproperty</name>
- <broker>
- <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
- <name>binding-osgi-broker</name>
- </broker>
- <alto-northbound-router>
- <type xmlns:alto-northbound-router="urn:alto:northbound">alto-northbound-router:alto-northbound-router</type>
- <name>alto-northbound-router</name>
- </alto-northbound-router>
- </module>
- </modules>
- </data>
- </configuration>
-</snapshot>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<metadata modelVersion="1.1.0">
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-impl</artifactId>
- <version>0.2.0-SNAPSHOT</version>
- <versioning>
- <snapshot>
- <localCopy>true</localCopy>
- </snapshot>
- <lastUpdated>20151105030453</lastUpdated>
- <snapshotVersions>
- <snapshotVersion>
- <classifier>config</classifier>
- <extension>xml</extension>
- <value>0.2.0-SNAPSHOT</value>
- <updated>20151105030453</updated>
- </snapshotVersion>
- </snapshotVersions>
- </versioning>
-</metadata>
package org.opendaylight.alto.core.northbound.route.endpointproperty.impl;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.opendaylight.alto.core.northbound.api.exception.AltoErrorInvalidFieldValue;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285EndpointPropertyMap;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285VersionTag;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
-public class AltoNorthboundRouteEndpointproperty implements BindingAwareProvider, AutoCloseable, AltoNorthboundRoute {
+public class AltoNorthboundRouteEndpointproperty implements AltoNorthboundRoute {
public static final String ALTO_ENDPOINTPROPERTY_FILTER = "application/alto-endpointpropparams+json";
public static final String ALTO_ENDPOINTPROPERTY = "application/alto-endpointprop+json";
public static final String FIELD_PROPERTIES = "properties";
private ObjectMapper mapper = new ObjectMapper();
private static final Logger LOG = LoggerFactory.getLogger(AltoNorthboundRouteEndpointproperty.class);
- private static DataBroker m_dataBroker = null;
+
+ private DataBroker dataBroker = null;
+
private AltoNorthboundRouter m_router = null;
private static AltoModelEndpointpropertyService mapService = null;
- @Override
- public void onSessionInitiated(ProviderContext session) {
- m_dataBroker = session.getSALService(DataBroker.class);
- if (m_dataBroker == null) {
+ public void setDataBroker(DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
+ }
+
+ public void setMapService(final AltoModelEndpointpropertyService mapService) {
+ this.mapService = mapService;
+ }
+
+ public void init() {
+
+ if (dataBroker == null) {
LOG.error("Failed to init: data broker is null");
}
- mapService = session.getRpcService(AltoModelEndpointpropertyService.class);
+
LOG.info("AltoNorthboundRouteEndpointProperty initiated");
}
m_router.addRoute("endpointproperty", new AltoNorthboundRouteEndpointproperty());
}
- @Override
public void close() {
m_router.removeRoute("endpointproperty");
}
}
protected QueryInput prepareInput(String path, Iterator<JsonNode> properties, Iterator<JsonNode> endpoints) {
- ReadOnlyTransaction rtx = m_dataBroker.newReadOnlyTransaction();
+ ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
InstanceIdentifier<ContextTag> ctagIID = getResourceByPath(path, rtx);
if(ctagIID == null){
return null;
+++ /dev/null
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointproperty.impl.rev151021;
-
-import org.opendaylight.alto.core.northbound.route.endpointproperty.impl.AltoNorthboundRouteEndpointproperty;
-
-public class AltoNorthboundRouteEndpointpropertyModule extends org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointproperty.impl.rev151021.AbstractAltoNorthboundRouteEndpointpropertyModule {
- public AltoNorthboundRouteEndpointpropertyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public AltoNorthboundRouteEndpointpropertyModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointproperty.impl.rev151021.AltoNorthboundRouteEndpointpropertyModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void customValidation() {
- // add custom validation form module attributes here.
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- AltoNorthboundRouteEndpointproperty endpointproperty = new AltoNorthboundRouteEndpointproperty();
- getBrokerDependency().registerProvider(endpointproperty);
- endpointproperty.register(getAltoNorthboundRouterDependency());
- return endpointproperty;
- }
-
-}
+++ /dev/null
-/*
-* Generated file
-*
-* Generated from: yang module name: alto-northbound-route-endpointproperty-impl yang module local name: alto-northbound-route-endpointproperty-impl
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Tue Dec 08 16:37:14 CST 2015
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointproperty.impl.rev151021;
-public class AltoNorthboundRouteEndpointpropertyModuleFactory extends org.opendaylight.yang.gen.v1.urn.alto.northbound.route.endpointproperty.impl.rev151021.AbstractAltoNorthboundRouteEndpointpropertyModuleFactory {
-
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright © 2016 SNLab and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+ <odl:rpc-service id='altoModelEndpointpropertyService'
+ interface='org.opendaylight.alto.core.northbound.route.endpointproperty.impl.AltoModelEndpointpropertyService' />
+ <bean id="provider"
+ class="org.opendaylight.alto.core.northbound.route.endpointproperty.impl.AltoNorthboundRouteEndpointproperty"
+ init-method="init" destroy-method="close">
+ <property name='mapService' ref='altoModelEndpointpropertyService' />
+ </bean>
+</blueprint>
+++ /dev/null
-module alto-northbound-route-endpointproperty-impl {
- yang-version 1;
- namespace "urn:alto:northbound:route:endpointproperty:impl";
- prefix "alto-northbound-router-endpointproperty-impl";
-
- import alto-northbound { prefix alto-northbound; revision-date 2015-10-21; }
- import config { prefix config; revision-date 2013-04-05; }
- import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
-
- description
- "Service definition for northbound project";
-
- revision "2015-10-21" {
- description
- "Initial revision";
- }
-
- identity alto-northbound-route-endpointproperty-impl {
- base config:module-type;
- config:java-name-prefix AltoNorthboundRouteEndpointproperty;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- case alto-northbound-route-endpointproperty {
- when "/config:modules/config:module/config:type = 'alto-northbound-route-endpointproperty-impl'";
- container broker {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity md-sal-binding:binding-broker-osgi-registry;
- }
- }
- }
-
- container alto-northbound-router {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity alto-northbound:alto-northbound-router;
- }
- }
- }
- }
-
- }
-}
public void testPrepareInput() {
AltoNorthboundRouteEndpointproperty anbreSpy = spy(anbre);
- BindingAwareBroker.ProviderContext session = mock(BindingAwareBroker.ProviderContext.class);
InstanceIdentifier<ContextTag> ctagIID = InstanceIdentifier.create(ContextTag.class);
JsonNode filterNode = EndpointpropertyRouteChecker.checkJsonSyntax(ENDPOINTPROPERTY_FILTER);
JsonNode _properties = filterNode.get(AltoNorthboundRouteEndpointproperty.FIELD_PROPERTIES);
doReturn(ctagIID)
.when(anbreSpy)
.getResourceByPath(eq(PATH), (ReadOnlyTransaction) anyObject());
- when(session.getSALService(DataBroker.class)).thenReturn(new DataBroker() {
+ anbreSpy.setDataBroker(new DataBroker() {
@Override public ReadOnlyTransaction newReadOnlyTransaction() {
return null;
}
}
});
- anbreSpy.onSessionInitiated(session);
+ anbreSpy.init();
QueryInput input = anbreSpy.prepareInput(PATH, _properties.elements(), _endpoints.elements());
EndpointpropertyRequest request = (EndpointpropertyRequest)input.getRequest();
EndpointpropertyParams params = request.getEndpointpropertyParams();
@Test
public void testBuildOutput() throws IOException, ExecutionException, InterruptedException{
AltoNorthboundRouteEndpointproperty anbreSpy = spy(anbre);
- BindingAwareBroker.ProviderContext session = mock(BindingAwareBroker.ProviderContext.class);
InstanceIdentifier<ContextTag> ctagIID = InstanceIdentifier.create(ContextTag.class);
AltoModelEndpointpropertyService epService = mock(AltoModelEndpointpropertyService.class);
when(rpcResult.getResult()).thenReturn(queryOutputBuilder.build());
when(future.get()).thenReturn(rpcResult);
when(epService.query((QueryInput) anyObject())).thenReturn(future);
- when(session.getRpcService(AltoModelEndpointpropertyService.class)).thenReturn(epService);
- when(session.getSALService(DataBroker.class)).thenReturn(new DataBroker() {
+ anbreSpy.setMapService(epService);
+ anbreSpy.setDataBroker(new DataBroker() {
@Override public ReadOnlyTransaction newReadOnlyTransaction() {
return null;
}
meta.netmap_tags.add(vtag);
doReturn(meta).when(anbreSpy).buildMeta((InstanceIdentifier<?>) anyObject());
- anbreSpy.onSessionInitiated(session);
+ anbreSpy.init();
Response response = anbreSpy.getEndpointProperty(PATH, ENDPOINTPROPERTY_FILTER);
String stringResponse = response.getEntity().toString();
ObjectMapper mapper = new ObjectMapper();
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
-Copyright © 2015 Yale University and others. All rights reserved.
-
-This program and the accompanying materials are made available under the
-terms of the Eclipse Public License v1.0 which accompanies this distribution,
-and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<snapshot>
- <required-capabilities>
- <capability>urn:alto:northbound:route:networkmap:impl?module=alto-northbound-route-networkmap-impl&revision=2015-10-21</capability>
- <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28</capability>
- <capability>urn:alto:northbound?module=alto-northbound&revision=2015-10-21</capability>
- </required-capabilities>
- <configuration>
-
- <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
- <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
- <module>
- <type xmlns:prefix="urn:alto:northbound:route:networkmap:impl">prefix:alto-northbound-route-networkmap-impl</type>
- <name>alto-northbound-route-networkmap</name>
- <broker>
- <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
- <name>binding-osgi-broker</name>
- </broker>
- <alto-northbound-router>
- <type xmlns:alto-northbound-router="urn:alto:northbound">alto-northbound-router:alto-northbound-router</type>
- <name>alto-northbound-router</name>
- </alto-northbound-router>
- </module>
- </modules>
- </data>
- </configuration>
-</snapshot>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<metadata modelVersion="1.1.0">
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-impl</artifactId>
- <version>0.2.1-SNAPSHOT</version>
- <versioning>
- <snapshot>
- <localCopy>true</localCopy>
- </snapshot>
- <lastUpdated>20151105030453</lastUpdated>
- <snapshotVersions>
- <snapshotVersion>
- <classifier>config</classifier>
- <extension>xml</extension>
- <value>0.2.1-SNAPSHOT</value>
- <updated>20151105030453</updated>
- </snapshotVersion>
- </snapshotVersions>
- </versioning>
-</metadata>
package org.opendaylight.alto.core.northbound.route.networkmap.impl;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285NetworkMap;
import org.opendaylight.alto.core.northbound.api.utils.rfc7285.RFC7285Endpoint.AddressGroup;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class AltoNorthboundRouteNetworkmap implements BindingAwareProvider, AutoCloseable, AltoNorthboundRoute {
+public class AltoNorthboundRouteNetworkmap implements AltoNorthboundRoute {
public static final String NETWORKMAP_ROUTE = "networkmap";
public static final String ALTO_NETWORKMAP_FILTER = "application/alto-networkmapfilter+json";
private ObjectMapper mapper = new ObjectMapper();
private static final Logger LOG = LoggerFactory.getLogger(AltoNorthboundRouteNetworkmap.class);
- private static DataBroker m_dataBroker = null;
+
+ private DataBroker dataBroker = null;
+
private AltoNorthboundRouter m_router = null;
private static AltoModelNetworkmapService mapService = null;
- @Override
- public void onSessionInitiated(ProviderContext session) {
- m_dataBroker = session.getSALService(DataBroker.class);
- if (m_dataBroker == null) {
+ public void setDataBroker(DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
+ }
+
+ public void setMapService(final AltoModelNetworkmapService mapService) {
+ this.mapService = mapService;
+ }
+
+ public void init() {
+
+ if (dataBroker == null) {
LOG.error("Failed to init: data broker is null");
}
- mapService = session.getRpcService(AltoModelNetworkmapService.class);
+
LOG.info("AltoNorthboundRouteNetworkmap initiated");
}
m_router.addRoute("networkmap", new AltoNorthboundRouteNetworkmap());
}
- @Override
public void close() {
m_router.removeRoute("networkmap");
}
//TODO
QueryInputBuilder queryInputBuilder = new QueryInputBuilder();
- ReadOnlyTransaction rtx = m_dataBroker.newReadOnlyTransaction();
+ ReadOnlyTransaction rtx = dataBroker.newReadOnlyTransaction();
InstanceIdentifier<ContextTag> ctagIID = getResourceByPath(path, rtx);
if(ctagIID == null){
return null;
+++ /dev/null
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.networkmap.impl.rev151021;
-
-import org.opendaylight.alto.core.northbound.route.networkmap.impl.AltoNorthboundRouteNetworkmap;
-
-public class AltoNorthboundRouteNetworkmapModule extends org.opendaylight.yang.gen.v1.urn.alto.northbound.route.networkmap.impl.rev151021.AbstractAltoNorthboundRouteNetworkmapModule {
- public AltoNorthboundRouteNetworkmapModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public AltoNorthboundRouteNetworkmapModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.alto.northbound.route.networkmap.impl.rev151021.AltoNorthboundRouteNetworkmapModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void customValidation() {
- // add custom validation form module attributes here.
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- AltoNorthboundRouteNetworkmap networkmap = new AltoNorthboundRouteNetworkmap();
- getBrokerDependency().registerProvider(networkmap);
- networkmap.register(getAltoNorthboundRouterDependency());
-
- return networkmap;
- }
-
-}
+++ /dev/null
-/*
-* Generated file
-*
-* Generated from: yang module name: alto-northbound-route-networkmap-impl yang module local name: alto-northbound-route-networkmap-impl
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Thu Nov 05 12:06:09 CST 2015
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.networkmap.impl.rev151021;
-public class AltoNorthboundRouteNetworkmapModuleFactory extends org.opendaylight.yang.gen.v1.urn.alto.northbound.route.networkmap.impl.rev151021.AbstractAltoNorthboundRouteNetworkmapModuleFactory {
-
-}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright © 2016 SNLab and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+ <odl:rpc-service id='altoModelNetworkmapService'
+ interface='org.opendaylight.alto.core.northbound.route.networkmap.impl.AltoModelNetworkmapService' />
+ <bean id="provider"
+ class="org.opendaylight.alto.core.northbound.route.networkmap.impl.AltoNorthboundRouteNetworkmap"
+ init-method="init" destroy-method="close">
+ <property name='mapService' ref='altoModelNetworkmapService' />
+ </bean>
+</blueprint>
+++ /dev/null
-module alto-northbound-route-networkmap-impl {
- yang-version 1;
- namespace "urn:alto:northbound:route:networkmap:impl";
- prefix "alto-northbound-router-networkmap-impl";
-
- import alto-northbound { prefix alto-northbound; revision-date 2015-10-21; }
- import config { prefix config; revision-date 2013-04-05; }
- import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;}
-
- description
- "Service definition for northbound project";
-
- revision "2015-10-21" {
- description
- "Initial revision";
- }
-
- identity alto-northbound-route-networkmap-impl {
- base config:module-type;
- config:java-name-prefix AltoNorthboundRouteNetworkmap;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- case alto-northbound-route-networkmap {
- when "/config:modules/config:module/config:type = 'alto-northbound-route-networkmap-impl'";
- container broker {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity md-sal-binding:binding-broker-osgi-registry;
- }
- }
- }
-
- container alto-northbound-router {
- uses config:service-ref {
- refine type {
- mandatory true;
- config:required-identity alto-northbound:alto-northbound-router;
- }
- }
- }
- }
- }
-}
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yang.gen.v1.urn.alto.resourcepool.rev150921.context.resource.ContextTag;
@Test
public void testprepareInput() throws JsonProcessingException{
-
//configure the mock
AltoNorthboundRouteNetworkmap networkmap = new AltoNorthboundRouteNetworkmap();
AltoNorthboundRouteNetworkmap networkmapSpy = spy(networkmap);
- BindingAwareBroker.ProviderContext session = mock(BindingAwareBroker.ProviderContext.class);
InstanceIdentifier<ContextTag> ctagIID = InstanceIdentifier.create(ContextTag.class);
doReturn(ctagIID).when(networkmapSpy).getResourceByPath(eq(path), (ReadOnlyTransaction) anyObject());
doReturn( AddressTypeIpv4.class).when(networkmapSpy).getAddressTypeByName(eq("ipv4"), eq(path), (ReadOnlyTransaction)anyObject());
doReturn( AddressTypeIpv6.class).when(networkmapSpy).getAddressTypeByName(eq("ipv6"), eq(path), (ReadOnlyTransaction)anyObject());
- when(session.getSALService(DataBroker.class)).thenReturn(new DataBroker() {
+ networkmapSpy.setDataBroker(new DataBroker() {
@Override
public ReadOnlyTransaction newReadOnlyTransaction() {
return null;
return null;
}
});
- when(session.getRpcService(AltoModelNetworkmapService.class)).thenReturn(new AltoModelNetworkmapService() {
+ networkmapSpy.setMapService(new AltoModelNetworkmapService() {
@Override
public Future<RpcResult<QueryOutput>> query(QueryInput queryInput) {
return null;
}
});
- networkmapSpy.onSessionInitiated(session);
QueryInput input = networkmapSpy.prepareInput(path, pids, addressTypes);
NetworkmapRequest request = (NetworkmapRequest)input.getRequest();
PidName pid1 = request.getNetworkmapFilter().getPid().get(0);
AltoNorthboundRouteNetworkmap networkmap = new AltoNorthboundRouteNetworkmap();
AltoNorthboundRouteNetworkmap networkmapSpy = spy(networkmap);
- BindingAwareBroker.ProviderContext session = mock(BindingAwareBroker.ProviderContext.class);
InstanceIdentifier<ContextTag> ctagIID = InstanceIdentifier.create(ContextTag.class);
doReturn(ctagIID).when(networkmapSpy).getResourceByPath(eq(path), (ReadOnlyTransaction) anyObject());
doReturn( AddressTypeIpv4.class).when(networkmapSpy).getAddressTypeByName(eq("ipv4"), eq(path), (ReadOnlyTransaction)anyObject());
when(rpcResult.getResult()).thenReturn(queryOutputBuilder.build());
when(future.get()).thenReturn(rpcResult);
when(networkmapService.query((QueryInput)anyObject())).thenReturn(future);
- when(session.getRpcService(AltoModelNetworkmapService.class)).thenReturn(networkmapService);
- when(session.getSALService(DataBroker.class)).thenReturn(new DataBroker() {
+ networkmapSpy.setMapService(networkmapService);
+ networkmapSpy.setDataBroker(new DataBroker() {
@Override
public ReadOnlyTransaction newReadOnlyTransaction() {
return null;
doReturn(new RFC7285NetworkMap.Meta()).when(networkmapSpy).buildMeta((InstanceIdentifier<?>)anyObject());
//start test
- networkmapSpy.onSessionInitiated(session);
+ networkmapSpy.init();
Response response = networkmapSpy.getFilteredMap(path, filter);
String surex = response.getEntity().toString();
ObjectMapper mapper = new ObjectMapper();
+++ /dev/null
-/*
- * Copyright © 2015 Yale University and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.networkmap.impl.rev151021;
-
-import org.junit.Test;
-
-public class AltoNorthboundRouteNetworkmapModuleFactoryTest {
- @Test
- public void testFactoryConstructor() {
- // ensure no exceptions on construction
- new AltoNorthboundRouteNetworkmapModuleFactory();
- }
-}
+++ /dev/null
-/*
- * Copyright © 2015 Yale University and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yang.gen.v1.urn.alto.northbound.route.networkmap.impl.rev151021;
-
-import org.junit.Test;
-import org.opendaylight.controller.config.api.DependencyResolver;
-import org.opendaylight.controller.config.api.JmxAttribute;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.alto.core.northbound.api.AltoNorthboundRouter;
-
-import javax.management.ObjectName;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class AltoNorthboundRouteNetworkmapModuleTest {
- @Test
- public void testCustomValidation() {
- AltoNorthboundRouteNetworkmapModule module = new AltoNorthboundRouteNetworkmapModule(mock(ModuleIdentifier.class), mock(DependencyResolver.class));
-
- // ensure no exceptions on validation
- // currently this method is empty
- module.customValidation();
- }
-
- @Test
- public void testCreateInstance() throws Exception {
- // configure mocks
- DependencyResolver dependencyResolver = mock(DependencyResolver.class);
- BindingAwareBroker broker = mock(BindingAwareBroker.class);
- AltoNorthboundRouter router = mock(AltoNorthboundRouter.class);
- when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker);
- when(dependencyResolver.resolveInstance(eq(AltoNorthboundRouter.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(router);
-
- // create instance of module with injected mocks
- AltoNorthboundRouteNetworkmapModule module = new AltoNorthboundRouteNetworkmapModule(mock(ModuleIdentifier.class), dependencyResolver);
-
- // getInstance calls resolveInstance to get the broker dependency and then calls createInstance
- AutoCloseable closeable = module.getInstance();
-
- // ensure no exceptions on close
- closeable.close();
-
- // verify that the route is released after closed
- verify(router).removeRoute("networkmap");
- }
-}
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-impl</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>config</classifier>
- </dependency>
-
<dependency>
<groupId>org.opendaylight.alto.core</groupId>
<artifactId>alto-northbound-route-networkmap-api</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-route-networkmap-impl</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>config</classifier>
- </dependency>
-
<dependency>
<groupId>org.opendaylight.alto.core</groupId>
<artifactId>alto-northbound-route-costmap-api</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-route-costmap-impl</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>config</classifier>
- </dependency>
-
<dependency>
<groupId>org.opendaylight.alto.core</groupId>
<artifactId>alto-northbound-route-endpointcost-api</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-route-endpointcost-impl</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>config</classifier>
- </dependency>
-
<dependency>
<groupId>org.opendaylight.alto.core</groupId>
<artifactId>alto-northbound-route-endpointproperty-api</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.opendaylight.alto.core</groupId>
- <artifactId>alto-northbound-route-endpointproperty-impl</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>config</classifier>
- </dependency>
-
<dependency>
<groupId>org.opendaylight.alto.core</groupId>
<artifactId>alto-service-model-ird-api</artifactId>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-api/${project.version}</bundle>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-impl/${project.version}</bundle>
- <configfile finalname="${configfile.directory}/alto-northbound.xml">
- mvn:org.opendaylight.alto.core/alto-northbound-impl/${project.version}/xml/config
- </configfile>
</feature>
<feature name='odl-alto-standard-service-models' version='${project.version}'
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-networkmap-api/${project.version}</bundle>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-networkmap-impl/${project.version}</bundle>
- <configfile finalname="${configfile.directory}/alto-northbound-route-networkmap.xml">
- mvn:org.opendaylight.alto.core/alto-northbound-route-networkmap-impl/${project.version}/xml/config
- </configfile>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-costmap-api/${project.version}</bundle>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-costmap-impl/${project.version}</bundle>
- <configfile finalname="${configfile.directory}/alto-northbound-route-costmap.xml">
- mvn:org.opendaylight.alto.core/alto-northbound-route-costmap-impl/${project.version}/xml/config
- </configfile>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-endpointcost-api/${project.version}</bundle>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-endpointcost-impl/${project.version}</bundle>
- <configfile finalname="${configfile.directory}/alto-northbound-route-endpointcost.xml">
- mvn:org.opendaylight.alto.core/alto-northbound-route-endpointcost-impl/${project.version}/xml/config
- </configfile>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-endpointproperty-api/${project.version}</bundle>
<bundle>mvn:org.opendaylight.alto.core/alto-northbound-route-endpointproperty-impl/${project.version}</bundle>
- <configfile finalname="${configfile.directory}/alto-northbound-route-endpointproperty.xml">
- mvn:org.opendaylight.alto.core/alto-northbound-route-endpointproperty-impl/${project.version}/xml/config
- </configfile>
</feature>
<feature name='odl-alto-standard-resource-translator' version='${project.version}'
--- /dev/null
+##############################################################################
+# Copyright (c) 2016 SNLab. All rights reserved.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v1.0 which accompanies this distribution,
+# and is available at http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+#!/bin/bash
+
+recursive_remove() {
+ DIR=$1
+
+ rmdir $DIR
+ while [ $? = 0 ]; do
+ DIR=$(dirname $DIR)
+ if [ $DIR = . ]; then
+ break
+ fi
+ rmdir $DIR
+ done
+}
+
+migrate_blueprint() {
+ pushd $1
+
+ PROVIDER=$(grep -rnl src/main/java -e '^\W*public void onSessionInitiated.*$')
+ PROVIDER_CLASS=$(echo $PROVIDER | sed 's_src/main/java/__;s/.java//;s_/_._g')
+ PROVIDER_NAME=$(basename $PROVIDER | sed 's/.java//')
+ PACKAGE=$(dirname $PROVIDER | sed 's_src/main/java/__;s_/_._g')
+
+ #----------------------
+ # extract flags
+ DB_FLAG=$(grep 'DataBroker' $PROVIDER)
+ RPC_FLAG=$(grep 'RpcRegistration' $PROVIDER)
+ ROUTED_RPC_FLAG=$(grep 'RoutedRpcRegistration' $PROVIDER)
+ RPC_CONSUME_LIST=$(grep 'getRpcService' $PROVIDER | \
+ sed 's/^\W*\([a-zA-Z_]\+\) *=.*getRpcService( *\([a-zA-Z]\+\)\.class *).*$/\1,\2/')
+
+ #----------------------
+ # remove redundancy
+ rm -rf src/main/config src/main/yang
+ for mf in $(find src/main -name '*Module.java'); do
+ rm $mf
+ recursive_remove $(dirname $mf)
+ done;
+
+ for mf in $(find src/main -name '*ModuleFactory.java'); do
+ rm $mf
+ recursive_remove $(dirname $mf)
+ done;
+
+ for mf in $(find src/test -name '*ModuleTest.java'); do
+ rm $mf
+ recursive_remove $(dirname $mf)
+ done;
+
+ for mf in $(find src/test -name '*ModuleFactoryTest.java'); do
+ rm $mf
+ recursive_remove $(dirname $mf)
+ done;
+
+ #----------------------
+ # insert blueprint
+ BLUEPRINT_DIR=src/main/resources/org/opendaylight/blueprint
+ mkdir -p $BLUEPRINT_DIR
+ echo '<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+Copyright © 2016 SNLab and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">' > $BLUEPRINT_DIR/impl-blueprint.xml
+
+ ## insert dataBroker
+ if [[ $DB_FLAGS ]]; then
+ echo ' <reference id="dataBroker"
+ interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"
+ odl:type="default" />' >> $BLUEPRINT_DIR/impl-blueprint.xml
+ fi
+
+ ## insert rpcRegistry
+ ## TODO:
+
+ ## insert routedRpcRegistry
+ ## TODO:
+
+ ## insert rpcService
+ for rpc in $RPC_CONSUME_LIST; do
+ SERV_NAME=$(echo $rpc | sed 's/^.*,//')
+ SERV_CLASS=$(grep "^import .*\.$SERV_NAME;" $PROVIDER | sed 's/^import \(.*\);$/\1/')
+ if [[ $SERV_CLASS ]]; then
+ SERV_CLASS="$PACKAGE.$SERV_NAME"
+ fi
+ SERV_ID=$(echo ${SERV_NAME:0:1} | tr '[:upper:]' '[:lower:]')${SERV_NAME:1}
+ echo " <odl:rpc-service id='$SERV_ID'
+ interface='$SERV_CLASS' />" >> $BLUEPRINT_DIR/impl-blueprint.xml
+ done
+
+ ## insert provider
+ echo ' <bean id="provider"
+ class="'$PROVIDER_CLASS'"
+ init-method="init" destroy-method="close">' >> $BLUEPRINT_DIR/impl-blueprint.xml
+ if [[ $DB_FLAGS ]]; then
+ echo ' <property name="dataBroker" ref="dataBroker" />' >> $BLUEPRINT_DIR/impl-blueprint.xml
+ fi
+ for rpc in $RPC_CONSUME_LIST; do
+ SERV_VAL=$(echo $rpc | sed 's/,.*$//')
+ SERV_NAME=$(echo $rpc | sed 's/^.*,//')
+ SERV_ID=$(echo ${SERV_NAME:0:1} | tr '[:upper:]' '[:lower:]')${SERV_NAME:1}
+ echo " <property name='$SERV_VAL' ref='$SERV_ID' />" >> $BLUEPRINT_DIR/impl-blueprint.xml
+ done
+ echo ' </bean>
+</blueprint>' >> $BLUEPRINT_DIR/impl-blueprint.xml
+
+ #----------------------
+ # refactor init class
+ sed -i '
+ s/^import .*ProviderContext;\n$//
+ s/^import .*BindingAwareProvider;\n$//
+ /@Override/{
+ N
+ s/^\W*@Override\n *public void onSessionInitiated.*/ public void init() {/
+ s/^\W*@Override\n\( *public void close().*\)/\1/
+ }
+ s/ BindingAwareProvider,\?//
+ s/ AutoCloseable,\?//
+ s/implements *{/{/
+ ' $PROVIDER
+
+ ## refactor dataBroke
+ if [[ $DB_FLAG ]]; then
+ ### refactor dataBroker variable name
+ DB_VAL=$(grep '^\W*private .* DataBroker' $PROVIDER | \
+ sed 's/^\W*private.* DataBroker *\([a-zA-Z_]\+\).*$/\1/')
+ sed -i "
+ s/^.*DataBroker.*$//
+ /^package/a\\\n\nimport org.opendaylight.controller.md.sal.binding.api.DataBroker;
+ /private static final Logger/a\\\n private DataBroker dataBroker = null;
+ /public void init()/i\ public void setDataBroker(DataBroker dataBroker) {\n this.dataBroker = dataBroker;\n }\n
+ s/$DB_VAL/dataBroker/g
+ " $PROVIDER
+ fi
+
+ ## refactor rpcService
+ sed -i 's/^\W*\([a-zA-Z_]\+\) *=.*getRpcService.*$//' $PROVIDER
+ for rpc in $RPC_CONSUME_LIST; do
+ SERV_VAL=$(echo $rpc | sed 's/,.*$//')
+ SERV_NAME=$(echo $rpc | sed 's/^.*,//')
+ SERV_SET_VAL=set$(echo ${SERV_VAL:0:1} | tr '[:lower:]' '[:upper:]')${SERV_VAL:1}
+ sed -i "
+ /public void init()/i\ public void $SERV_SET_VAL(final $SERV_NAME $SERV_VAL) {\n this.$SERV_VAL = $SERV_VAL;\n }\n
+ " $PROVIDER
+ done
+
+ popd
+}
+
+usage() {
+ echo "Usage: $0 [option]"
+ echo ""
+ echo "Options:"
+ echo " all migrate all subprojects"
+ echo " <dir> only migrate subprojects in <dir>"
+ echo " help display help information"
+}
+
+if [ -z $1 ]; then
+ usage
+ exit 0
+fi
+
+case $1 in
+ all)
+ # Migrate all subproject
+ cd $(dirname $0)/..
+ PROJECT_ROOT=$(pwd)
+
+ for suffix in alto-{core,basic,extensions}; do
+ for f in $(find $PROJECT_ROOT -name pom.xml); do
+ if [ $(basename $(dirname $f)) = impl ]; then
+ migrate_blueprint $(dirname $f)
+ fi
+ done
+ done
+ ;;
+ help)
+ usage
+ ;;
+ *)
+ # Migrate a specific directory
+ for f in $(find $1 -name pom.xml); do
+ if [ $(basename $(dirname $f)) = impl ]; then
+ migrate_blueprint $(dirname $f)
+ fi
+ done
+esac
##############################################################################
-# Copyright (c) 2016 <Company or Individual>. All rights reserved.
+# Copyright (c) 2016 SNLab. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0 which accompanies this distribution,