Build docker image
Package to a single plugin file to follow airflow plugin structure

Change-Id: I53765c6d399f8d8e9eeed28901132953c1cf7df6
diff --git a/.gitignore b/.gitignore
index 5811e16..be7ca2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.idea
 .noseids
 .vscode
 build
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..9b5dbeb
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,47 @@
+# opencord/cord-workflow-airflow
+# To build use: docker build -t opencord/cord-workflow-airflow .
+# To run use: docker run -p 8080:8080 -d opencord/cord-workflow-airflow
+FROM puckel/docker-airflow:1.10.2
+
+USER root
+
+# install dependencies of our plugin
+RUN set -ex \
+    && pip install multistructlog~=2.1.0 \
+    && pip install cord-workflow-controller-client~=0.2.0 \
+    && pip install pyfiglet~=0.7 \
+    && pip install xossynchronizer~=3.2.6 \
+    && pip install xosapi~=3.2.6 \
+    && apt-get purge --auto-remove -yqq $buildDeps \
+    && apt-get autoremove -yqq --purge \
+    && apt-get clean \
+    && rm -rf \
+        /var/lib/apt/lists/* \
+        /tmp/* \
+        /var/tmp/* \
+        /usr/share/man \
+        /usr/share/doc \
+        /usr/share/doc-base
+
+# drop plugin to plugin dir of airflow
+COPY src/cord_workflow_airflow_extensions/cord_workflow_plugin.py /usr/local/airflow/plugins/
+
+USER airflow
+
+# Label image
+ARG org_label_schema_schema_version=1.0
+ARG org_label_schema_name=cord-workflow-airflow
+ARG org_label_schema_version=unknown
+ARG org_label_schema_vcs_url=unknown
+ARG org_label_schema_vcs_ref=unknown
+ARG org_label_schema_build_date=unknown
+ARG org_opencord_vcs_commit_date=unknown
+
+LABEL org.label-schema.schema-version=$org_label_schema_schema_version \
+      org.label-schema.name=$org_label_schema_name \
+      org.label-schema.version=$org_label_schema_version \
+      org.label-schema.vcs-url=$org_label_schema_vcs_url \
+      org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
+      org.label-schema.build-date=$org_label_schema_build_date \
+      org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date
+
diff --git a/Makefile b/Makefile
index 7b82614..38dbcde 100644
--- a/Makefile
+++ b/Makefile
@@ -12,15 +12,43 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# set default shell
+# Configure shell
 SHELL = bash -e -o pipefail
 
 # Variables
 VERSION                  ?= $(shell cat ./VERSION)
+CONTAINER_NAME           ?= $(notdir $(abspath .))
+
+## Docker related
+DOCKER_REGISTRY          ?=
+DOCKER_REPOSITORY        ?=
+DOCKER_BUILD_ARGS        ?=
+DOCKER_TAG               ?= ${VERSION}
+DOCKER_IMAGENAME         := ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}${CONTAINER_NAME}:${DOCKER_TAG}
+
+## Docker labels. Only set ref and commit date if committed
+DOCKER_LABEL_VCS_URL     ?= $(shell git remote get-url $(shell git remote))
+DOCKER_LABEL_VCS_REF     ?= $(shell git diff-index --quiet HEAD -- && git rev-parse HEAD || echo "unknown")
+DOCKER_LABEL_COMMIT_DATE ?= $(shell git diff-index --quiet HEAD -- && git show -s --format=%cd --date=iso-strict HEAD || echo "unknown" )
+DOCKER_LABEL_BUILD_DATE  ?= $(shell date -u "+%Y-%m-%dT%H:%M:%SZ")
+
 
 # Targets
 all: test
 
+docker-build:
+	docker build $(DOCKER_BUILD_ARGS) \
+    -t ${DOCKER_IMAGENAME} \
+    --build-arg org_label_schema_version="${VERSION}" \
+    --build-arg org_label_schema_vcs_url="${DOCKER_LABEL_VCS_URL}" \
+    --build-arg org_label_schema_vcs_ref="${DOCKER_LABEL_VCS_REF}" \
+    --build-arg org_label_schema_build_date="${DOCKER_LABEL_BUILD_DATE}" \
+    --build-arg org_opencord_vcs_commit_date="${DOCKER_LABEL_COMMIT_DATE}" \
+    -f Dockerfile .
+
+docker-push:
+	docker push ${DOCKER_IMAGENAME}
+
 # Create a virtualenv and install all the libraries
 venv-cordworkflowairflow:
 	virtualenv $@;\
diff --git a/VERSION b/VERSION
index 341cf11..9325c3c 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.2.0
\ No newline at end of file
+0.3.0
\ No newline at end of file
diff --git a/docker-compose-LocalExecutor.yml b/docker-compose-LocalExecutor.yml
new file mode 100644
index 0000000..13d480b
--- /dev/null
+++ b/docker-compose-LocalExecutor.yml
@@ -0,0 +1,44 @@
+# Copyright Matthieu "Puckel_" Roisil (https://github.com/puckel)
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# this file is copied from following link
+# https://github.com/puckel/docker-airflow/blob/master/docker-compose-LocalExecutor.yml
+
+version: '2.1'
+services:
+    postgres:
+        image: postgres:9.6
+        environment:
+            - POSTGRES_USER=airflow
+            - POSTGRES_PASSWORD=airflow
+            - POSTGRES_DB=airflow
+
+    webserver:
+        image: opencord/cord-workflow-airflow
+        restart: always
+        depends_on:
+            - postgres
+        environment:
+            - LOAD_EX=n
+            - EXECUTOR=Local
+        volumes:
+            - ./dags:/usr/local/airflow/dags
+        ports:
+            - "8080:8080"
+        command: webserver
+        healthcheck:
+            test: ["CMD-SHELL", "[ -f /usr/local/airflow/airflow-webserver.pid ]"]
+            interval: 30s
+            timeout: 30s
+            retries: 3
diff --git a/requirements.txt b/requirements.txt
index 1b0f05e..0e6a84b 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,6 +2,7 @@
 werkzeug~=0.15
 apache-airflow~=1.10.2
 multistructlog~=2.1.0
-requests~=2.22.0
 pyfiglet~=0.7
 cord-workflow-controller-client~=0.2.0
+xossynchronizer~=3.2.6
+xosapi~=3.2.6
\ No newline at end of file
diff --git a/src/cord_workflow_airflow_extensions/cord_workflow_plugin.py b/src/cord_workflow_airflow_extensions/cord_workflow_plugin.py
new file mode 100644
index 0000000..152862f
--- /dev/null
+++ b/src/cord_workflow_airflow_extensions/cord_workflow_plugin.py
@@ -0,0 +1,267 @@
+#!/usr/bin/env python3
+
+# Copyright 2019-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from airflow.plugins_manager import AirflowPlugin
+from airflow.hooks.base_hook import BaseHook
+from airflow.operators.python_operator import PythonOperator
+from airflow.sensors.base_sensor_operator import BaseSensorOperator
+from airflow.utils.decorators import apply_defaults
+from cord_workflow_controller_client.workflow_run import WorkflowRun
+
+
+"""
+Airflow Hook
+"""
+
+
+class CORDWorkflowControllerException(Exception):
+    """
+    Alias for Exception.
+    """
+
+
+class CORDWorkflowControllerHook(BaseHook):
+    """
+    Hook for accessing CORD Workflow Controller
+    """
+
+    def __init__(
+            self,
+            workflow_id,
+            workflow_run_id,
+            controller_conn_id='cord_controller_default'):
+        super().__init__(source=None)
+        self.workflow_id = workflow_id
+        self.workflow_run_id = workflow_run_id
+        self.controller_conn_id = controller_conn_id
+
+        self.workflow_run_client = None
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        if self.workflow_run_client is not None:
+            self.close_conn()
+
+    def get_conn(self):
+        """
+        Connect a Workflow Run client.
+        """
+        if self.workflow_run_client is None:
+            # find connection info from database or environment
+            # ENV: AIRFLOW_CONN_CORD_CONTROLLER_DEFAULT
+            connection_params = self.get_connection(self.controller_conn_id)
+            # connection_params have three fields
+            # host
+            # login - we don't use this yet
+            # password - we don't use this yet
+            try:
+                self.workflow_run_client = WorkflowRun(self.workflow_id, self.workflow_run_id)
+                self.workflow_run_client.connect(connection_params.host)
+            except BaseException as ex:
+                raise CORDWorkflowControllerException(ex)
+
+        return self.workflow_run_client
+
+    def close_conn(self):
+        """
+        Close the Workflow Run client
+        """
+        if self.workflow_run_client:
+            try:
+                self.workflow_run_client.disconnect()
+            except BaseException as ex:
+                raise CORDWorkflowControllerException(ex)
+
+        self.workflow_run_client = None
+
+    def update_status(self, task_id, status):
+        """
+        Update status of the workflow run.
+        'state' should be one of ['begin', 'end']
+        """
+        client = self.get_conn()
+        try:
+            return client.update_status(task_id, status)
+        except BaseException as ex:
+            raise CORDWorkflowControllerException(ex)
+
+    def count_events(self):
+        """
+        Count queued events for the workflow run.
+        """
+        client = self.get_conn()
+        try:
+            return client.count_events()
+        except BaseException as ex:
+            raise CORDWorkflowControllerException(ex)
+
+    def fetch_event(self, task_id, topic):
+        """
+        Fetch an event for the workflow run.
+        """
+        client = self.get_conn()
+        try:
+            return client.fetch_event(task_id, topic)
+        except BaseException as ex:
+            raise CORDWorkflowControllerException(ex)
+
+
+"""
+Airflow Operators
+"""
+
+
+class CORDModelOperator(PythonOperator):
+    """
+    Calls a python function with model accessor.
+    """
+
+    # SCARLET
+    # http://bootflat.github.io/color-picker.html
+    ui_color = '#cf3a24'
+
+    @apply_defaults
+    def __init__(
+        self,
+        python_callable,
+        cord_event_sensor_task_id=None,
+        op_args=None,
+        op_kwargs=None,
+        provide_context=True,
+        templates_dict=None,
+        templates_exts=None,
+        *args,
+        **kwargs
+    ):
+        super().__init__(
+            python_callable=python_callable,
+            op_args=op_args,
+            op_kwargs=op_kwargs,
+            provide_context=True,
+            templates_dict=templates_dict,
+            templates_exts=templates_exts,
+            *args,
+            **kwargs)
+        self.cord_event_sensor_task_id = cord_event_sensor_task_id
+
+    def execute_callable(self):
+        # TODO
+        model_accessor = None
+
+        message = None
+        if self.cord_event_sensor_task_id:
+            message = self.op_kwargs['ti'].xcom_pull(task_ids=self.cord_event_sensor_task_id)
+
+        new_op_kwargs = dict(self.op_kwargs, model_accessor=model_accessor, message=message)
+        return self.python_callable(*self.op_args, **new_op_kwargs)
+
+
+"""
+Airflow Sensors
+"""
+
+
+class CORDEventSensor(BaseSensorOperator):
+    # STEEL BLUE
+    # http://bootflat.github.io/color-picker.html
+    ui_color = '#4b77be'
+
+    @apply_defaults
+    def __init__(
+            self,
+            topic,
+            key_field,
+            controller_conn_id='cord_controller_default',
+            *args,
+            **kwargs):
+        super().__init__(*args, **kwargs)
+
+        self.topic = topic
+        self.key_field = key_field
+        self.controller_conn_id = controller_conn_id
+        self.message = None
+        self.hook = None
+
+    def __create_hook(self, context):
+        """
+        Return connection hook.
+        """
+        return CORDWorkflowControllerHook(self.dag_id, context['dag_run'].run_id, self.controller_conn_id)
+
+    def execute(self, context):
+        """
+        Overridden to allow messages to be passed to next tasks via XCOM
+        """
+        if self.hook is None:
+            self.hook = self.__create_hook(context)
+
+        self.hook.update_status(self.task_id, 'begin')
+
+        super().execute(context)
+
+        self.hook.update_status(self.task_id, 'end')
+        self.hook.close_conn()
+        self.hook = None
+        return self.message
+
+    def poke(self, context):
+        # we need to use notification to immediately react at event
+        # https://github.com/apache/airflow/blob/master/airflow/sensors/base_sensor_operator.py#L122
+        self.log.info('Poking : trying to fetch a message with a topic %s', self.topic)
+        event = self.hook.fetch_event(self.task_id, self.topic)
+        if event:
+            self.message = event
+            return True
+        return False
+
+
+class CORDModelSensor(CORDEventSensor):
+    # SISKIN SPROUT YELLOW
+    # http://bootflat.github.io/color-picker.html
+    ui_color = '#7a942e'
+
+    @apply_defaults
+    def __init__(
+            self,
+            model_name,
+            key_field,
+            controller_conn_id='cord_controller_default',
+            *args,
+            **kwargs):
+        topic = 'datamodel.%s' % model_name
+        super().__init__(topic=topic, *args, **kwargs)
+
+
+"""
+Airflow Plugin Definition
+"""
+
+
+# Defining the plugin class
+class CORD_Workflow_Airflow_Plugin(AirflowPlugin):
+    name = "CORD_Workflow_Airflow_Plugin"
+    operators = [CORDModelOperator]
+    sensors = [CORDEventSensor, CORDModelSensor]
+    hooks = [CORDWorkflowControllerHook]
+    executors = []
+    macros = []
+    admin_views = []
+    flask_blueprints = []
+    menu_links = []
+    appbuilder_views = []
+    appbuilder_menu_items = []
diff --git a/src/cord_workflow_airflow_extensions/hook.py b/src/cord_workflow_airflow_extensions/hook.py
deleted file mode 100644
index a2ebb4e..0000000
--- a/src/cord_workflow_airflow_extensions/hook.py
+++ /dev/null
@@ -1,116 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright 2019-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""
-Airflow Hook
-"""
-
-from airflow.hooks.base_hook import BaseHook
-from cord_workflow_controller_client.workflow_run import WorkflowRun
-
-
-class CORDWorkflowControllerException(Exception):
-    """
-    Alias for Exception.
-    """
-
-
-class CORDWorkflowControllerHook(BaseHook):
-    """
-    Hook for accessing CORD Workflow Controller
-    """
-
-    def __init__(
-            self,
-            workflow_id,
-            workflow_run_id,
-            controller_conn_id='cord_controller_default'):
-        super().__init__(source=None)
-        self.workflow_id = workflow_id
-        self.workflow_run_id = workflow_run_id
-        self.controller_conn_id = controller_conn_id
-
-        self.workflow_run_client = None
-
-    def __enter__(self):
-        return self
-
-    def __exit__(self, exc_type, exc_val, exc_tb):
-        if self.workflow_run_client is not None:
-            self.close_conn()
-
-    def get_conn(self):
-        """
-        Connect a Workflow Run client.
-        """
-        if self.workflow_run_client is None:
-            # find connection info from database or environment
-            # ENV: AIRFLOW_CONN_CORD_CONTROLLER_DEFAULT
-            connection_params = self.get_connection(self.controller_conn_id)
-            # connection_params have three fields
-            # host
-            # login - we don't use this yet
-            # password - we don't use this yet
-            try:
-                self.workflow_run_client = WorkflowRun(self.workflow_id, self.workflow_run_id)
-                self.workflow_run_client.connect(connection_params.host)
-            except BaseException as ex:
-                raise CORDWorkflowControllerException(ex)
-
-        return self.workflow_run_client
-
-    def close_conn(self):
-        """
-        Close the Workflow Run client
-        """
-        if self.workflow_run_client:
-            try:
-                self.workflow_run_client.disconnect()
-            except BaseException as ex:
-                raise CORDWorkflowControllerException(ex)
-
-        self.workflow_run_client = None
-
-    def update_status(self, task_id, status):
-        """
-        Update status of the workflow run.
-        'state' should be one of ['begin', 'end']
-        """
-        client = self.get_conn()
-        try:
-            return client.update_status(task_id, status)
-        except BaseException as ex:
-            raise CORDWorkflowControllerException(ex)
-
-    def count_events(self):
-        """
-        Count queued events for the workflow run.
-        """
-        client = self.get_conn()
-        try:
-            return client.count_events()
-        except BaseException as ex:
-            raise CORDWorkflowControllerException(ex)
-
-    def fetch_event(self, task_id, topic):
-        """
-        Fetch an event for the workflow run.
-        """
-        client = self.get_conn()
-        try:
-            return client.fetch_event(task_id, topic)
-        except BaseException as ex:
-            raise CORDWorkflowControllerException(ex)
diff --git a/src/cord_workflow_airflow_extensions/operators.py b/src/cord_workflow_airflow_extensions/operators.py
deleted file mode 100644
index ab1ddd9..0000000
--- a/src/cord_workflow_airflow_extensions/operators.py
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright 2019-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""
-Airflow Operators
-"""
-
-from airflow.operators import PythonOperator
-from airflow.utils.decorators import apply_defaults
-
-
-class CORDModelOperator(PythonOperator):
-    """
-    Calls a python function with model accessor.
-    """
-
-    # SCARLET
-    # http://bootflat.github.io/color-picker.html
-    ui_color = '#cf3a24'
-
-    @apply_defaults
-    def __init__(
-        self,
-        python_callable,
-        cord_event_sensor_task_id=None,
-        op_args=None,
-        op_kwargs=None,
-        provide_context=True,
-        templates_dict=None,
-        templates_exts=None,
-        *args,
-        **kwargs
-    ):
-        super().__init__(
-            python_callable=python_callable,
-            op_args=op_args,
-            op_kwargs=op_kwargs,
-            provide_context=True,
-            templates_dict=templates_dict,
-            templates_exts=templates_exts,
-            *args,
-            **kwargs)
-        self.cord_event_sensor_task_id = cord_event_sensor_task_id
-
-    def execute_callable(self):
-        # TODO
-        model_accessor = None
-
-        message = None
-        if self.cord_event_sensor_task_id:
-            message = self.op_kwargs['ti'].xcom_pull(task_ids=self.cord_event_sensor_task_id)
-
-        new_op_kwargs = dict(self.op_kwargs, model_accessor=model_accessor, message=message)
-        return self.python_callable(*self.op_args, **new_op_kwargs)
diff --git a/src/cord_workflow_airflow_extensions/sensors.py b/src/cord_workflow_airflow_extensions/sensors.py
deleted file mode 100644
index cba72e3..0000000
--- a/src/cord_workflow_airflow_extensions/sensors.py
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/usr/bin/env python3
-
-# Copyright 2019-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""
-Airflow Sensors
-"""
-
-from .hook import CORDWorkflowControllerHook
-from airflow.sensors.base_sensor_operator import BaseSensorOperator
-from airflow.utils.decorators import apply_defaults
-
-
-class CORDEventSensor(BaseSensorOperator):
-    # STEEL BLUE
-    # http://bootflat.github.io/color-picker.html
-    ui_color = '#4b77be'
-
-    @apply_defaults
-    def __init__(
-            self,
-            topic,
-            key_field,
-            controller_conn_id='cord_controller_default',
-            *args,
-            **kwargs):
-        super().__init__(*args, **kwargs)
-
-        self.topic = topic
-        self.key_field = key_field
-        self.controller_conn_id = controller_conn_id
-        self.message = None
-        self.hook = None
-
-    def __create_hook(self, context):
-        """
-        Return connection hook.
-        """
-        return CORDWorkflowControllerHook(self.dag_id, context['dag_run'].run_id, self.controller_conn_id)
-
-    def execute(self, context):
-        """
-        Overridden to allow messages to be passed to next tasks via XCOM
-        """
-        if self.hook is None:
-            self.hook = self.__create_hook(context)
-
-        self.hook.update_status(self.task_id, 'begin')
-
-        super().execute(context)
-
-        self.hook.update_status(self.task_id, 'end')
-        self.hook.close_conn()
-        self.hook = None
-        return self.message
-
-    def poke(self, context):
-        # we need to use notification to immediately react at event
-        # https://github.com/apache/airflow/blob/master/airflow/sensors/base_sensor_operator.py#L122
-        self.log.info('Poking : trying to fetch a message with a topic %s', self.topic)
-        event = self.hook.fetch_event(self.task_id, self.topic)
-        if event:
-            self.message = event
-            return True
-        return False
-
-
-class CORDModelSensor(CORDEventSensor):
-    # SISKIN SPROUT YELLOW
-    # http://bootflat.github.io/color-picker.html
-    ui_color = '#7a942e'
-
-    @apply_defaults
-    def __init__(
-            self,
-            model_name,
-            key_field,
-            controller_conn_id='cord_controller_default',
-            *args,
-            **kwargs):
-        topic = 'datamodel.%s' % model_name
-        super().__init__(topic=topic, *args, **kwargs)
diff --git a/workflow_examples/simple-att-workflow/att_dag.py b/workflow_examples/simple-att-workflow/att_dag.py
new file mode 100644
index 0000000..fd40b28
--- /dev/null
+++ b/workflow_examples/simple-att-workflow/att_dag.py
@@ -0,0 +1,234 @@
+# Copyright 2019-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""
+Example AT&T workflow using Airflow
+"""
+
+
+import logging
+from datetime import datetime
+from airflow import DAG
+from cord_workflow_airflow_extensions.sensors import CORDEventSensor, CORDModelSensor
+from cord_workflow_airflow_extensions.operators import CORDModelOperator
+
+
+log = logging.getLogger(__name__)
+
+args = {
+    'start_date': datetime.utcnow(),
+    'owner': 'iychoi',
+}
+
+dag_att = DAG(
+    dag_id='simple_att_workflow',
+    default_args=args,
+    # this dag will be triggered by external systems
+    schedule_interval=None,
+)
+
+dag_att.doc_md = __doc__
+
+
+def ONU_event(model_accessor, message, **kwargs):
+    log.info('onu.events: received an event - %s' % message)
+
+    """
+    si = find_or_create_att_si(model_accessor, logging, message)
+    if message['status'] == 'activated':
+        logging.info('onu.events: activated onu', message=message)
+        si.no_sync = False
+        si.uni_port_id = long(message['portNumber'])
+        si.of_dpid = message['deviceId']
+        si.oper_onu_status = 'ENABLED'
+        si.save_changed_fields(always_update_timestamp=True)
+    elif message['status'] == 'disabled':
+        logging.info('onu.events: disabled onu, resetting the subscriber', value=message)
+        si.oper_onu_status = 'DISABLED'
+        si.save_changed_fields(always_update_timestamp=True)
+    else:
+        logging.warn('onu.events: Unknown status value: %s' % message['status'], value=message)
+        raise AirflowException('onu.events: Unknown status value: %s' % message['status'], value=message)
+    """
+
+
+def AUTH_event(model_accessor, message, **kwargs):
+    log.info('authentication.events: received an event - %s' % message)
+
+    """
+    si = find_or_create_att_si(model_accessor, logging, message)
+    logging.debug('authentication.events: Updating service instance', si=si)
+    si.authentication_state = message['authenticationState']
+    si.save_changed_fields(always_update_timestamp=True)
+    """
+
+
+def DHCP_event(model_accessor, message, **kwargs):
+    log.info('dhcp.events: received an event - %s' % message)
+
+    """
+    si = find_or_create_att_si(model_accessor, logging, message)
+    logging.debug('dhcp.events: Updating service instance', si=si)
+    si.dhcp_state = message['messageType']
+    si.ip_address = message['ipAddress']
+    si.mac_address = message['macAddress']
+    si.save_changed_fields(always_update_timestamp=True)
+    """
+
+
+def DriverService_event(model_accessor, message, **kwargs):
+    log.info('model event: received an event - %s' % message)
+
+    """
+    event_type = message['event_type']
+
+    go = False
+    si = find_or_create_att_si(model_accessor, logging, message)
+
+    if event_type == 'create':
+        logging.debug('MODEL_POLICY: handle_create for AttWorkflowDriverServiceInstance %s ' % si.id)
+        go = True
+    elif event_type == 'update':
+        logging.debug('MODEL_POLICY: handle_update for AttWorkflowDriverServiceInstance %s ' %
+                          (si.id), onu_state=si.admin_onu_state, authentication_state=si.authentication_state)
+        go = True
+    elif event_type == 'delete':
+        pass
+    else:
+        pass
+
+    if not go:
+        return
+
+    # handle only create & update events
+
+    # Changing ONU state can change auth state
+    # Changing auth state can change DHCP state
+    # So need to process in this order
+    process_onu_state(model_accessor, si)
+    process_auth_state(si)
+    process_dhcp_state(si)
+
+    validate_states(si)
+
+    # handling the subscriber status
+    # It's a combination of all the other states
+    subscriber = get_subscriber(model_accessor, si.serial_number)
+    if subscriber:
+        update_subscriber(model_accessor, subscriber, si)
+
+    si.save_changed_fields()
+    """
+
+
+onu_event_sensor = CORDEventSensor(
+    task_id='onu_event_sensor',
+    topic='onu.events',
+    key_field='serialNumber',
+    controller_conn_id='local_cord_controller',
+    poke_interval=5,
+    dag=dag_att
+)
+
+onu_event_handler = CORDModelOperator(
+    task_id='onu_event_handler',
+    python_callable=ONU_event,
+    cord_event_sensor_task_id='onu_event_sensor',
+    dag=dag_att
+)
+
+auth_event_sensor = CORDEventSensor(
+    task_id='auth_event_sensor',
+    topic='authentication.events',
+    key_field='serialNumber',
+    controller_conn_id='local_cord_controller',
+    poke_interval=5,
+    dag=dag_att
+)
+
+auth_event_handler = CORDModelOperator(
+    task_id='auth_event_handler',
+    python_callable=AUTH_event,
+    cord_event_sensor_task_id='auth_event_sensor',
+    dag=dag_att
+)
+
+dhcp_event_sensor = CORDEventSensor(
+    task_id='dhcp_event_sensor',
+    topic='dhcp.events',
+    key_field='serialNumber',
+    controller_conn_id='local_cord_controller',
+    poke_interval=5,
+    dag=dag_att
+)
+
+dhcp_event_handler = CORDModelOperator(
+    task_id='dhcp_event_handler',
+    python_callable=DHCP_event,
+    cord_event_sensor_task_id='dhcp_event_sensor',
+    dag=dag_att
+)
+
+att_model_event_sensor1 = CORDModelSensor(
+    task_id='att_model_event_sensor1',
+    model_name='AttWorkflowDriverServiceInstance',
+    key_field='serialNumber',
+    controller_conn_id='local_cord_controller',
+    poke_interval=5,
+    dag=dag_att
+)
+
+att_model_event_handler1 = CORDModelOperator(
+    task_id='att_model_event_handler1',
+    python_callable=DriverService_event,
+    cord_event_sensor_task_id='att_model_event_sensor1',
+    dag=dag_att
+)
+
+att_model_event_sensor2 = CORDModelSensor(
+    task_id='att_model_event_sensor2',
+    model_name='AttWorkflowDriverServiceInstance',
+    key_field='serialNumber',
+    controller_conn_id='local_cord_controller',
+    poke_interval=5,
+    dag=dag_att
+)
+
+att_model_event_handler2 = CORDModelOperator(
+    task_id='att_model_event_handler2',
+    python_callable=DriverService_event,
+    cord_event_sensor_task_id='att_model_event_sensor2',
+    dag=dag_att
+)
+
+att_model_event_sensor3 = CORDModelSensor(
+    task_id='att_model_event_sensor3',
+    model_name='AttWorkflowDriverServiceInstance',
+    key_field='serialNumber',
+    controller_conn_id='local_cord_controller',
+    poke_interval=5,
+    dag=dag_att
+)
+
+att_model_event_handler3 = CORDModelOperator(
+    task_id='att_model_event_handler3',
+    python_callable=DriverService_event,
+    cord_event_sensor_task_id='att_model_event_sensor3',
+    dag=dag_att
+)
+
+
+onu_event_sensor >> onu_event_handler >> att_model_event_sensor1 >> att_model_event_handler1 >> \
+    auth_event_sensor >> auth_event_handler >> att_model_event_sensor2 >> att_model_event_handler2 >> \
+    dhcp_event_sensor >> dhcp_event_handler >> att_model_event_sensor3 >> att_model_event_handler3