예제 #1
0
    def config_file_with_type_util(self, connect):
        PROJECT_NAME = verta._internal_utils._utils.generate_default_name()
        DATASET_NAME = verta._internal_utils._utils.generate_default_name()
        EXPERIMENT_NAME = verta._internal_utils._utils.generate_default_name()
        CONFIG_FILENAME = "verta_config.json"

        HOST_KEY, EMAIL_KEY, DEV_KEY_KEY = "VERTA_HOST", "VERTA_EMAIL", "VERTA_DEV_KEY"

        HOST, EMAIL, DEV_KEY = os.environ[HOST_KEY], os.environ[EMAIL_KEY], os.environ[DEV_KEY_KEY]
        try:
            del os.environ[HOST_KEY], os.environ[EMAIL_KEY], os.environ[DEV_KEY_KEY]

            try:
                with open(CONFIG_FILENAME, 'w') as f:
                    json.dump(
                        {
                            'host': HOST,
                            'email': EMAIL, 'dev_key': DEV_KEY,
                            'project': PROJECT_NAME,
                            'experiment': EXPERIMENT_NAME,
                            'dataset': DATASET_NAME,
                        },
                        f,
                    )

                client = verta.Client(_connect=connect)
                conn = client._conn

                back_end_url = urlparse(HOST)
                socket = back_end_url.netloc + back_end_url.path.rstrip('/')

                assert conn.socket == socket
                assert conn.auth['Grpc-Metadata-email'] == EMAIL
                assert conn.auth['Grpc-Metadata-developer_key'] == DEV_KEY

                if connect:
                    try:
                        assert client.set_experiment_run()
                        assert client.proj.name == PROJECT_NAME
                        assert client.expt.name == EXPERIMENT_NAME
                    finally:
                        if client.proj is not None:
                            client.proj.delete()
                    dataset = client.set_dataset()
                    try:
                        assert dataset.name == DATASET_NAME
                    finally:
                        dataset.delete()
                else:
                    assert client._set_from_config_if_none(None, "project") == PROJECT_NAME
                    assert client._set_from_config_if_none(None, "experiment") == EXPERIMENT_NAME
                    assert client._set_from_config_if_none(None, "dataset") == DATASET_NAME

            finally:
                if os.path.exists(CONFIG_FILENAME):
                    os.remove(CONFIG_FILENAME)
        finally:
            os.environ[HOST_KEY], os.environ[EMAIL_KEY], os.environ[DEV_KEY_KEY] = HOST, EMAIL, DEV_KEY
예제 #2
0
    def update(
        self,
        model_reference,
        strategy=None,
        wait=False,
        resources=None,
        autoscaling=None,
        env_vars=None,
        kafka_settings=None,
    ):
        """
        Update the endpoint with a model logged in an Experiment Run or a Model Version.

        .. versionadded:: 0.19.0
            The `kafka_settings` parameter.

        Parameters
        ----------
        model_reference : :class:`~verta.tracking.entities.ExperimentRun` or :class:`~verta.registry.entities.RegisteredModelVersion` or :class:`~verta.endpoint.Build`
            An Experiment Run, Model Version with a model logged, or a Build.
        strategy : :mod:`~verta.endpoint.update`, default DirectUpdateStrategy()
            Strategy (direct or canary) for updating the endpoint.
        wait : bool, default False
            Whether to wait for the endpoint to finish updating before returning.
        resources : :class:`~verta.endpoint.resources.Resources`, optional
            Resources allowed for the updated endpoint.
        autoscaling : :class:`~verta.endpoint.autoscaling.Autoscaling`, optional
            Autoscaling condition for the updated endpoint.
        env_vars : dict of str to str, optional
            Environment variables.
        kafka_settings : :class:`verta.endpoint.KafkaSettings` or False, optional
            Kafka settings. If ``False``, clears this endpoint's existing Kafka
            settings.

        Returns
        -------
        status : dict of str to {None, bool, float, int, str, list, dict}

        """
        if not isinstance(model_reference,
                          (RegisteredModelVersion, ExperimentRun, Build)):
            raise TypeError(
                "`model_reference` must be an ExperimentRun, RegisteredModelVersion, or Build"
            )

        if not strategy:
            strategy = DirectUpdateStrategy()

        update_body = self._create_update_body(strategy, resources,
                                               autoscaling, env_vars)

        self._update_kafka_settings(kafka_settings)

        if isinstance(model_reference, Build):
            update_body["build_id"] = model_reference.id
        else:
            # create new build
            build = self._create_build(model_reference)
            update_body["build_id"] = build.id

        ret = self._update_from_build(update_body, wait)
        if isinstance(model_reference, RegisteredModelVersion):
            model_version = model_reference

            try:
                # TODO: make exception catching more specific
                local_path = model_version._get_artifact_msg(
                    "reference_data").path
            except:
                return ret
            bucket = urlparse(
                model_version._get_url_for_artifact(
                    "reference_data", "GET").url).hostname.split('.')[0]
            conn = self._conn
            url = "{}://{}/api/v1/monitoring/ingest/reference/endpoint/{}".format(
                conn.scheme, conn.socket, self.id)
            ingestRequest = {"bucket": bucket, "path": local_path}
            response = _utils.make_request("POST",
                                           url,
                                           conn,
                                           json=ingestRequest)
            _utils.raise_for_http_error(response)
        return ret