Exemplo n.º 1
0
    def __init__(self,
                 config=None,
                 lib=None,
                 disk_path=None,
                 proxy_endpoint=None):
        if lib is None:
            lib = Library().lib_

        if config is None:
            config = messages_pb2.MasterComponentConfig()
        if disk_path is not None:
            config.disk_path = disk_path

        self.lib_ = lib
        master_config_blob = config.SerializeToString()
        master_config_blob_p = ctypes.create_string_buffer(master_config_blob)

        if isinstance(config, messages_pb2.MasterComponentConfig):
            self.config_ = config
            self.id_ = HandleErrorCode(
                self.lib_,
                self.lib_.ArtmCreateMasterComponent(len(master_config_blob),
                                                    master_config_blob_p))
            return

        if isinstance(config, messages_pb2.MasterProxyConfig):
            self.config_ = config.config
            self.id_ = HandleErrorCode(
                self.lib_,
                self.lib_.ArtmCreateMasterProxy(len(master_config_blob),
                                                master_config_blob_p))
            return

        raise ArgumentOutOfRangeException(
            "config is neither MasterComponentConfig nor MasterProxyConfig")
Exemplo n.º 2
0
 def CreateScore(self, name, type, config):
     master_config = messages_pb2.MasterComponentConfig()
     master_config.CopyFrom(self.config_)
     score_config = master_config.score_config.add()
     score_config.name = name
     score_config.type = type
     score_config.config = config.SerializeToString()
     self.Reconfigure(master_config)
Exemplo n.º 3
0
    def RemoveStream(self, stream_name):
        new_config_ = messages_pb2.MasterComponentConfig()
        new_config_.CopyFrom(self.config_)
        new_config_.ClearField('stream')

        for stream_index in range(0, len(self.config_.stream)):
            if self.config_.stream[stream_index].name != stream_name:
                s = new_config_.stream.add()
                s.CopyFrom(self.config_.stream[stream_index])
        self.Reconfigure(new_config_)
Exemplo n.º 4
0
 def CreateMasterComponent(self, config=None):
     if config is None:
         config = messages_pb2.MasterComponentConfig()
     return MasterComponent(config, self.lib_)
Exemplo n.º 5
0
 def config(self):
     master_config = messages_pb2.MasterComponentConfig()
     master_config.CopyFrom(self.config_)
     return master_config
Exemplo n.º 6
0
 def CreateMasterComponent(self,
                           config=messages_pb2.MasterComponentConfig()):
     return MasterComponent(config, self.lib_)
Exemplo n.º 7
0
if sys.platform.count('linux') == 1:
    interface_address = os.path.abspath(
        os.path.join(os.curdir, os.pardir, 'python_interface'))
    sys.path.append(interface_address)
else:
    sys.path.append('../python_interface/')

import messages_pb2
import python_interface
from python_interface import *

#################################################################################
# ALL CODE BELOW DEFINES PROTOBUF MESSAGES NEED TO TEST THE INTERFACE FUNCTIONS

# Create master_config
master_config = messages_pb2.MasterComponentConfig()
master_config.processors_count = 2
master_config.processor_queue_max_size = 5
master_config.cache_theta = 1

perplexity_config = messages_pb2.PerplexityScoreConfig()
perplexity_config.stream_name = 'stream_0'

master_proxy_config = messages_pb2.MasterProxyConfig()
master_proxy_config.node_connect_endpoint = "tcp://localhost:5555"
master_proxy_config.config.CopyFrom(master_config)

stream_ = master_config.stream.add()
stream_.name = ('stream_0')
stream_.type = Stream_Type_Global
stream_.modulus = 3