use of com.microsoft.azure.toolkit.lib.Azure in project azure-tools-for-java by Microsoft.
the class AzureSignInAction method onAzureSignIn.
public static void onAzureSignIn(Project project) {
JFrame frame = WindowManager.getInstance().getFrame(project);
AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
boolean isSignIn = authMethodManager.isSignedIn();
if (isSignIn) {
boolean res = DefaultLoader.getUIHelper().showYesNoDialog(frame.getRootPane(), getSignOutWarningMessage(authMethodManager), "Azure Sign Out", AzureIconLoader.loadIcon(AzureIconSymbol.Common.AZURE));
if (res) {
EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
authMethodManager.signOut();
});
}
} else {
signInIfNotSignedIn(project).subscribe(isLoggedIn -> {
if (isLoggedIn) {
AzureAccount az = Azure.az(AzureAccount.class);
AzureTaskManager.getInstance().runOnPooledThread(() -> authMethodManager.getAzureManager().getSelectedSubscriptions().stream().limit(5).forEach(s -> {
// pre-load regions;
az.listRegions(s.getId());
}));
}
});
}
}
use of com.microsoft.azure.toolkit.lib.Azure in project azure-tools-for-java by Microsoft.
the class CreateDeploymentForm method doOKAction.
@Override
protected void doOKAction() {
deploymentName = deploymentNameTextField.getText();
final AzureString title = AzureOperationBundle.title("arm|deployment.deploy", deploymentName);
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, false, () -> {
EventUtil.executeWithLog(TelemetryConstants.ARM, TelemetryConstants.CREATE_DEPLOYMENT, (operation -> {
Subscription subs = (Subscription) subscriptionCb.getSelectedItem();
com.microsoft.azure.management.Azure azure = AuthMethodManager.getInstance().getAzureClient(subs.getId());
WithTemplate template;
if (createNewRgButton.isSelected()) {
rgName = rgNameTextFiled.getText();
final Region region = (Region) regionCb.getSelectedItem();
template = azure.deployments().define(deploymentName).withNewResourceGroup(rgNameTextFiled.getText(), com.microsoft.azure.management.resources.fluentcore.arm.Region.fromName(region.getName()));
} else {
ResourceGroup rg = (ResourceGroup) rgNameCb.getSelectedItem();
List<ResourceEx<Deployment>> deployments = AzureMvpModel.getInstance().getDeploymentByRgName(subs.getId(), rg.getName());
boolean isExist = deployments.parallelStream().anyMatch(deployment -> deployment.getResource().name().equals(deploymentName));
if (isExist) {
throw new RuntimeException(DUPLICATED_DEPLOYMENT_NAME);
}
rgName = rg.getName();
template = azure.deployments().define(deploymentName).withExistingResourceGroup(rg.getName());
}
String fileText = templateTextField.getText();
String content = IOUtils.toString(new FileReader(fileText));
String parametersPath = parametersTextField.getText();
String parameters = StringUtils.isEmpty(parametersPath) ? "{}" : IOUtils.toString(new FileReader(parametersPath));
parameters = DeploymentUtils.parseParameters(parameters);
template.withTemplate(content).withParameters(parameters).withMode(DeploymentMode.INCREMENTAL).create();
UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_SUCCESS, MessageType.INFO);
updateUI();
}), (ex) -> {
UIUtils.showNotification(statusBar, NOTIFY_CREATE_DEPLOYMENT_FAIL + ", " + ex.getMessage(), MessageType.ERROR);
updateUI();
});
}));
close(DialogWrapper.OK_EXIT_CODE, true);
}
use of com.microsoft.azure.toolkit.lib.Azure in project azure-tools-for-java by Microsoft.
the class SignInCommandHandler method onAzureSignIn.
private void onAzureSignIn(Shell shell) {
final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
boolean isSignIn = authMethodManager.isSignedIn();
if (isSignIn) {
boolean res = showYesNoDialog(shell, "Azure Sign Out", SignOutCommandHandler.getSignOutWarningMessage(authMethodManager));
if (res) {
EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
authMethodManager.signOut();
});
}
} else {
signInIfNotSignedIn(shell).subscribe(isLoggedIn -> {
if (isLoggedIn) {
AzureAccount az = Azure.az(AzureAccount.class);
AzureTaskManager.getInstance().runOnPooledThread(() -> authMethodManager.getAzureManager().getSelectedSubscriptions().stream().limit(5).forEach(s -> {
// pre-load regions;
az.listRegions(s.getId());
}));
}
});
}
}
use of com.microsoft.azure.toolkit.lib.Azure in project azure-tools-for-java by Microsoft.
the class AzurePlugin method runActivity.
@Override
public void runActivity(@NotNull Project project) {
// read legacy settings from old data.xml
final String installationId = "wangmi-azure-intellij-plugin-base";
final String pluginVersion = "0.0.1-SNAPSHOT";
// check non-empty for valid data.xml
if (StringUtils.isNoneBlank(installationId, pluginVersion)) {
final IntellijStore.AzureConfigurationData config = IntellijStore.getInstance().getState();
IntellijStore.getInstance().loadState(config);
}
final IntellijStore.AzureConfigurationData config = IntellijStore.getInstance().getState();
String installationID = InstallationIdUtils.getHashMac();
if (StringUtils.isBlank(installationID)) {
installationID = StringUtils.firstNonBlank(InstallationIdUtils.getHashMac(), InstallationIdUtils.hash(PermanentInstallationID.get()));
}
final String userAgent = String.format(USER_AGENT, PLUGIN_VERSION, installationID);
Azure.az().config().setLogLevel("NONE");
Azure.az().config().setUserAgent(userAgent);
final AnAction action = ActionManager.getInstance().getAction(WhatsNewAction.ID);
final DataContext context = dataId -> CommonDataKeys.PROJECT.getName().equals(dataId) ? project : null;
AzureTaskManager.getInstance().runLater(() -> ActionUtil.invokeAction(action, context, "AzurePluginStartupActivity", null, null));
}
Aggregations