-
Notifications
You must be signed in to change notification settings - Fork 360
Add support for Dataproc Flexible Machine Types in compute profiles #16204
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| /* | ||
| * Copyright © 2018-2020 Cask Data, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
|
|
@@ -17,6 +17,7 @@ | |
| package io.cdap.cdap.runtime.spi.provisioner.dataproc; | ||
|
|
||
| import com.google.auth.oauth2.GoogleCredentials; | ||
| import com.google.common.base.Splitter; | ||
| import com.google.common.base.Strings; | ||
| import io.cdap.cdap.runtime.spi.common.DataprocUtils; | ||
| import java.io.ByteArrayInputStream; | ||
|
|
@@ -27,11 +28,14 @@ | |
| import java.nio.charset.StandardCharsets; | ||
| import java.security.MessageDigest; | ||
| import java.security.NoSuchAlgorithmException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
Check warning on line 37 in cdap-runtime-ext-dataproc/src/main/java/io/cdap/cdap/runtime/spi/provisioner/dataproc/DataprocConf.java
|
||
| import java.util.Set; | ||
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
| import javax.annotation.Nullable; | ||
|
|
@@ -72,6 +76,7 @@ | |
| static final String TEMP_BUCKET = "tempBucket"; | ||
|
|
||
| static final Pattern CLUSTER_PROPERTIES_PATTERN = Pattern.compile("^[a-zA-Z0-9\\-]+:"); | ||
| static final String NETWORK_TAGS = "networkTags"; | ||
| static final int MAX_NETWORK_TAGS = 64; | ||
|
|
||
| static final String SECURE_BOOT_ENABLED = "secureBootEnabled"; | ||
|
|
@@ -111,6 +116,12 @@ | |
| private static final String COMPUTE_CREDENTIALS_MAX_RETRIES_KEY = "compute.credentials.max.retries"; | ||
| private static final int COMPUTE_CREDENTIALS_MAX_RETRIES_DEFAULT = 50; | ||
|
|
||
| public static final String MASTER_FLEX_VM_MACHINE_TYPES = "masterFlexVmMachineTypes"; | ||
| public static final String WORKER_FLEX_VM_MACHINE_TYPES = "workerFlexVmMachineTypes"; | ||
|
|
||
| private static final Splitter COMMA_SPLITTER = | ||
| Splitter.on(',').trimResults().omitEmptyStrings(); | ||
|
|
||
| private final String accountKey; | ||
| private final String region; | ||
| private final String zone; | ||
|
|
@@ -128,6 +139,7 @@ | |
| private final int masterDiskGb; | ||
| private final String masterDiskType; | ||
| private final String masterMachineType; | ||
| private final List<String> masterFlexVmMachineTypes; | ||
|
|
||
| private final int workerNumNodes; | ||
| private final int secondaryWorkerNumNodes; | ||
|
|
@@ -136,6 +148,7 @@ | |
| private final int workerDiskGb; | ||
| private final String workerDiskType; | ||
| private final String workerMachineType; | ||
| private final List<String> workerFlexVmMachineTypes; | ||
|
|
||
| private final long pollCreateDelay; | ||
| private final long pollCreateJitter; | ||
|
|
@@ -189,8 +202,10 @@ | |
| @Nullable String networkHostProjectId, @Nullable String network, @Nullable String subnet, | ||
| int masterNumNodes, int masterCpus, int masterMemoryMb, | ||
| int masterDiskGb, String masterDiskType, @Nullable String masterMachineType, | ||
| List<String> masterFlexVmMachineTypes, | ||
| int workerNumNodes, int secondaryWorkerNumNodes, int workerCpus, int workerMemoryMb, | ||
| int workerDiskGb, String workerDiskType, @Nullable String workerMachineType, | ||
| List<String> workerFlexVmMachineTypes, | ||
| long pollCreateDelay, long pollCreateJitter, long pollDeleteDelay, long pollInterval, | ||
| @Nullable String encryptionKeyName, @Nullable String gcsBucket, | ||
| @Nullable String tempBucket, @Nullable String serviceAccount, boolean preferExternalIp, | ||
|
|
@@ -230,13 +245,15 @@ | |
| this.masterDiskGb = masterDiskGb; | ||
| this.masterDiskType = masterDiskType; | ||
| this.masterMachineType = masterMachineType; | ||
| this.masterFlexVmMachineTypes = masterFlexVmMachineTypes; | ||
| this.workerNumNodes = workerNumNodes; | ||
| this.secondaryWorkerNumNodes = secondaryWorkerNumNodes; | ||
| this.workerCpus = workerCpus; | ||
| this.workerMemoryMb = workerMemoryMb; | ||
| this.workerDiskGb = workerDiskGb; | ||
| this.workerDiskType = workerDiskType; | ||
| this.workerMachineType = workerMachineType; | ||
| this.workerFlexVmMachineTypes = workerFlexVmMachineTypes; | ||
| this.pollCreateDelay = pollCreateDelay; | ||
| this.pollCreateJitter = pollCreateJitter; | ||
| this.pollDeleteDelay = pollDeleteDelay; | ||
|
|
@@ -339,6 +356,14 @@ | |
| return getMachineType(workerMachineType, workerCpus, workerMemoryMb); | ||
| } | ||
|
|
||
| public List<String> getMasterFlexVmMachineTypes() { | ||
| return formatFlexMachineTypes(masterFlexVmMachineTypes, masterCpus, masterMemoryMb); | ||
| } | ||
|
|
||
| public List<String> getWorkerFlexVmMachineTypes() { | ||
| return formatFlexMachineTypes(workerFlexVmMachineTypes, workerCpus, workerMemoryMb); | ||
| } | ||
|
|
||
| int getTotalWorkerCpus() { | ||
| if (enablePredefinedAutoScaling) { | ||
| return workerCpus | ||
|
|
@@ -667,12 +692,14 @@ | |
| if (masterDiskType == null) { | ||
| masterDiskType = "pd-standard"; | ||
| } | ||
| final List<String> masterFlexVmMachineTypes = getStringList(properties, MASTER_FLEX_VM_MACHINE_TYPES); | ||
| final int workerDiskGb = getInt(properties, "workerDiskGB", 1000); | ||
| String workerDiskType = getString(properties, "workerDiskType"); | ||
| final String workerMachineType = getString(properties, "workerMachineType"); | ||
| if (workerDiskType == null) { | ||
| workerDiskType = "pd-standard"; | ||
| } | ||
| final List<String> workerFlexVmMachineTypes = getStringList(properties, WORKER_FLEX_VM_MACHINE_TYPES); | ||
|
|
||
| final long pollCreateDelay = getLong(properties, "pollCreateDelay", 60); | ||
| final long pollCreateJitter = getLong(properties, "pollCreateJitter", 20); | ||
|
|
@@ -712,14 +739,7 @@ | |
| final Map<String, String> clusterLabels = Collections.unmodifiableMap( | ||
| DataprocUtils.parseKeyValueConfig(getString(properties, CLUSTER_LABELS), ";", "\\|")); | ||
|
|
||
| final String networkTagsProperty = Optional.ofNullable(getString(properties, "networkTags")) | ||
| .orElse(""); | ||
| final List<String> networkTags = Collections.unmodifiableList( | ||
| Arrays.stream(networkTagsProperty.split(",")) | ||
| .map(String::trim) | ||
| .filter(s -> !s.isEmpty()) | ||
| .collect(Collectors.toList())); | ||
|
|
||
| final List<String> networkTags = getStringList(properties, NETWORK_TAGS); | ||
| if (networkTags.size() > MAX_NETWORK_TAGS) { | ||
| throw new IllegalArgumentException( | ||
| "Number of network tags cannot be more than " + MAX_NETWORK_TAGS); | ||
|
|
@@ -781,21 +801,16 @@ | |
| Boolean.parseBoolean(properties.getOrDefault(DataprocUtils.LOCAL_CACHE_DISABLED, | ||
| "false")); | ||
|
|
||
| final String scopesProperty = String.format("%s,%s", | ||
| Optional.ofNullable(getString(properties, SCOPES)).orElse(""), CLOUD_PLATFORM_SCOPE); | ||
| List<String> scopes = Collections.unmodifiableList( | ||
| Arrays.stream(scopesProperty.split(",")) | ||
| .map(String::trim) | ||
| .filter(s -> !s.isEmpty()) | ||
| .distinct() | ||
| .collect(Collectors.toList())); | ||
| Set<String> scopesSet = new LinkedHashSet<>(getStringList(properties, SCOPES)); | ||
| scopesSet.add(CLOUD_PLATFORM_SCOPE); | ||
| final List<String> scopes = Collections.unmodifiableList(new ArrayList<>(scopesSet)); | ||
|
|
||
| return new DataprocConf(accountKey, region, zone, projectId, networkHostProjectId, network, | ||
| subnet, | ||
| masterNumNodes, masterCpus, masterMemoryMb, masterDiskGb, | ||
| masterDiskType, masterMachineType, | ||
| masterDiskType, masterMachineType, masterFlexVmMachineTypes, | ||
| workerNumNodes, secondaryWorkerNumNodes, workerCpus, workerMemoryMb, workerDiskGb, | ||
| workerDiskType, workerMachineType, | ||
| workerDiskType, workerMachineType, workerFlexVmMachineTypes, | ||
| pollCreateDelay, pollCreateJitter, pollDeleteDelay, pollInterval, | ||
| gcpCmekKeyName, gcpCmekBucket, tempBucket, serviceAccount, preferExternalIp, | ||
| stackdriverLoggingEnabled, stackdriverMonitoringEnabled, | ||
|
|
@@ -856,4 +871,23 @@ | |
| valStr)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private List<String> formatFlexMachineTypes(List<String> flexTypes, int cpus, int memoryMb) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be simplified as: private List<String> formatFlexMachineTypes(List<String> flexTypes, int cpus, int memoryMb) {
return flexTypes.stream()
.map(type -> getMachineType(type, cpus, memoryMb))
.collect(Collectors.toUnmodifiableList());
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| List<String> result = flexTypes.stream() | ||
| .map(type -> getMachineType(type, cpus, memoryMb)) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| return Collections.unmodifiableList(result); | ||
| } | ||
|
|
||
| /** | ||
| * Parses a comma-separated string property into a trimmed list of strings, | ||
| * or returns an empty list if null/empty. | ||
| */ | ||
| private static List<String> getStringList(Map<String, String> properties, String key) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we check other fields that are How are they parsed ? And if this function can be made generic to be used for other such fields?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the other "widget-type": "csv" fields (networkTags, scopes, and initActions).
|
||
| String val = getString(properties, key); | ||
| return Strings.isNullOrEmpty(val) | ||
| ? Collections.emptyList() | ||
| : COMMA_SPLITTER.splitToList(val); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,20 @@ | |
| "size": "medium" | ||
| } | ||
| }, | ||
| { | ||
| "widget-type": "multi-select", | ||
|
123-komal marked this conversation as resolved.
|
||
| "label": "Master Flexible Machine Types", | ||
| "name": "masterFlexVmMachineTypes", | ||
| "description": "Optional comma-separated list of fallback machine types in priority order if the primary master machine type is unavailable.", | ||
| "widget-attributes": { | ||
| "options": [ | ||
| "n1", | ||
| "n2", | ||
| "n2d", | ||
| "e2" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Below as well.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have kept the supported option same as the one with we listed in |
||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "widget-type": "select", | ||
| "label": "Master Cores", | ||
|
|
@@ -254,6 +268,20 @@ | |
| "size": "medium" | ||
| } | ||
| }, | ||
| { | ||
| "widget-type": "multi-select", | ||
| "label": "Worker Flexible Machine Types", | ||
| "name": "workerFlexVmMachineTypes", | ||
| "description": "Machine types in priority order if the primary worker machine type is unavailable.", | ||
| "widget-attributes": { | ||
| "options": [ | ||
| "n1", | ||
| "n2", | ||
| "n2d", | ||
| "e2" | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "widget-type": "select", | ||
| "label": "Worker Cores", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: fix indentation, if broken.