コード例 #1
0
 def getApolloData(self, key):
     '''
     :param key: 传入key
     :return: 返回apollo上对应的key键的value值
     '''
     client = ApolloClient(app_id=self.appid, config_server_url=self.url)
     client.start()
     return client.get_value(key, namespace=self.ns)
コード例 #2
0
 def apollo_client(self,
                   app_id='yuanjie',
                   cluster='yuanjie',
                   config_server_url="http://106.54.227.205:8080"):
     """
         client.get_value('yuanjie')
     :param app_id:
     :param cluster:
     :param config_server_url:
     :return:
     """
     client = ApolloClient(app_id, cluster, config_server_url)
     client.start()
     return client
コード例 #3
0
def apollo_client():
    client = ApolloClient(app_id=APP_ID, config_server_url=URL, cycle_time=CYCLE_TIME, timeout=300)
    client.start()
    notification_num = 10000000000000

    while True:
        num = client._notification_map['application']
        if notification_num != num:
            notification_num = num
            res = client.get_value('hahaha')
            print('-------res', res)
            k8s = K8s()
            k8s.update_configmap({'hahaha': res})

        time.sleep(CYCLE_TIME)
コード例 #4
0
def apo_client(section, file_name):
    """
            获取apollo连接
            :return: ApolloClient
    """
    apollo_host = ini_conf(section=section,
                           option='host',
                           default='127.0.0.1',
                           file_name=file_name)
    apollo_port = ini_conf(section=section,
                           option='port',
                           default=8080,
                           file_name=file_name)
    apollo_cluster = ini_conf(section=section,
                              option='cluster',
                              default='default',
                              file_name=file_name)
    apollo_app_id = ini_conf(section=section,
                             option="app_id",
                             default="",
                             file_name=file_name)

    print("Debug apollo configure: {} {} {} {}".format(apollo_host,
                                                       apollo_port,
                                                       apollo_cluster,
                                                       apollo_app_id))

    ap_client = ApolloClient(app_id=apollo_app_id,
                             config_server_url='http://' + apollo_host + ':' +
                             str(apollo_port),
                             cluster=apollo_cluster,
                             timeout=300)

    ap_client.start()

    return ap_client
コード例 #5
0
def apo_client():
    """
            获取apollo客户端连接
            return: ApolloClient
    """

    print("debug apollo configures {} {} {} {} {}".format(
        apollo_host, apollo_port, apollo_cluster, apollo_namespace,
        apollo_app_id))

    ap_client = ApolloClient(apollo_app_id,
                             config_server_url='http://' + apollo_host + ':' +
                             apollo_port,
                             cluster=apollo_cluster,
                             timeout=300)

    return ap_client
コード例 #6
0
def getApolloData(key):
    '''
    :param key: 传入key
    :return: 返回apollo上对应的key键的value值
    '''
    props = properties.Properties(r"./env.properties")
    url = props.get('appurl')
    appid = props.get('appid')
    ns = props.get('ns')
    client = ApolloClient(app_id=appid, config_server_url=url)
    client.start()
    print(client.get_value(key, namespace=ns))
    return client.get_value(key, namespace=ns)
コード例 #7
0
import time

import threading

from pyapollo import ApolloClient

client = ApolloClient('Mengniu-Rec-test')


def client_loop(loop_interval=3):
    while True:
        client.start()
        time.sleep(loop_interval)


threading.Thread(target=client_loop, args=(3, )).start()


def recommend():
    v = client.get_value("source_id_weight")
    return v
コード例 #8
0
ファイル: config.py プロジェクト: antmoveh/grow
from pyapollo import ApolloClient

logging.basicConfig(level=logging.INFO,
                    filename="new.log",
                    filemode="a",
                    format='%(levelname)s %(message)s',
                    datefmt='%a, %d %b %Y %H:%M:%S')
logger = logging.getLogger()

node_ip = os.getenv("NODE_NAME", "default")
pod_name = os.getenv("POD_NAME", "default")
pod_namespace = os.getenv("POD_NAMESPACE", "default")
pod_ip = os.getenv("POD_IP", "default")

app_id = os.getenv("APP_ID", "SampleApp")
cluster = os.getenv("CLUSTER", "default")
config_server_url = os.getenv("CONFIG_SERVER_URL", "")
svc_name = os.getenv("SVC_NAME")
namespace = os.getenv("NAMESPACE", "default")

client = None

if config_server_url != "":
    client = ApolloClient(app_id=app_id,
                          cluster=cluster,
                          config_server_url=config_server_url,
                          timeout=65,
                          ip=svc_name)
    #client.start()
    t = threading.Thread(target=client.start, kwargs={"catch_signals": False})
    t.start()
コード例 #9
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from pyapollo import ApolloClient

client = ApolloClient(app_id="SampleApp", timeout=65)
client.start(use_eventlet=True)

timeout = client.get_value('timeout', namespace="demo")

print("Timeout value is:%s" % timeout)

# client.stop()
コード例 #10
0
ファイル: first.py プロジェクト: wild46cat/apollo-client-demo
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from pyapollo import ApolloClient
from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello_world():
    x = client.get_value("timeout", 10, "application")
    return x


client = ApolloClient(app_id="test01",
                      cluster="cluster1",
                      config_server_url="http://10.14.41.63:8080",
                      cache_file_path="./")

if __name__ == '__main__':
    client.start()
    app.run(port=44556)
コード例 #11
0
ファイル: apollo-client.py プロジェクト: atomkang/devops
"""
Author: Atom
Create time: 2020-08-27 10:21
IDE: PyCharm
"""

import time
import os
from pyapollo import ApolloClient

while True:
    client = ApolloClient(app_id='pm',config_server_url='http://192.168.102.202:8080')
    client.start(5)
    content=(client.get_value('pm'))

    fo = open("/work/code/.env","w")
    fo.write(content)
    fo.close()
    time.sleep(60)