|
|
@@ -28,6 +28,7 @@ import ( |
|
|
"gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice" |
|
|
"gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice" |
|
|
"gitlink.org.cn/JointCloud/pcm-modelarts/modelarts" |
|
|
"gitlink.org.cn/JointCloud/pcm-modelarts/modelarts" |
|
|
modelartsclient "gitlink.org.cn/JointCloud/pcm-modelarts/modelarts" |
|
|
modelartsclient "gitlink.org.cn/JointCloud/pcm-modelarts/modelarts" |
|
|
|
|
|
"log" |
|
|
"mime/multipart" |
|
|
"mime/multipart" |
|
|
"strconv" |
|
|
"strconv" |
|
|
"strings" |
|
|
"strings" |
|
|
@@ -334,7 +335,6 @@ func (m *ModelArtsLink) getSourceLocationFromImages(ctx context.Context, option |
|
|
for _, ListImages := range ListImagesResp.Data { |
|
|
for _, ListImages := range ListImagesResp.Data { |
|
|
if ListImages.Name == option.ModelName { |
|
|
if ListImages.Name == option.ModelName { |
|
|
m.SourceLocation = ListImages.SwrPath |
|
|
m.SourceLocation = ListImages.SwrPath |
|
|
//m.Version = ListImages.Mo |
|
|
|
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@@ -367,47 +367,45 @@ func (m *ModelArtsLink) GetModelId(ctx context.Context, option *option.InferOpti |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Get AI Application List |
|
|
|
|
|
func (m *ModelArtsLink) GetModelStatus(ctx context.Context, option *option.InferOption) error { |
|
|
|
|
|
|
|
|
func (m *ModelArtsLink) GetModel(ctx context.Context, option *option.InferOption) string { |
|
|
req := &modelarts.ShowModelReq{ |
|
|
req := &modelarts.ShowModelReq{ |
|
|
Platform: m.platform, |
|
|
Platform: m.platform, |
|
|
ModelId: option.ModelId, |
|
|
ModelId: option.ModelId, |
|
|
} |
|
|
} |
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Second) |
|
|
|
|
|
defer cancel() |
|
|
ShowModelsResp, err := m.modelArtsRpc.ShowModels(ctx, req) |
|
|
ShowModelsResp, err := m.modelArtsRpc.ShowModels(ctx, req) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
|
|
|
|
|
|
if err == context.DeadlineExceeded { |
|
|
|
|
|
log.Println("Request timed out") |
|
|
|
|
|
// 重试请求或其他处理 |
|
|
|
|
|
} else { |
|
|
|
|
|
log.Fatalf("could not call method: %v", err) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
if ShowModelsResp.Code != 200 { |
|
|
if ShowModelsResp.Code != 200 { |
|
|
return errors.New("failed to get ListModels") |
|
|
|
|
|
|
|
|
errors.New("failed to get findModelsStatus") |
|
|
} |
|
|
} |
|
|
ModelStatus := ShowModelsResp.ShowModelDetail.ModelStatus |
|
|
|
|
|
|
|
|
return ShowModelsResp.ShowModelDetail.ModelStatus |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get AI Application List |
|
|
|
|
|
func (m *ModelArtsLink) GetModelStatus(ctx context.Context, option *option.InferOption) error { |
|
|
var wg sync.WaitGroup |
|
|
var wg sync.WaitGroup |
|
|
wg.Add(1) |
|
|
wg.Add(1) |
|
|
|
|
|
|
|
|
//model := MyModel{Status: "draft"} |
|
|
|
|
|
|
|
|
|
|
|
// 使用goroutine进行轮询 |
|
|
// 使用goroutine进行轮询 |
|
|
go func() { |
|
|
|
|
|
defer wg.Done() |
|
|
|
|
|
|
|
|
|
|
|
for { |
|
|
|
|
|
status := ModelStatus |
|
|
|
|
|
if status == "published" { |
|
|
|
|
|
fmt.Println("Model is now published.") |
|
|
|
|
|
break // 一旦状态变为published,就退出循环 |
|
|
|
|
|
} |
|
|
|
|
|
fmt.Println("Waiting for model to be published...") |
|
|
|
|
|
time.Sleep(2 * time.Second) // 等待一段时间后再次检查 |
|
|
|
|
|
|
|
|
//defer wg.Done() |
|
|
|
|
|
for { |
|
|
|
|
|
status := m.GetModel(ctx, option) |
|
|
|
|
|
if status == "published" { |
|
|
|
|
|
fmt.Println("Model is now published.") |
|
|
|
|
|
break // 一旦状态变为published,就退出循环 |
|
|
} |
|
|
} |
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
// 等待goroutine完成 |
|
|
|
|
|
wg.Wait() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("Waiting for model to be published...") |
|
|
|
|
|
time.Sleep(5 * time.Second) // 等待一段时间后再次检查 |
|
|
|
|
|
} |
|
|
// 在这里执行模型状态为published后需要进行的操作 |
|
|
// 在这里执行模型状态为published后需要进行的操作 |
|
|
fmt.Println("Continuing with the program...") |
|
|
fmt.Println("Continuing with the program...") |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -773,6 +771,8 @@ func (m *ModelArtsLink) CreateInferDeployInstance(ctx context.Context, option *o |
|
|
InferType: "real-time", |
|
|
InferType: "real-time", |
|
|
ServiceName: option.TaskName, |
|
|
ServiceName: option.TaskName, |
|
|
} |
|
|
} |
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 150*time.Second) |
|
|
|
|
|
defer cancel() |
|
|
resp, err := m.modelArtsRpc.CreateService(ctx, req) |
|
|
resp, err := m.modelArtsRpc.CreateService(ctx, req) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return "", err |
|
|
return "", err |
|
|
|