NEUTRON-208: BGPVPN network and router association
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronNorthboundRSApplication.java
index e5b4096e5117bc125d65974362d82d30e8e8fa4c..522f1c2b5d59f07307560ca5dc279608305007b4 100644 (file)
@@ -16,7 +16,11 @@ import java.util.Set;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
 import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * This class is an instance of javax.ws.rs.core.Application and is used to return the classes
@@ -25,6 +29,9 @@ import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
  */
 @Singleton
 public final class NeutronNorthboundRSApplication extends Application {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NeutronNorthboundRSApplication.class);
+
     private static final int HASHMAP_SIZE = 3;
 
     private final NeutronNetworksNorthbound neutronNetworksNorthbound;
@@ -58,6 +65,8 @@ public final class NeutronNorthboundRSApplication extends Application {
     private final NeutronTrunksNorthbound neutronTrunksNorthbound;
     private final NeutronTapServiceNorthbound neutronTapServiceNorthbound;
     private final NeutronTapFlowNorthbound neutronTapFlowNorthbound;
+    private final NeutronBgpvpnNetworkAssociationsNorthbound neutronBgpvpnNetworkAssociationsNorthbound;
+    private final NeutronBgpvpnRouterAssociationsNorthbound neutronBgpvpnRouterAssociationsNorthbound;
 
     @Inject
     public NeutronNorthboundRSApplication(
@@ -91,7 +100,9 @@ public final class NeutronNorthboundRSApplication extends Application {
             NeutronQosPolicyNorthbound neutronQosPolicyNorthbound,
             NeutronTrunksNorthbound neutronTrunksNorthbound,
             NeutronTapServiceNorthbound neutronTapServiceNorthbound,
-            NeutronTapFlowNorthbound neutronTapFlowNorthbound) {
+            NeutronTapFlowNorthbound neutronTapFlowNorthbound,
+            NeutronBgpvpnNetworkAssociationsNorthbound neutronBgpvpnNetworkAssociationsNorthbound,
+            NeutronBgpvpnRouterAssociationsNorthbound neutronBgpvpnRouterAssociationsNorthbound) {
 
         this.neutronNetworksNorthbound = neutronNetworksNorthbound;
         this.neutronSubnetsNorthbound = neutronSubnetsNorthbound;
@@ -124,6 +135,8 @@ public final class NeutronNorthboundRSApplication extends Application {
         this.neutronTrunksNorthbound = neutronTrunksNorthbound;
         this.neutronTapServiceNorthbound = neutronTapServiceNorthbound;
         this.neutronTapFlowNorthbound = neutronTapFlowNorthbound;
+        this.neutronBgpvpnNetworkAssociationsNorthbound = neutronBgpvpnNetworkAssociationsNorthbound;
+        this.neutronBgpvpnRouterAssociationsNorthbound = neutronBgpvpnRouterAssociationsNorthbound;
     }
 
     @Override
@@ -133,7 +146,7 @@ public final class NeutronNorthboundRSApplication extends Application {
 
     @Override
     public Set<Object> getSingletons() {
-        return ImmutableSet.builderWithExpectedSize(32)
+        return ImmutableSet.builderWithExpectedSize(34)
                 .add(getMOXyJsonProvider())
                 // Northbound URIs JAX RS Resources:
                 .add(neutronNetworksNorthbound)
@@ -157,6 +170,8 @@ public final class NeutronNorthboundRSApplication extends Application {
                 .add(neutronVpnIpSecPoliciesNorthbound)
                 .add(neutronVpnIpSecSiteConnectionsNorthbound)
                 .add(neutronBgpvpnsNorthbound)
+                .add(neutronBgpvpnNetworkAssociationsNorthbound)
+                .add(neutronBgpvpnRouterAssociationsNorthbound)
                 .add(neutronL2gatewayNorthbound)
                 .add(neutronL2gatewayConnectionNorthbound)
                 .add(neutronSFCFlowClassifiersNorthbound)
@@ -167,6 +182,7 @@ public final class NeutronNorthboundRSApplication extends Application {
                 .add(neutronTrunksNorthbound)
                 .add(neutronTapServiceNorthbound)
                 .add(neutronTapFlowNorthbound)
+                .add(new LoggingExceptionMapper())
                 .build();
     }
 
@@ -189,4 +205,19 @@ public final class NeutronNorthboundRSApplication extends Application {
 
         return moxyJsonProvider;
     }
+
+    // do not inline this as a lambda; for some (strange) reason, the HK2 DI thing used by Jersey (v2.25.1) does
+    // not like it: "WARNING: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
+    //  javax.ws.rs.ProcessingException: Could not find exception type for given ExceptionMapper class:
+    //  class org.opendaylight.neutron.northbound.api.NeutronNorthboundRSApplication$$Lambda$157/5987161."
+    public static class LoggingExceptionMapper implements ExceptionMapper<Exception> {
+        @Override
+        public Response toResponse(Exception exception) {
+            LOG.error("Error processing response", exception);
+            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+            // In order to return the exception in the Response, it would need mapping.
+            // This could be brittle, and potentially insecure to provide internal exception externally.
+            // We thus intentionally chose to only return a generic 500 with details (only) in the log.
+        }
+    }
 }