diff --git a/dependencies/hp.cfg b/dependencies/hp.cfg index 456f345..918295b 100644 --- a/dependencies/hp.cfg +++ b/dependencies/hp.cfg @@ -27,8 +27,8 @@ "bin_args": "/contract/echo_contract.js", "roundtime": 2000, "stage_slice": 25, - "consensus": "private", - "npl": "private", + "consensus": "public", + "npl": "public", "max_input_ledger_offset": 10, "appbill": { "mode": "", diff --git a/examples/message-board/message-board.js b/examples/message-board/message-board.js index e8a8a11..4dfc81e 100644 --- a/examples/message-board/message-board.js +++ b/examples/message-board/message-board.js @@ -51,6 +51,185 @@ const interatctiveInterface = async () => { }) } + const askForInstanceConfig = async (config) => { + modifyNode = await askForInput('Modify node section? [y/N]', 'n'); + if (modifyNode === 'y' || modifyNode === 'Y') { + role = await askForInput('Role: validator | observer(optional)'); + if (role && role != 'validator' && role != 'observer') { + console.error('Invalid role. (Should be "validator" or "observer").') + return -1; + } + history = await askForInput('History <{full|custom},max_primary_shards,max_raw_shards> (optional)'); + split = []; + if (history) { + split = history.split(','); + if (split.length == 0 || split.length !== 3) { + console.error('Invalid history.') + return -1; + } + else if (split[0] != 'full' && split[0] != 'custom') { + console.error('Invalid history. (Should be "full" or "custom").') + return -1; + } + } + config.node = { + role: role, + history: history ? split[0] : undefined, + history_config: history ? { + max_primary_shards: parseInt(split[1]), + max_raw_shards: parseInt(split[2]) + } : undefined + }; + } + + modifyContract = await askForInput('Modify contract section? [y/N]', 'n'); + if (modifyContract === 'y' || modifyContract === 'Y') { + unl = await askForInput('Comma seperated UNL ,,...'); + execute = await askForInput('Execute contract? (optional)'); + roundtime = await askForInput('Roundtime? (optional)'); + log = await askForInput('log <{true|false},max_mbytes_per_file,max_file_count> (optional)'); + if (log) { + split = log.split(','); + if (split.length == 0 || split.length !== 3) { + console.error('Invalid log config.') + return -1; + } + else if (split[0] != 'true' && split[0] != 'false') { + console.error('Log enable tag should be either true or false') + return -1; + } + } + config.contract = { + execute: execute ? (execute === 'true' ? true : false) : undefined, + roundtime: roundtime ? parseInt(roundtime) : undefined, + log: log ? { + enable: split[0] === 'true' ? true : false, + max_mbytes_per_file: parseInt(split[1]), + max_file_count: parseInt(split[2]) + } : undefined, + unl: unl ? unl.split(',') : undefined + } + } + modifyMesh = await askForInput('Modify mesh section? [y/N]', 'n'); + if (modifyMesh === 'y' || modifyMesh === 'Y') { + idleTimeout = await askForInput('Idle timeout?(optional)'); + peers = await askForInput('Comma seperated Peer List ,,...(optional)'); + msgForwarding = await askForInput('Message forwarding [true|false]?(optional)'); + set01 = await askForInput('Comma seperated max_connections, max_known_connections and max_in_connections_per_host?(optional)'); + if (set01) { + split01 = set01.split(','); + if (split01.length == 0 || split01.length !== 3) { + console.error('Make sure to add all three. Eg: 1,1,1'); + return -1; + } + } + + set02 = await askForInput('Comma seperated max_bytes_per_msg, max_bytes_per_min and max_bad_msgs_per_min?(optional)'); + if (set02) { + split02 = set02.split(','); + if (split02.length == 0 || split02.length !== 3) { + console.error('Make sure to add all three. Eg: 1,1,1'); + return -1; + } + } + + set03 = await askForInput('Comma seperated max_bad_msgsigs_per_min and max_dup_msgs_per_min?(optional)'); + if (set03) { + split03 = set03.split(','); + if (split03.length == 0 || split03.length !== 2) { + console.error('Make sure to add all two. Eg: 1,1'); + return -1; + } + } + + peerDiscovery = await askForInput('Peer discovery <{true|false}, Interval>?(optional)'); + if (peerDiscovery) { + peerDiscovery = peerDiscovery.split(','); + if (peerDiscovery.length == 0 || peerDiscovery.length !== 2) { + console.error('Make sure to add all two. Eg: true,10000'); + return -1; + } + } + + config.mesh = { + idle_timeout: idleTimeout ? parseInt(idleTimeout) : undefined, + known_peers: peers ? peers.split(',') : undefined, + msg_forwarding: msgForwarding ? (msgForwarding === 'true' ? true : false) : undefined, + max_connections: set01 ? parseInt(split01[0]) : undefined, + max_known_connections: set01 ? parseInt(split01[1]) : undefined, + max_in_connections_per_host: set01 ? parseInt(split01[2]) : undefined, + max_bytes_per_msg: set02 ? parseInt(split02[0]) : undefined, + max_bytes_per_min: set02 ? parseInt(split02[1]) : undefined, + max_bad_msgs_per_min: set02 ? parseInt(split02[2]) : undefined, + max_bad_msgsigs_per_min: set03 ? parseInt(split03[0]) : undefined, + max_dup_msgs_per_min: set03 ? parseInt(split03[1]) : undefined, + peer_discovery: peerDiscovery ? { + enabled: peerDiscovery[0] === 'true' ? true : false, + interval: parseInt(peerDiscovery[1]) + } : undefined + }; + + + } + modifyUser = await askForInput('Modify user section? [y/N]', 'n'); + if (modifyUser === 'y' || modifyUser === 'Y') { + idleTimeout = await askForInput('Idle timeout?(optional)'); + set01 = await askForInput('Comma seperated max_bytes_per_msg, max_bytes_per_min and max_bad_msgs_per_min?(optional)'); + if (set01) { + split01 = set01.split(','); + if (split01.length == 0 || split01.length !== 3) { + console.error('Make sure to add all three. Eg: 1,1,1'); + return -1; + } + } + set02 = await askForInput('Comma seperated max_connections, max_in_connections_per_host and concurrent_read_reqeuests?(optional)'); + if (set02) { + split02 = set02.split(','); + if (split02.length == 0 || split02.length !== 3) { + console.error('Make sure to add all three. Eg: 1,1,1'); + return -1; + } + } + config.user = { + idle_timeout: idleTimeout ? parseInt(idleTimeout) : undefined, + max_bytes_per_msg: set01 ? parseInt(split01[0]) : undefined, + max_bytes_per_min: set01 ? parseInt(split01[1]) : undefined, + max_bad_msgs_per_min: set01 ? parseInt(split01[2]) : undefined, + max_connections: set02 ? parseInt(split02[0]) : undefined, + max_in_connections_per_host: set02 ? parseInt(split02[1]) : undefined, + concurrent_read_requests: set02 ? parseInt(split02[2]) : undefined + }; + } + modifyHpfs = await askForInput('Modify hpfs section? [y/N]', 'n'); + if (modifyHpfs === 'y' || modifyHpfs === 'Y') { + logLevel = await askForInput('Hpfs log level?(optional)'); + config.hpfs = logLevel ? { + log_level: logLevel ? logLevel : undefined + } : undefined; + } + + modifyLogs = await askForInput('Modify log section? [y/N]', 'n'); + if (modifyLogs === 'y' || modifyLogs === 'Y') { + logLevel = await askForInput('HP log level?(optional)'); + set01 = await askForInput('Comma seperated max_mbytes_per_file and max_file_count?(optional)'); + if (set01) { + split01 = set01.split(','); + if (split01.length == 0 || split01.length !== 2) { + console.error('Make sure to add all two. Eg: 1,1'); + return -1; + } + } + loggers = await askForInput('Comma seperated loggers?(optional)'); + config.log = { + log_level: logLevel ? logLevel : undefined, + max_mbytes_per_file: set01 ? parseInt(split01[0]) : undefined, + max_file_count: set01 ? parseInt(split01[1]) : undefined, + loggers: loggers ? loggers.split(',') : undefined + }; + } + return 0; + } + console.log("Ready to accept inputs."); const inputPump = () => { @@ -70,198 +249,31 @@ const interatctiveInterface = async () => { console.error('Invalid image. (Should be "1" or "2").') break; } + let createConfig = {}; + addConfig = await askForInput('Add config section? [y/N]', 'n'); + let ret = -1; + if (addConfig === 'y' || addConfig === 'Y') + ret = await askForInstanceConfig(createConfig); sendToAgent(JSON.stringify({ type: 'create', owner_pubkey: 'ed5cb83404120ac759609819591ef839b7d222c84f1f08b3012f490586159d2b50', contract_id: contractId, - image: (image == "1" ? "hp.0.5-ubt.20.04" : "hp.0.5-ubt.20.04-njs.14") + image: (image == "1" ? "hp.0.5-ubt.20.04" : "hp.0.5-ubt.20.04-njs.14"), + config: ret !== -1 ? createConfig : undefined })); break; - case 'initiate': - containerName = await askForInput('Container Name'); - let config = {}; - modifyNode = await askForInput('Modify node section? [y/N]', 'n'); - if (modifyNode === 'y' || modifyNode === 'Y') { - role = await askForInput('Role: validator | observer(optional)'); - if (role && role != 'validator' && role != 'observer') { - console.error('Invalid role. (Should be "validator" or "observer").') - break; - } - history = await askForInput('History <{full|custom},max_primary_shards,max_raw_shards> (custom,1,1)', "custom,1,1"); - split = []; - if (history) { - split = history.split(','); - if (split.length == 0 || split.length !== 3) { - console.error('Invalid history.') - break; - } - else if (split[0] != 'full' && split[0] != 'custom') { - console.error('Invalid history. (Should be "full" or "custom").') - break; - } - } - config.node = { - role: role, - history: history ? split[0] : undefined, - history_config: history ? { - max_primary_shards: parseInt(split[1]), - max_raw_shards: parseInt(split[2]) - } : undefined - }; - } + // case 'initiate': + // containerName = await askForInput('Container Name'); + // let config = {}; + // const iniRet = await askForInstanceConfig(config); - modifyContract = await askForInput('Modify contract section? [y/N]', 'n'); - if (modifyContract === 'y' || modifyContract === 'Y') { - unl = await askForInput('Comma seperated UNL ,,...'); - execute = await askForInput('Execute contract? (optional)'); - roundtime = await askForInput('Roundtime? (optional)'); - log = await askForInput('log <{true|false},max_mbytes_per_file,max_file_count> (optional)'); - if (log) { - split = log.split(','); - if (split.length == 0 || split.length !== 3) { - console.error('Invalid log config.') - break; - } - else if (split[0] != 'true' && split[0] != 'false') { - console.error('Log enable tag should be either true or false') - break; - } - } - config.contract = { - execute: execute ? (execute === 'true' ? true : false) : undefined, - roundtime: roundtime ? parseInt(roundtime) : undefined, - log: log ? { - enable: split[0] === 'true' ? true : false, - max_mbytes_per_file: parseInt(split[1]), - max_file_count: parseInt(split[2]) - } : undefined, - unl: unl ? unl.split(',') : undefined - } - } - modifyMesh = await askForInput('Modify mesh section? [y/N]', 'n'); - if (modifyMesh === 'y' || modifyMesh === 'Y') { - idleTimeout = await askForInput('Idle timeout?(optional)'); - peers = await askForInput('Comma seperated Peer List ,,...(optional)'); - msgForwarding = await askForInput('Message forwarding [true|false]?(optional)'); - set01 = await askForInput('Comma seperated max_connections, max_known_connections and max_in_connections_per_host?(optional)'); - if (set01) { - split01 = set01.split(','); - if (split01.length == 0 || split01.length !== 3) { - console.error('Make sure to add all three. Eg: 1,1,1'); - break; - } - } - - set02 = await askForInput('Comma seperated max_bytes_per_msg, max_bytes_per_min and max_bad_msgs_per_min?(optional)'); - if (set02) { - split02 = set02.split(','); - if (split02.length == 0 || split02.length !== 3) { - console.error('Make sure to add all three. Eg: 1,1,1'); - break; - } - } - - set03 = await askForInput('Comma seperated max_bad_msgsigs_per_min and max_dup_msgs_per_min?(optional)'); - if (set03) { - split03 = set03.split(','); - if (split03.length == 0 || split03.length !== 2) { - console.error('Make sure to add all two. Eg: 1,1'); - break; - } - } - - peerDiscovery = await askForInput('Peer discovery <{true|false}, Interval>?(optional)'); - if (peerDiscovery) { - peerDiscovery = peerDiscovery.split(','); - if (peerDiscovery.length == 0 || peerDiscovery.length !== 2) { - console.error('Make sure to add all two. Eg: true,10000'); - break; - } - } - - config.mesh = { - idle_timeout: idleTimeout ? parseInt(idleTimeout) : undefined, - known_peers: peers ? peers.split(',') : undefined, - msg_forwarding: msgForwarding ? (msgForwarding === 'true' ? true : false) : undefined, - max_connections: set01 ? parseInt(split01[0]) : undefined, - max_known_connections: set01 ? parseInt(split01[1]) : undefined, - max_in_connections_per_host: set01 ? parseInt(split01[2]) : undefined, - max_bytes_per_msg: set02 ? parseInt(split02[0]) : undefined, - max_bytes_per_min: set02 ? parseInt(split02[1]) : undefined, - max_bad_msgs_per_min: set02 ? parseInt(split02[2]) : undefined, - max_bad_msgsigs_per_min: set03 ? parseInt(split03[0]) : undefined, - max_dup_msgs_per_min: set03 ? parseInt(split03[1]) : undefined, - peer_discovery: peerDiscovery ? { - enabled: peerDiscovery[0] === 'true' ? true : false, - interval: parseInt(peerDiscovery[1]) - } : undefined - }; - - - } - modifyUser = await askForInput('Modify user section? [y/N]', 'n'); - if (modifyUser === 'y' || modifyUser === 'Y') { - idleTimeout = await askForInput('Idle timeout?(optional)'); - set01 = await askForInput('Comma seperated max_bytes_per_msg, max_bytes_per_min and max_bad_msgs_per_min?(optional)'); - if (set01) { - split01 = set01.split(','); - if (split01.length == 0 || split01.length !== 3) { - console.error('Make sure to add all three. Eg: 1,1,1'); - break; - } - } - set02 = await askForInput('Comma seperated max_connections, max_in_connections_per_host and concurrent_read_reqeuests?(optional)'); - if (set02) { - split02 = set02.split(','); - if (split02.length == 0 || split02.length !== 3) { - console.error('Make sure to add all three. Eg: 1,1,1'); - break; - } - } - config.user = { - idle_timeout: idleTimeout ? parseInt(idleTimeout) : undefined, - max_bytes_per_msg: set01 ? parseInt(split01[0]) : undefined, - max_bytes_per_min: set01 ? parseInt(split01[1]) : undefined, - max_bad_msgs_per_min: set01 ? parseInt(split01[2]) : undefined, - max_connections: set02 ? parseInt(split02[0]) : undefined, - max_in_connections_per_host: set02 ? parseInt(split02[1]) : undefined, - concurrent_read_requests: set02 ? parseInt(split02[2]) : undefined - }; - } - modifyHpfs = await askForInput('Modify hpfs section? [y/N]', 'n'); - if (modifyHpfs === 'y' || modifyHpfs === 'Y') { - logLevel = await askForInput('Hpfs log level?(optional)'); - config.hpfs = logLevel ? { - log_level: logLevel ? logLevel : undefined - } : undefined; - } - - modifyLogs = await askForInput('Modify log section? [y/N]', 'n'); - if (modifyLogs === 'y' || modifyLogs === 'Y') { - logLevel = await askForInput('HP log level?(optional)'); - set01 = await askForInput('Comma seperated max_mbytes_per_file and max_file_count?(optional)'); - if (set01) { - split01 = set01.split(','); - if (split01.length == 0 || split01.length !== 2) { - console.error('Make sure to add all two. Eg: 1,1'); - break; - } - } - loggers = await askForInput('Comma seperated loggers?(optional)'); - config.log = { - log_level: logLevel ? logLevel : undefined, - max_mbytes_per_file: set01 ? parseInt(split01[0]) : undefined, - max_file_count: set01 ? parseInt(split01[1]) : undefined, - loggers: loggers ? loggers.split(',') : undefined - }; - } - sendToAgent(JSON.stringify({ - type: 'initiate', - container_name: containerName, - config: config - })); - break; + // sendToAgent(JSON.stringify({ + // type: 'initiate', + // container_name: containerName, + // config: iniRet !== -1 ? config : undefined + // })); + // break; case 'destroy': containerName = await askForInput('Container Name'); sendToAgent(JSON.stringify({ @@ -285,7 +297,7 @@ const interatctiveInterface = async () => { break; default: - console.error('Invalid command. Only valid [create, initiate, destroy, start and stop]'); + console.error('Invalid command. Only valid [create, destroy, start and stop]'); break; } diff --git a/src/comm/comm_handler.cpp b/src/comm/comm_handler.cpp index 2f3d9c3..3a3207c 100644 --- a/src/comm/comm_handler.cpp +++ b/src/comm/comm_handler.cpp @@ -190,28 +190,33 @@ namespace comm else if (type == msg::MSGTYPE_CREATE) { msg::create_msg msg; - if (msg_parser.extract_create_message(msg) == -1) + msg::initiate_msg init_msg; + if (msg_parser.extract_create_message(msg) == -1 || + msg_parser.extract_initiate_message(init_msg) == -1) __HANDLE_RESPONSE(msg::MSGTYPE_CREATE_RES, "format_error", -1); hp::instance_info info; if (hp::create_new_instance(info, msg.pubkey, msg.contract_id, msg.image) == -1) __HANDLE_RESPONSE(msg::MSGTYPE_CREATE_RES, "create_error", -1); + if (hp::initiate_instance(info.container_name, init_msg) == -1) + __HANDLE_RESPONSE(msg::MSGTYPE_INITIATE_RES, "init_error", -1); + std::string create_res; msg_parser.build_create_response(create_res, info); __HANDLE_RESPONSE(msg::MSGTYPE_CREATE_RES, create_res, 0); } - else if (type == msg::MSGTYPE_INITIATE) - { - msg::initiate_msg msg; - if (msg_parser.extract_initiate_message(msg) == -1) - __HANDLE_RESPONSE(msg::MSGTYPE_INITIATE_RES, "format_error", -1); + // else if (type == msg::MSGTYPE_INITIATE) + // { + // msg::initiate_msg msg; + // if (msg_parser.extract_initiate_message(msg) == -1) + // __HANDLE_RESPONSE(msg::MSGTYPE_INITIATE_RES, "format_error", -1); - if (hp::initiate_instance(msg.container_name, msg) == -1) - __HANDLE_RESPONSE(msg::MSGTYPE_INITIATE_RES, "init_error", -1); + // if (hp::initiate_instance(msg.container_name, msg) == -1) + // __HANDLE_RESPONSE(msg::MSGTYPE_INITIATE_RES, "init_error", -1); - __HANDLE_RESPONSE(msg::MSGTYPE_INITIATE_RES, "initiated", 0); - } + // __HANDLE_RESPONSE(msg::MSGTYPE_INITIATE_RES, "initiated", 0); + // } else if (type == msg::MSGTYPE_DESTROY) { msg::destroy_msg msg; diff --git a/src/msg/json/msg_json.cpp b/src/msg/json/msg_json.cpp index 52d82ae..d231229 100644 --- a/src/msg/json/msg_json.cpp +++ b/src/msg/json/msg_json.cpp @@ -138,22 +138,23 @@ namespace msg::json */ int extract_initiate_message(initiate_msg &msg, const jsoncons::json &d) { - if (extract_type(msg.type, d) == -1) - return -1; + // Commented out when merging create and initiate messages. + // if (extract_type(msg.type, d) == -1) + // return -1; - if (!d.contains(msg::FLD_CONTAINER_NAME)) - { - LOG_ERROR << "Field container_name is missing."; - return -1; - } + // if (!d.contains(msg::FLD_CONTAINER_NAME)) + // { + // LOG_ERROR << "Field container_name is missing."; + // return -1; + // } - if (!d[msg::FLD_CONTAINER_NAME].is()) - { - LOG_ERROR << "Invalid container_name value."; - return -1; - } + // if (!d[msg::FLD_CONTAINER_NAME].is()) + // { + // LOG_ERROR << "Invalid container_name value."; + // return -1; + // } - msg.container_name = d[msg::FLD_CONTAINER_NAME].as(); + // msg.container_name = d[msg::FLD_CONTAINER_NAME].as(); if (!d.contains(msg::FLD_CONFIG)) { LOG_ERROR << "Field config is missing."; diff --git a/test/vm-cluster/cluster.sh b/test/vm-cluster/cluster.sh index 03f0615..ded322c 100755 --- a/test/vm-cluster/cluster.sh +++ b/test/vm-cluster/cluster.sh @@ -16,7 +16,7 @@ # reconfig - Re configure the sashimono with given "max_instance_count" in all the hosts (Only update the sa.cfg, Reinstall the sashimono if "R" option is given). # lcl - Get lcl of the hosts. # create - Create new sashimono hotpocket instance in each node. -# initiate - Initiate sashimono hotpocket instance with configs. +# docker-pull - Pull the latest docker image from docker hub. # start - Start sashimono hotpocket instance. # stop - Stop sashimono hotpocket instance. # destroy - Destroy sashimono hotpocket instance. @@ -28,11 +28,11 @@ PRINTFORMAT="Node %2s: %s\n" mode=$1 -if [ "$mode" == "select" ] || [ "$mode" == "reconfig" ] || [ "$mode" == "lcl" ] || [ "$mode" == "docker-pull" ] || [ "$mode" == "create" ] || [ "$mode" == "initiate" ] || [ "$mode" == "start" ] || [ "$mode" == "stop" ] || [ "$mode" == "destroy" ]; then +if [ "$mode" == "select" ] || [ "$mode" == "reconfig" ] || [ "$mode" == "lcl" ] || [ "$mode" == "docker-pull" ] || [ "$mode" == "create" ] || [ "$mode" == "start" ] || [ "$mode" == "stop" ] || [ "$mode" == "destroy" ]; then echo "mode: $mode" else echo "Invalid command." - echo " Expected: select | reconfig [N] [R] | lcl [N] | docker-pull [N] | create [N] | initiate [N] | start [N] | stop [N] | destroy [N]" + echo " Expected: select | reconfig [N] [R] | lcl [N] | docker-pull [N] | create [N] | start [N] | stop [N] | destroy [N]" echo " [N]: Optional node no. [R]: 'R' If sashimono needed to reinstall." exit 1 fi @@ -319,7 +319,30 @@ if [ $mode == "create" ]; then # If host info is already populated, skip instance creation. containername=$(echo $continfo | jq -r ".hosts.\"$hostaddr\".name") if [ "$containername" == "" ] || [ "$containername" == "null" ]; then - command="sashi json -m '{\"type\":\"create\",\"owner_pubkey\":\"$ownerpubkey\",\"contract_id\":\"$contractid\",\"image\":\"$image\"}'" + if [ "$1" != 0 ]; then + hostinfo=$(echo $continfo | jq -r ".hosts.\"${hostaddrs[0]}\"") + pubkey=$(echo $hostinfo | jq -r '.pubkey') + fi + + config=$(echo $continfo | jq -c -r ".config") + if [ "$1" != 0 ]; then + peers="" + for ((i = 0; i < $1; i++)); do + hostinfo=$(echo $continfo | jq -r ".hosts.\"${hostaddrs[$i]}\"") + peerport=$(echo $hostinfo | jq -r '.peer_port') + + if [ "$hostinfo" == "" ] || [ "$hostinfo" == "null" ] || + [ "$peerport" == "" ] || [ "$peerport" == "null" ]; then + echo "Host info is empty for ${hostaddrs[$i]}" + exit 1 + fi + peers+="\"${hostaddrs[$i]}:$peerport\"," + done + peers=${peers%?} + config=$(echo "$config" | jq -c ".mesh.known_peers = [$peers]" | jq -c ".contract.unl = [\"$pubkey\"]") + fi + + command="sashi json -m '{\"type\":\"create\",\"owner_pubkey\":\"$ownerpubkey\",\"contract_id\":\"$contractid\",\"image\":\"$image\",\"config\":$config}'" output=$(sshskp $sshuser@$hostaddr $command | tr '\0' '\n') # If an output received consider updating the json file. if [ ! "$output" = "" ]; then @@ -328,6 +351,10 @@ if [ $mode == "create" ]; then # Update the json if no error. if [ ! "$content" == "" ] && [ ! "$content" == "null" ] && [[ ! "$content" =~ ^[a-zA-Z]+_error$ ]]; then updateconfig "jq '(.contracts[] | select(.name == \"$selectedcont\") | .hosts.\"$hostaddr\") |= $content'" + # Refresh the in-memory config to include latest node creation details. + continfo=$(jq -r ".contracts[] | select(.name == \"$selectedcont\")" $configfile) + hosts=$(echo $continfo | jq -r '.hosts') + hostaddrs=($(echo $hosts | jq -r 'keys_unsorted[]')) fi else printf "$PRINTFORMAT" "$nodeno" "Instance creation error." @@ -339,7 +366,7 @@ if [ $mode == "create" ]; then if [ $nodeid = -1 ]; then for i in "${!hostaddrs[@]}"; do - createinstance $i & + createinstance $i done wait else @@ -348,60 +375,60 @@ if [ $mode == "create" ]; then exit 0 fi -if [ $mode == "initiate" ]; then - # Initiate the instance of given host. - function initiateinstance() { - hostaddr=${hostaddrs[$1]} - nodeno=$(expr $1 + 1) - peers=$2 - unl=$3 - config=$(echo $continfo | jq -r ".config") - containername=$(echo $continfo | jq -r ".hosts.\"$hostaddr\".name") - peerport=$(echo $continfo | jq -r ".hosts.\"$hostaddr\".peer_port") - selfpeer="\"$hostaddr:$peerport\"" - # Remove self peer from the peers. - updatedpeers=$(echo $peers | sed "s/\($selfpeer,\|,$selfpeer\|$selfpeer\)//g") - # Update the in memory config with received peers and unl. - updatedconfig=$(echo $config | jq ".mesh.known_peers = [$updatedpeers]" | jq ".contract.unl = [$unl]") - command="sashi json -m '{\"type\":\"initiate\",\"container_name\":\"$containername\",\"config\":$updatedconfig}'" - output=$(sshskp $sshuser@$hostaddr $command 2>&1 | tr '\0' '\n') - printf "$PRINTFORMAT" "$nodeno" "$output" - } +# if [ $mode == "initiate" ]; then +# # Initiate the instance of given host. +# function initiateinstance() { +# hostaddr=${hostaddrs[$1]} +# nodeno=$(expr $1 + 1) +# peers=$2 +# unl=$3 +# config=$(echo $continfo | jq -r ".config") +# containername=$(echo $continfo | jq -r ".hosts.\"$hostaddr\".name") +# peerport=$(echo $continfo | jq -r ".hosts.\"$hostaddr\".peer_port") +# selfpeer="\"$hostaddr:$peerport\"" +# # Remove self peer from the peers. +# updatedpeers=$(echo $peers | sed "s/\($selfpeer,\|,$selfpeer\|$selfpeer\)//g") +# # Update the in memory config with received peers and unl. +# updatedconfig=$(echo $config | jq ".mesh.known_peers = [$updatedpeers]" | jq ".contract.unl = [$unl]") +# command="sashi json -m '{\"type\":\"initiate\",\"container_name\":\"$containername\",\"config\":$updatedconfig}'" +# output=$(sshskp $sshuser@$hostaddr $command 2>&1 | tr '\0' '\n') +# printf "$PRINTFORMAT" "$nodeno" "$output" +# } - # Read each hosts config and construct cluster unl and peers. - peers="" - unl="" - for hostaddr in "${hostaddrs[@]}"; do - hostinfo=$(echo $continfo | jq -r ".hosts.\"$hostaddr\"") - pubkey=$(echo $hostinfo | jq -r '.pubkey') - ip=$(echo $hostinfo | jq -r '.ip') - peerport=$(echo $hostinfo | jq -r '.peer_port') +# # Read each hosts config and construct cluster unl and peers. +# peers="" +# unl="" +# for hostaddr in "${hostaddrs[@]}"; do +# hostinfo=$(echo $continfo | jq -r ".hosts.\"$hostaddr\"") +# pubkey=$(echo $hostinfo | jq -r '.pubkey') +# ip=$(echo $hostinfo | jq -r '.ip') +# peerport=$(echo $hostinfo | jq -r '.peer_port') - if [ "$hostinfo" == "" ] || [ "$hostinfo" == "null" ] || - [ "$pubkey" == "" ] || [ "$pubkey" == "null" ] || - [ "$ip" == "" ] || [ "$ip" == "null" ] || - [ "$peerport" == "" ] || [ "$peerport" == "null" ]; then - echo "Host info is empty for $hostaddr" - exit 1 - fi - peers+="\"$hostaddr:$peerport\"," - unl+="\"$pubkey\"," - done +# if [ "$hostinfo" == "" ] || [ "$hostinfo" == "null" ] || +# [ "$pubkey" == "" ] || [ "$pubkey" == "null" ] || +# [ "$ip" == "" ] || [ "$ip" == "null" ] || +# [ "$peerport" == "" ] || [ "$peerport" == "null" ]; then +# echo "Host info is empty for $hostaddr" +# exit 1 +# fi +# peers+="\"$hostaddr:$peerport\"," +# unl+="\"$pubkey\"," +# done - # Remove trainling comma(,) and add square brackets for the lists. - peers=${peers%?} - unl=${unl%?} +# # Remove trainling comma(,) and add square brackets for the lists. +# peers=${peers%?} +# unl=${unl%?} - if [ $nodeid = -1 ]; then - for i in "${!hostaddrs[@]}"; do - initiateinstance $i $peers $unl & - done - wait - else - initiateinstance $nodeid $peers $unl - fi - exit 0 -fi +# if [ $nodeid = -1 ]; then +# for i in "${!hostaddrs[@]}"; do +# initiateinstance $i $peers $unl & +# done +# wait +# else +# initiateinstance $nodeid $peers $unl +# fi +# exit 0 +# fi if [ $mode == "start" ]; then # Start instance of given host.