You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
321 lines
9.8 KiB
321 lines
9.8 KiB
import { mapState, mapActions, commit } from 'vuex'
|
|
import store from '@/store/index'
|
|
import axios from 'axios'
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
token: '',
|
|
status: {}
|
|
},
|
|
getters: {
|
|
gettoken (state, container) {
|
|
return state.token
|
|
},
|
|
getlog (state, container) {
|
|
return state.log
|
|
},
|
|
getstatus (state, container) {
|
|
return state.status
|
|
}
|
|
},
|
|
mutations: {
|
|
set_token (state, data) {
|
|
state.token=data;
|
|
},
|
|
set_status (state, data) {
|
|
state.status=data;
|
|
},
|
|
add_log (state, data) {
|
|
//console.log("js1 set "+JSON.stringify(data))
|
|
state.log.push(data);
|
|
}
|
|
},
|
|
actions: {
|
|
addlog({commit}, value) {
|
|
//console.log("container "+value)
|
|
var tt = {}
|
|
tt.message = value.log.log.message
|
|
tt.tailed_path = value.log.log.tailed_path
|
|
tt.date = value.log.date
|
|
commit('add_log', tt)
|
|
},
|
|
settoken({commit}, value) {
|
|
//console.log("container "+value)
|
|
commit('set_token', value.token)
|
|
},
|
|
setstatus({commit}, value) {
|
|
//console.log("container "+value)
|
|
commit('set_status', value.status)
|
|
},
|
|
async swarmlabstart({commit,rootGetters}, value) {
|
|
console.log('from '+JSON.stringify(value))
|
|
try {
|
|
var token = value.token
|
|
var params = {
|
|
action: value.action,
|
|
}
|
|
var options = {
|
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
|
|
};
|
|
var p = await axios.post('http://localhost:8084/run',params,options);
|
|
//console.log(value.token)
|
|
//console.log(value.swarmlabname)
|
|
console.log(JSON.stringify(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 swarmlabhybridadd({commit,rootGetters}, value) {
|
|
try {
|
|
var token = value.token
|
|
var params = {
|
|
action: value.action,
|
|
nodename: value.nodename,
|
|
nodeip: value.nodeip,
|
|
nodeid: value.nodeid,
|
|
noderole: value.noderole,
|
|
nodezones: value.nodezones,
|
|
nodedesc: value.nodedesc
|
|
}
|
|
var options = {
|
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
|
|
};
|
|
var p = await axios.post('https://api.swarmlab.io/swarmlabhybridadd',params,options);
|
|
if(p.error == "invalid_token"){
|
|
console.log(p)
|
|
console.log(JSON.stringify(p))
|
|
}else{
|
|
}
|
|
//console.log(value.token)
|
|
//console.log(value.swarmlabname)
|
|
console.log(JSON.stringify(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 swarmlabhybridrm({commit,rootGetters}, value) {
|
|
try {
|
|
var token = value.token
|
|
var params = {
|
|
action: value.action,
|
|
nodename: value.nodename,
|
|
nodeip: value.nodeip,
|
|
nodeid: value.nodeid,
|
|
noderole: value.noderole,
|
|
nodezones: value.nodezones,
|
|
nodedesc: value.nodedesc
|
|
}
|
|
var options = {
|
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
|
|
};
|
|
var p = await axios.post('https://api.swarmlab.io/swarmlabhybridrm',params,options);
|
|
if(p.error == "invalid_token"){
|
|
console.log(p)
|
|
console.log(JSON.stringify(p))
|
|
}else{
|
|
}
|
|
//console.log(value.token)
|
|
//console.log(value.swarmlabname)
|
|
console.log(JSON.stringify(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 getservicesinfo({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 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 getservicesstatus({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 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))
|
|
|
|
try {
|
|
var token = value.token
|
|
var params = {
|
|
value: value.value
|
|
}
|
|
var options = {
|
|
params: params,
|
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
|
|
};
|
|
var p = await axios.get('https://localhost:3000/create_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 get_config({commit,rootGetters}, value) {
|
|
console.log('value '+JSON.stringify(value))
|
|
|
|
try {
|
|
var token = value.token
|
|
var params = {
|
|
value: 'get'
|
|
}
|
|
var options = {
|
|
params: params,
|
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
|
|
};
|
|
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 getswarmlabinfo({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/getswarmlabhybridservicesinfo',options);
|
|
return info
|
|
|
|
} catch (e) {
|
|
console.error(e);
|
|
if(e.error == "invalid_token"){
|
|
window.location.href = 'https://api-login.swarmlab.io:8089';
|
|
}
|
|
}
|
|
},
|
|
async swarmlabhybridconfig({commit,rootGetters}, value) {
|
|
try {
|
|
var token = value.token
|
|
var params = {
|
|
action: 'add'
|
|
}
|
|
var options = {
|
|
headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` },
|
|
};
|
|
var p = await axios.post('https://api.swarmlab.io/swarmlabhybridconfiginfo',params,options);
|
|
if(p.error == "invalid_token"){
|
|
console.log(p)
|
|
console.log(JSON.stringify(p))
|
|
}else{
|
|
}
|
|
//console.log(value.token)
|
|
//console.log(value.swarmlabname)
|
|
console.log(JSON.stringify(p))
|
|
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;
|
|
}
|
|
}
|
|
},
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|