Exemple #1
0
def main(argv):
    logging.info("RadioStation main got argv(list): " + str(argv))

    try:
        opts, args = getopt.getopt(argv, "dhp:", ["help", "port=", "cert="])
    except getopt.GetoptError as e:
        logging.error(e)
        usage()
        sys.exit(1)

    port = conf.PORT_RADIOSTATION
    cert = None
    pw = None

    # apply option values
    for opt, arg in opts:
        if opt == "-d":
            util.set_log_level_debug()
        elif (opt == "-p") or (opt == "--port"):
            port = arg
        elif opt == "--cert":
            cert = arg
        elif (opt == "-h") or (opt == "--help"):
            usage()
            return

    # Check Port is Using
    if util.check_port_using(conf.IP_RADIOSTATION, int(port)):
        logging.error('RadioStation Service Port is Using ' + str(port))
        return

    RadioStationService(conf.IP_RADIOSTATION, cert, pw).serve(port)
Exemple #2
0
def main(argv):
    logging.info("Peer main got argv(list): " + str(argv))

    try:
        opts, args = getopt.getopt(argv, "dhr:p:c:",
                                   ["help",
                                    "radio_station_ip=",
                                    "radio_station_port=",
                                    "port=",
                                    "score=",
                                    "cert="
                                    ])
    except getopt.GetoptError as e:
        logging.error(e)
        usage()
        sys.exit(1)

    # default option values
    port = conf.PORT_PEER
    radio_station_ip = conf.IP_RADIOSTATION
    radio_station_port = conf.PORT_RADIOSTATION
    score = conf.DEFAULT_SCORE_PACKAGE
    cert = None
    pw = None

    # apply option values
    for opt, arg in opts:
        if (opt == "-r") or (opt == "--radio_station_ip"):
            radio_station_ip = arg
        elif (opt == "-p") or (opt == "--port"):
            port = arg
        elif (opt == "-c") or (opt == "--score"):
            score = arg
        elif opt == "--cert":
            cert = arg
        elif opt == "-d":
            util.set_log_level_debug()
        elif (opt == "-h") or (opt == "--help"):
            usage()
            return

    # run peer service with parameters
    logging.info("\nTry Peer Service run with: \nport(" +
                 str(port) + ") \nRadio Station(" +
                 radio_station_ip + ":" +
                 str(radio_station_port) + ") \nScore(" +
                 score + ") \n")
    # check Port Using
    if util.check_port_using(conf.IP_PEER, int(port)):
        logging.error('Peer Service Port is Using '+str(port))
        return

    ObjectManager().peer_service = PeerService(None, radio_station_ip, radio_station_port, cert, pw)
    logging.info("loopchain peer_service is: " + str(ObjectManager().peer_service))
    ObjectManager().peer_service.serve(port, score)
Exemple #3
0
def main(argv):
    logging.info("loadtest tool got argv(list): " + str(argv))

    try:
        opts, args = getopt.getopt(argv, "c:p:m:w:t:hd",
                                   ["client=",
                                    "peer=",
                                    "mins=",
                                    "help",
                                    "debug"
                                    ])
    except getopt.GetoptError as e:
        logging.error(e)
        usage()
        sys.exit(1)

    # default option values
    client = 1
    peer = "127.0.0.1:7100"
    duration = 10  # seconds, but param is mins
    test_way = 0

    # apply option values
    for opt, arg in opts:
        if (opt == "-c") or (opt == "--client"):
            client = int(arg)
        elif (opt == "-p") or (opt == "--peer"):
            peer = arg
        elif (opt == "-m") or (opt == "--mins"):
            duration = int(arg) * 60  # seconds, but param is mins
        elif opt == "-d":
            util.set_log_level_debug()
        elif opt == "-t":
            test_way = int(arg)
        elif (opt == "-h") or (opt == "--help"):
            usage()
            return

    method_name = ["CreateTx", "Query"][test_way]

    # run peer service with parameters
    logging.info("\nTry load test with: \nclient( " +
                 str(client) + " ) \npeer( " +
                 peer + " ) \nduration( " +
                 str(duration) + " seconds )\n")

    pool = Pool(processes=client)
    pool.map_async(client_process, (client*((peer, duration, method_name),)), callback=log_result)

    logging.debug("wait for duration")
    pool.close()
    pool.join()
def main(argv):
    util.logger.spam("RESTful proxy main got argv(list): " + str(argv))

    try:
        opts, args = getopt.getopt(argv, "dhp:", [
            "help",
            "port=",
        ])
    except getopt.GetoptError as e:
        logging.error(e)
        usage()
        sys.exit(1)

    # Port and host values.
    port = conf.PORT_PEER
    host = '0.0.0.0'

    # Parse command line arguments.
    for opt, arg in opts:
        if opt == "-p":
            port = int(arg)
        elif opt == "-d":
            util.set_log_level_debug()
        elif opt == "-h":
            usage()
            return

    # Connect gRPC stub.
    ServerComponents().set_stub_port(port, conf.IP_LOCAL)
    ServerComponents().set_argument()
    ServerComponents().set_resource()

    api_port = port + conf.PORT_DIFF_REST_SERVICE_CONTAINER
    logging.debug("Run gunicorn webserver for HA. Port = %s", str(api_port))

    certfile = ""
    keyfile = ""

    if ServerComponents().ssl_context is not None:
        certfile = ServerComponents().ssl_context(0)
        keyfile = ServerComponents().ssl_context(1)

    options = {
        'bind': '%s:%s' % (host, api_port),
        'workers': number_of_workers(),
        'certfile': certfile,
        'keyfile': keyfile
    }

    StandaloneApplication(ServerComponents().app, options).run()
Exemple #5
0
def main(argv):
    logging.info("RadioStation main got argv(list): " + str(argv))

    try:
        opts, args = getopt.getopt(
            argv, "dhp:o:s:",
            ["help", "port=", "cert=", "configure_file_path=", "seed="])
    except getopt.GetoptError as e:
        logging.error(e)
        usage()
        sys.exit(1)

    # apply json configure values
    for opt, arg in opts:
        if (opt == "-o") or (opt == "--configure_file_path"):
            conf.Configure().load_configure_json(arg)

    # apply default configure values
    port = conf.PORT_RADIOSTATION
    cert = None
    pw = None
    seed = None

    # apply option values
    for opt, arg in opts:
        if opt == "-d":
            util.set_log_level_debug()
        elif (opt == "-p") or (opt == "--port"):
            port = arg
        elif opt == "--cert":
            cert = arg
        elif (opt == "-s") or (opt == "--seed"):
            try:
                seed = int(arg)
            except ValueError as e:
                util.exit_and_msg(f"seed or s opt must be int \n"
                                  f"intput value : {arg}")
        elif (opt == "-h") or (opt == "--help"):
            usage()
            return

    # Check Port is Using
    if util.check_port_using(conf.IP_RADIOSTATION, int(port)):
        logging.error('RadioStation Service Port is Using ' + str(port))
        return

    RadioStationService(conf.IP_RADIOSTATION, cert, pw, seed).serve(port)
# 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.
"""Test Score Helper"""

import unittest
from unittest.mock import patch
import json
import loopchain.utils as util
import os.path as osp
import shutil
import loopchain.configure as conf
from loopchain.baseservice import ObjectManager
from loopchain.tools.score_helper import ScoreHelper, ScoreDatabaseType

util.set_log_level_debug()


class TestScoreHelper(unittest.TestCase):
    conf = None
    __repository_path = osp.join(osp.dirname(__file__), 'db_')
    @classmethod
    def setUpClass(cls):
        conf.DEFAULT_SCORE_REPOSITORY_PATH = cls.__repository_path
        # Deploy path 에 clone 한다
        if osp.exists(cls.__repository_path):
            shutil.rmtree(cls.__repository_path, True)

    @classmethod
    def tearDownClass(cls):
        #shutil.rmtree(cls.__repository_path, True)
Exemple #7
0
def main(argv):
    # logging.debug("Peer main got argv(list): " + str(argv))

    try:
        opts, args = getopt.getopt(argv, "dhr:p:c:o:a:", [
            "help", "radio_station_target=", "port=", "score=", "public=",
            "private=", "password="******"configure_file_path="
        ])
    except getopt.GetoptError as e:
        logging.error(e)
        usage()
        sys.exit(1)

    # apply json configure values
    for opt, arg in opts:
        if (opt == "-o") or (opt == "--configure_file_path"):
            conf.Configure().load_configure_json(arg)

    # apply default configure values
    port = conf.PORT_PEER
    radio_station_ip = conf.IP_RADIOSTATION
    radio_station_port = conf.PORT_RADIOSTATION
    radio_station_ip_sub = conf.IP_RADIOSTATION
    radio_station_port_sub = conf.PORT_RADIOSTATION
    score = conf.DEFAULT_SCORE_PACKAGE
    public = conf.PUBLIC_PATH
    private = conf.PRIVATE_PATH
    pw = conf.DEFAULT_PW

    # Parse command line arguments.
    for opt, arg in opts:
        if (opt == "-r") or (opt == "--radio_station_target"):
            try:
                if ':' in arg:
                    target_list = util.parse_target_list(arg)
                    if len(target_list) == 2:
                        radio_station_ip, radio_station_port = target_list[0]
                        radio_station_ip_sub, radio_station_port_sub = target_list[
                            1]
                    else:
                        radio_station_ip, radio_station_port = target_list[0]
                    # util.logger.spam(f"peer "
                    #                  f"radio_station_ip({radio_station_ip}) "
                    #                  f"radio_station_port({radio_station_port}) "
                    #                  f"radio_station_ip_sub({radio_station_ip_sub}) "
                    #                  f"radio_station_port_sub({radio_station_port_sub})")
                elif len(arg.split('.')) == 4:
                    radio_station_ip = arg
                else:
                    raise Exception("Invalid IP format")
            except Exception as e:
                util.exit_and_msg(
                    f"'-r' or '--radio_station_target' option requires "
                    f"[IP Address of Radio Station]:[PORT number of Radio Station], "
                    f"or just [IP Address of Radio Station] format. error({e})"
                )
        elif (opt == "-p") or (opt == "--port"):
            port = arg
        elif (opt == "-c") or (opt == "--score"):
            score = arg
        elif (opt == "-a") or (opt == "--password"):
            pw = arg
        elif opt == "--public":
            public = arg
        elif opt == "--private":
            private = arg
        elif opt == "-d":
            util.set_log_level_debug()
        elif (opt == "-h") or (opt == "--help"):
            usage()
            return

    # run peer service with parameters
    logging.info(f"loopchain peer run with: port({port}) "
                 f"radio station({radio_station_ip}:{radio_station_port}) "
                 f"score({score})")

    # check Port Using
    if util.check_port_using(conf.IP_PEER, int(port)):
        util.exit_and_msg('Peer Service Port is Using ' + str(port))

    # str password to bytes
    if isinstance(pw, str):
        pw = pw.encode()

    ObjectManager().peer_service = PeerService(
        radio_station_ip=radio_station_ip,
        radio_station_port=radio_station_port,
        public_path=public,
        private_path=private,
        cert_pass=pw)

    # logging.debug("loopchain peer_service is: " + str(ObjectManager().peer_service))
    ObjectManager().peer_service.serve(port, score)