Skip to content

Commit

Permalink
Merge pull request #73 from RADAR-CNS/0.2.1-release
Browse files Browse the repository at this point in the history
 Release 0.2.1
  • Loading branch information
nivemaham authored Nov 28, 2017
2 parents 146c0c1 + d415cdd commit 477210c
Show file tree
Hide file tree
Showing 18 changed files with 302 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COPY commons /code/commons
COPY specifications /code/specifications
COPY restapi /code/restapi
COPY java-sdk/gradle /code/java-sdk/gradle
COPY java-sdk/gradle.properties java-sdk/build.gradle java-sdk/settings.gradle java-sdk/gradlew /code/java-sdk/
COPY java-sdk/build.gradle java-sdk/settings.gradle java-sdk/gradlew /code/java-sdk/
RUN ./gradlew tasks
COPY java-sdk/radar-schemas-commons/build.gradle /code/java-sdk/radar-schemas-commons/
COPY java-sdk/radar-schemas-commons/src /code/java-sdk/radar-schemas-commons/src
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ docker-compose run --rm tools radar-schemas-tools list
docker-compose run --rm tools radar-schemas-tools register http://schema-registry:8081
# create topics with zookeeper
docker-compose run --rm tools radar-schemas-tools create zookeeper-1:2181
# run source-catalogue webservice
docker-compose run --rm tools radar-schemas-tools serve -p <portnumber>

```
2 changes: 1 addition & 1 deletion java-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ subprojects {
apply plugin: 'idea'

// Configuration
version = '0.2'
version = '0.2.1'
group = 'org.radarcns'
ext.githubRepoName = 'RADAR-CNS/RADAR-Schemas'

Expand Down
8 changes: 7 additions & 1 deletion java-sdk/radar-schemas-tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ sourceSets {

ext.junitVersion = '4.12'
ext.slf4jVersion = '1.7.25'

ext.jettyVersion = '9.4.7.v20170914'
ext.jerseyVersion = '2.9'
dependencies {
api group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.10'
api group: 'javax.validation', name: 'validation-api', version: '2.0.0.Final'
Expand All @@ -32,6 +33,11 @@ dependencies {
implementation (group: 'org.apache.kafka', name: 'kafka_2.11', version: '0.11.0.1') {
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
}
implementation group: 'org.eclipse.jetty', name: 'jetty-server', version: jettyVersion
implementation group: 'org.eclipse.jetty', name: 'jetty-servlet', version: jettyVersion
implementation group: 'org.glassfish.jersey.core', name: 'jersey-server', version: jerseyVersion
implementation group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet-core', version: jerseyVersion
implementation group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: jerseyVersion

runtimeOnly group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.sourceforge.argparse4j.inf.Subparsers;
import org.radarcns.schema.registration.KafkaTopics;
import org.radarcns.schema.registration.SchemaRegistry;
import org.radarcns.schema.service.SourceCatalogueServer;
import org.radarcns.schema.specification.DataProducer;
import org.radarcns.schema.specification.DataTopic;
import org.radarcns.schema.specification.SourceCatalogue;
Expand Down Expand Up @@ -53,6 +54,7 @@
*/
@SuppressWarnings("PMD.SystemPrintln")
public class CommandLineApp {

private static final Logger logger = LoggerFactory.getLogger(CommandLineApp.class);

private final SourceCatalogue catalogue;
Expand Down Expand Up @@ -166,7 +168,8 @@ public static void main(String... args) {
KafkaTopics.command(),
SchemaRegistry.command(),
listCommand(),
SchemaValidator.command());
SchemaValidator.command(),
SourceCatalogueServer.command());

ArgumentParser parser = getArgumentParser(subCommands);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.radarcns.schema.service;

import java.io.Closeable;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.Namespace;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
import org.radarcns.schema.CommandLineApp;
import org.radarcns.schema.specification.SourceCatalogue;
import org.radarcns.schema.util.SubCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This server provides a webservice to share the SourceType Catalogues provided in *.yml files as
* {@link org.radarcns.schema.service.SourceCatalogueService.SourceTypeResponse}
*/
public class SourceCatalogueServer implements Closeable {

private static final Logger logger = LoggerFactory.getLogger(SourceCatalogueServer.class);

private final Server server;

public SourceCatalogueServer(int serverPort) {
this.server = new Server(serverPort);
}

@Override
public void close() {
try {
this.server.join();
} catch (InterruptedException e) {
logger.error("Cannot stop server", e);
}
server.destroy();
}

@SuppressWarnings("PMD.SignatureDeclareThrowsException")
private void start(SourceCatalogue sourceCatalogue) throws Exception {

ResourceConfig config = new ResourceConfig();
config.register(new SourceCatalogueService(sourceCatalogue));
ServletHolder servlet = new ServletHolder(new ServletContainer(config));
ServletContextHandler context = new ServletContextHandler(server, "/*");
context.addServlet(servlet, "/*");
server.start();
}

public static SubCommand command() {
return new SourceCatalogueServiceCommand();
}

private static class SourceCatalogueServiceCommand implements SubCommand {

@Override
public String getName() {
return "serve";
}

@Override
public int execute(Namespace options, CommandLineApp app) {
int partitions = options.getInt("port");
SourceCatalogueServer service = new SourceCatalogueServer(partitions);
try {
service.start(app.getCatalogue());
} catch (Exception e) {
logger.error("Cannot start server ", e);
return 1;
}
service.close();
return 0;
}

@Override
public void addParser(ArgumentParser parser) {
parser.description("A web service to share source-type catalogs");
parser.addArgument("-p" ,"--port")
.help("Port number of the SourceCatalogue Server ")
.type(Integer.class)
.setDefault(9010);
SubCommand.addRootArgument(parser);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.radarcns.schema.service;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.radarcns.schema.specification.SourceCatalogue;
import org.radarcns.schema.specification.active.ActiveSource;
import org.radarcns.schema.specification.monitor.MonitorSource;
import org.radarcns.schema.specification.passive.PassiveSource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;

/**
* Webservice resource to share SourceCatalogues. The response has a "Source-Type-Class" header that
* mentions the class of SourceCatalogues and the body has the SourceCatalogues in JSON format.
*/
@Path("/source-types")
@Produces(MediaType.APPLICATION_JSON)
public class SourceCatalogueService {

private static final String SOURCE_TYPE_CLASS_HEADER = "Source-Type-Class";
private final SourceCatalogue sourceCatalogue;

SourceCatalogueService(SourceCatalogue sourceCatalogue) {
this.sourceCatalogue = sourceCatalogue;
}

@GET
@Path("/passive")
public Response getPassiveSources() {
return Response.ok().entity(new SourceTypeResponse(this.sourceCatalogue).passive())
.header(SOURCE_TYPE_CLASS_HEADER, "PASSIVE").build();
}

@GET
@Path("/active")
public Response getActiveSources() {
return Response.ok().entity(new SourceTypeResponse(this.sourceCatalogue).active())
.header(SOURCE_TYPE_CLASS_HEADER, "ACTIVE").build();
}

@GET
@Path("/monitor")
public Response getMonitorSources() {
return Response.ok().entity(new SourceTypeResponse(this.sourceCatalogue).monitor())
.header(SOURCE_TYPE_CLASS_HEADER, "MONITOR").build();
}

@GET
public Response getAllSourceTypes() {
return Response.ok().entity(new SourceTypeResponse(this.sourceCatalogue).all())
.header(SOURCE_TYPE_CLASS_HEADER, "ALL").build();
}

public class SourceTypeResponse {

@JsonIgnore
private final SourceCatalogue sourceCatalogue;

@JsonProperty("passive-source-types")
private List<PassiveSource> passiveSources;

@JsonProperty("active-source-types")
private List<ActiveSource> activeSources;

@JsonProperty("monitor-source-types")
private List<MonitorSource> monitorSources;

private SourceTypeResponse(SourceCatalogue sourceCatalogue) {
this.sourceCatalogue = sourceCatalogue;
}

private SourceTypeResponse passive() {
this.passiveSources = new ArrayList<>(
this.sourceCatalogue.getPassiveSources().values());
return this;
}

public SourceTypeResponse active() {
this.activeSources = new ArrayList<>(this.sourceCatalogue.getActiveSources().values());
return this;
}

public SourceTypeResponse monitor() {
this.monitorSources = new ArrayList<>(
this.sourceCatalogue.getMonitorSources().values());
return this;
}

private SourceTypeResponse all() {
this.passiveSources = new ArrayList<>(
this.sourceCatalogue.getPassiveSources().values());
this.activeSources = new ArrayList<>(this.sourceCatalogue.getActiveSources().values());
this.monitorSources = new ArrayList<>(
this.sourceCatalogue.getMonitorSources().values());
return this;
}

public List<PassiveSource> getPassiveSources() {
return passiveSources;
}

public List<ActiveSource> getActiveSources() {
return activeSources;
}

public List<MonitorSource> getMonitorSources() {
return monitorSources;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import java.util.Objects;

import static org.radarcns.schema.util.Utils.expandClass;

public abstract class AppSource<T extends DataTopic> extends DataProducer<T> {
@JsonProperty("app_provider")
private String appProvider;

@JsonProperty
private String vendor;

@JsonProperty
private String model;

@JsonProperty
private String version;

@JsonSetter
@SuppressWarnings("PMD.UnusedPrivateMethod")
private void setAppProvider(String provider) {
Expand All @@ -18,4 +28,37 @@ private void setAppProvider(String provider) {
public String getAppProvider() {
return appProvider;
}

public String getVersion() {
return version;
}

public String getVendor() {
return vendor;
}

public String getModel() {
return model;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AppSource provider = (AppSource) o;
return Objects.equals(appProvider, provider.appProvider)
&& Objects.equals(version, provider.version)
&& Objects.equals(model, provider.model)
&& Objects.equals(vendor, provider.vendor)
&& Objects.equals(getData(), provider.getData());
}

@Override
public int hashCode() {
return Objects.hash(appProvider, vendor, model, version, getData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Stream<String> getTopicNames() {
return getData().stream().flatMap(applyOrEmpty(DataTopic::getTopics));
}


@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public enum RadarSourceTypes {
@JsonProperty
private List<T> data;

@JsonProperty
private String vendor;

@JsonProperty
private String model;

@JsonProperty
private String version;

public String getAssessmentType() {
return assessmentType;
}
Expand All @@ -60,4 +69,16 @@ public List<T> getData() {
public Scope getScope() {
return Scope.ACTIVE;
}

public String getVendor() {
return vendor;
}

public String getModel() {
return model;
}

public String getVersion() {
return version;
}
}
Loading

0 comments on commit 477210c

Please sign in to comment.