Skip to content

Commit 1744391

Browse files
authored
Google Cloud BigQuery bug fix (#18647)
* updates * updates * version * updates * updates * updates * move @google-cloud/compute import * versions * version
1 parent 8dcaa1b commit 1744391

File tree

17 files changed

+126
-111
lines changed

17 files changed

+126
-111
lines changed

components/google_cloud/actions/bigquery-insert-rows/bigquery-insert-rows.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import utils from "../../common/utils.mjs";
33

44
export default {
55
name: "Bigquery Insert Rows",
6-
version: "0.0.4",
6+
version: "0.0.5",
77
annotations: {
88
destructiveHint: false,
99
openWorldHint: true,

components/google_cloud/actions/create-bucket/create-bucket.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import storageClasses from "../../utils/storageClasses.mjs";
33

44
export default {
55
name: "Create Bucket",
6-
version: "0.0.4",
6+
version: "0.0.5",
77
annotations: {
88
destructiveHint: false,
99
openWorldHint: true,

components/google_cloud/actions/create-scheduled-query/create-scheduled-query.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
key: "google_cloud-create-scheduled-query",
1313
name: "Create Scheduled Query",
1414
description: "Creates a scheduled query in Google Cloud. [See the documentation](https://cloud.google.com/bigquery/docs/scheduling-queries)",
15-
version: "0.0.2",
15+
version: "0.0.3",
1616
annotations: {
1717
destructiveHint: false,
1818
openWorldHint: true,

components/google_cloud/actions/get-bucket/get-bucket.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import googleCloud from "../../google_cloud.app.mjs";
22

33
export default {
44
name: "Get Bucket Metadata",
5-
version: "0.0.5",
5+
version: "0.0.6",
66
annotations: {
77
destructiveHint: false,
88
openWorldHint: true,

components/google_cloud/actions/get-object/get-object.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import googleCloud from "../../google_cloud.app.mjs";
22

33
export default {
44
name: "Get Object",
5-
version: "0.0.4",
5+
version: "0.0.5",
66
annotations: {
77
destructiveHint: false,
88
openWorldHint: true,

components/google_cloud/actions/list-buckets/list-buckets.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import googleCloud from "../../google_cloud.app.mjs";
22

33
export default {
44
name: "List Buckets",
5-
version: "0.0.4",
5+
version: "0.0.5",
66
annotations: {
77
destructiveHint: false,
88
openWorldHint: true,

components/google_cloud/actions/logging-write-log/logging-write-log.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import logSeverity from "../../utils/logSeverity.mjs";
33

44
export default {
55
name: "Logging - Write Log",
6-
version: "0.0.5",
6+
version: "0.0.6",
77
annotations: {
88
destructiveHint: false,
99
openWorldHint: true,

components/google_cloud/actions/run-query/run-query.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import googleCloud from "../../google_cloud.app.mjs";
22

33
export default {
44
name: "Run Query",
5-
version: "0.0.2",
5+
version: "0.0.3",
66
annotations: {
77
destructiveHint: false,
88
openWorldHint: true,

components/google_cloud/actions/search-objects/search-objects.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import googleCloud from "../../google_cloud.app.mjs";
22

33
export default {
44
name: "Search Objects",
5-
version: "0.0.4",
5+
version: "0.0.5",
66
annotations: {
77
destructiveHint: false,
88
openWorldHint: true,

components/google_cloud/actions/switch-instance-boot-status/switch-instance-boot-status.mjs

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import googleCloud from "../../google_cloud.app.mjs";
2+
import {
3+
ZonesClient,
4+
ZoneOperationsClient,
5+
InstancesClient,
6+
} from "@google-cloud/compute";
7+
import { ConfigurationError } from "@pipedream/platform";
28

39
export default {
410
name: "Switch Instance Boot Status",
5-
version: "0.0.3",
11+
version: "0.0.4",
612
annotations: {
713
destructiveHint: true,
814
openWorldHint: true,
@@ -14,19 +20,23 @@ export default {
1420
props: {
1521
googleCloud,
1622
zone: {
17-
propDefinition: [
18-
googleCloud,
19-
"zoneName",
20-
],
23+
label: "Zone",
24+
description: "The unique zone name",
25+
type: "string",
26+
async options() {
27+
const zones = await this.listZones();
28+
return zones.map((item) => (item.name));
29+
},
2130
},
2231
instanceName: {
23-
propDefinition: [
24-
googleCloud,
25-
"instanceName",
26-
({ zone }) => ({
27-
zone,
28-
}),
29-
],
32+
label: "Instance Name",
33+
description: "The unique instance name",
34+
type: "string",
35+
async options({ zone }) {
36+
if (!zone) { return []; }
37+
const instances = await this.listVmInstancesByZone(zone);
38+
return instances.map((item) => (item.name));
39+
},
3040
},
3141
newInstanceStatus: {
3242
label: "New Instance Status",
@@ -44,6 +54,70 @@ export default {
4454
default: false,
4555
},
4656
},
57+
methods: {
58+
zonesClient() {
59+
return new ZonesClient(this.googleCloud.sdkParams());
60+
},
61+
zoneOperationsClient() {
62+
return new ZoneOperationsClient(this.googleCloud.sdkParams());
63+
},
64+
instancesClient() {
65+
return new InstancesClient(this.googleCloud.sdkParams());
66+
},
67+
async listZones() {
68+
const zonesClient = this.zonesClient();
69+
const sdkParams = this.googleCloud.sdkParams();
70+
const [
71+
zones,
72+
] = await zonesClient.list({
73+
project: sdkParams.projectId,
74+
});
75+
return zones;
76+
},
77+
async waitOperation(operation) {
78+
const operationsClient = this.zoneOperationsClient();
79+
const sdkParams = this.googleCloud.sdkParams();
80+
while (operation.status !== "DONE") {
81+
[
82+
operation,
83+
] = await operationsClient.wait({
84+
operation: operation.name,
85+
project: sdkParams.projectId,
86+
zone: operation.zone.split("/").pop(),
87+
});
88+
}
89+
return operation;
90+
},
91+
async listVmInstancesByZone(zone) {
92+
const instancesClient = this.instancesClient();
93+
const sdkParams = this.googleCloud.sdkParams();
94+
const [
95+
instances,
96+
] = await instancesClient.list({
97+
project: sdkParams.projectId,
98+
zone,
99+
});
100+
return instances;
101+
},
102+
async switchInstanceBootStatus(zone, instance, newStatus) {
103+
if (![
104+
"start",
105+
"stop",
106+
].includes(newStatus)) {
107+
throw new ConfigurationError("The new VM boot status must be 'start' or 'stop'.");
108+
}
109+
const instancesClient = this.instancesClient();
110+
const sdkParams = this.googleCloud.sdkParams();
111+
const [
112+
response,
113+
] = await instancesClient[newStatus]({
114+
project: sdkParams.projectId,
115+
zone,
116+
instance,
117+
});
118+
return response.latestResponse;
119+
},
120+
},
47121
async run({ $ }) {
48122
const {
49123
zone,
@@ -52,14 +126,14 @@ export default {
52126
newInstanceStatus,
53127
} = this;
54128

55-
let operation = await this.googleCloud.switchInstanceBootStatus(
129+
let operation = await this.switchInstanceBootStatus(
56130
zone,
57131
instanceName,
58132
newInstanceStatus,
59133
);
60134

61135
if (waitCompletion) {
62-
operation = await this.googleCloud.waitOperation(operation);
136+
operation = await this.waitOperation(operation);
63137
}
64138

65139
$.export("$summary", `Instance ${instanceName} boot status was set to ${newInstanceStatus}.`);

0 commit comments

Comments
 (0)