use of com.microsoft.azuretools.telemetrywrapper.Operation 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.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class FunctionsModuleBuilder method setupRootModel.
@Override
public void setupRootModel(@NotNull final ModifiableRootModel rootModel) {
final VirtualFile root = createAndGetContentEntry();
rootModel.addContentEntry(root);
// todo this should be moved to generic ModuleBuilder
if (myJdk != null) {
rootModel.setSdk(myJdk);
} else {
rootModel.inheritSdk();
}
final Project project = rootModel.getProject();
runWhenInitialized(rootModel.getProject(), () -> {
final Operation operation = TelemetryManager.createOperation(TelemetryConstants.FUNCTION, TelemetryConstants.CREATE_FUNCTION_PROJECT);
try {
operation.start();
final String tool = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_TOOL_KEY);
final String groupId = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_GROUPID_KEY);
final String artifactId = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_ARTIFACTID_KEY);
final String version = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_VERSION_KEY);
final String packageName = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_PACKAGE_NAME_KEY);
final String[] triggers = wizardContext.getUserData(AzureFunctionsConstants.WIZARD_TRIGGERS_KEY);
operation.trackProperty("tool", tool);
operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, StringUtils.join(triggers, ","));
File tempProjectFolder = null;
try {
tempProjectFolder = AzureFunctionsUtils.createFunctionProjectToTempFolder(groupId, artifactId, version, tool);
if (tempProjectFolder != null) {
if (tempProjectFolder.exists() && tempProjectFolder.isDirectory()) {
final File moduleFile = new File(getContentEntryPath());
final File srcFolder = Paths.get(tempProjectFolder.getAbsolutePath(), "src/main/java").toFile();
for (final String trigger : triggers) {
// class name like HttpTriggerFunction
final String className = trigger + "Function";
final String fileContent = AzureFunctionsUtils.generateFunctionClassByTrigger(trigger, packageName, className);
final File targetFile = Paths.get(srcFolder.getAbsolutePath(), String.format("%s/%s.java", packageName.replace('.', '/'), className)).toFile();
targetFile.getParentFile().mkdirs();
FileUtils.write(targetFile, fileContent, "utf-8");
}
FileUtils.copyDirectory(tempProjectFolder, moduleFile);
final VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
RefreshQueue.getInstance().refresh(true, true, null, new VirtualFile[] { vf });
final VirtualFile pomFile = vf.findChild("pom.xml");
if (pomFile != null) {
final MavenProjectsManager mavenProjectsManager = MavenProjectsManager.getInstance(project);
mavenProjectsManager.addManagedFiles(Collections.singletonList(pomFile));
}
}
}
} catch (final Exception e) {
PluginUtil.displayErrorDialogAndLog("Error", "Cannot create Azure Function Project in Java.", e);
EventUtil.logError(operation, ErrorType.systemError, e, null, null);
} finally {
if (tempProjectFolder != null && tempProjectFolder.isDirectory()) {
try {
FileUtils.deleteDirectory(tempProjectFolder);
} catch (final IOException e) {
// ignore
}
}
}
} finally {
operation.complete();
}
});
}
use of com.microsoft.azuretools.telemetrywrapper.Operation 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.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class DeploymentNodePresenter method onGetExportTemplateRes.
public void onGetExportTemplateRes(String template, File file) {
Operation operation = TelemetryManager.createOperation(ARM, EXPORT_TEMPALTE_FILE);
Observable.fromCallable(() -> {
operation.start();
IOUtils.write(template, new FileOutputStream(file), Charset.defaultCharset());
return true;
}).subscribe(res -> DefaultLoader.getIdeHelper().invokeLater(() -> {
operation.complete();
if (!isViewDetached()) {
getMvpView().showExportTemplateResult(true, null);
}
}), ex -> {
operation.complete();
EventUtil.logError(operation, ErrorType.systemError, Exceptions.propagate(ex), null, null);
if (!isViewDetached()) {
getMvpView().showExportTemplateResult(false, ex);
}
});
}
use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class RedisExplorerPresenter method onGetKeyAndValue.
public void onGetKeyAndValue(int db, String key) {
Operation operation = TelemetryManager.createOperation(TelemetryConstants.REDIS, TelemetryConstants.REDIS_GET);
operation.start();
Observable.fromCallable(() -> {
boolean isExist = RedisExplorerMvpModel.getInstance().checkKeyExistance(sid, id, db, key);
if (!isExist) {
return null;
} else {
return getValueByKey(db, key);
}
}).subscribeOn(getSchedulerProvider().io()).subscribe(result -> {
DefaultLoader.getIdeHelper().invokeLater(() -> {
if (isViewDetached()) {
return;
}
if (result == null) {
getMvpView().getKeyFail();
return;
}
getMvpView().updateKeyList();
getMvpView().showContent(result);
operation.complete();
});
}, e -> {
EventUtil.logError(operation, ErrorType.userError, new Exception(e), null, null);
operation.complete();
errorHandler(CANNOT_GET_REDIS_INFO, (Exception) e);
});
}
Aggregations