From e62406dffc3ec4e6e0c04f66b39fddfc7beace5c Mon Sep 17 00:00:00 2001 From: valentine-mario Date: Fri, 17 Dec 2021 09:06:08 +0100 Subject: [PATCH 1/8] port stop rnode --- bootstrap/stop-rnode.js | 33 +++++++++++++++++++++++++++++++++ bootstrap/util/exec_script.js | 13 +++++++++++++ src/MasterURI.localhost.json | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 bootstrap/stop-rnode.js create mode 100644 bootstrap/util/exec_script.js diff --git a/bootstrap/stop-rnode.js b/bootstrap/stop-rnode.js new file mode 100644 index 00000000..3867dec7 --- /dev/null +++ b/bootstrap/stop-rnode.js @@ -0,0 +1,33 @@ +const exec_shell = require('./util/exec_script'); +const readline = require('readline'); +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); +const main = async () => { + //get current pid for rnode + const shell_output = await exec_shell( + `ps aux |grep -v grep | grep "java .*rnode"|sed 's/[ \t][ \t]*/ /g'|cut -d' ' -f 2`, + ); + if (!shell_output) { + rl.close(); + return; + } + const formatted_string = shell_output.replace(/\r?\n|\r/g, ' '); + console.log( + `rnode is currently running. Use 'kill ${formatted_string}' to fix`, + ); + rl.question(`Execute 'kill ${formatted_string}' [y]? `, async (reply) => { + if ( + reply.toLocaleLowerCase() === 'yes' || + reply.toLocaleLowerCase() === 'y' + ) { + await exec_shell(`kill ${formatted_string}`); + } else { + console.log('Aboring ...'); + } + rl.close(); + }); +}; + +main(); diff --git a/bootstrap/util/exec_script.js b/bootstrap/util/exec_script.js new file mode 100644 index 00000000..218d0cf9 --- /dev/null +++ b/bootstrap/util/exec_script.js @@ -0,0 +1,13 @@ +const { exec } = require('child_process'); + +//execute shell script within node js +function exec_shell(cmd) { + return new Promise((resolve, reject) => { + exec(cmd, (err, stdout, _stdin) => { + if (err) throw err; + resolve(stdout); + }); + }); +} + +module.exports = exec_shell; diff --git a/src/MasterURI.localhost.json b/src/MasterURI.localhost.json index fa35b36c..c3441ecb 100644 --- a/src/MasterURI.localhost.json +++ b/src/MasterURI.localhost.json @@ -1,3 +1,3 @@ {"localhostNETWORK": { "MasterURI": -"`rho:id:ao5pwhsj6sjtequ47oo8d6jw4dyu7fk89nmzsofjxz7j1d68go58ao`" +"`rho:id:aodxqsafr1mbbfjr5p6bzyiqydncd7qfxh8jdhgmwxdb71hh3kqfkq`" }} From a82b55968298ed9a32f778621645f3f59819b7a7 Mon Sep 17 00:00:00 2001 From: valentine-mario Date: Fri, 17 Dec 2021 09:33:03 +0100 Subject: [PATCH 2/8] port check node --- bootstrap/check-rnode.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 bootstrap/check-rnode.js diff --git a/bootstrap/check-rnode.js b/bootstrap/check-rnode.js new file mode 100644 index 00000000..73950fd1 --- /dev/null +++ b/bootstrap/check-rnode.js @@ -0,0 +1,14 @@ +const exec_shell = require('./util/exec_script'); + +const main = async () => { + const shell_output = await exec_shell( + `ps aux |grep -v grep | grep "java .*rnode"|sed 's/[ \t][ \t]*/ /g'|cut -d' ' -f 2`, + ); + if (!shell_output) { + console.log( + `rnode is NOT currently running. Run "node run-rnode.js" to fix.`, + ); + } +}; + +main(); From 542b0196f5dfda4df680ef63eb05b7601df713d1 Mon Sep 17 00:00:00 2001 From: valentine-mario Date: Fri, 17 Dec 2021 12:50:00 +0100 Subject: [PATCH 3/8] port snapshot --- bootstrap/create-snapshot.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 bootstrap/create-snapshot.js diff --git a/bootstrap/create-snapshot.js b/bootstrap/create-snapshot.js new file mode 100644 index 00000000..6707876b --- /dev/null +++ b/bootstrap/create-snapshot.js @@ -0,0 +1,35 @@ +const fs = require('fs'); +const exec_shell = require('./util/exec_script'); + +const main = async () => { + //take snapshot name from arg + const arg_input = process.argv[2]; + if (arg_input === undefined) { + console.log('Please specify snapshot name'); + return; + } + + //check if .rnode dir exist + const homedir = require('os').homedir(); + if (!fs.existsSync(homedir + '/.rnode')) { + console.log(`Cannot snapshot: ${homedir}/.rnode does not exist`); + return; + } + + //run stop node script + require('child_process').fork('stop-rnode.js'); + + //create snapshot dir + await exec_shell(`mkdir -p snapshot`); + const target = `${__dirname}/snapshot/${arg_input}.tgz`; + + if (fs.existsSync(target)) { + console.log('snapshot already exist'); + return; + } + + await exec_shell(`cd ~ && tar czf "${target}" .rnode`); + console.log(`snapshot created: ${target}`); +}; + +main(); From 4e27b729ed6041c376a31c6bc09cce3c212c3be0 Mon Sep 17 00:00:00 2001 From: valentine-mario Date: Mon, 20 Dec 2021 08:00:26 +0100 Subject: [PATCH 4/8] updates implemeted --- bootstrap/create-snapshot.js | 45 ++++++++++++++++++------------------ bootstrap/stop-rnode.js | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/bootstrap/create-snapshot.js b/bootstrap/create-snapshot.js index 6707876b..618878b5 100644 --- a/bootstrap/create-snapshot.js +++ b/bootstrap/create-snapshot.js @@ -2,34 +2,33 @@ const fs = require('fs'); const exec_shell = require('./util/exec_script'); const main = async () => { - //take snapshot name from arg - const arg_input = process.argv[2]; - if (arg_input === undefined) { - console.log('Please specify snapshot name'); - return; - } + try { + //take snapshot name from arg + const arg_input = process.argv[2]; + if (arg_input === undefined) { + console.log('Please specify snapshot name'); + return; + } - //check if .rnode dir exist - const homedir = require('os').homedir(); - if (!fs.existsSync(homedir + '/.rnode')) { - console.log(`Cannot snapshot: ${homedir}/.rnode does not exist`); - return; - } + //check if .rnode dir exist + const homedir = require('os').homedir(); + if (!fs.existsSync(homedir + '/.rnode')) { + console.log(`Cannot snapshot: ${homedir}/.rnode does not exist`); + return; + } - //run stop node script - require('child_process').fork('stop-rnode.js'); + //run stop node script + require('child_process').fork('stop-rnode.js'); - //create snapshot dir - await exec_shell(`mkdir -p snapshot`); - const target = `${__dirname}/snapshot/${arg_input}.tgz`; + //create snapshot dir + fs.mkdirSync('snapshot', { recursive: true }); + const target = `${__dirname}/snapshot/${arg_input}.tgz`; - if (fs.existsSync(target)) { - console.log('snapshot already exist'); - return; + await exec_shell(`cd ~ && tar czf "${target}" .rnode`); + console.log(`snapshot created: ${target}`); + } catch (error) { + console.log(error); } - - await exec_shell(`cd ~ && tar czf "${target}" .rnode`); - console.log(`snapshot created: ${target}`); }; main(); diff --git a/bootstrap/stop-rnode.js b/bootstrap/stop-rnode.js index 3867dec7..63d17412 100644 --- a/bootstrap/stop-rnode.js +++ b/bootstrap/stop-rnode.js @@ -24,7 +24,7 @@ const main = async () => { ) { await exec_shell(`kill ${formatted_string}`); } else { - console.log('Aboring ...'); + console.log('Aborting ...'); } rl.close(); }); From 67adc552213ec06b899e27eafe09950da53f0f10 Mon Sep 17 00:00:00 2001 From: valentine-mario Date: Thu, 23 Dec 2021 08:28:09 +0100 Subject: [PATCH 5/8] bug fix --- bootstrap/create-snapshot.js | 47 +++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/bootstrap/create-snapshot.js b/bootstrap/create-snapshot.js index 618878b5..2cbf5fdf 100644 --- a/bootstrap/create-snapshot.js +++ b/bootstrap/create-snapshot.js @@ -1,5 +1,10 @@ const fs = require('fs'); const exec_shell = require('./util/exec_script'); +const readline = require('readline'); +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); const main = async () => { try { @@ -7,6 +12,7 @@ const main = async () => { const arg_input = process.argv[2]; if (arg_input === undefined) { console.log('Please specify snapshot name'); + rl.close(); return; } @@ -14,18 +20,47 @@ const main = async () => { const homedir = require('os').homedir(); if (!fs.existsSync(homedir + '/.rnode')) { console.log(`Cannot snapshot: ${homedir}/.rnode does not exist`); + rl.close(); return; } //run stop node script - require('child_process').fork('stop-rnode.js'); + const cp = require('child_process').fork('stop-rnode.js'); + cp.on('close', async (code, signal) => { + //if stop script terminates with error, exit + if (code === 1) { + rl.close(); + return; + } + fs.mkdirSync('snapshot', { recursive: true }); + const target = `${__dirname}/snapshot/${arg_input}.tgz`; + + if (fs.existsSync(target)) { + //if snapshot exist, alert user to override or exit + rl.question( + `Snapshot exist. Create new snapshot [y]? `, + async (reply) => { + if ( + reply.toLocaleLowerCase() === 'yes' || + reply.toLocaleLowerCase() === 'y' + ) { + await exec_shell(`cd ~ && tar czf "${target}" .rnode`); + console.log(`snapshot created: ${target}`); + rl.close(); + } else { + console.log('Aborting...'); + rl.close(); + } + }, + ); + } else { + await exec_shell(`cd ~ && tar czf "${target}" .rnode`); + console.log(`snapshot created: ${target}`); + rl.close(); + } + }); //create snapshot dir - fs.mkdirSync('snapshot', { recursive: true }); - const target = `${__dirname}/snapshot/${arg_input}.tgz`; - - await exec_shell(`cd ~ && tar czf "${target}" .rnode`); - console.log(`snapshot created: ${target}`); } catch (error) { console.log(error); } From 2124b6f990da9f72080d3e8801f843d8cdb4da72 Mon Sep 17 00:00:00 2001 From: K Momchilov Date: Fri, 24 Dec 2021 00:00:36 +0000 Subject: [PATCH 6/8] sequential loop example action (#278) --- src/actions.js | 7 ++++++ src/actions/sequencialLooping.rho | 38 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/actions/sequencialLooping.rho diff --git a/src/actions.js b/src/actions.js index 4af8fb00..c08ae9bc 100644 --- a/src/actions.js +++ b/src/actions.js @@ -23,6 +23,13 @@ export const actions = { }, filename: 'actions/transfer.rho', }, + _____________________________________: { + fields: {}, +}, + sequencialLooping: { + fields: {}, + filename: 'actions/sequencialLooping.rho', +}, _____________________________: { fields: {}, }, diff --git a/src/actions/sequencialLooping.rho b/src/actions/sequencialLooping.rho new file mode 100644 index 00000000..4d2d5d8a --- /dev/null +++ b/src/actions/sequencialLooping.rho @@ -0,0 +1,38 @@ +match [] { + [] => { + new output, num, increaseByNum, increase, currentCount in { + currentCount!(0) | + contract increase(ack) = { + for(old <- currentCount) { + currentCount!(*old + 1) | + ack!(*old) + } + + } | + contract increaseByNum(num, ack) = { + // output!(*num) | + match *num { + 0 => { + output!("Recursion finished.") | + ack!(Nil) + } + _ => { + new kiril in { + for (k <- kiril) { ack!(Nil) } | + output!(*num) | + increase!(*num) | + increaseByNum!(*num-1, *kiril) + } + } + } + } | + new finished in { + increaseByNum!(500, *finished) | + for (_ <- finished) { + for (cc <- currentCount) { + output!({"Current count": *cc}) + } + } + } + } +} From edec5069795d3a9794f69bc7ecaa6dd10fb1f5ce Mon Sep 17 00:00:00 2001 From: Valentine-Mario Date: Sun, 30 Jan 2022 11:15:39 +0100 Subject: [PATCH 7/8] minor updates --- bootstrap/create-snapshot.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bootstrap/create-snapshot.js b/bootstrap/create-snapshot.js index 2cbf5fdf..c73783b9 100644 --- a/bootstrap/create-snapshot.js +++ b/bootstrap/create-snapshot.js @@ -13,7 +13,7 @@ const main = async () => { if (arg_input === undefined) { console.log('Please specify snapshot name'); rl.close(); - return; + return {message:"failed"} } //check if .rnode dir exist @@ -21,7 +21,7 @@ const main = async () => { if (!fs.existsSync(homedir + '/.rnode')) { console.log(`Cannot snapshot: ${homedir}/.rnode does not exist`); rl.close(); - return; + return {message:"failed"} } //run stop node script @@ -30,7 +30,7 @@ const main = async () => { //if stop script terminates with error, exit if (code === 1) { rl.close(); - return; + return {message:"failed"}; } fs.mkdirSync('snapshot', { recursive: true }); const target = `${__dirname}/snapshot/${arg_input}.tgz`; @@ -47,9 +47,11 @@ const main = async () => { await exec_shell(`cd ~ && tar czf "${target}" .rnode`); console.log(`snapshot created: ${target}`); rl.close(); + return {message:"successful"} } else { console.log('Aborting...'); rl.close(); + return {message:"failed"} } }, ); @@ -57,6 +59,7 @@ const main = async () => { await exec_shell(`cd ~ && tar czf "${target}" .rnode`); console.log(`snapshot created: ${target}`); rl.close(); + return {message:"successful"} } }); From 21a025e6dcfda347aafe7de7c0e2e65182a819b3 Mon Sep 17 00:00:00 2001 From: Valentine-Mario Date: Sun, 30 Jan 2022 11:26:31 +0100 Subject: [PATCH 8/8] resolvecd conflict --- bootstrap/cli-utils/create-snapshot-script.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bootstrap/cli-utils/create-snapshot-script.js b/bootstrap/cli-utils/create-snapshot-script.js index 624e7845..0e2e8a06 100644 --- a/bootstrap/cli-utils/create-snapshot-script.js +++ b/bootstrap/cli-utils/create-snapshot-script.js @@ -20,7 +20,7 @@ module.exports = { if (!fs.existsSync(homedir + '/.rnode')) { console.log(`Cannot snapshot: ${homedir}/.rnode does not exist`); rl.close(); - return; + return {message:"failed"}; } //run stop node script @@ -29,7 +29,7 @@ module.exports = { //if stop script terminates with error, exit if (code === 1) { rl.close(); - return; + return {message:"failed"}; } fs.mkdirSync('snapshot', { recursive: true }); @@ -49,9 +49,11 @@ module.exports = { await exec_shell(`cd ~ && tar czf "${target}" .rnode`); console.log(`snapshot created: ${target}`); rl.close(); + return {message:"successful"}; } else { console.log('Aborting...'); rl.close(); + return {message:"failed"} } }, ); @@ -59,6 +61,7 @@ module.exports = { await exec_shell(`cd ~ && tar czf "${target}" .rnode`); console.log(`snapshot created: ${target}`); rl.close(); + return {message:"successful"}; } });