예제 #1
0
    def PatchAlpha(self, tensorboard_time_series_ref, args):
        """Update a Tensorboard time series."""
        tensorboard_time_series = (
            self.messages.GoogleCloudAiplatformV1alpha1TensorboardTimeSeries())
        update_mask = []

        if args.display_name is not None:
            tensorboard_time_series.displayName = args.display_name
            update_mask.append('display_name')

        if args.description is not None:
            tensorboard_time_series.description = args.description
            update_mask.append('description')

        if args.plugin_name is not None:
            tensorboard_time_series.pluginName = args.plugin_name
            update_mask.append('plugin_name')

        if args.plugin_data is not None:
            tensorboard_time_series.pluginData = bytes(args.plugin_data,
                                                       encoding='utf8')
            update_mask.append('plugin_data')

        if not update_mask:
            raise errors.NoFieldsSpecifiedError('No updates requested.')

        request = self.messages.AiplatformProjectsLocationsTensorboardsExperimentsRunsTimeSeriesPatchRequest(
            name=tensorboard_time_series_ref.RelativeName(),
            googleCloudAiplatformV1alpha1TensorboardTimeSeries=
            tensorboard_time_series,
            updateMask=','.join(update_mask))
        return self._service.Patch(request)
예제 #2
0
    def PatchAlpha(self, tensorboard_run_ref, args):
        """Update a Tensorboard run."""
        tensorboard_run = self.messages.GoogleCloudAiplatformV1alpha1TensorboardRun(
        )
        update_mask = []

        def GetLabels():
            return self.Get(tensorboard_run_ref).labels

        labels_update = labels_util.ProcessUpdateArgsLazy(
            args, self.messages.GoogleCloudAiplatformV1alpha1TensorboardRun.
            LabelsValue, GetLabels)
        if labels_update.needs_update:
            tensorboard_run.labels = labels_update.labels
            update_mask.append('labels')

        if args.display_name is not None:
            tensorboard_run.displayName = args.display_name
            update_mask.append('display_name')

        if args.description is not None:
            tensorboard_run.description = args.description
            update_mask.append('description')

        if not update_mask:
            raise errors.NoFieldsSpecifiedError('No updates requested.')

        request = self.messages.AiplatformProjectsLocationsTensorboardsExperimentsRunsPatchRequest(
            name=tensorboard_run_ref.RelativeName(),
            googleCloudAiplatformV1alpha1TensorboardRun=tensorboard_run,
            updateMask=','.join(update_mask))
        return self._service.Patch(request)
    def PatchBeta(self, index_endpoint_ref, args):
        """Update an index endpoint."""
        index_endpoint = self.messages.GoogleCloudAiplatformV1beta1IndexEndpoint(
        )
        update_mask = []

        if args.display_name is not None:
            index_endpoint.displayName = args.display_name
            update_mask.append('display_name')

        if args.description is not None:
            index_endpoint.description = args.description
            update_mask.append('description')

        def GetLabels():
            return self.Get(index_endpoint_ref).labels

        labels_update = labels_util.ProcessUpdateArgsLazy(
            args, self.messages.GoogleCloudAiplatformV1beta1IndexEndpoint.
            LabelsValue, GetLabels)
        if labels_update.needs_update:
            index_endpoint.labels = labels_update.labels
            update_mask.append('labels')

        if not update_mask:
            raise errors.NoFieldsSpecifiedError('No updates requested.')

        request = self.messages.AiplatformProjectsLocationsIndexEndpointsPatchRequest(
            name=index_endpoint_ref.RelativeName(),
            googleCloudAiplatformV1beta1IndexEndpoint=index_endpoint,
            updateMask=','.join(update_mask))
        return self._service.Patch(request)
예제 #4
0
    def PatchBeta(self, endpoint_ref, args):
        """Update a endpoint."""
        endpoint = self.messages.GoogleCloudAiplatformV1beta1Endpoint()
        update_mask = []

        def GetLabels():
            return self.Get(endpoint_ref).labels

        labels_update = labels_util.ProcessUpdateArgsLazy(
            args,
            self.messages.GoogleCloudAiplatformV1beta1Endpoint.LabelsValue,
            GetLabels)
        if labels_update.needs_update:
            endpoint.labels = labels_update.labels
            update_mask.append('labels')

        if args.display_name is not None:
            endpoint.displayName = args.display_name
            update_mask.append('display_name')

        if args.traffic_split is not None:
            additional_properties = []
            for key, value in sorted(args.traffic_split.items()):
                additional_properties.append(
                    endpoint.TrafficSplitValue().AdditionalProperty(
                        key=key, value=value))
            endpoint.trafficSplit = endpoint.TrafficSplitValue(
                additionalProperties=additional_properties)
            update_mask.append('traffic_split')

        if args.clear_traffic_split:
            endpoint.trafficSplit = None
            update_mask.append('traffic_split')

        if args.description is not None:
            endpoint.description = args.description
            update_mask.append('description')

        if not update_mask:
            raise errors.NoFieldsSpecifiedError('No updates requested.')

        req = self.messages.AiplatformProjectsLocationsEndpointsPatchRequest(
            name=endpoint_ref.RelativeName(),
            googleCloudAiplatformV1beta1Endpoint=endpoint,
            updateMask=','.join(update_mask))
        return self.client.projects_locations_endpoints.Patch(req)
예제 #5
0
  def Patch(self, tensorboard_ref, args):
    """Update a Tensorboard."""
    if self._version == constants.ALPHA_VERSION:
      tensorboard = self.messages.GoogleCloudAiplatformV1alpha1Tensorboard()
      labels_value = self.messages.GoogleCloudAiplatformV1alpha1Tensorboard.LabelsValue
    else:
      tensorboard = self.messages.GoogleCloudAiplatformV1beta1Tensorboard()
      labels_value = self.messages.GoogleCloudAiplatformV1beta1Tensorboard.LabelsValue

    update_mask = []

    def GetLabels():
      return self.Get(tensorboard_ref).labels

    labels_update = labels_util.ProcessUpdateArgsLazy(args, labels_value,
                                                      GetLabels)

    if labels_update.needs_update:
      tensorboard.labels = labels_update.labels
      update_mask.append('labels')

    if args.display_name is not None:
      tensorboard.displayName = args.display_name
      update_mask.append('display_name')

    if args.description is not None:
      tensorboard.description = args.description
      update_mask.append('description')

    if not update_mask:
      raise errors.NoFieldsSpecifiedError('No updates requested.')

    if self._version == constants.ALPHA_VERSION:
      req = self.messages.AiplatformProjectsLocationsTensorboardsPatchRequest(
          name=tensorboard_ref.RelativeName(),
          googleCloudAiplatformV1alpha1Tensorboard=tensorboard,
          updateMask=','.join(update_mask))
    else:
      req = self.messages.AiplatformProjectsLocationsTensorboardsPatchRequest(
          name=tensorboard_ref.RelativeName(),
          googleCloudAiplatformV1beta1Tensorboard=tensorboard,
          updateMask=','.join(update_mask))
    return self._service.Patch(req)
예제 #6
0
def Patch(args):
    """Update an instance config."""
    client = apis.GetClientInstance('spanner', 'v1')
    msgs = apis.GetMessagesModule('spanner', 'v1')
    ref = resources.REGISTRY.Parse(
        args.config,
        params={'projectsId': properties.VALUES.core.project.GetOrFail},
        collection='spanner.projects.instanceConfigs')
    instance_config = msgs.InstanceConfig(name=ref.RelativeName())

    update_mask = []

    if args.display_name is not None:
        instance_config.displayName = args.display_name
        update_mask.append('display_name')

    if args.etag is not None:
        instance_config.etag = args.etag

    def GetLabels():
        req = msgs.SpannerProjectsInstanceConfigsGetRequest(
            name=ref.RelativeName())
        return client.projects_instanceConfigs.Get(req).labels

    labels_update = labels_util.ProcessUpdateArgsLazy(
        args, msgs.InstanceConfig.LabelsValue, GetLabels)
    if labels_update.needs_update:
        instance_config.labels = labels_update.labels
        update_mask.append('labels')

    if not update_mask:
        raise errors.NoFieldsSpecifiedError('No updates requested.')

    req = msgs.SpannerProjectsInstanceConfigsPatchRequest(
        name=ref.RelativeName(),
        updateInstanceConfigRequest=msgs.UpdateInstanceConfigRequest(
            instanceConfig=instance_config,
            updateMask=','.join(update_mask),
            validateOnly=args.validate_only))
    return client.projects_instanceConfigs.Patch(req)
예제 #7
0
    def PatchBeta(self,
                  endpoint_ref,
                  labels_update,
                  display_name=None,
                  description=None,
                  traffic_split=None,
                  clear_traffic_split=False):
        """Updates an endpoint using v1beta1 API.

    Args:
      endpoint_ref: Resource, the parsed endpoint to be updated.
      labels_update: UpdateResult, the result of applying the label diff
        constructed from args.
      display_name: str or None, the new display name of the endpoint.
      description: str or None, the new description of the endpoint.
      traffic_split: dict or None, the new traffic split of the endpoint.
      clear_traffic_split: bool, whether or not clear traffic split of the
        endpoint.

    Returns:
      The response message of Patch.

    Raises:
      NoFieldsSpecifiedError: An error if no updates requested.
    """
        endpoint = self.messages.GoogleCloudAiplatformV1beta1Endpoint()
        update_mask = []

        if labels_update.needs_update:
            endpoint.labels = labels_update.labels
            update_mask.append('labels')

        if display_name is not None:
            endpoint.displayName = display_name
            update_mask.append('display_name')

        if traffic_split is not None:
            additional_properties = []
            for key, value in sorted(traffic_split.items()):
                additional_properties.append(
                    endpoint.TrafficSplitValue().AdditionalProperty(
                        key=key, value=value))
            endpoint.trafficSplit = endpoint.TrafficSplitValue(
                additionalProperties=additional_properties)
            update_mask.append('traffic_split')

        if clear_traffic_split:
            endpoint.trafficSplit = None
            update_mask.append('traffic_split')

        if description is not None:
            endpoint.description = description
            update_mask.append('description')

        if not update_mask:
            raise errors.NoFieldsSpecifiedError('No updates requested.')

        req = self.messages.AiplatformProjectsLocationsEndpointsPatchRequest(
            name=endpoint_ref.RelativeName(),
            googleCloudAiplatformV1beta1Endpoint=endpoint,
            updateMask=','.join(update_mask))
        return self.client.projects_locations_endpoints.Patch(req)
예제 #8
0
    def Patch(self, model_monitoring_job_ref, args):
        """Update a model deployment monitoring job."""
        model_monitoring_job_to_update = self.messages.GoogleCloudAiplatformV1beta1ModelDeploymentMonitoringJob(
        )
        update_mask = []

        job_spec = self.messages.GoogleCloudAiplatformV1beta1ModelDeploymentMonitoringJob(
        )
        if args.monitoring_config_from_file:
            data = yaml.load_path(args.monitoring_config_from_file)
            if data:
                job_spec = messages_util.DictToMessageWithErrorCheck(
                    data, self.messages.
                    GoogleCloudAiplatformV1beta1ModelDeploymentMonitoringJob)
                model_monitoring_job_to_update.modelDeploymentMonitoringObjectiveConfigs = job_spec.modelDeploymentMonitoringObjectiveConfigs
                update_mask.append(
                    'model_deployment_monitoring_objective_configs')

        if args.feature_thresholds:
            get_monitoring_job_req = self.messages.AiplatformProjectsLocationsModelDeploymentMonitoringJobsGetRequest(
                name=model_monitoring_job_ref.RelativeName())
            model_monitoring_job = self._service.Get(get_monitoring_job_req)
            model_monitoring_job_to_update.modelDeploymentMonitoringObjectiveConfigs = self._ConstructObjectiveConfigForUpdate(
                model_monitoring_job, args.feature_thresholds)
            update_mask.append('model_deployment_monitoring_objective_configs')

        if args.display_name:
            model_monitoring_job_to_update.displayName = args.display_name
            update_mask.append('display_name')

        if args.emails:
            model_monitoring_job_to_update.modelMonitoringAlertConfig = self.messages.GoogleCloudAiplatformV1beta1ModelMonitoringAlertConfig(
                emailAlertConfig=self.messages.
                GoogleCloudAiplatformV1beta1ModelMonitoringAlertConfigEmailAlertConfig(
                    userEmails=args.emails))
            update_mask.append('model_monitoring_alert_config')

        # sampling rate
        if args.prediction_sampling_rate:
            model_monitoring_job_to_update.loggingSamplingStrategy = self.messages.GoogleCloudAiplatformV1beta1SamplingStrategy(
                randomSampleConfig=self.messages.
                GoogleCloudAiplatformV1beta1SamplingStrategyRandomSampleConfig(
                    sampleRate=args.prediction_sampling_rate))
            update_mask.append('logging_sampling_strategy')

        # schedule
        if args.monitoring_frequency:
            model_monitoring_job_to_update.modelDeploymentMonitoringScheduleConfig = self.messages.GoogleCloudAiplatformV1beta1ModelDeploymentMonitoringScheduleConfig(
                monitorInterval='{}s'.format(
                    six.text_type(3600 * int(args.monitoring_frequency))))
            update_mask.append('model_deployment_monitoring_schedule_config')

        if args.analysis_instance_schema:
            model_monitoring_job_to_update.analysisInstanceSchemaUri = args.analysis_instance_schema
            update_mask.append('analysis_instance_schema_uri')

        if args.log_ttl:
            model_monitoring_job_to_update.logTtl = '{}s'.format(
                six.text_type(86400 * int(args.log_ttl)))
            update_mask.append('log_ttl')

        if not update_mask:
            raise errors.NoFieldsSpecifiedError('No updates requested.')

        req = self.messages.AiplatformProjectsLocationsModelDeploymentMonitoringJobsPatchRequest(
            name=model_monitoring_job_ref.RelativeName(),
            googleCloudAiplatformV1beta1ModelDeploymentMonitoringJob=
            model_monitoring_job_to_update,
            updateMask=','.join(update_mask))
        return self._service.Patch(req)