import { mapState, mapActions, commit } from 'vuex' import store from '@/store/index' import axios from 'axios' export default { namespaced: true, state: { token: '' }, getters: { gettoken (state, container) { return state.token }, getlog (state, container) { return state.log } }, mutations: { set_token (state, data) { state.token=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) }, 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 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 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'; } } } } }