From 25eefbcfe1bccb82861749583d56f229953cdf7b Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 17 Jul 2019 11:33:31 -0700 Subject: [PATCH] versions work! --- products/mlengine/ansible.yaml | 8 ++++ products/mlengine/ansible_version_added.yaml | 34 +++++++++++++++ products/mlengine/api.yaml | 38 ++++++++++++++++- .../mlengine/examples/ansible/version.yaml | 41 +++++++++++++++++++ .../mlengine/helpers/ansible/model_decoder.py | 3 +- 5 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 products/mlengine/examples/ansible/version.yaml diff --git a/products/mlengine/ansible.yaml b/products/mlengine/ansible.yaml index a754df4ad0ec..6211040539e4 100644 --- a/products/mlengine/ansible.yaml +++ b/products/mlengine/ansible.yaml @@ -17,12 +17,20 @@ datasources: !ruby/object:Overrides::ResourceOverrides Model: !ruby/object:Overrides::Ansible::ResourceOverride facts: !ruby/object:Provider::Ansible::FactsOverride has_filters: false + Version: !ruby/object:Overrides::Ansible::ResourceOverride + facts: !ruby/object:Provider::Ansible::FactsOverride + has_filters: false overrides: !ruby/object:Overrides::ResourceOverrides Model: !ruby/object:Overrides::Ansible::ResourceOverride transport: !ruby/object:Overrides::Ansible::Transport decoder: decode_response provider_helpers: - products/mlengine/helpers/ansible/model_decoder.py + Version: !ruby/object:Overrides::Ansible::ResourceOverride + transport: !ruby/object:Overrides::Ansible::Transport + decoder: decode_response + provider_helpers: + - products/mlengine/helpers/ansible/model_decoder.py files: !ruby/object:Provider::Config::Files resource: <%= lines(indent(compile('provider/ansible/resource~compile.yaml'), 4)) -%> diff --git a/products/mlengine/ansible_version_added.yaml b/products/mlengine/ansible_version_added.yaml index bbf219ddd5c1..86ef82eab608 100644 --- a/products/mlengine/ansible_version_added.yaml +++ b/products/mlengine/ansible_version_added.yaml @@ -2,6 +2,8 @@ :facts: :Model: :version_added: '2.9' + :Version: + :version_added: '2.9' :regular: :Model: :version_added: '2.9' @@ -21,3 +23,35 @@ :version_added: '2.9' :labels: :version_added: '2.9' + :Version: + :version_added: '2.9' + :name: + :version_added: '2.9' + :description: + :version_added: '2.9' + :deploymentUri: + :version_added: '2.9' + :runtimeVersion: + :version_added: '2.9' + :machineType: + :version_added: '2.9' + :labels: + :version_added: '2.9' + :framework: + :version_added: '2.9' + :pythonVersion: + :version_added: '2.9' + :serviceAccount: + :version_added: '2.9' + :autoScaling: + :version_added: '2.9' + :minNodes: + :version_added: '2.9' + :manualScaling: + :version_added: '2.9' + :nodes: + :version_added: '2.9' + :predictionClass: + :version_added: '2.9' + :model: + :version_added: '2.9' diff --git a/products/mlengine/api.yaml b/products/mlengine/api.yaml index 5407884eeed8..9cd4f13c0de3 100644 --- a/products/mlengine/api.yaml +++ b/products/mlengine/api.yaml @@ -31,6 +31,24 @@ objects: self_link: projects/{{project}}/models/{{name}} # This resources is not updatable (outside of versions, which is a version-level method) input: true + async: !ruby/object:Api::Async + actions: ['delete'] + operation: !ruby/object:Api::Async::Operation + path: 'name' + base_url: '{{op_id}}' + wait_ms: 1000 + result: !ruby/object:Api::Async::Result + path: 'response' + resource_inside_response: true + status: !ruby/object:Api::Async::Status + path: 'done' + complete: True + allowed: + - True + - False + error: !ruby/object:Api::Async::Error + path: 'error' + message: 'message' description: | Represents a machine learning solution. @@ -81,12 +99,30 @@ objects: description: | Each version is a trained model deployed in the cloud, ready to handle prediction requests. A model can have multiple versions + async: !ruby/object:Api::Async + operation: !ruby/object:Api::Async::Operation + path: 'name' + base_url: '{{op_id}}' + wait_ms: 1000 + result: !ruby/object:Api::Async::Result + path: 'response' + resource_inside_response: true + status: !ruby/object:Api::Async::Status + path: 'done' + complete: True + allowed: + - True + - False + error: !ruby/object:Api::Async::Error + path: 'error' + message: 'message' parameters: - !ruby/object:Api::Type::ResourceRef name: 'model' description: The model that this version belongs to resource: Model imports: name + required: true properties: - !ruby/object:Api::Type::String name: 'name' @@ -115,7 +151,7 @@ objects: - !ruby/object:Api::Type::Time name: 'lastUseTime' description: The time the version was last used for prediction. - output: ture + output: true - !ruby/object:Api::Type::String name: 'runtimeVersion' description: The AI Platform runtime version to use for this deployment diff --git a/products/mlengine/examples/ansible/version.yaml b/products/mlengine/examples/ansible/version.yaml new file mode 100644 index 000000000000..9b17b715e047 --- /dev/null +++ b/products/mlengine/examples/ansible/version.yaml @@ -0,0 +1,41 @@ +# Copyright 2017 Google Inc. +# 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. +--- !ruby/object:Provider::Ansible::Example +task: !ruby/object:Provider::Ansible::Task + name: gcp_mlengine_version + code: + # ML Engine doesn't like dashes, which ansible's test name + # generator uses. + name: "{{ resource_name | replace('-', '_') }}" + model: "{{ model }}" + runtime_version: 1.13 + python_version: 3.5 + deployment_uri: gs://ansible-cloudml-bucket/ + project: <%= ctx[:project] %> + auth_kind: <%= ctx[:auth_kind] %> + service_account_file: <%= ctx[:service_account_file] %> + +dependencies: + - !ruby/object:Provider::Ansible::Task + name: gcp_mlengine_model + code: + name: <%= dependency_name('model', 'version').gsub('-', '_') %> + description: 'My model' + regions: + - 'us-central1' + online_prediction_logging: true + online_prediction_console_logging: true + project: <%= ctx[:project] %> + auth_kind: <%= ctx[:auth_kind] %> + service_account_file: <%= ctx[:service_account_file] %> + register: model diff --git a/products/mlengine/helpers/ansible/model_decoder.py b/products/mlengine/helpers/ansible/model_decoder.py index 925568b58fc7..028f39fcdef3 100644 --- a/products/mlengine/helpers/ansible/model_decoder.py +++ b/products/mlengine/helpers/ansible/model_decoder.py @@ -14,5 +14,6 @@ # Short names are given (and expected) by the API # but are returned as full names. def decode_response(response, module): - response['name'] = response['name'].split('/')[-1] + if 'name' in response and 'metadata' not in response: + response['name'] = response['name'].split('/')[-1] return response