-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New paradigm: - M&C DB has authoritative "observation" table - Librarian DB has clone of this table Changes - separate config file for M&C (~/.hera_mc) - change low-level DB code to handle separate DBs - change setup scripts to create M&C items - add PHP and Python bindings of M&C RPCs - both DBs have "source" and "observation" tables; keep code in a common place (db_util.inc)
- Loading branch information
1 parent
e1248f3
commit e3b8715
Showing
19 changed files
with
408 additions
and
172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
// MySQL code for MC and Librarian DBs | ||
|
||
$link = null; | ||
$db_error = ''; | ||
define('LIBRARIAN_DB_NAME', 'hera_lib'); | ||
define('MC_DB_NAME', 'hera_mc'); | ||
|
||
function init_db($db_name) { | ||
global $link; | ||
$link = @mysqli_connect('', '', '', $db_name); | ||
return $link; | ||
} | ||
|
||
function insert_id() { | ||
global $link; | ||
return mysqli_insert_id($link); | ||
} | ||
|
||
function db_error() { | ||
global $link; | ||
return mysqli_error($link); | ||
} | ||
|
||
function enum($table, $clause=null) { | ||
global $link; | ||
if (!$clause) $clause = 'TRUE'; | ||
$query = "select * from $table where $clause"; | ||
$r = mysqli_query($link, $query); | ||
$items = array(); | ||
while ($f = mysqli_fetch_object($r)) { | ||
$items[] = $f; | ||
} | ||
mysqli_free_result($r); | ||
return $items; | ||
} | ||
|
||
function lookup_id($table, $id) { | ||
global $link; | ||
$query = "select * from $table where id=$id"; | ||
$r = mysqli_query($link, $query); | ||
$source = mysqli_fetch_object($r); | ||
mysqli_free_result($r); | ||
return $source; | ||
} | ||
|
||
//// SOURCE //// | ||
|
||
function source_insert($source) { | ||
global $link; | ||
$auth = $link->escape_string($source->authenticator); | ||
$query = "insert into source (name, authenticator, create_time) values ('$source->name', '$auth', $source->create_time)"; | ||
return mysqli_query($link, $query); | ||
} | ||
|
||
function source_lookup_auth($auth) { | ||
global $link; | ||
$auth = $link->escape_string($auth); | ||
$query = "select * from source where authenticator='$auth'"; | ||
$r = mysqli_query($link, $query); | ||
$source = mysqli_fetch_object($r); | ||
mysqli_free_result($r); | ||
return $source; | ||
} | ||
|
||
function source_lookup_id($id) { | ||
return lookup_id("source", $id); | ||
} | ||
|
||
function source_enum() { | ||
return enum('source'); | ||
} | ||
|
||
//// OBSERVATION //// | ||
|
||
function observation_insert_hl($obs) { | ||
global $link; | ||
$polarization = $link->escape_string($obs->polarization); | ||
$query = "insert into observation (id, source_id, julian_date, polarization, length_days) values ($obs->id, $obs->source_id, $obs->julian_date, '$polarization', $obs->length_days)"; | ||
return mysqli_query($link, $query); | ||
} | ||
|
||
function observation_insert_mc($obs) { | ||
global $link; | ||
$polarization = $link->escape_string($obs->polarization); | ||
$query = "insert into observation (source_id, julian_date, polarization, length_days) values ($obs->source_id, $obs->julian_date, '$polarization', $obs->length_days)"; | ||
return mysqli_query($link, $query); | ||
} | ||
|
||
function observation_lookup_id($id) { | ||
return lookup_id("observation", $id); | ||
} | ||
|
||
?> |
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 |
---|---|---|
@@ -1,42 +1,15 @@ | ||
import os | ||
import urllib | ||
import json | ||
|
||
# parse config file, return as a dictionary | ||
# | ||
def get_config(): | ||
path = os.path.expanduser('~/.hera_librarian') | ||
f = open(path, 'r') | ||
config = {} | ||
for line in f: | ||
wds = line.split() | ||
config[wds[0]] = wds[1] | ||
f.close() | ||
return config | ||
|
||
# do a POST operation, | ||
# passing a JSON version of the request and expecting a JSON reply; | ||
# return the decoded version of the latter. | ||
# | ||
def do_http_post(req, config): | ||
req_json = json.dumps(req) | ||
params = urllib.urlencode({'request': req_json}) | ||
url = config['server']+'/hl_rpc_handler.php' | ||
f = urllib.urlopen(url , params); | ||
reply_json = f.read() | ||
reply = json.loads(reply_json) | ||
return reply | ||
import hera_rpc | ||
|
||
# RPC to create a file | ||
# | ||
def create_file(name, size, md5, store_name): | ||
config = get_config() | ||
config = get_config('.hera_librarian') | ||
req = {'operation': 'create_file', | ||
'authenticator': config['authenticator'], | ||
'name': name, | ||
'size': size, | ||
'md5': md5, | ||
'store_name': store_name} | ||
return do_http_post(req, config) | ||
return do_http_post(req, config['server']) | ||
|
||
#create_file('filename2', 2e9, 'ajfjfkdjffjf', 'UCB RAID') |
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,15 @@ | ||
import hera_rpc | ||
|
||
# Python binding of M&C RPCs | ||
|
||
# create an observation | ||
# | ||
def create_observation(julian_date, polarization, length): | ||
config = get_config('.hera_mc') | ||
req = {'operation': 'create_observation', | ||
'authenticator': config['authenticator'], | ||
'name': name, | ||
'size': size, | ||
'md5': md5, | ||
'store_name': store_name} | ||
return do_http_post(req, config['server']) |
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,31 @@ | ||
# utility functions for Python RPC bindings | ||
|
||
import os | ||
import urllib | ||
import json | ||
|
||
# parse config file, return as a dictionary | ||
# | ||
def get_config(file): | ||
path = os.path.expanduser('~/'+file) | ||
f = open(path, 'r') | ||
config = {} | ||
for line in f: | ||
wds = line.split() | ||
config[wds[0]] = wds[1] | ||
f.close() | ||
return config | ||
|
||
# do a POST operation, | ||
# passing a JSON version of the request and expecting a JSON reply; | ||
# return the decoded version of the latter. | ||
# | ||
def do_http_post(req, server): | ||
req_json = json.dumps(req) | ||
params = urllib.urlencode({'request': req_json}) | ||
url = server+'/hl_rpc_handler.php' | ||
f = urllib.urlopen(url , params); | ||
reply_json = f.read() | ||
reply = json.loads(reply_json) | ||
return reply | ||
|
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.