use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class WebAppService method convertConfig2Settings.
@AzureOperation(name = "webapp.init_config", type = AzureOperation.Type.TASK)
public static WebAppSettingModel convertConfig2Settings(final WebAppConfig config) {
final WebAppSettingModel settings = new WebAppSettingModel();
settings.setSubscriptionId(config.getSubscription().getId());
// creating if id is empty
settings.setCreatingResGrp(config.getResourceGroup() instanceof Draft || StringUtils.isEmpty(config.getResourceGroup().getId()));
settings.setResourceGroup(config.getResourceGroup().getName());
settings.setWebAppName(config.getName());
settings.setRegion(config.getRegion().getName());
settings.saveRuntime(config.getRuntime());
// creating if id is empty
settings.setCreatingAppServicePlan(config.getServicePlan() instanceof Draft || StringUtils.isEmpty(config.getServicePlan().getId()));
if (settings.isCreatingAppServicePlan()) {
settings.setAppServicePlanName(config.getServicePlan().getName());
} else {
settings.setAppServicePlanId(config.getServicePlan().getId());
}
settings.setPricing(config.getServicePlan().getPricingTier().getSize());
final MonitorConfig monitorConfig = config.getMonitorConfig();
if (monitorConfig != null) {
final DiagnosticConfig diagnosticConfig = monitorConfig.getDiagnosticConfig();
settings.setEnableApplicationLog(diagnosticConfig.isEnableApplicationLog());
settings.setApplicationLogLevel(diagnosticConfig.getApplicationLogLevel() == null ? null : diagnosticConfig.getApplicationLogLevel().getValue());
settings.setEnableWebServerLogging(diagnosticConfig.isEnableWebServerLogging());
settings.setWebServerLogQuota(diagnosticConfig.getWebServerLogQuota());
settings.setWebServerRetentionPeriod(diagnosticConfig.getWebServerRetentionPeriod());
settings.setEnableDetailedErrorMessage(diagnosticConfig.isEnableDetailedErrorMessage());
settings.setEnableFailedRequestTracing(diagnosticConfig.isEnableFailedRequestTracing());
}
settings.setTargetName(config.getApplication() == null ? null : config.getApplication().toFile().getName());
settings.setTargetPath(config.getApplication() == null ? null : config.getApplication().toString());
return settings;
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation 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;
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class CreateWebAppAction method createWebApp.
@AzureOperation(name = "webapp.create_detail", params = { "config.getName()" }, type = AzureOperation.Type.ACTION)
private Single<IWebApp> createWebApp(final WebAppConfig config) {
final AzureString title = title("webapp.create_detail", config.getName());
final AzureTask<IWebApp> task = new AzureTask<>(null, title, false, () -> {
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
indicator.setIndeterminate(true);
return webappService.createWebApp(config);
});
return AzureTaskManager.getInstance().runInModalAsObservable(task).toSingle().doOnSuccess(app -> {
this.notifyCreationSuccess(app);
this.refreshAzureExplorer(app);
});
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class CreateWebAppAction method actionPerformed.
@Override
@AzureOperation(name = "webapp.create", type = AzureOperation.Type.ACTION)
public void actionPerformed(NodeActionEvent e) {
final Project project = (Project) webappModule.getProject();
AzureSignInAction.requireSignedIn(project, () -> this.openDialog(project, null));
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class PushImageAction method onActionPerformed.
@Override
@AzureOperation(name = "docker|image.push.configuration", type = AzureOperation.Type.ACTION)
public boolean onActionPerformed(@NotNull AnActionEvent event, @Nullable Operation operation) {
Module module = DataKeys.MODULE.getData(event.getDataContext());
if (module == null) {
notifyError(Constant.ERROR_NO_SELECTED_PROJECT);
return true;
}
AzureTaskManager.getInstance().runLater(() -> runConfiguration(module));
return true;
}
Aggregations