import org.opendaylight.alto.commons.types.rfc7285.RFC7285Endpoint;
import org.opendaylight.alto.services.api.rfc7285.AltoService;
+import org.opendaylight.alto.services.api.rfc7285.IRDService;
+import org.opendaylight.alto.services.api.rfc7285.NetworkMapService;
+import org.opendaylight.alto.services.api.rfc7285.CostMapService;
+import org.opendaylight.alto.services.api.rfc7285.EndpointCostService;
+import org.opendaylight.alto.services.api.rfc7285.EndpointPropertyService;
-import org.opendaylight.alto.ext.fake.FakeAltoService;
import org.opendaylight.alto.northbound.exception.AltoBasicException;
import org.opendaylight.alto.northbound.exception.AltoBadFormatException;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(AltoNorthbound.class);
- private AltoService altoService = new FakeAltoService();
private RFC7285JSONMapper mapper = new RFC7285JSONMapper();
- private void checkAltoService() throws Exception {
- if (altoService == null)
+ private <E> E getService(Class<E> clazz) {
+ E service = (E)ServiceHelper.getGlobalInstance(clazz, this);
+ if (service == null) {
+ service = (E)ServiceHelper.getGlobalInstance(AltoService.class, this);
+ }
+ return service;
+ }
+
+ private void checkService(Object service) throws Exception {
+ if (service == null)
throw new AltoBasicException(Status.SERVICE_UNAVAILABLE, null);
}
@GET
@Produces({ MediaType.ALTO_DIRECTORY, MediaType.ALTO_ERROR })
public Response retrieveIRD() throws Exception {
- checkAltoService();
+ IRDService service = getService(IRDService.class);
+ checkService(service);
- RFC7285IRD ird = altoService.getDefaultIRD();
+ RFC7285IRD ird = service.getDefaultIRD();
if (ird == null)
return fail(Status.NOT_FOUND, null);
return success(ird, MediaType.ALTO_DIRECTORY);
@Produces({ MediaType.ALTO_DIRECTORY, MediaType.ALTO_ERROR })
public Response retrieveIRD(
@PathParam("id") String id) throws Exception {
- checkAltoService();
+ IRDService service = getService(IRDService.class);
+ checkService(service);
checkResourceId(id);
- RFC7285IRD ird = altoService.getIRD(id);
+ RFC7285IRD ird = service.getIRD(id);
if (ird == null)
return fail(Status.NOT_FOUND, id);
return success(ird, MediaType.ALTO_DIRECTORY);
@GET
@Produces({ MediaType.ALTO_NETWORKMAP, MediaType.ALTO_ERROR })
public Response retrieveDefaultNetworkMap() throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
- RFC7285NetworkMap map = altoService.getDefaultNetworkMap();
+ RFC7285NetworkMap map = service.getDefaultNetworkMap();
if (map == null)
return fail(Status.NOT_FOUND, null);
return success(map, MediaType.ALTO_NETWORKMAP);
@Produces({ MediaType.ALTO_NETWORKMAP, MediaType.ALTO_ERROR })
public Response retrieveNetworkMap(
@PathParam("id") String id) throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
checkResourceId(id);
- RFC7285NetworkMap map = altoService.getNetworkMap(id);
+ RFC7285NetworkMap map = service.getNetworkMap(id);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_NETWORKMAP);
public Response retrieveNetworkMap(
@PathParam("id") String id,
@PathParam("tag") String tag) throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
- RFC7285NetworkMap map = altoService.getNetworkMap(vtag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285NetworkMap map = service.getNetworkMap(vtag);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_NETWORKMAP);
@GET
@Produces({ MediaType.ALTO_COSTMAP, MediaType.ALTO_ERROR})
public Response retrieveCostMap(@PathParam("id") String id) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
- RFC7285CostMap map = altoService.getCostMap(id);
+ RFC7285CostMap map = service.getCostMap(id);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_COSTMAP);
public Response retrieveCostMap(
@PathParam("id") String id,
@PathParam("tag") String tag) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
- RFC7285CostMap map = altoService.getCostMap(vtag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285CostMap map = service.getCostMap(vtag);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_COSTMAP);
@PathParam("id") String id,
@PathParam("mode") String mode,
@PathParam("metric") String metric) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
RFC7285CostType costType = new RFC7285CostType(mode, metric);
- if (!altoService.supportCostType(id, costType))
+ if (!service.supportCostType(id, costType))
return fail(Status.NOT_FOUND, costType);
- RFC7285CostMap map = altoService.getCostMap(id, costType);
+ RFC7285CostMap map = service.getCostMap(id, costType);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_COSTMAP);
@PathParam("tag") String tag,
@PathParam("mode") String mode,
@PathParam("metric") String metric) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285CostType costType = new RFC7285CostType(mode, metric);
- if (!altoService.supportCostType(vtag, costType))
+ if (!service.supportCostType(vtag, costType))
return fail(Status.NOT_FOUND, costType);
- RFC7285CostMap map = altoService.getCostMap(vtag, costType);
+ RFC7285CostMap map = service.getCostMap(vtag, costType);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_COSTMAP);
@Produces({ MediaType.ALTO_NETWORKMAP, MediaType.ALTO_ERROR})
public Response retrieveFilteredNetworkMap(
@PathParam("id") String id, String filterJSON) throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
checkResourceId(id);
RFC7285NetworkMap.Filter filter = mapper.asNetworkMapFilter(filterJSON);
- if (!altoService.validateNetworkMapFilter(id, filter))
+ if (!service.validateNetworkMapFilter(id, filter))
return fail(Status.BAD_REQUEST, filter);
- RFC7285NetworkMap map = altoService.getNetworkMap(id, filter);
+ RFC7285NetworkMap map = service.getNetworkMap(id, filter);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_NETWORKMAP);
@PathParam("id") String id,
@PathParam("tag") String tag,
String filterJSON) throws Exception {
- checkAltoService();
+ NetworkMapService service = getService(NetworkMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285NetworkMap.Filter filter = mapper.asNetworkMapFilter(filterJSON);
- if (!altoService.validateNetworkMapFilter(vtag, filter))
+ if (!service.validateNetworkMapFilter(vtag, filter))
return fail(Status.BAD_REQUEST, filter);
- RFC7285NetworkMap map = altoService.getNetworkMap(vtag, filter);
+ RFC7285NetworkMap map = service.getNetworkMap(vtag, filter);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_NETWORKMAP);
@Produces({ MediaType.ALTO_COSTMAP, MediaType.ALTO_ERROR})
public Response retrieveFilteredCostMap(
@PathParam("id") String id, String filterJSON) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
RFC7285CostMap.Filter filter = mapper.asCostMapFilter(filterJSON);
- if (!altoService.validateCostMapFilter(id, filter))
+ if (!service.validateCostMapFilter(id, filter))
return fail(Status.BAD_REQUEST, filter);
- RFC7285CostMap map = altoService.getCostMap(id, filter);
+ RFC7285CostMap map = service.getCostMap(id, filter);
if (map == null)
return fail(Status.NOT_FOUND, id);
return success(map, MediaType.ALTO_COSTMAP);
public Response retrieveFilteredCostMap(
@PathParam("id") String id,
@PathParam("tag") String tag, String filterJSON) throws Exception {
- checkAltoService();
+ CostMapService service = getService(CostMapService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285CostMap.Filter filter = mapper.asCostMapFilter(filterJSON);
- if (!altoService.validateCostMapFilter(vtag, filter))
+ if (!service.validateCostMapFilter(vtag, filter))
return fail(Status.BAD_REQUEST, filter);
- RFC7285CostMap map = altoService.getCostMap(vtag, filter);
+ RFC7285CostMap map = service.getCostMap(vtag, filter);
if (map == null)
return fail(Status.NOT_FOUND, vtag);
return success(map, MediaType.ALTO_COSTMAP);
public Response retrieveEndpointPropMap(
@PathParam("id") String id,
String params) throws Exception {
- checkAltoService();
+ EndpointPropertyService service = getService(EndpointPropertyService.class);
+ checkService(service);
checkResourceId(id);
RFC7285Endpoint.PropertyRequest request = mapper.asPropertyRequest(params);
- RFC7285Endpoint.PropertyResponse response = altoService.getEndpointProperty(id, request);
+ RFC7285Endpoint.PropertyResponse response = service.getEndpointProperty(id, request);
if (response == null)
return fail(Status.NOT_FOUND, request);
return success(response, MediaType.ALTO_ENDPOINT_PROP);
@PathParam("id") String id,
@PathParam("tag") String tag,
String params) throws Exception {
- checkAltoService();
+ EndpointPropertyService service = getService(EndpointPropertyService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
- RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
+ RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285Endpoint.PropertyRequest request = mapper.asPropertyRequest(params);
- RFC7285Endpoint.PropertyResponse response = altoService.getEndpointProperty(vtag, request);
+ RFC7285Endpoint.PropertyResponse response = service.getEndpointProperty(vtag, request);
if (response == null)
return fail(Status.NOT_FOUND, request);
return success(response, MediaType.ALTO_ENDPOINT_PROP);
public Response retrieveEndpointCostMap(
@PathParam("id") String id,
String params) throws Exception {
- checkAltoService();
+ EndpointCostService service = getService(EndpointCostService.class);
+ checkService(service);
checkResourceId(id);
RFC7285Endpoint.CostRequest request = mapper.asCostRequest(params);
- RFC7285Endpoint.CostResponse response = altoService.getEndpointCost(id, request);
+ RFC7285Endpoint.CostResponse response = service.getEndpointCost(id, request);
if (response == null)
return fail(Status.NOT_FOUND, request);
return success(response, MediaType.ALTO_ENDPOINT_COST);
@PathParam("id") String id,
@PathParam("tag") String tag,
String params) throws Exception {
- checkAltoService();
+ EndpointCostService service = getService(EndpointCostService.class);
+ checkService(service);
checkResourceId(id);
checkTag(tag);
RFC7285VersionTag vtag = new RFC7285VersionTag(id, tag);
RFC7285Endpoint.CostRequest request = mapper.asCostRequest(params);
- RFC7285Endpoint.CostResponse response = altoService.getEndpointCost(vtag, request);
+ RFC7285Endpoint.CostResponse response = service.getEndpointCost(vtag, request);
if (response == null)
return fail(Status.NOT_FOUND, request);
return success(response, MediaType.ALTO_ENDPOINT_COST);