use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.
the class AzureSdkCategoryService method loadAzureSDKCategories.
@Cacheable(value = "azure-sdk-category-entities")
@AzureOperation(name = "sdk.load_category_data", type = AzureOperation.Type.TASK)
public static Map<String, List<AzureSdkCategoryEntity>> loadAzureSDKCategories() {
try (final InputStream stream = AzureSdkCategoryService.class.getResourceAsStream(SERVICE_CATEGORY_CSV)) {
// read
final ObjectReader reader = CSV_MAPPER.readerFor(AzureSdkCategoryEntity.class).with(CsvSchema.emptySchema().withHeader());
final MappingIterator<AzureSdkCategoryEntity> data = reader.readValues(stream);
final List<AzureSdkCategoryEntity> categories = data.readAll();
// default category & description suffix.
categories.stream().filter(c -> StringUtils.isNotBlank(c.getServiceName())).forEach(c -> {
if (StringUtils.isBlank(c.getCategory())) {
c.setCategory("Others");
}
final String trimDescription = StringUtils.trim(c.getDescription());
if (StringUtils.isNotBlank(trimDescription) && !StringUtils.endsWith(trimDescription, ".")) {
c.setDescription(trimDescription + ".");
}
});
// unique
final List<AzureSdkCategoryEntity> uniqueCategories = categories.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getCategory() + "," + o.getServiceName()))), ArrayList::new));
// group
return uniqueCategories.stream().collect(Collectors.groupingBy(AzureSdkCategoryEntity::getCategory));
} catch (final IOException e) {
final String message = String.format("failed to load Azure SDK categories from \"%s\"", SERVICE_CATEGORY_CSV);
throw new AzureToolkitRuntimeException(message, e);
}
}
use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.
the class MySQLPropertyView method refreshProperty.
private void refreshProperty(String sid, String resourceGroup, String name) {
final MySQLProperty newProperty = new MySQLProperty();
newProperty.setSubscriptionId(sid);
// find server
try {
newProperty.setServer(Azure.az(AzureMySql.class).subscription(sid).get(resourceGroup, name));
} catch (final Exception ex) {
final String error = "find Azure Database for MySQL server information";
final String action = "confirm your network is available and your server actually exists.";
throw new AzureToolkitRuntimeException(error, action);
}
if (StringUtils.equalsIgnoreCase("READY", newProperty.getServer().entity().getState())) {
// find firewalls
newProperty.setFirewallRules(newProperty.getServer().firewallRules().list());
}
this.property = newProperty;
}
use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.
the class FunctionNode method triggerHttpTrigger.
@AzureOperation(name = "function|trigger.start_http", params = { "this.functionApp.name()" }, type = AzureOperation.Type.TASK)
private void triggerHttpTrigger(FunctionEntity.BindingEntity binding) {
final AuthorizationLevel authLevel = EnumUtils.getEnumIgnoreCase(AuthorizationLevel.class, binding.getProperty("authLevel"));
String targetUrl;
switch(authLevel) {
case ANONYMOUS:
targetUrl = getAnonymousHttpTriggerUrl();
break;
case FUNCTION:
targetUrl = getFunctionHttpTriggerUrl();
break;
case ADMIN:
targetUrl = getAdminHttpTriggerUrl();
break;
default:
final String format = String.format("Unsupported authorization level %s", authLevel);
throw new AzureToolkitRuntimeException(format);
}
DefaultLoader.getUIHelper().openInBrowser(targetUrl);
}
use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.
the class EclipseSecureStore method savePassword.
@Override
public void savePassword(@Nonnull String serviceName, @Nullable String key, @Nullable String userName, @Nonnull String password) {
try {
node.put(combineKey(serviceName, key, userName), password, true);
node.flush();
} catch (StorageException | IOException e) {
throw new AzureToolkitRuntimeException(e.getMessage(), e);
}
}
use of com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException in project azure-tools-for-java by Microsoft.
the class SqlServerPropertyView method refreshProperty.
private void refreshProperty(String sid, String resourceGroup, String name) {
// find server
try {
SqlServer server = Azure.az(AzureSqlServer.class).sqlServer(sid, resourceGroup, name);
this.property.setServer(server);
} catch (Exception ex) {
String error = "find Azure Database for MySQL server information";
String action = "confirm your network is available and your server actually exists.";
throw new AzureToolkitRuntimeException(error, action);
}
SqlServerEntity entity = property.getServer().entity();
if ("Ready".equals(entity.getState())) {
// find firewalls
List<FirewallRuleEntity> firewallRules = Azure.az(AzureSqlServer.class).sqlServer(entity.getId()).firewallRules();
this.property.setFirewallRules(firewallRules);
}
}
Aggregations