1 package job
2
3
4
5
6
7
8
9 import (
10 "context"
11 "encoding/json"
12 "github.com/Azure/go-autorest/autorest"
13 "github.com/Azure/go-autorest/autorest/date"
14 "github.com/Azure/go-autorest/autorest/to"
15 "github.com/Azure/go-autorest/tracing"
16 "github.com/gofrs/uuid"
17 "net/http"
18 )
19
20
21 const fqdn = "github.com/Azure/azure-sdk-for-go/services/preview/datalake/analytics/2015-11-01-preview/job"
22
23
24 type DataPath struct {
25 autorest.Response `json:"-"`
26
27 JobID *uuid.UUID `json:"jobId,omitempty"`
28
29 Command *string `json:"command,omitempty"`
30
31 Paths *[]string `json:"paths,omitempty"`
32 }
33
34
35 func (dp DataPath) MarshalJSON() ([]byte, error) {
36 objectMap := make(map[string]interface{})
37 return json.Marshal(objectMap)
38 }
39
40
41 type ErrorDetails struct {
42
43 Description *string `json:"description,omitempty"`
44
45 Details *string `json:"details,omitempty"`
46
47 EndOffset *int32 `json:"endOffset,omitempty"`
48
49 ErrorID *string `json:"errorId,omitempty"`
50
51 FilePath *string `json:"filePath,omitempty"`
52
53 HelpLink *string `json:"helpLink,omitempty"`
54
55 InternalDiagnostics *string `json:"internalDiagnostics,omitempty"`
56
57 LineNumber *int32 `json:"lineNumber,omitempty"`
58
59 Message *string `json:"message,omitempty"`
60
61 Resolution *string `json:"resolution,omitempty"`
62
63 InnerError *InnerError `json:"InnerError,omitempty"`
64
65 Severity SeverityTypes `json:"severity,omitempty"`
66
67 Source *string `json:"source,omitempty"`
68
69 StartOffset *int32 `json:"startOffset,omitempty"`
70 }
71
72
73 func (ed ErrorDetails) MarshalJSON() ([]byte, error) {
74 objectMap := make(map[string]interface{})
75 return json.Marshal(objectMap)
76 }
77
78
79 type HiveJobProperties struct {
80
81 StatementInfo *[]HiveJobStatementInfo `json:"statementInfo,omitempty"`
82
83 LogsLocation *string `json:"logsLocation,omitempty"`
84
85 WarehouseLocation *string `json:"warehouseLocation,omitempty"`
86
87 StatementCount *int32 `json:"statementCount,omitempty"`
88
89 ExecutedStatementCount *int32 `json:"executedStatementCount,omitempty"`
90
91 RuntimeVersion *string `json:"runtimeVersion,omitempty"`
92
93 Script *string `json:"script,omitempty"`
94
95 Type Type `json:"type,omitempty"`
96 }
97
98
99 func (hjp HiveJobProperties) MarshalJSON() ([]byte, error) {
100 hjp.Type = TypeHive
101 objectMap := make(map[string]interface{})
102 if hjp.StatementInfo != nil {
103 objectMap["statementInfo"] = hjp.StatementInfo
104 }
105 if hjp.LogsLocation != nil {
106 objectMap["logsLocation"] = hjp.LogsLocation
107 }
108 if hjp.WarehouseLocation != nil {
109 objectMap["warehouseLocation"] = hjp.WarehouseLocation
110 }
111 if hjp.StatementCount != nil {
112 objectMap["statementCount"] = hjp.StatementCount
113 }
114 if hjp.ExecutedStatementCount != nil {
115 objectMap["executedStatementCount"] = hjp.ExecutedStatementCount
116 }
117 if hjp.RuntimeVersion != nil {
118 objectMap["runtimeVersion"] = hjp.RuntimeVersion
119 }
120 if hjp.Script != nil {
121 objectMap["script"] = hjp.Script
122 }
123 if hjp.Type != "" {
124 objectMap["type"] = hjp.Type
125 }
126 return json.Marshal(objectMap)
127 }
128
129
130 func (hjp HiveJobProperties) AsUSQLJobProperties() (*USQLJobProperties, bool) {
131 return nil, false
132 }
133
134
135 func (hjp HiveJobProperties) AsHiveJobProperties() (*HiveJobProperties, bool) {
136 return &hjp, true
137 }
138
139
140 func (hjp HiveJobProperties) AsProperties() (*Properties, bool) {
141 return nil, false
142 }
143
144
145 func (hjp HiveJobProperties) AsBasicProperties() (BasicProperties, bool) {
146 return &hjp, true
147 }
148
149
150 type HiveJobStatementInfo struct {
151
152 LogLocation *string `json:"logLocation,omitempty"`
153
154 ResultPreviewLocation *string `json:"resultPreviewLocation,omitempty"`
155
156 ResultLocation *string `json:"resultLocation,omitempty"`
157
158 ErrorMessage *string `json:"errorMessage,omitempty"`
159 }
160
161
162 type InfoListResult struct {
163 autorest.Response `json:"-"`
164
165 Value *[]Information `json:"value,omitempty"`
166
167 NextLink *string `json:"nextLink,omitempty"`
168
169 Count *int64 `json:"count,omitempty"`
170 }
171
172
173 func (ilr InfoListResult) MarshalJSON() ([]byte, error) {
174 objectMap := make(map[string]interface{})
175 return json.Marshal(objectMap)
176 }
177
178
179 type InfoListResultIterator struct {
180 i int
181 page InfoListResultPage
182 }
183
184
185
186 func (iter *InfoListResultIterator) NextWithContext(ctx context.Context) (err error) {
187 if tracing.IsEnabled() {
188 ctx = tracing.StartSpan(ctx, fqdn+"/InfoListResultIterator.NextWithContext")
189 defer func() {
190 sc := -1
191 if iter.Response().Response.Response != nil {
192 sc = iter.Response().Response.Response.StatusCode
193 }
194 tracing.EndSpan(ctx, sc, err)
195 }()
196 }
197 iter.i++
198 if iter.i < len(iter.page.Values()) {
199 return nil
200 }
201 err = iter.page.NextWithContext(ctx)
202 if err != nil {
203 iter.i--
204 return err
205 }
206 iter.i = 0
207 return nil
208 }
209
210
211
212
213 func (iter *InfoListResultIterator) Next() error {
214 return iter.NextWithContext(context.Background())
215 }
216
217
218 func (iter InfoListResultIterator) NotDone() bool {
219 return iter.page.NotDone() && iter.i < len(iter.page.Values())
220 }
221
222
223 func (iter InfoListResultIterator) Response() InfoListResult {
224 return iter.page.Response()
225 }
226
227
228
229 func (iter InfoListResultIterator) Value() Information {
230 if !iter.page.NotDone() {
231 return Information{}
232 }
233 return iter.page.Values()[iter.i]
234 }
235
236
237 func NewInfoListResultIterator(page InfoListResultPage) InfoListResultIterator {
238 return InfoListResultIterator{page: page}
239 }
240
241
242 func (ilr InfoListResult) IsEmpty() bool {
243 return ilr.Value == nil || len(*ilr.Value) == 0
244 }
245
246
247 func (ilr InfoListResult) hasNextLink() bool {
248 return ilr.NextLink != nil && len(*ilr.NextLink) != 0
249 }
250
251
252
253 func (ilr InfoListResult) infoListResultPreparer(ctx context.Context) (*http.Request, error) {
254 if !ilr.hasNextLink() {
255 return nil, nil
256 }
257 return autorest.Prepare((&http.Request{}).WithContext(ctx),
258 autorest.AsJSON(),
259 autorest.AsGet(),
260 autorest.WithBaseURL(to.String(ilr.NextLink)))
261 }
262
263
264 type InfoListResultPage struct {
265 fn func(context.Context, InfoListResult) (InfoListResult, error)
266 ilr InfoListResult
267 }
268
269
270
271 func (page *InfoListResultPage) NextWithContext(ctx context.Context) (err error) {
272 if tracing.IsEnabled() {
273 ctx = tracing.StartSpan(ctx, fqdn+"/InfoListResultPage.NextWithContext")
274 defer func() {
275 sc := -1
276 if page.Response().Response.Response != nil {
277 sc = page.Response().Response.Response.StatusCode
278 }
279 tracing.EndSpan(ctx, sc, err)
280 }()
281 }
282 for {
283 next, err := page.fn(ctx, page.ilr)
284 if err != nil {
285 return err
286 }
287 page.ilr = next
288 if !next.hasNextLink() || !next.IsEmpty() {
289 break
290 }
291 }
292 return nil
293 }
294
295
296
297
298 func (page *InfoListResultPage) Next() error {
299 return page.NextWithContext(context.Background())
300 }
301
302
303 func (page InfoListResultPage) NotDone() bool {
304 return !page.ilr.IsEmpty()
305 }
306
307
308 func (page InfoListResultPage) Response() InfoListResult {
309 return page.ilr
310 }
311
312
313 func (page InfoListResultPage) Values() []Information {
314 if page.ilr.IsEmpty() {
315 return nil
316 }
317 return *page.ilr.Value
318 }
319
320
321 func NewInfoListResultPage(cur InfoListResult, getNextPage func(context.Context, InfoListResult) (InfoListResult, error)) InfoListResultPage {
322 return InfoListResultPage{
323 fn: getNextPage,
324 ilr: cur,
325 }
326 }
327
328
329 type Information struct {
330 autorest.Response `json:"-"`
331
332 JobID *uuid.UUID `json:"jobId,omitempty"`
333
334 Name *string `json:"name,omitempty"`
335
336 Type TypeEnum `json:"type,omitempty"`
337
338 Submitter *string `json:"submitter,omitempty"`
339
340 ErrorMessage *[]ErrorDetails `json:"errorMessage,omitempty"`
341
342 DegreeOfParallelism *int32 `json:"degreeOfParallelism,omitempty"`
343
344 DegreeOfParallelismPercent *float64 `json:"degreeOfParallelismPercent,omitempty"`
345
346 Priority *int32 `json:"priority,omitempty"`
347
348 SubmitTime *date.Time `json:"submitTime,omitempty"`
349
350 StartTime *date.Time `json:"startTime,omitempty"`
351
352 EndTime *date.Time `json:"endTime,omitempty"`
353
354 State State `json:"state,omitempty"`
355
356 Result Result `json:"result,omitempty"`
357
358 StateAuditRecords *[]StateAuditRecord `json:"stateAuditRecords,omitempty"`
359
360 HierarchyQueueNode *string `json:"hierarchyQueueNode,omitempty"`
361
362 Properties BasicProperties `json:"properties,omitempty"`
363 }
364
365
366 func (i Information) MarshalJSON() ([]byte, error) {
367 objectMap := make(map[string]interface{})
368 if i.JobID != nil {
369 objectMap["jobId"] = i.JobID
370 }
371 if i.Name != nil {
372 objectMap["name"] = i.Name
373 }
374 if i.Type != "" {
375 objectMap["type"] = i.Type
376 }
377 if i.Submitter != nil {
378 objectMap["submitter"] = i.Submitter
379 }
380 if i.DegreeOfParallelism != nil {
381 objectMap["degreeOfParallelism"] = i.DegreeOfParallelism
382 }
383 if i.DegreeOfParallelismPercent != nil {
384 objectMap["degreeOfParallelismPercent"] = i.DegreeOfParallelismPercent
385 }
386 if i.Priority != nil {
387 objectMap["priority"] = i.Priority
388 }
389 objectMap["properties"] = i.Properties
390 return json.Marshal(objectMap)
391 }
392
393
394 func (i *Information) UnmarshalJSON(body []byte) error {
395 var m map[string]*json.RawMessage
396 err := json.Unmarshal(body, &m)
397 if err != nil {
398 return err
399 }
400 for k, v := range m {
401 switch k {
402 case "jobId":
403 if v != nil {
404 var jobID uuid.UUID
405 err = json.Unmarshal(*v, &jobID)
406 if err != nil {
407 return err
408 }
409 i.JobID = &jobID
410 }
411 case "name":
412 if v != nil {
413 var name string
414 err = json.Unmarshal(*v, &name)
415 if err != nil {
416 return err
417 }
418 i.Name = &name
419 }
420 case "type":
421 if v != nil {
422 var typeVar TypeEnum
423 err = json.Unmarshal(*v, &typeVar)
424 if err != nil {
425 return err
426 }
427 i.Type = typeVar
428 }
429 case "submitter":
430 if v != nil {
431 var submitter string
432 err = json.Unmarshal(*v, &submitter)
433 if err != nil {
434 return err
435 }
436 i.Submitter = &submitter
437 }
438 case "errorMessage":
439 if v != nil {
440 var errorMessage []ErrorDetails
441 err = json.Unmarshal(*v, &errorMessage)
442 if err != nil {
443 return err
444 }
445 i.ErrorMessage = &errorMessage
446 }
447 case "degreeOfParallelism":
448 if v != nil {
449 var degreeOfParallelism int32
450 err = json.Unmarshal(*v, °reeOfParallelism)
451 if err != nil {
452 return err
453 }
454 i.DegreeOfParallelism = °reeOfParallelism
455 }
456 case "degreeOfParallelismPercent":
457 if v != nil {
458 var degreeOfParallelismPercent float64
459 err = json.Unmarshal(*v, °reeOfParallelismPercent)
460 if err != nil {
461 return err
462 }
463 i.DegreeOfParallelismPercent = °reeOfParallelismPercent
464 }
465 case "priority":
466 if v != nil {
467 var priority int32
468 err = json.Unmarshal(*v, &priority)
469 if err != nil {
470 return err
471 }
472 i.Priority = &priority
473 }
474 case "submitTime":
475 if v != nil {
476 var submitTime date.Time
477 err = json.Unmarshal(*v, &submitTime)
478 if err != nil {
479 return err
480 }
481 i.SubmitTime = &submitTime
482 }
483 case "startTime":
484 if v != nil {
485 var startTime date.Time
486 err = json.Unmarshal(*v, &startTime)
487 if err != nil {
488 return err
489 }
490 i.StartTime = &startTime
491 }
492 case "endTime":
493 if v != nil {
494 var endTime date.Time
495 err = json.Unmarshal(*v, &endTime)
496 if err != nil {
497 return err
498 }
499 i.EndTime = &endTime
500 }
501 case "state":
502 if v != nil {
503 var state State
504 err = json.Unmarshal(*v, &state)
505 if err != nil {
506 return err
507 }
508 i.State = state
509 }
510 case "result":
511 if v != nil {
512 var resultVar Result
513 err = json.Unmarshal(*v, &resultVar)
514 if err != nil {
515 return err
516 }
517 i.Result = resultVar
518 }
519 case "stateAuditRecords":
520 if v != nil {
521 var stateAuditRecords []StateAuditRecord
522 err = json.Unmarshal(*v, &stateAuditRecords)
523 if err != nil {
524 return err
525 }
526 i.StateAuditRecords = &stateAuditRecords
527 }
528 case "hierarchyQueueNode":
529 if v != nil {
530 var hierarchyQueueNode string
531 err = json.Unmarshal(*v, &hierarchyQueueNode)
532 if err != nil {
533 return err
534 }
535 i.HierarchyQueueNode = &hierarchyQueueNode
536 }
537 case "properties":
538 if v != nil {
539 properties, err := unmarshalBasicProperties(*v)
540 if err != nil {
541 return err
542 }
543 i.Properties = properties
544 }
545 }
546 }
547
548 return nil
549 }
550
551
552 type InnerError struct {
553
554 DiagnosticCode *int32 `json:"diagnosticCode,omitempty"`
555
556 Severity SeverityTypes `json:"severity,omitempty"`
557
558 Details *string `json:"details,omitempty"`
559
560 Component *string `json:"component,omitempty"`
561
562 ErrorID *string `json:"errorId,omitempty"`
563
564 HelpLink *string `json:"helpLink,omitempty"`
565
566 InternalDiagnostics *string `json:"internalDiagnostics,omitempty"`
567
568 Message *string `json:"message,omitempty"`
569
570 Resolution *string `json:"resolution,omitempty"`
571
572 Source *string `json:"source,omitempty"`
573
574 Description *string `json:"description,omitempty"`
575 }
576
577
578 func (ie InnerError) MarshalJSON() ([]byte, error) {
579 objectMap := make(map[string]interface{})
580 return json.Marshal(objectMap)
581 }
582
583
584 type BasicProperties interface {
585 AsUSQLJobProperties() (*USQLJobProperties, bool)
586 AsHiveJobProperties() (*HiveJobProperties, bool)
587 AsProperties() (*Properties, bool)
588 }
589
590
591 type Properties struct {
592
593 RuntimeVersion *string `json:"runtimeVersion,omitempty"`
594
595 Script *string `json:"script,omitempty"`
596
597 Type Type `json:"type,omitempty"`
598 }
599
600 func unmarshalBasicProperties(body []byte) (BasicProperties, error) {
601 var m map[string]interface{}
602 err := json.Unmarshal(body, &m)
603 if err != nil {
604 return nil, err
605 }
606
607 switch m["type"] {
608 case string(TypeUSQL):
609 var usjp USQLJobProperties
610 err := json.Unmarshal(body, &usjp)
611 return usjp, err
612 case string(TypeHive):
613 var hjp HiveJobProperties
614 err := json.Unmarshal(body, &hjp)
615 return hjp, err
616 default:
617 var p Properties
618 err := json.Unmarshal(body, &p)
619 return p, err
620 }
621 }
622 func unmarshalBasicPropertiesArray(body []byte) ([]BasicProperties, error) {
623 var rawMessages []*json.RawMessage
624 err := json.Unmarshal(body, &rawMessages)
625 if err != nil {
626 return nil, err
627 }
628
629 pArray := make([]BasicProperties, len(rawMessages))
630
631 for index, rawMessage := range rawMessages {
632 p, err := unmarshalBasicProperties(*rawMessage)
633 if err != nil {
634 return nil, err
635 }
636 pArray[index] = p
637 }
638 return pArray, nil
639 }
640
641
642 func (p Properties) MarshalJSON() ([]byte, error) {
643 p.Type = TypeJobProperties
644 objectMap := make(map[string]interface{})
645 if p.RuntimeVersion != nil {
646 objectMap["runtimeVersion"] = p.RuntimeVersion
647 }
648 if p.Script != nil {
649 objectMap["script"] = p.Script
650 }
651 if p.Type != "" {
652 objectMap["type"] = p.Type
653 }
654 return json.Marshal(objectMap)
655 }
656
657
658 func (p Properties) AsUSQLJobProperties() (*USQLJobProperties, bool) {
659 return nil, false
660 }
661
662
663 func (p Properties) AsHiveJobProperties() (*HiveJobProperties, bool) {
664 return nil, false
665 }
666
667
668 func (p Properties) AsProperties() (*Properties, bool) {
669 return &p, true
670 }
671
672
673 func (p Properties) AsBasicProperties() (BasicProperties, bool) {
674 return &p, true
675 }
676
677
678 type Resource struct {
679
680 Name *string `json:"name,omitempty"`
681
682 ResourcePath *string `json:"resourcePath,omitempty"`
683
684 Type ResourceType `json:"type,omitempty"`
685 }
686
687
688
689 type StateAuditRecord struct {
690
691 NewState *string `json:"newState,omitempty"`
692
693 TimeStamp *date.Time `json:"timeStamp,omitempty"`
694
695 RequestedByUser *string `json:"requestedByUser,omitempty"`
696
697 Details *string `json:"details,omitempty"`
698 }
699
700
701 func (sar StateAuditRecord) MarshalJSON() ([]byte, error) {
702 objectMap := make(map[string]interface{})
703 return json.Marshal(objectMap)
704 }
705
706
707 type Statistics struct {
708 autorest.Response `json:"-"`
709
710 LastUpdateTimeUtc *date.Time `json:"lastUpdateTimeUtc,omitempty"`
711
712 Stages *[]StatisticsVertexStage `json:"stages,omitempty"`
713 }
714
715
716 func (s Statistics) MarshalJSON() ([]byte, error) {
717 objectMap := make(map[string]interface{})
718 return json.Marshal(objectMap)
719 }
720
721
722 type StatisticsVertexStage struct {
723
724 DataRead *int64 `json:"dataRead,omitempty"`
725
726 DataReadCrossPod *int64 `json:"dataReadCrossPod,omitempty"`
727
728 DataReadIntraPod *int64 `json:"dataReadIntraPod,omitempty"`
729
730 DataToRead *int64 `json:"dataToRead,omitempty"`
731
732 DataWritten *int64 `json:"dataWritten,omitempty"`
733
734 DuplicateDiscardCount *int32 `json:"duplicateDiscardCount,omitempty"`
735
736 FailedCount *int32 `json:"failedCount,omitempty"`
737
738 MaxVertexDataRead *int64 `json:"maxVertexDataRead,omitempty"`
739
740 MinVertexDataRead *int64 `json:"minVertexDataRead,omitempty"`
741
742 ReadFailureCount *int32 `json:"readFailureCount,omitempty"`
743
744 RevocationCount *int32 `json:"revocationCount,omitempty"`
745
746 RunningCount *int32 `json:"runningCount,omitempty"`
747
748 ScheduledCount *int32 `json:"scheduledCount,omitempty"`
749
750 StageName *string `json:"stageName,omitempty"`
751
752 SucceededCount *int32 `json:"succeededCount,omitempty"`
753
754 TempDataWritten *int64 `json:"tempDataWritten,omitempty"`
755
756 TotalCount *int32 `json:"totalCount,omitempty"`
757
758 TotalFailedTime *string `json:"totalFailedTime,omitempty"`
759
760 TotalProgress *int32 `json:"totalProgress,omitempty"`
761
762 TotalSucceededTime *string `json:"totalSucceededTime,omitempty"`
763 }
764
765
766 func (svs StatisticsVertexStage) MarshalJSON() ([]byte, error) {
767 objectMap := make(map[string]interface{})
768 return json.Marshal(objectMap)
769 }
770
771
772 type USQLJobProperties struct {
773
774 Resources *[]Resource `json:"resources,omitempty"`
775
776 Statistics *Statistics `json:"statistics,omitempty"`
777
778 DebugData *DataPath `json:"debugData,omitempty"`
779
780 AlgebraFilePath *string `json:"algebraFilePath,omitempty"`
781
782 TotalCompilationTime *string `json:"totalCompilationTime,omitempty"`
783
784 TotalPauseTime *string `json:"totalPauseTime,omitempty"`
785
786 TotalQueuedTime *string `json:"totalQueuedTime,omitempty"`
787
788 TotalRunningTime *string `json:"totalRunningTime,omitempty"`
789
790 RootProcessNodeID *string `json:"rootProcessNodeId,omitempty"`
791
792 YarnApplicationID *string `json:"yarnApplicationId,omitempty"`
793
794 YarnApplicationTimeStamp *int64 `json:"yarnApplicationTimeStamp,omitempty"`
795
796 CompileMode CompileMode `json:"compileMode,omitempty"`
797
798 RuntimeVersion *string `json:"runtimeVersion,omitempty"`
799
800 Script *string `json:"script,omitempty"`
801
802 Type Type `json:"type,omitempty"`
803 }
804
805
806 func (usjp USQLJobProperties) MarshalJSON() ([]byte, error) {
807 usjp.Type = TypeUSQL
808 objectMap := make(map[string]interface{})
809 if usjp.Resources != nil {
810 objectMap["resources"] = usjp.Resources
811 }
812 if usjp.Statistics != nil {
813 objectMap["statistics"] = usjp.Statistics
814 }
815 if usjp.DebugData != nil {
816 objectMap["debugData"] = usjp.DebugData
817 }
818 if usjp.CompileMode != "" {
819 objectMap["compileMode"] = usjp.CompileMode
820 }
821 if usjp.RuntimeVersion != nil {
822 objectMap["runtimeVersion"] = usjp.RuntimeVersion
823 }
824 if usjp.Script != nil {
825 objectMap["script"] = usjp.Script
826 }
827 if usjp.Type != "" {
828 objectMap["type"] = usjp.Type
829 }
830 return json.Marshal(objectMap)
831 }
832
833
834 func (usjp USQLJobProperties) AsUSQLJobProperties() (*USQLJobProperties, bool) {
835 return &usjp, true
836 }
837
838
839 func (usjp USQLJobProperties) AsHiveJobProperties() (*HiveJobProperties, bool) {
840 return nil, false
841 }
842
843
844 func (usjp USQLJobProperties) AsProperties() (*Properties, bool) {
845 return nil, false
846 }
847
848
849 func (usjp USQLJobProperties) AsBasicProperties() (BasicProperties, bool) {
850 return &usjp, true
851 }
852
View as plain text