56
56
import com .netflix .spinnaker .clouddriver .google .deploy .GoogleOperationPoller ;
57
57
import com .netflix .spinnaker .clouddriver .google .deploy .SafeRetry ;
58
58
import com .netflix .spinnaker .clouddriver .google .deploy .description .BasicGoogleDeployDescription ;
59
+ import com .netflix .spinnaker .clouddriver .google .deploy .exception .GoogleOperationException ;
59
60
import com .netflix .spinnaker .clouddriver .google .deploy .ops .GoogleUserDataProvider ;
60
61
import com .netflix .spinnaker .clouddriver .google .model .GoogleHealthCheck ;
61
62
import com .netflix .spinnaker .clouddriver .google .model .GoogleLabeledResource ;
@@ -289,8 +290,45 @@ protected String getMachineTypeNameFromInput(
289
290
if (description .getInstanceType ().contains ("custom-" )) {
290
291
return description .getInstanceType ();
291
292
} else {
292
- return GCEUtil .queryMachineType (
293
- description .getInstanceType (), location , description .getCredentials (), task , BASE_PHASE );
293
+ List <String > queryZone =
294
+ description .getRegional ()
295
+ ? (description .getSelectZones ()
296
+ ? description .getDistributionPolicy ().getZones ()
297
+ : Collections .singletonList (location ))
298
+ : Collections .singletonList (location );
299
+ String machineTypeName = "" ;
300
+ for (String zoneOrLocation : queryZone ) {
301
+ String msg =
302
+ description .getRegional ()
303
+ ? (description .getSelectZones ()
304
+ ? "Machine type "
305
+ + description .getInstanceType ()
306
+ + " not found in zone "
307
+ + zoneOrLocation
308
+ + ". When using selectZones, the machine type must be available in all selected zones."
309
+ : "Machine type "
310
+ + description .getInstanceType ()
311
+ + " not found in zone "
312
+ + zoneOrLocation
313
+ + ". When using Regional distribution without explicit selection of Zones, the machine type must be available in all zones of the region." )
314
+ : "Machine type "
315
+ + description .getInstanceType ()
316
+ + " not found in region "
317
+ + zoneOrLocation
318
+ + "." ;
319
+ try {
320
+ machineTypeName =
321
+ queryMachineType (
322
+ description .getInstanceType (),
323
+ zoneOrLocation ,
324
+ description .getCredentials (),
325
+ task ,
326
+ BASE_PHASE );
327
+ } catch (GoogleOperationException e ) {
328
+ throw new GoogleOperationException (msg );
329
+ }
330
+ }
331
+ return machineTypeName ;
294
332
}
295
333
}
296
334
@@ -300,15 +338,15 @@ protected GoogleNetwork buildNetworkFromInput(
300
338
StringUtils .isNotBlank (description .getNetwork ())
301
339
? description .getNetwork ()
302
340
: DEFAULT_NETWORK_NAME ;
303
- return GCEUtil . queryNetwork (
341
+ return queryNetwork (
304
342
description .getAccountName (), networkName , task , BASE_PHASE , googleNetworkProvider );
305
343
}
306
344
307
345
protected GoogleSubnet buildSubnetFromInput (
308
346
BasicGoogleDeployDescription description , Task task , GoogleNetwork network , String region ) {
309
347
GoogleSubnet subnet =
310
348
StringUtils .isNotBlank (description .getSubnet ())
311
- ? GCEUtil . querySubnet (
349
+ ? querySubnet (
312
350
description .getAccountName (),
313
351
region ,
314
352
description .getSubnet (),
@@ -323,7 +361,7 @@ protected GoogleSubnet buildSubnetFromInput(
323
361
if (subnet != null && network .getId ().contains ("/" ) && network .getAutoCreateSubnets ()) {
324
362
// Auto-created subnets have the same name as the containing network.
325
363
subnet =
326
- GCEUtil . querySubnet (
364
+ querySubnet (
327
365
description .getAccountName (),
328
366
region ,
329
367
network .getId (),
@@ -346,7 +384,7 @@ protected LoadBalancerInfo getLoadBalancerToUpdateFromInput(
346
384
// GCEUtil.queryAllLoadBalancers() will throw an exception if a referenced load balancer cannot
347
385
// be resolved.
348
386
List <GoogleLoadBalancerView > foundLB =
349
- GCEUtil . queryAllLoadBalancers (
387
+ queryAllLoadBalancers (
350
388
googleLoadBalancerProvider , description .getLoadBalancers (), task , BASE_PHASE );
351
389
// Queue ILBs to update, but wait to update metadata until Https LBs are calculated.
352
390
info .internalLoadBalancers =
@@ -381,7 +419,7 @@ protected LoadBalancerInfo getLoadBalancerToUpdateFromInput(
381
419
}
382
420
383
421
protected Image buildBootImage (BasicGoogleDeployDescription description , Task task ) {
384
- return GCEUtil . getBootImage (
422
+ return getBootImage (
385
423
description ,
386
424
task ,
387
425
BASE_PHASE ,
@@ -488,7 +526,7 @@ protected List<BackendService> getBackendServiceToUpdate(
488
526
.map (GoogleLoadBalancerView ::getName )
489
527
.collect (Collectors .toList ()));
490
528
globalLbNames .addAll (
491
- GCEUtil . resolveHttpLoadBalancerNamesMetadata (
529
+ resolveHttpLoadBalancerNamesMetadata (
492
530
backendServices ,
493
531
description .getCredentials ().getCompute (),
494
532
description .getCredentials ().getProject (),
@@ -500,15 +538,15 @@ protected List<BackendService> getBackendServiceToUpdate(
500
538
try {
501
539
BackendService backendService =
502
540
getBackendServiceFromProvider (description .getCredentials (), backendServiceName );
503
- GCEUtil . updateMetadataWithLoadBalancingPolicy (policy , instanceMetadata , objectMapper );
504
- Backend backendToAdd = GCEUtil . backendFromLoadBalancingPolicy (policy );
541
+ updateMetadataWithLoadBalancingPolicy (policy , instanceMetadata , objectMapper );
542
+ Backend backendToAdd = backendFromLoadBalancingPolicy (policy );
505
543
if (description .getRegional ()) {
506
544
backendToAdd .setGroup (
507
- GCEUtil . buildRegionalServerGroupUrl (
545
+ buildRegionalServerGroupUrl (
508
546
description .getCredentials ().getProject (), region , serverGroupName ));
509
547
} else {
510
548
backendToAdd .setGroup (
511
- GCEUtil . buildZonalServerGroupUrl (
549
+ buildZonalServerGroupUrl (
512
550
description .getCredentials ().getProject (),
513
551
description .getZone (),
514
552
serverGroupName ));
@@ -587,17 +625,17 @@ protected List<BackendService> getRegionBackendServicesToUpdate(
587
625
description .getCredentials (), region , serverGroupName );
588
626
Backend backendToAdd ;
589
627
if (internalHttpLbBackendServices .contains (backendServiceName )) {
590
- backendToAdd = GCEUtil . backendFromLoadBalancingPolicy (policy );
628
+ backendToAdd = backendFromLoadBalancingPolicy (policy );
591
629
} else {
592
630
backendToAdd = new Backend ();
593
631
}
594
632
if (description .getRegional ()) {
595
633
backendToAdd .setGroup (
596
- GCEUtil . buildRegionalServerGroupUrl (
634
+ buildRegionalServerGroupUrl (
597
635
description .getCredentials ().getProject (), region , serverGroupName ));
598
636
} else {
599
637
backendToAdd .setGroup (
600
- GCEUtil . buildZonalServerGroupUrl (
638
+ buildZonalServerGroupUrl (
601
639
description .getCredentials ().getProject (),
602
640
description .getZone (),
603
641
serverGroupName ));
@@ -659,11 +697,11 @@ protected void addSelectZonesToInstanceMetadata(BasicGoogleDeployDescription des
659
697
}
660
698
661
699
protected Metadata buildMetadataFromInstanceMetadata (BasicGoogleDeployDescription description ) {
662
- return GCEUtil . buildMetadataFromMap (description .getInstanceMetadata ());
700
+ return buildMetadataFromMap (description .getInstanceMetadata ());
663
701
}
664
702
665
703
protected Tags buildTagsFromInput (BasicGoogleDeployDescription description ) {
666
- return GCEUtil . buildTagsFromList (description .getTags ());
704
+ return buildTagsFromList (description .getTags ());
667
705
}
668
706
669
707
protected List <ServiceAccount > buildServiceAccountFromInput (
@@ -673,12 +711,11 @@ protected List<ServiceAccount> buildServiceAccountFromInput(
673
711
description .setServiceAccountEmail ("default" );
674
712
}
675
713
676
- return GCEUtil .buildServiceAccount (
677
- description .getServiceAccountEmail (), description .getAuthScopes ());
714
+ return buildServiceAccount (description .getServiceAccountEmail (), description .getAuthScopes ());
678
715
}
679
716
680
717
protected Scheduling buildSchedulingFromInput (BasicGoogleDeployDescription description ) {
681
- return GCEUtil . buildScheduling (description );
718
+ return buildScheduling (description );
682
719
}
683
720
684
721
protected Map <String , String > buildLabelsFromInput (
@@ -762,8 +799,8 @@ protected void addShieldedVmConfigToInstanceProperties(
762
799
BasicGoogleDeployDescription description ,
763
800
InstanceProperties instanceProperties ,
764
801
Image bootImage ) {
765
- if (GCEUtil . isShieldedVmCompatible (bootImage )) {
766
- instanceProperties .setShieldedVmConfig (GCEUtil . buildShieldedVmConfig (description ));
802
+ if (isShieldedVmCompatible (bootImage )) {
803
+ instanceProperties .setShieldedVmConfig (buildShieldedVmConfig (description ));
767
804
}
768
805
}
769
806
@@ -790,7 +827,7 @@ protected void setAutoscalerCapacityFromInput(BasicGoogleDeployDescription descr
790
827
description .getAutoscalingPolicy ().setMinNumReplicas (description .getCapacity ().getMin ());
791
828
description .getAutoscalingPolicy ().setMaxNumReplicas (description .getCapacity ().getMax ());
792
829
}
793
- GCEUtil . calibrateTargetSizeWithAutoscaler (description );
830
+ calibrateTargetSizeWithAutoscaler (description );
794
831
}
795
832
}
796
833
@@ -817,7 +854,7 @@ protected void setCapacityFromSource(BasicGoogleDeployDescription description, T
817
854
818
855
// Locate the ancestor server group.
819
856
GoogleServerGroup .View ancestorServerGroup =
820
- GCEUtil . queryServerGroup (
857
+ queryServerGroup (
821
858
googleClusterProvider ,
822
859
description .getAccountName (),
823
860
source .getRegion (),
@@ -834,7 +871,7 @@ protected List<InstanceGroupManagerAutoHealingPolicy> buildAutoHealingPolicyFrom
834
871
&& StringUtils .isNotBlank (description .getAutoHealingPolicy ().getHealthCheck ())) {
835
872
autoHealingHealthCheck =
836
873
(GoogleHealthCheck )
837
- GCEUtil . queryHealthCheck (
874
+ queryHealthCheck (
838
875
description .getCredentials ().getProject (),
839
876
description .getAccountName (),
840
877
description .getAutoHealingPolicy ().getHealthCheck (),
@@ -972,9 +1009,7 @@ protected void setDistributionPolicyToInstanceGroup(
972
1009
.map (
973
1010
it ->
974
1011
new DistributionPolicyZoneConfiguration ()
975
- .setZone (
976
- GCEUtil .buildZoneUrl (
977
- description .getCredentials ().getProject (), it )))
1012
+ .setZone (buildZoneUrl (description .getCredentials ().getProject (), it )))
978
1013
.collect (Collectors .toList ());
979
1014
distributionPolicy .setZones (selectedZones );
980
1015
}
@@ -1118,7 +1153,7 @@ private String createInstanceTemplateAndWait(
1118
1153
instanceTemplateCreateOperation .getName (),
1119
1154
null ,
1120
1155
task ,
1121
- "instance template " + GCEUtil . getLocalName (instanceTemplateUrl ),
1156
+ "instance template " + getLocalName (instanceTemplateUrl ),
1122
1157
BASE_PHASE );
1123
1158
return instanceTemplateUrl ;
1124
1159
}
@@ -1176,7 +1211,7 @@ protected void createRegionalAutoscaler(
1176
1211
BASE_PHASE , String .format ("Creating regional autoscaler for %s..." , serverGroupName ));
1177
1212
1178
1213
Autoscaler autoscaler =
1179
- GCEUtil . buildAutoscaler (serverGroupName , targetLink , description .getAutoscalingPolicy ());
1214
+ buildAutoscaler (serverGroupName , targetLink , description .getAutoscalingPolicy ());
1180
1215
1181
1216
timeExecute (
1182
1217
description
@@ -1246,7 +1281,7 @@ protected void createAutoscaler(
1246
1281
BASE_PHASE , String .format ("Creating zonal autoscaler for %s..." , serverGroupName ));
1247
1282
1248
1283
Autoscaler autoscaler =
1249
- GCEUtil . buildAutoscaler (serverGroupName , targetLink , description .getAutoscalingPolicy ());
1284
+ buildAutoscaler (serverGroupName , targetLink , description .getAutoscalingPolicy ());
1250
1285
1251
1286
timeExecute (
1252
1287
description
0 commit comments