Browse Source

error handling

master
zeus 3 years ago
parent
commit
7b05a5accd
  1. 2
      dist/index.html
  2. 2
      dist/js/app.ac72e2cf.js
  3. 1
      dist/js/app.ac72e2cf.js.map
  4. 2
      dist/js/app.dc17cc65.js
  5. 1
      dist/js/app.dc17cc65.js.map
  6. 17
      run.yml
  7. 151
      src-local/llo/new.js
  8. 53
      src/components/mynetwork/mytable.vue
  9. 31
      src/store/modules/create_pipelineLLO.js

2
dist/index.html

@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Vue App</title><link href="/css/app.25658f84.css" rel="preload" as="style"><link href="/css/chunk-vendors.e469b508.css" rel="preload" as="style"><link href="/js/app.ac72e2cf.js" rel="preload" as="script"><link href="/js/chunk-vendors.d8d18fe6.js" rel="preload" as="script"><link href="/css/chunk-vendors.e469b508.css" rel="stylesheet"><link href="/css/app.25658f84.css" rel="stylesheet"></head><body><div id="app"></div><script src="/js/chunk-vendors.d8d18fe6.js"></script><script src="/js/app.ac72e2cf.js"></script></body></html> <!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Vue App</title><link href="/css/app.25658f84.css" rel="preload" as="style"><link href="/css/chunk-vendors.e469b508.css" rel="preload" as="style"><link href="/js/app.dc17cc65.js" rel="preload" as="script"><link href="/js/chunk-vendors.d8d18fe6.js" rel="preload" as="script"><link href="/css/chunk-vendors.e469b508.css" rel="stylesheet"><link href="/css/app.25658f84.css" rel="stylesheet"></head><body><div id="app"></div><script src="/js/chunk-vendors.d8d18fe6.js"></script><script src="/js/app.dc17cc65.js"></script></body></html>

2
dist/js/app.ac72e2cf.js

File diff suppressed because one or more lines are too long

1
dist/js/app.ac72e2cf.js.map

File diff suppressed because one or more lines are too long

2
dist/js/app.dc17cc65.js

File diff suppressed because one or more lines are too long

1
dist/js/app.dc17cc65.js.map

File diff suppressed because one or more lines are too long

17
run.yml

@ -70,6 +70,23 @@ services:
networks: networks:
hybrid-net: hybrid-net:
swarmlabvolumemanager:
image: hub.swarmlab.io:5480/swarmlab-filemanager:latest
user: docker
#privileged: true
container_name: swarmlab-volumemanager-agent
entrypoint: ["sec_bootstrap", "role=masterservice", "sec_master_service_name=masterservice", "sec_worker_service_name=workerservice"]
environment:
- NODENAME={{.Node.Hostname}}
- NODEID={{.Node.ID}}
ports:
- "3383:8080"
volumes:
- ${nodepath}/src-local/mybackups:/data
- /etc/localtime:/etc/localtime:ro
networks:
hybrid-net:
networks: networks:
hybrid-net: hybrid-net:

151
src-local/llo/new.js

@ -114,11 +114,7 @@ const { spawn, exec, execSync } = require('child_process')
//const logerr = fs.openSync('./logs/out.log', 'a'); //const logerr = fs.openSync('./logs/out.log', 'a');
try {
const logerribuild = fs.openSync('./logs/build-out.log', 'a'); const logerribuild = fs.openSync('./logs/build-out.log', 'a');
} catch (error) {
console.log('Error:', error);
}
@ -1450,15 +1446,7 @@ app.get('/rungui', (req, res, next) => {
//const builderr = fs.openSync(builderrdir, 'a'); //const builderr = fs.openSync(builderrdir, 'a');
try { try {
const buildout = fs.openSync(buildoutdir, 'a'); const buildout = fs.openSync(buildoutdir, 'a');
} catch (error) {
console.log('Error:', error);
}
try {
const builderr = fs.openSync(builderrdir, 'a'); const builderr = fs.openSync(builderrdir, 'a');
} catch (error) {
console.log('Error:', error);
}
var buildimage = `echo "EXEC PID: $$"; ${showexec}` var buildimage = `echo "EXEC PID: $$"; ${showexec}`
//var buildimage = `echo "EXEC PID: $$"; docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix microservice-firefox /bin/sh -c "firefox"` //var buildimage = `echo "EXEC PID: $$"; docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix microservice-firefox /bin/sh -c "firefox"`
@ -1512,6 +1500,79 @@ try {
}); });
console.log(run_buildimage.pid); console.log(run_buildimage.pid);
run_buildimage.unref(); run_buildimage.unref();
} catch (error) {
console.log('Error:', error);
RES.error = true
RES.error_msg = error
RES.data = 'no'
res.json(RES)
}
});
app.get('/runbackup', (req, res, next) => {
var RES = new Object();
var mypath = process.cwd()
RES.instance = req.query["instance"]
RES.error = false
RES.error_msg = "ok"
RES.error_msg0 = ""
RES.data = "All_services_are_running";
var showexec = `./swarmlab_backup_service.sh ${RES.instance}`
console.log('exec tar :', showexec);
var runpath = `${mypath}`
var runpathfile = `${mypath}/swarmlab_backup_service.sh`
var buildoutdir = `${runpath}/logs/tar-backup-out.log`
var builderrdir = `${runpath}/logs/tar-backup-out.log`
try {
const buildout = fs.openSync(buildoutdir, 'a');
const builderr = fs.openSync(builderrdir, 'a');
console.log('buildout :', buildout);
var buildimage = `echo "EXEC PID: $$"; ${showexec}`
const run_buildimage = spawn(buildimage, {
detached: true,
shell: true,
stdio: [ 'ignore', buildout, builderr ],
cwd: runpath
});
var n = {}
n.pid = run_buildimage.pid
io.emit('build_set_buildpid', n);
n.data = 'start ...'
io.emit('message_out', n);
n.data = 'Your backup might take a long time, depending on the number of files to back up. '
io.emit('message_out', n);
run_buildimage.on('exit', (data) => {
var n = {}
n.data = 'exit!'
io.emit('message_close', n);
});
run_buildimage.on('close', (data) => {
var n = {}
n.data = 'close!'
io.emit('message_close', n);
n.name = `${RES.instance}`
n.dir = `${runpath}`
io.emit('message_close_build', n);
});
console.log(run_buildimage.pid);
run_buildimage.unref();
} catch (error) {
console.log('Error:', error);
RES.error = true
RES.error_msg = error
RES.data = 'no'
res.json(RES)
}
}); });
@ -2056,11 +2117,7 @@ app.get('/create_config', (req, res, next) => {
RES.value = req.query["value"] RES.value = req.query["value"]
//console.log('value error '+JSON.stringify(RES.value)) //console.log('value error '+JSON.stringify(RES.value))
//var showexec = `cd ./hybrid; /bin/bash ./create-keys.sh` //var showexec = `cd ./hybrid; /bin/bash ./create-keys.sh`
try {
fs.writeFileSync('./hybrid/keys.json', JSON.stringify(RES.value)); fs.writeFileSync('./hybrid/keys.json', JSON.stringify(RES.value));
} catch (error) {
console.log('Error:', error);
}
RES.value = JSON.parse(RES.value); RES.value = JSON.parse(RES.value);
var INTERFACE_IP=RES.value.wg_ip var INTERFACE_IP=RES.value.wg_ip
@ -2103,11 +2160,7 @@ var swarmlab_config_template = `
ip rule add table main suppress_prefixlength 0 ip rule add table main suppress_prefixlength 0
ip rule show | grep -w "suppress_prefixlength" ip rule show | grep -w "suppress_prefixlength"
` `
try {
fs.writeFileSync('./hybrid/connect/swarmlab-connect.sh', swarmlab_config_template); fs.writeFileSync('./hybrid/connect/swarmlab-connect.sh', swarmlab_config_template);
} catch (error) {
console.log('Error:', error);
}
var allowed_ips=RES.value.allowed_ips var allowed_ips=RES.value.allowed_ips
var swarmlab_public_wgkey=RES.value.swarmlab_public_wgkey var swarmlab_public_wgkey=RES.value.swarmlab_public_wgkey
@ -2125,11 +2178,7 @@ var swarmlab_wg0_template = `[Interface]
` `
//fs.writeFileSync('./hybrid/connect/template-wg0.conf', swarmlab_wg0_template); //fs.writeFileSync('./hybrid/connect/template-wg0.conf', swarmlab_wg0_template);
try {
fs.writeFileSync('./hybrid/connect/wg0.conf', swarmlab_wg0_template); fs.writeFileSync('./hybrid/connect/wg0.conf', swarmlab_wg0_template);
} catch (error) {
console.log('Error:', error);
}
var swarmlab_swarm=RES.value.workerkey var swarmlab_swarm=RES.value.workerkey
var swarmlab_swarm_ip=RES.value.swarm_ip var swarmlab_swarm_ip=RES.value.swarm_ip
@ -2137,11 +2186,7 @@ var swarmlab_swarm_template = `
docker swarm join --token ${swarmlab_swarm} ${swarmlab_swarm_ip} docker swarm join --token ${swarmlab_swarm} ${swarmlab_swarm_ip}
` `
//fs.writeFileSync('./hybrid/connect/template-swarm.sh', swarmlab_swarm_template); //fs.writeFileSync('./hybrid/connect/template-swarm.sh', swarmlab_swarm_template);
try {
fs.writeFileSync('./hybrid/connect/reload-swarmlab.sh', swarmlab_swarm_template); fs.writeFileSync('./hybrid/connect/reload-swarmlab.sh', swarmlab_swarm_template);
} catch (error) {
console.log('Error:', error);
}
var swarmlab_swarm_join_template = ` var swarmlab_swarm_join_template = `
@ -2193,11 +2238,7 @@ fi
/bin/bash ${mypath}/hybrid/connect/get-swarmlab-ca /bin/bash ${mypath}/hybrid/connect/get-swarmlab-ca
/bin/bash ${mypath}/hybrid/connect/get-base-ca /bin/bash ${mypath}/hybrid/connect/get-base-ca
` `
try {
fs.writeFileSync('./hybrid/connect/join.sh', swarmlab_swarm_join_template); fs.writeFileSync('./hybrid/connect/join.sh', swarmlab_swarm_join_template);
} catch (error) {
console.log('Error:', error);
}
var swarmlab_swarm_leave_template = ` var swarmlab_swarm_leave_template = `
function hybrid_ifup() { function hybrid_ifup() {
@ -2224,11 +2265,7 @@ else
fi fi
` `
try {
fs.writeFileSync('./hybrid/connect/leave.sh', swarmlab_swarm_leave_template); fs.writeFileSync('./hybrid/connect/leave.sh', swarmlab_swarm_leave_template);
} catch (error) {
console.log('Error:', error);
}
RES.error = false RES.error = false
RES.error_msg = "ok" RES.error_msg = "ok"
@ -2339,6 +2376,7 @@ io.on('connection', function(socket) {
//console.log('start') //console.log('start')
//console.log('value '+JSON.stringify(value)) //console.log('value '+JSON.stringify(value))
if(value.swarmlabname){ if(value.swarmlabname){
try {
var service = value.swarmlabname var service = value.swarmlabname
var services_path = './instance/'+service+'/'+service var services_path = './instance/'+service+'/'+service
var ENV_service_file_path = services_path+'/.env' var ENV_service_file_path = services_path+'/.env'
@ -2402,11 +2440,7 @@ TEST=${service}
` `
//console.log('value1 '+JSON.stringify(ENV_service_file_path)) //console.log('value1 '+JSON.stringify(ENV_service_file_path))
//console.log('value2 '+JSON.stringify(ENV_service_file)) //console.log('value2 '+JSON.stringify(ENV_service_file))
try {
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'w'}); fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'w'});
} catch (error) {
console.log('Error:', error);
}
var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size
@ -2443,6 +2477,9 @@ try {
io.emit('message_close', n); io.emit('message_close', n);
}); });
}); });
} catch (error) {
console.log('Error:', error);
}
}else{ }else{
var n = {} var n = {}
n.data = 'NoSwarmlabname' n.data = 'NoSwarmlabname'
@ -2452,6 +2489,7 @@ try {
socket.on('start_storage', (value) => { socket.on('start_storage', (value) => {
if(value.swarmlabname){ if(value.swarmlabname){
try {
var service = value.swarmlabname var service = value.swarmlabname
var services_path = './instance/'+service var services_path = './instance/'+service
var ENV_service_file_path = services_path+'/.env' var ENV_service_file_path = services_path+'/.env'
@ -2465,11 +2503,7 @@ try {
var ENV_service_file = ` var ENV_service_file = `
SWARMLAB_STORAGE_PASSWORD=${service_password} SWARMLAB_STORAGE_PASSWORD=${service_password}
` `
try {
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'}); fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'});
} catch (error) {
console.log('Error:', error);
}
var service_up = '/bin/bash ./run.sh' var service_up = '/bin/bash ./run.sh'
@ -2501,6 +2535,9 @@ try {
n.data = code n.data = code
io.emit('message_close_storage', n); io.emit('message_close_storage', n);
}); });
} catch (error) {
console.log('Error:', error);
}
}else{ }else{
var n = {} var n = {}
n.data = 'NoSwarmlabname' n.data = 'NoSwarmlabname'
@ -2510,6 +2547,7 @@ try {
socket.on('start_poc', (value) => { socket.on('start_poc', (value) => {
if(value.swarmlabname){ if(value.swarmlabname){
try {
var service = value.swarmlabname var service = value.swarmlabname
var services_path = './instance/'+service var services_path = './instance/'+service
var ENV_service_file_path = services_path+'/.env' var ENV_service_file_path = services_path+'/.env'
@ -2523,11 +2561,7 @@ try {
var ENV_service_file = ` var ENV_service_file = `
SWARMLAB_STORAGE_PASSWORD=${service_password} SWARMLAB_STORAGE_PASSWORD=${service_password}
` `
try {
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'}); fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'a'});
} catch (error) {
console.log('Error:', error);
}
var service_up = '/bin/bash ./run.sh' var service_up = '/bin/bash ./run.sh'
@ -2559,6 +2593,9 @@ try {
n.data = code n.data = code
io.emit('message_close_poc', n); io.emit('message_close_poc', n);
}); });
} catch (error) {
console.log('Error:', error);
}
}else{ }else{
var n = {} var n = {}
n.data = 'NoSwarmlabname' n.data = 'NoSwarmlabname'
@ -2648,6 +2685,7 @@ try {
socket.on('install', (value) => { socket.on('install', (value) => {
if(value.swarmlabname){ if(value.swarmlabname){
try {
//console.log('install') //console.log('install')
var service = value.swarmlabname var service = value.swarmlabname
var service_git = value.git var service_git = value.git
@ -2727,6 +2765,9 @@ SSH_PORT=
} }
}); });
} }
} catch (error) {
console.log('Error:', error);
}
}else{ }else{
var n = {} var n = {}
n.data = 'no services' n.data = 'no services'
@ -2737,6 +2778,7 @@ SSH_PORT=
socket.on('installstorage', (value) => { socket.on('installstorage', (value) => {
if(value.swarmlabname){ if(value.swarmlabname){
try {
//console.log('install') //console.log('install')
var service = value.swarmlabname var service = value.swarmlabname
var service_git = value.git var service_git = value.git
@ -2817,6 +2859,9 @@ SSH_PORT=
} }
}); });
} }
} catch (error) {
console.log('Error:', error);
}
}else{ }else{
var n = {} var n = {}
n.data = 'no services' n.data = 'no services'
@ -2877,9 +2922,6 @@ SSH_PORT=
try { try {
const buildout = fs.openSync(buildoutdir, 'a'); const buildout = fs.openSync(buildoutdir, 'a');
const builderr = fs.openSync(builderrdir, 'a'); const builderr = fs.openSync(builderrdir, 'a');
} catch (error) {
console.log('Error:', error);
}
var buildimage = `echo "EXEC PID: $$"; packer build -force -only=virtualbox-iso ${image_config}` var buildimage = `echo "EXEC PID: $$"; packer build -force -only=virtualbox-iso ${image_config}`
const run_buildimage = spawn(buildimage, { const run_buildimage = spawn(buildimage, {
@ -2947,6 +2989,9 @@ try {
console.log(run_buildimage.pid); console.log(run_buildimage.pid);
run_buildimage.unref(); run_buildimage.unref();
} catch (error) {
console.log('Error:', error);
}
/* /*
@ -3140,11 +3185,7 @@ try {
}; };
let datajson = JSON.stringify(services_json); let datajson = JSON.stringify(services_json);
try {
fs.writeFileSync(rawdatafile, datajson); fs.writeFileSync(rawdatafile, datajson);
} catch (error) {
console.log('Error:', error);
}
var services_path = ` ---------------- var services_path = ` ----------------
create a file create a file

53
src/components/mynetwork/mytable.vue

@ -13,7 +13,7 @@
<br> <br>
<div class="row"> <div class="row">
<div class="col-9"> <div class="col-7">
<div class="input-group input-group-sm sm-3"> <div class="input-group input-group-sm sm-3">
<div class="input-group-prepend"> <div class="input-group-prepend">
<button <button
@ -109,7 +109,7 @@
</div> </div>
</div> <!-- col --> </div> <!-- col -->
<div class="col-3"> <div class="col-5">
<div class="input-group input-group-sm sm-3"> <div class="input-group input-group-sm sm-3">
<div class="input-group-prepend float-right"> <div class="input-group-prepend float-right">
<button <button
@ -119,7 +119,27 @@
type="button" type="button"
@click="onAction('basedir')" @click="onAction('basedir')"
> >
BaseDir-Persistent_data</button> Persistent Data</button>
</div>
<div class="input-group-prepend float-right">
<button
v-if="hybridshowdata.Names"
class="btn btn-outline-warning"
round
type="button"
@click="onAction('basebackup')"
>
Backup</button>
</div>
<div class="input-group-prepend float-right">
<button
v-if="hybridshowdata.Names"
class="btn btn-outline-success"
round
type="button"
@click="onAction('basebackupview')"
>
BrowseBackups</button>
</div> </div>
</div> </div>
</div> <!-- col --> </div> <!-- col -->
@ -567,6 +587,33 @@ export default {
//console.log('start ' + JSON.stringify(log)) //console.log('start ' + JSON.stringify(log))
//console.log('startobj ' + JSON.stringify(obj)) //console.log('startobj ' + JSON.stringify(obj))
////console.log(this.$socket.client.connect()) ////console.log(this.$socket.client.connect())
}else if(action == 'basebackupview'){
var info=`<h5><b>Backups</b><br>
<br>
`
info +='<p class="text-secondary">'
info +=' <b>Click on hyperlink opens Directory in new tab</b></p>'
info +='<b> <a class="text-info" href="http://127.0.0.1:3383/" target="_blank">View Backups</a></b>'
info +='<br>'
this.$swal({
type: 'Info',
title: 'Info!',
icon:'info',
html: info,
showCloseButton: true,
showLoaderOnConfirm: false,
allowOutsideClick: false,
cancelButtonText: 'No, cancel!',
showCancelButton: false,
showLoaderOnConfirm: false,
reverseButtons: true,
focusCancel: true,
confirmButtonText: 'Ok!'
})
}else if(action == 'basebackup'){
var log = await store.dispatch("pipelineLLO/runbackup",{
instance: this.hybridshowdata.Names
})
}else if(action == 'basedir'){ }else if(action == 'basedir'){
var log = await store.dispatch("pipelineLLO/getmountinfo",{ var log = await store.dispatch("pipelineLLO/getmountinfo",{
instance:this.hybridshowdata.Names instance:this.hybridshowdata.Names

31
src/store/modules/create_pipelineLLO.js

@ -367,6 +367,37 @@ export default {
return R; return R;
} }
} }
},
async runbackup({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+'/runbackup'
var p = await axios.get(sock_server_l,options);
//var p = await axios.get('https://localhost:3000/getservicesinfo',options);
return p
//console.log(JSON.stringify(p))
//console.log(value.token)
//console.log(value.swarmlabname)
} 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 hybrid_rmimage({commit,rootGetters}, value) { async hybrid_rmimage({commit,rootGetters}, value) {
//console.log('value '+JSON.stringify(value)) //console.log('value '+JSON.stringify(value))

Loading…
Cancel
Save