CORD-880 modify exampleservice synchronizer to use new_base
Change-Id: I5056982f7dbda607244f14b0095f56f14d10a526
diff --git a/xos/synchronizer/Dockerfile.synchronizer b/xos/synchronizer/Dockerfile.synchronizer
new file mode 100644
index 0000000..e70aad6
--- /dev/null
+++ b/xos/synchronizer/Dockerfile.synchronizer
@@ -0,0 +1,9 @@
+FROM xosproject/xos-synchronizer-base
+
+ADD . /opt/xos/synchronizers/exampleservice
+
+ENTRYPOINT []
+
+WORKDIR "/opt/xos/synchronizers/exampleservice"
+
+CMD bash -c "cd /opt/xos/synchronizers/exampleservice; ./run-from-api.sh"
diff --git a/xos/synchronizer/Makefile b/xos/synchronizer/Makefile
new file mode 100644
index 0000000..7d196e3
--- /dev/null
+++ b/xos/synchronizer/Makefile
@@ -0,0 +1,5 @@
+synchronizer:
+ sudo docker build --rm -f Dockerfile.synchronizer -t xosproject/exampleservice-synchronizer .
+
+up:
+ docker-compose -p exampleservice up -d
diff --git a/xos/synchronizer/docker-compose.yml b/xos/synchronizer/docker-compose.yml
new file mode 100644
index 0000000..78a620e
--- /dev/null
+++ b/xos/synchronizer/docker-compose.yml
@@ -0,0 +1,24 @@
+version: '2'
+
+networks:
+ xos:
+ external: true
+
+services:
+ synchronizer:
+ image: xosproject/exampleservice-synchronizer
+ networks:
+ - xos
+ #command: bash -c "cd /opt/xos/synchronizers/exampleservice; ./run-from-api.sh"
+ #command: bash -c "sleep 86400"
+ volumes:
+ - /opt/cord_profile/key_import/exampleservice_rsa:/opt/xos/services/exampleservice/keys/exampleservice_rsa:ro
+ - /opt/cord_profile/node_key:/opt/cord_profile/node_key:ro
+ - /opt/cord/build/platform-install/credentials/xosadmin@opencord.org:/opt/xos/services/exampleservice/credentials/xosadmin@opencord.org
+ external_links:
+ - rcord_xos_redis_1:redis
+ logging:
+ driver: "json-file"
+ options:
+ max-size: "1000k"
+ max-file: "5"
diff --git a/xos/synchronizer/exampleservice-synchronizer.py b/xos/synchronizer/exampleservice-synchronizer.py
index 90d2c98..aafdb44 100644
--- a/xos/synchronizer/exampleservice-synchronizer.py
+++ b/xos/synchronizer/exampleservice-synchronizer.py
@@ -7,7 +7,7 @@
import sys
synchronizer_path = os.path.join(os.path.dirname(
- os.path.realpath(__file__)), "../../synchronizers/base")
+ os.path.realpath(__file__)), "../../synchronizers/new_base")
sys.path.append(synchronizer_path)
mod = importlib.import_module("xos-synchronizer")
mod.main()
diff --git a/xos/synchronizer/exampleservice_from_api_config b/xos/synchronizer/exampleservice_from_api_config
new file mode 100644
index 0000000..e55e519
--- /dev/null
+++ b/xos/synchronizer/exampleservice_from_api_config
@@ -0,0 +1,18 @@
+# Sets options for the synchronizer
+[observer]
+name=exampleservice
+dependency_graph=/opt/xos/synchronizers/exampleservice/model-deps
+steps_dir=/opt/xos/synchronizers/exampleservice/steps
+sys_dir=/opt/xos/synchronizers/exampleservice/sys
+#logfile=/var/log/xos_backend.log
+log_file=console
+log_level=debug
+pretend=False
+backoff_disabled=True
+save_ansible_output=True
+proxy_ssh=True
+proxy_ssh_key=/opt/cord_profile/node_key
+proxy_ssh_user=root
+enable_watchers=True
+accessor_kind=api
+accessor_password=@/opt/xos/services/exampleservice/credentials/xosadmin@opencord.org
diff --git a/xos/synchronizer/run-from-api.sh b/xos/synchronizer/run-from-api.sh
new file mode 100755
index 0000000..1245084
--- /dev/null
+++ b/xos/synchronizer/run-from-api.sh
@@ -0,0 +1,2 @@
+export XOS_DIR=/opt/xos
+python exampleservice-synchronizer.py -C $XOS_DIR/synchronizers/exampleservice/exampleservice_from_api_config
diff --git a/xos/synchronizer/steps/sync_exampletenant.py b/xos/synchronizer/steps/sync_exampletenant.py
index 1b2f619..bb40a86 100644
--- a/xos/synchronizer/steps/sync_exampletenant.py
+++ b/xos/synchronizer/steps/sync_exampletenant.py
@@ -1,9 +1,7 @@
import os
import sys
-from django.db.models import Q, F
-from core.models import ModelLink, CoarseTenant, ServiceMonitoringAgentInfo
-from services.exampleservice.models import ExampleService, ExampleTenant
-from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+from synchronizers.new_base.modelaccessor import *
from xos.logger import Logger, logging
parentdir = os.path.join(os.path.dirname(__file__), "..")
@@ -28,22 +26,11 @@
def __init__(self, *args, **kwargs):
super(SyncExampleTenant, self).__init__(*args, **kwargs)
- def fetch_pending(self, deleted):
-
- if (not deleted):
- objs = ExampleTenant.get_tenant_objects().filter(
- Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
- else:
- # If this is a deletion we get all of the deleted tenants..
- objs = ExampleTenant.get_deleted_tenant_objects()
-
- return objs
-
def get_exampleservice(self, o):
if not o.provider_service:
return None
- exampleservice = ExampleService.get_service_objects().filter(id=o.provider_service.id)
+ exampleservice = ExampleService.objects.filter(id=o.provider_service.id)
if not exampleservice:
return None
@@ -73,7 +60,7 @@
logger.info("handle watch notifications for service monitoring agent info...ignoring because target_uri attribute in monitoring agent info:%s is null" % (monitoring_agent_info))
return
- objs = ExampleTenant.get_tenant_objects().all()
+ objs = ExampleTenant.objects.all()
for obj in objs:
if obj.provider_service.id != monitoring_agent_info.service.id:
logger.info("handle watch notifications for service monitoring agent info...ignoring because service attribute in monitoring agent info:%s is not matching" % (monitoring_agent_info))