Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
UvA
CONF
Commits
b38bd2ce
Commit
b38bd2ce
authored
Oct 31, 2017
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed encoding error
parent
4826746e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
20 deletions
+42
-20
DeployService.java
.../main/java/nl/uva/sne/drip/api/service/DeployService.java
+2
-1
Converter.java
...rc/main/java/nl/uva/sne/drip/commons/utils/Converter.java
+5
-0
docker_check.py
drip-deployer/docker_check.py
+35
-19
docker_check.pyc
drip-deployer/docker_check.pyc
+0
-0
No files found.
drip-api/src/main/java/nl/uva/sne/drip/api/service/DeployService.java
View file @
b38bd2ce
...
@@ -601,8 +601,9 @@ public class DeployService {
...
@@ -601,8 +601,9 @@ public class DeployService {
Map
<
String
,
Object
>
info
=
new
HashMap
();
Map
<
String
,
Object
>
info
=
new
HashMap
();
for
(
MessageParameter
param
:
params
)
{
for
(
MessageParameter
param
:
params
)
{
String
jsonResp
=
param
.
getValue
().
replaceAll
(
"^\"|\"$"
,
""
);
String
jsonResp
=
param
.
getValue
().
replaceAll
(
"^\"|\"$"
,
""
);
System
.
err
.
println
(
jsonResp
);
Map
<
String
,
Object
>
kv
=
Converter
.
jsonString2Map
(
jsonResp
);
Map
<
String
,
Object
>
kv
=
Converter
.
jsonString2Map
(
jsonResp
);
info
.
putAll
(
kv
);
info
.
putAll
(
kv
);
}
}
return
info
;
return
info
;
...
...
drip-commons/src/main/java/nl/uva/sne/drip/commons/utils/Converter.java
View file @
b38bd2ce
...
@@ -26,6 +26,8 @@ import java.util.Iterator;
...
@@ -26,6 +26,8 @@ import java.util.Iterator;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials
;
import
nl.uva.sne.drip.drip.commons.data.v1.external.CloudCredentials
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.commons.io.FilenameUtils
;
...
@@ -102,6 +104,9 @@ public class Converter {
...
@@ -102,6 +104,9 @@ public class Converter {
value
=
jsonArray2List
((
JSONArray
)
value
);
value
=
jsonArray2List
((
JSONArray
)
value
);
}
else
if
(
value
instanceof
JSONObject
)
{
}
else
if
(
value
instanceof
JSONObject
)
{
value
=
jsonObject2Map
((
JSONObject
)
value
);
value
=
jsonObject2Map
((
JSONObject
)
value
);
}
else
if
(
value
.
equals
(
"[]"
))
{
Logger
.
getLogger
(
Converter
.
class
.
getName
()).
log
(
Level
.
WARNING
,
"value: {0} is not JSONArray or an JSONObject"
,
value
);
value
=
null
;
}
}
map
.
put
(
key
,
value
);
map
.
put
(
key
,
value
);
}
}
...
...
drip-deployer/docker_check.py
View file @
b38bd2ce
...
@@ -23,10 +23,11 @@ import json
...
@@ -23,10 +23,11 @@ import json
import
logging
import
logging
import
linecache
import
linecache
import
sys
import
sys
import
re
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
if
not
getattr
(
logger
,
'handler_set'
,
None
):
if
not
getattr
(
logger
,
'handler_set'
,
None
):
logger
.
setLevel
(
logging
.
INFO
)
#
logger.setLevel(logging.INFO)
h
=
logging
.
StreamHandler
()
h
=
logging
.
StreamHandler
()
formatter
=
logging
.
Formatter
(
'
%(asctime)
s -
%(name)
s -
%(levelname)
s -
%(message)
s'
)
formatter
=
logging
.
Formatter
(
'
%(asctime)
s -
%(name)
s -
%(levelname)
s -
%(message)
s'
)
h
.
setFormatter
(
formatter
)
h
.
setFormatter
(
formatter
)
...
@@ -34,6 +35,10 @@ if not getattr(logger, 'handler_set', None):
...
@@ -34,6 +35,10 @@ if not getattr(logger, 'handler_set', None):
logger
.
handler_set
=
True
logger
.
handler_set
=
True
def
get_resp_line
(
line
):
line
=
line
.
encode
(
'utf-8'
)
.
strip
(
'
\n
'
)
.
encode
(
'string_escape'
)
return
json
.
dumps
(
line
)
def
docker_check
(
vm
,
compose_name
):
def
docker_check
(
vm
,
compose_name
):
try
:
try
:
...
@@ -48,10 +53,10 @@ def docker_check(vm, compose_name):
...
@@ -48,10 +53,10 @@ def docker_check(vm, compose_name):
cluster_node_info
=
[]
cluster_node_info
=
[]
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
cmd
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
cmd
)
node_ls_resp
=
stdout
.
readlines
()
node_ls_resp
=
stdout
.
readlines
()
for
i
in
node_ls_resp
:
for
i
in
node_ls_resp
:
if
i
.
encode
():
line
=
get_resp_line
(
i
)
json_str
=
json
.
loads
(
i
.
encode
()
.
strip
(
'
\n
'
))
if
line
:
cluster_node_info
.
append
(
json
_str
)
cluster_node_info
.
append
(
json
.
loads
(
line
)
)
json_response
[
'cluster_node_info'
]
=
cluster_node_info
json_response
[
'cluster_node_info'
]
=
cluster_node_info
services_format
=
'
\'
{
\"
ID
\"
:
\"
{{.ID}}
\"
,
\"
name
\"
:
\"
{{.Name}}
\"
,
\"
image
\"
:
\"
{{.Image}}
\"
,
\"
node
\"
:
\"
{{.Node}}
\"
,
\"
desired_state
\"
:
\"
{{.DesiredState}}
\"
,
\"
current_state
\"
:
\"
{{.CurrentState}}
\"
,
\"
error
\"
:
\"
{{.Error}}
\"
,
\"
ports
\"
:
\"
{{.Ports}}
\"
}
\'
'
services_format
=
'
\'
{
\"
ID
\"
:
\"
{{.ID}}
\"
,
\"
name
\"
:
\"
{{.Name}}
\"
,
\"
image
\"
:
\"
{{.Image}}
\"
,
\"
node
\"
:
\"
{{.Node}}
\"
,
\"
desired_state
\"
:
\"
{{.DesiredState}}
\"
,
\"
current_state
\"
:
\"
{{.CurrentState}}
\"
,
\"
error
\"
:
\"
{{.Error}}
\"
,
\"
ports
\"
:
\"
{{.Ports}}
\"
}
\'
'
...
@@ -60,22 +65,32 @@ def docker_check(vm, compose_name):
...
@@ -60,22 +65,32 @@ def docker_check(vm, compose_name):
stack_ps_resp
=
stdout
.
readlines
()
stack_ps_resp
=
stdout
.
readlines
()
services_info
=
[]
services_info
=
[]
nodes_hostname
=
set
()
nodes_hostname
=
set
()
for
i
in
stack_ps_resp
:
for
i
in
stack_ps_resp
:
if
i
.
encode
():
line
=
get_resp_line
(
i
)
json_str
=
json
.
loads
(
i
.
encode
()
.
strip
(
'
\n
'
))
if
line
:
if
json_str
[
'node'
]
not
in
nodes_hostname
:
json_dict
=
json
.
loads
(
line
)
nodes_hostname
.
add
(
json_str
[
'node'
])
json_dict
=
json
.
loads
(
json
.
dumps
(
json_dict
))
services_info
.
append
(
json_str
)
if
not
isinstance
(
json_dict
,
dict
):
try
:
json_dict
=
json
.
loads
(
json_dict
)
except
Exception
as
e
:
json_dict
=
json_dict
.
replace
(
'
\"
ports
\"
:
\"\"
'
,
'
\"
ports
\"
:null'
)
.
replace
(
'
\"\"
'
,
'
\"
'
)
json_dict
=
json_dict
.
replace
(
"
\\
"
,
""
)
.
replace
(
"Noxe2x80xa6"
,
"No..."
)
json_dict
=
json
.
loads
(
json_dict
)
nodes_hostname
.
add
(
json_dict
[
'node'
])
services_info
.
append
(
json_dict
)
json_response
[
'services_info'
]
=
services_info
json_response
[
'services_info'
]
=
services_info
stack_format
=
'
\'
{"ID":"{{.ID}}","name":"{{.Name}}","mode":"{{.Mode}}","replicas":"{{.Replicas}}","image":"{{.Image}}"}
\'
'
stack_format
=
'
\'
{"ID":"{{.ID}}","name":"{{.Name}}","mode":"{{.Mode}}","replicas":"{{.Replicas}}","image":"{{.Image}}"}
\'
'
cmd
=
'sudo docker stack services '
+
compose_name
+
' --format '
+
(
stack_format
)
cmd
=
'sudo docker stack services '
+
compose_name
+
' --format '
+
(
stack_format
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
cmd
)
stdin
,
stdout
,
stderr
=
ssh
.
exec_command
(
cmd
)
stack_resp
=
stdout
.
readlines
()
stack_resp
=
stdout
.
readlines
()
stack_info
=
[]
stack_info
=
[]
for
i
in
stack_resp
:
for
i
in
stack_resp
:
if
i
.
encode
():
line
=
get_resp_line
(
i
)
json_str
=
json
.
loads
(
i
.
encode
()
.
strip
(
'
\n
'
))
if
line
:
stack_info
.
append
(
json_str
)
json_dict
=
json
.
loads
(
line
)
stack_info
.
append
(
json_dict
)
json_response
[
'stack_info'
]
=
stack_info
json_response
[
'stack_info'
]
=
stack_info
cmd
=
'sudo docker node inspect '
cmd
=
'sudo docker node inspect '
...
@@ -87,11 +102,12 @@ def docker_check(vm, compose_name):
...
@@ -87,11 +102,12 @@ def docker_check(vm, compose_name):
response_str
=
""
response_str
=
""
for
i
in
inspect_resp
:
for
i
in
inspect_resp
:
if
i
.
encode
():
line
=
get_resp_line
(
i
)
response_str
+=
i
.
encode
()
.
strip
(
'
\n
'
)
if
line
:
response_str
+=
line
json_
str
=
json
.
loads
(
response_str
.
rstrip
(
"
\n\r
"
)
.
strip
()
.
encode
(
'string_escape'
))
json_
dict
=
json
.
loads
(
response_str
.
rstrip
(
"
\n\r
"
)
.
strip
()
.
encode
(
'string_escape'
))
json_response
[
'nodes_info'
]
=
json_
str
json_response
[
'nodes_info'
]
=
json_
dict
logger
.
info
(
"Finished docker info services on: "
+
vm
.
ip
)
logger
.
info
(
"Finished docker info services on: "
+
vm
.
ip
)
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -104,7 +120,7 @@ def docker_check(vm, compose_name):
...
@@ -104,7 +120,7 @@ def docker_check(vm, compose_name):
print
'EXCEPTION IN ({}, LINE {} "{}"): {}'
.
format
(
filename
,
lineno
,
line
.
strip
(),
exc_obj
)
print
'EXCEPTION IN ({}, LINE {} "{}"): {}'
.
format
(
filename
,
lineno
,
line
.
strip
(),
exc_obj
)
logger
.
error
(
vm
.
ip
+
" "
+
str
(
e
)
+
" line:"
+
lineno
)
#
logger.error(vm.ip + " " + str(e)+ " line:" +lineno)
return
"ERROR:"
+
vm
.
ip
+
" "
+
str
(
e
)
return
"ERROR:"
+
vm
.
ip
+
" "
+
str
(
e
)
ssh
.
close
()
ssh
.
close
()
return
json_response
return
json_response
...
...
drip-deployer/docker_check.pyc
View file @
b38bd2ce
No preview for this file type
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