Skip to content

Commit

Permalink
Update .slycatrc file from timeseries wizard #622
Browse files Browse the repository at this point in the history
  • Loading branch information
srbdev committed Aug 24, 2016
1 parent b351e36 commit 50ad0ea
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 14 deletions.
40 changes: 35 additions & 5 deletions agent/slycat-agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,46 @@ def get_user_config():

rc = os.path.expanduser('~') + ("/.slycatrc")
if os.path.isfile(rc):
parser = ConfigParser.SafeConfigParser()
parser.read(rc)
configuration = {section : {key : eval(value) for key, value in parser.items(section)} for section in parser.sections()}
results["config"] = configuration
results["errors"] = ""
try:
parser = ConfigParser.RawConfigParser()
parser.read(rc)
configuration = {section : {key : eval(value) for key, value in parser.items(section)} for section in parser.sections()}
results["config"] = configuration
results["errors"] = ""
except Exception as e:
results["config"] = {}
results["errors"] = "%s" % e
else:
results["config"] = "see errors"
results["errors"] = "the user does not have a .slycatrc file under their home directory"

sys.stdout.write("%s\n" % json.dumps(results))
sys.stdout.flush()

def set_user_config(command):
results = {
"ok": True,
"errors": ""
}
config = command["command"]["config"]

rc = os.path.expanduser('~') + ("/.slycatrc")
rc_file = open(rc, "w+")
parser = ConfigParser.RawConfigParser()

for section_key in config:
if not parser.has_section(section_key):
parser.add_section(section_key)
section = config[section_key]
for option_key in section:
if not str(section[option_key]) == "":
parser.set(section_key, option_key, "\"%s\"" % section[option_key])

parser.write(rc_file)
rc_file.close()
sys.stdout.write("%s\n" % json.dumps(results))
sys.stdout.flush()

def generate_batch(wckey, nnodes, partition, ntasks_per_node, time_hours, time_minutes, time_seconds, fn, tmp_file):
f = tmp_file

Expand Down Expand Up @@ -468,6 +496,8 @@ def main():
cancel_job(command)
elif action == "get-user-config":
get_user_config()
elif action == "set-user-config":
set_user_config(command)
else:
raise Exception("Unknown command.")
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions packages/slycat/web/server/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def abspath(path):
dispatcher.connect("get-job-output", "/remotes/get-job-output", slycat.web.server.handlers.get_job_output, conditions={ "method": ["POST"] })
dispatcher.connect("post-agent-function", "/remotes/run-agent-function", slycat.web.server.handlers.run_agent_function, conditions={ "method": ["POST"] })
dispatcher.connect("get-user-config", "/remotes/get-user-config", slycat.web.server.handlers.get_user_config, conditions={ "method": ["POST"] })
dispatcher.connect("set-user-config", "/remotes/set-user-config", slycat.web.server.handlers.set_user_config, conditions={ "method": ["POST"] })

dispatcher.connect("post-uploads", "/uploads", slycat.web.server.handlers.post_uploads, conditions={"method" : ["POST"]})
dispatcher.connect("put-upload-file-part", "/uploads/:uid/files/:fid/parts/:pid", slycat.web.server.handlers.put_upload_file_part, conditions={"method" : ["PUT"]})
Expand Down
8 changes: 8 additions & 0 deletions packages/slycat/web/server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,14 @@ def get_user_config():
with slycat.web.server.remote.get_session(sid) as session:
return session.get_user_config()

@cherrypy.tools.json_in(on = True)
@cherrypy.tools.json_out(on = True)
def set_user_config():
sid = cherrypy.request.json["sid"]
config = cherrypy.request.json["config"]
with slycat.web.server.remote.get_session(sid) as session:
return session.set_user_config(config)

@cherrypy.tools.json_in(on = True)
@cherrypy.tools.json_out(on = True)
def run_agent_function():
Expand Down
46 changes: 37 additions & 9 deletions packages/slycat/web/server/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,31 @@ def get_user_config(self):
slycat.email.send_error("slycat.web.server.remote.py get_user_config", "cherrypy.HTTPError 500 no Slycat agent present on remote host.")
raise cherrypy.HTTPError(500)

def set_user_config(self, config):
"""Submits a command to the slycat-agent to set the content of a user's .slycatrc file in their home directory.
Returns
-------
response : dict
"""
if self._agent is not None:
stdin, stdout, stderr = self._agent
payload = { "action": "set-user-config", "command": { "config": config } }

stdin.write("%s\n" % json.dumps(payload))
stdin.flush()

response = json.loads(stdout.readline())
if not response["ok"]:
cherrypy.response.headers["x-slycat-message"] = response["message"]
slycat.email.send_error("slycat.web.server.remote.py set_user_config", "cherrypy.HTTPError 400 %s" % response["message"])
raise cherrypy.HTTPError(400)
return { "errors": response["errors"] }
else:
cherrypy.response.headers["x-slycat-message"] = "No Slycat agent present on remote host."
slycat.email.send_error("slycat.web.server.remote.py set_user_config", "cherrypy.HTTPError 500 no Slycat agent present on remote host.")
raise cherrypy.HTTPError(500)

def run_agent_function(self, wckey, nnodes, partition, ntasks_per_node, time_hours, time_minutes, time_seconds, fn, fn_params, uid):
"""Submits a command to the slycat-agent to run a predefined function on a cluster running SLURM.
Expand Down Expand Up @@ -392,25 +417,28 @@ def create_distance_matrix(fn_id, params):
def compute_timeseries(fn_id, params):
arr = list(ipython_parallel_setup_arr)

# uncomment this line for production
if params["to_hdf5"] is True:
if params["timeseries_type"] == "csv":
arr.append("python $SLYCAT_HOME/agent/slycat-timeseries-to-hdf5.py --output-directory \"%s\" --id-column=\"%s\" --inputs-file \"%s\" --inputs-file-delimiter=%s --force" % (params["output_directory"], params["id_column"], params["inputs_file"], params["inputs_file_delimiter"]))
# uncomment this line for production
# arr.append("python $SLYCAT_HOME/agent/slycat-timeseries-to-hdf5.py --output-directory \"%s\" --id-column=\"%s\" --inputs-file \"%s\" --inputs-file-delimiter=%s --force" % (params["output_directory"], params["id_column"], params["inputs_file"], params["inputs_file_delimiter"]))
# uncomment this line for local development
# arr.append("python slycat-timeseries-to-hdf5.py --output-directory \"%s\" --id-column=\"%s\" --inputs-file \"%s\" --inputs-file-delimiter=%s --force" % (params["output_directory"], params["id_column"], params["inputs_file"], params["inputs_file_delimiter"]))
arr.append("python slycat-timeseries-to-hdf5.py --output-directory \"%s\" --id-column=\"%s\" --inputs-file \"%s\" --inputs-file-delimiter=%s --force" % (params["output_directory"], params["id_column"], params["inputs_file"], params["inputs_file_delimiter"]))
if params["timeseries_type"] == "xyce":
arr.append("python $SLYCAT_HOME/agent/slycat-xyce-timeseries-to-hdf5.py --id-column=\"%s\" --timeseries-file=\"%s\" --force \"%s\" \"%s\"" % (params["id_column"], params["xyce_timeseries_file"], params["input_directory"], params["output_directory"]))
# uncomment this line for production
# arr.append("python $SLYCAT_HOME/agent/slycat-xyce-timeseries-to-hdf5.py --id-column=\"%s\" --timeseries-file=\"%s\" --force \"%s\" \"%s\"" % (params["id_column"], params["xyce_timeseries_file"], params["input_directory"], params["output_directory"]))
# uncomment this line for locat development
# arr.append("python slycat-xyce-timeseries-to-hdf5.py --id-column=\"%s\" --timeseries-file=\"%s\" --force \"%s\" \"%s\"" % (params["id_column"], params["xyce_timeseries_file"], params["input_directory"], params["output_directory"]))
arr.append("python slycat-xyce-timeseries-to-hdf5.py --id-column=\"%s\" --timeseries-file=\"%s\" --force \"%s\" \"%s\"" % (params["id_column"], params["xyce_timeseries_file"], params["input_directory"], params["output_directory"]))

if params["timeseries_type"] == "csv":
arr.append("python $SLYCAT_HOME/agent/slycat-agent-compute-timeseries.py \"%s\" --timeseries-name=\"%s\" --cluster-sample-count %s --cluster-sample-type %s --cluster-type %s --cluster-metric %s --workdir \"%s\" --hash %s --profile ${profile}" % (params["output_directory"], params["timeseries_name"], params["cluster_sample_count"], params["cluster_sample_type"], params["cluster_type"], params["cluster_metric"], params["workdir"], uid))
# uncomment this line for production
# arr.append("python $SLYCAT_HOME/agent/slycat-agent-compute-timeseries.py \"%s\" --timeseries-name=\"%s\" --cluster-sample-count %s --cluster-sample-type %s --cluster-type %s --cluster-metric %s --workdir \"%s\" --hash %s --profile ${profile}" % (params["output_directory"], params["timeseries_name"], params["cluster_sample_count"], params["cluster_sample_type"], params["cluster_type"], params["cluster_metric"], params["workdir"], uid))
# uncomment this line for local development
# arr.append("python slycat-agent-compute-timeseries.py \"%s\" --timeseries-name=\"%s\" --cluster-sample-count %s --cluster-sample-type %s --cluster-type %s --cluster-metric %s --workdir \"%s\" --hash %s --profile ${profile}" % (params["output_directory"], params["timeseries_name"], params["cluster_sample_count"], params["cluster_sample_type"], params["cluster_type"], params["cluster_metric"], params["workdir"], uid))
arr.append("python slycat-agent-compute-timeseries.py \"%s\" --timeseries-name=\"%s\" --cluster-sample-count %s --cluster-sample-type %s --cluster-type %s --cluster-metric %s --workdir \"%s\" --hash %s --profile ${profile}" % (params["output_directory"], params["timeseries_name"], params["cluster_sample_count"], params["cluster_sample_type"], params["cluster_type"], params["cluster_metric"], params["workdir"], uid))
if params["timeseries_type"] == "xyce":
arr.append("python $SLYCAT_HOME/agent/slycat-agent-compute-timeseries.py \"%s\" --cluster-sample-count %s --cluster-sample-type %s --cluster-type %s --cluster-metric %s --workdir \"%s\" --hash %s --profile ${profile}" % (params["output_directory"], params["cluster_sample_count"], params["cluster_sample_type"], params["cluster_type"], params["cluster_metric"], params["workdir"], uid))
# uncomment this line for production
# arr.append("python $SLYCAT_HOME/agent/slycat-agent-compute-timeseries.py \"%s\" --cluster-sample-count %s --cluster-sample-type %s --cluster-type %s --cluster-metric %s --workdir \"%s\" --hash %s --profile ${profile}" % (params["output_directory"], params["cluster_sample_count"], params["cluster_sample_type"], params["cluster_type"], params["cluster_metric"], params["workdir"], uid))
# uncomment this line for local development
# arr.append("python slycat-agent-compute-timeseries.py \"%s\" --cluster-sample-count %s --cluster-sample-type %s --cluster-type %s --cluster-metric %s --workdir \"%s\" --hash %s --profile ${profile}" % (params["output_directory"], params["cluster_sample_count"], params["cluster_sample_type"], params["cluster_type"], params["cluster_metric"], params["workdir"], uid))
arr.append("python slycat-agent-compute-timeseries.py \"%s\" --cluster-sample-count %s --cluster-sample-type %s --cluster-type %s --cluster-metric %s --workdir \"%s\" --hash %s --profile ${profile}" % (params["output_directory"], params["cluster_sample_count"], params["cluster_sample_type"], params["cluster_type"], params["cluster_metric"], params["workdir"], uid))


return arr
Expand Down
20 changes: 20 additions & 0 deletions web-server/js/slycat-web-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,26 @@ define("slycat-web-client", ["slycat-server-root", "jquery", "URI"], function(se
});
};

module.set_user_config = function(params) {
$.ajax({
contentType: 'application/json',
data: JSON.stringify({
sid: params.sid,
config: params.config
}),
type: 'POST',
url: server_root + 'remotes/set-user-config',
success: function(result) {
if (params.success)
params.success(result);
},
error: function(request, status, reason_phrase) {
if (params.error)
params.error(request, status, reason_phrase);
}
});
};

module.post_agent_function = function(params) {
$.ajax({
contentType: 'application/json',
Expand Down
48 changes: 48 additions & 0 deletions web-server/plugins/slycat-timeseries-model/wizard-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,39 @@ define(['slycat-server-root', 'slycat-web-client', 'slycat-dialog', 'slycat-mark
component.cluster_sample_type = ko.observableArray(['uniform-paa', 'uniform-pla']);
component.cluster_type = ko.observableArray(['average', 'single', 'complete', 'weighted']);
component.cluster_metric = ko.observableArray(['euclidean']);
// SLURM parameters
component.wckey = ko.observable('');
component.partition = ko.observable('');
component.workdir = ko.observable('');
component.nnodes = ko.observable('');
component.ntasks_per_node = ko.observable('');
component.time_hours = ko.observable('');
component.time_minutes = ko.observable('');
component.time_seconds = ko.observable('');

component.user_config = {};

var removeErrors = function() {
$('.form-group').removeClass('has-error');
};

var updateUserConfig = function() {
component.user_config['timeseries-wizard'] = component.user_config['timeseries-wizard'] || {};
component.user_config['timeseries-wizard']['persistent-output'] = component.output_directory();
component.user_config['timeseries-wizard']['id-column'] = component.id_column();
component.user_config['timeseries-wizard']['inputs-file-delimiter'] = component.inputs_file_delimiter();
component.user_config['timeseries-wizard']['timeseries-name'] = component.timeseries_name();

client.set_user_config({
sid: component.remote.sid(),
config: component.user_config,
success: function(response) { },
error: function(request, status, reason_phrase) {
console.log(reason_phrase);
}
});
};

component.create_model = function() {
client.post_project_models({
pid: component.project._id(),
Expand Down Expand Up @@ -82,14 +106,22 @@ define(['slycat-server-root', 'slycat-web-client', 'slycat-dialog', 'slycat-mark
if (response.config['timeseries-wizard']) {
response.config['timeseries-wizard']['persistent-output'] ? component.output_directory(response.config['timeseries-wizard']['persistent-output']) : null;
response.config['timeseries-wizard']['timeseries-name'] ? component.timeseries_name(response.config['timeseries-wizard']['timeseries-name']) : null;
response.config['timeseries-wizard']['id-column'] ? component.id_column(response.config['timeseries-wizard']['id-column']) : null;
response.config['timeseries-wizard']['inputs-file-delimiter'] ? component.inputs_file_delimiter(response.config['timeseries-wizard']['inputs-file-delimiter']) : null;
}

if (response.config.slurm) {
response.config.slurm.wcid ? component.wckey(response.config.slurm.wcid) : null;
response.config.slurm.partition ? component.partition(response.config.slurm.partition) : null;
response.config.slurm.workdir ? component.workdir(response.config.slurm.workdir) : null;
response.config.slurm.nnodes ? component.nnodes(response.config.slurm.nnodes) : null;
response.config.slurm['ntasks-per-node'] ? component.ntasks_per_node(response.config.slurm['ntasks-per-node']) : null;
response.config.slurm['time-hours'] ? component.time_hours(response.config.slurm['time-hours']) : null;
response.config.slurm['time-minutes'] ? component.time_minutes(response.config.slurm['time-minutes']) : null;
response.config.slurm['time-seconds'] ? component.time_seconds(response.config.slurm['time-seconds']) : null;
}

component.user_config = response.config;
component.tab(2);
}
});
Expand Down Expand Up @@ -222,15 +254,31 @@ define(['slycat-server-root', 'slycat-web-client', 'slycat-dialog', 'slycat-mark
vm.wckey(component.wckey());
vm.partition(component.partition());
vm.workdir(component.workdir());
vm.nnodes(component.nnodes());
vm.ntasks_per_node(component.ntasks_per_node());
vm.time_hours(component.time_hours());
vm.time_minutes(component.time_minutes());
vm.time_seconds(component.time_seconds());
}
};

component.compute = function() {
var vm = ko.dataFor($('.slycat-remote-interface')[0]);
vm.submit_job();

component.user_config['slurm'] = component.user_config['slurm'] || {};
component.user_config['slurm']['wcid'] = vm.wckey();
component.user_config['slurm']['partition'] = vm.partition();
component.user_config['slurm']['workdir'] = vm.workdir();
component.user_config['slurm']['time-hours'] = vm.time_hours();
component.user_config['slurm']['time-minutes'] = vm.time_minutes();
component.user_config['slurm']['time-seconds'] = vm.time_seconds();
component.user_config['slurm']['nnodes'] = vm.nnodes();
component.user_config['slurm']['ntasks-per-node'] = vm.ntasks_per_node();
};

component.to_compute_next_step = function() {
updateUserConfig();
component.tab(6);
};

Expand Down

0 comments on commit 50ad0ea

Please sign in to comment.