import { mapState, mapActions, commit } from 'vuex' import store from '@/store/index' import axios from 'axios' import {ApiConfig} from "@/config/index"; export default { namespaced: true, state: { token: '', socketStatus:'close', status: {} }, getters: { getsocketStatus (state, container) { return state.socketStatus }, gettoken (state, container) { return state.token }, getlog (state, container) { return state.log }, getstatus (state, container) { return state.status } }, mutations: { set_socketStatus (state, data) { state.socketStatus=data; }, 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) }, setsocketStatus({commit}, value) { //console.log("container "+value) commit('set_socketStatus', value.status) }, 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 sock_server_l = ApiConfig.url_80+'/run' var p = await axios.post(sock_server_l,params,options); //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 getmountinfo({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+'/getmountinfo' 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 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 sock_server_l = ApiConfig.url_80+'/getservicesinfo' 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 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 sock_server_l = ApiConfig.url_80+'/getservicesstatus' 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)) 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 sock_server_l = ApiConfig.url_80+'/create_config' var p = await axios.get(sock_server_l,options); //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 sock_server_l = ApiConfig.url_80+'/get_config' 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 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; } } }, async hybrid_servicerm({commit,rootGetters}, value) { try { var token = value.token var params = { bootstrapstackid: value.bootstrapstackid, bootstrapnameid: value.bootstrapnameid, action: 'servicesrm' } var options = { headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, }; var p = await axios.post('https://api.swarmlab.io/swarmlabhybridrmservice',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; } } }, async stackrm({commit,rootGetters}, value) { try { var token = value.token var params = { bootstrapstackid: value.bootstrapstackid, action: 'stackrm' } var options = { headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, }; var p = await axios.post('https://api.swarmlab.io/swarmlabhybridrmstack',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; } } }, async swarmlabhybridjoin({commit,rootGetters}, value) { try { var token = value.token var params = { swarmlabservice: 'ondemand_test_spitifgdfgdfkngkndfkngkdfngkdfk', action: 'join' } var options = { headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, }; var p = await axios.post('https://api.swarmlab.io/swarmlabhybridjoin',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; } } }, async adddeploy({commit,rootGetters}, value) { try { var token = value.token var params = { deploy: value.deploy, action: 'deploy' } var options = { headers: { 'content-type': 'application/x-www-form-urlencoded',Authorization: `Bearer ${token}` }, }; var p = await axios.post('https://api.swarmlab.io/adddeployhybrid',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; } } }, } }