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();
}
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();
}
}
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();
}
}
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;
}
Aggregations