[VOL-4246] Feature parity with the previous implementation
Change-Id: I3741edb3c1b88b1cf8b5e6d4ff0900132e2e5e6a
diff --git a/web/pom.xml b/web/pom.xml
index 7c64f96..6b95b8d 100644
--- a/web/pom.xml
+++ b/web/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- ~ Copyright 2016-present Open Networking Foundation
+ ~ Copyright 2021 Open Networking Foundation
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
@@ -18,12 +18,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
- <groupId>org.opencord</groupId>
<artifactId>olt</artifactId>
- <version>4.6.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
+ <groupId>org.opencord</groupId>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
-
<modelVersion>4.0.0</modelVersion>
<artifactId>olt-web</artifactId>
<packaging>bundle</packaging>
@@ -38,70 +36,19 @@
</api.description>
<api.package>org.opencord.olt.rest</api.package>
</properties>
-
<dependencies>
<dependency>
- <groupId>org.opencord</groupId>
- <artifactId>olt-api</artifactId>
- <version>${olt.api.version}</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.opencord</groupId>
- <artifactId>olt-impl</artifactId>
- <version>${project.version}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.opencord</groupId>
- <artifactId>sadis-api</artifactId>
- <version>${sadis.api.version}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-cli</artifactId>
- <version>${onos.version}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-api</artifactId>
- <version>${onos.version}</version>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-core-serializers</artifactId>
- <version>${onos.version}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.karaf.shell</groupId>
- <artifactId>org.apache.karaf.shell.console</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.karaf.shell</groupId>
- <artifactId>org.apache.karaf.shell.core</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.opencord</groupId>
+ <artifactId>olt-api</artifactId>
+ <version>5.0.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
-
<build>
<plugins>
<plugin>
@@ -123,10 +70,9 @@
*,org.glassfish.jersey.servlet
</Import-Package>
<Web-ContextPath>${web.context}</Web-ContextPath>
- <Karaf-Commands>org.opencord.olt.cli</Karaf-Commands>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
-</project>
+</project>
\ No newline at end of file
diff --git a/web/src/main/java/org/opencord/olt/rest/OltWebResource.java b/web/src/main/java/org/opencord/olt/rest/OltWebResource.java
index 7b19b18..c512304 100644
--- a/web/src/main/java/org/opencord/olt/rest/OltWebResource.java
+++ b/web/src/main/java/org/opencord/olt/rest/OltWebResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-present Open Networking Foundation
+ * Copyright 2021-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,12 +21,11 @@
import org.onosproject.net.PortNumber;
import org.onosproject.rest.AbstractWebResource;
import org.opencord.olt.AccessDeviceService;
-import org.opencord.olt.AccessSubscriberId;
import org.slf4j.Logger;
-import java.util.Optional;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@@ -34,6 +33,8 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import java.util.Optional;
+
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static org.slf4j.LoggerFactory.getLogger;
@@ -43,10 +44,15 @@
@Path("oltapp")
public class OltWebResource extends AbstractWebResource {
-
private final Logger log = getLogger(getClass());
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("status")
+ public Response status() {
+ return Response.ok().build();
+ }
/**
* Provision a subscriber.
*
@@ -64,6 +70,7 @@
DeviceId deviceId = DeviceId.deviceId(device);
PortNumber portNumber = PortNumber.portNumber(port);
ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber);
+
try {
service.provisionSubscriber(connectPoint);
} catch (Exception e) {
@@ -113,7 +120,39 @@
Optional<VlanId> emptyVlan = Optional.empty();
Optional<Integer> emptyTpId = Optional.empty();
- if (service.provisionSubscriber(new AccessSubscriberId(portName), emptyVlan, emptyVlan, emptyTpId)) {
+ // Check if we can find the connect point to which this subscriber is connected
+ ConnectPoint cp = service.findSubscriberConnectPoint(portName);
+ if (cp == null) {
+ log.warn("ConnectPoint not found for {}", portName);
+ return Response.status(INTERNAL_SERVER_ERROR)
+ .entity("ConnectPoint not found for " + portName).build();
+ }
+ if (service.provisionSubscriber(cp)) {
+ return ok("").build();
+ }
+ return Response.noContent().build();
+ }
+
+ /**
+ * Removes services for a subscriber.
+ *
+ * @param portName Name of the port on which the subscriber is connected
+ * @return 200 OK or 204 NO CONTENT
+ */
+ @DELETE
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("services/{portName}")
+ public Response deleteServices(
+ @PathParam("portName") String portName) {
+ AccessDeviceService service = get(AccessDeviceService.class);
+
+ ConnectPoint cp = service.findSubscriberConnectPoint(portName);
+ if (cp == null) {
+ log.warn("ConnectPoint not found for {}", portName);
+ return Response.status(INTERNAL_SERVER_ERROR)
+ .entity("ConnectPoint not found for " + portName).build();
+ }
+ if (service.removeSubscriber(cp)) {
return ok("").build();
}
return Response.noContent().build();
@@ -141,30 +180,16 @@
VlanId cTag = VlanId.vlanId(cTagVal);
VlanId sTag = VlanId.vlanId(sTagVal);
Integer tpId = Integer.valueOf(tpIdVal);
-
- if (service.provisionSubscriber(new AccessSubscriberId(portName), Optional.of(sTag),
- Optional.of(cTag), Optional.of(tpId))) {
- return ok("").build();
+ // TODO this is not optimal, because we call device service 2 times here and
+ // 2 times in the provisionSubscriber call, optimize byu having 2 more methods
+ // in the OltService that allow provisioning with portName.
+ ConnectPoint cp = service.findSubscriberConnectPoint(portName);
+ if (cp == null) {
+ log.warn("ConnectPoint not found for {}", portName);
+ return Response.status(INTERNAL_SERVER_ERROR)
+ .entity("ConnectPoint not found for " + portName).build();
}
- return Response.noContent().build();
- }
-
- /**
- * Removes services for a subscriber.
- *
- * @param portName Name of the port on which the subscriber is connected
- * @return 200 OK or 204 NO CONTENT
- */
- @DELETE
- @Produces(MediaType.APPLICATION_JSON)
- @Path("services/{portName}")
- public Response deleteServices(
- @PathParam("portName") String portName) {
- AccessDeviceService service = get(AccessDeviceService.class);
-
- Optional<VlanId> emptyVlan = Optional.empty();
- Optional<Integer> emptyTpId = Optional.empty();
- if (service.removeSubscriber(new AccessSubscriberId(portName), emptyVlan, emptyVlan, emptyTpId)) {
+ if (service.provisionSubscriber(cp, cTag, sTag, tpId)) {
return ok("").build();
}
return Response.noContent().build();
@@ -192,12 +217,18 @@
VlanId cTag = VlanId.vlanId(cTagVal);
VlanId sTag = VlanId.vlanId(sTagVal);
Integer tpId = Integer.valueOf(tpIdVal);
-
- if (service.removeSubscriber(new AccessSubscriberId(portName), Optional.of(sTag),
- Optional.of(cTag), Optional.of(tpId))) {
+ // TODO this is not optimal, because we call device service 2 times here and
+ // 2 times in the provisionSubscriber call, optimize byu having 2 more methods
+ // in the OltService that allow provisioning with portName.
+ ConnectPoint cp = service.findSubscriberConnectPoint(portName);
+ if (cp == null) {
+ log.warn("ConnectPoint not found for {}", portName);
+ return Response.status(INTERNAL_SERVER_ERROR)
+ .entity("ConnectPoint not found for " + portName).build();
+ }
+ if (service.removeSubscriber(cp, cTag, sTag, tpId)) {
return ok("").build();
}
return Response.noContent().build();
}
-
}