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