<artifactId>northbound-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <!-- because the REST API classes @Inject @OsgiService INeutronCRUD dependencies,
+ we do need a dependency to the implementation of those INeutronCRUDs in transcriber;
+ otherwise this feature would not work standalone, and SFT will fail. -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>transcriber</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
<type>xml</type>
<classifier>features</classifier>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>transcriber</artifactId>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>model</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
+ <!-- TODO Remove this when AbstractNeutronNorthbound does not need
+ to use bundleContext.getServiceReferences() anymore... -->
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<artifactId>javax.inject</artifactId>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.cdi</groupId>
+ <artifactId>pax-cdi-api</artifactId>
+ <optional>true</optional>
+ </dependency>
<dependency>
<groupId>org.opendaylight.aaa.web</groupId>
<artifactId>web-api</artifactId>
import java.net.HttpURLConnection;
import java.util.Collection;
import java.util.List;
+import java.util.Objects;
import javax.ws.rs.core.Response;
import org.opendaylight.neutron.spi.INeutronCRUD;
import org.opendaylight.neutron.spi.INeutronObject;
private static final String INTERFACE_NAME_BASE = " CRUD Interface";
private static final String UUID_NO_EXIST_BASE = " UUID does not exist.";
+ private final I neutronCRUD;
+
+ /**
+ * Default constructor.
+ *
+ * @deprecated Replace usage of this method with direct dependency injection,
+ * see NeutronNetworksNorthbound for how-to. This will shortly be removed.
+ */
+ @Deprecated
+ protected AbstractNeutronNorthbound() {
+ this.neutronCRUD = null;
+ }
+
+ protected AbstractNeutronNorthbound(I neutronCRUD) {
+ this.neutronCRUD = Objects.requireNonNull(neutronCRUD, "neutronCRUD");
+ }
+
protected final String serviceUnavailable() {
return getResourceName() + INTERFACE_NAME_BASE + RestMessages.SERVICEUNAVAILABLE.toString();
}
}
protected I getNeutronCRUD() {
+ // TODO remove null check and everything below when the @deprecated default constructor is removed...
+ if (this.neutronCRUD != null) {
+ return this.neutronCRUD;
+ }
+
// cls = I.class
Class<I> cls = getActualTypeArgument(NEUTRON_CRUD_TYPE_INDEX);
I neutronCrud = fetchINeutronCRUD(cls, (Object) this);
protected Response show(String uuid,
// return fields
List<String> fields) {
- I neutronCRUD = getNeutronCRUD();
- T ans = neutronCRUD.get(uuid);
+ I gotNeutronCRUD = getNeutronCRUD(); // TODO remove and just use new private neutronCRUD field
+ T ans = gotNeutronCRUD.get(uuid);
if (ans == null) {
throw new ResourceNotFoundException(uuidNoExist());
}
}
protected Response create(final R input) {
- I neutronCRUD = getNeutronCRUD();
+ I gotNeutronCRUD = getNeutronCRUD(); // TODO remove and just use new private neutronCRUD field
if (input.isSingleton()) {
T singleton = input.getSingleton();
singleton.initDefaults();
- neutronCRUD.add(singleton);
+ gotNeutronCRUD.add(singleton);
} else {
if (input.getBulk() == null) {
throw new BadRequestException("Invalid requests");
}
for (T test : input.getBulk()) {
test.initDefaults();
- neutronCRUD.add(test);
+ gotNeutronCRUD.add(test);
}
}
return Response.status(HttpURLConnection.HTTP_CREATED).entity(input).build();
}
protected Response update(String uuid, final R input) {
- I neutronCRUD = getNeutronCRUD();
+ I gotNeutronCRUD = getNeutronCRUD(); // TODO remove and just use new private neutronCRUD field
if (!input.isSingleton()) {
throw new BadRequestException("Only singleton edit supported");
}
T delta = input.getSingleton();
- T original = neutronCRUD.get(uuid);
+ T original = gotNeutronCRUD.get(uuid);
if (original == null) {
throw new ResourceNotFoundException(uuidNoExist());
}
/*
* update the object and return it
*/
- if (!neutronCRUD.update(uuid, delta)) {
+ if (!gotNeutronCRUD.update(uuid, delta)) {
throw new ResourceNotFoundException(uuidNoExist());
}
- T updated = neutronCRUD.get(uuid);
+ T updated = gotNeutronCRUD.get(uuid);
return Response.status(HttpURLConnection.HTTP_OK).entity(newNeutronRequest(updated)).build();
}
protected Response delete(String uuid) {
- final I neutronCRUD = getNeutronCRUD();
+ final I gotNeutronCRUD = getNeutronCRUD(); // TODO remove and just use new private neutronCRUD field
/*
* remove it and return 204 status
*/
- if (!neutronCRUD.remove(uuid)) {
+ if (!gotNeutronCRUD.remove(uuid)) {
throw new ResourceNotFoundException(uuidNoExist());
}
import java.net.HttpURLConnection;
import java.util.ArrayList;
import java.util.List;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
import org.codehaus.enunciate.jaxrs.TypeHint;
+import org.opendaylight.neutron.spi.INeutronCRUD;
import org.opendaylight.neutron.spi.INeutronNetworkCRUD;
import org.opendaylight.neutron.spi.NeutronNetwork;
+import org.ops4j.pax.cdi.api.OsgiService;
/**
* Neutron Northbound REST APIs for Network.
*/
+@Singleton
@Path("/networks")
public final class NeutronNetworksNorthbound
extends AbstractNeutronNorthbound<NeutronNetwork, NeutronNetworkRequest, INeutronNetworkCRUD> {
private static final String RESOURCE_NAME = "Network";
+ @Inject
+ public NeutronNetworksNorthbound(@OsgiService INeutronNetworkCRUD neutronNetworkCRUD) {
+ super(neutronNetworkCRUD);
+ }
+
@Context
UriInfo uriInfo;
@DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
// sorting not supported
) {
- INeutronNetworkCRUD networkInterface = getNeutronCRUD();
+ INeutronCRUD<NeutronNetwork> networkInterface = getNeutronCRUD();
List<NeutronNetwork> allNetworks = networkInterface.getAll();
List<NeutronNetwork> ans = new ArrayList<>();
for (NeutronNetwork network : allNetworks) {
}
return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronNetworkRequest(ans)).build();
-
}
/**
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import javax.ws.rs.core.Application;
import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
* that will be instantiated for JAXRS processing. This is necessary
* because package scanning in jersey doesn't yet work in OSGi environment.
*/
+@Singleton
public final class NeutronNorthboundRSApplication extends Application {
private static final int HASHMAP_SIZE = 3;
+ private final NeutronNetworksNorthbound neutronNetworksNorthbound;
+
+ @Inject
+ public NeutronNorthboundRSApplication(NeutronNetworksNorthbound neutronNetworksNorthbound) {
+ this.neutronNetworksNorthbound = neutronNetworksNorthbound;
+ }
+
@Override
public Set<Class<?>> getClasses() {
return emptySet();
return ImmutableSet.builderWithExpectedSize(32)
.add(getMOXyJsonProvider())
// Northbound URIs JAX RS Resources:
- .add(new NeutronNetworksNorthbound())
+ .add(neutronNetworksNorthbound)
.add(new NeutronSubnetsNorthbound())
.add(new NeutronPortsNorthbound())
.add(new NeutronRoutersNorthbound())
private final WebContextRegistration registraton;
@Inject
- public WebInitializer(WebServer webServer, WebContextSecurer webContextSecurer) throws ServletException {
+ public WebInitializer(WebServer webServer, WebContextSecurer webContextSecurer, NeutronNorthboundRSApplication app)
+ throws ServletException {
WebContextBuilder webContextBuilder = WebContext.builder()
.contextPath("/controller/nb/v2/neutron").supportsSessions(true)
// TODO confirm through testing that Jersey & Neutron are fine without sessions, and false instead true
.addServlet(ServletDetails.builder()
- .servlet(new com.sun.jersey.spi.container.servlet.ServletContainer(
- new NeutronNorthboundRSApplication()))
+ .servlet(new com.sun.jersey.spi.container.servlet.ServletContainer(app))
.addUrlPattern("/*").build());
webContextSecurer.requireAuthentication(webContextBuilder, "/*");