Reorganized SADIS to separate out api and app
Change-Id: Id30e9bc2880282930f97ab947dd95f19f853b3e8
diff --git a/app/src/main/java/org/opencord/sadis/cli/SubscriberGetCommand.java b/app/src/main/java/org/opencord/sadis/cli/SubscriberGetCommand.java
new file mode 100644
index 0000000..bc5e812
--- /dev/null
+++ b/app/src/main/java/org/opencord/sadis/cli/SubscriberGetCommand.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+
+/**
+ * Subscriber And Device Information Service CLI.
+ */
+@Command(scope = "onos", name = "sadis", description = "Subscriber And Device Information Service CLI command")
+public class SubscriberGetCommand extends AbstractShellCommand {
+
+ @Argument(index = 0, name = "ID", description = "subscriber ID", required = true, multiValued = false)
+ String id;
+
+ @Override
+ protected void execute() {
+ print("Hello %s", "World");
+ }
+
+}
diff --git a/app/src/main/java/org/opencord/sadis/cli/package-info.java b/app/src/main/java/org/opencord/sadis/cli/package-info.java
new file mode 100644
index 0000000..04738d2
--- /dev/null
+++ b/app/src/main/java/org/opencord/sadis/cli/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * SADIS application for handling Subscriber and Device Information.
+ */
+package org.opencord.sadis.cli;
diff --git a/app/src/main/java/org/opencord/sadis/impl/SadisConfig.java b/app/src/main/java/org/opencord/sadis/impl/SadisConfig.java
new file mode 100644
index 0000000..26aaa87
--- /dev/null
+++ b/app/src/main/java/org/opencord/sadis/impl/SadisConfig.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.VlanId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+import org.opencord.sadis.SubscriberAndDeviceInformation;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.ObjectCodec;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+/**
+ * Configuration options for the Subscriber And Device Information Service.
+ *
+ * <pre>
+ * "sadis" : {
+ * "integration" : {
+ * "url" : "http://{hostname}{:port}",
+ * "cache" : {
+ * "enable" : true or false,
+ * "maxsize" : number of entries,
+ * "entryttl" : duration, i.e. 10s or 1m
+ * }
+ * },
+ * "entries" : [
+ * {
+ * "id" : "uniqueid",
+ * "ctag" : int,
+ * "stag" : int,
+ * "nasportid" : string,
+ * "port" : int,
+ * "slot" : int,
+ * "hardwareidentifier" : string,
+ * "ipAddress" : string,
+ * "nasId" : string
+ * }, ...
+ * ]
+ * }
+ * </pre>
+ */
+public class SadisConfig extends Config<ApplicationId> {
+
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ private static final String SADIS_INTEGRATION = "integration";
+ private static final String SADIS_CACHE = "cache";
+ private static final String SADIS_CACHE_ENABLED = "enabled";
+ private static final String SADIS_CACHE_SIZE = "maxsize";
+ private static final String SADIS_CACHE_TTL = "ttl";
+ private static final String SADIS_URL = "url";
+ private static final String SADIS_ENTRIES = "entries";
+ private static final String DEFAULT_CACHE_TTL = "PT0S";
+
+ /**
+ * Returns SADIS integration URL.
+ *
+ * @return configured URL or null
+ * @throws MalformedURLException
+ * specified URL not valid
+ */
+ public URL getUrl() throws MalformedURLException {
+ final JsonNode integration = this.object.path(SADIS_INTEGRATION);
+ if (integration.isMissingNode()) {
+ return null;
+ }
+
+ final JsonNode url = integration.path(SADIS_URL);
+ if (url.isMissingNode()) {
+ return null;
+ }
+
+ return new URL(url.asText());
+ }
+
+ /**
+ * Returns configuration if cache should be used or not. Only used if
+ * integration URL is set.
+ *
+ * @return if cache should be used
+ */
+ public Boolean getCacheEnabled() {
+ final JsonNode integration = this.object.path(SADIS_INTEGRATION);
+ if (integration.isMissingNode()) {
+ return false;
+ }
+
+ final JsonNode cache = integration.path(SADIS_CACHE);
+ if (cache.isMissingNode()) {
+ return false;
+ }
+
+ return cache.path(SADIS_CACHE_ENABLED).asBoolean(false);
+ }
+
+ public int getCacheMaxSize() {
+ final JsonNode integration = this.object.path(SADIS_INTEGRATION);
+ if (integration.isMissingNode()) {
+ return -1;
+ }
+
+ final JsonNode cache = integration.path(SADIS_CACHE);
+ if (cache.isMissingNode()) {
+ return -1;
+ }
+
+ return cache.path(SADIS_CACHE_SIZE).asInt(-1);
+ }
+
+ public Duration getCacheTtl() {
+ final JsonNode integration = this.object.path(SADIS_INTEGRATION);
+ if (integration.isMissingNode()) {
+ return Duration.parse(DEFAULT_CACHE_TTL);
+ }
+
+ final JsonNode cache = integration.path(SADIS_CACHE);
+ if (cache.isMissingNode()) {
+ return Duration.parse(DEFAULT_CACHE_TTL);
+ }
+
+ return Duration.parse(cache.path(SADIS_CACHE_TTL).asText(DEFAULT_CACHE_TTL));
+ }
+
+ public List<SubscriberAndDeviceInformation> getEntries() {
+ List<SubscriberAndDeviceInformation> result = new ArrayList<SubscriberAndDeviceInformation>();
+ ObjectMapper mapper = new ObjectMapper();
+ SimpleModule module = new SimpleModule();
+ module.addDeserializer(VlanId.class, new VlanIdDeserializer());
+ module.addDeserializer(Ip4Address.class, new Ip4AddressDeserializer());
+ mapper.registerModule(module);
+ final JsonNode entries = this.object.path(SADIS_ENTRIES);
+ entries.forEach(entry -> {
+ try {
+ result.add(mapper.readValue(entry.toString(), SubscriberAndDeviceInformation.class));
+ } catch (IOException e) {
+ log.warn("Unable to parse configuration entry, '{}', error: {}", entry.toString(), e.getMessage());
+ }
+ });
+
+ return result;
+ }
+
+ public class VlanIdDeserializer extends JsonDeserializer<VlanId> {
+ @Override
+ public VlanId deserialize(JsonParser jp, DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+ ObjectCodec oc = jp.getCodec();
+ JsonNode node = oc.readTree(jp);
+ return VlanId.vlanId((short) node.asInt());
+ }
+ }
+
+ public class Ip4AddressDeserializer extends JsonDeserializer<Ip4Address> {
+ @Override
+ public Ip4Address deserialize(JsonParser jp, DeserializationContext ctxt)
+ throws IOException, JsonProcessingException {
+ ObjectCodec oc = jp.getCodec();
+ JsonNode node = oc.readTree(jp);
+ return Ip4Address.valueOf((String) node.asText());
+ }
+ }
+}
diff --git a/app/src/main/java/org/opencord/sadis/impl/SadisManager.java b/app/src/main/java/org/opencord/sadis/impl/SadisManager.java
new file mode 100644
index 0000000..713b8b0
--- /dev/null
+++ b/app/src/main/java/org/opencord/sadis/impl/SadisManager.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis.impl;
+
+import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY;
+
+import java.util.Set;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Subscriber And Device Information Service application component. Component
+ * that manages the integration of ONOS into a deployment providing a bridge
+ * between ONOS and deployment specific information about subscribers and access
+ * devices.
+ */
+@Service
+@Component(immediate = true)
+public class SadisManager extends SubscriberAndDeviceInformationAdapter {
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ private static final String SADIS_APP = "org.opencord.sadis";
+ private ApplicationId appId;
+ private final InternalConfigListener cfgListener = new InternalConfigListener();
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected CoreService coreService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected NetworkConfigRegistry cfgService;
+
+ @SuppressWarnings("rawtypes")
+ private final Set<ConfigFactory> factories = ImmutableSet
+ .of(new ConfigFactory<ApplicationId, SadisConfig>(APP_SUBJECT_FACTORY, SadisConfig.class, "sadis") {
+ @Override
+ public SadisConfig createConfig() {
+ return new SadisConfig();
+ }
+ });
+
+ /**
+ * Initialize the SADIS ONOS application.
+ */
+ @Activate
+ protected void activate() {
+
+ this.appId = this.coreService.registerApplication(SADIS_APP);
+ this.cfgService.addListener(this.cfgListener);
+ this.factories.forEach(this.cfgService::registerConfigFactory);
+ this.updateConfig();
+
+ this.log.info("Started");
+ }
+
+ /**
+ * Cleans up resources utilized by the SADIS ONOS application.
+ */
+ @Deactivate
+ protected void deactivate() {
+ this.log.info("Stopped");
+ }
+
+ /**
+ * Validates the configuration and updates any operational settings that are
+ * affected by configuration changes.
+ */
+ private void updateConfig() {
+ final SadisConfig cfg = this.cfgService.getConfig(this.appId, SadisConfig.class);
+ if (cfg == null) {
+ this.log.warn("Subscriber And Device Information Service (SADIS) configuration not available");
+ return;
+ }
+ this.log.info("Cache Enabled: {}", cfg.getCacheEnabled());
+ this.log.info("Cache Mac Size: {}", cfg.getCacheMaxSize());
+ this.log.info("Cache TTL: {}", cfg.getCacheTtl().getSeconds());
+ this.log.info("Entries: {}", cfg.getEntries());
+
+ configure(cfg);
+ }
+
+ /**
+ * Listener for SADIS configuration events.
+ */
+ private class InternalConfigListener implements NetworkConfigListener {
+
+ @Override
+ public void event(final NetworkConfigEvent event) {
+
+ if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED
+ || event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)
+ && event.configClass().equals(SadisConfig.class)) {
+ SadisManager.this.updateConfig();
+ SadisManager.this.log.info("Reconfigured");
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationAdapter.java b/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationAdapter.java
new file mode 100644
index 0000000..7e063f7
--- /dev/null
+++ b/app/src/main/java/org/opencord/sadis/impl/SubscriberAndDeviceInformationAdapter.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.opencord.sadis.SubscriberAndDeviceInformation;
+import org.opencord.sadis.SubscriberAndDeviceInformationService;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.collect.Maps;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public abstract class SubscriberAndDeviceInformationAdapter implements SubscriberAndDeviceInformationService {
+
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ private static final int DEFAULT_MAXIMUM_CACHE_SIZE = 0;
+ private static final long DEFAULT_TTL = 0;
+
+ private String url;
+ private Cache<String, SubscriberAndDeviceInformation> cache;
+ private int maxiumCacheSize = DEFAULT_MAXIMUM_CACHE_SIZE;
+ private long cacheEntryTtl = DEFAULT_TTL;
+
+ private Map<String, SubscriberAndDeviceInformation> localCfgData = null;
+
+ public SubscriberAndDeviceInformationAdapter() {
+ cache = CacheBuilder.newBuilder().maximumSize(maxiumCacheSize)
+ .expireAfterAccess(cacheEntryTtl, TimeUnit.SECONDS).build();
+ }
+
+ /**
+ * Configures the Adapter for data source and cache parameters.
+ *
+ * @param cfg Configuration data.
+ */
+ public void configure(SadisConfig cfg) {
+ String url = null;
+ try {
+ // if the url is not present then assume data is in netcfg
+ if (cfg.getUrl() != null) {
+ url = cfg.getUrl().toString();
+ } else {
+ localCfgData = Maps.newConcurrentMap();
+
+ cfg.getEntries().forEach(entry -> {
+ localCfgData.put(entry.id(), entry);
+ });
+ log.info("url is null, data source is local netcfg data");
+ }
+ } catch (MalformedURLException mUrlEx) {
+ log.error("Invalid URL specified: {}", mUrlEx);
+ }
+
+ int maximumCacheSeize = cfg.getCacheMaxSize();
+ long cacheEntryTtl = cfg.getCacheTtl().getSeconds();
+
+ // Rebuild cache if needed
+ if ((url != null && url != this.url) || maximumCacheSeize != this.maxiumCacheSize ||
+ cacheEntryTtl != this.cacheEntryTtl) {
+ this.maxiumCacheSize = maximumCacheSeize;
+ this.cacheEntryTtl = cacheEntryTtl;
+ this.url = url;
+
+ Cache<String, SubscriberAndDeviceInformation> newCache = CacheBuilder.newBuilder()
+ .maximumSize(maxiumCacheSize).expireAfterAccess(cacheEntryTtl, TimeUnit.SECONDS).build();
+ Cache<String, SubscriberAndDeviceInformation> oldCache = cache;
+
+ synchronized (this) {
+ cache = newCache;
+ }
+
+ oldCache.invalidateAll();
+ oldCache.cleanUp();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.opencord.sadis.SubscriberAndDeviceInformationService#clearCache()
+ */
+ @Override
+ public void invalidateAll() {
+ cache.invalidateAll();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.opencord.sadis.SubscriberAndDeviceInformationService#get(java.lang.
+ * String)
+ */
+ @Override
+ public SubscriberAndDeviceInformation get(String id) {
+ Cache<String, SubscriberAndDeviceInformation> local;
+ synchronized (this) {
+ local = cache;
+ }
+
+ SubscriberAndDeviceInformation info = local.getIfPresent(id);
+ if (info != null) {
+ return info;
+ }
+
+ /*
+ * Not in cache, if we have a URL configured we can attempt to get it
+ * from there, else check for it in the locally configured data
+ */
+ if (this.url == null) {
+ info = localCfgData.get(id);
+
+ if (info != null) {
+ local.put(id, info);
+ return info;
+ }
+ } else {
+ // Augment URL with query parameters
+ StringBuilder buf = new StringBuilder(this.url);
+ if (buf.charAt(buf.length() - 1) != '/') {
+ buf.append('/');
+ }
+
+ buf.append(id);
+
+ try (InputStream io = new URL(buf.toString()).openStream()) {
+ ObjectMapper mapper = new ObjectMapper();
+ info = mapper.readValue(io, SubscriberAndDeviceInformation.class);
+ local.put(id, info);
+ return info;
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ log.error("Data not found for id {}", id);
+ return null;
+ }
+}
diff --git a/app/src/main/java/org/opencord/sadis/impl/package-info.java b/app/src/main/java/org/opencord/sadis/impl/package-info.java
new file mode 100644
index 0000000..cef1f21
--- /dev/null
+++ b/app/src/main/java/org/opencord/sadis/impl/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * The purpose of this service is to define an optional service that provides a bridge
+ * to the customer's infrastructure to query / cache subsciber/access information
+ * and make it available to other services / applications within the ONOS/CORD
+ * infrastructure.
+ */
+package org.opencord.sadis;
diff --git a/app/src/main/java/org/opencord/sadis/rest/AppWebApplication.java b/app/src/main/java/org/opencord/sadis/rest/AppWebApplication.java
new file mode 100644
index 0000000..25c3683
--- /dev/null
+++ b/app/src/main/java/org/opencord/sadis/rest/AppWebApplication.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opencord.sadis.rest;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * Subscriber And Device Infomration Service REST API web application.
+ */
+public class AppWebApplication extends AbstractWebApplication {
+ @Override
+ public Set<Class<?>> getClasses() {
+ return getClasses(AppWebResource.class);
+ }
+}
diff --git a/app/src/main/java/org/opencord/sadis/rest/AppWebResource.java b/app/src/main/java/org/opencord/sadis/rest/AppWebResource.java
new file mode 100644
index 0000000..41c2819
--- /dev/null
+++ b/app/src/main/java/org/opencord/sadis/rest/AppWebResource.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.opencord.sadis.rest;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.rest.AbstractWebResource;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+/**
+ * Subscriber And Device Information Service web resource.
+ */
+@Path("sadis")
+public class AppWebResource extends AbstractWebResource {
+
+ /**
+ * Get subscriber object.
+ *
+ * @param id
+ * ID of the subscriber
+ *
+ * @return 200 OK
+ */
+ @GET
+ @Path("/subscriber/{id}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getSubscriber(@PathParam("id") String id) {
+ ObjectNode node = mapper().createObjectNode().put("hello", "world");
+ return ok(node).build();
+ }
+
+ /**
+ * Update subscriber object.
+ *
+ * @param id
+ * ID of the subscriber
+ *
+ * @return 200 OK
+ */
+ @PUT
+ @Path("/subscriber/{id}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response putSubscriber(@PathParam("id") String id) {
+ return Response.ok().build();
+ }
+
+ /**
+ * Create subscriber object.
+ *
+ * @return 201 Created
+ */
+ @POST
+ @Path("/subscriber")
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response postSubscriber() {
+ try {
+ return Response.created(new URI("/subsciber/123")).build();
+ } catch (URISyntaxException e) {
+ return Response.serverError().build();
+ }
+ }
+
+ /**
+ * Delete subscriber object.
+ *
+ * @param id
+ * ID of the subscriber
+ * @return 204 NoContent
+ */
+ @DELETE
+ @Path("/subscriber/{id}")
+ public Response deleteSubscriber(@PathParam("id") String id) {
+ return Response.noContent().build();
+ }
+}
diff --git a/app/src/main/java/org/opencord/sadis/rest/package-info.java b/app/src/main/java/org/opencord/sadis/rest/package-info.java
new file mode 100755
index 0000000..4a0c20e
--- /dev/null
+++ b/app/src/main/java/org/opencord/sadis/rest/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * REST APIs for the SADIS application.
+ */
+package org.opencord.sadis.rest;