/
DataLakeLeaseClient.ts
153 lines (144 loc) · 3.73 KB
/
DataLakeLeaseClient.ts
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { BlobLeaseClient } from "@azure/storage-blob";
import { CanonicalCode } from "@opentelemetry/api";
import { Lease, LeaseOperationOptions, LeaseOperationResponse } from "./models";
import { createSpan } from "./utils/tracing";
export class DataLakeLeaseClient {
public get leaseId(): string {
return this.client.leaseId;
}
public get url(): string {
return this.client.url;
}
constructor(private readonly client: BlobLeaseClient) {}
public async acquireLease(
duration: number,
options: LeaseOperationOptions = {}
): Promise<LeaseOperationResponse> {
options.conditions = options.conditions || {};
const { span, spanOptions } = createSpan(
"DataLakeLeaseClient-acquireLease",
options.tracingOptions
);
try {
return await this.client.acquireLease(duration, {
...options,
tracingOptions: {
...options.tracingOptions,
spanOptions
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
public async changeLease(
proposedLeaseId: string,
options: LeaseOperationOptions = {}
): Promise<LeaseOperationResponse> {
options.conditions = options.conditions || {};
const { span, spanOptions } = createSpan(
"DataLakeLeaseClient-changeLease",
options.tracingOptions
);
try {
return await this.client.changeLease(proposedLeaseId, {
...options,
tracingOptions: {
...options.tracingOptions,
spanOptions
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
public async releaseLease(options: LeaseOperationOptions = {}): Promise<LeaseOperationResponse> {
options.conditions = options.conditions || {};
const { span, spanOptions } = createSpan(
"DataLakeLeaseClient-releaseLease",
options.tracingOptions
);
try {
return await this.client.releaseLease({
...options,
tracingOptions: {
...options.tracingOptions,
spanOptions
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
public async renewLease(options: LeaseOperationOptions = {}): Promise<Lease> {
options.conditions = options.conditions || {};
const { span, spanOptions } = createSpan(
"DataLakeLeaseClient-renewLease",
options.tracingOptions
);
try {
return await this.client.renewLease({
...options,
tracingOptions: {
...options.tracingOptions,
spanOptions
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
public async breakLease(
breakPeriod: number,
options: LeaseOperationOptions = {}
): Promise<LeaseOperationResponse> {
options.conditions = options.conditions || {};
const { span, spanOptions } = createSpan(
"DataLakeLeaseClient-renewLease",
options.tracingOptions
);
try {
return await this.client.breakLease(breakPeriod, {
...options,
tracingOptions: {
...options.tracingOptions,
spanOptions
}
});
} catch (e) {
span.setStatus({
code: CanonicalCode.UNKNOWN,
message: e.message
});
throw e;
} finally {
span.end();
}
}
}