Example #1
0
def main():

    log = create_logger(Config().get("logging"))

    models_active = False
    wait = False
    while not models_active:
        try:
            _ = Instance.objects.first()
            _ = NetworkTemplate.objects.first()
            models_active = True
        except Exception as e:
            log.exception("Exception", e=e)
            log.info("Waiting for data model to come up before starting...")
            time.sleep(10)
            wait = True

    if wait:
        time.sleep(
            60
        )  # Safety factor, seeing that we stumbled waiting for the data model to come up.

    # start model policies thread
    policies_dir = Config.get("model_policies_dir")

    XOSPolicyEngine(policies_dir=policies_dir, log=log).run()
Example #2
0
    def run(self):
        observer_thread = None
        watcher_thread = None
        model_policy_thread = None

        model_accessor.update_diag(sync_start=time.time(),
                                   backend_status="Synchronizer Start")

        steps_dir = Config.get("steps_dir")
        if steps_dir:
            sync_steps = self.load_sync_step_modules(steps_dir)
            if sync_steps:
                # start the observer
                observer = XOSObserver(sync_steps, log=self.log)
                observer_thread = threading.Thread(target=observer.run,
                                                   name='synchronizer')
                observer_thread.start()

                # start the watcher thread
                if (watchers_enabled):
                    watcher = XOSWatcher(sync_steps)
                    watcher_thread = threading.Thread(target=watcher.run,
                                                      name='watcher')
                    watcher_thread.start()
        else:
            self.log.info(
                "Skipping observer and watcher threads due to no steps dir.")

        # start model policies thread
        policies_dir = Config.get("model_policies_dir")
        if policies_dir:
            policy_engine = XOSPolicyEngine(policies_dir=policies_dir,
                                            log=self.log)
            model_policy_thread = threading.Thread(target=policy_engine.run,
                                                   name="policy_engine")
            model_policy_thread.start()
        else:
            self.log.info(
                "Skipping model policies thread due to no model_policies dir.")

        if (not observer_thread) and (not watcher_thread) and (
                not model_policy_thread):
            self.log.info(
                "No sync steps and no policies. Synchronizer exiting.")
            # the caller will exit with status 0
            return

        while True:
            try:
                time.sleep(1000)
            except KeyboardInterrupt:
                print "exiting due to keyboard interrupt"
                # TODO: See about setting the threads as daemons
                if observer_thread:
                    observer_thread._Thread__stop()
                if watcher_thread:
                    watcher_thread._Thread__stop()
                if model_policy_thread:
                    model_policy_thread._Thread__stop()
                sys.exit(1)
Example #3
0
    def run(self):
        observer_thread = None
        model_policy_thread = None
        event_engine = None

        steps_dir = Config.get("steps_dir")
        if steps_dir:
            sync_steps = []

            # load sync_steps
            if steps_dir:
                sync_steps = self.load_sync_step_modules(steps_dir)

            # if we have at least one sync_step
            if len(sync_steps) > 0:
                # start the observer
                self.log.info("Starting XOSObserver", sync_steps=sync_steps)
                observer = XOSObserver(sync_steps, self.log)
                observer_thread = threading.Thread(target=observer.run,
                                                   name="synchronizer")
                observer_thread.start()

        else:
            self.log.info("Skipping observer thread due to no steps dir.")

        pull_steps_dir = Config.get("pull_steps_dir")
        if pull_steps_dir:
            self.log.info("Starting XOSPullStepEngine",
                          pull_steps_dir=pull_steps_dir)
            pull_steps_engine = XOSPullStepEngine()
            pull_steps_engine.load_pull_step_modules(pull_steps_dir)
            pull_steps_thread = threading.Thread(
                target=pull_steps_engine.start, name="pull_step_engine")
            pull_steps_thread.start()
        else:
            self.log.info(
                "Skipping pull step engine due to no pull_steps_dir dir.")

        event_steps_dir = Config.get("event_steps_dir")
        if event_steps_dir:
            self.log.info("Starting XOSEventEngine",
                          event_steps_dir=event_steps_dir)
            event_engine = XOSEventEngine(self.log)
            event_engine.load_event_step_modules(event_steps_dir)
            event_engine.start()
        else:
            self.log.info("Skipping event engine due to no event_steps dir.")

        # start model policies thread
        policies_dir = Config.get("model_policies_dir")
        if policies_dir:
            policy_engine = XOSPolicyEngine(policies_dir=policies_dir,
                                            log=self.log)
            model_policy_thread = threading.Thread(target=policy_engine.run,
                                                   name="policy_engine")
            model_policy_thread.is_policy_thread = True
            model_policy_thread.start()
        else:
            self.log.info(
                "Skipping model policies thread due to no model_policies dir.")

        if (not observer_thread) and (not model_policy_thread) and (
                not event_engine):
            self.log.info(
                "No sync steps, no policies, and no event steps. Synchronizer exiting."
            )
            # the caller will exit with status 0
            return

        while True:
            try:
                time.sleep(1000)
            except KeyboardInterrupt:
                print("exiting due to keyboard interrupt")
                # TODO: See about setting the threads as daemons
                if observer_thread:
                    observer_thread._Thread__stop()
                if model_policy_thread:
                    model_policy_thread._Thread__stop()
                sys.exit(1)
Example #4
0

def main():

    models_active = False
    wait = False
    while not models_active:
        try:
            _ = Instance.objects.first()
            _ = NetworkTemplate.objects.first()
            models_active = True
        except Exception, e:
            log.exception("Exception", e=e)
            log.info('Waiting for data model to come up before starting...')
            time.sleep(10)
            wait = True

    if (wait):
        time.sleep(
            60
        )  # Safety factor, seeing that we stumbled waiting for the data model to come up.

    # start model policies thread
    policies_dir = Config.get("model_policies_dir")

    XOSPolicyEngine(policies_dir=policies_dir).run()


if __name__ == '__main__':
    main()