use of net.sourceforge.argparse4j.inf.Namespace in project cogcomp-nlp by CogComp.
the class MainServer method startServer.
public static void startServer(String[] args, Logger logger) {
Namespace parseResults;
try {
parseResults = argumentParser.parseArgs(args);
} catch (HelpScreenException ex) {
return;
} catch (ArgumentParserException ex) {
logger.error("Exception while parsing arguments", ex);
return;
}
port(parseResults.getInt("port"));
// create a hashmap to keep track of client ip addresses and their
int rate = parseResults.getInt("rate");
if (rate > 0) {
clients = new HashMap<String, Integer>();
}
AnnotatorService finalPipeline = pipeline;
get("/annotate", "application/json", (request, response) -> {
logger.info("GET request . . . ");
boolean canServe = true;
if (rate > 0) {
resetServer();
String ip = request.ip();
int callsSofar = (Integer) clients.getOrDefault(ip, 0);
if (callsSofar > rate)
canServe = false;
clients.put(ip, callsSofar + 1);
}
if (canServe) {
logger.info("request.body(): " + request.body());
String text = request.queryParams("text");
String views = request.queryParams("views");
return annotateText(finalPipeline, text, views, logger);
} else {
response.status(429);
return "You have reached your maximum daily query limit :-/ ";
}
});
post("/annotate", (request, response) -> {
logger.info("POST request . . . ");
boolean canServe = true;
if (rate > 0) {
resetServer();
String ip = request.ip();
int callsSofar = (Integer) clients.getOrDefault(ip, 0);
if (callsSofar > rate)
canServe = false;
clients.put(ip, callsSofar + 1);
}
if (canServe) {
logger.info("request.body(): " + request.body());
Map<String, String> map = splitQuery(request.body());
System.out.println("POST body parameters parsed: " + map);
String text = map.get("text");
String views = map.get("views");
return annotateText(finalPipeline, text, views, logger);
} else {
response.status(429);
return "You have reached your maximum daily query limit :-/ ";
}
});
// api to get name of the available views
String viewsString = "";
for (String view : pipeline.getAvailableViews()) {
viewsString += ", " + view;
}
String finalViewsString = viewsString;
enableCORS("*", "*", "*");
get("/viewNames", (req, res) -> finalViewsString);
post("/viewNames", (req, res) -> finalViewsString);
}
use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.
the class DbTagCommandTest method testRun.
@Test
public void testRun() throws Exception {
// Migrate some DDL changes
final TestMigrationConfiguration conf = createConfiguration(getDatabaseUrl());
final DbMigrateCommand<TestMigrationConfiguration> dbMigrateCommand = new DbMigrateCommand<>(new TestMigrationDatabaseConfiguration(), TestMigrationConfiguration.class, migrationsFileName);
dbMigrateCommand.run(null, new Namespace(ImmutableMap.of()), conf);
// Tag them
dbTagCommand.run(null, new Namespace(ImmutableMap.of("tag-name", ImmutableList.of("v1"))), conf);
// Verify that the tag exists
try (CloseableLiquibase liquibase = dbTagCommand.openLiquibase(conf.getDataSource(), new Namespace(ImmutableMap.of()))) {
assertThat(liquibase.tagExists("v1")).isTrue();
}
}
use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.
the class DbCalculateChecksumCommandTest method testRun.
@Test
public void testRun() throws Exception {
final AtomicBoolean checkSumVerified = new AtomicBoolean();
migrateCommand.setCheckSumConsumer(checkSum -> {
assertThat(checkSum).isEqualTo(CheckSum.parse("7:3a61a7a72c9ce082b7059215975e6e09"));
checkSumVerified.set(true);
});
migrateCommand.run(null, new Namespace(ImmutableMap.of("id", ImmutableList.of("2"), "author", ImmutableList.of("db_dev"))), createConfiguration(getDatabaseUrl()));
assertThat(checkSumVerified.get()).isTrue();
}
use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.
the class DbCommandTest method testRunSubCommand.
@Test
public void testRunSubCommand() throws Exception {
final String databaseUrl = getDatabaseUrl();
final TestMigrationConfiguration conf = createConfiguration(databaseUrl);
dbCommand.run(null, new Namespace(ImmutableMap.of("subcommand", "migrate")), conf);
try (Handle handle = new DBI(databaseUrl, "sa", "").open()) {
assertThat(handle.createQuery("select count(*) from persons").mapTo(Integer.class).first()).isEqualTo(1);
}
}
use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.
the class DbLocksCommandTest method testFailsWhenNoListOrRelease.
@Test
public void testFailsWhenNoListOrRelease() throws Exception {
final Liquibase liquibase = Mockito.mock(Liquibase.class);
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> locksCommand.run(new Namespace(ImmutableMap.of("list", false, "release", false)), liquibase)).withMessage("Must specify either --list or --force-release");
}
Aggregations