|
24 | 24 | import com.microsoft.azure.toolkit.lib.common.model.Region; |
25 | 25 | import com.microsoft.azure.toolkit.lib.common.model.Subscription; |
26 | 26 | import com.microsoft.azuretools.authmanage.AuthMethodManager; |
27 | | -import com.microsoft.azuretools.exception.AzureRuntimeException; |
28 | 27 | import org.apache.commons.collections4.CollectionUtils; |
29 | 28 | import org.apache.commons.lang3.StringUtils; |
30 | 29 |
|
|
33 | 32 | import java.util.Arrays; |
34 | 33 | import java.util.Comparator; |
35 | 34 | import java.util.List; |
36 | | -import java.util.Objects; |
37 | 35 | import java.util.stream.Collectors; |
38 | 36 |
|
39 | 37 | import static com.microsoft.azure.toolkit.lib.Azure.az; |
@@ -79,19 +77,22 @@ public static Server create(final String subscriptionId, final String resourceGr |
79 | 77 | Region region, final ServerPropertiesForDefaultCreate properties) { |
80 | 78 | final MySQLManager manager = AuthMethodManager.getInstance().getMySQLManager(subscriptionId); |
81 | 79 | List<PerformanceTierPropertiesInner> tiers = manager.locationBasedPerformanceTiers().inner().list(region.getName()); |
82 | | - PerformanceTierPropertiesInner tier = tiers.stream().filter(e -> StringUtils.equals("Basic", e.id())).findFirst().orElse( |
83 | | - tiers.stream().filter(e -> StringUtils.equals("GeneralPurpose", e.id())).findFirst().orElse( |
84 | | - tiers.stream().filter(e -> StringUtils.equals("MemoryOptimized", e.id())).findFirst().orElse(null) |
85 | | - )); |
86 | | - if (Objects.isNull(tier)) { |
87 | | - throw new AzureToolkitRuntimeException("Currently, the service is not available in this location for your subscription."); |
88 | | - } |
| 80 | + PerformanceTierPropertiesInner tier = tiers.stream().filter(e -> CollectionUtils.isNotEmpty(e.serviceLevelObjectives())).sorted((o1, o2) -> { |
| 81 | + int priority1 = getTierPriority(o1); |
| 82 | + int priority2 = getTierPriority(o2); |
| 83 | + return priority1 > priority2 ? 1 : -1; |
| 84 | + }).findFirst().orElseThrow(() -> new AzureToolkitRuntimeException("Currently, the service is not available in this location for your subscription.")); |
89 | 85 | Sku sku = new Sku().withName(tier.serviceLevelObjectives().get(0).id()); // Basic,GeneralPurpose,MemoryOptimized |
90 | 86 | Server result = manager.servers().define(serverName).withRegion(region.getName()).withExistingResourceGroup(resourceGroupName) |
91 | 87 | .withProperties(properties).withSku(sku).create(); |
92 | 88 | return result; |
93 | 89 | } |
94 | 90 |
|
| 91 | + private static int getTierPriority(PerformanceTierPropertiesInner tier) { |
| 92 | + return StringUtils.equals("Basic", tier.id()) ? 1 : |
| 93 | + StringUtils.equals("GeneralPurpose", tier.id()) ? 2 : StringUtils.equals("MemoryOptimized", tier.id()) ? 3 : 4; |
| 94 | + } |
| 95 | + |
95 | 96 | public static void delete(final String subscriptionId, final String id) { |
96 | 97 | final MySQLManager mySQLManager = AuthMethodManager.getInstance().getMySQLManager(subscriptionId); |
97 | 98 | mySQLManager.servers().deleteByIds(id); |
|
0 commit comments