-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from RADAR-CNS/0.2.1-release
Release 0.2.1
- Loading branch information
Showing
18 changed files
with
302 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
.../radar-schemas-tools/src/main/java/org/radarcns/schema/service/SourceCatalogueServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
|
||
} |
116 changes: 116 additions & 0 deletions
116
...radar-schemas-tools/src/main/java/org/radarcns/schema/service/SourceCatalogueService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.