use of com.azure.core.management.exception.ManagementException in project azure-tools-for-java by Microsoft.
the class SqlServerRegionValidator method apply.
@Override
public AzureValidationInfo apply(RegionComboBox comboBox) {
AzureSqlServer service = Azure.az(AzureSqlServer.class);
try {
if (service.checkRegionCapability(comboBox.getSubscription().getId(), comboBox.getValue().getName())) {
return AzureValidationInfo.OK;
}
} catch (ManagementException e) {
return AzureValidationInfo.builder().input(comboBox).message(e.getMessage()).type(AzureValidationInfo.Type.ERROR).build();
}
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
return builder.input(comboBox).message(REGION_UNAVAILABLE_MESSAGE).type(AzureValidationInfo.Type.ERROR).build();
}
use of com.azure.core.management.exception.ManagementException in project azure-tools-for-java by Microsoft.
the class SqlServerNameValidator method apply.
@Override
public AzureValidationInfo apply(ServerNameTextField textField) {
final String value = textField.getValue();
// validate availability
CheckNameAvailabilityResultEntity resultEntity;
try {
resultEntity = Azure.az(AzureSqlServer.class).checkNameAvailability(textField.getSubscriptionId(), value);
} catch (ManagementException e) {
return AzureValidationInfo.builder().input(textField).message(e.getMessage()).type(AzureValidationInfo.Type.ERROR).build();
}
if (!resultEntity.isAvailable()) {
String message = resultEntity.getUnavailabilityReason();
if ("AlreadyExists".equalsIgnoreCase(resultEntity.getUnavailabilityReason())) {
message = "The specified server name is already in use.";
}
return AzureValidationInfo.builder().input(textField).message(message).type(AzureValidationInfo.Type.ERROR).build();
}
return AzureValidationInfo.OK;
}
use of com.azure.core.management.exception.ManagementException in project azure-tools-for-java by Microsoft.
the class AccountNameTextField method doValidateValue.
@Override
@Nonnull
public AzureValidationInfo doValidateValue() {
if (StringUtils.isBlank(subscriptionId)) {
return AzureValidationInfo.UNINITIALIZED;
}
final AzureValidationInfo info = super.doValidateValue();
if (!AzureValidationInfo.OK.equals(info)) {
return info;
}
final String value = this.getValue();
// validate length
if (StringUtils.length(value) < minLength || StringUtils.length(value) > maxLength) {
return AzureValidationInfo.builder().input(this).message(String.format("Server name must be at least %s characters and at most %s characters.", minLength, maxLength)).type(AzureValidationInfo.Type.ERROR).build();
}
// validate special character
if (!PATTERN.matcher(value).matches()) {
return AzureValidationInfo.builder().input(this).message("The field can contain only lowercase letters and numbers. Name must be between 3 and 24 characters.").type(AzureValidationInfo.Type.ERROR).build();
}
// validate availability
CheckNameAvailabilityResultEntity resultEntity;
try {
resultEntity = Azure.az(AzureStorageAccount.class).checkNameAvailability(subscriptionId, this.getValue());
} catch (ManagementException e) {
return AzureValidationInfo.builder().input(this).message(e.getMessage()).type(AzureValidationInfo.Type.ERROR).build();
}
if (!resultEntity.isAvailable()) {
String message = resultEntity.getUnavailabilityReason();
if ("AlreadyExists".equalsIgnoreCase(resultEntity.getUnavailabilityReason())) {
message = "The specified storage account name is already taken.";
}
return AzureValidationInfo.builder().input(this).message(message).type(AzureValidationInfo.Type.ERROR).build();
}
return AzureValidationInfo.OK;
}
Aggregations