Search in sources :

Example 26 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation 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 27 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class Connection method prepareBeforeRun.

/**
 * do some preparation in the {@code Connect Azure Resource} before run task
 * of the {@code configuration}<br>
 */
@AzureOperation(name = "connector|connection.prepare_before_run", type = AzureOperation.Type.ACTION)
public boolean prepareBeforeRun(@Nonnull RunConfiguration configuration, DataContext dataContext) {
    this.env = this.resource.initEnv(configuration.getProject()).entrySet().stream().collect(Collectors.toMap(e -> e.getKey().replaceAll(Connection.ENV_PREFIX, this.getEnvPrefix()), Map.Entry::getValue));
    if (configuration instanceof IWebAppRunConfiguration) {
        // set envs for remote deploy
        final IWebAppRunConfiguration webAppConfiguration = (IWebAppRunConfiguration) configuration;
        webAppConfiguration.setApplicationSettings(this.env);
    }
    return true;
}
Also used : IWebAppRunConfiguration(com.microsoft.azure.toolkit.intellij.common.runconfig.IWebAppRunConfiguration) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 28 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class CreateSqlServerTask method execute.

@AzureOperation(name = "sqlserver|server.create", params = { "config.getServerName()", "config.getSubscription().getName()" }, type = AzureOperation.Type.SERVICE)
public SqlServer execute() {
    final Operation operation = TelemetryManager.createOperation(ActionConstants.MySQL.CREATE);
    try {
        operation.start();
        final String subscriptionId = config.getSubscription().getId();
        EventUtil.logEvent(EventType.info, operation, Collections.singletonMap(TelemetryConstants.SUBSCRIPTIONID, subscriptionId));
        // create resource group if necessary.
        if (config.getResourceGroup() instanceof Draft) {
            ResourceGroup newResourceGroup = Azure.az(AzureGroup.class).subscription(subscriptionId).create(config.getResourceGroup().getName(), config.getRegion().getName());
            config.setResourceGroup(newResourceGroup);
        }
        // create sql server
        return Azure.az(AzureSqlServer.class).subscription(config.getSubscription().getId()).create(com.microsoft.azure.toolkit.lib.sqlserver.model.SqlServerConfig.builder().name(config.getServerName()).subscription(config.getSubscription()).resourceGroup(config.getResourceGroup()).region(config.getRegion()).administratorLoginName(config.getAdminUsername()).administratorLoginPassword(String.valueOf(config.getPassword())).enableAccessFromAzureServices(config.isAllowAccessFromAzureServices()).enableAccessFromLocalMachine(config.isAllowAccessFromLocalMachine()).build()).commit();
    } catch (final RuntimeException e) {
        EventUtil.logError(operation, ErrorType.systemError, e, null, null);
        throw e;
    } finally {
        operation.complete();
    }
}
Also used : Draft(com.microsoft.azure.toolkit.intellij.common.Draft) AzureSqlServer(com.microsoft.azure.toolkit.lib.sqlserver.AzureSqlServer) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 29 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.

the class OpenSqlServerByToolsAction method doActionPerformed.

@AzureOperation(name = "sqlserver|server.open_by_database_tools", params = { "this.node.getServer().entity().getName()" }, type = AzureOperation.Type.ACTION)
private void doActionPerformed(Project project) {
    SqlServerEntity entity = node.getServer().entity();
    IntellijDatasourceService.DatasourceProperties properties = IntellijDatasourceService.DatasourceProperties.builder().name(String.format(NAME_PREFIX, entity.getName())).driverClassName(DEFAULT_DRIVER_CLASS_NAME).url(JdbcUrl.sqlserver(entity.getFullyQualifiedDomainName()).toString()).username(entity.getAdministratorLoginName() + "@" + entity.getName()).build();
    IntellijDatasourceService.getInstance().openDataSourceManagerDialog(project, properties);
}
Also used : SqlServerEntity(com.microsoft.azure.toolkit.lib.sqlserver.model.SqlServerEntity) IntellijDatasourceService(com.microsoft.azure.toolkit.intellij.common.IntellijDatasourceService) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 30 with AzureOperation

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation 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)

Aggregations

AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)64 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)11 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)11 IOException (java.io.IOException)10 Project (com.intellij.openapi.project.Project)9 ArrayList (java.util.ArrayList)9 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)8 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)6 Path (java.nio.file.Path)6 Module (com.intellij.openapi.module.Module)5 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)5 Azure (com.microsoft.azure.management.Azure)4 IFunctionApp (com.microsoft.azure.toolkit.lib.appservice.service.IFunctionApp)4 AzureUIRefreshEvent (com.microsoft.azuretools.utils.AzureUIRefreshEvent)4 Action (com.microsoft.azure.toolkit.lib.common.action.Action)3 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)3 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)3 AzureTaskManager (com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager)3