コード例 #1
0
    def __init__(self, config: Config):

        orchestration_topic = config.try_get(
            'servicesettings.orchestration-channel-in',
            default.ORCHESTRATION_NOTIF_TOPIC_DEFAULT)
        client_name = config.try_get('servicesettings.service-client-name',
                                     None)
        self.__notification_service_store_name = config.try_get(
            'servicesettings.notification-service-store-name',
            NotificationService.NOTIFICATION_SERVICE_STORE_NAME_DEFAULT)

        # load configurations
        self.__db_conn = CouchDbConnection(config['store.couchdb.connection'],
                                           config['store.couchdb.username'],
                                           config['store.couchdb.usertoken'])
        self.__pubsub_conn = PubSubConnectionKafka(
            config['eventqueue.kafka.server'])

        # intialize db readers
        self.__noti_repo = NotificationDefinitionRepository(
            self.__db_conn, self.__notification_service_store_name)

        # initialize message bus manager
        self.__pubsub_mgr = PubSubManagerKafka(self.__pubsub_conn,
                                               acquire_service_logger())

        super().__init__(orchestration_topic, self.__pubsub_mgr, client_name)

        # initialize handlers
        self.__update_handlers()

        # logging the client name for debugging
        self.log.debug(
            f"Created instance with client name {self._BaseWorkerService__client_name}"
        )
コード例 #2
0
    def test_negative(self):
        dummy_config_file_text = """
        version: 1.0
        store:
          couchdb:
            connection: 'localhost:5984'
            username: fake
            usertoken: fake
        """
        c = Config(None, dummy_config_file_text)

        try:
            print(c['store.kafka.connection'])
            self.assertTrue(False)  # must not reach here
        except KeyError as e:
            self.assertIsNotNone(e)

        default_val = c.try_get('store.kafka.connection', 'default_value')
        self.assertEqual(default_val, "default_value")
コード例 #3
0
    def __init__(self, config: Config):

        orch_infer_topic = config.try_get(
            'servicesettings.orchestration-inference-channel-in',
            default.ORCHESTRATION_INFER_TOPIC_DEFAULT)
        orch_notif_topic = config.try_get(
            'servicesettings.orchestration-notification-channel-in',
            default.ORCHESTRATION_NOTIF_TOPIC_DEFAULT)
        self.__scenario_store_name = config.try_get(
            'servicesettings.orchestration-service-store-name',
            OrchestrationService.ORCHESTRATION_SERVICE_STORE_NAME_DEFAULT)
        self.__client_name = config.try_get(
            'servicesettings.service-client-name', None)

        # load configurations
        self.__db_conn = CouchDbConnection(config['store.couchdb.connection'],
                                           config['store.couchdb.username'],
                                           config['store.couchdb.usertoken'])
        self.__pubsub_conn = PubSubConnectionKafka(
            config['eventqueue.kafka.server'])

        # intialize db readers
        self.__scn_repo = ScenarioRepository(self.__db_conn,
                                             self.__scenario_store_name)

        # initialize message bus manager and producers
        self.__pubsub_mgr = PubSubManagerKafka(self.__pubsub_conn,
                                               acquire_service_logger())
        self.__pubsub_mgr.create_topic_if_not_exist(orch_infer_topic)
        self.__pubsub_mgr.create_topic_if_not_exist(orch_notif_topic)
        self.__producers = {
            'infer':
            self.__pubsub_mgr.create_producer(orch_infer_topic,
                                              self.__client_name),
            'notif':
            self.__pubsub_mgr.create_producer(orch_notif_topic,
                                              self.__client_name),
        }

        super().__init__()
コード例 #4
0
    def __init__(self, config: Config):

        orchestration_topic = config.try_get(
            'servicesettings.orchestration-channel-in',
            default.ORCHESTRATION_INFER_TOPIC_DEFAULT)
        client_name = config.try_get('servicesettings.service-client-name',
                                     None)
        self.__inference_service_store_name = config.try_get(
            'servicesettings.inference-service-store-name',
            InferenceService.INFERENCE_SERVICE_STORE_NAME_DEFAULT)

        # load configurations
        self.__db_conn = CouchDbConnection(config['store.couchdb.connection'],
                                           config['store.couchdb.username'],
                                           config['store.couchdb.usertoken'])
        self.__pubsub_conn = PubSubConnectionKafka(
            config['eventqueue.kafka.server'])
        self.__model_cache_location = config.try_get(
            'servicesettings.model_cache_location',
            default.MODEL_CACHE_LOCATION)

        # intialize db readers
        self.__infer_repo = InferenceDefinitionRepository(
            self.__db_conn, self.__inference_service_store_name)

        # initialize message bus manager
        self.__pubsub_mgr = PubSubManagerKafka(self.__pubsub_conn,
                                               acquire_service_logger())

        super().__init__(orchestration_topic, self.__pubsub_mgr, client_name)

        # initialize model cache
        self.__model_cache = ModelCache(self.__model_cache_location, self.log)

        # logging the client name for debugging
        self.log.debug(
            f"Created instance with client name {self._BaseWorkerService__client_name}"
        )
コード例 #5
0
def main(args=None):

    parsed_args = parse_arguments(args)
    if parsed_args is None:
        print_help()

    default_cfg_path = os.path.join(os.path.dirname(__file__), "config.yml")
    cfg_path = parsed_args.get('config', default_cfg_path)
    cfg = Config(cfg_path)

    log = setup_service_logger(verbose=True)
    log.debug(f"Starting up using config '{cfg_path}' ...")

    svc_inst = svc.NotificationService(cfg)
    svc_inst.start(wait=True)
コード例 #6
0
    def test_basic(self):
        dummy_config_file_name = "config.yaml.temp"
        dummy_config_file_text = """
        version: 1.0
        store:
          couchdb:
            connection: 'localhost:5984'
            username: fake
            usertoken: fake
        """
        with open(dummy_config_file_name, "w",
                  encoding="utf-8") as dummy_config_file:
            print(dummy_config_file_text, file=dummy_config_file)
        c = Config(dummy_config_file_name)

        self.assertEqual(c['store']['couchdb']['connection'], 'localhost:5984')
        self.assertEqual(c['store.couchdb.connection'], 'localhost:5984')
コード例 #7
0
    def test_override(self):
        dummy_config_file_text = """
        version: 1.0
        store:
          couchdb:
            connection: 'localhost:5984'
            username: fake
            usertoken: fake
        """
        os.environ["THEBOX_STORE_COUCHDB_USERNAME"] = "******"
        c = Config(None, dummy_config_file_text)
        del os.environ["THEBOX_STORE_COUCHDB_USERNAME"]

        self.assertEqual(c['store']['couchdb']['username'], 'real')
        self.assertEqual(c['store.couchdb.username'], 'real')
        self.assertEqual(c['store']['couchdb']['usertoken'], 'fake')
        self.assertEqual(c['store.couchdb.usertoken'], 'fake')
コード例 #8
0
def main(args=None):

    parsed_args = parse_arguments(args)
    if parsed_args is None:
        print_help()

    default_cfg_path = os.path.join(os.path.dirname(__file__), "config.yml")
    cfg_path = parsed_args.get('config', default_cfg_path)
    cfg = Config(cfg_path)

    log = setup_service_logger(verbose=True)
    log.debug(f"Starting up using config '{cfg_path}' ...")

    api_resources = [
        APIResource(api.OrchestrationServiceAPI, '/scenario',
                    svc.OrchestrationService(cfg))
    ]

    app = create_app("ochestrator", api_resources)
    app.run(host='0.0.0.0', debug=True)
コード例 #9
0
    def setupTestPubsubTopics(self) -> PubSubManager:

        self.test_orch_topic = "unittest_orchestration_topic"
        self.test_scn_in_topic = "unittest_scenario_in_topic"
        self.test_scn_out_topic = "unittest_scenario_out_topic"
        self.test_infer_store = "unittest_table_inference"
        self.test_service_client_name = "unittest_inference_service"

        config = f"""
# config.yml

version: 1.0
store:
  couchdb:
    connection: "{self.test_db_conn.url}"
    username: {self.test_db_conn.user}
    usertoken: {self.test_db_conn.token}
eventqueue:
  kafka:
    server: "{self.test_pubsub_conn.server_url}"
servicesettings:
  orchestration-channel-in: {self.test_orch_topic}
  inference-service-store-name: {self.test_infer_store}
  service-client-name: {self.test_service_client_name}
  model_cache_location: '/var/tmp/thebox_test'
"""
        self.cfg = Config(None, config)
        print(self.cfg)

        initialize_test_db(self.test_db_conn, self.test_infer_store)

        pubsubmgr = PubSubManagerKafka(self.test_pubsub_conn)
        pubsubmgr.reset()
        time.sleep(5)

        pubsubmgr.create_topic_if_not_exist(self.test_orch_topic)
        pubsubmgr.create_topic_if_not_exist(self.test_scn_in_topic)
        pubsubmgr.create_topic_if_not_exist(self.test_scn_out_topic)

        return pubsubmgr