-
Notifications
You must be signed in to change notification settings - Fork 2.9k
migrate code from googleapis/java-dataproc #7407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
112 commits
Select commit
Hold shift + click to select a range
fca7fa4
samples: scaffold pom.xml files (#97)
yoshi-automation 938b016
chore(deps): update dependency com.google.cloud:libraries-bom to v4.3…
renovate-bot c906cf2
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot 34c6d0b
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot c83e938
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot f7e0446
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot 15f9d61
chore(deps): update dependency com.google.cloud:libraries-bom to v4.4…
renovate-bot a81072b
chore(deps): update dependency com.google.cloud:libraries-bom to v5 (…
renovate-bot 2695478
chore(deps): update dependency com.google.cloud:libraries-bom to v5.1…
renovate-bot 59e2093
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot 1ff149a
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot f44ab35
chore(deps): update dependency com.google.cloud:libraries-bom to v5.2…
renovate-bot 161e194
chore(deps): update dependency com.google.cloud:libraries-bom to v5.3…
renovate-bot 22f21b6
chore(deps): update dependency com.google.cloud:libraries-bom to v5.4…
renovate-bot 05b1c80
chore(deps): update dependency com.google.cloud:libraries-bom to v5.5…
renovate-bot 5f09fc3
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot 05d9509
chore(deps): update dependency com.google.cloud:libraries-bom to v5.7…
renovate-bot 829c1b6
chore(deps): update dependency com.google.cloud:libraries-bom to v6 (…
renovate-bot 1b3b4ad
chore(deps): update dependency com.google.cloud:libraries-bom to v7 (…
renovate-bot c2aedf0
chore(deps): update dependency com.google.cloud:libraries-bom to v7.0…
renovate-bot 5a79004
chore(deps): update dependency com.google.cloud:libraries-bom to v8 (…
renovate-bot 4ce6a1c
chore(deps): update dependency com.google.cloud:libraries-bom to v8.1…
renovate-bot 0baedc3
samples: feat: adding CreateCluster sample for Dataproc (#1734)
bradmiro 1d2fb6b
samples: fix: small updates to dataproc sample, test and pom (#1738)
bradmiro f78f8c0
samples: feat: dataproc quickstart and createcluster (#1908)
bradmiro b69fe54
samples: feat: add cli functionality to dataproc quickstart (#2047)
bradmiro 0bd96fd
samples: feat: dataproc instantiate inline workflow sample (#2360)
bradmiro 351dfb5
samples: changed template tag (#2532)
bradmiro 4f1ec2c
samples: feat: adding hadoopfs and autoscaling samples (#3262)
bradmiro bd3d1f2
samples(test): fix required dependencies for tests
chingor13 a665f79
docs: change relative URLs to absolute URLs to fix broken links. (#260)
yoshi-automation 0f36d67
chore(deps): update dependency com.google.cloud:libraries-bom to v9 (…
renovate-bot ba919ea
chore(deps): update dependency com.google.cloud:libraries-bom to v9.1.0
renovate-bot c8fcaa3
chore(deps): update dependency com.google.cloud:libraries-bom to v10
renovate-bot 3f68184
adding submit job sample and updating submit job in quickstart (#284)
bradmiro 1a60125
removed extra old code (#285)
bradmiro b01d8a1
chore(deps): update dependency com.google.cloud:libraries-bom to v11
renovate-bot 1257f16
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot 9990846
chore(deps): update dependency com.google.cloud:libraries-bom to v12 …
renovate-bot 155ddd0
test(deps): update dependency junit:junit to v4.13.1
renovate-bot bd46e22
chore(deps): update dependency com.google.cloud:libraries-bom to v12.…
renovate-bot 1e1dfc8
chore(deps): update dependency com.google.cloud:libraries-bom to v13 …
renovate-bot 348c95a
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot d9e181e
test(deps): update dependency com.google.truth:truth to v1.1 (#333)
renovate-bot 8e03207
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot 885e015
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot 8792acc
chore(deps): update dependency com.google.cloud:libraries-bom to v13.…
renovate-bot cd05c81
chore(deps): update dependency com.google.cloud:libraries-bom to v14 …
renovate-bot 7e62bc9
chore(deps): update dependency com.google.cloud:libraries-bom to v15 …
renovate-bot b2f760d
chore(deps): update dependency com.google.cloud:libraries-bom to v15.…
renovate-bot f13b320
chore(deps): update dependency com.google.cloud:libraries-bom to v16 …
renovate-bot 5801062
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot 71a8097
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot 58548f8
test(deps): update dependency com.google.truth:truth to v1.1.2 (#424)
renovate-bot 157ddc4
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot 618cd7e
chore(deps): update dependency com.google.cloud:libraries-bom to v16.…
renovate-bot 284539c
test(deps): update dependency junit:junit to v4.13.2 (#441)
renovate-bot f8adbb2
chore(deps): update dependency com.google.cloud:libraries-bom to v17 …
renovate-bot 8515207
chore(deps): update dependency com.google.cloud:libraries-bom to v18 …
renovate-bot f52b593
chore(deps): update dependency com.google.cloud:libraries-bom to v18.…
renovate-bot 877c45b
chore(deps): update dependency com.google.cloud:libraries-bom to v19 …
renovate-bot afe42c4
chore(deps): update dependency com.google.cloud:libraries-bom to v19.…
renovate-bot da75d1d
chore(deps): update dependency com.google.cloud:libraries-bom to v19.…
renovate-bot 7ac57a0
fixing machine type for new default image (#490)
bradmiro e306550
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot 807c130
chore(deps): update dependency com.google.cloud:libraries-bom to v20 …
renovate-bot e37b86a
chore: update QuickstartTest to use StdOutCaptureRule (#376)
BenWhitehead 5528b52
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot b19dd8e
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot c8b6c19
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot 7678388
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot e3c0d6c
test(deps): update dependency com.google.truth:truth to v1.1.3 (#561)
renovate-bot 7993408
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot c5f9253
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot e69d7ca
chore: migrate to owlbot (#582)
Neenu1995 31e3e9d
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot 346e69d
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot 8770076
chore(deps): update dependency com.google.cloud:libraries-bom to v20.…
renovate-bot dacc938
chore(deps): update dependency com.google.cloud:libraries-bom to v21 …
renovate-bot 6ee7252
chore(deps): update dependency com.google.cloud:libraries-bom to v22 …
renovate-bot 20e4b58
chore(deps): update dependency com.google.cloud:libraries-bom to v23 …
renovate-bot a430fd2
chore(deps): update dependency com.google.cloud:libraries-bom to v23.…
renovate-bot 50fca8e
chore(deps): update dependency com.google.cloud:libraries-bom to v24 …
renovate-bot 75c1a94
chore(deps): update dependency com.google.cloud.samples:shared-config…
renovate-bot e4930ea
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot e069415
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot 2086a6a
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot 16145f8
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot fb21dbd
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot 6a45dc3
build(deps): update dependency org.sonatype.plugins:nexus-staging-mav…
renovate-bot d9e7263
build(deps): update dependency org.sonatype.plugins:nexus-staging-mav…
renovate-bot c3311d0
build(deps): update dependency org.sonatype.plugins:nexus-staging-mav…
renovate-bot 5ae4c1f
chore(deps): update dependency com.google.cloud:libraries-bom to v24.…
renovate-bot 31a40e8
chore(deps): update dependency com.google.cloud:libraries-bom to v25 …
renovate-bot 48f8684
sample: changes in three tests to resolve flaky tests and presubmit e…
loferris 2e39e10
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot 6868ea9
build(deps): update dependency org.sonatype.plugins:nexus-staging-mav…
renovate-bot 693dc8d
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot 1323c4d
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot 2081b75
chore(deps): update dependency com.google.cloud:libraries-bom to v25.…
renovate-bot 563394e
chore(deps): update dependency com.google.cloud:libraries-bom to v26 …
renovate-bot 24430ea
build(deps): update dependency org.apache.maven.plugins:maven-deploy-…
renovate-bot 95e0c80
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot 08c8889
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot 2315677
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot 38ea218
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot 6cdf935
Merge remote-tracking branch 'migration/main' into java-dataproc-migr…
bourgeoisor ba3bca3
Remove generated from POM
bourgeoisor ec7759b
Move dataproc snippets one dir up
bourgeoisor 188bf81
Fix inclusive language
bourgeoisor 8ab79f4
Fix POM description
bourgeoisor 6714d3b
Revert "Fix inclusive language"
bourgeoisor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.example.dataproc</groupId> | ||
<artifactId>dataproc-snippets</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Google Dataproc Snippets</name> | ||
<url>https://github.com/GoogleCloudPlatform/java-docs-samples/tree/main/dataproc</url> | ||
|
||
<!-- | ||
The parent pom defines common style checks and testing strategies for our samples. | ||
Removing or replacing it should not affect the execution of the samples in anyway. | ||
--> | ||
<parent> | ||
<groupId>com.google.cloud.samples</groupId> | ||
<artifactId>shared-configuration</artifactId> | ||
<version>1.2.0</version> | ||
</parent> | ||
|
||
<properties> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
|
||
<!-- [START dataproc_install_with_bom] --> | ||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>libraries-bom</artifactId> | ||
<version>26.1.3</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-dataproc</artifactId> | ||
</dependency> | ||
<!-- [START_EXCLUDE] --> | ||
<dependency> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>google-cloud-storage</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.13.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.truth</groupId> | ||
<artifactId>truth</artifactId> | ||
<version>1.1.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- [END_EXCLUDE] --> | ||
</dependencies> | ||
<!-- [END dataproc_install_with_bom] --> | ||
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// [START dataproc_create_cluster] | ||
import com.google.api.gax.longrunning.OperationFuture; | ||
import com.google.cloud.dataproc.v1.Cluster; | ||
import com.google.cloud.dataproc.v1.ClusterConfig; | ||
import com.google.cloud.dataproc.v1.ClusterControllerClient; | ||
import com.google.cloud.dataproc.v1.ClusterControllerSettings; | ||
import com.google.cloud.dataproc.v1.ClusterOperationMetadata; | ||
import com.google.cloud.dataproc.v1.InstanceGroupConfig; | ||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class CreateCluster { | ||
|
||
public static void createCluster() throws IOException, InterruptedException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String projectId = "your-project-id"; | ||
String region = "your-project-region"; | ||
String clusterName = "your-cluster-name"; | ||
createCluster(projectId, region, clusterName); | ||
} | ||
|
||
public static void createCluster(String projectId, String region, String clusterName) | ||
throws IOException, InterruptedException { | ||
String myEndpoint = String.format("%s-dataproc.googleapis.com:443", region); | ||
|
||
// Configure the settings for the cluster controller client. | ||
ClusterControllerSettings clusterControllerSettings = | ||
ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build(); | ||
|
||
// Create a cluster controller client with the configured settings. The client only needs to be | ||
// created once and can be reused for multiple requests. Using a try-with-resources | ||
// closes the client, but this can also be done manually with the .close() method. | ||
try (ClusterControllerClient clusterControllerClient = | ||
ClusterControllerClient.create(clusterControllerSettings)) { | ||
// Configure the settings for our cluster. | ||
InstanceGroupConfig masterConfig = | ||
InstanceGroupConfig.newBuilder() | ||
.setMachineTypeUri("n1-standard-2") | ||
.setNumInstances(1) | ||
.build(); | ||
InstanceGroupConfig workerConfig = | ||
InstanceGroupConfig.newBuilder() | ||
.setMachineTypeUri("n1-standard-2") | ||
.setNumInstances(2) | ||
.build(); | ||
ClusterConfig clusterConfig = | ||
ClusterConfig.newBuilder() | ||
.setMasterConfig(masterConfig) | ||
.setWorkerConfig(workerConfig) | ||
.build(); | ||
// Create the cluster object with the desired cluster config. | ||
Cluster cluster = | ||
Cluster.newBuilder().setClusterName(clusterName).setConfig(clusterConfig).build(); | ||
|
||
// Create the Cloud Dataproc cluster. | ||
OperationFuture<Cluster, ClusterOperationMetadata> createClusterAsyncRequest = | ||
clusterControllerClient.createClusterAsync(projectId, region, cluster); | ||
Cluster response = createClusterAsyncRequest.get(); | ||
|
||
// Print out a success message. | ||
System.out.printf("Cluster created successfully: %s", response.getClusterName()); | ||
|
||
} catch (ExecutionException e) { | ||
System.err.println(String.format("Error executing createCluster: %s ", e.getMessage())); | ||
} | ||
} | ||
} | ||
// [END dataproc_create_cluster] |
174 changes: 174 additions & 0 deletions
174
dataproc/src/main/java/CreateClusterWithAutoscaling.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* This sample creates a Dataproc cluster with an autoscaling policy enabled. | ||
* The policy we will be creating mirrors the following YAML representation: | ||
* | ||
workerConfig: | ||
minInstances: 2 | ||
maxInstances: 100 | ||
weight: 1 | ||
secondaryWorkerConfig: | ||
minInstances: 0 | ||
maxInstances: 100 | ||
weight: 1 | ||
basicAlgorithm: | ||
cooldownPeriod: 4m | ||
yarnConfig: | ||
scaleUpFactor: 0.05 | ||
scaleDownFactor: 1.0 | ||
scaleUpMinWorkerFraction: 0.0 | ||
scaleDownMinWorkerFraction: 0.0 | ||
gracefulDecommissionTimeout: 1h | ||
*/ | ||
|
||
// [START dataproc_create_autoscaling_cluster] | ||
|
||
import com.google.api.gax.longrunning.OperationFuture; | ||
import com.google.cloud.dataproc.v1.AutoscalingConfig; | ||
import com.google.cloud.dataproc.v1.AutoscalingPolicy; | ||
import com.google.cloud.dataproc.v1.AutoscalingPolicyServiceClient; | ||
import com.google.cloud.dataproc.v1.AutoscalingPolicyServiceSettings; | ||
import com.google.cloud.dataproc.v1.BasicAutoscalingAlgorithm; | ||
import com.google.cloud.dataproc.v1.BasicYarnAutoscalingConfig; | ||
import com.google.cloud.dataproc.v1.Cluster; | ||
import com.google.cloud.dataproc.v1.ClusterConfig; | ||
import com.google.cloud.dataproc.v1.ClusterControllerClient; | ||
import com.google.cloud.dataproc.v1.ClusterControllerSettings; | ||
import com.google.cloud.dataproc.v1.ClusterOperationMetadata; | ||
import com.google.cloud.dataproc.v1.InstanceGroupAutoscalingPolicyConfig; | ||
import com.google.cloud.dataproc.v1.InstanceGroupConfig; | ||
import com.google.cloud.dataproc.v1.RegionName; | ||
import com.google.protobuf.Duration; | ||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class CreateClusterWithAutoscaling { | ||
|
||
public static void createClusterwithAutoscaling() throws IOException, InterruptedException { | ||
// TODO(developer): Replace these variables before running the sample. | ||
String projectId = "your-project-id"; | ||
String region = "your-project-region"; | ||
String clusterName = "your-cluster-name"; | ||
String autoscalingPolicyName = "your-autoscaling-policy"; | ||
createClusterwithAutoscaling(projectId, region, clusterName, autoscalingPolicyName); | ||
} | ||
|
||
public static void createClusterwithAutoscaling( | ||
String projectId, String region, String clusterName, String autoscalingPolicyName) | ||
throws IOException, InterruptedException { | ||
String myEndpoint = String.format("%s-dataproc.googleapis.com:443", region); | ||
|
||
// Configure the settings for the cluster controller client. | ||
ClusterControllerSettings clusterControllerSettings = | ||
ClusterControllerSettings.newBuilder().setEndpoint(myEndpoint).build(); | ||
|
||
// Configure the settings for the autoscaling policy service client. | ||
AutoscalingPolicyServiceSettings autoscalingPolicyServiceSettings = | ||
AutoscalingPolicyServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); | ||
|
||
// Create a cluster controller client and an autoscaling controller client with the configured | ||
// settings. The clients only need to be created once and can be reused for multiple requests. | ||
// Using a | ||
// try-with-resources closes the client, but this can also be done manually with the .close() | ||
// method. | ||
try (ClusterControllerClient clusterControllerClient = | ||
ClusterControllerClient.create(clusterControllerSettings); | ||
AutoscalingPolicyServiceClient autoscalingPolicyServiceClient = | ||
AutoscalingPolicyServiceClient.create(autoscalingPolicyServiceSettings)) { | ||
|
||
// Create the Autoscaling policy. | ||
InstanceGroupAutoscalingPolicyConfig workerInstanceGroupAutoscalingPolicyConfig = | ||
InstanceGroupAutoscalingPolicyConfig.newBuilder() | ||
.setMinInstances(2) | ||
.setMaxInstances(100) | ||
.setWeight(1) | ||
.build(); | ||
InstanceGroupAutoscalingPolicyConfig secondaryWorkerInstanceGroupAutoscalingPolicyConfig = | ||
InstanceGroupAutoscalingPolicyConfig.newBuilder() | ||
.setMinInstances(0) | ||
.setMaxInstances(100) | ||
.setWeight(1) | ||
.build(); | ||
BasicYarnAutoscalingConfig basicYarnApplicationConfig = | ||
BasicYarnAutoscalingConfig.newBuilder() | ||
.setScaleUpFactor(0.05) | ||
.setScaleDownFactor(1.0) | ||
.setScaleUpMinWorkerFraction(0.0) | ||
.setScaleUpMinWorkerFraction(0.0) | ||
.setGracefulDecommissionTimeout(Duration.newBuilder().setSeconds(3600).build()) | ||
.build(); | ||
BasicAutoscalingAlgorithm basicAutoscalingAlgorithm = | ||
BasicAutoscalingAlgorithm.newBuilder() | ||
.setCooldownPeriod(Duration.newBuilder().setSeconds(240).build()) | ||
.setYarnConfig(basicYarnApplicationConfig) | ||
.build(); | ||
AutoscalingPolicy autoscalingPolicy = | ||
AutoscalingPolicy.newBuilder() | ||
.setId(autoscalingPolicyName) | ||
.setWorkerConfig(workerInstanceGroupAutoscalingPolicyConfig) | ||
.setSecondaryWorkerConfig(secondaryWorkerInstanceGroupAutoscalingPolicyConfig) | ||
.setBasicAlgorithm(basicAutoscalingAlgorithm) | ||
.build(); | ||
RegionName parent = RegionName.of(projectId, region); | ||
|
||
// Policy is uploaded here. | ||
autoscalingPolicyServiceClient.createAutoscalingPolicy(parent, autoscalingPolicy); | ||
|
||
// Now the policy can be referenced when creating a cluster. | ||
String autoscalingPolicyUri = | ||
String.format( | ||
"projects/%s/locations/%s/autoscalingPolicies/%s", | ||
projectId, region, autoscalingPolicyName); | ||
AutoscalingConfig autoscalingConfig = | ||
AutoscalingConfig.newBuilder().setPolicyUri(autoscalingPolicyUri).build(); | ||
|
||
// Configure the settings for our cluster. | ||
InstanceGroupConfig masterConfig = | ||
InstanceGroupConfig.newBuilder() | ||
.setMachineTypeUri("n1-standard-2") | ||
.setNumInstances(1) | ||
.build(); | ||
InstanceGroupConfig workerConfig = | ||
InstanceGroupConfig.newBuilder() | ||
.setMachineTypeUri("n1-standard-2") | ||
.setNumInstances(2) | ||
.build(); | ||
ClusterConfig clusterConfig = | ||
ClusterConfig.newBuilder() | ||
.setMasterConfig(masterConfig) | ||
.setWorkerConfig(workerConfig) | ||
.setAutoscalingConfig(autoscalingConfig) | ||
.build(); | ||
|
||
// Create the cluster object with the desired cluster config. | ||
Cluster cluster = | ||
Cluster.newBuilder().setClusterName(clusterName).setConfig(clusterConfig).build(); | ||
|
||
// Create the Dataproc cluster. | ||
OperationFuture<Cluster, ClusterOperationMetadata> createClusterAsyncRequest = | ||
clusterControllerClient.createClusterAsync(projectId, region, cluster); | ||
Cluster response = createClusterAsyncRequest.get(); | ||
|
||
// Print out a success message. | ||
System.out.printf("Cluster created successfully: %s", response.getClusterName()); | ||
|
||
} catch (ExecutionException e) { | ||
// If cluster creation does not complete successfully, print the error message. | ||
System.err.println(String.format("createClusterWithAutoscaling: %s ", e.getMessage())); | ||
} | ||
} | ||
} | ||
// [END dataproc_create_autoscaling_cluster] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.