use of com.microsoft.azure.toolkit.lib.appservice.model.WebContainer in project azure-tools-for-java by Microsoft.
the class WebAppSlimSettingPanel method isAbleToDeployToRoot.
private boolean isAbleToDeployToRoot(final AzureArtifact azureArtifact) {
final WebAppComboBoxModel selectedWebApp = getSelectedWebApp();
if (selectedWebApp == null || azureArtifact == null) {
return false;
}
final WebContainer webContainer = selectedWebApp.getRuntime().getWebContainer();
final String packaging = AzureArtifactManager.getInstance(project).getPackaging(azureArtifact);
final boolean isDeployingWar = StringUtils.equalsAnyIgnoreCase(packaging, MavenConstants.TYPE_WAR, "ear");
return isDeployingWar && StringUtils.containsAnyIgnoreCase(webContainer.getValue(), "tomcat", "jboss");
}
use of com.microsoft.azure.toolkit.lib.appservice.model.WebContainer in project azure-tools-for-java by Microsoft.
the class WebAppDeployDialog method deploy.
private void deploy(String artifactName, String artifactPath) {
int selectedRow = table.getSelectionIndex();
String appServiceName = table.getItems()[selectedRow].getText(0);
IWebApp webApp = webAppDetailsMap.get(appServiceName);
String jobDescription = String.format("Web App '%s' deployment", webApp.name());
if (isDeployToSlot) {
jobDescription = String.format("Web App '%s' deploy to slot '%s'", webApp.name(), isCreateNewSlot ? webAppSettingModel.getNewSlotName() : webAppSettingModel.getSlotName());
}
String deploymentName = UUID.randomUUID().toString();
AzureDeploymentProgressNotification.createAzureDeploymentProgressNotification(deploymentName, jobDescription);
boolean isDeployToRoot = btnDeployToRoot.getSelection();
Job job = new Job(jobDescription) {
@Override
protected IStatus run(IProgressMonitor monitor) {
String message = "Packaging Artifact...";
String cancelMessage = "Interrupted by user";
String successMessage = "";
String errorMessage = "Error";
Map<String, String> postEventProperties = new HashMap<>();
try {
boolean isJar = MavenUtils.isMavenProject(project) && MavenUtils.getPackaging(project).equals("jar");
postEventProperties.put(TelemetryConstants.JAVA_APPNAME, project.getName());
postEventProperties.put(TelemetryConstants.FILETYPE, isJar ? "jar" : "war");
Runtime runtime = webApp.getRuntime();
String osValue = (String) Optional.ofNullable(runtime.getOperatingSystem()).map(com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem::toString).orElse("");
String webContainerValue = (String) Optional.ofNullable(runtime.getWebContainer()).map(WebContainer::getValue).orElse("");
String javaVersionValue = (String) Optional.ofNullable(runtime.getJavaVersion()).map(com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion::getValue).orElse("");
postEventProperties.put(TelemetryConstants.RUNTIME, String.format("%s-%s-%s", osValue, webContainerValue, javaVersionValue));
postEventProperties.put(TelemetryConstants.WEBAPP_DEPLOY_TO_SLOT, Boolean.valueOf(isDeployToSlot).toString());
} catch (Exception e) {
}
String errTitle = "Deploy Web App Error";
monitor.beginTask(message, IProgressMonitor.UNKNOWN);
IWebAppBase<? extends AppServiceBaseEntity> deployTarget = null;
Operation operation = TelemetryManager.createOperation(WEBAPP, DEPLOY_WEBAPP);
try {
operation.start();
deployTarget = getRealWebApp(webApp, this, monitor, deploymentName);
String sitePath = buildSiteLink(deployTarget, isDeployToRoot ? null : artifactName);
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 5, message);
if (!MavenUtils.isMavenProject(project)) {
export(artifactName, artifactPath);
}
message = "Deploying Web App...";
if (isDeployToSlot) {
message = "Deploying Web App to Slot...";
}
monitor.setTaskName(message);
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 30, message);
AzureWebAppMvpModel.getInstance().deployArtifactsToWebApp(deployTarget, new File(artifactPath), isDeployToRoot, new UpdateProgressIndicator(monitor));
if (monitor.isCanceled()) {
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, null, -1, cancelMessage);
return Status.CANCEL_STATUS;
}
message = "Checking Web App availability...";
monitor.setTaskName(message);
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 20, message);
// to make warn up cancelable
int stepLimit = 5;
int sleepMs = 1000;
CountDownLatch countDownLatch = new CountDownLatch(1);
new Thread(() -> {
try {
for (int step = 0; step < stepLimit; ++step) {
if (monitor.isCanceled() || isUrlAccessible(sitePath)) {
// warm up
break;
}
Thread.sleep(sleepMs);
}
} catch (Exception ex) {
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@Thread@run@ProgressDialog@deploy@AppServiceCreateDialog@SingInDialog", ex));
} finally {
countDownLatch.countDown();
}
}).start();
try {
countDownLatch.await();
} catch (Exception ignore) {
}
if (monitor.isCanceled()) {
// it's published but not warmed up yet - consider as success
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 100, successMessage);
return Status.CANCEL_STATUS;
}
monitor.done();
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, sitePath, 100, successMessage);
AppInsightsClient.create("Deploy as WebApp", "", postEventProperties);
} catch (Exception ex) {
postEventProperties.put("PublishError", ex.getMessage());
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@deploy@AppServiceCreateDialog", ex));
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, null, -1, errorMessage);
if (deployTarget != null) {
deployTarget.start();
}
Display.getDefault().asyncExec(() -> ErrorWindow.go(parentShell, ex.getMessage(), errTitle));
EventUtil.logError(operation, ErrorType.systemError, ex, postEventProperties, null);
} finally {
EventUtil.logEvent(EventType.info, operation, postEventProperties);
operation.complete();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
use of com.microsoft.azure.toolkit.lib.appservice.model.WebContainer in project azure-tools-for-java by Microsoft.
the class AppServiceCreateDialog method fillWebContainers.
protected void fillWebContainers() {
try {
if (MavenUtils.isMavenProject(project)) {
packaging = MavenUtils.getPackaging(project);
}
} catch (Exception e) {
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "fillWebContainers@AppServiceCreateDialog", e));
}
final boolean isJarPacking = packaging.equals("jar");
final JavaVersion jdkModel = getSelectedJavaVersion();
final List<WebContainer> webContainers = isJarPacking ? Arrays.asList(WebContainer.JAVA_SE) : listWindowsWebContainersForWarFile(jdkModel);
comboWebContainer.removeAll();
binderWebConteiners = new ArrayList<>();
for (int i = 0; i < webContainers.size(); i++) {
WebContainer webContainerMod = webContainers.get(i);
comboWebContainer.add(webContainerMod.toString());
binderWebConteiners.add(webContainerMod);
if (i == 0 || webContainerMod == DEFAULT_WEB_CONTAINER) {
comboWebContainer.select(i);
}
}
String webContainer = CommonUtils.getPreference(CommonUtils.RUNTIME_WEBCONTAINER);
CommonUtils.selectComboIndex(comboWebContainer, webContainer);
}
use of com.microsoft.azure.toolkit.lib.appservice.model.WebContainer in project azure-tools-for-java by Microsoft.
the class WebAppSettingModel method getRuntime.
public Runtime getRuntime() {
if (StringUtils.isAllEmpty(operatingSystem, webAppContainer, webAppJavaVersion)) {
return parseRuntimeFromDeprecatedConfiguration();
}
final com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem system = com.microsoft.azure.toolkit.lib.appservice.model.OperatingSystem.fromString(operatingSystem);
final WebContainer container = WebContainer.fromString(webAppContainer);
final com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion javaVersion = com.microsoft.azure.toolkit.lib.appservice.model.JavaVersion.fromString(webAppJavaVersion);
return Runtime.getRuntime(system, container, javaVersion);
}
Aggregations