Beispiel #1
0
    def execute(self, context: 'Context'):
        hook = EndpointServiceHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            impersonation_chain=self.impersonation_chain,
        )

        try:
            self.log.info("Get endpoint: %s", self.endpoint_id)
            endpoint_obj = hook.get_endpoint(
                project_id=self.project_id,
                region=self.region,
                endpoint=self.endpoint_id,
                retry=self.retry,
                timeout=self.timeout,
                metadata=self.metadata,
            )
            VertexAIEndpointLink.persist(context=context,
                                         task_instance=self,
                                         endpoint_id=self.endpoint_id)
            self.log.info("Endpoint was gotten.")
            return Endpoint.to_dict(endpoint_obj)
        except NotFound:
            self.log.info("The Endpoint ID %s does not exist.",
                          self.endpoint_id)
Beispiel #2
0
    def execute(self, context: 'Context'):
        hook = EndpointServiceHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            impersonation_chain=self.impersonation_chain,
        )

        self.log.info("Deploying model")
        operation = hook.deploy_model(
            project_id=self.project_id,
            region=self.region,
            endpoint=self.endpoint_id,
            deployed_model=self.deployed_model,
            traffic_split=self.traffic_split,
            retry=self.retry,
            timeout=self.timeout,
            metadata=self.metadata,
        )
        result = hook.wait_for_operation(timeout=self.timeout,
                                         operation=operation)

        deploy_model = endpoint_service.DeployModelResponse.to_dict(result)
        deployed_model_id = hook.extract_deployed_model_id(deploy_model)
        self.log.info("Model was deployed. Deployed Model ID: %s",
                      deployed_model_id)

        self.xcom_push(context,
                       key="deployed_model_id",
                       value=deployed_model_id)
        VertexAIModelLink.persist(context=context,
                                  task_instance=self,
                                  model_id=deployed_model_id)
        return deploy_model
Beispiel #3
0
    def execute(self, context: 'Context'):
        hook = EndpointServiceHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            impersonation_chain=self.impersonation_chain,
        )

        self.log.info("Creating endpoint")
        operation = hook.create_endpoint(
            project_id=self.project_id,
            region=self.region,
            endpoint=self.endpoint,
            endpoint_id=self.endpoint_id,
            retry=self.retry,
            timeout=self.timeout,
            metadata=self.metadata,
        )
        result = hook.wait_for_operation(timeout=self.timeout,
                                         operation=operation)

        endpoint = Endpoint.to_dict(result)
        endpoint_id = hook.extract_endpoint_id(endpoint)
        self.log.info("Endpoint was created. Endpoint ID: %s", endpoint_id)

        self.xcom_push(context, key="endpoint_id", value=endpoint_id)
        VertexAIEndpointLink.persist(context=context,
                                     task_instance=self,
                                     endpoint_id=endpoint_id)
        return endpoint
Beispiel #4
0
    def execute(self, context: 'Context'):
        hook = EndpointServiceHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            impersonation_chain=self.impersonation_chain,
        )

        self.log.info(f"Removing a DeployedModel {self.deployed_model_id}")
        operation = hook.undeploy_model(
            project_id=self.project_id,
            region=self.region,
            endpoint=self.endpoint_id,
            deployed_model_id=self.deployed_model_id,
            traffic_split=self.traffic_split,
            retry=self.retry,
            timeout=self.timeout,
            metadata=self.metadata,
        )
        hook.wait_for_operation(timeout=self.timeout, operation=operation)
        self.log.info("DeployedModel was removed successfully")
Beispiel #5
0
 def execute(self, context: 'Context'):
     hook = EndpointServiceHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         impersonation_chain=self.impersonation_chain,
     )
     results = hook.list_endpoints(
         project_id=self.project_id,
         region=self.region,
         filter=self.filter,
         page_size=self.page_size,
         page_token=self.page_token,
         read_mask=self.read_mask,
         order_by=self.order_by,
         retry=self.retry,
         timeout=self.timeout,
         metadata=self.metadata,
     )
     VertexAIEndpointListLink.persist(context=context, task_instance=self)
     return [Endpoint.to_dict(result) for result in results]
Beispiel #6
0
 def execute(self, context: 'Context'):
     hook = EndpointServiceHook(
         gcp_conn_id=self.gcp_conn_id,
         delegate_to=self.delegate_to,
         impersonation_chain=self.impersonation_chain,
     )
     self.log.info("Updating endpoint: %s", self.endpoint_id)
     result = hook.update_endpoint(
         project_id=self.project_id,
         region=self.region,
         endpoint_id=self.endpoint_id,
         endpoint=self.endpoint,
         update_mask=self.update_mask,
         retry=self.retry,
         timeout=self.timeout,
         metadata=self.metadata,
     )
     self.log.info("Endpoint was updated")
     VertexAIEndpointLink.persist(context=context,
                                  task_instance=self,
                                  endpoint_id=self.endpoint_id)
     return Endpoint.to_dict(result)
Beispiel #7
0
    def execute(self, context: 'Context'):
        hook = EndpointServiceHook(
            gcp_conn_id=self.gcp_conn_id,
            delegate_to=self.delegate_to,
            impersonation_chain=self.impersonation_chain,
        )

        try:
            self.log.info("Deleting endpoint: %s", self.endpoint_id)
            operation = hook.delete_endpoint(
                project_id=self.project_id,
                region=self.region,
                endpoint=self.endpoint_id,
                retry=self.retry,
                timeout=self.timeout,
                metadata=self.metadata,
            )
            hook.wait_for_operation(timeout=self.timeout, operation=operation)
            self.log.info("Endpoint was deleted.")
        except NotFound:
            self.log.info("The Endpoint ID %s does not exist.",
                          self.endpoint_id)