2 # -------------------------------------------------------------------------
3 # Copyright (c) 2015-2017 AT&T Intellectual Property
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # -------------------------------------------------------------------------
21 from oslo_config import cfg
22 from oslo_log import log
24 from conductor.common.models import plan
25 from conductor.common.music import api
26 from conductor.common.music import messaging as music_messaging
27 from conductor.common.music.model import base
28 from conductor.controller import rpc
29 from conductor.controller import translator_svc
30 from conductor import messaging
31 from conductor import service
33 LOG = log.getLogger(__name__)
41 help='Timeout for planning requests. '
42 'Default value is 10.'),
46 help='Maximum number of result sets to return. '
47 'Default value is 1.'),
51 help='Number of workers for controller service. '
52 'Default value is 1.'),
53 cfg.BoolOpt('concurrent',
55 help='Set to True when controller will run in active-active '
56 'mode. When set to False, controller will flush any '
57 'abandoned messages at startup. The controller always '
58 'restarts abandoned template translations at startup.'),
65 CONF.register_opts(CONTROLLER_OPTS, group='controller')
67 # Pull in service opts. We use them here.
69 CONF.register_opts(OPTS)
72 class ControllerServiceLauncher(object):
73 """Launcher for the controller service."""
75 def __init__(self, conf):
78 # Set up Music access.
79 self.music = api.API()
80 self.music.keyspace_create(keyspace=conf.keyspace)
82 # Dynamically create a plan class for the specified keyspace
83 self.Plan = base.create_dynamic_model(
84 keyspace=conf.keyspace, baseclass=plan.Plan, classname="Plan")
90 transport = messaging.get_transport(self.conf)
93 target = music_messaging.Target(topic=topic)
94 endpoints = [rpc.ControllerRPCEndpoint(self.conf, self.Plan), ]
95 flush = not self.conf.controller.concurrent
96 kwargs = {'transport': transport,
98 'endpoints': endpoints,
100 svcmgr = cotyledon.ServiceManager()
101 svcmgr.add(music_messaging.RPCService,
102 workers=self.conf.controller.workers,
103 args=(self.conf,), kwargs=kwargs)
105 kwargs = {'plan_class': self.Plan, }
106 svcmgr.add(translator_svc.TranslatorService,
107 workers=self.conf.controller.workers,
108 args=(self.conf,), kwargs=kwargs)