Skip to content

Commit b04a050

Browse files
committed
updates
1 parent 2153ac3 commit b04a050

File tree

7 files changed

+116
-111
lines changed

7 files changed

+116
-111
lines changed

components/databricks/actions/create-sql-warehouse/create-sql-warehouse.mjs

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import databricks from "../../databricks.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
import utils from "../../common/utils.mjs";
4+
import { ConfigurationError } from "@pipedream/platform";
25

36
export default {
47
key: "databricks-create-sql-warehouse",
@@ -17,17 +20,7 @@ export default {
1720
type: "string",
1821
label: "Cluster Size",
1922
description: "Size of the cluster",
20-
options: [
21-
"2X-Small",
22-
"X-Small",
23-
"Small",
24-
"Medium",
25-
"Large",
26-
"X-Large",
27-
"2X-Large",
28-
"3X-Large",
29-
"4X-Large",
30-
],
23+
options: constants.CLUSTER_SIZES,
3124
},
3225
autoStopMinutes: {
3326
type: "integer",
@@ -93,20 +86,10 @@ export default {
9386
optional: true,
9487
},
9588
tags: {
96-
type: "object[]",
89+
type: "object",
9790
label: "Tags",
9891
description:
9992
"Custom key-value tags for resources associated with this SQL Warehouse.",
100-
properties: {
101-
key: {
102-
type: "string",
103-
label: "Key",
104-
},
105-
value: {
106-
type: "string",
107-
label: "Value",
108-
},
109-
},
11093
optional: true,
11194
},
11295
instanceProfileArn: {
@@ -125,14 +108,14 @@ export default {
125108

126109
if (this.autoStopMinutes !== undefined) {
127110
if (this.autoStopMinutes !== 0 && this.autoStopMinutes < 10) {
128-
throw new Error("autoStopMinutes must be 0 or ≥ 10.");
111+
throw new ConfigurationError("autoStopMinutes must be 0 or ≥ 10.");
129112
}
130113
payload.auto_stop_mins = this.autoStopMinutes;
131114
}
132115

133116
const minNumClusters = this.minNumClusters ?? 1;
134117
if (minNumClusters < 1 || minNumClusters > 30) {
135-
throw new Error("minNumClusters must be between 1 and 30.");
118+
throw new ConfigurationError("minNumClusters must be between 1 and 30.");
136119
}
137120
payload.min_num_clusters = minNumClusters;
138121

@@ -141,24 +124,31 @@ export default {
141124
this.maxNumClusters < payload.min_num_clusters ||
142125
this.maxNumClusters > 30
143126
) {
144-
throw new Error(
127+
throw new ConfigurationError(
145128
`maxNumClusters must be ≥ minNumClusters (${payload.min_num_clusters}) and ≤ 30.`,
146129
);
147130
}
148131
payload.max_num_clusters = this.maxNumClusters;
149132
}
150133

134+
const parsedTags = utils.parseObject(this.tags);
135+
const tags = Object.entries(parsedTags).map(([
136+
key,
137+
value,
138+
]) => ({
139+
key,
140+
value,
141+
}));
142+
151143
if (this.enablePhoton !== undefined)
152144
payload.enable_photon = this.enablePhoton;
153145
if (this.enableServerlessCompute !== undefined)
154146
payload.enable_serverless_compute = this.enableServerlessCompute;
155147
if (this.warehouseType) payload.warehouse_type = this.warehouseType;
156148
if (this.spotInstancePolicy)
157149
payload.spot_instance_policy = this.spotInstancePolicy;
158-
if (this.channel) payload.channel = this.channel;
159-
if (this.tags?.length) payload.tags = {
160-
custom_tags: this.tags,
161-
};
150+
if (this.channel) payload.channel = utils.parseObject(this.channel);
151+
if (tags.length) payload.tags = tags;
162152
if (this.instanceProfileArn)
163153
payload.instance_profile_arn = this.instanceProfileArn;
164154

components/databricks/actions/edit-sql-warehouse/edit-sql-warehouse.mjs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import databricks from "../../databricks.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
import utils from "../../common/utils.mjs";
4+
import { ConfigurationError } from "@pipedream/platform";
25

36
export default {
47
key: "databricks-edit-sql-warehouse",
58
name: "Edit SQL Warehouse",
6-
description: "Edits the configuration of an existing SQL Warehouse. [See docs](https://docs.databricks.com/api/workspace/warehouses/edit)",
9+
description: "Edits the configuration of an existing SQL Warehouse. [See the documentation](https://docs.databricks.com/api/workspace/warehouses/edit)",
710
version: "0.0.1",
811
type: "action",
912
props: {
@@ -25,17 +28,7 @@ export default {
2528
type: "string",
2629
label: "Cluster Size",
2730
description: "Size of clusters allocated for this warehouse.",
28-
options: [
29-
"2X-Small",
30-
"X-Small",
31-
"Small",
32-
"Medium",
33-
"Large",
34-
"X-Large",
35-
"2X-Large",
36-
"3X-Large",
37-
"4X-Large",
38-
],
31+
options: constants.CLUSTER_SIZES,
3932
optional: true,
4033
},
4134
autoStopMins: {
@@ -114,56 +107,65 @@ export default {
114107

115108
if (this.name !== undefined) {
116109
if (typeof this.name !== "string" || this.name.length >= 100) {
117-
throw new Error("name must be a string with fewer than 100 characters.");
110+
throw new ConfigurationError("name must be a string with fewer than 100 characters.");
118111
}
119112
payload.name = this.name;
120113
}
121114
if (this.clusterSize !== undefined) payload.cluster_size = this.clusterSize;
122115

123116
if (this.autoStopMins !== undefined) {
124117
if (this.autoStopMins !== 0 && this.autoStopMins < 10) {
125-
throw new Error("autoStopMins must be 0 or >= 10.");
118+
throw new ConfigurationError("autoStopMins must be 0 or >= 10.");
126119
}
127120
payload.auto_stop_mins = this.autoStopMins;
128121
}
129122

130123
if (this.minNumClusters !== undefined) {
131124
if (this.minNumClusters < 1 || this.minNumClusters > 30) {
132-
throw new Error("minNumClusters must be between 1 and 30.");
125+
throw new ConfigurationError("minNumClusters must be between 1 and 30.");
133126
}
134127
payload.min_num_clusters = this.minNumClusters;
135128
}
136129

137130
if (this.maxNumClusters !== undefined) {
138131
if (this.maxNumClusters < 1 || this.maxNumClusters > 30) {
139-
throw new Error("maxNumClusters must be between 1 and 30.");
132+
throw new ConfigurationError("maxNumClusters must be between 1 and 30.");
140133
}
141134
if (this.minNumClusters !== undefined && this.maxNumClusters < this.minNumClusters) {
142-
throw new Error("maxNumClusters must be >= minNumClusters.");
135+
throw new ConfigurationError("maxNumClusters must be >= minNumClusters.");
143136
}
144137
payload.max_num_clusters = this.maxNumClusters;
145138
}
146139

147140
if (this.enablePhoton !== undefined) payload.enable_photon = this.enablePhoton;
148141
if (this.enableServerlessCompute !== undefined) {
149142
if (this.warehouseType === "CLASSIC" && this.enableServerlessCompute) {
150-
throw new Error("Serverless compute requires warehouseType = PRO.");
143+
throw new ConfigurationError("Serverless compute requires warehouseType = PRO.");
151144
}
152145
payload.enable_serverless_compute = this.enableServerlessCompute;
153146
}
154147

148+
const parsedTags = utils.parseObject(this.tags);
149+
const tags = Object.entries(parsedTags).map(([
150+
key,
151+
value,
152+
]) => ({
153+
key,
154+
value,
155+
}));
156+
155157
if (this.warehouseType !== undefined) payload.warehouse_type = this.warehouseType;
156158
if (this.spotInstancePolicy !== undefined) {
157159
payload.spot_instance_policy = this.spotInstancePolicy;
158160
}
159-
if (this.tags !== undefined) payload.tags = this.tags;
160-
if (this.channel !== undefined) payload.channel = this.channel;
161+
if (tags.length) payload.tags = tags;
162+
if (this.channel !== undefined) payload.channel = utils.parseObject(this.channel);
161163
if (this.instanceProfileArn !== undefined) {
162164
payload.instance_profile_arn = this.instanceProfileArn;
163165
}
164166

165167
if (!Object.keys(payload).length) {
166-
throw new Error("No fields to update. Provide at least one property.");
168+
throw new ConfigurationError("No fields to update. Provide at least one property.");
167169
}
168170

169171
const response = await this.databricks.editSQLWarehouse({

components/databricks/actions/get-sql-warehouse-config/get-sql-warehouse-config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import databricks from "../../databricks.app.mjs";
33
export default {
44
key: "databricks-get-sql-warehouse-config",
55
name: "Get SQL Warehouse Config",
6-
description: "Retrieves the global configuration for SQL Warehouses. [See docs](https://docs.databricks.com/api/workspace/warehouses/getworkspacewarehouseconfig)",
6+
description: "Retrieves the global configuration for SQL Warehouses. [See the documentation](https://docs.databricks.com/api/workspace/warehouses/getworkspacewarehouseconfig)",
77
version: "0.0.1",
88
type: "action",
99
props: {

components/databricks/actions/get-sql-warehouse-permissions/get-sql-warehouse-permissions.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import databricks from "../../databricks.app.mjs";
33
export default {
44
key: "databricks-get-sql-warehouse-permissions",
55
name: "Get SQL Warehouse Permissions",
6-
description: "Retrieves the permissions for a specific SQL Warehouse. [See docs](https://docs.databricks.com/api/workspace/warehouses/getpermissions)",
6+
description: "Retrieves the permissions for a specific SQL Warehouse. [See the documentation](https://docs.databricks.com/api/workspace/warehouses/getpermissions)",
77
version: "0.0.1",
88
type: "action",
99
props: {

components/databricks/actions/set-sql-warehouse-config/set-sql-warehouse-config.mjs

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import databricks from "../../databricks.app.mjs";
2+
import utils from "../../common/utils.mjs";
3+
import { ConfigurationError } from "@pipedream/platform";
24

35
export default {
46
key: "databricks-set-sql-warehouse-config",
57
name: "Set SQL Warehouse Config",
6-
description: "Updates the global configuration for SQL Warehouses. [See docs](https://docs.databricks.com/api/workspace/warehouses/setworkspacewarehouseconfig)",
8+
description: "Updates the global configuration for SQL Warehouses. [See the documentation](https://docs.databricks.com/api/workspace/warehouses/setworkspacewarehouseconfig)",
79
version: "0.0.1",
810
type: "action",
911
props: {
@@ -44,67 +46,27 @@ export default {
4446
optional: true,
4547
},
4648
configParam: {
47-
type: "object[]",
49+
type: "object",
4850
label: "Config Parameters",
4951
description: "General config key/value pairs. Example item: `{ \"key\": \"some.config\", \"value\": \"true\" }`",
50-
properties: {
51-
key: {
52-
type: "string",
53-
label: "Key",
54-
},
55-
value: {
56-
type: "string",
57-
label: "Value",
58-
},
59-
},
6052
optional: true,
6153
},
6254
globalParam: {
63-
type: "object[]",
55+
type: "object",
6456
label: "Global Parameters",
6557
description: "Global config key/value pairs applied to all warehouses.",
66-
properties: {
67-
key: {
68-
type: "string",
69-
label: "Key",
70-
},
71-
value: {
72-
type: "string",
73-
label: "Value",
74-
},
75-
},
7658
optional: true,
7759
},
7860
sqlConfigurationParameters: {
79-
type: "object[]",
61+
type: "object",
8062
label: "SQL Configuration Parameters",
8163
description: "SQL-specific configuration key/value pairs.",
82-
properties: {
83-
key: {
84-
type: "string",
85-
label: "Key",
86-
},
87-
value: {
88-
type: "string",
89-
label: "Value",
90-
},
91-
},
9264
optional: true,
9365
},
9466
dataAccessConfig: {
95-
type: "object[]",
67+
type: "object",
9668
label: "Data Access Config",
9769
description: "Key/value pairs for data access configuration (e.g., credentials passthrough, external storage access).",
98-
properties: {
99-
key: {
100-
type: "string",
101-
label: "Key",
102-
},
103-
value: {
104-
type: "string",
105-
label: "Value",
106-
},
107-
},
10870
optional: true,
10971
},
11072
},
@@ -140,48 +102,53 @@ export default {
140102
payload.security_policy = this.securityPolicy;
141103
}
142104
if (this.channel !== undefined) {
143-
payload.channel = this.channel;
105+
payload.channel = utils.parseObject(this.channel);
144106
}
145-
if (Array.isArray(this.enabledWarehouseTypes) && this.enabledWarehouseTypes.length) {
146-
payload.enabled_warehouse_types = this.enabledWarehouseTypes.map((item, idx) => {
107+
const enabledWarehouseTypes = utils.parseObject(this.enabledWarehouseTypes);
108+
if (Array.isArray(enabledWarehouseTypes) && enabledWarehouseTypes.length) {
109+
payload.enabled_warehouse_types = enabledWarehouseTypes.map((item, idx) => {
147110
let obj = item;
148111
if (typeof item === "string") {
149112
try { obj = JSON.parse(item); } catch (e) {
150-
throw new Error(`enabledWarehouseTypes[${idx}] must be valid JSON: ${e.message}`);
113+
throw new ConfigurationError(`enabledWarehouseTypes[${idx}] must be valid JSON: ${e.message}`);
151114
}
152115
}
153116
if (!obj || typeof obj !== "object") {
154-
throw new Error(`enabledWarehouseTypes[${idx}] must be an object with { "warehouse_type": string, "enabled": boolean }`);
117+
throw new ConfigurationError(`enabledWarehouseTypes[${idx}] must be an object with { "warehouse_type": string, "enabled": boolean }`);
155118
}
156119
const {
157120
warehouse_type, enabled,
158121
} = obj;
159122
if (typeof warehouse_type !== "string" || typeof enabled !== "boolean") {
160-
throw new Error(`enabledWarehouseTypes[${idx}] invalid shape; expected { "warehouse_type": string, "enabled": boolean }`);
123+
throw new ConfigurationError(`enabledWarehouseTypes[${idx}] invalid shape; expected { "warehouse_type": string, "enabled": boolean }`);
161124
}
162125
return {
163126
warehouse_type,
164127
enabled: Boolean(enabled),
165128
};
166129
});
167130
}
168-
if (Array.isArray(this.configParam) && this.configParam.length) {
131+
const configParam = utils.parseObject(this.configParam);
132+
if (Array.isArray(configParam) && configParam.length) {
169133
payload.config_param = {
170-
configuration_pairs: this.configParam,
134+
configuration_pairs: configParam,
171135
};
172136
}
173-
if (Array.isArray(this.globalParam) && this.globalParam.length) {
137+
const globalParam = utils.parseObject(this.globalParam);
138+
if (Array.isArray(globalParam) && globalParam.length) {
174139
payload.global_param = {
175-
configuration_pairs: this.globalParam,
140+
configuration_pairs: globalParam,
176141
};
177142
}
178-
if (Array.isArray(this.sqlConfigurationParameters) && this.sqlConfigurationParameters.length) {
143+
const sqlConfigurationParameters = utils.parseObject(this.sqlConfigurationParameters);
144+
if (Array.isArray(sqlConfigurationParameters) && sqlConfigurationParameters.length) {
179145
payload.sql_configuration_parameters = {
180-
configuration_pairs: this.sqlConfigurationParameters,
146+
configuration_pairs: sqlConfigurationParameters,
181147
};
182148
}
183-
if (Array.isArray(this.dataAccessConfig) && this.dataAccessConfig.length) {
184-
payload.data_access_config = this.dataAccessConfig;
149+
const dataAccessConfig = utils.parseObject(this.dataAccessConfig);
150+
if (Array.isArray(dataAccessConfig) && dataAccessConfig.length) {
151+
payload.data_access_config = dataAccessConfig;
185152
}
186153
const response = await this.databricks.setSQLWarehouseConfig({
187154
data: payload,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const CLUSTER_SIZES = [
2+
"2X-Small",
3+
"X-Small",
4+
"Small",
5+
"Medium",
6+
"Large",
7+
"X-Large",
8+
"2X-Large",
9+
"3X-Large",
10+
"4X-Large",
11+
];
12+
13+
export default {
14+
CLUSTER_SIZES,
15+
};

0 commit comments

Comments
 (0)