Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
9623eeb3
Commit
9623eeb3
authored
10 years ago
by
Kevin S. Hahn
Browse files
Options
Downloads
Plain Diff
Merge branch 'adapt_to_central'
parents
acd5ba3b
b5c26f23
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api.py
+2
-2
2 additions, 2 deletions
api.py
api.wsgi
+6
-6
6 additions, 6 deletions
api.wsgi
centralclient.py
+9
-8
9 additions, 8 deletions
centralclient.py
with
17 additions
and
16 deletions
api.py
+
2
−
2
View file @
9623eeb3
...
...
@@ -139,9 +139,9 @@ if __name__ == '__main__':
app
.
config
[
'
demo
'
]
=
args
.
demo
if
not
app
.
config
[
'
ssl_cert
'
]:
log
.
warning
(
'
SSL certificate not specified,
interNIMS
functionality disabled
'
)
log
.
warning
(
'
SSL certificate not specified,
scitran central
functionality disabled
'
)
elif
not
app
.
config
[
'
site_id
'
]:
log
.
warning
(
'
site_id not configured,
interNIMS
functionality disabled
'
)
log
.
warning
(
'
site_id not configured,
scitran central
functionality disabled
'
)
if
not
os
.
path
.
exists
(
app
.
config
[
'
data_path
'
]):
os
.
makedirs
(
app
.
config
[
'
data_path
'
])
...
...
This diff is collapsed.
Click to expand it.
api.wsgi
+
6
−
6
View file @
9623eeb3
...
...
@@ -8,7 +8,7 @@ import argparse
import uwsgidecorators
import api
import
internims
client
import
central
client
os.environ['PYTHON_EGG_CACHE'] = '/tmp/python_egg_cache'
os.umask(0o022)
...
...
@@ -18,7 +18,7 @@ ap.add_argument('--db_uri', help='mongodb uri', required=True)
ap.add_argument('--data_path', help='path to data', required=True)
ap.add_argument('--log_path', help='path to log', required=True) # for SHOWING the log, not where to write
ap.add_argument('--ssl_cert', help='path to ssl cert in pem format, key+cert', required=True)
ap.add_argument('--api_uri', help='api uri')
ap.add_argument('--api_uri', help='api uri
, with https:// prefix
')
ap.add_argument('--site_id', help='site id')
ap.add_argument('--site_name', help='site name', nargs='+')
ap.add_argument('--oauth2_id_endpoint', help='oauth2 id endpoint url', default='https://www.googleapis.com/plus/v1/people/me/openIdConnect')
...
...
@@ -78,13 +78,13 @@ else:
fail_count = 0
@uwsgidecorators.timer(60)
def
internims
client_timer(signum):
def
central
client_timer(signum):
global fail_count
if not
internims
client.update(application.db, args.api_uri, args.site_name, args.site_id, args.ssl_cert, args.central_uri):
if not
central
client.update(application.db, args.api_uri, args.site_name, args.site_id, args.ssl_cert, args.central_uri):
fail_count += 1
else:
fail_count = 0
if fail_count == 3:
log.debug('
InterNIMS
unreachable, purging all remotes info')
internims
client.clean_remotes(application.db)
log.debug('
scitran central
unreachable, purging all remotes info')
central
client.clean_remotes(application.db)
This diff is collapsed.
Click to expand it.
internims
client.py
→
central
client.py
+
9
−
8
View file @
9623eeb3
...
...
@@ -12,7 +12,7 @@ local users are permitted to access data in other instances.
import
logging
import
logging.config
logging
.
basicConfig
()
log
=
logging
.
getLogger
(
'
internims
'
)
log
=
logging
.
getLogger
(
'
centralclient
'
)
logging
.
getLogger
(
'
requests
'
).
setLevel
(
logging
.
WARNING
)
# silence Requests library logging
import
re
...
...
@@ -20,7 +20,7 @@ import json
import
requests
def
update
(
db
,
api_uri
,
site_name
,
site_id
,
ssl_cert
,
internims
_url
):
def
update
(
db
,
api_uri
,
site_name
,
site_id
,
ssl_cert
,
central
_url
):
"""
Send is-alive signal to central peer registry.
"""
proj_userlist
=
[
p
[
'
permissions
'
]
for
p
in
db
.
projects
.
find
(
None
,
{
'
_id
'
:
False
,
'
permissions._id
'
:
True
,
'
permissions.site
'
:
True
})]
col_userlist
=
[
c
[
'
permissions
'
]
for
c
in
db
.
collections
.
find
(
None
,
{
'
_id
'
:
False
,
'
permissions._id
'
:
True
,
'
permissions.site
'
:
True
})]
...
...
@@ -29,9 +29,10 @@ def update(db, api_uri, site_name, site_id, ssl_cert, internims_url):
remote_users
=
set
([(
user
[
'
_id
'
],
user
[
'
site
'
])
for
container
in
proj_userlist
+
col_userlist
+
grp_userlist
for
user
in
container
if
user
.
get
(
'
site
'
)
is
not
None
])
remote_users
=
[{
'
user
'
:
user
[
0
],
'
site
'
:
user
[
1
]}
for
user
in
remote_users
]
payload
=
json
.
dumps
({
'
_id
'
:
site_id
,
'
api_uri
'
:
api_uri
,
'
users
'
:
remote_users
,
'
name
'
:
site_name
})
payload
=
json
.
dumps
({
'
api_uri
'
:
api_uri
,
'
users
'
:
remote_users
,
'
name
'
:
site_name
})
route
=
'
%s/%s/%s
'
%
(
central_url
,
'
instances
'
,
site_id
)
try
:
r
=
requests
.
p
ost
(
internims_url
,
data
=
payload
,
cert
=
ssl_cert
)
r
=
requests
.
p
ut
(
route
,
data
=
payload
,
cert
=
ssl_cert
)
except
requests
.
exceptions
.
ConnectionError
:
log
.
debug
(
'
SDMC is not reachable
'
)
else
:
...
...
@@ -87,9 +88,9 @@ if __name__ == '__main__':
import
argparse
arg_parser
=
argparse
.
ArgumentParser
()
arg_parser
.
add_argument
(
'
--
internims
_url
'
,
help
=
'
Scitran Central API URL
'
,
default
=
'
https://sdmc.scitran.io
'
)
arg_parser
.
add_argument
(
'
--
central
_url
'
,
help
=
'
Scitran Central API URL
'
,
default
=
'
https://sdmc.scitran.io
'
)
arg_parser
.
add_argument
(
'
--db_uri
'
,
help
=
'
DB URI
'
,
required
=
True
)
arg_parser
.
add_argument
(
'
--api_uri
'
,
help
=
'
API URL, with
out
http://
or https://
'
,
required
=
True
)
arg_parser
.
add_argument
(
'
--api_uri
'
,
help
=
'
API URL, with http
s
://
prefix
'
,
required
=
True
)
arg_parser
.
add_argument
(
'
--site_id
'
,
help
=
'
instance hostname (used as unique ID)
'
,
required
=
True
)
arg_parser
.
add_argument
(
'
--site_name
'
,
help
=
'
instance name
'
,
nargs
=
'
+
'
,
required
=
True
)
arg_parser
.
add_argument
(
'
--ssl_cert
'
,
help
=
'
path to server ssl certificate file
'
,
required
=
True
)
...
...
@@ -106,11 +107,11 @@ if __name__ == '__main__':
fail_count
=
0
while
True
:
if
not
update
(
db
,
args
.
api_uri
,
args
.
site_name
,
args
.
site_id
,
args
.
ssl_cert
,
args
.
internims
_url
):
if
not
update
(
db
,
args
.
api_uri
,
args
.
site_name
,
args
.
site_id
,
args
.
ssl_cert
,
args
.
central
_url
):
fail_count
+=
1
else
:
fail_count
=
0
if
fail_count
==
3
:
log
.
debug
(
'
InterNIMS
unreachable, purging all remotes info
'
)
log
.
debug
(
'
scitran central
unreachable, purging all remotes info
'
)
clean_remotes
(
db
)
time
.
sleep
(
args
.
sleeptime
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment