diff --git a/README.md b/README.md index 6fa6f852..e7ecf1cb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ # shipyard Directed acyclic graph controller for Kubernetes and OpenStack control plane life cycle management -## Testing 1 2 3 diff --git a/shipyard_airflow/README.md b/shipyard_airflow/README.md index 16bbfb3f..88496910 100644 --- a/shipyard_airflow/README.md +++ b/shipyard_airflow/README.md @@ -5,7 +5,7 @@ A python REST workflow orchestrator To run: ``` -$ virtualenv -p python2.7 /var/tmp/shipyard +$ virtualenv -p python3 /var/tmp/shipyard $ . /var/tmp/shipyard/bin/activate $ python setup.py install $ uwsgi --http :9000 -w shipyard_airflow.shipyard --callable shipyard -L diff --git a/shipyard_airflow/control/base.py b/shipyard_airflow/control/base.py index 94945f2b..05912178 100644 --- a/shipyard_airflow/control/base.py +++ b/shipyard_airflow/control/base.py @@ -11,10 +11,11 @@ # 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. -import falcon.request as request +import falcon, falcon.request as request import uuid import json -import ConfigParser +import configparser +import os class BaseResource(object): @@ -57,17 +58,23 @@ class BaseResource(object): resp.status = status_code # Get Config Data - def retrieve_config(self, resp, section="", variable=""): - config = ConfigParser.ConfigParser() + def retrieve_config(self, section="", data=""): # The current assumption is that shipyard.conf will be placed in a fixed path # within the shipyard container - Path TBD - config.read('/home/ubuntu/att-comdev/shipyard/shipyard_airflow/control/shipyard.conf') + path = '/home/ubuntu/att-comdev/shipyard/shipyard_airflow/control/shipyard.conf' + + # Check that shipyard.conf exists + if os.path.isfile(path): + config = configparser.ConfigParser() + config.read(path) - # Retrieve data from shipyard.conf - query_data = config.get(section, variable) + # Retrieve data from shipyard.conf + query_data = config.get(section, data) - return query_data + return query_data + else: + return 'Error - Missing Configuration File' class ShipyardRequestContext(object): diff --git a/shipyard_airflow/control/dag_runs.py b/shipyard_airflow/control/dag_runs.py index 4fcaca84..7a462d3d 100644 --- a/shipyard_airflow/control/dag_runs.py +++ b/shipyard_airflow/control/dag_runs.py @@ -23,20 +23,25 @@ class DagRunResource(BaseResource): def on_post(self, req, resp, dag_id, run_id=None, conf=None, execution_date=None): # Retrieve URL - web_server_url = self.retrieve_config(resp, 'BASE', 'WEB_SERVER') + web_server_url = self.retrieve_config('BASE', 'WEB_SERVER') - req_url = '{}/api/experimental/dags/{}/dag_runs'.format(web_server_url, dag_id) - - response = requests.post(req_url, - json={ - "run_id": run_id, - "conf": conf, - "execution_date": execution_date, - }) - - if response.ok: - resp.status = falcon.HTTP_200 - else: - self.return_error(resp, falcon.HTTP_400, 'Fail to Execute Dag') + if 'Error' in web_server_url: + resp.status = falcon.HTTP_400 + resp.body = json.dumps({'Error': 'Missing Configuration File'}) return + else: + req_url = '{}/api/experimental/dags/{}/dag_runs'.format(web_server_url, dag_id) + + response = requests.post(req_url, + json={ + "run_id": run_id, + "conf": conf, + "execution_date": execution_date, + }) + + if response.ok: + resp.status = falcon.HTTP_200 + else: + self.return_error(resp, falcon.HTTP_400, 'Fail to Execute Dag') + return diff --git a/shipyard_airflow/control/tasks.py b/shipyard_airflow/control/tasks.py index 4584c54c..9cb2f6e8 100644 --- a/shipyard_airflow/control/tasks.py +++ b/shipyard_airflow/control/tasks.py @@ -23,16 +23,21 @@ class TaskResource(BaseResource): def on_get(self, req, resp, dag_id, task_id): # Retrieve URL - web_server_url = self.retrieve_config(resp, 'BASE', 'WEB_SERVER') + web_server_url = self.retrieve_config('BASE', 'WEB_SERVER') - req_url = '{}/api/experimental/dags/{}/tasks/{}'.format(web_server_url, dag_id, task_id) - task_details = requests.get(req_url).json() - - if 'error' in task_details: + if 'Error' in web_server_url: resp.status = falcon.HTTP_400 - resp.body = json.dumps(task_details) + resp.body = json.dumps({'Error': 'Missing Configuration File'}) return else: - resp.status = falcon.HTTP_200 - resp.body = json.dumps(task_details) + req_url = '{}/api/experimental/dags/{}/tasks/{}'.format(web_server_url, dag_id, task_id) + task_details = requests.get(req_url).json() + + if 'error' in task_details: + resp.status = falcon.HTTP_400 + resp.body = json.dumps(task_details) + return + else: + resp.status = falcon.HTTP_200 + resp.body = json.dumps(task_details)