Search in sources :

Example 11 with AzureToolkitRuntimeException

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);
    }
}
Also used : AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) List(java.util.List) Map(java.util.Map) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) Comparator(java.util.Comparator) InputStream(java.io.InputStream) AzureSdkCategoryEntity(com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkCategoryEntity) InputStream(java.io.InputStream) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IOException(java.io.IOException) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 12 with AzureToolkitRuntimeException

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;
}
Also used : AzureMySql(com.microsoft.azure.toolkit.lib.mysql.AzureMySql) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) MySQLProperty(com.microsoft.tooling.msservices.serviceexplorer.azure.mysql.MySQLProperty) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)

Example 13 with AzureToolkitRuntimeException

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);
}
Also used : AuthorizationLevel(com.microsoft.azure.functions.annotation.AuthorizationLevel) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 14 with AzureToolkitRuntimeException

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);
    }
}
Also used : AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) IOException(java.io.IOException) StorageException(org.eclipse.equinox.security.storage.StorageException)

Example 15 with AzureToolkitRuntimeException

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);
    }
}
Also used : AzureSqlServer(com.microsoft.azure.toolkit.lib.sqlserver.AzureSqlServer) SqlServerEntity(com.microsoft.azure.toolkit.lib.sqlserver.model.SqlServerEntity) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) FirewallRuleEntity(com.microsoft.azure.toolkit.lib.database.entity.FirewallRuleEntity) SqlServer(com.microsoft.azure.toolkit.lib.sqlserver.SqlServer) AzureSqlServer(com.microsoft.azure.toolkit.lib.sqlserver.AzureSqlServer) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)

Aggregations

AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)29 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)13 IOException (java.io.IOException)13 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)9 File (java.io.File)5 AzureExecutionException (com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException)4 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 HashMap (java.util.HashMap)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)3 Path (java.nio.file.Path)3 PsiMethod (com.intellij.psi.PsiMethod)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 MsalClientException (com.microsoft.aad.msal4j.MsalClientException)2 AuthorizationLevel (com.microsoft.azure.functions.annotation.AuthorizationLevel)2 AppServiceFile (com.microsoft.azure.toolkit.lib.appservice.model.AppServiceFile)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1