Exemplo n.º 1
0
def test_registration():
    name = "name"
    managementUrl = "managementUrl"
    healthUrl = "healthUrl"
    serviceUrl = "serviceUrl"
    source = "source"
    metadata = "metadata"

    registration = Registration(
        name=name,
        managementUrl=managementUrl,
        source=source,
        serviceUrl=serviceUrl,
        healthUrl=healthUrl,
        metadata=metadata
    )

    assert registration.name == name
    assert registration.managementUrl == managementUrl
    assert registration.healthUrl == healthUrl
    assert registration.serviceUrl == serviceUrl
    assert registration.source == source
    assert registration.metadata == metadata
Exemplo n.º 2
0
SERVICE_NAME_COMPONENT = '{0}-{1}-{2}'.format(
    os.environ['SERVICE_NAME_COMPONENT'], os.environ['QA_SYSTEM_NAME'],
    SERVICE_PORT)
SERVICE_DESCRIPTION_COMPONENT = os.environ['SERVICE_DESCRIPTION_COMPONENT']
URL_COMPONENT = f"http://{SERVICE_HOST}:{SERVICE_PORT}"

# define metadata that will be shown in the Spring Boot Admin server UI
metadata = {
    "start": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
    "description": SERVICE_DESCRIPTION_COMPONENT,
    "about": f"{SERVICE_HOST}:{SERVICE_PORT}{aboutendpoint}",
    "written in": "Python"
}

# initialize the registration object, to be send to the Spring Boot Admin server
registration = Registration(
    name=SERVICE_NAME_COMPONENT,
    serviceUrl=f"{SERVICE_HOST}:{SERVICE_PORT}",
    healthUrl=f"{SERVICE_HOST}:{SERVICE_PORT}{healthendpoint}",
    metadata=metadata)

# start a thread that will contact iteratively the Spring Boot Admin server
registrator_thread = Registrator(SPRING_BOOT_ADMIN_URL,
                                 SPRING_BOOT_ADMIN_USERNAME,
                                 SPRING_BOOT_ADMIN_PASSWORD, registration)
registrator_thread.setDaemon(True)
registrator_thread.start()

if __name__ == "__main__":
    # start the web service
    app.run(debug=True, port=SERVICE_PORT)
Exemplo n.º 3
0
    # define metadata that will be shown in the Spring Boot Admin server UI
    metadata = {
        "start":
        datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        "description":
        configuration.servicedescription,
        "about":
        "%s:%d%s" %
        (configuration.servicehost, configuration.serviceport, aboutendpoint),
        "written in":
        "Python"
    }

    # initialize the registation object, to be send to the Spring Boot Admin server
    myRegistration = Registration(
        name=configuration.servicename,
        serviceUrl="%s:%d" %
        (configuration.servicehost, 80),  # configuration.serviceport
        healthUrl="%s:%d%s" % (configuration.servicehost, 80,
                               healthendpoint),  # configuration.serviceport
        metadata=metadata)

    # start a thread that will contact iteratively the Spring Boot Admin server
    registratorThread = Registrator(
        configuration.springbootadminserverurl,
        configuration.springbootadminserveruser,
        configuration.springbootadminserverpassword, myRegistration)
    registratorThread.start()

    # start the web service
    app.run(debug=True, port=configuration.serviceport)
Exemplo n.º 4
0
from qanary_helpers.registrator import Registrator
from qanary_helpers.registration import Registration

name = "name"
managementUrl = "managementUrl"
healthUrl = "healthUrl"
serviceUrl = "serviceUrl"
source = "source"
metadata = "metadata"

registration = Registration(name=name,
                            managementUrl=managementUrl,
                            source=source,
                            serviceUrl=serviceUrl,
                            healthUrl=healthUrl,
                            metadata=metadata)

registrator_thread = Registrator(admin_server_url="",
                                 admin_server_user="",
                                 admin_server_password="",
                                 registration=registration)


def test_json_headers():
    json_headers = {
        "Content-type": "application/json",
        "Accept": "application/json"
    }

    assert registrator_thread.json_headers == json_headers
Exemplo n.º 5
0
    def __init__(self, configfile, aboutendpoint, healthendpoint, blueprint):
        base = Blueprint('base', __name__, template_folder='templates')

        @base.route(healthendpoint, methods=['GET'])
        def health():
            """required health endpoint for callback of Spring Boot Admin server"""
            return "alive"

        self.app = Flask(__name__)
        self.app.register_blueprint(blueprint)
        self.app.register_blueprint(base)

        logging.basicConfig(format='%(asctime)s - %(message)s',
                            level=logging.INFO)

        # allow configuration of the configfile via command line parameters
        argparser = argparse.ArgumentParser(
            description=
            'You might provide a configuration file, otherwise "%s" is used.' %
            (configfile))
        argparser.add_argument('-c',
                               '--configfile',
                               action='store',
                               dest='configfile',
                               default=configfile,
                               help='overwrite the default configfile "%s"' %
                               (configfile))
        configfile = argparser.parse_args().configfile
        configuration = Configuration(configfile, [
            'springbootadminserverurl', 'springbootadminserveruser',
            'springbootadminserverpassword', 'servicehost', 'serviceport',
            'servicename', 'servicedescription', 'serviceversion'
        ])

        try:
            configuration.serviceport = int(
                configuration.serviceport
            )  # ensure an int value for the server port
        except Exception as e:
            logging.error(
                "in configfile '%s': serviceport '%s' is not valid (%s)" %
                (configfile, configuration.serviceport, e))

        # define metadata that will be shown in the Spring Boot Admin server UI
        metadata = {
            "start":
            datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
            "description":
            configuration.servicedescription,
            "about":
            "%s:%d%s" % (configuration.servicehost, configuration.serviceport,
                         aboutendpoint),
            "written in":
            "Python"
        }

        # initialize the registation object, to be send to the Spring Boot Admin server
        myRegistration = Registration(
            name=configuration.servicename,
            serviceUrl="%s:%d" %
            (configuration.servicehost, configuration.serviceport),  # 
            healthUrl="%s:%d%s" %
            (configuration.servicehost, configuration.serviceport,
             healthendpoint),  # 
            metadata=metadata)

        # start a thread that will contact iteratively the Spring Boot Admin server
        registratorThread = Registrator(
            configuration.springbootadminserverurl,
            configuration.springbootadminserveruser,
            configuration.springbootadminserverpassword, myRegistration)
        registratorThread.start()

        # start the web service
        self.app.run(host='0.0.0.0',
                     debug=True,
                     threaded=True,
                     port=configuration.serviceport)