Merge "Add launch script for each service"

This commit is contained in:
Jenkins 2016-01-06 08:53:29 +00:00 committed by Gerrit Code Review
commit 887a7d155e
6 changed files with 485 additions and 0 deletions

View File

@ -32,3 +32,7 @@ upload-dir = doc/build/html
[entry_points]
console_scripts =
terracotta-server = terracotta.cmd.launch:main
terracotta-api = terracotta.cmd.api:main
terracotta-global-manager = terracotta.cmd.global_manager:main
terracotta-local-manager = terracotta.cmd.local_manager:main
terracotta-collector = terracotta.cmd.collector:main

108
terracotta/cmd/api.py Normal file
View File

@ -0,0 +1,108 @@
# Copyright 2016 - Huawei Technologies Co. Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import eventlet
eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)
import os
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'terracotta', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR)
from oslo_config import cfg
from oslo_log import log as logging
from wsgiref import simple_server
from terracotta.api import app
from terracotta import config
from terracotta import rpc
from terracotta import version
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
def launch_api(transport):
host = cfg.CONF.api.host
port = cfg.CONF.api.port
server = simple_server.make_server(
host,
port,
app.setup_app()
)
LOG.info("Terracotta API is serving on http://%s:%s (PID=%s)" %
(host, port, os.getpid()))
server.serve_forever()
TERRACOTTA_TITLE = """
##### ##### ##### ##### ##### ##### ##### ##### ##### #####
# # # # # # # # # # # # # # #
# ##### ##### ##### ##### # # # # # #####
# # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# ##### # # # # # # ##### ##### # # # #
Terracotta Dynamic Scheduling Service, version %s
""" % version.version_string()
def print_service_info():
print(TERRACOTTA_TITLE)
comp_str = ("terracotta API"
if cfg.CONF.server == ['all'] else cfg.CONF.server)
print('Launching server components %s...' % comp_str)
def launch_any(transport, options):
thread = eventlet.spawn(launch_api, transport)
print('Server started.')
thread.wait()
def main():
try:
config.parse_args()
print_service_info()
logging.setup(CONF, 'Terracotta')
transport = rpc.get_transport()
launch_any(transport, set(cfg.CONF.server))
except RuntimeError as excp:
sys.stderr.write("ERROR: %s\n" % excp)
sys.exit(1)
if __name__ == '__main__':
main()

122
terracotta/cmd/collector.py Normal file
View File

@ -0,0 +1,122 @@
# Copyright 2016 - Huawei Technologies Co. Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import eventlet
eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)
import os
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'terracotta', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR)
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from terracotta import config
from terracotta import rpc
from terracotta.locals import collector
from terracotta.openstack.common import threadgroup
from terracotta import version
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
def launch_collector(transport):
target = messaging.Target(
topic=cfg.CONF.collector.topic,
server=cfg.CONF.collector.host
)
launch_collector = collector.Collector()
endpoints = [rpc.GlobalManagerServer(launch_collector)]
tg = threadgroup.ThreadGroup()
tg.add_dynamic_timer(
launch_collector.run_periodic_tasks,
initial_delay=None,
periodic_interval_max=None,
context=None
)
server = messaging.get_rpc_server(
transport,
target,
endpoints,
executor='eventlet'
)
server.start()
server.wait()
def launch_any(transport, options):
thread = eventlet.spawn(launch_collector, transport)
print('Server started.')
thread.wait()
TERRACOTTA_TITLE = """
##### ##### ##### ##### ##### ##### ##### ##### ##### #####
# # # # # # # # # # # # # # #
# ##### ##### ##### ##### # # # # # #####
# # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# ##### # # # # # # ##### ##### # # # #
Terracotta Dynamic Scheduling Service, version %s
""" % version.version_string()
def print_service_info():
print(TERRACOTTA_TITLE)
comp_str = ("collector"
if cfg.CONF.server == ['all'] else cfg.CONF.server)
print('Launching server components %s...' % comp_str)
def main():
try:
config.parse_args()
print_service_info()
logging.setup(CONF, 'Terracotta')
transport = rpc.get_transport()
launch_any(transport, set(cfg.CONF.server))
except RuntimeError as excp:
sys.stderr.write("ERROR: %s\n" % excp)
sys.exit(1)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,112 @@
# Copyright 2016 - Huawei Technologies Co. Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import eventlet
eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)
import os
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'terracotta', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR)
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from terracotta import config
from terracotta import rpc
from terracotta.globals import manager as global_mgr
from terracotta import version
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
def launch_global_manager(transport):
target = messaging.Target(
topic=cfg.CONF.global_manager.topic,
server=cfg.CONF.global_manager.host
)
global_manager = global_mgr.GlobalManager()
endpoints = [rpc.GlobalManagerServer(global_manager)]
server = messaging.get_rpc_server(
transport,
target,
endpoints,
executor='eventlet',
)
server.start()
server.wait()
def launch_any(transport, options):
thread = eventlet.spawn(launch_global_manager, transport)
print('Server started.')
thread.wait()
TERRACOTTA_TITLE = """
##### ##### ##### ##### ##### ##### ##### ##### ##### #####
# # # # # # # # # # # # # # #
# ##### ##### ##### ##### # # # # # #####
# # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# ##### # # # # # # ##### ##### # # # #
Terracotta Dynamic Scheduling Service, version %s
""" % version.version_string()
def print_service_info():
print(TERRACOTTA_TITLE)
comp_str = ("global-manager"
if cfg.CONF.server == ['all'] else cfg.CONF.server)
print('Launching server components %s...' % comp_str)
def main():
try:
config.parse_args()
print_service_info()
logging.setup(CONF, 'Terracotta')
transport = rpc.get_transport()
launch_any(transport, set(cfg.CONF.server))
except RuntimeError as excp:
sys.stderr.write("ERROR: %s\n" % excp)
sys.exit(1)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,120 @@
# Copyright 2016 - Huawei Technologies Co. Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
import eventlet
eventlet.monkey_patch(
os=True,
select=True,
socket=True,
thread=False if '--use-debugger' in sys.argv else True,
time=True)
import os
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'terracotta', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR)
from oslo_config import cfg
from oslo_log import log as logging
import oslo_messaging as messaging
from terracotta import config
from terracotta import rpc
from terracotta.locals import manager as local_mgr
from terracotta.openstack.common import threadgroup
from terracotta import version
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
def launch_local_manager(transport):
target = messaging.Target(
topic=cfg.CONF.local_manager.topic,
server=cfg.CONF.local_manager.host
)
local_manager = local_mgr.LocalManager()
endpoints = [rpc.LocalManagerServer(local_manager)]
tg = threadgroup.ThreadGroup()
tg.add_dynamic_timer(
local_manager.run_periodic_tasks,
initial_delay=None,
periodic_interval_max=None,
context=None
)
server = messaging.get_rpc_server(
transport,
target,
endpoints,
executor='eventlet'
)
server.start()
server.wait()
def launch_any(transport, options):
thread = eventlet.spawn(launch_local_manager, transport)
print('Server started.')
thread.wait()
TERRACOTTA_TITLE = """
##### ##### ##### ##### ##### ##### ##### ##### ##### #####
# # # # # # # # # # # # # # #
# ##### ##### ##### ##### # # # # # #####
# # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
# ##### # # # # # # ##### ##### # # # #
Terracotta Dynamic Scheduling Service, version %s
""" % version.version_string()
def print_service_info():
print(TERRACOTTA_TITLE)
comp_str = ("local-manager"
if cfg.CONF.server == ['all'] else cfg.CONF.server)
print('Launching server components %s...' % comp_str)
def main():
try:
config.parse_args()
print_service_info()
logging.setup(CONF, 'Terracotta')
transport = rpc.get_transport()
launch_any(transport, set(cfg.CONF.server))
except RuntimeError as excp:
sys.stderr.write("ERROR: %s\n" % excp)
sys.exit(1)
if __name__ == '__main__':
main()

View File

@ -87,8 +87,27 @@ from terracotta import common
from terracotta.utils import db_utils
global_mgr_ops = [
cfg.StrOpt('os_admin_user',
default='admin',
help='The admin user name for authentication '
'with Nova using Keystone.'),
cfg.StrOpt('os_admin_password',
default='admin',
help='The admin user password for authentication '
'with Nova using Keystone.'),
cfg.StrOpt('os_admin_tenant_name',
default='admin',
group='global_manager',
help='The admin user password for authentication '
'with Nova using Keystone.'),
]
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
CONF.register_opts(global_mgr_ops)
def host_mac(host):