From 77307c68dbab4cc94aa247493cd7e02db52136ee Mon Sep 17 00:00:00 2001 From: zeus Date: Sat, 20 Mar 2021 01:43:05 +0200 Subject: [PATCH] add storage 1 --- src-local/LabLearningObject-hybrid | 2 +- src-local/llo/new.js | 244 +++++++ src/App.vue | 26 +- .../mynetwork/availableservices.vue | 8 +- src/components/mynetwork/availablestorage.vue | 666 ++++++++++++++++++ src/components/mynetwork/mytable.vue | 43 ++ src/components/mystorage.vue | 70 ++ src/store/modules/create_pipelineLLO.js | 80 +++ 8 files changed, 1132 insertions(+), 7 deletions(-) create mode 100644 src/components/mynetwork/availablestorage.vue create mode 100644 src/components/mystorage.vue diff --git a/src-local/LabLearningObject-hybrid b/src-local/LabLearningObject-hybrid index 922df49..1f4f01d 160000 --- a/src-local/LabLearningObject-hybrid +++ b/src-local/LabLearningObject-hybrid @@ -1 +1 @@ -Subproject commit 922df495bbafc1b8580dc8bbdf019d27ac31f320 +Subproject commit 1f4f01de2f0c87e952dc8f3ea59bde7cd4bbe95c diff --git a/src-local/llo/new.js b/src-local/llo/new.js index d5b650d..8ba2bf8 100644 --- a/src-local/llo/new.js +++ b/src-local/llo/new.js @@ -675,6 +675,59 @@ app.get('/getservicesstatus', (req, res, next) => { }); +app.get('/getstoragestatus', (req, res, next) => { + + var RES = new Object(); + RES.instance = req.query["instance"] + var showfile = `./instance/${RES.instance}/swarmlabconfig/instance` + //console.log(JSON.stringify(showfile)) + fs.readFile(showfile, 'utf8', function (err, data) { + if (err) { + var found = 'no' + RES.error = false + RES.error_msg = "ok" + RES.data = "no sudorun file found"; + console.log(JSON.stringify(err)) + res.json(RES) + }else{ + + data = data.trim(); + + var showexec = `docker ps --format '{"Names":"{{ .Names }}", "Status":"{{.Status}}"}' | jq . -s ` + exec(showexec, (err, stdout, stderr) => { + if (err) { + return; + } + if (stdout) { + var string = stdout.toString() + var datajson = JSON.parse(string); + var extenderror = new RegExp(data); + var found = 'no'; + for(var i = 0; i < datajson.length; i++) { + var servicename = datajson[i].Names + if(extenderror.test(servicename)){ + found = 'yes'; + } + } + RES.error = false + RES.error_msg = "ok" + RES.test = datajson; + RES.data = found; + res.json(RES) + + }else{ + var found = 'no' + RES.error = false + RES.error_msg = "ok" + RES.data = found; + res.json(RES) + } + }); + } + }); + +}); + app.get('/rm_swarmlab', (req, res, next) => { var mypath = process.cwd() @@ -696,6 +749,28 @@ app.get('/rm_swarmlab', (req, res, next) => { } }); +}); +app.get('/rm_swarmlabstorage', (req, res, next) => { + + var mypath = process.cwd() + var RES = new Object(); + RES.instance = req.query["instance"] + var services_path = './instance/'+RES.instance + fs.rm(services_path, { + recursive: true, + force: true + }, (error) => { + if (error) { + RES.error = true + RES.error_msg = "no" + res.json(RES) + } else { + RES.error = false + RES.error_msg = "ok" + res.json(RES) + } + }); + }); app.get('/get_config', (req, res, next) => { @@ -1033,6 +1108,60 @@ TEST=${service} } }); + socket.on('start_storage', (value) => { + if(value.swarmlabname){ + var service = value.swarmlabname + var services_path = './instance/'+service + var ENV_service_file_path = services_path+'/.env' + var service_password = '' + if(value.password){ + service_password = value.password + }else{ + service_password = Math.random().toString(36).substring(7); + } + + var ENV_service_file = ` +SWARMLAB_STORAGE_PASSWORD=${service_password} +` + fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'}); + + var service_up = '/bin/bash ./run.sh' + + child[0] = spawn(service_up, { + shell: true, + cwd: services_path, + //detached: true, + detached: false, + //stdio: [ 'ignore', logout, logerr ] + stdio: 'pipe' + }); + + ppid = child[0].pid; + //console.log(ppid) + child[0].stdout.on('data', function (data) { + var n = {} + n.data = data.toString() + io.emit('message_out_storage', n); + }); + + child[0].stderr.on('data', function (data) { + var n = {} + n.data = data.toString() + io.emit('message_err_storage', n); + }); + + child[0].on('close', function (code) { + var n = {} + n.data = code + io.emit('message_close_storage', n); + }); + }else{ + var n = {} + n.data = 'NoSwarmlabname' + io.emit('message_err_storage', n); + } + }); + socket.on('stop', (service) => { var services_path = './instance/'+service+'/'+service @@ -1060,6 +1189,33 @@ TEST=${service} }); }); + socket.on('stop_storage', (service) => { + var services_path = './instance/'+service + //console.log(services_path) + const stop = spawn('/bin/sh ./stop.sh', { + stdio: 'pipe', + shell: true, + cwd: services_path + }); + stop.stdout.on('data', function (data) { + var n = {} + n.data = data.toString() + io.emit('message_out_storage', n); + }); + + stop.stderr.on('data', function (data) { + var n = {} + n.data = data.toString() + io.emit('message_err_storage', n); + }); + + stop.on('close', function (code) { + var n = {} + n.data = code + io.emit('message_close_storage', n); + }); + }); + socket.on('install', (value) => { if(value.swarmlabname){ //console.log('install') @@ -1145,6 +1301,94 @@ SSH_PORT= } }); + + socket.on('installstorage', (value) => { + if(value.swarmlabname){ + //console.log('install') + var service = value.swarmlabname + var service_git = value.git + var services_path = './instance/'+service + var ENV_service_dir = services_path+'/'+service + var ENV_service_file_path = services_path+'/'+service+'/'.env + var nn = {} + nn.data = 'Wait for service(s) to be available before executing a command' + io.emit('message_out_storage', nn); + if (fs.existsSync(services_path)) { + const git = simpleGit( + { + baseDir: services_path, + maxConcurrentProcesses: 10 + }); + try { + git.pull() + .then((status) => { + var n = {} + n.data = 'Updated' + io.emit('message_out_storage', n); + n.data = '...' + io.emit('message_out_storage', n); + n.data = 'ok' + io.emit('message_close_storage', n); + //create_project_storage(service,service) + }).catch((err) => { + var n = {} + n.data = err.toString() + io.emit('message_err_storage', n); + console.log('error ' + JSON.stringify(err)) + }); + } catch (e) { + var n = {} + n.data = e.toString() + io.emit('message_err_storage', n); + } + }else{ + fs.mkdir(services_path, { recursive: true }, (err) => { + if (err){ + console.log('error ' + JSON.stringify(err)) + }else{ +// var ENV_service_file = ` +//IMAGE_NAME=${service} +//SSH_PORT= +//` + const git = simpleGit( + { + baseDir: '.', + maxConcurrentProcesses: 10 + }); + try { + git.clone(service_git, services_path) + .then((status) => { + var n = {} + n.data = 'Installed' + io.emit('message_out_storage', n); + n.data = '...' + io.emit('message_out_storage', n); + n.data = 'ok' + io.emit('message_close_storage', n); + //fs.writeFileSync(ENV_service_file_path, ENV_service_file); + //create_project_storage(service,service) + }).catch((err) => { + var n = {} + n.data = err.toString() + io.emit('message_err_storage', n); + console.log('error ' + JSON.stringify(err)) + }); + } catch (e) { + var n = {} + n.data = e.toString() + io.emit('message_err_storage', n); + } + + } + }); + } + }else{ + var n = {} + n.data = 'no services' + io.emit('message_err_storage', n); + } + }); + socket.on('container-stop', (service, id) => { var mypath = process.cwd() //console.log(mypath); diff --git a/src/App.vue b/src/App.vue index b7b26f0..1860aee 100644 --- a/src/App.vue +++ b/src/App.vue @@ -256,7 +256,8 @@ Private/Local - Bootstrap + LabRoom + Storage @@ -322,7 +323,8 @@ - + + @@ -421,6 +423,20 @@ + + + + + + + + + + @@ -509,6 +525,7 @@ import ConnectServer from "./components/myconnect-server.vue"; import NetworkTable from "./components/mynetwork.vue"; import ServicesTable from "./components/myservices.vue"; import ManageServices from "./components/manageservices.vue"; +import ManageStorage from "./components/mystorage.vue"; import ManageDeploy from "./components/managedeploy.vue"; import ManageLlo from "./components/managello.vue"; import ViewDashboard from "./components/dashboard.vue"; @@ -521,6 +538,7 @@ export default { ServicesTable, ConnectServer, ManageServices, + ManageStorage, ManageDeploy, ManageLlo }, @@ -529,6 +547,7 @@ export default { warning: true, componentKeyreload:1, componentKeyreload1:1, + componentKeyreload2:1, setStatusAgent:'', issocket:false, //socket server isconnect:false, // dockerswarm wg @@ -596,6 +615,7 @@ export default { //window.location.reload() this.componentKeyreload += 1 this.componentKeyreload1 += 1 + this.componentKeyreload2 += 1 } }, async serverstatus(action){ @@ -632,6 +652,8 @@ export default { this.$root.$emit('hybrid_refresh_availableservices') }else if(action == 'manage_service'){ //this.$root.$emit('hybrid_manage_service') + }else if(action == 'storage'){ + //this.$root.$emit('hybrid_manage_service') }else if(action == 'manage_deploy'){ } }, diff --git a/src/components/mynetwork/availableservices.vue b/src/components/mynetwork/availableservices.vue index 0906c46..595ab8d 100644 --- a/src/components/mynetwork/availableservices.vue +++ b/src/components/mynetwork/availableservices.vue @@ -17,7 +17,7 @@
- Swarmlab Deploy - Local + Swarmlab LabRoom Deploy - Local
@@ -125,7 +125,7 @@ + + +
+ +
+ + +
+ + + Storage Service Options + + +
+ +
+ + + +
+ +
+ +
+
+ + +
+
+
+
+ +
+
+
+
+ + +
+
+ +
+ + + + +
+
+ + + + + diff --git a/src/components/mynetwork/mytable.vue b/src/components/mynetwork/mytable.vue index 15b31c5..56650c8 100644 --- a/src/components/mynetwork/mytable.vue +++ b/src/components/mynetwork/mytable.vue @@ -209,6 +209,15 @@ export default { //console.log('RUN exec '+JSON.stringify(this.swarmlabname)) this.onAction('start') }) + this.$root.$on('hybrid_start_instance_storage', (data) => { + var obj = {} + obj.action = 'up' + obj.token = this.token + obj.swarmlabname = data.swarmlabname + obj.password = data.password + this.$socket.client.open(); + this.$socket.client.emit('start_storage', obj); + }) // from available services socket run here this.$root.$on('hybrid_install_instance', (data) => { this.swarmlabname = data.swarmlabname @@ -216,6 +225,18 @@ export default { //this.swarmlabname_port = data.port this.onAction('install') }) +// from available storage socket run here + this.$root.$on('hybrid_install_instance_storage', (data) => { + //this.swarmlabname = data.swarmlabname + //this.swarmlabname_git = data.git + var obj = {} + obj.action = 'up' + obj.token = this.token + obj.swarmlabname = data.swarmlabname + obj.git = data.git + this.$socket.client.open(); + this.$socket.client.emit('installstorage', obj); + }) // from available services socket run here this.$root.$on('hybrid_connect_server', (data) => { //this.onAction('create-wirequard') @@ -227,6 +248,13 @@ export default { //console.log('RUN exec '+JSON.stringify(this.swarmlabname)) this.onAction('stop') }) +// from available storage socket run here + this.$root.$on('hybrid_stop_instance_storage', (data) => { + //this.swarmlabname = data + //console.log('RUN exec '+JSON.stringify(this.swarmlabname)) + //this.onAction('stop') + this.$socket.client.emit('stop_storage', data); + }) }, created() { var url_string = window.location.href @@ -245,6 +273,7 @@ export default { this.$root.$off('hybrid_stop_instance') this.$root.$off('hybrid_connect_server') this.$root.$off('hybrid_install_instance') + this.$root.$off('hybrid_install_instance_storage') }, computed: { httpOptions() { @@ -632,6 +661,20 @@ info +='This permits the docker user on the local machine to connect to X window // refresh adhocview.vue on console await console this.$root.$emit('SERVER_hybrid_table_stop') }, + async message_err_storage(val) { + //console.log(" socket err "+JSON.stringify(val)) + this.$root.$emit('hybrid_log_in',val) + }, + async message_out_storage(val) { + console.log(" socket out storage "+JSON.stringify(val)) + this.$root.$emit('hybrid_log_in',val) + //this.hybridshowdata = {} + }, + async message_close_storage(val) { + // refresh table hybrid storage + this.$root.$emit('hybrid_log_in',val) + this.$root.$emit('hybrid_refresh_table_storage') + }, async message_hybrid_status(val) { var obj = {} obj.status = val diff --git a/src/components/mystorage.vue b/src/components/mystorage.vue new file mode 100644 index 0000000..90d689d --- /dev/null +++ b/src/components/mystorage.vue @@ -0,0 +1,70 @@ + + + + diff --git a/src/store/modules/create_pipelineLLO.js b/src/store/modules/create_pipelineLLO.js index e1fe7d7..a6245ec 100644 --- a/src/store/modules/create_pipelineLLO.js +++ b/src/store/modules/create_pipelineLLO.js @@ -424,6 +424,34 @@ export default { return R; } } + }, + async getstoragestatus({commit,rootGetters}, value) { + //console.log('value '+JSON.stringify(value)) + try { + var token = value.token + var params = { + instance: value.instance + } + var options = { + params: params, + headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, + }; + var sock_server_l = ApiConfig.url_80+'/getstoragestatus' + var p = await axios.get(sock_server_l,options); + //var p = await axios.get('https://localhost:3000/getservicesstatus',options); + return p + } catch (e) { + if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){ + //console.log('error '+JSON.stringify(e)) + window.location.href = 'https://api-login.swarmlab.io:8089'; + }else{ + var R = { + ERROR_str: e, + ERROR: 'yes' + } + return R; + } + } }, async create_config({commit,rootGetters}, value) { //console.log('value '+JSON.stringify(value)) @@ -484,6 +512,36 @@ export default { } } + }, + async rmswarmlablocalstorage({commit,rootGetters}, value) { + //console.log('value '+JSON.stringify(value)) + + try { + var token = value.token + var params = { + instance: value + } + var options = { + params: params, + headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, + }; + var sock_server_l = ApiConfig.url_80+'/rm_swarmlabstorage' + var p = await axios.get(sock_server_l,options); + //var p = await axios.get('https://localhost:3000/get_config',options); + return p + } catch (e) { + if(e.message == "Request failed with status code 401" || /401/i.test(e.message)){ + //console.log('error '+JSON.stringify(e)) + window.location.href = 'https://api-login.swarmlab.io:8089'; + }else{ + var R = { + ERROR_str: e, + ERROR: 'yes' + } + return R; + } + } + }, async save_llo_asciidoctmp({commit,rootGetters}, value) { //console.log('value '+JSON.stringify(value)) @@ -628,6 +686,28 @@ export default { } } }, + async getswarmlabstorageinfo({commit,rootGetters}, value) { + try { + var token = rootGetters['pipelineLLO/gettoken'] + //console.log('token ' + token) + var params = { + swarmlabname: value + } + var options = { + params: params, + headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, + }; + + const info = await axios.get('https://api.swarmlab.io/getswarmlabhybridstorageinfo',options); + return info + + } catch (e) { + //console.error(e); + if(e.error == "invalid_token"){ + window.location.href = 'https://api-login.swarmlab.io:8089'; + } + } + }, async hybrid_join({commit,rootGetters}, value) { try { var token = value.token