Skip to content

Commit c176883

Browse files
lilangjojoliang
authored andcommitted
工作流增删改查
1 parent 3d28a02 commit c176883

File tree

2 files changed

+234
-77
lines changed

2 files changed

+234
-77
lines changed

ci_media.go

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,8 +1831,52 @@ type MediaWorkflow struct {
18311831

18321832
// MarshalXML TODO
18331833
func (m *CreateMediaWorkflowOptions) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
1834-
fmt.Println(123)
1835-
return nil
1834+
if m == nil {
1835+
return nil
1836+
}
1837+
type xmlMapEntry struct {
1838+
XMLName xml.Name
1839+
Type string `xml:"Type"`
1840+
Input interface{} `xml:",innerxml"`
1841+
Operation interface{} `xml:",innerxml"`
1842+
}
1843+
tokens := []xml.Token{}
1844+
tokens = append(tokens, xml.StartElement{Name: xml.Name{Local: "Request"}})
1845+
tokens = append(tokens, xml.StartElement{Name: xml.Name{Local: "MediaWorkflow"}})
1846+
t := xml.StartElement{Name: xml.Name{Local: "Name"}}
1847+
tokens = append(tokens, t, xml.CharData(m.MediaWorkflow.Name), xml.EndElement{Name: t.Name})
1848+
t = xml.StartElement{Name: xml.Name{Local: "State"}}
1849+
tokens = append(tokens, t, xml.CharData(m.MediaWorkflow.State), xml.EndElement{Name: t.Name})
1850+
tokens = append(tokens, xml.StartElement{Name: xml.Name{Local: "Topology"}})
1851+
tokens = append(tokens, xml.StartElement{Name: xml.Name{Local: "Dependencies"}})
1852+
for key, value := range m.MediaWorkflow.Topology.Dependencies {
1853+
t := xml.StartElement{Name: xml.Name{Local: key}}
1854+
tokens = append(tokens, t, xml.CharData(value), xml.EndElement{Name: t.Name})
1855+
}
1856+
tokens = append(tokens, xml.EndElement{Name: xml.Name{Local: "Dependencies"}})
1857+
// Nodes
1858+
tokens = append(tokens, xml.StartElement{Name: xml.Name{Local: "Nodes"}})
1859+
for _, t := range tokens {
1860+
err := e.EncodeToken(t)
1861+
if err != nil {
1862+
return err
1863+
}
1864+
}
1865+
tokens = tokens[:0]
1866+
for k, v := range m.MediaWorkflow.Topology.Nodes {
1867+
e.Encode(xmlMapEntry{XMLName: xml.Name{Local: k}, Type: v.Type, Input: v.Input, Operation: v.Operation})
1868+
}
1869+
tokens = append(tokens, xml.EndElement{Name: xml.Name{Local: "Nodes"}})
1870+
tokens = append(tokens, xml.EndElement{Name: xml.Name{Local: "Topology"}})
1871+
tokens = append(tokens, xml.EndElement{Name: xml.Name{Local: "MediaWorkflow"}})
1872+
tokens = append(tokens, xml.EndElement{Name: xml.Name{Local: "Request"}})
1873+
for _, t := range tokens {
1874+
err := e.EncodeToken(t)
1875+
if err != nil {
1876+
return err
1877+
}
1878+
}
1879+
return e.Flush()
18361880
}
18371881

18381882
// UnmarshalXML TODO
@@ -1915,6 +1959,20 @@ func (s *CIService) CreateMediaWorkflow(ctx context.Context, opt *CreateMediaWor
19151959
return &res, resp, err
19161960
}
19171961

1962+
// UpdateMediaWorkflow TODO
1963+
func (s *CIService) UpdateMediaWorkflow(ctx context.Context, opt *CreateMediaWorkflowOptions, workflowId string) (*CreateMediaWorkflowResult, *Response, error) {
1964+
var res CreateMediaWorkflowResult
1965+
sendOpt := sendOptions{
1966+
baseURL: s.client.BaseURL.CIURL,
1967+
uri: "/workflow/" + workflowId,
1968+
method: http.MethodPut,
1969+
body: opt,
1970+
result: &res,
1971+
}
1972+
resp, err := s.client.send(ctx, &sendOpt)
1973+
return &res, resp, err
1974+
}
1975+
19181976
// DescribeMediaWorkflowOptions TODO
19191977
type DescribeMediaWorkflowOptions struct {
19201978
Ids string `url:"ids,omitempty"`
@@ -1954,7 +2012,7 @@ type DeleteMediaWorkflowResult struct {
19542012
WorkflowId string `xml:"WorkflowId,omitempty"`
19552013
}
19562014

1957-
// DeleteMediaWorkflow TODO
2015+
// DeleteMediaWorkflow 删除工作流
19582016
func (s *CIService) DeleteMediaWorkflow(ctx context.Context, workflowId string) (*DeleteMediaWorkflowResult, *Response, error) {
19592017
var res DeleteMediaWorkflowResult
19602018
sendOpt := sendOptions{

example/CI/media_process/media_workflow.go

Lines changed: 173 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func CreateWorkflow() {
112112
Dependencies: map[string]string{"Start": "Transcode_1581665960537", "Transcode_1581665960537": "Snapshot_1581665960536",
113113
"Snapshot_1581665960536": "End"},
114114
Nodes: map[string]cos.Node{"Start": cos.Node{Type: "Start", Input: &cos.NodeInput{QueueId: "p09d709939fef48a0a5c247ef39d90cec",
115-
ObjectPrefix: "wk-test", ExtFilter: &cos.ExtFilter{State: "On", CustomExts: "mp4"}}},
115+
ObjectPrefix: "wk-test", ExtFilter: &cos.ExtFilter{State: "On", Custom: "true", CustomExts: "mp4"}}},
116116
"Transcode_1581665960537": cos.Node{Type: "Transcode", Operation: &cos.NodeOperation{TemplateId: "t01e57db1c2d154d2fb57aa5de9313a897",
117117
Output: &cos.NodeOutput{Region: "ap-chongqing", Bucket: "lilang-1253960454", Object: "trans1.mp4"}}},
118118
"Snapshot_1581665960536": cos.Node{Type: "Snapshot", Operation: &cos.NodeOperation{TemplateId: "t07740e32081b44ad7a0aea03adcffd54a",
@@ -136,82 +136,181 @@ func CreateWorkflow() {
136136
}
137137
}
138138

139-
// // UpdateTranscodeWorkflow TODO
140-
// func UpdateTranscodeWorkflow() {
141-
// u, _ := url.Parse("https://lilang-1253960454.cos.ap-chongqing.myqcloud.com")
142-
// cu, _ := url.Parse("https://lilang-1253960454.ci.ap-chongqing.myqcloud.com")
143-
// b := &cos.BaseURL{BucketURL: u, CIURL: cu}
144-
// c := cos.NewClient(b, &http.Client{
145-
// Transport: &cos.AuthorizationTransport{
146-
// SecretID: os.Getenv("COS_SECRETID"),
147-
// SecretKey: os.Getenv("COS_SECRETKEY"),
148-
// Transport: &debug.DebugRequestTransport{
149-
// RequestHeader: true,
150-
// // Notice when put a large file and set need the request body, might happend out of memory error.
151-
// RequestBody: true,
152-
// ResponseHeader: true,
153-
// ResponseBody: true,
154-
// },
155-
// },
156-
// })
157-
// // UpdateMediaWorkflow
158-
// rand.Seed(time.Now().UnixNano())
159-
// updateTplOpt := &cos.CreateMediaTranscodeWorkflowOptions{
160-
// Tag: "Transcode",
161-
// Name: "transtpl-" + strconv.Itoa(rand.Intn(100)),
162-
// Container: &cos.Container{
163-
// Format: "mp4",
164-
// },
165-
// Video: &cos.Video{
166-
// Codec: "h.264",
167-
// Width: "1280",
168-
// Fps: "30",
169-
// Crf: "26",
170-
// },
171-
// Audio: &cos.Audio{
172-
// Codec: "aac",
173-
// },
174-
// TimeInterval: &cos.TimeInterval{
175-
// Start: "0",
176-
// Duration: "",
177-
// },
178-
// }
179-
// WorkflowId := "t1d31d58d8a4204d7396087f56a448abd5"
180-
// updateTplRes, _, err := c.CI.UpdateMediaTranscodeWorkflow(context.Background(), updateTplOpt, WorkflowId)
181-
// log_status(err)
182-
// fmt.Printf("%+v\n", updateTplRes.Workflow)
139+
// UpdateWorkflow TODO
140+
func UpdateWorkflow() {
141+
u, _ := url.Parse("https://lilang-1253960454.cos.ap-chongqing.myqcloud.com")
142+
cu, _ := url.Parse("https://lilang-1253960454.ci.ap-chongqing.myqcloud.com")
143+
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
144+
c := cos.NewClient(b, &http.Client{
145+
Transport: &cos.AuthorizationTransport{
146+
SecretID: os.Getenv("COS_SECRETID"),
147+
SecretKey: os.Getenv("COS_SECRETKEY"),
148+
Transport: &debug.DebugRequestTransport{
149+
RequestHeader: true,
150+
// Notice when put a large file and set need the request body, might happend out of memory error.
151+
RequestBody: true,
152+
ResponseHeader: true,
153+
ResponseBody: true,
154+
},
155+
},
156+
})
157+
// UpdateMediaWorkflow
158+
rand.Seed(time.Now().UnixNano())
159+
updateWorkflowOpt := &cos.CreateMediaWorkflowOptions{
160+
MediaWorkflow: &cos.MediaWorkflow{
161+
Name: "workflow-" + strconv.Itoa(rand.Intn(100)),
162+
State: "Paused",
163+
Topology: &cos.Topology{
164+
Dependencies: map[string]string{"Start": "Transcode_1581665960537", "Transcode_1581665960537": "Snapshot_1581665960536",
165+
"Snapshot_1581665960536": "End"},
166+
Nodes: map[string]cos.Node{"Start": cos.Node{Type: "Start", Input: &cos.NodeInput{QueueId: "p09d709939fef48a0a5c247ef39d90cec",
167+
ObjectPrefix: "wk-test", ExtFilter: &cos.ExtFilter{State: "On", Custom: "true", CustomExts: "mp4"}}},
168+
"Transcode_1581665960537": cos.Node{Type: "Transcode", Operation: &cos.NodeOperation{TemplateId: "t01e57db1c2d154d2fb57aa5de9313a897",
169+
Output: &cos.NodeOutput{Region: "ap-chongqing", Bucket: "lilang-1253960454", Object: "trans1.mp4"}}},
170+
"Snapshot_1581665960536": cos.Node{Type: "Snapshot", Operation: &cos.NodeOperation{TemplateId: "t07740e32081b44ad7a0aea03adcffd54a",
171+
Output: &cos.NodeOutput{Region: "ap-chongqing", Bucket: "lilang-1253960454", Object: "snapshot-${number}.jpg"}}},
172+
},
173+
},
174+
},
175+
}
176+
WorkflowId := "web6ac56c1ef54dbfa44d7f4103203be9"
177+
updateWorkflowRes, _, err := c.CI.UpdateMediaWorkflow(context.Background(), updateWorkflowOpt, WorkflowId)
178+
log_status(err)
179+
fmt.Printf("%+v\n", updateWorkflowRes.MediaWorkflow)
180+
181+
opt := &cos.DescribeMediaWorkflowOptions{
182+
Ids: WorkflowId,
183+
}
184+
DescribeWorkflowRes, _, err := c.CI.DescribeMediaWorkflow(context.Background(), opt)
185+
log_status(err)
186+
fmt.Printf("%+v\n", DescribeWorkflowRes)
187+
}
188+
189+
// CreateStreamWorkflow 创建自适应码流工作流
190+
func CreateStreamWorkflow() {
191+
u, _ := url.Parse("https://lilang-1253960454.cos.ap-chongqing.myqcloud.com")
192+
cu, _ := url.Parse("https://lilang-1253960454.ci.ap-chongqing.myqcloud.com")
193+
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
194+
c := cos.NewClient(b, &http.Client{
195+
Transport: &cos.AuthorizationTransport{
196+
SecretID: os.Getenv("COS_SECRETID"),
197+
SecretKey: os.Getenv("COS_SECRETKEY"),
198+
Transport: &debug.DebugRequestTransport{
199+
RequestHeader: true,
200+
// Notice when put a large file and set need the request body, might happend out of memory error.
201+
RequestBody: true,
202+
ResponseHeader: true,
203+
ResponseBody: true,
204+
},
205+
},
206+
})
207+
// CreateMediaWorkflow
208+
rand.Seed(time.Now().UnixNano())
209+
hpi := &cos.NodeHlsPackInfo{}
210+
vsc1 := &cos.VideoStreamConfig{VideoStreamName: "VideoStream_1581665960536", BandWidth: "200000"}
211+
vsc2 := &cos.VideoStreamConfig{VideoStreamName: "VideoStream_1581665960537", BandWidth: "500000"}
212+
hpi.VideoStreamConfig = append(hpi.VideoStreamConfig, *vsc1, *vsc2)
213+
createWorkflowOpt := &cos.CreateMediaWorkflowOptions{
214+
MediaWorkflow: &cos.MediaWorkflow{
215+
Name: "workflow-" + strconv.Itoa(rand.Intn(100)),
216+
State: "Active",
217+
Topology: &cos.Topology{
218+
Dependencies: map[string]string{"Start": "StreamPackConfig_1581665960532", "StreamPackConfig_1581665960532": "VideoStream_1581665960536,VideoStream_1581665960537",
219+
"VideoStream_1581665960536": "StreamPack_1581665960538", "VideoStream_1581665960537": "StreamPack_1581665960538",
220+
"StreamPack_1581665960538": "End"},
221+
Nodes: map[string]cos.Node{"Start": cos.Node{Type: "Start", Input: &cos.NodeInput{QueueId: "p09d709939fef48a0a5c247ef39d90cec",
222+
ObjectPrefix: "wk-test", ExtFilter: &cos.ExtFilter{State: "On", Custom: "true", CustomExts: "mp4"}}},
223+
"StreamPackConfig_1581665960532": cos.Node{Type: "StreamPackConfig", Operation: &cos.NodeOperation{
224+
Output: &cos.NodeOutput{Region: "ap-chongqing", Bucket: "lilang-1253960454", Object: "${InputPath}/${InputName}._${RunId}.${ext}"},
225+
StreamPackConfigInfo: &cos.NodeStreamPackConfigInfo{PackType: "HLS", IgnoreFailedStream: true}}},
226+
"VideoStream_1581665960536": cos.Node{Type: "VideoStream", Operation: &cos.NodeOperation{TemplateId: "t03e862f296fba4152a1dd186b4ad5f64b",
227+
Output: &cos.NodeOutput{Region: "ap-chongqing", Bucket: "lilang-1253960454", Object: "${RunId}_Substream_1/video.m3u8"}}},
228+
"VideoStream_1581665960537": cos.Node{Type: "VideoStream", Operation: &cos.NodeOperation{TemplateId: "t09f9da59ed3c44ecd8ea1778e5ce5669c",
229+
Output: &cos.NodeOutput{Region: "ap-chongqing", Bucket: "lilang-1253960454", Object: "${RunId}_Substream_1/video.m3u8"}}},
230+
"StreamPack_1581665960538": cos.Node{Type: "StreamPack", Operation: &cos.NodeOperation{StreamPackInfo: hpi}},
231+
},
232+
},
233+
},
234+
}
235+
createWorkflowRes, _, err := c.CI.CreateMediaWorkflow(context.Background(), createWorkflowOpt)
236+
log_status(err)
237+
fmt.Printf("%+v\n", createWorkflowRes.MediaWorkflow)
238+
239+
// DescribeMediaWorkflow
240+
if createWorkflowRes.MediaWorkflow != nil {
241+
opt := &cos.DescribeMediaWorkflowOptions{
242+
Ids: createWorkflowRes.MediaWorkflow.WorkflowId,
243+
}
244+
DescribeWorkflowRes, _, err := c.CI.DescribeMediaWorkflow(context.Background(), opt)
245+
log_status(err)
246+
fmt.Printf("%+v\n", DescribeWorkflowRes)
247+
}
248+
}
249+
250+
// UpdatStreamWorkflow 更新自适应码流工作流
251+
func UpdatStreamWorkflow() {
252+
u, _ := url.Parse("https://lilang-1253960454.cos.ap-chongqing.myqcloud.com")
253+
cu, _ := url.Parse("https://lilang-1253960454.ci.ap-chongqing.myqcloud.com")
254+
b := &cos.BaseURL{BucketURL: u, CIURL: cu}
255+
c := cos.NewClient(b, &http.Client{
256+
Transport: &cos.AuthorizationTransport{
257+
SecretID: os.Getenv("COS_SECRETID"),
258+
SecretKey: os.Getenv("COS_SECRETKEY"),
259+
Transport: &debug.DebugRequestTransport{
260+
RequestHeader: true,
261+
// Notice when put a large file and set need the request body, might happend out of memory error.
262+
RequestBody: true,
263+
ResponseHeader: true,
264+
ResponseBody: true,
265+
},
266+
},
267+
})
268+
// UpdateMediaWorkflow
269+
rand.Seed(time.Now().UnixNano())
270+
hpi := &cos.NodeHlsPackInfo{}
271+
vsc1 := &cos.VideoStreamConfig{VideoStreamName: "VideoStream_1581665960536", BandWidth: "200000"}
272+
vsc2 := &cos.VideoStreamConfig{VideoStreamName: "VideoStream_1581665960537", BandWidth: "500000"}
273+
hpi.VideoStreamConfig = append(hpi.VideoStreamConfig, *vsc1, *vsc2)
274+
updateWorkflowOpt := &cos.CreateMediaWorkflowOptions{
275+
MediaWorkflow: &cos.MediaWorkflow{
276+
Name: "workflow-" + strconv.Itoa(rand.Intn(100)),
277+
State: "Active",
278+
Topology: &cos.Topology{
279+
Dependencies: map[string]string{"Start": "StreamPackConfig_1581665960532", "StreamPackConfig_1581665960532": "VideoStream_1581665960536,VideoStream_1581665960537",
280+
"VideoStream_1581665960536": "StreamPack_1581665960538", "VideoStream_1581665960537": "StreamPack_1581665960538",
281+
"StreamPack_1581665960538": "End"},
282+
Nodes: map[string]cos.Node{"Start": cos.Node{Type: "Start", Input: &cos.NodeInput{QueueId: "p09d709939fef48a0a5c247ef39d90cec",
283+
ObjectPrefix: "wk-test", ExtFilter: &cos.ExtFilter{State: "On", Custom: "true", CustomExts: "mp4"}}},
284+
"StreamPackConfig_1581665960532": cos.Node{Type: "StreamPackConfig", Operation: &cos.NodeOperation{
285+
Output: &cos.NodeOutput{Region: "ap-chongqing", Bucket: "lilang-1253960454", Object: "${InputPath}/${InputName}._${RunId}.${ext}"},
286+
StreamPackConfigInfo: &cos.NodeStreamPackConfigInfo{PackType: "HLS", IgnoreFailedStream: true}}},
287+
"VideoStream_1581665960536": cos.Node{Type: "VideoStream", Operation: &cos.NodeOperation{TemplateId: "t03e862f296fba4152a1dd186b4ad5f64b",
288+
Output: &cos.NodeOutput{Region: "ap-chongqing", Bucket: "lilang-1253960454", Object: "${RunId}_Substream_1/video.m3u8"}}},
289+
"VideoStream_1581665960537": cos.Node{Type: "VideoStream", Operation: &cos.NodeOperation{TemplateId: "t09f9da59ed3c44ecd8ea1778e5ce5669c",
290+
Output: &cos.NodeOutput{Region: "ap-chongqing", Bucket: "lilang-1253960454", Object: "${RunId}_Substream_1/video.m3u8"}}},
291+
"StreamPack_1581665960538": cos.Node{Type: "StreamPack", Operation: &cos.NodeOperation{StreamPackInfo: hpi}},
292+
},
293+
},
294+
},
295+
}
296+
WorkflowId := "w5fecd57f8a7745b3ac8143b211613789"
297+
updateWorkflowRes, _, err := c.CI.UpdateMediaWorkflow(context.Background(), updateWorkflowOpt, WorkflowId)
298+
log_status(err)
299+
fmt.Printf("%+v\n", updateWorkflowRes.MediaWorkflow)
183300

184-
// opt := &cos.DescribeMediaWorkflowOptions{
185-
// Ids: WorkflowId,
186-
// }
187-
// DescribeWorkflowRes, _, err := c.CI.DescribeMediaWorkflow(context.Background(), opt)
188-
// log_status(err)
189-
// fmt.Printf("%+v\n", DescribeWorkflowRes)
190-
// }
301+
opt := &cos.DescribeMediaWorkflowOptions{
302+
Ids: WorkflowId,
303+
}
304+
DescribeWorkflowRes, _, err := c.CI.DescribeMediaWorkflow(context.Background(), opt)
305+
log_status(err)
306+
fmt.Printf("%+v\n", DescribeWorkflowRes)
307+
}
191308

192309
func main() {
193-
DescribeWorkflow()
310+
// DescribeWorkflow()
194311
// DeleteWorkflow()
195312
// CreateWorkflow()
196-
// UpdateTranscodeWorkflow()
197-
// CreateSnapshotWorkflow()
198-
// UpdateSnapshotWorkflow()
199-
// CreateHighSpeedHdWorkflow()
200-
// UpdateHighSpeedHdWorkflow()
201-
// CreateAnimationWorkflow()
202-
// UpdateAnimationWorkflow()
203-
// CreateConcatWorkflow()
204-
// UpdateConcatWorkflow()
205-
// CreateVideoProcessWorkflow()
206-
// UpdateVideoProcessWorkflow()
207-
// CreateVideoMontageWorkflow()
208-
// UpdateVideoMontageWorkflow()
209-
// CreateVoiceSeparateWorkflow()
210-
// UpdateVoiceSeparateWorkflow()
211-
// CreateSuperResolutionWorkflow()
212-
// UpdateSuperResolutionWorkflow()
213-
// CreatePicProcessWorkflow()
214-
// UpdatePicProcessWorkflow()
215-
// CreateWatermarkWorkflow()
216-
// UpdateWatermarkWorkflow()
313+
// UpdateWorkflow()
314+
// CreateStreamWorkflow()
315+
UpdatStreamWorkflow()
217316
}

0 commit comments

Comments
 (0)