-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add scheduled pipelines client system test.
fix: Remove Schedule read mask because ListSchedules does not support it. PiperOrigin-RevId: 539819661
- Loading branch information
1 parent
69c5f60
commit 1fda417
Showing
4 changed files
with
100 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright 2023 Google LLC | ||
# | ||
# 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 google.cloud import aiplatform | ||
from google.cloud.aiplatform.compat.types import schedule_v1beta1 as gca_schedule | ||
from google.cloud.aiplatform.preview.pipelinejobschedule import pipeline_job_schedules | ||
from tests.system.aiplatform import e2e_base | ||
|
||
from kfp import components | ||
from kfp.v2 import compiler | ||
|
||
import pytest | ||
from google.protobuf.json_format import MessageToDict | ||
|
||
|
||
@pytest.mark.usefixtures( | ||
"tear_down_resources", "prepare_staging_bucket", "delete_staging_bucket" | ||
) | ||
class TestPreviewPipelineJobSchedule(e2e_base.TestEndToEnd): | ||
_temp_prefix = "tmpvrtxsdk-e2e-pjs" | ||
|
||
def test_create_get_list(self, shared_state): | ||
# Components: | ||
def train( | ||
number_of_epochs: int, | ||
learning_rate: float, | ||
): | ||
print(f"number_of_epochs={number_of_epochs}") | ||
print(f"learning_rate={learning_rate}") | ||
|
||
train_op = components.create_component_from_func(train) | ||
|
||
# Pipeline: | ||
def training_pipeline(number_of_epochs: int = 2): | ||
train_op( | ||
number_of_epochs=number_of_epochs, | ||
learning_rate="0.1", | ||
) | ||
|
||
# Creating the pipeline job schedule. | ||
aiplatform.init( | ||
project=e2e_base._PROJECT, | ||
location=e2e_base._LOCATION, | ||
) | ||
|
||
ir_file = "pipeline.json" | ||
compiler.Compiler().compile( | ||
pipeline_func=training_pipeline, | ||
package_path=ir_file, | ||
pipeline_name="training-pipeline", | ||
) | ||
job = aiplatform.PipelineJob( | ||
template_path=ir_file, | ||
display_name="display_name", | ||
) | ||
|
||
pipeline_job_schedule = pipeline_job_schedules.PipelineJobSchedule( | ||
pipeline_job=job, display_name="pipeline_job_schedule_display_name" | ||
) | ||
|
||
pipeline_job_schedule.create(cron_expression="*/2 * * * *", max_run_count=2) | ||
|
||
shared_state.setdefault("resources", []).append(pipeline_job_schedule) | ||
|
||
pipeline_job_schedule.pause() | ||
assert pipeline_job_schedule.state == gca_schedule.Schedule.State.PAUSED | ||
|
||
pipeline_job_schedule.resume() | ||
assert pipeline_job_schedule.state == gca_schedule.Schedule.State.ACTIVE | ||
|
||
pipeline_job_schedule.wait() | ||
|
||
list_jobs_with_read_mask = pipeline_job_schedule.list_jobs( | ||
enable_simple_view=True | ||
) | ||
list_jobs_without_read_mask = pipeline_job_schedule.list_jobs() | ||
|
||
# enable_simple_view=True should apply the `read_mask` filter to limit PipelineJob fields returned | ||
assert "serviceAccount" in MessageToDict( | ||
list_jobs_without_read_mask[0].gca_resource._pb | ||
) | ||
assert "serviceAccount" not in MessageToDict( | ||
list_jobs_with_read_mask[0].gca_resource._pb | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters