use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.
the class AzureLoginHelper method ensureAzureSubsAvailable.
public static void ensureAzureSubsAvailable() throws AzureExecutionException {
if (!AuthMethodManager.getInstance().isSignedIn()) {
throw new AzureExecutionException(NEED_SIGN_IN);
}
IdentityAzureManager azureManager = IdentityAzureManager.getInstance();
final List<Subscription> subscriptions = azureManager.getSubscriptions();
if (CollectionUtils.isEmpty(subscriptions)) {
throw new AzureExecutionException(NO_SUBSCRIPTION);
}
final List<Subscription> selectedSubscriptions = azureManager.getSelectedSubscriptions();
if (CollectionUtils.isEmpty(selectedSubscriptions)) {
throw new AzureExecutionException(MUST_SELECT_SUBSCRIPTION);
}
}
use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.
the class FunctionDeploymentState method prepareStagingFolder.
@AzureOperation(name = "function.prepare_staging_folder_detail", params = { "stagingFolder.getName()", "this.deployModel.getFunctionAppConfig().getName()" }, type = AzureOperation.Type.TASK)
private void prepareStagingFolder(File stagingFolder, RunProcessHandler processHandler, @NotNull final Operation operation) {
AzureTaskManager.getInstance().read(() -> {
final Path hostJsonPath = FunctionUtils.getDefaultHostJson(project);
final PsiMethod[] methods = FunctionUtils.findFunctionsByAnnotation(functionDeployConfiguration.getModule());
final Path folder = stagingFolder.toPath();
try {
final Map<String, FunctionConfiguration> configMap = FunctionUtils.prepareStagingFolder(folder, hostJsonPath, functionDeployConfiguration.getModule(), methods);
operation.trackProperty(TelemetryConstants.TRIGGER_TYPE, StringUtils.join(FunctionUtils.getFunctionBindingList(configMap), ","));
} catch (final AzureExecutionException | IOException e) {
final String error = String.format("failed prepare staging folder[%s]", folder);
throw new AzureToolkitRuntimeException(error, e);
}
});
}
use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.
the class AnnotationHelper method getEnumConstantString.
private static String getEnumConstantString(PsiAnnotationMemberValue value) throws AzureExecutionException {
if (value instanceof PsiReferenceExpression) {
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression) value;
final Object resolved = referenceExpression.resolve();
if (resolved instanceof PsiEnumConstant) {
final PsiEnumConstant enumConstant = (PsiEnumConstant) resolved;
final PsiClass enumClass = enumConstant.getContainingClass();
if (enumClass != null) {
try {
return getEnumFieldString(enumClass.getQualifiedName(), enumConstant.getName());
} catch (ClassNotFoundException | IllegalAccessException e) {
throw new AzureExecutionException(e.getMessage(), e);
}
} else {
return enumConstant.getName();
}
}
}
return null;
}
use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.
the class AddDependencyAction method onActionPerformed.
@Override
public boolean onActionPerformed(@NotNull AnActionEvent event, @Nullable Operation operation) {
final Module module = event.getData(LangDataKeys.MODULE);
final Project project = module.getProject();
final MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
final MavenProject mavenProject = projectsManager.findProject(module);
if (mavenProject == null) {
PluginUtil.showErrorNotificationProject(project, "Error", String.format("Project '%s' is not a maven project.", project.getName()));
return true;
}
final AzureString title = AzureOperationBundle.title("springcloud.update_dependency", project.getName());
AzureTaskManager.getInstance().runInBackground(new AzureTask(project, title, true, () -> {
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
progressIndicator.setText("Syncing maven project " + project.getName());
final SettableFuture<Boolean> isDirty = SettableFuture.create();
AzureTaskManager.getInstance().runAndWait(() -> {
ProjectNotificationAware notificationAware = ProjectNotificationAware.getInstance(project);
isDirty.set(notificationAware.isNotificationVisible());
if (notificationAware.isNotificationVisible()) {
ExternalSystemProjectTracker projectTracker = ExternalSystemProjectTracker.getInstance(project);
projectTracker.scheduleProjectRefresh();
}
});
try {
if (isDirty.get().booleanValue()) {
projectsManager.forceUpdateProjects(Collections.singletonList(mavenProject)).get();
}
} catch (InterruptedException | ExecutionException e) {
PluginUtil.showErrorNotification("Error", "Failed to update project due to error: " + e.getMessage());
return;
}
try {
progressIndicator.setText("Check existing dependencies");
final String evaluateEffectivePom = MavenUtils.evaluateEffectivePom(project, mavenProject);
ProgressManager.checkCanceled();
if (StringUtils.isEmpty(evaluateEffectivePom)) {
PluginUtil.showErrorNotificationProject(project, "Error", "Failed to evaluate effective pom.");
return;
}
final String springBootVer = getMavenLibraryVersion(mavenProject, SPRING_BOOT_GROUP_ID, "spring-boot-autoconfigure");
if (StringUtils.isEmpty(springBootVer)) {
throw new AzureExecutionException(String.format("Module %s is not a spring-boot application.", module.getName()));
}
progressIndicator.setText("Get latest versions ...");
SpringCloudDependencyManager dependencyManager = new SpringCloudDependencyManager(evaluateEffectivePom);
Map<String, DependencyArtifact> versionMaps = dependencyManager.getDependencyVersions();
Map<String, DependencyArtifact> managerDependencyVersionsMaps = dependencyManager.getDependencyManagementVersions();
// given the spring-cloud-commons is greater or equal to 2.2.5.RELEASE, we should not add spring-cloud-starter-azure-spring-cloud-client
// because the code is already merged into spring repo: https://github.com/spring-cloud/spring-cloud-commons/pull/803
boolean noAzureSpringCloudClientDependency = shouldNotAddAzureSpringCloudClientDependency(versionMaps) || shouldNotAddAzureSpringCloudClientDependency(managerDependencyVersionsMaps);
ProgressManager.checkCanceled();
final List<DependencyArtifact> versionChanges = calculateVersionChanges(springBootVer, noAzureSpringCloudClientDependency, versionMaps);
if (versionChanges.isEmpty()) {
PluginUtil.showInfoNotificationProject(project, "Your project is update-to-date.", "No updates are needed.");
return;
}
progressIndicator.setText("Applying versions ...");
final File pomFile = new File(mavenProject.getFile().getCanonicalPath());
ProgressManager.checkCanceled();
if (applyVersionChanges(dependencyManager, pomFile, springBootVer, managerDependencyVersionsMaps, versionChanges)) {
noticeUserVersionChanges(project, pomFile, versionChanges);
} else {
PluginUtil.showInfoNotificationProject(project, "Your project is update-to-date.", "No updates are needed.");
}
} catch (DocumentException | IOException | AzureExecutionException | MavenProcessCanceledException e) {
PluginUtil.showErrorNotification("Error", "Failed to update Azure Spring Cloud dependencies due to error: " + e.getMessage());
}
}));
return false;
}
use of com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException in project azure-tools-for-java by Microsoft.
the class SpringCloudDependencyManager method getCompatibleVersions.
public static List<DependencyArtifact> getCompatibleVersions(List<DependencyArtifact> dependencies, String springBootVersionStr) throws AzureExecutionException, IOException, DocumentException {
List<DependencyArtifact> res = new ArrayList<>();
DefaultArtifactVersion springBootVersion = new DefaultArtifactVersion(springBootVersionStr);
for (DependencyArtifact dependency : dependencies) {
if (StringUtils.isNotEmpty(dependency.getCurrentVersion()) && isCompatibleVersion(dependency.getCurrentVersion(), springBootVersionStr)) {
continue;
}
List<String> latestVersions = getMavenCentralVersions(dependency.getGroupId(), dependency.getArtifactId());
String targetVersionText = getCompatibleVersionWithBootVersion(latestVersions, springBootVersion);
if (StringUtils.isEmpty(targetVersionText)) {
if (isGreaterOrEqualVersion(springBootVersionStr, LATEST_SPRING_BOOT_RELEASE) && !latestVersions.isEmpty()) {
// to handle the ege case: spring-cloud-starter-config 2.2.5.RELEASE supports spring boot 2.3.0
// here for newest spring boot versions, use the latest versions
targetVersionText = latestVersions.get(latestVersions.size() - 1);
} else {
throw new AzureExecutionException(String.format("Cannot get compatible version for %s:%s with Spring Boot with version %s", dependency.getGroupId(), dependency.getArtifactId(), springBootVersionStr));
}
}
dependency.setCompatibleVersion(targetVersionText);
if (!StringUtils.equals(dependency.getCurrentVersion(), targetVersionText)) {
res.add(dependency);
}
}
return res;
}
Aggregations