/
warmpathjob.go
84 lines (72 loc) · 2.42 KB
/
warmpathjob.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE-CODE in the project root for license information.
package cachewarmer
import (
"encoding/json"
"strings"
"github.com/Azure/azure-storage-queue-go/azqueue"
)
// WarmPathJob contains the information for a new job item
type WarmPathJob struct {
WarmTargetMountAddresses []string
WarmTargetExportPath string
WarmTargetPath string
InclusionList []string
ExclusionList []string
MaxFileSizeBytes int64
queueMessageID azqueue.MessageID
queuePopReceipt azqueue.PopReceipt
}
func (j *WarmPathJob) FileMatches(filename string, filesize int64) bool {
return FileMatches(j.InclusionList, j.ExclusionList, j.MaxFileSizeBytes, filename, filesize)
}
// InitializeWarmPathJob initializes the job submitter structure
func InitializeWarmPathJob(
warmTargetMountAddresses string,
warmTargetExportPath string,
warmTargetPath string,
inclusionCsv string,
exclusionCsv string,
maxFileSizeBytes int64) *WarmPathJob {
return &WarmPathJob{
WarmTargetMountAddresses: prepareCsvList(warmTargetMountAddresses),
WarmTargetExportPath: warmTargetExportPath,
WarmTargetPath: warmTargetPath,
InclusionList: prepareCsvList(inclusionCsv),
ExclusionList: prepareCsvList(exclusionCsv),
MaxFileSizeBytes: maxFileSizeBytes,
}
}
// InitializeWarmPathJobFromString reads warmPathJobContents
func InitializeWarmPathJobFromString(warmPathJobContents string) (*WarmPathJob, error) {
var result WarmPathJob
if err := json.Unmarshal([]byte(warmPathJobContents), &result); err != nil {
return nil, err
}
return &result, nil
}
// GetWarmPathJobFileContents returns the contents of the file
func (j *WarmPathJob) GetWarmPathJobFileContents() (string, error) {
data, err := json.Marshal(j)
if err != nil {
return "", err
}
return string(data), nil
}
func (j *WarmPathJob) SetQueueMessageInfo(id azqueue.MessageID, popReceipt azqueue.PopReceipt) {
j.queueMessageID = id
j.queuePopReceipt = popReceipt
}
func (j *WarmPathJob) GetQueueMessageInfo() (azqueue.MessageID, azqueue.PopReceipt) {
return j.queueMessageID, j.queuePopReceipt
}
func prepareCsvList(csv string) []string {
result := []string{}
for _, s := range strings.Split(csv, ",") {
trim := strings.TrimSpace(s)
if len(trim) > 0 {
result = append(result, trim)
}
}
return result
}