|
| 1 | +import cuid from 'cuid' |
| 2 | +import { google } from '@google-cloud/dataproc/build/protos/protos' |
| 3 | +import { |
| 4 | + GcpDataprocCluster, |
| 5 | + GcpDataprocClusterConfig, |
| 6 | + GcpDataprocClusterConfigEndpoint, |
| 7 | + GcpDataprocClusterConfigGceCluster, |
| 8 | + GcpDataprocClusterConfigGke, |
| 9 | + GcpDataprocClusterConfigInstanceGroup, |
| 10 | + GcpDataprocClusterConfigLifecycleConfig, |
| 11 | + GcpDataprocClusterConfigNodeInitializationAction, |
| 12 | + GcpDataprocClusterConfigSecurity, |
| 13 | + GcpDataprocClusterConfigSoftware, |
| 14 | + GcpDataprocClusterStatus, |
| 15 | +} from '../../types/generated' |
| 16 | +import { RawGcpDataprocCluster } from './data' |
| 17 | +import { toISOString } from '../../utils/dateutils' |
| 18 | +import { enumKeyToString, formatKeyValueMap, formatLabelsFromMap } from '../../utils/format' |
| 19 | + |
| 20 | +const formatClusterConfigGceCluster = ({ |
| 21 | + zoneUri, |
| 22 | + networkUri, |
| 23 | + subnetworkUri, |
| 24 | + internalIpOnly, |
| 25 | + privateIpv6GoogleAccess, |
| 26 | + serviceAccount, |
| 27 | + serviceAccountScopes, |
| 28 | + tags, |
| 29 | + metadata = {}, |
| 30 | + reservationAffinity, |
| 31 | + nodeGroupAffinity, |
| 32 | + shieldedInstanceConfig, |
| 33 | + confidentialInstanceConfig, |
| 34 | +}: google.cloud.dataproc.v1.IGceClusterConfig): GcpDataprocClusterConfigGceCluster => { |
| 35 | + return { |
| 36 | + zoneUri, |
| 37 | + networkUri, |
| 38 | + subnetworkUri, |
| 39 | + internalIpOnly, |
| 40 | + privateIpv6GoogleAccess: enumKeyToString(google.cloud.dataproc.v1.GceClusterConfig.PrivateIpv6GoogleAccess, privateIpv6GoogleAccess), |
| 41 | + serviceAccount, |
| 42 | + serviceAccountScopes, |
| 43 | + tags, |
| 44 | + metadata: formatKeyValueMap(metadata), |
| 45 | + consumeReservationType: enumKeyToString(google.cloud.dataproc.v1.ReservationAffinity.Type, reservationAffinity?.consumeReservationType), |
| 46 | + reservationAffinityKey: reservationAffinity?.key || '', |
| 47 | + reservationAffinityValues: reservationAffinity?.values || [], |
| 48 | + nodeGroupAffinityNodeGroupUri: nodeGroupAffinity?.nodeGroupUri || '', |
| 49 | + shieldedInstanceConfigEnableSecureBoot: shieldedInstanceConfig?.enableSecureBoot || false, |
| 50 | + shieldedInstanceConfigEnableVtpm: shieldedInstanceConfig?.enableVtpm || false, |
| 51 | + shieldedInstanceConfigEnableIntegrityMonitoring: shieldedInstanceConfig?.enableIntegrityMonitoring || false, |
| 52 | + confidentialInstanceConfigEnableConfidentialCompute: confidentialInstanceConfig?.enableConfidentialCompute || false, |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +const formatClusterConfigInstanceGroup = ({ |
| 57 | + numInstances, |
| 58 | + instanceNames, |
| 59 | + imageUri, |
| 60 | + machineTypeUri, |
| 61 | + diskConfig = {}, |
| 62 | + isPreemptible, |
| 63 | + preemptibility, |
| 64 | + managedGroupConfig = {}, |
| 65 | + accelerators = [], |
| 66 | + minCpuPlatform, |
| 67 | +}: google.cloud.dataproc.v1.IInstanceGroupConfig): GcpDataprocClusterConfigInstanceGroup => { |
| 68 | + return { |
| 69 | + numInstances, |
| 70 | + instanceNames, |
| 71 | + imageUri, |
| 72 | + machineTypeUri, |
| 73 | + diskConfigBootDiskType: diskConfig?.bootDiskType || '', |
| 74 | + diskConfigBootDiskSizeGb: diskConfig?.bootDiskSizeGb || 0, |
| 75 | + diskConfigNumLocalSsds: diskConfig?.numLocalSsds || 0, |
| 76 | + isPreemptible, |
| 77 | + preemptibility: enumKeyToString(google.cloud.dataproc.v1.InstanceGroupConfig.Preemptibility, preemptibility), |
| 78 | + managedGroupConfigInstanceTemplateName: managedGroupConfig?.instanceTemplateName || '', |
| 79 | + managedGroupConfigInstanceGroupManagerName: managedGroupConfig?.instanceGroupManagerName || '', |
| 80 | + accelerators: accelerators?.map(({ |
| 81 | + acceleratorTypeUri, |
| 82 | + acceleratorCount, |
| 83 | + }) => { |
| 84 | + return { |
| 85 | + id: cuid(), |
| 86 | + acceleratorTypeUri, |
| 87 | + acceleratorCount, |
| 88 | + }}), |
| 89 | + minCpuPlatform, |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +const formatClusterConfigSoftware = ({ |
| 94 | + imageVersion, |
| 95 | + properties, |
| 96 | + optionalComponents = [], |
| 97 | +}: google.cloud.dataproc.v1.ISoftwareConfig): GcpDataprocClusterConfigSoftware => { |
| 98 | + return { |
| 99 | + imageVersion, |
| 100 | + properties: formatKeyValueMap(properties), |
| 101 | + optionalComponents: optionalComponents?.map(component => { |
| 102 | + return enumKeyToString(google.cloud.dataproc.v1.Component, component) |
| 103 | + }), |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +const formatClusterConfigNodeInitializationAction = ({ |
| 108 | + executableFile, |
| 109 | + executionTimeout, |
| 110 | +}: google.cloud.dataproc.v1.INodeInitializationAction): GcpDataprocClusterConfigNodeInitializationAction => { |
| 111 | + return { |
| 112 | + id: cuid(), |
| 113 | + executableFile, |
| 114 | + executionTimeout: executionTimeout?.seconds?.toString() || '', |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +const formatClusterConfigSecurity = ({ |
| 119 | + kerberosConfig = {}, |
| 120 | + identityConfig = {}, |
| 121 | +}: google.cloud.dataproc.v1.ISecurityConfig): GcpDataprocClusterConfigSecurity => { |
| 122 | + return { |
| 123 | + kerberosConfigEnableKerberos: kerberosConfig?.enableKerberos || false, |
| 124 | + kerberosConfigRootPrincipalPasswordUri: kerberosConfig?.rootPrincipalPasswordUri || '', |
| 125 | + kerberosConfigKmsKeyUri: kerberosConfig?.kmsKeyUri || '', |
| 126 | + kerberosConfigKeystoreUri: kerberosConfig?.keystoreUri || '', |
| 127 | + kerberosConfigTruststoreUri: kerberosConfig?.truststoreUri || '', |
| 128 | + kerberosConfigKeystorePasswordUri: kerberosConfig?.keystorePasswordUri || '', |
| 129 | + kerberosConfigKeyPasswordUri: kerberosConfig?.keyPasswordUri || '', |
| 130 | + kerberosConfigTruststorePasswordUri: kerberosConfig?.truststorePasswordUri || '', |
| 131 | + kerberosConfigCrossRealmTrustRealm: kerberosConfig?.crossRealmTrustRealm || '', |
| 132 | + kerberosConfigCrossRealmTrustKdc: kerberosConfig?.crossRealmTrustKdc || '', |
| 133 | + kerberosConfigCrossRealmTrustAdminServer: kerberosConfig?.crossRealmTrustAdminServer || '', |
| 134 | + kerberosConfigCrossRealmTrustSharedPasswordUri: kerberosConfig?.crossRealmTrustSharedPasswordUri || '', |
| 135 | + kerberosConfigKdcDbKeyUri: kerberosConfig?.kdcDbKeyUri || '', |
| 136 | + kerberosConfigTgtLifetimeHours: kerberosConfig?.tgtLifetimeHours || 0, |
| 137 | + kerberosConfigRealm: kerberosConfig?.realm || '', |
| 138 | + identityConfigUserServiceAccountMapping: formatKeyValueMap(identityConfig?.userServiceAccountMapping), |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +const formatClusterConfigLifecycle = ({ |
| 143 | + idleDeleteTtl, |
| 144 | + autoDeleteTime, |
| 145 | + autoDeleteTtl, |
| 146 | + idleStartTime, |
| 147 | +}: google.cloud.dataproc.v1.ILifecycleConfig): GcpDataprocClusterConfigLifecycleConfig => { |
| 148 | + return { |
| 149 | + idleDeleteTtl: idleDeleteTtl.seconds?.toString() || '', |
| 150 | + autoDeleteTime: toISOString(autoDeleteTime?.seconds?.toString()), |
| 151 | + autoDeleteTtl: autoDeleteTtl.seconds?.toString() || '', |
| 152 | + idleStartTime: toISOString(idleStartTime?.seconds?.toString()), |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +const formatClusterConfigEndpoint = ({ |
| 157 | + httpPorts, |
| 158 | + enableHttpPortAccess, |
| 159 | +}: google.cloud.dataproc.v1.IEndpointConfig): GcpDataprocClusterConfigEndpoint => { |
| 160 | + return { |
| 161 | + httpPorts: formatKeyValueMap(httpPorts), |
| 162 | + enableHttpPortAccess, |
| 163 | + } |
| 164 | +} |
| 165 | + |
| 166 | +const formatClusterConfigGke = ({ |
| 167 | + namespacedGkeDeploymentTarget, |
| 168 | +}: google.cloud.dataproc.v1.IGkeClusterConfig): GcpDataprocClusterConfigGke => { |
| 169 | + return { |
| 170 | + namespacedGkeDeploymentTargetTargetGkeCluster: namespacedGkeDeploymentTarget?.targetGkeCluster || '', |
| 171 | + namespacedGkeDeploymentTargetClusterNamespace: namespacedGkeDeploymentTarget?.clusterNamespace || '', |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +const formatClusterConfig = ({ |
| 176 | + configBucket, |
| 177 | + tempBucket, |
| 178 | + gceClusterConfig = {}, |
| 179 | + masterConfig = {}, |
| 180 | + workerConfig = {}, |
| 181 | + secondaryWorkerConfig = {}, |
| 182 | + softwareConfig = {}, |
| 183 | + initializationActions = [], |
| 184 | + encryptionConfig = {}, |
| 185 | + autoscalingConfig = {}, |
| 186 | + securityConfig = {}, |
| 187 | + lifecycleConfig = {}, |
| 188 | + endpointConfig = {}, |
| 189 | + metastoreConfig = {}, |
| 190 | + gkeClusterConfig = {}, |
| 191 | +}: google.cloud.dataproc.v1.IClusterConfig): GcpDataprocClusterConfig => { |
| 192 | + return { |
| 193 | + configBucket, |
| 194 | + tempBucket, |
| 195 | + gceClusterConfig: formatClusterConfigGceCluster(gceClusterConfig), |
| 196 | + masterConfig: formatClusterConfigInstanceGroup(masterConfig), |
| 197 | + workerConfig: formatClusterConfigInstanceGroup(workerConfig), |
| 198 | + secondaryWorkerConfig: formatClusterConfigInstanceGroup(secondaryWorkerConfig), |
| 199 | + softwareConfig: formatClusterConfigSoftware(softwareConfig), |
| 200 | + initializationActions: initializationActions?.map(formatClusterConfigNodeInitializationAction), |
| 201 | + encryptionConfigGcePdKmsKeyName: encryptionConfig?.gcePdKmsKeyName || '', |
| 202 | + autoscalingConfigPolicyUri: autoscalingConfig?.policyUri || '', |
| 203 | + securityConfig: formatClusterConfigSecurity(securityConfig), |
| 204 | + lifecycleConfig: formatClusterConfigLifecycle(lifecycleConfig), |
| 205 | + endpointConfig: formatClusterConfigEndpoint(endpointConfig), |
| 206 | + metastoreMetastoreServiceConfig: metastoreConfig?.dataprocMetastoreService || '', |
| 207 | + gkeClusterConfig: formatClusterConfigGke(gkeClusterConfig), |
| 208 | + } |
| 209 | +} |
| 210 | + |
| 211 | +const formatClusterStatus = ({ |
| 212 | + state, |
| 213 | + detail, |
| 214 | + stateStartTime, |
| 215 | + substate, |
| 216 | +}: google.cloud.dataproc.v1.IClusterStatus): GcpDataprocClusterStatus => { |
| 217 | + return { |
| 218 | + id: cuid(), |
| 219 | + state: enumKeyToString(google.cloud.dataproc.v1.ClusterStatus.State, state), |
| 220 | + detail, |
| 221 | + stateStartTime: toISOString(stateStartTime?.seconds?.toString()) || '', |
| 222 | + substate: enumKeyToString(google.cloud.dataproc.v1.ClusterStatus.Substate, substate), |
| 223 | + } |
| 224 | +} |
| 225 | + |
| 226 | +export default ({ |
| 227 | + service, |
| 228 | + region, |
| 229 | +}: { |
| 230 | + service: RawGcpDataprocCluster |
| 231 | + region: string |
| 232 | +}): GcpDataprocCluster => { |
| 233 | + const { |
| 234 | + id, |
| 235 | + projectId, |
| 236 | + clusterName, |
| 237 | + config = {}, |
| 238 | + Labels, |
| 239 | + status = {}, |
| 240 | + statusHistory = [], |
| 241 | + clusterUuid, |
| 242 | + metrics = {}, |
| 243 | + } = service |
| 244 | + |
| 245 | + return { |
| 246 | + id, |
| 247 | + projectId, |
| 248 | + region, |
| 249 | + name: clusterName, |
| 250 | + config: formatClusterConfig(config), |
| 251 | + labels: formatLabelsFromMap(Labels), |
| 252 | + status: formatClusterStatus(status), |
| 253 | + statusHistory: statusHistory?.map(history => formatClusterStatus(history)), |
| 254 | + clusterUuid, |
| 255 | + hdfsMetrics: formatKeyValueMap(metrics?.hdfsMetrics || {}), |
| 256 | + yarnMetrics: formatKeyValueMap(metrics?.yarnMetrics || {}), |
| 257 | + } |
| 258 | +} |
0 commit comments