From b7b36a6d96a545147541336b1780fbd1bbe6883e Mon Sep 17 00:00:00 2001 From: HR Wu <5631010+heiruwu@users.noreply.github.com> Date: Fri, 18 Aug 2023 19:50:19 +0800 Subject: [PATCH] refactor(controller): remove most dependencies from controller (#405) Because - reduce dependency cycle between `controller-model` and `model-backend` This commit - remove resource updating from `model-backend` to `controller-model` to avoid api calls cycle - update public deploy/undeploy methods to change the desire state only, and let `controller-model` handle the actual deployment request - update integration-test regarding to the deploy/undeploy public methods --- go.mod | 2 +- go.sum | 4 +- integration-test/grpc.js | 3 +- integration-test/grpc_create_model.js | 4 +- integration-test/grpc_deploy_model.js | 4 +- integration-test/grpc_deploy_model_private.js | 12 ++ integration-test/grpc_infer_model.js | 8 +- integration-test/grpc_publish_model.js | 13 +- integration-test/grpc_query_model.js | 38 +++++- integration-test/grpc_query_model_private.js | 25 +++- integration-test/grpc_update_model.js | 13 +- .../proto/model/model/v1alpha/model.proto | 10 +- integration-test/rest.js | 3 +- integration-test/rest_create_model.js | 63 +++++++++ .../rest_create_model_with_jwt.js | 26 ++++ integration-test/rest_deploy_model.js | 54 ++++---- integration-test/rest_infer_github_model.js | 40 +----- integration-test/rest_infer_model.js | 84 +++--------- .../rest_longrunning_operation.js | 42 +++--- integration-test/rest_model_card.js | 26 ++++ integration-test/rest_model_card_with_jwt.js | 13 ++ integration-test/rest_publish_model.js | 14 ++ .../rest_publish_model_with_jwt.js | 13 ++ integration-test/rest_query_model.js | 42 ++++++ integration-test/rest_query_model_private.js | 42 ++++++ integration-test/rest_query_model_with_jwt.js | 26 ++++ integration-test/rest_update_model.js | 14 ++ .../rest_update_model_with_jwt.js | 13 ++ pkg/handler/private_handler.go | 42 ++---- pkg/handler/public_handler.go | 122 +++--------------- pkg/service/service.go | 35 ++--- pkg/service/worker.go | 49 ++++--- pkg/worker/model.go | 92 +------------ 33 files changed, 551 insertions(+), 440 deletions(-) diff --git a/go.mod b/go.mod index 8ce266d7..760685e8 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 github.com/iancoleman/strcase v0.2.0 - github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230801085304-c9e30fb0f220 + github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230818082151-fe5c9357e125 github.com/instill-ai/usage-client v0.2.4-alpha github.com/instill-ai/x v0.3.0-alpha github.com/knadh/koanf v1.4.4 diff --git a/go.sum b/go.sum index caf7bf4d..82d2ea85 100644 --- a/go.sum +++ b/go.sum @@ -1305,8 +1305,8 @@ github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230801085304-c9e30fb0f220 h1:moXVYUrVc8N4TFNVykVCiW5Ens2EzI09GhyuNV6F3u4= -github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230801085304-c9e30fb0f220/go.mod h1:qsq5ecnA1xi2rLnVQFo/9xksA7I7wQu8c7rqM5xbIrQ= +github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230818082151-fe5c9357e125 h1:T8ey9xcT9gSkd675d1XdOgC5KEFB/TxW/dMbVUHqMEk= +github.com/instill-ai/protogen-go v0.3.3-alpha.0.20230818082151-fe5c9357e125/go.mod h1:qsq5ecnA1xi2rLnVQFo/9xksA7I7wQu8c7rqM5xbIrQ= github.com/instill-ai/usage-client v0.2.4-alpha h1:mYXd62eZsmGKBlzwMcdEgTBgn8zlbagYUHro6+p50c8= github.com/instill-ai/usage-client v0.2.4-alpha/go.mod h1:BMxgyr02sqH6SeITXSV4M1ewwvfklzXIc5yzIqaN0c8= github.com/instill-ai/x v0.3.0-alpha h1:z9fedROOG2dVHhswBfVwU/hzHuq8/JKSUON7inF+FH8= diff --git a/integration-test/grpc.js b/integration-test/grpc.js index e9d7117e..4f4a5203 100644 --- a/integration-test/grpc.js +++ b/integration-test/grpc.js @@ -54,7 +54,8 @@ export default () => { queryModelPrivate.ListModels() queryModelPrivate.LookUpModel() deployModelPrivate.CheckModel() - deployModelPrivate.DeployUndeployModel() + // private deploy will be triggered by public deploy + // deployModelPrivate.DeployUndeployModel() } // Create model API diff --git a/integration-test/grpc_create_model.js b/integration-test/grpc_create_model.js index 84cc6e1d..3970f5c0 100644 --- a/integration-test/grpc_create_model.js +++ b/integration-test/grpc_create_model.js @@ -71,9 +71,7 @@ export function CreateModel() { } check(client.invoke('model.model.v1alpha.ModelPublicService/DeployModel', req, {}), { 'DeployModel status': (r) => r && r.status === grpc.StatusOK, - 'DeployModel operation name': (r) => r && r.message.operation.name !== undefined, - 'DeployModel operation metadata': (r) => r && r.message.operation.metadata === null, - 'DeployModel operation done': (r) => r && r.message.operation.done === false, + 'DeployModel model name': (r) => r && r.message.modelId === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) diff --git a/integration-test/grpc_deploy_model.js b/integration-test/grpc_deploy_model.js index c062f1c4..8f47530f 100644 --- a/integration-test/grpc_deploy_model.js +++ b/integration-test/grpc_deploy_model.js @@ -68,9 +68,7 @@ export function DeployUndeployModel() { } check(client.invoke('model.model.v1alpha.ModelPublicService/DeployModel', req, {}), { 'DeployModel status': (r) => r && r.status === grpc.StatusOK, - 'DeployModel operation name': (r) => r && r.message.operation.name !== undefined, - 'DeployModel operation metadata': (r) => r && r.message.operation.metadata === null, - 'DeployModel operation done': (r) => r && r.message.operation.done === false, + 'DeployModel model name': (r) => r && r.message.modelId === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) diff --git a/integration-test/grpc_deploy_model_private.js b/integration-test/grpc_deploy_model_private.js index 734aafe5..555ad933 100644 --- a/integration-test/grpc_deploy_model_private.js +++ b/integration-test/grpc_deploy_model_private.js @@ -90,6 +90,18 @@ export function CheckModel() { }, {}), { 'CheckModelAdmin uuid length is invalid': (r) => r && r.status === grpc.StatusInvalidArgument, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = publicClient.invoke('model.model.v1alpha.ModelPublicService/WatchModel', { + name: `models/${model_id}` + }, {}) + if (res.message.state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } check(publicClient.invoke('model.model.v1alpha.ModelPublicService/DeleteModel', { name: "models/" + model_id }), { diff --git a/integration-test/grpc_infer_model.js b/integration-test/grpc_infer_model.js index fa8b45c6..4df53fe4 100644 --- a/integration-test/grpc_infer_model.js +++ b/integration-test/grpc_infer_model.js @@ -69,9 +69,7 @@ export function InferModel() { } check(client.invoke('model.model.v1alpha.ModelPublicService/DeployModel', req, {}), { 'DeployModel status': (r) => r && r.status === grpc.StatusOK, - 'DeployModel operation name': (r) => r && r.message.operation.name !== undefined, - 'DeployModel operation metadata': (r) => r && r.message.operation.metadata === null, - 'DeployModel operation done': (r) => r && r.message.operation.done === false, + 'DeployModel model name': (r) => r && r.message.modelId === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) @@ -181,9 +179,7 @@ export function InferModel() { } check(client.invoke('model.model.v1alpha.ModelPublicService/DeployModel', req, {}), { 'DeployModel status': (r) => r && r.status === grpc.StatusOK, - 'DeployModel operation name': (r) => r && r.message.operation.name !== undefined, - 'DeployModel operation metadata': (r) => r && r.message.operation.metadata === null, - 'DeployModel operation done': (r) => r && r.message.operation.done === false, + 'DeployModel model name': (r) => r && r.message.modelId === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) diff --git a/integration-test/grpc_publish_model.js b/integration-test/grpc_publish_model.js index 7fc50527..dda09d7b 100644 --- a/integration-test/grpc_publish_model.js +++ b/integration-test/grpc_publish_model.js @@ -110,7 +110,18 @@ export function PublishUnPublishModel() { }), { "UnpublishModel response not found status": (r) => r.status === grpc.StatusNotFound, }); - + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = client.invoke('model.model.v1alpha.ModelPublicService/WatchModel', { + name: `models/${model_id}` + }, {}) + if (res.message.state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } check(client.invoke('model.model.v1alpha.ModelPublicService/DeleteModel', { name: "models/" + model_id }), { diff --git a/integration-test/grpc_query_model.js b/integration-test/grpc_query_model.js index d3cd8f73..eaf4bc00 100644 --- a/integration-test/grpc_query_model.js +++ b/integration-test/grpc_query_model.js @@ -85,7 +85,18 @@ export function GetModel() { }, {}), { 'GetModel non-existed model status not found': (r) => r && r.status === grpc.StatusNotFound, }); - + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = client.invoke('model.model.v1alpha.ModelPublicService/WatchModel', { + name: `models/${model_id}` + }, {}) + if (res.message.state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } check(client.invoke('model.model.v1alpha.ModelPublicService/DeleteModel', { name: "models/" + model_id }), { @@ -149,7 +160,18 @@ export function ListModels() { "ListModels response models[0].create_time": (r) => r.message.models[0].createTime !== undefined, "ListModels response models[0].update_time": (r) => r.message.models[0].updateTime !== undefined, }); - + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = client.invoke('model.model.v1alpha.ModelPublicService/WatchModel', { + name: `models/${model_id}` + }, {}) + if (res.message.state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } check(client.invoke('model.model.v1alpha.ModelPublicService/DeleteModel', { name: "models/" + model_id }), { @@ -221,6 +243,18 @@ export function LookupModel() { }, {}), { 'LookUpModel non-existed model status not found': (r) => r && r.status === grpc.StatusInvalidArgument, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = client.invoke('model.model.v1alpha.ModelPublicService/WatchModel', { + name: `models/${model_id}` + }, {}) + if (res.message.state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } check(client.invoke('model.model.v1alpha.ModelPublicService/DeleteModel', { name: "models/" + model_id }), { diff --git a/integration-test/grpc_query_model_private.js b/integration-test/grpc_query_model_private.js index a425c00f..929b6b4b 100644 --- a/integration-test/grpc_query_model_private.js +++ b/integration-test/grpc_query_model_private.js @@ -88,7 +88,18 @@ export function ListModels() { "ListModelsAdmin response models[0].create_time": (r) => r.message.models[0].createTime !== undefined, "ListModelsAdmin response models[0].update_time": (r) => r.message.models[0].updateTime !== undefined, }); - + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = publicClient.invoke('model.model.v1alpha.ModelPublicService/WatchModel', { + name: `models/${model_id}` + }, {}) + if (res.message.state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } check(publicClient.invoke('model.model.v1alpha.ModelPublicService/DeleteModel', { name: "models/" + model_id }), { @@ -167,6 +178,18 @@ export function LookUpModel() { }, {}), { 'LookUpModelAdmin non-existed model status not found': (r) => r && r.status === grpc.StatusInvalidArgument, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = publicClient.invoke('model.model.v1alpha.ModelPublicService/WatchModel', { + name: `models/${model_id}` + }, {}) + if (res.message.state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } check(publicClient.invoke('model.model.v1alpha.ModelPublicService/DeleteModel', { name: "models/" + model_id }), { diff --git a/integration-test/grpc_update_model.js b/integration-test/grpc_update_model.js index 656e79ef..5d701b7b 100644 --- a/integration-test/grpc_update_model.js +++ b/integration-test/grpc_update_model.js @@ -84,7 +84,18 @@ export function UpdateModel() { "UpdateModel response model.create_time": (r) => r.message.model.createTime !== undefined, "UpdateModel response model.update_time": (r) => r.message.model.updateTime !== undefined, }); - + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = client.invoke('model.model.v1alpha.ModelPublicService/WatchModel', { + name: `models/${model_id}` + }, {}) + if (res.message.state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } check(client.invoke('model.model.v1alpha.ModelPublicService/DeleteModel', { name: "models/" + model_id }), { diff --git a/integration-test/proto/model/model/v1alpha/model.proto b/integration-test/proto/model/model/v1alpha/model.proto index ac49f2a5..9195baf4 100644 --- a/integration-test/proto/model/model/v1alpha/model.proto +++ b/integration-test/proto/model/model/v1alpha/model.proto @@ -340,8 +340,9 @@ message DeployModelRequest { // DeployModelResponse represents a response for a deployed model message DeployModelResponse { - // Deploy operation message - google.longrunning.Operation operation = 1; + // Deployed model's id + // Format: models/{model} + string model_id = 1; } // UndeployModelRequest represents a request to undeploy a model to offline @@ -357,8 +358,9 @@ message UndeployModelRequest { // UndeployModelResponse represents a response for a undeployed model message UndeployModelResponse { - // Undeploy operation message - google.longrunning.Operation operation = 1; + // Undeployed model's id + // Format: models/{model} + string model_id = 1; } // GetModelCardRequest represents a request to query a model's README card diff --git a/integration-test/rest.js b/integration-test/rest.js index 69051029..f4879218 100644 --- a/integration-test/rest.js +++ b/integration-test/rest.js @@ -50,7 +50,8 @@ export default function (data) { if (!constant.apiGatewayMode) { queryModelPrivate.ListModelsAdmin() queryModelPrivate.LookupModelAdmin() - deployModelPrivate.DeployUndeployModel() + // private deploy will be trigger by public deploy + // deployModelPrivate.DeployUndeployModel() } // Infer Model API diff --git a/integration-test/rest_create_model.js b/integration-test/rest_create_model.js index ec2b4164..900386c5 100644 --- a/integration-test/rest_create_model.js +++ b/integration-test/rest_create_model.js @@ -169,6 +169,31 @@ export function CreateModelFromLocal() { r.status === 409, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res_cls = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_cls}/watch`, { + headers: genHeader(`application/json`), + }) + let res_det = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_det}/watch`, { + headers: genHeader(`application/json`), + }) + let res_keypoint = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_keypoint}/watch`, { + headers: genHeader(`application/json`), + }) + let res_unspecified = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_unspecified}/watch`, { + headers: genHeader(`application/json`), + }) + if (res_cls.json().state !== "STATE_UNSPECIFIED" && + res_det.json().state !== "STATE_UNSPECIFIED" && + res_keypoint.json().state !== "STATE_UNSPECIFIED" && + res_unspecified.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id_cls}`, null, { headers: genHeader(`application/json`), @@ -281,6 +306,31 @@ export function CreateModelFromLocal() { r.status === 400, }); + let currentTime = new Date().getTime(); + let timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res_cls = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_cls}/watch`, { + headers: genHeader(`application/json`), + }) + let res_det = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_det}/watch`, { + headers: genHeader(`application/json`), + }) + let res_keypoint = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_keypoint}/watch`, { + headers: genHeader(`application/json`), + }) + let res_unspecified = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_unspecified}/watch`, { + headers: genHeader(`application/json`), + }) + if (res_cls.json().state !== "STATE_UNSPECIFIED" && + res_det.json().state !== "STATE_UNSPECIFIED" && + res_keypoint.json().state !== "STATE_UNSPECIFIED" && + res_unspecified.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id_cls}`, null, { headers: genHeader(`application/json`), @@ -388,6 +438,19 @@ export function CreateModelFromGitHub() { r.status === 400, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeader(`application/json`), diff --git a/integration-test/rest_create_model_with_jwt.js b/integration-test/rest_create_model_with_jwt.js index b84135e0..dc368636 100644 --- a/integration-test/rest_create_model_with_jwt.js +++ b/integration-test/rest_create_model_with_jwt.js @@ -70,6 +70,19 @@ export function CreateModelFromLocal() { currentTime = new Date().getTime(); } + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeaderwithJwtSub(`application/json`, uuidv4()), @@ -147,6 +160,19 @@ export function CreateModelFromGitHub() { currentTime = new Date().getTime(); } + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeaderwithJwtSub(`application/json`, uuidv4()), diff --git a/integration-test/rest_deploy_model.js b/integration-test/rest_deploy_model.js index 8a029ee0..a98bf893 100644 --- a/integration-test/rest_deploy_model.js +++ b/integration-test/rest_deploy_model.js @@ -59,14 +59,8 @@ export function DeployUndeployModel() { }), { [`POST /v1alpha/models/${model_id}/deploy online task cls response status`]: (r) => r.status === 200, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.response`]: (r) => - r.json().operation.response !== undefined, + [`POST /v1alpha/models/${model_id}/deploy online task cls response mode ID`]: (r) => + r.json().model_id === model_id }); check(http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}`, { @@ -78,6 +72,19 @@ export function DeployUndeployModel() { r.json().model.state === "STATE_ONLINE", }) + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state === "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + check(http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { headers: genHeader(`application/json`), }), { @@ -115,13 +122,7 @@ export function DeployUndeployModel() { [`POST /v1alpha/models/${model_id}/undeploy online task cls response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/undeploy online task cls response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/undeploy online task cls response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/undeploy online task cls response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/undeploy online task cls response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); check(http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}`, { @@ -152,16 +153,23 @@ export function DeployUndeployModel() { }), { [`POST /v1alpha/models/${model_id}/deploy online task cls response status`]: (r) => r.status === 200, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.response`]: (r) => - r.json().operation.response !== undefined, + [`POST /v1alpha/models/${model_id}/deploy online task cls response model ID`]: (r) => + r.json().model_id === model_id }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state === "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + check(http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { headers: genHeader(`application/json`), }), { diff --git a/integration-test/rest_infer_github_model.js b/integration-test/rest_infer_github_model.js index a7e16348..0145fc50 100644 --- a/integration-test/rest_infer_github_model.js +++ b/integration-test/rest_infer_github_model.js @@ -64,13 +64,7 @@ export function InferGitHubModel() { [`POST /v1alpha/models/${model_id}/deploy online task cls response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model instance state being updated in 1 hours. Some GitHub models is huge. @@ -333,13 +327,7 @@ export function InferGitHubModel() { [`POST /v1alpha/models/${model_id}/deploy online task cls response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model instance state being updated in 1 hours. Some GitHub models is huge. @@ -602,13 +590,7 @@ export function InferGitHubModel() { [`POST /v1alpha/models/${model_id}/deploy online task det response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task det response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task det response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task det response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task det response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model instance state being updated in 1 hour @@ -1010,13 +992,7 @@ export function InferGitHubModel() { [`POST /v1alpha/models/${model_id}/deploy online task det response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task det response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task det response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task det response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task det response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model instance state being updated in 1 hour @@ -1418,13 +1394,7 @@ export function InferGitHubModel() { [`POST /v1alpha/models/${model_id}/deploy online task keypoint response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task keypoint response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task keypoint response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task keypoint response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task keypoint response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model instance state being updated in 1 hours. Some GitHub models is huge. diff --git a/integration-test/rest_infer_model.js b/integration-test/rest_infer_model.js index a62901c2..7789815c 100644 --- a/integration-test/rest_infer_model.js +++ b/integration-test/rest_infer_model.js @@ -62,13 +62,7 @@ export function InferModel() { [`POST /v1alpha/models/${model_id}/deploy online task cls response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) @@ -331,13 +325,7 @@ export function InferModel() { [`POST /v1alpha/models/${model_id}/deploy online task det response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task det response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task det response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task det response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task det response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) @@ -740,13 +728,7 @@ export function InferModel() { [`POST /v1alpha/models/${model_id}/deploy online task unspecified response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task unspecified response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task unspecified response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task unspecified response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task unspecified response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) @@ -1066,13 +1048,7 @@ export function InferModel() { [`POST /v1alpha/models/${model_id}/deploy online task keypoint response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task keypoint response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task keypoint response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task keypoint response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task keypoint response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) @@ -1442,13 +1418,7 @@ export function InferModel() { [`POST /v1alpha/models/${model_id}/deploy online task det empty response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task det empty response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task det empty response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task det empty response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task det empty response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) @@ -1814,13 +1784,7 @@ export function InferModel() { [`POST /v1alpha/models/${model_id}/deploy online task semantic response status`]: (r) => r.status === 200, [`POST /v1alpha/models/${model_id}/deploy online task semantic response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task semantic response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task semantic response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task semantic response operation.response`]: (r) => - r.json().operation.response !== undefined, + r.json().model_id === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) @@ -2107,16 +2071,10 @@ export function InferModel() { check(http.post(`${constant.apiPublicHost}/v1alpha/models/${model_id}/deploy`, {}, { headers: genHeader(`application/json`), }), { - [`POST /v1alpha/models/${model_id}/deploy online task response status`]: (r) => + [`POST /v1alpha/models/${model_id}/deploy online task semantic response status`]: (r) => r.status === 200, - [`POST /v1alpha/models/${model_id}/deploy online task response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task response operation.response`]: (r) => - r.json().operation.response !== undefined, + [`POST /v1alpha/models/${model_id}/deploy online task semantic response operation.name`]: (r) => + r.json().model_id === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) @@ -2539,16 +2497,10 @@ export function InferModel() { check(http.post(`${constant.apiPublicHost}/v1alpha/models/${model_id}/deploy`, {}, { headers: genHeader(`application/json`), }), { - [`POST /v1alpha/models/${model_id}/deploy online task text to image response status`]: (r) => + [`POST /v1alpha/models/${model_id}/deploy online task semantic response status`]: (r) => r.status === 200, - [`POST /v1alpha/models/${model_id}/deploy online task text to image response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task text to image response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task text to image response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task text to image response operation.response`]: (r) => - r.json().operation.response !== undefined, + [`POST /v1alpha/models/${model_id}/deploy online task semantic response operation.name`]: (r) => + r.json().model_id === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) @@ -2775,16 +2727,10 @@ export function InferModel() { check(http.post(`${constant.apiPublicHost}/v1alpha/models/${model_id}/deploy`, {}, { headers: genHeader(`application/json`), }), { - [`POST /v1alpha/models/${model_id}/deploy online task text generation response status`]: (r) => + [`POST /v1alpha/models/${model_id}/deploy online task semantic response status`]: (r) => r.status === 200, - [`POST /v1alpha/models/${model_id}/deploy online task text generation response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task text generation response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task text generation response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task text generation response operation.response`]: (r) => - r.json().operation.response !== undefined, + [`POST /v1alpha/models/${model_id}/deploy online task semantic response operation.name`]: (r) => + r.json().model_id === model_id }); // Check the model state being updated in 120 secs (in integration test, model is dummy model without download time but in real use case, time will be longer) diff --git a/integration-test/rest_longrunning_operation.js b/integration-test/rest_longrunning_operation.js index 54cf8c23..378f46b2 100644 --- a/integration-test/rest_longrunning_operation.js +++ b/integration-test/rest_longrunning_operation.js @@ -54,41 +54,24 @@ export function GetLongRunningOperation() { currentTime = new Date().getTime(); } + // TODO: public endpoint of deploy/undeploy is not longrunning anymore, need test revise + let operationRes = http.post(`${constant.apiPublicHost}/v1alpha/models/${model_id}/deploy`, {}, { headers: genHeader(`application/json`), }) check(operationRes, { - [`POST /v1alpha/models/${model_id}/deploy online task cls response status`]: (r) => + [`POST /v1alpha/models/${model_id}/deploy online task semantic response status`]: (r) => r.status === 200, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.done`]: (r) => - r.json().operation.done === false, - [`POST /v1alpha/models/${model_id}/deploy online task cls response operation.response`]: (r) => - r.json().operation.response !== undefined, + [`POST /v1alpha/models/${model_id}/deploy online task semantic response operation.name`]: (r) => + r.json().model_id === model_id }); sleep(1) // take time to execute in Temporal - check(http.get(`${constant.apiPublicHost}/v1alpha/${operationRes.json().operation.name}`, {}, { - headers: genHeader(`application/json`), - }), { - [`GET v1alpha/${operationRes.json().operation.name} response status`]: (r) => - r.status === 200, - [`GET v1alpha/${operationRes.json().operation.name} response operation.name`]: (r) => - r.json().operation.name !== undefined, - [`GET v1alpha/${operationRes.json().operation.name} response operation.metadata`]: (r) => - r.json().operation.metadata === null, - [`GET v1alpha/${operationRes.json().operation.name} response operation.done`]: (r) => - r.json().operation.done !== undefined, - }); - // Check the model state being updated in 120 secs currentTime = new Date().getTime(); timeoutTime = new Date().getTime() + 120000; while (timeoutTime > currentTime) { - var res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { headers: genHeader(`application/json`), }) if (res.json().state === "STATE_UNSPECIFIED") { @@ -98,6 +81,19 @@ export function GetLongRunningOperation() { currentTime = new Date().getTime(); } + // check(http.get(`${constant.apiPublicHost}/v1alpha/${operationRes.json().operation.name}`, {}, { + // headers: genHeader(`application/json`), + // }), { + // [`GET v1alpha/${operationRes.json().operation.name} response status`]: (r) => + // r.status === 200, + // [`GET v1alpha/${operationRes.json().operation.name} response operation.name`]: (r) => + // r.json().operation.name !== undefined, + // [`GET v1alpha/${operationRes.json().operation.name} response operation.metadata`]: (r) => + // r.json().operation.metadata === null, + // [`GET v1alpha/${operationRes.json().operation.name} response operation.done`]: (r) => + // r.json().operation.done !== undefined, + // }); + // model can only be deleted after operation done while (timeoutTime > currentTime) { var res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { diff --git a/integration-test/rest_model_card.js b/integration-test/rest_model_card.js index fb552e68..0bc502b4 100644 --- a/integration-test/rest_model_card.js +++ b/integration-test/rest_model_card.js @@ -70,6 +70,19 @@ export function GetModelCard() { r.json().readme.content !== undefined, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeader(`application/json`), @@ -128,6 +141,19 @@ export function GetModelCard() { r.json().readme.content === "", }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeader(`application/json`), diff --git a/integration-test/rest_model_card_with_jwt.js b/integration-test/rest_model_card_with_jwt.js index 7b5a4050..47a8752c 100644 --- a/integration-test/rest_model_card_with_jwt.js +++ b/integration-test/rest_model_card_with_jwt.js @@ -69,6 +69,19 @@ export function GetModelCard() { r.status === 200, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeaderwithJwtSub(`application/json`, userUid), diff --git a/integration-test/rest_publish_model.js b/integration-test/rest_publish_model.js index 6299fd33..7820f807 100644 --- a/integration-test/rest_publish_model.js +++ b/integration-test/rest_publish_model.js @@ -120,6 +120,20 @@ export function PublishUnpublishModel() { }), { [`POST /v1alpha/models/${model_id}/unpublish task cls response not found status`]: (r) => r.status === 404, }); + + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeader(`application/json`), diff --git a/integration-test/rest_publish_model_with_jwt.js b/integration-test/rest_publish_model_with_jwt.js index a1093528..dc9b28e1 100644 --- a/integration-test/rest_publish_model_with_jwt.js +++ b/integration-test/rest_publish_model_with_jwt.js @@ -82,6 +82,19 @@ export function PublishUnpublishModel() { r.status === 200, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeaderwithJwtSub(`application/json`, userUid), diff --git a/integration-test/rest_query_model.js b/integration-test/rest_query_model.js index 13883cf5..16e9fb1b 100644 --- a/integration-test/rest_query_model.js +++ b/integration-test/rest_query_model.js @@ -117,6 +117,19 @@ export function GetModel() { r.json().model.update_time !== undefined, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeader(`application/json`), @@ -339,6 +352,22 @@ export function ListModels() { r.json().models[1].update_time !== undefined, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res_1 = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_1}/watch`, { + headers: genHeader(`application/json`), + }) + let res_2 = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_2}/watch`, { + headers: genHeader(`application/json`), + }) + if (res_1.json().state !== "STATE_UNSPECIFIED" && res_2.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id_1}`, null, { headers: genHeader(`application/json`), @@ -455,6 +484,19 @@ export function LookupModel() { r.json().model.update_time !== undefined, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeader(`application/json`), diff --git a/integration-test/rest_query_model_private.js b/integration-test/rest_query_model_private.js index 4c2c5fa0..1935163f 100644 --- a/integration-test/rest_query_model_private.js +++ b/integration-test/rest_query_model_private.js @@ -228,6 +228,22 @@ export function ListModelsAdmin() { r.json().models[1].update_time !== undefined, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res_1 = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_1}/watch`, { + headers: genHeader(`application/json`), + }) + let res_2 = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id_2}/watch`, { + headers: genHeader(`application/json`), + }) + if (res_1.json().state !== "STATE_UNSPECIFIED" && res_2.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id_1}`, null, { headers: genHeader(`application/json`), @@ -347,6 +363,32 @@ export function LookupModelAdmin() { r.json().model.update_time !== undefined, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeader(`application/json`), diff --git a/integration-test/rest_query_model_with_jwt.js b/integration-test/rest_query_model_with_jwt.js index 49f80da6..768bb482 100644 --- a/integration-test/rest_query_model_with_jwt.js +++ b/integration-test/rest_query_model_with_jwt.js @@ -80,6 +80,19 @@ export function GetModel() { r.status === 200, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeaderwithJwtSub(`application/json`, userUid), @@ -215,6 +228,19 @@ export function LookupModel() { r.status === 200, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeaderwithJwtSub(`application/json`, userUid), diff --git a/integration-test/rest_update_model.js b/integration-test/rest_update_model.js index 3291d861..344e3327 100644 --- a/integration-test/rest_update_model.js +++ b/integration-test/rest_update_model.js @@ -123,6 +123,20 @@ export function UpdateModel() { [`PATCH /v1alpha/models/${model_id} task cls description empty response model.update_time`]: (r) => r.json().model.update_time !== undefined, }); + + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeader(`application/json`), diff --git a/integration-test/rest_update_model_with_jwt.js b/integration-test/rest_update_model_with_jwt.js index 13366156..49124abe 100644 --- a/integration-test/rest_update_model_with_jwt.js +++ b/integration-test/rest_update_model_with_jwt.js @@ -74,6 +74,19 @@ export function UpdateModel() { r.status === 200, }); + currentTime = new Date().getTime(); + timeoutTime = new Date().getTime() + 120000; + while (timeoutTime > currentTime) { + let res = http.get(`${constant.apiPublicHost}/v1alpha/models/${model_id}/watch`, { + headers: genHeader(`application/json`), + }) + if (res.json().state !== "STATE_UNSPECIFIED") { + break + } + sleep(1) + currentTime = new Date().getTime(); + } + // clean up check(http.request("DELETE", `${constant.apiPublicHost}/v1alpha/models/${model_id}`, null, { headers: genHeaderwithJwtSub(`application/json`, userUid), diff --git a/pkg/handler/private_handler.go b/pkg/handler/private_handler.go index 49269057..71adec81 100644 --- a/pkg/handler/private_handler.go +++ b/pkg/handler/private_handler.go @@ -161,21 +161,19 @@ func (h *PrivateHandler) DeployModelAdmin(ctx context.Context, req *modelPB.Depl wfID := strings.Split(resp.Operation.Name, "/")[1] - if err := h.service.UpdateResourceState( - ctx, - dbModel.UID, - modelPB.Model_STATE_UNSPECIFIED, - nil, - &wfID, - ); err != nil { - return &modelPB.DeployModelAdminResponse{}, err - } - + var operation *longrunningpb.Operation done := false for !done { - operation, _ := h.service.GetOperation(ctx, wfID) - done = operation.Done time.Sleep(time.Second) + operation, err = h.service.GetOperation(ctx, wfID) + if err != nil { + return &modelPB.DeployModelAdminResponse{}, status.Errorf(codes.Internal, "get model create operation error") + } + done = operation.Done + } + + if operation.GetError() != nil { + return &modelPB.DeployModelAdminResponse{}, status.Errorf(codes.Internal, "model create operation error") } } @@ -212,16 +210,6 @@ func (h *PrivateHandler) DeployModelAdmin(ctx context.Context, req *modelPB.Depl return &modelPB.DeployModelAdminResponse{}, st.Err() } - if err := h.service.UpdateResourceState( - ctx, - dbModel.UID, - modelPB.Model_STATE_UNSPECIFIED, - nil, - &wfID, - ); err != nil { - return &modelPB.DeployModelAdminResponse{}, err - } - return &modelPB.DeployModelAdminResponse{Operation: &longrunningpb.Operation{ Name: fmt.Sprintf("operations/%s", wfID), Done: false, @@ -252,16 +240,6 @@ func (h *PrivateHandler) UndeployModelAdmin(ctx context.Context, req *modelPB.Un return &modelPB.UndeployModelAdminResponse{}, err } - if err := h.service.UpdateResourceState( - ctx, - dbModel.UID, - modelPB.Model_STATE_UNSPECIFIED, - nil, - &wfId, - ); err != nil { - return &modelPB.UndeployModelAdminResponse{}, err - } - return &modelPB.UndeployModelAdminResponse{Operation: &longrunningpb.Operation{ Name: fmt.Sprintf("operations/%s", wfId), Done: false, diff --git a/pkg/handler/public_handler.go b/pkg/handler/public_handler.go index 1e3ef010..aa1d914f 100644 --- a/pkg/handler/public_handler.go +++ b/pkg/handler/public_handler.go @@ -1839,7 +1839,7 @@ func (h *PublicHandler) UpdateModel(ctx context.Context, req *modelPB.UpdateMode func (h *PublicHandler) DeleteModel(ctx context.Context, req *modelPB.DeleteModelRequest) (*modelPB.DeleteModelResponse, error) { - eventName := "UpdateModel" + eventName := "DeleteModel" ctx, span := tracer.Start(ctx, eventName, trace.WithSpanKind(trace.SpanKindServer)) @@ -2034,6 +2034,10 @@ func (h *PublicHandler) DeployModel(ctx context.Context, req *modelPB.DeployMode eventName := "DeployModel" + // block for controller to update the state + ctx, cancel := context.WithTimeout(ctx, 4*time.Second) + defer cancel() + ctx, span := tracer.Start(ctx, eventName, trace.WithSpanKind(trace.SpanKindServer)) defer span.End() @@ -2065,17 +2069,6 @@ func (h *PublicHandler) DeployModel(ctx context.Context, req *modelPB.DeployMode return &modelPB.DeployModelResponse{}, status.Errorf(codes.Unauthenticated, "Unauthorized") } - state, err := h.service.GetResourceState(ctx, dbModel.UID) - if err != nil { - span.SetStatus(1, err.Error()) - return &modelPB.DeployModelResponse{}, err - } - - if *state != modelPB.Model_STATE_OFFLINE { - return &modelPB.DeployModelResponse{}, - status.Error(codes.FailedPrecondition, fmt.Sprintf("Deploy model only work with offline model state, current model state is %s", state)) - } - _, err = h.service.GetTritonModels(ctx, dbModel.UID) if err != nil { span.SetStatus(1, err.Error()) @@ -2087,43 +2080,12 @@ func (h *PublicHandler) DeployModel(ctx context.Context, req *modelPB.DeployMode return &modelPB.DeployModelResponse{}, err } - wfId, err := h.service.DeployModelAsync(ctx, ownerPermalink, dbModel.UID) - if err != nil { - st, e := sterr.CreateErrorResourceInfo( - codes.Internal, - fmt.Sprintf("[handler] deploy a model error: %s", err.Error()), - "triton-inference-server", - "deploy model", - "", - err.Error(), - ) - if strings.Contains(err.Error(), "Failed to allocate memory") { - st, e = sterr.CreateErrorResourceInfo( - codes.ResourceExhausted, - "[handler] deploy model error", - "triton-inference-server", - "Out of memory for deploying the model to triton server, maybe try with smaller batch size", - "", - err.Error(), - ) - } - - if e != nil { - logger.Error(e.Error()) + state := modelPB.Model_STATE_OFFLINE.Enum() + for state.String() == modelPB.Model_STATE_OFFLINE.String() { + if state, err = h.service.GetResourceState(ctx, dbModel.UID); err != nil { + return &modelPB.DeployModelResponse{}, err } - span.SetStatus(1, st.Err().Error()) - return &modelPB.DeployModelResponse{}, st.Err() - } - - if err := h.service.UpdateResourceState( - ctx, - dbModel.UID, - modelPB.Model_STATE_UNSPECIFIED, - nil, - &wfId, - ); err != nil { - span.SetStatus(1, err.Error()) - return &modelPB.DeployModelResponse{}, err + time.Sleep(100 * time.Millisecond) } logger.Info(string(custom_otel.NewLogMessage( @@ -2133,26 +2095,19 @@ func (h *PublicHandler) DeployModel(ctx context.Context, req *modelPB.DeployMode eventName, custom_otel.SetEventResource(dbModel), custom_otel.SetEventMessage(fmt.Sprintf("%s done", eventName)), - custom_otel.SetEventResult(&longrunningpb.Operation_Response{ - Response: &anypb.Any{ - Value: []byte(wfId), - }, - }), ))) - return &modelPB.DeployModelResponse{Operation: &longrunningpb.Operation{ - Name: fmt.Sprintf("operations/%s", wfId), - Done: false, - Result: &longrunningpb.Operation_Response{ - Response: &anypb.Any{}, - }, - }}, nil + return &modelPB.DeployModelResponse{ModelId: dbModel.ID}, nil } func (h *PublicHandler) UndeployModel(ctx context.Context, req *modelPB.UndeployModelRequest) (*modelPB.UndeployModelResponse, error) { eventName := "UndeployModel" + // block for controller to update the state + ctx, cancel := context.WithTimeout(ctx, 4*time.Second) + defer cancel() + ctx, span := tracer.Start(ctx, eventName, trace.WithSpanKind(trace.SpanKindServer)) defer span.End() @@ -2184,47 +2139,23 @@ func (h *PublicHandler) UndeployModel(ctx context.Context, req *modelPB.Undeploy return &modelPB.UndeployModelResponse{}, status.Errorf(codes.Unauthenticated, "Unauthorized") } - state, err := h.service.GetResourceState(ctx, dbModel.UID) - if err != nil { span.SetStatus(1, err.Error()) return &modelPB.UndeployModelResponse{}, err } - if *state != modelPB.Model_STATE_ONLINE { - span.SetStatus(1, fmt.Sprintf("undeploy model only work with online model instance state, current model state is %s", - state)) - return &modelPB.UndeployModelResponse{}, - status.Error(codes.FailedPrecondition, fmt.Sprintf("undeploy model only work with online model instance state, current model state is %s", - state)) - } - // set user desired state to STATE_OFFLINE if _, err := h.service.UpdateModelState(ctx, dbModel.UID, &dbModel, datamodel.ModelState(modelPB.Model_STATE_OFFLINE)); err != nil { span.SetStatus(1, err.Error()) return &modelPB.UndeployModelResponse{}, err } - wfId, err := h.service.UndeployModelAsync(ctx, ownerPermalink, dbModel.UID) - if err != nil { - // Manually set the custom header to have a StatusUnprocessableEntity http response for REST endpoint - if err := grpc.SetHeader(ctx, metadata.Pairs("x-http-code", strconv.Itoa(http.StatusUnprocessableEntity))); err != nil { - span.SetStatus(1, err.Error()) - return &modelPB.UndeployModelResponse{}, status.Errorf(codes.Internal, err.Error()) + state := modelPB.Model_STATE_ONLINE.Enum() + for state.String() == modelPB.Model_STATE_ONLINE.String() { + if state, err = h.service.GetResourceState(ctx, dbModel.UID); err != nil { + return &modelPB.UndeployModelResponse{}, err } - span.SetStatus(1, err.Error()) - return &modelPB.UndeployModelResponse{}, err - } - - if err := h.service.UpdateResourceState( - ctx, - dbModel.UID, - modelPB.Model_STATE_UNSPECIFIED, - nil, - &wfId, - ); err != nil { - span.SetStatus(1, err.Error()) - return &modelPB.UndeployModelResponse{}, err + time.Sleep(100 * time.Millisecond) } logger.Info(string(custom_otel.NewLogMessage( @@ -2234,20 +2165,9 @@ func (h *PublicHandler) UndeployModel(ctx context.Context, req *modelPB.Undeploy eventName, custom_otel.SetEventResource(dbModel), custom_otel.SetEventMessage(fmt.Sprintf("%s done", eventName)), - custom_otel.SetEventResult(&longrunningpb.Operation_Response{ - Response: &anypb.Any{ - Value: []byte(wfId), - }, - }), ))) - return &modelPB.UndeployModelResponse{Operation: &longrunningpb.Operation{ - Name: fmt.Sprintf("operations/%s", wfId), - Done: false, - Result: &longrunningpb.Operation_Response{ - Response: &anypb.Any{}, - }, - }}, nil + return &modelPB.UndeployModelResponse{ModelId: dbModel.ID}, nil } func (h *PublicHandler) WatchModel(ctx context.Context, req *modelPB.WatchModelRequest) (*modelPB.WatchModelResponse, error) { diff --git a/pkg/service/service.go b/pkg/service/service.go index 5efd19b7..793e05d7 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -8,6 +8,7 @@ import ( "path/filepath" "strconv" "strings" + "time" "cloud.google.com/go/longrunning/autogen/longrunningpb" "github.com/go-redis/redis/v9" @@ -117,6 +118,7 @@ func (s *service) GetMgmtPrivateServiceClient() mgmtPB.MgmtPrivateServiceClient return s.mgmtPrivateServiceClient } +// TODO: determine the necessity of this block of codes // func (s *service) DeployModel(modelUID uuid.UUID) error { // var tEnsembleModel datamodel.TritonModel // var err error @@ -145,26 +147,13 @@ func (s *service) GetMgmtPrivateServiceClient() mgmtPB.MgmtPrivateServiceClient func (s *service) UndeployModel(ctx context.Context, modelUID uuid.UUID) error { - var tritonModels []datamodel.TritonModel + // var tritonModels []datamodel.TritonModel var err error - if tritonModels, err = s.repository.GetTritonModels(modelUID); err != nil { + if _, err = s.repository.GetTritonModels(modelUID); err != nil { return err } - for _, tm := range tritonModels { - // Unload all models composing the ensemble model - if _, err = s.triton.UnloadModelRequest(ctx, tm.Name); err != nil { - // If any models unloaded with error, we set the ensemble model status with ERROR and return - if err1 := s.repository.UpdateModel(modelUID, datamodel.Model{ - State: datamodel.ModelState(modelPB.Model_STATE_ERROR), - }); err1 != nil { - return err1 - } - return err - } - } - if err := s.repository.UpdateModel(modelUID, datamodel.Model{ State: datamodel.ModelState(modelPB.Model_STATE_OFFLINE), }); err != nil { @@ -704,15 +693,6 @@ func (s *service) DeleteModel(ctx context.Context, owner string, modelID string) } if err := s.UndeployModel(ctx, modelInDB.UID); err != nil { - if err := s.UpdateResourceState( - ctx, - modelInDB.UID, - modelPB.Model_STATE_ERROR, - nil, - nil, - ); err != nil { - return err - } return err } @@ -727,6 +707,13 @@ func (s *service) DeleteModel(ctx context.Context, owner string, modelID string) } } + for state.String() == modelPB.Model_STATE_ONLINE.String() { + if state, err = s.GetResourceState(ctx, modelInDB.UID); err != nil { + return err + } + time.Sleep(100 * time.Millisecond) + } + if err := s.DeleteResourceState(ctx, modelInDB.UID); err != nil { return err } diff --git a/pkg/service/worker.go b/pkg/service/worker.go index 00dea1ff..8e6cb13a 100644 --- a/pkg/service/worker.go +++ b/pkg/service/worker.go @@ -13,8 +13,6 @@ import ( "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/protobuf/types/known/anypb" - workflowpb "go.temporal.io/api/workflow/v1" - "github.com/instill-ai/model-backend/config" "github.com/instill-ai/model-backend/pkg/datamodel" "github.com/instill-ai/model-backend/pkg/logger" @@ -94,16 +92,42 @@ func (s *service) UndeployModelAsync(ctx context.Context, owner string, modelUID return id.String(), nil } -func getOperationFromWorkflowInfo(workflowExecutionInfo *workflowpb.WorkflowExecutionInfo) (*longrunningpb.Operation, error) { +func (s *service) GetOperation(ctx context.Context, workflowId string) (*longrunningpb.Operation, error) { + workflowExecutionRes, err := s.temporalClient.DescribeWorkflowExecution(ctx, workflowId, "") + if err != nil { + return nil, err + } + + workflowExecutionInfo := workflowExecutionRes.WorkflowExecutionInfo + operation := longrunningpb.Operation{} switch workflowExecutionInfo.Status { case enums.WORKFLOW_EXECUTION_STATUS_COMPLETED: - operation = longrunningpb.Operation{ - Done: true, - Result: &longrunningpb.Operation_Response{ - Response: &anypb.Any{}, - }, + var result error + workflowRun := s.temporalClient.GetWorkflow(ctx, workflowId, "") + err = workflowRun.Get(ctx, &result) + if err != nil { + return nil, err + } + if result != nil { + operation = longrunningpb.Operation{ + Done: true, + Result: &longrunningpb.Operation_Error{ + Error: &status.Status{ + Code: int32(enums.WORKFLOW_EXECUTION_STATUS_FAILED), + Details: []*anypb.Any{}, + Message: result.Error(), + }, + }, + } + } else { + operation = longrunningpb.Operation{ + Done: true, + Result: &longrunningpb.Operation_Response{ + Response: &anypb.Any{}, + }, + } } case enums.WORKFLOW_EXECUTION_STATUS_RUNNING: case enums.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW: @@ -130,15 +154,6 @@ func getOperationFromWorkflowInfo(workflowExecutionInfo *workflowpb.WorkflowExec return &operation, nil } -func (s *service) GetOperation(ctx context.Context, workflowId string) (*longrunningpb.Operation, error) { - workflowExecutionRes, err := s.temporalClient.DescribeWorkflowExecution(ctx, workflowId, "") - - if err != nil { - return nil, err - } - return getOperationFromWorkflowInfo(workflowExecutionRes.WorkflowExecutionInfo) -} - func (s *service) CreateModelAsync(ctx context.Context, owner string, model *datamodel.Model) (string, error) { logger, _ := logger.GetZapLogger(ctx) id, _ := uuid.NewV4() diff --git a/pkg/worker/model.go b/pkg/worker/model.go index 6d172542..5fcc76c0 100644 --- a/pkg/worker/model.go +++ b/pkg/worker/model.go @@ -18,7 +18,6 @@ import ( "github.com/instill-ai/model-backend/pkg/datamodel" "github.com/instill-ai/model-backend/pkg/utils" - controllerPB "github.com/instill-ai/protogen-go/model/controller/v1alpha" modelPB "github.com/instill-ai/protogen-go/model/model/v1alpha" ) @@ -76,16 +75,6 @@ func (w *worker) DeployModelActivity(ctx context.Context, param *ModelParams) er return err } - resourcePermalink := utils.ConvertModelToResourcePermalink(dbModel.UID.String()) - - updateResourceReq := controllerPB.UpdateResourceRequest{ - Resource: &controllerPB.Resource{ - ResourcePermalink: resourcePermalink, - State: &controllerPB.Resource_ModelState{}, - Progress: nil, - }, - } - // downloading model weight when making inference rdid, _ := uuid.NewV4() modelSrcDir := fmt.Sprintf("/tmp/%s", rdid.String()) @@ -176,34 +165,15 @@ func (w *worker) DeployModelActivity(ctx context.Context, param *ModelParams) er if _, err = w.triton.LoadModelRequest(ctx, tModel.Name); err == nil { continue } - updateResourceReq.Resource.State = &controllerPB.Resource_ModelState{ - ModelState: modelPB.Model_STATE_ERROR, - } - if _, err := w.controllerClient.UpdateResource(ctx, &updateResourceReq); err != nil { - return err - } return err } if tEnsembleModel.Name != "" { // load ensemble model. if _, err = w.triton.LoadModelRequest(ctx, tEnsembleModel.Name); err != nil { - updateResourceReq.Resource.State = &controllerPB.Resource_ModelState{ - ModelState: modelPB.Model_STATE_ERROR, - } - if _, err := w.controllerClient.UpdateResource(ctx, &updateResourceReq); err != nil { - return err - } return err } } - updateResourceReq.Resource.State = &controllerPB.Resource_ModelState{ - ModelState: modelPB.Model_STATE_ONLINE, - } - if _, err := w.controllerClient.UpdateResource(ctx, &updateResourceReq); err != nil { - return err - } - logger.Info("DeployModelActivity completed") return nil @@ -247,41 +217,13 @@ func (w *worker) UnDeployModelActivity(ctx context.Context, param *ModelParams) return err } - dbModel, err := w.repository.GetModelByUID(param.Owner, param.Model.UID, modelPB.View_VIEW_FULL) - if err != nil { - return err - } - - resourcePermalink := utils.ConvertModelToResourcePermalink(dbModel.UID.String()) - - updateResourceReq := controllerPB.UpdateResourceRequest{ - Resource: &controllerPB.Resource{ - ResourcePermalink: resourcePermalink, - State: &controllerPB.Resource_ModelState{}, - Progress: nil, - }, - } - for _, tm := range tritonModels { // Unload all models composing the ensemble model if _, err = w.triton.UnloadModelRequest(ctx, tm.Name); err != nil { - updateResourceReq.Resource.State = &controllerPB.Resource_ModelState{ - ModelState: modelPB.Model_STATE_ERROR, - } - if _, err := w.controllerClient.UpdateResource(ctx, &updateResourceReq); err != nil { - return err - } return err } } - updateResourceReq.Resource.State = &controllerPB.Resource_ModelState{ - ModelState: modelPB.Model_STATE_OFFLINE, - } - if _, err := w.controllerClient.UpdateResource(ctx, &updateResourceReq); err != nil { - return err - } - logger.Info("UnDeployModelActivity completed") return nil @@ -292,17 +234,6 @@ func (w *worker) CreateModelWorkflow(ctx workflow.Context, param *ModelParams) e logger := workflow.GetLogger(ctx) logger.Info("CreateModelWorkflow started") - updateResourceReq := controllerPB.UpdateResourceRequest{ - Resource: &controllerPB.Resource{ - ResourcePermalink: "", - State: &controllerPB.Resource_ModelState{}, - Progress: nil, - }, - } - - controllerCtx, cancel := context.WithCancel(context.Background()) - defer cancel() - preDeployModel, err := GetPreDeployGitHubModelUUID(param.Model) if err != nil { return err @@ -310,33 +241,14 @@ func (w *worker) CreateModelWorkflow(ctx workflow.Context, param *ModelParams) e if preDeployModel != nil && !config.Config.Server.ItMode.Enabled { if err := w.repository.CreatePreDeployModel(*preDeployModel); err != nil { - updateResourceReq.Resource.State = &controllerPB.Resource_ModelState{ - ModelState: modelPB.Model_STATE_ERROR, - } + return err } } else { if err := w.repository.CreateModel(param.Model); err != nil { - updateResourceReq.Resource.State = &controllerPB.Resource_ModelState{ - ModelState: modelPB.Model_STATE_ERROR, - } + return err } } - dbModel, err := w.repository.GetModelByID(param.Owner, param.Model.ID, modelPB.View_VIEW_BASIC) - if err != nil { - return err - } - - resourcePermalink := utils.ConvertModelToResourcePermalink(dbModel.UID.String()) - - updateResourceReq.Resource.ResourcePermalink = resourcePermalink - updateResourceReq.Resource.State = &controllerPB.Resource_ModelState{ - ModelState: modelPB.Model_STATE_OFFLINE, - } - if _, err := w.controllerClient.UpdateResource(controllerCtx, &updateResourceReq); err != nil { - return err - } - logger.Info("CreateModelWorkflow completed") return nil