use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class CreateRedisCacheForm method onOK.
private void onOK() {
final Operation operation = TelemetryManager.createOperation(REDIS, CREATE_REDIS);
try {
operation.start();
Azure azure = azureManager.getAzure(currentSub.getId());
setSubscription(currentSub);
ProcessingStrategy processor = RedisCacheUtil.doGetProcessor(azure, skus, redisCacheNameValue, selectedLocationValue, selectedResGrpValue, selectedPriceTierValue, noSSLPort, newResGrp);
ExecutorService executor = Executors.newSingleThreadExecutor();
ListeningExecutorService executorService = MoreExecutors.listeningDecorator(executor);
ListenableFuture<Void> futureTask = executorService.submit(new CreateRedisCallable(processor));
final ProcessingStrategy processorInner = processor;
Futures.addCallback(futureTask, new FutureCallback<Void>() {
@Override
public void onSuccess(Void arg0) {
if (onCreate != null) {
onCreate.run();
operation.complete();
}
}
@Override
public void onFailure(Throwable throwable) {
DefaultLoader.getUIHelper().showError(throwable.getMessage(), "Error occurred when creating Redis Cache: " + redisCacheNameValue);
EventUtil.logError(operation, ErrorType.userError, new Exception(throwable), null, null);
operation.complete();
try {
// notify the waitting thread the thread being waited incurred exception to clear blocking queue
processorInner.notifyCompletion();
} catch (InterruptedException ex) {
String msg = String.format(CREATING_ERROR_INDICATOR, "notifyCompletion", ex.getMessage());
PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, ex);
}
}
}, MoreExecutors.directExecutor());
close(DialogWrapper.OK_EXIT_CODE, true);
} catch (Exception ex) {
ex.printStackTrace();
EventUtil.logError(operation, ErrorType.userError, ex, null, null);
operation.complete();
}
}
use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class LivySparkBatchJobRunConfiguration method getState.
@Nullable
@Override
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment executionEnvironment) throws ExecutionException {
Operation operation = executionEnvironment.getUserData(TelemetryKeys.OPERATION);
final String debugTarget = executionEnvironment.getUserData(SparkBatchJobDebuggerRunner.DEBUG_TARGET_KEY);
final boolean isExecutor = StringUtils.equals(debugTarget, SparkBatchJobDebuggerRunner.DEBUG_EXECUTOR);
RunProfileStateWithAppInsightsEvent state = null;
final Artifact selectedArtifact = ArtifactUtil.getArtifactWithOutputPaths(getProject()).stream().filter(artifact -> artifact.getName().equals(getSubmitModel().getArtifactName())).findFirst().orElse(null);
if (executor instanceof SparkBatchJobDebugExecutor) {
final ISparkBatchJob remoteDebugBatch = sparkRemoteBatch;
if (!(remoteDebugBatch instanceof SparkBatchRemoteDebugJob)) {
throw new ExecutionException("Spark Batch Job is not prepared for " + executor.getId());
}
if (isExecutor) {
setRunMode(RunMode.REMOTE_DEBUG_EXECUTOR);
state = new SparkBatchRemoteDebugExecutorState(getModel().getSubmitModel(), operation, remoteDebugBatch);
} else {
if (selectedArtifact != null) {
BuildArtifactsBeforeRunTaskProvider.setBuildArtifactBeforeRun(getProject(), this, selectedArtifact);
}
setRunMode(RunMode.REMOTE);
state = new SparkBatchRemoteDebugState(getModel().getSubmitModel(), operation, sparkRemoteBatch);
}
} else if (executor instanceof SparkBatchJobRunExecutor) {
final ISparkBatchJob remoteBatch = sparkRemoteBatch;
if (remoteBatch == null) {
throw new ExecutionException("Spark Batch Job is not prepared for " + executor.getId());
}
if (selectedArtifact != null) {
BuildArtifactsBeforeRunTaskProvider.setBuildArtifactBeforeRun(getProject(), this, selectedArtifact);
}
setRunMode(RunMode.REMOTE);
state = new SparkBatchRemoteRunState(getModel().getSubmitModel(), operation, remoteBatch);
} else if (executor instanceof DefaultDebugExecutor) {
setRunMode(RunMode.LOCAL);
if (operation == null) {
operation = TelemetryManager.createOperation(TelemetryConstants.HDINSIGHT, TelemetryConstants.DEBUG_LOCAL_SPARK_JOB);
operation.start();
}
state = new SparkBatchLocalDebugState(getProject(), getModel().getLocalRunConfigurableModel(), operation);
} else if (executor instanceof DefaultRunExecutor) {
setRunMode(RunMode.LOCAL);
if (operation == null) {
operation = TelemetryManager.createOperation(TelemetryConstants.HDINSIGHT, TelemetryConstants.RUN_LOCAL_SPARK_JOB);
operation.start();
}
state = new SparkBatchLocalRunState(getProject(), getModel().getLocalRunConfigurableModel(), operation);
}
if (state != null) {
final Map<String, String> props = getActionProperties().entrySet().stream().collect(Collectors.toMap((Map.Entry<Object, Object> entry) -> entry.getKey() == null ? null : entry.getKey().toString(), (Map.Entry<Object, Object> entry) -> entry.getValue() == null ? "" : entry.getValue().toString()));
final String configurationId = Optional.ofNullable(executionEnvironment.getRunnerAndConfigurationSettings()).map(settings -> settings.getType().getId()).orElse("");
props.put("configurationId", configurationId);
state.createAppInsightEvent(executor, props);
EventUtil.logEvent(EventType.info, operation, props);
// Clear the action properties
getActionProperties().clear();
}
return state;
}
use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class NodeActionListener method actionPerformedAsync.
public ListenableFuture<Void> actionPerformedAsync(NodeActionEvent e) {
String serviceName = transformHDInsight(getServiceName(e), e.getAction().getNode());
String operationName = getOperationName(e);
Operation operation = TelemetryManager.createOperation(serviceName, operationName);
Node node = e.getAction().getNode();
Mono<Map<String, String>> telemetryMono = buildProp(node);
try {
operation.start();
actionPerformed(e);
return Futures.immediateFuture(null);
} catch (AzureCmdException | RuntimeException ex) {
EventUtil.logError(operation, ErrorType.systemError, ex, null, null);
AzureMessager.getMessager().error(ex);
return Futures.immediateFailedFuture(ex);
} finally {
telemetryMono.subscribeOn(Schedulers.boundedElastic()).subscribe(properties -> {
operation.trackProperties(properties);
operation.complete();
});
}
}
use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class RedisExplorerPresenter method onKeyList.
/**
* Called when Scan button is clicked.
*
* @param sid
* subscription id of Redis Cache
* @param id
* resource id of Redis Cache
* @param db
* index of Redis Cache database
* @param cursor
* scan cursor for Redis Cache
* @param pattern
* scan match pattern for Redis Cache
*/
public void onKeyList(int db, String cursor, String pattern) {
Operation operation = TelemetryManager.createOperation(TelemetryConstants.REDIS, TelemetryConstants.REDIS_SCAN);
operation.start();
Observable.fromCallable(() -> {
return RedisExplorerMvpModel.getInstance().scanKeys(sid, id, db, cursor, pattern);
}).subscribeOn(getSchedulerProvider().io()).subscribe(result -> {
DefaultLoader.getIdeHelper().invokeLater(() -> {
if (isViewDetached()) {
return;
}
getMvpView().showScanResult(new RedisScanResult(result));
operation.complete();
});
}, e -> {
EventUtil.logError(operation, ErrorType.userError, new Exception(e), null, null);
operation.complete();
errorHandler(CANNOT_GET_REDIS_INFO, (Exception) e);
});
}
use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class CreateFunctionAction method invokeDialog.
@Override
protected PsiElement[] invokeDialog(Project project, PsiDirectory psiDirectory) {
final Operation operation = TelemetryManager.createOperation(TelemetryConstants.FUNCTION, TelemetryConstants.CREATE_FUNCTION_TRIGGER);
try {
operation.start();
PsiPackage pkg = JavaDirectoryService.getInstance().getPackage(psiDirectory);
// get existing package from current directory
String hintPackageName = pkg == null ? "" : pkg.getQualifiedName();
CreateFunctionForm form = new CreateFunctionForm(project, hintPackageName);
List<PsiElement> psiElements = new ArrayList<>();
if (form.showAndGet()) {
final FunctionTemplate bindingTemplate;
try {
Map<String, String> parameters = form.getTemplateParameters();
final String connectionName = parameters.get("connection");
String triggerType = form.getTriggerType();
String packageName = parameters.get("packageName");
String className = parameters.get("className");
PsiDirectory directory = ClassUtil.sourceRoot(psiDirectory);
String newName = packageName.replace('.', '/');
bindingTemplate = AzureFunctionsUtils.getFunctionTemplate(triggerType);
operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, triggerType);
if (StringUtils.equalsIgnoreCase(triggerType, CreateFunctionForm.EVENT_HUB_TRIGGER)) {
if (StringUtils.isBlank(connectionName)) {
throw new AzureExecutionException(message("function.createFunction.error.connectionMissed"));
}
parameters.putIfAbsent("eventHubName", "myeventhub");
parameters.putIfAbsent("consumerGroup", "$Default");
}
final String functionClassContent = AzureFunctionsUtils.substituteParametersInTemplate(bindingTemplate, parameters);
if (StringUtils.isNotEmpty(functionClassContent)) {
AzureTaskManager.getInstance().write(() -> {
CreateFileAction.MkDirs mkDirs = ApplicationManager.getApplication().runWriteAction((Computable<CreateFileAction.MkDirs>) () -> new CreateFileAction.MkDirs(newName + '/' + className, directory));
PsiFileFactory factory = PsiFileFactory.getInstance(project);
try {
mkDirs.directory.checkCreateFile(className + ".java");
} catch (final IncorrectOperationException e) {
final String dir = mkDirs.directory.getName();
final String error = String.format("failed to create function class[%s] in directory[%s]", className, dir);
throw new AzureToolkitRuntimeException(error, e);
}
CommandProcessor.getInstance().executeCommand(project, () -> {
PsiFile psiFile = factory.createFileFromText(className + ".java", JavaFileType.INSTANCE, functionClassContent);
psiElements.add(mkDirs.directory.add(psiFile));
}, null, null);
if (StringUtils.equalsIgnoreCase(triggerType, CreateFunctionForm.EVENT_HUB_TRIGGER)) {
try {
String connectionString = form.getEventHubNamespace() == null ? DEFAULT_EVENT_HUB_CONNECTION_STRING : getEventHubNamespaceConnectionString(form.getEventHubNamespace());
AzureFunctionsUtils.applyKeyValueToLocalSettingFile(new File(project.getBasePath(), "local.settings.json"), parameters.get("connection"), connectionString);
} catch (IOException e) {
EventUtil.logError(operation, ErrorType.systemError, e, null, null);
final String error = "failed to get connection string and save to local settings";
throw new AzureToolkitRuntimeException(error, e);
}
}
});
}
} catch (AzureExecutionException e) {
AzureMessager.getMessager().error(e);
EventUtil.logError(operation, ErrorType.systemError, e, null, null);
}
}
if (!psiElements.isEmpty()) {
FileEditorManager.getInstance(project).openFile(psiElements.get(0).getContainingFile().getVirtualFile(), false);
}
return psiElements.toArray(new PsiElement[0]);
} finally {
operation.complete();
}
}
Aggregations