diff --git a/docker-compose.yml b/docker-compose.yml index 1f815304..e56a80b7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,8 +44,10 @@ services: hostname: cello-operator-dashboard restart: unless-stopped environment: - - MONGO_URL=mongodb://cello-mongo:27017 + - MONGO_URL=mongodb://cello-mongo:27017 # used by pymongo, deprecate soon + - MONGO_HOST=mongo - MONGO_DB=dev + - MONGODB_PORT=27017 - DEBUG=True # in debug mode, service will auto-restart - LOG_LEVEL=DEBUG # what level log will be output - STATIC_FOLDER=$STATIC_FOLDER @@ -53,6 +55,8 @@ services: - ENABLE_EMAIL_ACTIVE=$ENABLE_EMAIL_ACTIVE ports: - "8080:8080" + #volumes: + # - ./src:/app #TODO: need to follow other images to put at dockerhub user-dashboard: @@ -90,12 +94,16 @@ services: hostname: cello-engine restart: unless-stopped environment: - - MONGO_URL=mongodb://cello-mongo:27017 + - MONGO_URL=mongodb://cello-mongo:27017 # used by pymongo, deprecate soon + - MONGO_HOST=mongo - MONGO_DB=dev + - MONGODB_PORT=27017 - DEBUG=True # in debug mode, service will auto-restart - LOG_LEVEL=DEBUG # what level log will be output ports: - "80:80" + #volumes: + # - ./src:/app # cello watchdog service watchdog: @@ -104,10 +112,14 @@ services: hostname: cello-watchdog restart: unless-stopped environment: - - MONGO_URL=mongodb://cello-mongo:27017 + - MONGO_URL=mongodb://mongo:27017 # used by pymongo, deprecate soon + - MONGO_HOST=mongo - MONGO_DB=dev + - MONGODB_PORT=27017 - DEBUG=True # in debug mode, service will auto-restart - LOG_LEVEL=DEBUG # what level log will be output + #volumes: + # - ./src:/app # mongo database, may use others in future mongo: @@ -135,6 +147,8 @@ services: # TODO: we may use one mongo instance, that should be enough dashboard_mongo: image: hyperledger/cello-mongo + hostname: cello-dashboard_mongo + container_name: cello-dashboard_mongo restart: unless-stopped environment: - NO_USED=0 diff --git a/src/agent/docker/host.py b/src/agent/docker/host.py index 7cfb3194..779a680b 100644 --- a/src/agent/docker/host.py +++ b/src/agent/docker/host.py @@ -11,7 +11,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) from common import \ - db, log_handler, \ + log_handler, \ LOG_LEVEL from ..host_base import HostBase @@ -38,7 +38,6 @@ class DockerHost(HostBase): """ Main handler to operate the Docker hosts """ def __init__(self, host_type): - self.col = db["host"] self.host_type = host_type def is_active(self, *args): diff --git a/src/common/__init__.py b/src/common/__init__.py index 067d690b..b7f380c1 100644 --- a/src/common/__init__.py +++ b/src/common/__init__.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 # -from .db import db, col_host +from .db import db from .response import make_ok_resp, make_fail_resp, CODE_NOT_FOUND, \ CODE_BAD_REQUEST, CODE_CONFLICT, CODE_CREATED, CODE_FORBIDDEN, \ CODE_METHOD_NOT_ALLOWED, CODE_NO_CONTENT, CODE_NOT_ACCEPTABLE, CODE_OK diff --git a/src/common/db.py b/src/common/db.py index 58bf9487..4d891e31 100644 --- a/src/common/db.py +++ b/src/common/db.py @@ -12,7 +12,3 @@ mongo_client = MongoClient(MONGO_URL) db = mongo_client[MONGO_DB] - -col_host = db["host"] -# col_cluster_active = db["cluster_active"] -# col_cluster_released = db["cluster_released"] diff --git a/src/common/fabric_network.py b/src/common/fabric_network.py index 30659cc1..b762b970 100644 --- a/src/common/fabric_network.py +++ b/src/common/fabric_network.py @@ -8,7 +8,7 @@ from common.blockchain_network import BlockchainNetwork from common.fabric_network_config import \ FabricPreNetworkConfig, FabricV1NetworkConfig -from common import db, log_handler, LOG_LEVEL +from common import log_handler, LOG_LEVEL logger = logging.getLogger(__name__) logger.setLevel(LOG_LEVEL) diff --git a/src/config.py b/src/config.py index 0d69318a..664c7f54 100644 --- a/src/config.py +++ b/src/config.py @@ -18,8 +18,8 @@ class ProductionConfig(Config): class DevelopmentConfig(Config): DEBUG = True - MONGODB_DB = os.getenv('MONGODB_DB', 'dashboard') MONGODB_HOST = os.getenv('MONGODB_HOST', 'mongo') + MONGODB_DB = os.getenv('MONGODB_DB', 'dev') MONGODB_PORT = int(os.getenv('MONGODB_PORT', 27017)) MONGODB_USERNAME = os.getenv('MONGODB_USERNAME', '') MONGODB_PASSWORD = os.getenv('MONGODB_PASSWORD', '') diff --git a/src/modules/cluster.py b/src/modules/cluster.py index 592d1a55..ae2aaba0 100644 --- a/src/modules/cluster.py +++ b/src/modules/cluster.py @@ -26,13 +26,12 @@ WORKER_TYPES, WORKER_TYPE_DOCKER, WORKER_TYPE_SWARM, WORKER_TYPE_K8S, \ WORKER_TYPE_VSPHERE, VMIP, \ NETWORK_SIZE_FABRIC_PRE_V1, \ - PEER_SERVICE_PORTS, CA_SERVICE_PORTS, EXPLORER_PORT, \ + PEER_SERVICE_PORTS, EXPLORER_PORT, \ ORDERER_SERVICE_PORTS, \ NETWORK_STATUS_CREATING, NETWORK_STATUS_RUNNING, NETWORK_STATUS_DELETING from common import FabricPreNetworkConfig, FabricV1NetworkConfig -from common.fabric_network import FabricV1Network from modules import host @@ -40,7 +39,7 @@ from modules.models import Cluster as ClusterModel from modules.models import Host as HostModel from modules.models import ClusterSchema, CLUSTER_STATE, \ - CLUSTER_STATUS, Container, ServicePort + Container, ServicePort logger = logging.getLogger(__name__) logger.setLevel(LOG_LEVEL) diff --git a/src/modules/host.py b/src/modules/host.py index 9ffd8bb8..4f5fc1bb 100644 --- a/src/modules/host.py +++ b/src/modules/host.py @@ -16,10 +16,9 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..')) from common import \ - db, log_handler, \ + log_handler, \ FabricV1NetworkConfig, \ LOG_LEVEL, CLUSTER_LOG_TYPES, CLUSTER_LOG_LEVEL, \ - NETWORK_TYPE_FABRIC_V1, \ NETWORK_SIZE_FABRIC_V1, \ CLUSTER_PORT_START, CLUSTER_PORT_STEP, \ CONSENSUS_PLUGINS_FABRIC_V1, CONSENSUS_PLUGIN_SOLO, \ @@ -57,7 +56,6 @@ class HostHandler(object): A host can be a worker like Docker host, Swarm or Kubernetes """ def __init__(self): - self.col = db["host"] self.host_agents = { 'docker': DockerHost("docker"), 'swarm': DockerHost("swarm"), @@ -486,22 +484,5 @@ def db_set_by_id(self, id, **kwargs): return HostModel.objects.get(id=id) - def db_update_one(self, filter, operations, after=True): - """ - Update the data into the active db - - :param filter: Which instance to update, e.g., {"id": "xxx"} - :param operations: data to update to db, e.g., {"$set": {}} - :param after: return AFTER or BEFORE - :return: The updated host json dict - """ - if after: - return_type = ReturnDocument.AFTER - else: - return_type = ReturnDocument.BEFORE - doc = self.col.find_one_and_update( - filter, operations, return_document=return_type) - return self._serialize(doc) - host_handler = HostHandler() diff --git a/src/resources/host_api.py b/src/resources/host_api.py index 26cd8876..70a2fce6 100644 --- a/src/resources/host_api.py +++ b/src/resources/host_api.py @@ -45,7 +45,7 @@ def hosts_list(): @bp_host_api.route('/host/', methods=['GET']) def host_query(host_id): request_debug(r, logger) - result = host_handler.get_by_id(host_id) + result = host_handler.schema(host_handler.get_by_id(host_id)) logger.debug(result) if result: return make_ok_resp(data=result) diff --git a/src/watchdog.py b/src/watchdog.py index 4118773a..f8ca9e02 100644 --- a/src/watchdog.py +++ b/src/watchdog.py @@ -13,8 +13,8 @@ from mongoengine import connect import os -MONGODB_DB = os.getenv('MONGODB_DB', 'dashboard') MONGODB_HOST = os.getenv('MONGODB_HOST', 'mongo') +MONGODB_DB = os.getenv('MONGODB_DB', 'dev') MONGODB_PORT = int(os.getenv('MONGODB_PORT', 27017)) MONGODB_USERNAME = os.getenv('MONGODB_USERNAME', '') MONGODB_PASSWORD = os.getenv('MONGODB_PASSWORD', '')