Scott Baker | 25467ff | 2016-08-04 09:50:22 -0700 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | import base64 |
| 4 | from django.db.models import F, Q |
| 5 | from xos.config import Config |
| 6 | from synchronizers.base.syncstep import SyncStep |
| 7 | from core.models import Service |
| 8 | from services.hpc.models import HpcService |
| 9 | from services.requestrouter.models import RequestRouterService |
| 10 | from xos.logger import Logger, logging |
| 11 | |
| 12 | # hpclibrary will be in steps/.. |
| 13 | parentdir = os.path.join(os.path.dirname(__file__),"..") |
| 14 | sys.path.insert(0,parentdir) |
| 15 | |
| 16 | from hpclib import HpcLibrary |
| 17 | |
| 18 | logger = Logger(level=logging.INFO) |
| 19 | |
| 20 | class SyncHpcService(SyncStep, HpcLibrary): |
| 21 | provides=[HpcService] |
| 22 | observes=HpcService |
| 23 | requested_interval=0 |
| 24 | |
| 25 | def __init__(self, **args): |
| 26 | SyncStep.__init__(self, **args) |
| 27 | HpcLibrary.__init__(self) |
| 28 | |
| 29 | def filter_hpc_service(self, objs): |
| 30 | hpcService = self.get_hpc_service() |
| 31 | |
| 32 | return [x for x in objs if x == hpcService] |
| 33 | |
| 34 | def fetch_pending(self, deleted): |
| 35 | # Looks like deletion is not supported for this object - Sapan |
| 36 | if (deleted): |
| 37 | return [] |
| 38 | else: |
| 39 | return self.filter_hpc_service(HpcService.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))) |
| 40 | |
| 41 | def sync_record(self, hpc_service): |
| 42 | logger.info("sync'ing hpc_service %s" % str(hpc_service),extra=hpc_service.tologdict()) |
| 43 | hpc_service.save() |