Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33_sdk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
harrylee2015
chain33_sdk
Commits
fc94b850
Commit
fc94b850
authored
May 04, 2018
by
lihailei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add task module.
parent
7eb356fa
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
99 additions
and
14 deletions
+99
-14
remote_function.go
src/common/remote_function.go
+8
-7
server.go
src/controllers/server.go
+3
-1
task.go
src/controllers/task.go
+1
-0
healthcheck.go
src/healthcheck/healthcheck.go
+56
-0
const.go
src/models/const.go
+7
-0
task.go
src/models/task.go
+24
-6
No files found.
src/common/remote_function.go
View file @
fc94b850
...
...
@@ -47,10 +47,10 @@ type CmdInfo struct {
remoteDir
string
}
type
SshInfo
struct
{
u
serName
string
p
assWord
string
h
ostIp
string
p
ort
int
U
serName
string
P
assWord
string
H
ostIp
string
P
ort
int
}
type
tomlConfig
struct
{
Title
string
...
...
@@ -183,17 +183,18 @@ func RemoteExec(cmdInfo *CmdInfo) error {
//远程查看进程是否存在
func
RemoteViewProcIsExist
(
procName
string
,
ssh
SshInfo
)
(
bool
,
error
)
{
session
,
err
:=
sshconnect
(
ssh
.
userName
,
ssh
.
passWord
,
ssh
.
hostIp
,
ssh
.
p
ort
)
session
,
err
:=
sshconnect
(
ssh
.
UserName
,
ssh
.
PassWord
,
ssh
.
HostIp
,
ssh
.
P
ort
)
if
err
!=
nil
{
return
false
,
err
}
defer
session
.
Close
()
cmd
:=
fmt
.
Sprintf
(
"ps -ef | grep %s | grep -v grep| awk '{print $2}'"
,
procName
)
data
,
err
:=
session
.
Output
(
cmd
)
fmt
.
Println
(
string
(
data
))
if
string
(
data
)
!=
""
&&
err
==
nil
{
return
true
,
err
return
true
,
nil
}
return
false
,
nil
return
false
,
err
}
func
remoteScp
(
si
*
ScpInfo
,
reqnum
chan
struct
{})
{
defer
func
()
{
...
...
src/controllers/server.go
View file @
fc94b850
...
...
@@ -7,6 +7,7 @@ import (
.
"gitlab.33.cn/lihailei/chain33_sdk/src/common"
"gitlab.33.cn/lihailei/chain33_sdk/src/common/crypto"
.
"gitlab.33.cn/lihailei/chain33_sdk/src/models"
.
"gitlab.33.cn/lihailei/chain33_sdk/src/healthcheck"
"encoding/json"
"fmt"
...
...
@@ -61,7 +62,8 @@ func (c *ServerController) DeployChain() {
c
.
Ctx
.
ResponseWriter
.
WriteHeader
(
500
)
return
}
//go StartAll(serverList)
go
StartAll
(
serverList
)
go
ChainCheck
(
serverList
,
task
)
c
.
Data
[
"json"
]
=
task
c
.
ServeJSON
()
}
...
...
src/controllers/task.go
View file @
fc94b850
...
...
@@ -31,6 +31,7 @@ func (c *TaskController) GetTaskStatus() {
data
,
err
:=
GetData
(
taskId
)
if
err
!=
nil
{
clog
.
Error
(
"getData err:"
,
err
.
Error
())
c
.
Data
[
"json"
]
=
err
.
Error
()
c
.
ServeJSON
()
}
else
{
...
...
src/healthcheck/healthcheck.go
View file @
fc94b850
package
healthcheck
import
(
.
"gitlab.33.cn/lihailei/chain33_sdk/src/common"
.
"gitlab.33.cn/lihailei/chain33_sdk/src/models"
"sync/atomic"
"time"
"fmt"
)
func
ChainCheck
(
serverList
ServerList
,
task
*
Task
)
{
numC
:=
make
(
chan
struct
{},
len
(
serverList
.
ServerList
))
defer
close
(
numC
)
for
i
:=
0
;
i
<
20
;
i
++
{
time
.
Sleep
(
15
*
time
.
Second
)
var
count
int64
for
_
,
server
:=
range
serverList
.
ServerList
{
go
func
()
{
sshInfo
:=
&
SshInfo
{
server
.
UserName
,
server
.
PassWord
,
server
.
HostIp
,
server
.
Port
,
}
ok
,
err
:=
RemoteViewProcIsExist
(
"chain33"
,
*
sshInfo
)
fmt
.
Println
(
"value========:"
,
ok
)
if
ok
&&
err
==
nil
{
atomic
.
AddInt64
(
&
count
,
1
)
}
numC
<-
struct
{}{}
}()
}
//等待各个机器检查完毕
for
i
=
0
;
i
<
len
(
serverList
.
ServerList
);
i
++
{
<-
numC
}
//fmt.Println("count:",count)
//fmt.Println("len():",len(serverList.ServerList))
if
count
==
int64
(
len
(
serverList
.
ServerList
))
{
task
.
TaskStatus
=
TASK_SUCESS
fmt
.
Println
(
"task:"
,
task
)
err
:=
PutData
(
task
)
if
err
==
nil
{
fmt
.
Println
(
"putData sucess!"
)
break
}
fmt
.
Println
(
"err==========:"
,
err
.
Error
())
}
if
i
==
19
{
task
.
TaskStatus
=
TASK_FAIL
err
:=
PutData
(
task
)
if
err
==
nil
{
break
}
}
}
}
src/models/const.go
0 → 100644
View file @
fc94b850
package
models
type
Response
struct
{
Status_code
string
`json:"statu_code"`
Message
interface
{}
`json:"message"`
Result
interface
{}
`json:"result"`
}
src/models/task.go
View file @
fc94b850
...
...
@@ -6,9 +6,15 @@ import (
"encoding/json"
"errors"
"github.com/coreos/etcd/clientv3"
"golang.org/x/net/context"
"time"
"fmt"
)
var
(
dialTimeout
=
5
*
time
.
Second
requestTimeout
=
10
*
time
.
Second
endpoints
=
[]
string
{
"10.39.0.6:2379"
,}
EtcdURL
=
"http://localhost:2379"
)
...
...
@@ -45,14 +51,20 @@ func MarshalToString(data interface{}) (string, error) {
//通用存储接口封装,可根据不同类型,进行相应的kv存储
func
PutData
(
data
interface
{})
error
{
cli
,
err
:=
clientv3
.
NewFromURL
(
GetEtcdURL
())
defer
cli
.
Close
()
cli
,
err
:=
clientv3
.
New
(
clientv3
.
Config
{
Endpoints
:
[]
string
{
"localhost:2379"
},
DialTimeout
:
dialTimeout
,
})
if
err
!=
nil
{
return
err
}
defer
cli
.
Close
()
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
requestTimeout
)
if
task
,
ok
:=
data
.
(
*
Task
);
ok
{
str
,
_
:=
MarshalToString
(
task
)
_
,
err
:=
cli
.
Put
(
cli
.
Ctx
(),
task
.
TaskID
,
str
)
_
,
err
:=
cli
.
Put
(
ctx
,
task
.
TaskID
,
str
)
cancel
()
if
err
!=
nil
{
return
err
}
...
...
@@ -62,12 +74,18 @@ func PutData(data interface{}) error {
//不关注具体类型,只返回字节数组,由调用者自己进行反序列化
func
GetData
(
key
string
)
([]
byte
,
error
)
{
cli
,
err
:=
clientv3
.
NewFromURL
(
GetEtcdURL
())
defer
cli
.
Close
()
cli
,
err
:=
clientv3
.
New
(
clientv3
.
Config
{
Endpoints
:
[]
string
{
"localhost:2379"
},
DialTimeout
:
dialTimeout
,
})
if
err
!=
nil
{
return
nil
,
err
}
res
,
err
:=
cli
.
Get
(
cli
.
Ctx
(),
key
)
defer
cli
.
Close
()
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
requestTimeout
)
res
,
err
:=
cli
.
Get
(
ctx
,
key
)
cancel
()
if
err
!=
nil
{
return
nil
,
err
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment