Skip to content

Commit 6f930ca

Browse files
committed
Merge branch 'feature/cg-670-gcp-dataproc' into 'main'
Feature/cg-670-gcp-dataproc See merge request auto-cloud/cloudgraph/provider/cloudgraph-provider-gcp!41
2 parents 91f0ae9 + 5ea82a4 commit 6f930ca

33 files changed

Lines changed: 2307 additions & 25 deletions

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ CloudGraph GCP Provider will ask you what regions you would like to crawl and wi
7676
| cloudFunction | project, vpc |
7777
| cloudRouter | project |
7878
| computeProject | project |
79+
| dataprocClusters | project, dataprocJobs, dataprocWorkflowTemplate |
80+
| dataprocAutoscalingPolicies | project |
81+
| dataprocJobs | project, dataprocClusters |
82+
| dataprocWorkflowTemplate | project, dataprocClusters |
7983
| kmsCryptoKeys | iamPolicy, kmsKeyRing, project |
8084
| dnsManagedZone | project |
8185
| dnsPolicy | project, network |

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@cloudgraph/sdk": "^0.11.0",
3636
"@google-cloud/asset": "^3.22.0",
3737
"@google-cloud/compute": "^3.0.0",
38+
"@google-cloud/dataproc": "^3.2.0",
3839
"@google-cloud/dns": "^2.2.3",
3940
"@google-cloud/functions": "^1.2.0",
4041
"@google-cloud/kms": "^2.10.0",

src/enums/schemasMap.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ export default {
4040
[services.serviceAccount]: 'gcpServiceAccount',
4141
[services.apiKey]: 'gcpApiKey',
4242
[services.computeProject]: 'gcpComputeProject',
43+
[services.dataprocCluster]: 'gcpDataprocCluster',
44+
[services.dataprocAutoscalingPolicy]: 'gcpDataprocAutoscalingPolicy',
45+
[services.dataprocJob]: 'gcpDataprocJob',
46+
[services.dataprocWorkflowTemplate]: 'gcpDataprocWorkflowTemplate',
4347
tag: 'gcpTag',
4448
}

src/enums/serviceMap.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ import GcpSslPolicies from '../services/sslPolicy'
3636
import GcpServiceAccount from '../services/serviceAccount'
3737
import GcpApiKey from '../services/apiKey'
3838
import GcpComputeProject from '../services/computeProject'
39-
39+
import GcpDataprocCluster from '../services/dataprocCluster'
40+
import GcpDataprocAutoscalingPolicy from '../services/dataprocAutoscalingPolicy'
41+
import GcpDataprocJob from '../services/dataprocJob'
42+
import GcpDataprocWorkflowTemplate from '../services/dataprocWorkflowTemplate'
4043
/**
4144
* serviceMap is an object that contains all currently supported services
4245
* serviceMap is used by the serviceFactory to produce instances of service classes
@@ -78,5 +81,9 @@ export default {
7881
[services.serviceAccount]: GcpServiceAccount,
7982
[services.apiKey]: GcpApiKey,
8083
[services.computeProject]: GcpComputeProject,
84+
[services.dataprocCluster]: GcpDataprocCluster,
85+
[services.dataprocAutoscalingPolicy]: GcpDataprocAutoscalingPolicy,
86+
[services.dataprocJob]: GcpDataprocJob,
87+
[services.dataprocWorkflowTemplate]: GcpDataprocWorkflowTemplate,
8188
tag: GcpTag,
8289
}

src/enums/services.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export default {
2828
// composer: 'composer',
2929
// dataCatalog: 'data-catalog',
3030
// dataflow: 'dataflow',
31-
// dataproc: 'dataproc',
31+
dataprocCluster: 'dataprocClusters',
32+
dataprocAutoscalingPolicy: 'dataprocAutoscalingPolicies',
33+
dataprocJob: 'dataprocJobs',
34+
dataprocWorkflowTemplate: 'dataprocWorkflowTemplates',
3235
// metastore: 'metastore',
3336
// pubsub: 'pubsub',
3437
// bigtable: 'bigtable',

src/services/base/schema.graphql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ interface gcpBaseResource
1111
kind: String @search(by: [hash, regexp])
1212
labels: [gcpRawLabel]
1313
}
14+
15+
type gcpKeyValue
16+
@generate(
17+
query: { get: true, query: true, aggregate: true }
18+
mutation: { add: true, delete: false }
19+
subscription: false
20+
)
21+
@key(fields: "id") {
22+
id: String! @id @search(by: [hash])
23+
key: String! @search(by: [hash, regexp])
24+
value: String @search(by: [hash, regexp])
25+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { AutoscalingPolicyServiceClient } from '@google-cloud/dataproc'
2+
import CloudGraph from '@cloudgraph/sdk'
3+
import groupBy from 'lodash/groupBy'
4+
import { google } from '@google-cloud/dataproc/build/protos/protos'
5+
import gcpLoggerText from '../../properties/logger'
6+
import { GcpServiceInput } from '../../types'
7+
import { generateGcpErrorLog } from '../../utils'
8+
9+
const lt = { ...gcpLoggerText }
10+
const { logger } = CloudGraph
11+
const serviceName = 'Dataproc Autoscaling Policy'
12+
13+
export interface RawGcpDataprocAutoscalingPolicy extends Omit<google.cloud.dataproc.v1.IAutoscalingPolicy, 'id'|'labels'> {
14+
id: string
15+
region: string
16+
projectId: string
17+
Labels: { [key: string]: string }
18+
}
19+
20+
export default async ({
21+
regions,
22+
config,
23+
}: GcpServiceInput): Promise<{
24+
[region: string]: RawGcpDataprocAutoscalingPolicy[]
25+
}> => {
26+
const autoscalingPolicyList: RawGcpDataprocAutoscalingPolicy[] = []
27+
const { projectId } = config
28+
29+
for (const region of regions.split(',')) {
30+
/**
31+
* Get all the Dataproc Autoscaling Policies
32+
*/
33+
34+
try {
35+
const dataprocClient = new AutoscalingPolicyServiceClient({
36+
...config,
37+
apiEndpoint: `${region}-dataproc.googleapis.com`,
38+
projectId,
39+
})
40+
const locationName = dataprocClient.locationPath(projectId, region)
41+
const iterable = dataprocClient.listAutoscalingPoliciesAsync({
42+
parent: locationName,
43+
})
44+
for await (const { id, labels, ...response } of iterable) {
45+
if (response) {
46+
autoscalingPolicyList.push({
47+
...response,
48+
id,
49+
projectId,
50+
region,
51+
Labels: labels,
52+
})
53+
}
54+
}
55+
} catch (error) {
56+
generateGcpErrorLog(serviceName, 'dataprocAutoscalingPolicy:listAutoscalingPoliciesAsync', error)
57+
}
58+
}
59+
60+
logger.debug(lt.foundResources(serviceName, autoscalingPolicyList.length))
61+
return groupBy(autoscalingPolicyList, 'region')
62+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {
2+
GcpDataprocAutoscalingPolicy
3+
} from '../../types/generated'
4+
import { RawGcpDataprocAutoscalingPolicy } from './data'
5+
import { formatLabelsFromMap } from '../../utils/format'
6+
7+
export default ({
8+
service,
9+
region,
10+
}: {
11+
service: RawGcpDataprocAutoscalingPolicy
12+
region: string
13+
}): GcpDataprocAutoscalingPolicy => {
14+
const {
15+
id,
16+
projectId,
17+
name,
18+
basicAlgorithm = {},
19+
workerConfig = {},
20+
secondaryWorkerConfig = {},
21+
Labels = {},
22+
} = service
23+
24+
return {
25+
id,
26+
projectId,
27+
region,
28+
name,
29+
basicAlgorithmYarnConfigGracefulDecommissionTimeout: basicAlgorithm?.yarnConfig?.gracefulDecommissionTimeout?.seconds?.toString() || '',
30+
basicAlgorithmYarnConfigScaleUpFactor: basicAlgorithm?.yarnConfig?.scaleUpFactor || 0.0,
31+
basicAlgorithmYarnConfigScaleDownFactor: basicAlgorithm?.yarnConfig?.scaleDownFactor || 0.0,
32+
basicAlgorithmYarnConfigScaleUpMinWorkerFraction: basicAlgorithm?.yarnConfig?.scaleUpMinWorkerFraction || 0.0,
33+
basicAlgorithmYarnConfigScaleDownMinWorkerFraction: basicAlgorithm?.yarnConfig?.scaleDownMinWorkerFraction || 0.0,
34+
basicAlgorithmCooldownPeriod: basicAlgorithm?.cooldownPeriod?.seconds?.toString() || '',
35+
workerConfigMinInstances: workerConfig?.minInstances || 0,
36+
workerConfigMaxInstances: workerConfig?.maxInstances || 0,
37+
workerConfigWeight: workerConfig?.weight || 0,
38+
secondaryWorkerConfigMinInstances: secondaryWorkerConfig?.minInstances || 0,
39+
secondaryWorkerConfigMaxInstances: secondaryWorkerConfig?.maxInstances || 0,
40+
secondaryWorkerConfigWeight: secondaryWorkerConfig?.weight || 0,
41+
labels: formatLabelsFromMap(Labels),
42+
}
43+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Service} from '@cloudgraph/sdk'
2+
import BaseService from '../base'
3+
import format from './format'
4+
import getData from './data'
5+
import mutation from './mutation'
6+
7+
export default class GcpDataprocAutoscalingPolicy extends BaseService implements Service {
8+
format = format.bind(this)
9+
10+
getData = getData.bind(this)
11+
12+
mutation = mutation
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default `mutation($input: [AddgcpDataprocAutoscalingPolicyInput!]!) {
2+
addgcpDataprocAutoscalingPolicy(input: $input, upsert: true) {
3+
numUids
4+
}
5+
}`;

0 commit comments

Comments
 (0)