Permalink
Browse files

Changed the configuration system to refelct the separation between th…

…e http request handling and the name processing.

The http request handling and host details are now all configured via the tnrs_handler/config.yml file. The new options are:
* hostname: The name that will be used for redirects and will appear in messages returned by the service.
* prefix: The top level resource identifier.
An example config.yml file is included.

The handler_config.json file now only contains target directories and runtime options.

In addition I've made some layout and text changes.
  • Loading branch information...
1 parent 5222552 commit 9cedf2ad62360a700bff5a1cb22829d347914395 Naim Matasci committed Aug 17, 2012
View
@@ -20,3 +20,4 @@ tnrs_handler/bin/handler_config.json
testdata/names.test*
tnrs_handler/.tnrs_handler.pid
tnrs_handler/Makefile.old
+tnrs_handler/config.yml
@@ -27,4 +27,8 @@ template: "simple"
# start_tag: '[%'
# end_tag: '%]'
daemon: true
+
+#Host info
+host: "http://www.taxosaurus.org"
port: 80
+#prefix: "/tnrs"
@@ -18,7 +18,7 @@ use JSON;
our @ISA = qw(Exporter);
our @EXPORT = qw(get_cfg call_fun);
-our $VERSION = '0.1.0';
+our $VERSION = '0.1.1';
#################################
#Constants
@@ -28,7 +28,7 @@ our $VERSION = '0.1.0';
my $CALLS = {
sources_list => \&sources_list,
sources_SourceId => \&sources_SourceId,
- admin_reload_sources => \&admin_reload_sources,
+ admin_reload_sources => \&admin_reload_sources,
submit => \&submit,
retrieve_Job_id => \&retrieve_Job_id,
delete_Job_id => \&delete_Job_id,
@@ -96,10 +96,8 @@ sub delete_Job_id {
if ( -f "$cfg->{storage}/$job_id.json" ) {
return encode_json(
{
- 'status' => 'found',
- 'message' =>
-"The requested job $job_id has completed. You can retrieve the results at $cfg->{host}/retrieve/$job_id",
- 'uri' => "$cfg->{host}/retrieve/$job_id",
+ 'status' => 'found',
+ 'message' => "The requested job $job_id has completed.",
}
);
}
@@ -245,7 +243,7 @@ sub sources_SourceId {
my @sources = @{ $cfg->{modules}->{adapters} };
- #Problem: There are no source.
+ #Problem: There are no sources.
if ( !@sources ) {
return encode_json(
{
@@ -290,9 +288,6 @@ sub _init {
my @cfg = (<$CFG>);
close $CFG;
my $cfg_ref = decode_json( join '', @cfg );
- my $host = $cfg_ref->{host};
- $host = $cfg_ref->{port} ? "$host:" . $cfg_ref->{port} : $host;
- $cfg_ref->{host} = $host;
#load adapters registry
$cfg_ref->{modules} = _load_modules( $cfg_ref->{adapters_file} );
@@ -9,21 +9,56 @@
package tnrs_handler;
use handler_lib qw(get_cfg call_fun);
-use Dancer ':syntax';
use JSON;
+use Dancer ':syntax';
use Digest::MD5 qw(md5_hex);
+use Sys::Hostname;
+
+our $VERSION = '2.1.2';
-our $VERSION = '2.1.1';
+my $DEF_CONFIG = "handler_config.json";
-my $config_file_path = "handler_config.json";
-my $cfg = get_cfg($config_file_path);
+my $cfg = init($DEF_CONFIG);
+
+sub init {
+ my $def_config_file = shift;
+
+ my $handler_cfg = config->{handler_cfg};
+ if ( !$handler_cfg ) {
+ $handler_cfg = $def_config_file;
+ }
-my $n_pids = 0;
-if(!$cfg->{prefix}){
- prefix undef;
-} else{
- prefix $cfg->{prefix};
-}
+ my $_cfg = get_cfg($handler_cfg);
+
+ $_cfg->{prefix} = config->{prefix};
+ if ( !$_cfg->{prefix} ) {
+ prefix undef;
+ }
+ else {
+ prefix $_cfg->{prefix};
+ }
+
+ $_cfg->{host} = config->{hostname};
+ if ( !$_cfg->{host} ) {
+ $_cfg->{host} = hostname;
+ }
+ if ( $_cfg->{host} !~ /^http/ ) {
+ $_cfg->{host} = "http://$_cfg->{host}";
+ }
+
+ $_cfg->{port} = config->{port};
+ if ( !$_cfg->{port} ) {
+ $_cfg->{host} = "$_cfg->{host}:3000";
+ }
+ elsif ( $_cfg->{port} eq '80' ) {
+ $_cfg->{host} = $_cfg->{host};
+ }
+ else {
+ $_cfg->{host} = "$_cfg->{host}:$_cfg->{port}";
+ }
+ return $_cfg;
+
+}
#TODO: Add cache
@@ -48,7 +83,8 @@ sub call {
#Information
get '/' => sub {
- template 'index' => { host => $cfg->{host}, prefix => $cfg->{prefix}, version => $VERSION };
+ template 'index' =>
+ { host => $cfg->{host}, prefix => $cfg->{prefix}, version => $VERSION };
};
#Only for debugging purposes
@@ -139,7 +175,14 @@ any [ 'del', 'get', 'post' ] => '/delete/:job_id?' => sub {
"Please specify a job id. Usage: DELETE | GET | POST $cfg->{'host'}$cfg->{'prefix'}/delete/&ltjob_id&gt"
);
}
- return call( 'delete_Job_id', param('job_id') );
+ my $job_id = param('job_id');
+ my $ret = decode_json( call( 'delete_Job_id', $job_id ) );
+ if ( $ret->{'status'} eq 'found' ) {
+ $ret->{'message'} .=
+ "You can retrieve the results at $cfg->{host}/retrieve/$job_id",
+ $ret->{'uri'} = "$cfg->{host}/retrieve/$job_id";
+ }
+ return encode_json($ret);
};
#Stores a submitted list of names in a temporary file
@@ -2,15 +2,16 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
-<title>Welcome to TNRastic</title>
+<title>Welcome to Taxosaurus</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
- <img src="images/Phylotastic_logo.png" width="500px"/><h1>TNRastic - the Phylotastic Taxonomic Name Resolution Service version <% version %></h1>
- <p>Submit a list of scientific names to obtain the accepted name
- across various taxonomic sources. Fore more information, please visit <a
+ <img src="images/Phylotastic_logo.png" width="500px"/><h1>Taxosaurus - <i>The Taxonomic Thesaurus</i></h1>
+ <h2>Submit a list of scientific names to obtain the accepted name across various taxonomic sources.</h2>
+ <p>Taxosaurus is a meta Taxonomic Name Resolution Service that implements the Phylotastic TNRastic API.<br />Fore more information, please visit <a
href="http://www.evoio.org/wiki/Phylotastic/TNRS">http://www.evoio.org/wiki/Phylotastic/TNRS</a>.</p>
+
<div id="service"> <endpoint><% prefix %>/submit</endpoint>
<p>
@@ -117,6 +118,7 @@
</ul>
</p>
</div>
+ <div id="footer">Version <% version %></div>
<a class="img" href="http://www.iplantcollaborative.org" target="_blank"><img class="powered" src="images/iplant_power.png" width="100px"/></a>
</body>
</html>
@@ -3,7 +3,6 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=<% settings.charset %>" />
-<title>tnrs_handler</title>
<link rel="stylesheet" href="<% request.uri_base %>/css/style.css" />
<!-- Grab Google CDN's jQuery. fall back to local if necessary -->

0 comments on commit 9cedf2a

Please sign in to comment.