use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class AzureSignInAction method call.
private static <T> T call(Callable<T> loginCallable, String authMethod) {
final Operation operation = TelemetryManager.createOperation(ACCOUNT, SIGNIN);
final Map<String, String> properties = new HashMap<>();
properties.put(SIGNIN_METHOD, authMethod);
Optional.ofNullable(ProgressManager.getInstance().getProgressIndicator()).ifPresent(indicator -> indicator.setText2("Signing in..."));
try {
operation.start();
operation.trackProperties(properties);
operation.trackProperty(AZURE_ENVIRONMENT, Azure.az(AzureCloud.class).getName());
return loginCallable.call();
} catch (Exception e) {
if (shouldNoticeErrorToUser(e)) {
EventUtil.logError(operation, ErrorType.userError, e, properties, null);
}
throw new AzureToolkitRuntimeException(e.getMessage(), e);
} finally {
operation.complete();
}
}
use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class WebAppService method createWebApp.
@AzureOperation(name = "webapp.create_detail", params = { "config.getName()" }, type = AzureOperation.Type.SERVICE)
public IWebApp createWebApp(final WebAppConfig config) {
final WebAppSettingModel settings = convertConfig2Settings(config);
settings.setCreatingNew(true);
final Map<String, String> properties = settings.getTelemetryProperties(null);
final Operation operation = TelemetryManager.createOperation(WEBAPP, CREATE_WEBAPP);
try {
operation.start();
operation.trackProperties(properties);
return AzureWebAppMvpModel.getInstance().createWebAppFromSettingModel(settings);
} catch (final RuntimeException e) {
EventUtil.logError(operation, ErrorType.userError, e, properties, null);
throw e;
} finally {
operation.complete();
}
}
use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class CreateVMWizard method performFinish.
@Override
public boolean performFinish() {
Operation operation = TelemetryManager.createOperation(VM, CREATE_VM);
AzureTaskManager.getInstance().runInBackground("Creating virtual machine " + name + "...", new Runnable() {
@Override
public void run() {
try {
operation.start();
byte[] certData = new byte[0];
if (!certificate.isEmpty()) {
File certFile = new File(certificate);
if (certFile.exists()) {
try (FileInputStream certStream = new FileInputStream(certFile)) {
certData = new byte[(int) certFile.length()];
if (certStream.read(certData) != certData.length) {
throw new Exception("Unable to process certificate: " + "stream longer than informed size.");
}
} finally {
}
}
}
// create storage account when use choose to create new one
if (Objects.nonNull(newStorageAccount)) {
storageAccount = new CreateStorageAccountTask(newStorageAccount).execute();
}
VirtualMachine vm = AzureSDKManager.createVirtualMachine(subscription.getId(), name, resourceGroupName, isNewResourceGroup, size.name(), region.getName(), virtualMachineImage, knownMachineImage, isKnownMachineImage, storageAccount, virtualNetwork, newNetwork, isNewNetwork, subnet, publicIpAddress, withNewPip, availabilitySet, withNewAvailabilitySet, userName, password, certData.length > 0 ? new String(certData) : null);
// update resource groups cache if new resource group was created when creating storage account
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
try {
node.addChildNode(new VMNode(node, subscription.getId(), vm));
} catch (AzureCmdException e) {
PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), Messages.err, "An error occurred while refreshing the list of virtual machines.", e);
}
}
});
} catch (Exception e) {
EventUtil.logError(operation, ErrorType.userError, e, null, null);
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
public void run() {
PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), "Error Creating Virtual Machine", "An error occurred while trying to create the specified virtual machine", e);
}
});
} finally {
operation.complete();
}
}
});
return true;
}
use of com.microsoft.azuretools.telemetrywrapper.Operation in project azure-tools-for-java by Microsoft.
the class AddDockerSupportAction method onActionPerformed.
@Override
@AzureOperation(name = "docker.add_docker_support.configuration", type = AzureOperation.Type.ACTION)
public boolean onActionPerformed(@NotNull AnActionEvent anActionEvent, @Nullable Operation operation) {
module = DataKeys.MODULE.getData(anActionEvent.getDataContext());
if (module == null) {
notifyError(Constant.ERROR_NO_SELECTED_PROJECT);
return true;
}
pomXmlBasePath = Paths.get(module.getModuleFilePath()).getParent().toString();
String artifactRelativePath = Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER;
String dockerFileContent = Constant.DOCKERFILE_CONTENT_TOMCAT;
List<MavenProject> mavenProjects = MavenProjectsManager.getInstance(module.getProject()).getProjects();
Optional<MavenProject> res = mavenProjects.stream().filter(mvnprj -> Comparing.equal(Paths.get(mvnprj.getDirectory()).normalize(), Paths.get(pomXmlBasePath).normalize())).findFirst();
if (res.isPresent()) {
MavenProject mvnPrj = res.get();
String artifactName = mvnPrj.getFinalName() + "." + mvnPrj.getPackaging();
artifactRelativePath = Paths.get(pomXmlBasePath).toUri().relativize(Paths.get(mvnPrj.getBuildDirectory(), artifactName).toUri()).getPath();
// pre-define dockerfile content according to artifact type
if (MavenConstants.TYPE_WAR.equals(mvnPrj.getPackaging())) {
// maven war: tomcat
dockerFileContent = Constant.DOCKERFILE_CONTENT_TOMCAT;
} else if (MavenConstants.TYPE_JAR.equals(mvnPrj.getPackaging())) {
// maven jar: spring boot
dockerFileContent = Constant.DOCKERFILE_CONTENT_SPRING;
}
}
final Path path = Paths.get(pomXmlBasePath, Constant.DOCKERFILE_FOLDER, Constant.DOCKERFILE_NAME);
try {
// create docker file
DockerUtil.createDockerFile(pomXmlBasePath, Constant.DOCKERFILE_FOLDER, Constant.DOCKERFILE_NAME, String.format(dockerFileContent, artifactRelativePath));
VirtualFileManager.getInstance().asyncRefresh(() -> {
VirtualFile virtualDockerFile = LocalFileSystem.getInstance().findFileByPath(path.toString());
if (virtualDockerFile != null) {
new OpenFileDescriptor(module.getProject(), virtualDockerFile).navigate(true);
}
});
} catch (IOException e) {
EventUtil.logError(operation, ErrorType.userError, e, null, null);
e.printStackTrace();
notifyError(e.getMessage());
return true;
}
// detect docker daemon
String defaultDockerHost = null;
try {
defaultDockerHost = DefaultDockerClient.fromEnv().uri().toString();
} catch (DockerCertificateException e) {
EventUtil.logError(operation, ErrorType.userError, e, null, null);
e.printStackTrace();
// leave defaultDockerHost null
}
// print instructions
String notificationContent = "";
notificationContent += String.format(Constant.MESSAGE_DOCKERFILE_CREATED, path.normalize()) + "\n";
notificationContent += String.format(Constant.MESSAGE_DOCKER_HOST_INFO, defaultDockerHost) + "\n";
notificationContent += Constant.MESSAGE_ADD_DOCKER_SUPPORT_OK + "\n";
notificationContent += Constant.MESSAGE_INSTRUCTION + "\n";
notifyInfo(notificationContent);
return true;
}
Aggregations