From: tierno Date: Wed, 25 Nov 2020 13:25:08 +0000 (+0000) Subject: change charm installation for the New generation RO X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=edc193bd8ab14e14f772faa43537e8cc2ffc7db5;p=osm%2Fdevops.git change charm installation for the New generation RO Change-Id: I4d22a6e87061858ff99b44b81c3667a88e007d4e Signed-off-by: tierno --- diff --git a/installers/charm/ro-k8s/reactive/ro.py b/installers/charm/ro-k8s/reactive/ro.py index 8ad6f98c..8ea80705 100644 --- a/installers/charm/ro-k8s/reactive/ro.py +++ b/installers/charm/ro-k8s/reactive/ro.py @@ -31,40 +31,58 @@ def upgrade(): def restart(): clear_flag("ro-k8s.configured") +@when_not("kafka.ready") +@when_not("ro-k8s.configured") +@when("leadership.is_leader") +def waiting_for_kafka(): + layer.status.waiting("Waiting for kafka to be ready") -@when_not("mysql.available") + +@when_not("mongo.ready") @when_not("ro-k8s.configured") @when("leadership.is_leader") -def waiting_for_mysql(): - layer.status.waiting("Waiting for mysql to be ready") +def waiting_for_mongo(): + layer.status.waiting("Waiting for mongo to be ready") -@when("mysql.available") +@when("kafka.ready", "mongo.ready") @when_not("ro-k8s.configured") @when("leadership.is_leader") def configure(): layer.status.maintenance("Configuring ro container") try: - mysql = endpoint_from_flag("mysql.available") - - if mysql.host() is not None: - spec = make_pod_spec( - mysql.host(), - mysql.port(), - mysql.user(), - mysql.password(), - mysql.root_password(), - ) - - log("set pod spec:\n{}".format(spec)) - pod_spec_set(spec) - layer.status.active("creating container") - set_flag("ro-k8s.configured") + kafka = endpoint_from_flag("kafka.ready") + mongo = endpoint_from_flag("mongo.ready") + + if kafka and mongo: + kafka_units = kafka.kafkas() + kafka_unit = kafka_units[0] + + mongo_uri = mongo.connection_string() + log("Mongo URI: {}".format(mongo_uri)) + + if ( + mongo_uri + and kafka_unit["host"] + and kafka_unit["port"] + and ro_unit["host"] + and ro_unit["port"] + ): + spec = make_pod_spec( + kafka_unit["host"], + kafka_unit["port"], + mongo_uri, + ) + + log("set pod spec:\n{}".format(spec)) + pod_spec_set(spec) + layer.status.active("creating container") + set_flag("ro-k8s.configured") except Exception as e: layer.status.blocked("k8s spec failed to deploy: {}".format(e)) -@when("mysql.available") +@when("kafka.ready", "mongo.ready") @when_not("leadership.is_leader") def non_leaders_active(): layer.status.active("ready") @@ -91,17 +109,13 @@ def send_config(): log("Fail sending RO configuration: {}".format(e)) -def make_pod_spec( - mysql_host, mysql_port, mysql_user, mysql_password, mysql_root_password -): +def make_pod_spec(kafka_host, kafka_port, mongo_uri): """Make pod specification for Kubernetes Args: - mysql_name (str): RO DB name - mysql_host (str): RO DB host - mysql_port (int): RO DB port - mysql_user (str): RO DB user - mysql_password (str): RO DB password + kafka_host (str): Kafka hostname or IP + kafka_port (int): Kafka port + mongo_uri (str): Mongo URI Returns: pod_spec: Pod specification for Kubernetes """ @@ -109,17 +123,14 @@ def make_pod_spec( with open("reactive/spec_template.yaml") as spec_file: pod_spec_template = spec_file.read() - md = metadata() cfg = config() + md = metadata() data = { "name": md.get("name"), - "docker_image": cfg.get("image"), - "mysql_host": mysql_host, - "mysql_port": mysql_port, - "mysql_user": mysql_user, - "mysql_password": mysql_password, - "mysql_root_password": mysql_root_password, + "kafka_host": kafka_host, + "kafka_port": kafka_port, + "mongo_uri": mongo_uri, } data.update(cfg) diff --git a/installers/charm/ro-k8s/reactive/spec_template.yaml b/installers/charm/ro-k8s/reactive/spec_template.yaml index f4f7c9c3..985ccf23 100644 --- a/installers/charm/ro-k8s/reactive/spec_template.yaml +++ b/installers/charm/ro-k8s/reactive/spec_template.yaml @@ -39,17 +39,13 @@ containers: protocol: TCP config: ALLOW_ANONYMOUS_LOGIN: 'yes' - RO_DB_HOST: %(mysql_host)s - RO_DB_PORT: %(mysql_port)s - RO_DB_NAME: %(ro_database)s - RO_DB_USER: %(mysql_user)s - RO_DB_ROOT_PASSWORD: %(mysql_root_password)s - RO_DB_PASSWORD: %(mysql_password)s + + OSMRO_MESSAGE_DRIVER: kafka + OSMRO_MESSAGE_HOST: %(kafka_host)s + OSMRO_MESSAGE_PORT: %(kafka_port)s + + OSMRO_DATABASE_DRIVER: mongo + OSMRO_DATABASE_URI: %(mongo_uri)s + OSMRO_DATABASE_COMMONKEY: %(DATABASE_COMMONKEY)s + - RO_DB_OVIM_PASSWORD: %(mysql_password)s - RO_DB_OVIM_HOST: %(mysql_host)s - RO_DB_OVIM_PORT: %(mysql_port)s - RO_DB_OVIM_USER: %(mysql_user)s - RO_DB_OVIM_ROOT_PASSWORD: %(mysql_root_password)s - RO_DB_OVIM_NAME: %(vim_database)s - OPENMANO_TENANT: %(OPENMANO_TENANT)s