Skip to content

Commit 729f390

Browse files
authored
Merge pull request #5275 from microsoft/qianjin-sqlserver-refactor
refactor code to enhance to sort mysql tiers during creation phrase.
2 parents f9db2df + 48c3f62 commit 729f390

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Utils/azuretools-core/src/com/microsoft/azuretools/core/mvp/model/mysql/MySQLMvpModel.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.microsoft.azure.toolkit.lib.common.model.Region;
2525
import com.microsoft.azure.toolkit.lib.common.model.Subscription;
2626
import com.microsoft.azuretools.authmanage.AuthMethodManager;
27-
import com.microsoft.azuretools.exception.AzureRuntimeException;
2827
import org.apache.commons.collections4.CollectionUtils;
2928
import org.apache.commons.lang3.StringUtils;
3029

@@ -33,7 +32,6 @@
3332
import java.util.Arrays;
3433
import java.util.Comparator;
3534
import java.util.List;
36-
import java.util.Objects;
3735
import java.util.stream.Collectors;
3836

3937
import static com.microsoft.azure.toolkit.lib.Azure.az;
@@ -79,19 +77,22 @@ public static Server create(final String subscriptionId, final String resourceGr
7977
Region region, final ServerPropertiesForDefaultCreate properties) {
8078
final MySQLManager manager = AuthMethodManager.getInstance().getMySQLManager(subscriptionId);
8179
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."));
8985
Sku sku = new Sku().withName(tier.serviceLevelObjectives().get(0).id()); // Basic,GeneralPurpose,MemoryOptimized
9086
Server result = manager.servers().define(serverName).withRegion(region.getName()).withExistingResourceGroup(resourceGroupName)
9187
.withProperties(properties).withSku(sku).create();
9288
return result;
9389
}
9490

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+
9596
public static void delete(final String subscriptionId, final String id) {
9697
final MySQLManager mySQLManager = AuthMethodManager.getInstance().getMySQLManager(subscriptionId);
9798
mySQLManager.servers().deleteByIds(id);

0 commit comments

Comments
 (0)