Skip to content

Commit

Permalink
[CE-279] Start clean unused code
Browse files Browse the repository at this point in the history
Clean used pymongo code.

Change-Id: Ia97007178db8bfff5f49e7cbbdb8b287dfdbda78
Signed-off-by: Baohua Yang <yangbaohua@gmail.com>
  • Loading branch information
yeasy committed Feb 28, 2018
1 parent fe513ab commit df23ce4
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 37 deletions.
20 changes: 17 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ 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
- TEMPLATE_FOLDER=$TEMPLATE_FOLDER
- ENABLE_EMAIL_ACTIVE=$ENABLE_EMAIL_ACTIVE
ports:
- "8080:8080"
#volumes:
# - ./src:/app

#TODO: need to follow other images to put at dockerhub
user-dashboard:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/agent/docker/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion src/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/common/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion src/common/fabric_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand Down
5 changes: 2 additions & 3 deletions src/modules/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@
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

from agent import ClusterOnDocker, ClusterOnVsphere
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)
Expand Down
21 changes: 1 addition & 20 deletions src/modules/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion src/resources/host_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def hosts_list():
@bp_host_api.route('/host/<host_id>', 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)
Expand Down
2 changes: 1 addition & 1 deletion src/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand Down

0 comments on commit df23ce4

Please sign in to comment.