Exemplo n.º 1
0
    def do_GET(self):
        # Sending an '200 OK' response
        self.send_response(200)

        # Setting the header
        self.send_header("Content-type", "text/html")

        # Whenever using 'send_header', you also have to call 'end_headers'
        self.end_headers()

        # Extract query param
        key = 'timeout'
        namespace = 'application'
        query_components = parse_qs(urlparse(self.path).query)
        if 'key' in query_components:
            key = query_components["key"][0]
        if 'namespace' in query_components:
            namespace = query_components["namespace"][0]

        try:
            config = ApolloClient(app_id=app_id, cluster=cluster, config_server_url=config_server_url)
            value = config.get_value(key, f"not found!", namespace)
        except Exception as e:
            print("get_value:", e)
            value = e

        # Some custom HTML code, possibly generated by another function
        html = f"<html><head></head><body><h1>Apollo Demo</h1><p><span><a href='./?namespace=&key='>change key ?namespace=&key= " \
               f"</a></span></p> <p>[{namespace}] {key}: {value}</p></body></html>".format(namespace=namespace, key=key, value=value)
Exemplo n.º 2
0
class ApolloMgr:
    def __init__(self, app_id='APP_ID', server_url=None, namespaces=[]):
        self.client = ApolloClient(app_id=app_id,
                                   cluster='default',
                                   server_url=server_url)
        self.namespace_names = namespaces
        self.apollo_loop_start()

    def get(self, key=None, default=None):
        for name in self.namespace_names:
            v = self.client.get_value(key, default, namespace=name)
            if v is None:
                continue
            break
        return v

    def apollo_loop_start(self):
        self.client.start(use_process=True)

    def ucm_loop_stop(self):
        self.client.stop()
Exemplo n.º 3
0
 def __init__(self, app_id='APP_ID', server_url=None, namespaces=[]):
     self.client = ApolloClient(app_id=app_id,
                                cluster='default',
                                server_url=server_url)
     self.namespace_names = namespaces
     self.apollo_loop_start()
Exemplo n.º 4
0
# -*- coding: utf-8 -*-
# @Time:2020.09.12
# @author:xhrg
# @email:[email protected]
import os
import time

from apollo.apollo_client import ApolloClient

apollo_config_url = os.environ.get("APOLLO_CONFIG_URL")

print(apollo_config_url)


# ('update', u'application', u'name', u'12311')
# ('update', u'application', u'name', u'12311111111111111111')
# ('delete', u'application', u'aaa', u'vvv111111')
# ('add', u'application', u'cc', u'dd')
def listener(change_type, namespace, key, value):
    print(change_type, namespace, key, value)


client = ApolloClient(app_id="demo-service",
                      cluster="default",
                      config_url=apollo_config_url,
                      change_listener=listener)
val = client.get_value("name", default_val="defaultVal")

print(val)
time.sleep(100)
Exemplo n.º 5
0
from apollo.apollo_client import ApolloClient

apollo_client = ApolloClient(app_id="ise.expression.server",
                             cluster="default",
                             config_url="http://198.23.239.211:8180")
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time:2020.09.12
# @author:xhrg
# @email:[email protected]
import os
import time

from apollo.apollo_client import ApolloClient

apollo_config_url = os.environ.get("APOLLO_CONFIG_URL")

print(apollo_config_url)

client = ApolloClient(app_id="demo-service",
                      cluster="default",
                      config_url=apollo_config_url,
                      secret="cdbb0b1b67d94a63a20f9002c092e6cf")
val = client.get_value("name", default_val="defaultVal")

print(val)