use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class CreateStorageAccountAction method create.
@AzureOperation(name = "storage|account.create", params = { "config.getName()" }, type = AzureOperation.Type.ACTION)
public static void create(final StorageAccountConfig config) {
final AzureString title = AzureOperationBundle.title("storage|account.create", config.getName());
AzureTaskManager.getInstance().runInBackground(title, () -> createStorageAccount(config));
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class CreateFunctionAppAction method openDialog.
@AzureOperation(name = "function.open_creation_dialog", type = AzureOperation.Type.ACTION)
private void openDialog(final Project project, @Nullable final FunctionAppConfig data) {
final FunctionAppCreationDialog dialog = new FunctionAppCreationDialog(project);
if (Objects.nonNull(data)) {
dialog.setData(data);
}
dialog.setOkActionListener((config) -> {
dialog.close();
this.createFunctionApp(config).subscribe(functionApp -> {
}, (error) -> {
final String title = String.format("Reopen dialog \"%s\"", dialog.getTitle());
final Consumer<Object> act = t -> AzureTaskManager.getInstance().runLater("open dialog", () -> this.openDialog(project, config));
final Action<?> action = new Action<>(act, new ActionView.Builder(title));
AzureMessager.getMessager().error(error, null, action);
});
});
dialog.show();
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class CreateFunctionAppAction method createFunctionApp.
@AzureOperation(name = "function.create_detail", params = { "config.getName()" }, type = AzureOperation.Type.ACTION)
private Single<IFunctionApp> createFunctionApp(final FunctionAppConfig config) {
final AzureString title = title("function.create_detail", config.getName());
final IntellijAzureMessager actionMessenger = new IntellijAzureMessager() {
@Override
public boolean show(IAzureMessage raw) {
if (raw.getType() != IAzureMessage.Type.INFO) {
return super.show(raw);
}
return false;
}
};
final AzureTask<IFunctionApp> task = new AzureTask<>(null, title, false, () -> {
final Operation operation = TelemetryManager.createOperation(TelemetryConstants.FUNCTION, TelemetryConstants.CREATE_FUNCTION_APP);
operation.trackProperties(config.getTelemetryProperties());
try {
AzureMessager.getContext().setMessager(actionMessenger);
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
indicator.setIndeterminate(true);
return functionAppService.createFunctionApp(config);
} finally {
operation.trackProperties(AzureTelemetry.getActionContext().getProperties());
operation.complete();
}
});
return AzureTaskManager.getInstance().runInModalAsObservable(task).toSingle().doOnSuccess(app -> {
AzureMessager.getMessager().success(message("function.create.success.message", app.name()), message("function.create.success.title"));
this.refreshAzureExplorer(app);
});
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class FunctionUtils method prepareStagingFolder.
@AzureOperation(name = "function.prepare_staging_folder", type = AzureOperation.Type.TASK)
public static Map<String, FunctionConfiguration> prepareStagingFolder(Path stagingFolder, Path hostJson, Module module, PsiMethod[] methods) throws AzureExecutionException, IOException {
final Map<String, FunctionConfiguration> configMap = generateConfigurations(methods);
if (stagingFolder.toFile().isDirectory()) {
FileUtils.cleanDirectory(stagingFolder.toFile());
}
final Path jarFile = JarUtils.buildJarFileToStagingPath(stagingFolder.toString(), module);
final String scriptFilePath = "../" + jarFile.getFileName().toString();
configMap.values().forEach(config -> config.setScriptFile(scriptFilePath));
for (final Map.Entry<String, FunctionConfiguration> config : configMap.entrySet()) {
if (StringUtils.isNotBlank(config.getKey())) {
final File functionJsonFile = Paths.get(stagingFolder.toString(), config.getKey(), FUNCTION_JSON).toFile();
writeFunctionJsonFile(functionJsonFile, config.getValue());
}
}
final File hostJsonFile = new File(stagingFolder.toFile(), "host.json");
copyFilesWithDefaultContent(hostJson, hostJsonFile, DEFAULT_HOST_JSON);
final List<File> jarFiles = new ArrayList<>();
OrderEnumerator.orderEntries(module).productionOnly().forEachLibrary(lib -> {
if (StringUtils.isNotEmpty(lib.getName()) && ArrayUtils.contains(lib.getName().split("\\:"), FUNCTION_JAVA_LIBRARY_ARTIFACT_ID)) {
return true;
}
if (lib != null) {
for (final VirtualFile virtualFile : lib.getFiles(OrderRootType.CLASSES)) {
final File file = new File(stripExtraCharacters(virtualFile.getPath()));
if (file.exists()) {
jarFiles.add(file);
}
}
}
return true;
});
final File libFolder = new File(stagingFolder.toFile(), "lib");
for (final File file : jarFiles) {
FileUtils.copyFileToDirectory(file, libFolder);
}
return configMap;
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class FunctionRunState method launchDebugger.
@AzureOperation(name = "function.launch_debugger", type = AzureOperation.Type.TASK)
private void launchDebugger(final Project project, int debugPort) {
final Runnable runnable = () -> {
final RunManagerImpl manager = new RunManagerImpl(project);
final ConfigurationFactory configFactory = RemoteConfigurationType.getInstance().getConfigurationFactories()[0];
final RemoteConfiguration remoteConfig = new RemoteConfiguration(project, configFactory);
remoteConfig.PORT = String.valueOf(debugPort);
remoteConfig.HOST = "localhost";
remoteConfig.USE_SOCKET_TRANSPORT = true;
remoteConfig.SERVER_MODE = false;
remoteConfig.setName("azure functions");
final RunnerAndConfigurationSettings configuration = new RunnerAndConfigurationSettingsImpl(manager, remoteConfig, false);
manager.setTemporaryConfiguration(configuration);
ExecutionUtil.runConfiguration(configuration, ExecutorRegistry.getInstance().getExecutorById(ToolWindowId.DEBUG));
};
AzureTaskManager.getInstance().runAndWait(runnable, AzureTask.Modality.ANY);
}
Aggregations