def get_config():  # noqa: E501
    """Get config.

     # noqa: E501


    :rtype: object
    """
    data = rms_config()["ui"]
    return ApiStatus(code=0, msg='success', data=data)
示例#2
0
def main():
    config_name = os.getenv('FLASK_CONFIG', 'development')
    app = connexion.App(__name__,
                        specification_dir='rms/swagger_server/swagger',
                        skip_error_handlers=True)
    app.app.json_encoder = encoder.JSONEncoder
    app.app.config.from_object(settings.app_config[config_name])
    app_config = app.app.config
    app.app.register_blueprint(metrics_blueprint)
    # set errors
    ErrorHanlder.set_errors_handlers(app)

    # init connection pool
    max_size = app_config['CONN_POOL_MAX_SIZE']
    max_usage = app_config['CONN_POOL_MAX_USAGE']
    idle = app_config['CONN_POOL_IDLE']
    ttl = app_config['CONN_POOL_TTL']
    username = app_config['MYSQL_USERNAME']
    database = app_config['MYSQL_DATABASE']
    pw = app_config['MYSQL_PW']
    mysql_host = app_config['MYSQL_HOST']
    resource_name = app_config['RESOURCE']
    StorageConnPoolSingleton(username=username,
                             database=database,
                             pw=pw,
                             host=mysql_host,
                             max_size=max_size,
                             max_usage=max_usage,
                             idle=idle,
                             ttl=ttl)
    ResourceConnPoolSingleton(resource_name=resource_name,
                              max_size=max_size,
                              max_usage=max_usage,
                              idle=idle,
                              ttl=ttl)
    K8sConnPoolSingleton(max_size=max_size,
                         max_usage=max_usage,
                         idle=idle,
                         ttl=ttl)
    # set route
    app.add_api('swagger.yaml', arguments={'title': 'resource manager API'})
    # start slo
    second = rms_config()["frequency_second"]
    timer = threading.Timer(second, health)
    timer.start()
    # run app
    app.run(host=app_config['HOST'],
            port=app_config['PORT'],
            debug=app_config['DEBUG'])
示例#3
0
 def get_pvc(storage_type,
             namespace,
             module,
             ou_id,
             resource_api: Resource = None):
     data = []
     if storage_type == 'notebook' and resource_api.check_key_tab(
             namespace=namespace, ou_id=ou_id) is True:
         key_tab_pvc = rms_config()["keytab"]
         for pvc in key_tab_pvc:
             detail = PvcDetail(pvc_name=pvc,
                                namespace=namespace,
                                create_date=int(time.time()) * 1000)
             data.append(detail)
     elif namespace is not None:
         rows = StorageClient.query(namespace=namespace,
                                    module=module,
                                    ou_id=ou_id)
         for row in rows:
             if resource_api.check_pvc(row['namespace'], row['name']):
                 data.append(PvcService.transform_pvc(row))
     return data
示例#4
0
import threading

from flask import Flask
from prometheus_client import Summary, Counter

from rms.utils import flask_app_config, rms_config

ouId = os.getenv("OU_ID", "ouId")
app = Flask(os.getenv('FLASK_CONFIG', 'development'))
s = Summary(name='eap_storage_resource_manager_summary',
            documentation='summary',
            labelnames=['ouId', "label"])
c = Counter(name='eap_storage_resource_manager_counter',
            documentation='counter',
            labelnames=['ouId', "label"])
second = rms_config()["frequency_second"]


def health():
    try:
        s.labels(ouId, 'health').observe(1)
    except Exception as e:
        s.labels(ouId, 'health').observe(0)
    finally:
        c.labels(ouId, 'health').inc(1)
    timer = threading.Timer(second, health)
    timer.start()


def metrics_summary(label, count):
    s.labels(ouId, label).observe(count)
示例#5
0
 def namespace_list(self, ou_id):
     data = rms_config()["namespace"]
     return data