def sync(self):
        if self.running:
            self.log.debug('self.running: %s', self.running)
        if self.queued_tasks:
            self.log.debug('self.queued: %s', self.queued_tasks)
        self.kube_scheduler.sync()

        last_resource_version = None
        while not self.result_queue.empty():
            results = self.result_queue.get()
            key, state, pod_id, resource_version = results
            last_resource_version = resource_version
            self.log.info('Changing state of %s to %s', results, state)
            try:
                self._change_state(key, state, pod_id)
            except Exception as e:
                self.log.exception(
                    'Exception: %s when attempting ' +
                    'to change state of %s to %s, re-queueing.', e, results,
                    state)
                self.result_queue.put(results)

        KubeResourceVersion.checkpoint_resource_version(last_resource_version)

        for i in range(
                min((self.kube_config.worker_pods_creation_batch_size,
                     self.task_queue.qsize()))):
            task = self.task_queue.get()

            try:
                self.kube_scheduler.run_next(task)
            except ApiException:
                self.log.exception('ApiException when attempting ' +
                                   'to run task, re-queueing.')
                self.task_queue.put(task)
示例#2
0
    def sync(self):
        if self.running:
            self.log.debug('self.running: %s', self.running)
        if self.queued_tasks:
            self.log.debug('self.queued: %s', self.queued_tasks)
        self.kube_scheduler.sync()

        last_resource_version = None
        while not self.result_queue.empty():
            results = self.result_queue.get()
            key, state, pod_id, resource_version = results
            last_resource_version = resource_version
            self.log.info('Changing state of %s to %s', results, state)
            self._change_state(key, state, pod_id)

        KubeResourceVersion.checkpoint_resource_version(last_resource_version)

        for i in range(min((self.kube_config.worker_pods_creation_batch_size, self.task_queue.qsize()))):
            task = self.task_queue.get()

            try:
                self.kube_scheduler.run_next(task)
            except ApiException:
                self.log.exception('ApiException when attempting ' +
                                   'to run task, re-queueing.')
                self.task_queue.put(task)
 def start(self):
     self.log.info('Start Kubernetes executor')
     self.worker_uuid = KubeWorkerIdentifier.get_or_create_current_kube_worker_uuid(
     )
     self.log.debug('Start with worker_uuid: %s', self.worker_uuid)
     # always need to reset resource version since we don't know
     # when we last started, note for behavior below
     # https://github.com/kubernetes-client/python/blob/master/kubernetes/docs
     # /CoreV1Api.md#list_namespaced_pod
     KubeResourceVersion.reset_resource_version()
     self.task_queue = Queue()
     self.result_queue = Queue()
     self.kube_client = get_kube_client()
     self.kube_scheduler = AirflowKubernetesScheduler(
         self.kube_config, self.task_queue, self.result_queue,
         self.kube_client, self.worker_uuid)
     self._inject_secrets()
     self.clear_not_launched_queued_tasks()
示例#4
0
 def start(self):
     self.log.info('Start Kubernetes executor')
     self.worker_uuid = KubeWorkerIdentifier.get_or_create_current_kube_worker_uuid()
     self.log.debug('Start with worker_uuid: %s', self.worker_uuid)
     # always need to reset resource version since we don't know
     # when we last started, note for behavior below
     # https://github.com/kubernetes-client/python/blob/master/kubernetes/docs
     # /CoreV1Api.md#list_namespaced_pod
     KubeResourceVersion.reset_resource_version()
     self.task_queue = Queue()
     self.result_queue = Queue()
     self.kube_client = get_kube_client()
     self.kube_scheduler = AirflowKubernetesScheduler(
         self.kube_config, self.task_queue, self.result_queue,
         self.kube_client, self.worker_uuid
     )
     self._inject_secrets()
     self.clear_not_launched_queued_tasks()
 def _make_kube_watcher(self):
     resource_version = KubeResourceVersion.get_current_resource_version()
     watcher = KubernetesJobWatcher(self.namespace, self.watcher_queue,
                                    resource_version, self.worker_uuid)
     watcher.start()
     return watcher
示例#6
0
 def _make_kube_watcher(self):
     resource_version = KubeResourceVersion.get_current_resource_version()
     watcher = KubernetesJobWatcher(self.namespace, self.watcher_queue,
                                    resource_version, self.worker_uuid)
     watcher.start()
     return watcher
 def test_reset_resource_version(self):
     session = settings.Session()
     version = KubeResourceVersion.reset_resource_version(session)
     self.assertEqual(version, '0')
     self.assertEqual(
         KubeResourceVersion.get_current_resource_version(session), '0')
 def test_checkpoint_resource_version(self):
     session = settings.Session()
     KubeResourceVersion.checkpoint_resource_version('7', session)
     self.assertEqual(
         KubeResourceVersion.get_current_resource_version(session), '7')
 def test_reset_resource_version(self):
     session = settings.Session()
     version = KubeResourceVersion.reset_resource_version(session)
     self.assertEqual(version, '0')
     self.assertEqual(KubeResourceVersion.get_current_resource_version(session), '0')
示例#10
0
 def test_checkpoint_resource_version(self):
     session = settings.Session()
     KubeResourceVersion.checkpoint_resource_version('7', session)
     self.assertEqual(KubeResourceVersion.get_current_resource_version(session), '7')