Search in sources :

Example 1 with Draft

use of com.microsoft.azure.toolkit.intellij.common.Draft in project azure-tools-for-java by Microsoft.

the class CreateStorageAccountAction method createStorageAccount.

public static StorageAccount createStorageAccount(StorageAccountConfig config) {
    final String subscriptionId = config.getSubscription().getId();
    AzureTelemetry.getActionContext().setProperty("subscriptionId", subscriptionId);
    if (config.getResourceGroup() instanceof Draft) {
        // create resource group if necessary.
        final ResourceGroup newResourceGroup = Azure.az(AzureGroup.class).subscription(subscriptionId).create(config.getResourceGroup().getName(), config.getRegion().getName());
        config.setResourceGroup(newResourceGroup);
    }
    return Azure.az(AzureStorageAccount.class).create(config).commit();
}
Also used : Draft(com.microsoft.azure.toolkit.intellij.common.Draft) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) ResourceGroup(com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)

Example 2 with Draft

use of com.microsoft.azure.toolkit.intellij.common.Draft 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 3 with Draft

use of com.microsoft.azure.toolkit.intellij.common.Draft in project azure-tools-for-java by Microsoft.

the class CreateMySQLAction method createMySQL.

@AzureOperation(name = "mysql|server.create.task", params = { "config.getServerName()", "config.getSubscription().getName()" }, type = AzureOperation.Type.SERVICE)
public void createMySQL(final AzureMySQLConfig config) {
    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) {
            try {
                Azure.az(AzureGroup.class).get(subscriptionId, config.getResourceGroup().getName());
            } catch (Throwable ex) {
                Azure.az(AzureGroup.class).subscription(subscriptionId).create(config.getResourceGroup().getName(), config.getRegion().getName());
            }
            config.setResourceGroup(Azure.az(AzureGroup.class).get(subscriptionId, config.getResourceGroup().getName()));
        }
        // create mysql server
        final MySqlServer server = Azure.az(AzureMySql.class).subscription(subscriptionId).create(MySqlServerConfig.builder().subscription(config.getSubscription()).resourceGroup(config.getResourceGroup()).region(config.getRegion()).name(config.getServerName()).version(config.getVersion()).administratorLoginName(config.getAdminUsername()).administratorLoginPassword(String.valueOf(config.getPassword())).build()).commit();
        // update access from azure services
        if (config.isAllowAccessFromAzureServices()) {
            server.firewallRules().enableAzureAccessRule();
        }
        // update access from local machine
        if (config.isAllowAccessFromLocalMachine()) {
            server.firewallRules().enableLocalMachineAccessRule(server.getPublicIpForLocalMachine());
        }
    } 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) AzureMySql(com.microsoft.azure.toolkit.lib.mysql.AzureMySql) MySqlServer(com.microsoft.azure.toolkit.lib.mysql.MySqlServer) AzureGroup(com.microsoft.azure.toolkit.lib.resource.AzureGroup) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Example 4 with Draft

use of com.microsoft.azure.toolkit.intellij.common.Draft in project azure-tools-for-java by Microsoft.

the class WebAppService method convertConfig2Settings.

@AzureOperation(name = "webapp.init_config", type = AzureOperation.Type.TASK)
public static WebAppSettingModel convertConfig2Settings(final WebAppConfig config) {
    final WebAppSettingModel settings = new WebAppSettingModel();
    settings.setSubscriptionId(config.getSubscription().getId());
    // creating if id is empty
    settings.setCreatingResGrp(config.getResourceGroup() instanceof Draft || StringUtils.isEmpty(config.getResourceGroup().getId()));
    settings.setResourceGroup(config.getResourceGroup().getName());
    settings.setWebAppName(config.getName());
    settings.setRegion(config.getRegion().getName());
    settings.saveRuntime(config.getRuntime());
    // creating if id is empty
    settings.setCreatingAppServicePlan(config.getServicePlan() instanceof Draft || StringUtils.isEmpty(config.getServicePlan().getId()));
    if (settings.isCreatingAppServicePlan()) {
        settings.setAppServicePlanName(config.getServicePlan().getName());
    } else {
        settings.setAppServicePlanId(config.getServicePlan().getId());
    }
    settings.setPricing(config.getServicePlan().getPricingTier().getSize());
    final MonitorConfig monitorConfig = config.getMonitorConfig();
    if (monitorConfig != null) {
        final DiagnosticConfig diagnosticConfig = monitorConfig.getDiagnosticConfig();
        settings.setEnableApplicationLog(diagnosticConfig.isEnableApplicationLog());
        settings.setApplicationLogLevel(diagnosticConfig.getApplicationLogLevel() == null ? null : diagnosticConfig.getApplicationLogLevel().getValue());
        settings.setEnableWebServerLogging(diagnosticConfig.isEnableWebServerLogging());
        settings.setWebServerLogQuota(diagnosticConfig.getWebServerLogQuota());
        settings.setWebServerRetentionPeriod(diagnosticConfig.getWebServerRetentionPeriod());
        settings.setEnableDetailedErrorMessage(diagnosticConfig.isEnableDetailedErrorMessage());
        settings.setEnableFailedRequestTracing(diagnosticConfig.isEnableFailedRequestTracing());
    }
    settings.setTargetName(config.getApplication() == null ? null : config.getApplication().toFile().getName());
    settings.setTargetPath(config.getApplication() == null ? null : config.getApplication().toString());
    return settings;
}
Also used : Draft(com.microsoft.azure.toolkit.intellij.common.Draft) WebAppSettingModel(com.microsoft.azuretools.core.mvp.model.webapp.WebAppSettingModel) DiagnosticConfig(com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig) MonitorConfig(com.microsoft.azure.toolkit.lib.appservice.MonitorConfig) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Aggregations

Draft (com.microsoft.azure.toolkit.intellij.common.Draft)4 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)3 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)2 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)2 MonitorConfig (com.microsoft.azure.toolkit.lib.appservice.MonitorConfig)1 DiagnosticConfig (com.microsoft.azure.toolkit.lib.appservice.model.DiagnosticConfig)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 AzureMySql (com.microsoft.azure.toolkit.lib.mysql.AzureMySql)1 MySqlServer (com.microsoft.azure.toolkit.lib.mysql.MySqlServer)1 AzureGroup (com.microsoft.azure.toolkit.lib.resource.AzureGroup)1 AzureSqlServer (com.microsoft.azure.toolkit.lib.sqlserver.AzureSqlServer)1 WebAppSettingModel (com.microsoft.azuretools.core.mvp.model.webapp.WebAppSettingModel)1