예제 #1
0
    def _get_and_validate_project_location(
        self,
        resource_name: str,
        project: Optional[str] = None,
        location: Optional[str] = None,
    ) -> Tuple:

        """Validate the project and location for the resource.

        Args:
            resource_name(str): Required. A fully-qualified resource name or ID.
            project(str): Project of the resource noun.
            location(str): The location of the resource noun.

        Raises:
            RuntimeError if location is different from resource location
        """

        if not project and not location:
            return project, location

        fields = utils.extract_fields_from_resource_name(
            resource_name, self._resource_noun
        )
        if not fields:
            return project, location

        if location and fields.location != location:
            raise RuntimeError(
                f"location {location} is provided, but different from "
                f"the resource location {fields.location}"
            )

        return fields.project, fields.location
예제 #2
0
def custom_job_tensorboard_console_uri(tensorboard_resource_name: str,
                                       custom_job_resource_name: str) -> str:
    """Helper method to create console uri to tensorboard from custom job resource."""
    # projects+40556267596+locations+us-central1+tensorboards+740208820004847616+experiments+2214368039829241856
    fields = utils.extract_fields_from_resource_name(tensorboard_resource_name)
    experiment_resource_name = f"{tensorboard_resource_name}/experiments/{custom_job_resource_name.split('/')[-1]}"
    uri_experiment_resource_name = experiment_resource_name.replace("/", "+")
    return f"https://{fields.location}.tensorboard.googleusercontent.com/experiment/{uri_experiment_resource_name}"
예제 #3
0
def test_extract_fields_from_resource_name_with_extracted_fields(
    generated_resource_name: str, generated_resource_fields: utils.Fields
):
    """Verify fields extracted from resource name match the original fields"""

    assert (
        utils.extract_fields_from_resource_name(resource_name=generated_resource_name)
        == generated_resource_fields
    )
예제 #4
0
def test_extract_fields_from_resource_name_with_resource_noun(
    resource_name: str, resource_noun: str, expected: bool
):
    assert (
        bool(
            utils.extract_fields_from_resource_name(
                resource_name=resource_name, resource_noun=resource_noun
            )
        )
        == expected
    )
예제 #5
0
 def _dashboard_uri(self) -> Optional[str]:
     """Helper method to compose the dashboard uri where job can be viewed."""
     fields = utils.extract_fields_from_resource_name(self.resource_name)
     url = f"https://console.cloud.google.com/ai/platform/locations/{fields.location}/{self._job_type}/{fields.id}?project={fields.project}"
     return url
예제 #6
0
def test_extract_fields_from_resource_name(resource_name: str, expected: bool):
    # Given a resource name and expected validity, test extract_fields_from_resource_name()
    assert expected == bool(utils.extract_fields_from_resource_name(resource_name))
예제 #7
0
def custom_job_console_uri(custom_job_resource_name: str) -> str:
    """Helper method to create console uri from custom job resource name."""
    fields = utils.extract_fields_from_resource_name(custom_job_resource_name)
    return f"https://console.cloud.google.com/ai/platform/locations/{fields.location}/training/{fields.id}?project={fields.project}"
예제 #8
0
 def _dashboard_uri(self) -> str:
     """Helper method to compose the dashboard uri where pipeline can be
     viewed."""
     fields = utils.extract_fields_from_resource_name(self.resource_name)
     url = f"https://console.cloud.google.com/vertex-ai/locations/{fields.location}/pipelines/runs/{fields.id}?project={fields.project}"
     return url