20
20
import proto
21
21
from google .auth import credentials as auth_credentials
22
22
23
- from google .cloud .aiplatform import base
24
23
from google .cloud .aiplatform import models
25
24
from google .cloud .aiplatform import utils
26
25
from google .cloud .aiplatform .compat .types import event as gca_event
27
26
from google .cloud .aiplatform .compat .types import execution as gca_execution
28
27
from google .cloud .aiplatform .compat .types import (
29
28
metadata_service as gca_metadata_service ,
30
29
)
30
+ from google .cloud .aiplatform .constants import base as base_constants
31
31
from google .cloud .aiplatform .metadata import artifact
32
32
from google .cloud .aiplatform .metadata import metadata_store
33
33
from google .cloud .aiplatform .metadata import resource
@@ -142,18 +142,110 @@ def create(
142
142
Execution: Instantiated representation of the managed Metadata Execution.
143
143
144
144
"""
145
- self = cls ._empty_constructor (
146
- project = project , location = location , credentials = credentials
145
+ # Add User Agent Header for metrics tracking if one is not specified
146
+ # If one is already specified this call was initiated by a sub class.
147
+ if not base_constants .USER_AGENT_SDK_COMMAND :
148
+ base_constants .USER_AGENT_SDK_COMMAND = (
149
+ "aiplatform.metadata.execution.Execution.create"
150
+ )
151
+
152
+ return cls ._create (
153
+ resource_id = resource_id ,
154
+ schema_title = schema_title ,
155
+ display_name = display_name ,
156
+ schema_version = schema_version ,
157
+ description = description ,
158
+ metadata = metadata ,
159
+ state = state ,
160
+ metadata_store_id = metadata_store_id ,
161
+ project = project ,
162
+ location = location ,
163
+ credentials = credentials ,
164
+ )
165
+
166
+ # TODO() refactor code to move _create to _Resource class.
167
+ @classmethod
168
+ def _create (
169
+ cls ,
170
+ schema_title : str ,
171
+ * ,
172
+ state : gca_execution .Execution .State = gca_execution .Execution .State .RUNNING ,
173
+ resource_id : Optional [str ] = None ,
174
+ display_name : Optional [str ] = None ,
175
+ schema_version : Optional [str ] = None ,
176
+ metadata : Optional [Dict [str , Any ]] = None ,
177
+ description : Optional [str ] = None ,
178
+ metadata_store_id : str = "default" ,
179
+ project : Optional [str ] = None ,
180
+ location : Optional [str ] = None ,
181
+ credentials = Optional [auth_credentials .Credentials ],
182
+ ) -> "Execution" :
183
+ """
184
+ Creates a new Metadata Execution.
185
+
186
+ Args:
187
+ schema_title (str):
188
+ Required. schema_title identifies the schema title used by the Execution.
189
+ state (gca_execution.Execution.State.RUNNING):
190
+ Optional. State of this Execution. Defaults to RUNNING.
191
+ resource_id (str):
192
+ Optional. The <resource_id> portion of the Execution name with
193
+ the format. This is globally unique in a metadataStore:
194
+ projects/123/locations/us-central1/metadataStores/<metadata_store_id>/executions/<resource_id>.
195
+ display_name (str):
196
+ Optional. The user-defined name of the Execution.
197
+ schema_version (str):
198
+ Optional. schema_version specifies the version used by the Execution.
199
+ If not set, defaults to use the latest version.
200
+ metadata (Dict):
201
+ Optional. Contains the metadata information that will be stored in the Execution.
202
+ description (str):
203
+ Optional. Describes the purpose of the Execution to be created.
204
+ metadata_store_id (str):
205
+ Optional. The <metadata_store_id> portion of the resource name with
206
+ the format:
207
+ projects/123/locations/us-central1/metadataStores/<metadata_store_id>/artifacts/<resource_id>
208
+ If not provided, the MetadataStore's ID will be set to "default".
209
+ project (str):
210
+ Optional. Project used to create this Execution. Overrides project set in
211
+ aiplatform.init.
212
+ location (str):
213
+ Optional. Location used to create this Execution. Overrides location set in
214
+ aiplatform.init.
215
+ credentials (auth_credentials.Credentials):
216
+ Optional. Custom credentials used to create this Execution. Overrides
217
+ credentials set in aiplatform.init.
218
+
219
+ Returns:
220
+ Execution: Instantiated representation of the managed Metadata Execution.
221
+
222
+ """
223
+ appended_user_agent = []
224
+ if base_constants .USER_AGENT_SDK_COMMAND :
225
+ appended_user_agent = [
226
+ f"sdk_command/{ base_constants .USER_AGENT_SDK_COMMAND } "
227
+ ]
228
+ # Reset the value for the USER_AGENT_SDK_COMMAND to avoid counting future unrelated api calls.
229
+ base_constants .USER_AGENT_SDK_COMMAND = ""
230
+
231
+ api_client = cls ._instantiate_client (
232
+ location = location ,
233
+ credentials = credentials ,
234
+ appended_user_agent = appended_user_agent ,
235
+ )
236
+
237
+ parent = utils .full_resource_name (
238
+ resource_name = metadata_store_id ,
239
+ resource_noun = metadata_store ._MetadataStore ._resource_noun ,
240
+ parse_resource_name_method = metadata_store ._MetadataStore ._parse_resource_name ,
241
+ format_resource_name_method = metadata_store ._MetadataStore ._format_resource_name ,
242
+ project = project ,
243
+ location = location ,
147
244
)
148
- super (base .VertexAiResourceNounWithFutureManager , self ).__init__ ()
149
245
150
246
resource = Execution ._create_resource (
151
- client = self .api_client ,
152
- parent = metadata_store ._MetadataStore ._format_resource_name (
153
- project = self .project ,
154
- location = self .location ,
155
- metadata_store = metadata_store_id ,
156
- ),
247
+ client = api_client ,
248
+ parent = parent ,
157
249
schema_title = schema_title ,
158
250
resource_id = resource_id ,
159
251
metadata = metadata ,
@@ -162,6 +254,9 @@ def create(
162
254
schema_version = schema_version ,
163
255
state = state ,
164
256
)
257
+ self = cls ._empty_constructor (
258
+ project = project , location = location , credentials = credentials
259
+ )
165
260
self ._gca_resource = resource
166
261
167
262
return self
0 commit comments