use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.
the class PublishWebAppOnLinuxDialog method apply.
private void apply() {
model.setDockerFilePath(cpAcr.getDockerfilePath());
// set ACR info
model.setPrivateRegistryImageSetting(new PrivateRegistryImageSetting(cpAcr.getServerUrl(), cpAcr.getUserName(), cpAcr.getPassword(), cpAcr.getImageTag(), cpAcr.getStartupFile()));
// set target
model.setTargetPath(targetPath);
model.setTargetName(Paths.get(targetPath).getFileName().toString());
// set web app info
if (rdoExistingWebApp.getSelection()) {
// existing web app
model.setCreatingNewWebAppOnLinux(false);
IWebApp selectedWebApp = getSelectedWebApp();
if (selectedWebApp != null) {
model.setWebAppId(selectedWebApp.id());
model.setWebAppName(selectedWebApp.name());
model.setSubscriptionId(selectedWebApp.subscriptionId());
model.setResourceGroupName(selectedWebApp.resourceGroup());
} else {
model.setWebAppId(null);
model.setWebAppName(null);
model.setSubscriptionId(null);
model.setResourceGroupName(null);
}
} else if (rdoNewWebApp.getSelection()) {
// create new web app
model.setCreatingNewWebAppOnLinux(true);
model.setWebAppId("");
model.setWebAppName(cpNew.txtAppName.getText());
Subscription selectedSubscription = getSelectedSubscription();
if (selectedSubscription != null) {
model.setSubscriptionId(selectedSubscription.getId());
}
// resource group
if (cpNew.rdoExistingResourceGroup.getSelection()) {
// existing RG
model.setCreatingNewResourceGroup(false);
ResourceGroup selectedRg = getSelectedResourceGroup();
if (selectedRg != null) {
model.setResourceGroupName(selectedRg.getName());
} else {
model.setResourceGroupName(null);
}
} else if (cpNew.rdoNewResourceGroup.getSelection()) {
// new RG
model.setCreatingNewResourceGroup(true);
model.setResourceGroupName(cpNew.txtNewResourceGroupName.getText());
}
// app service plan
if (cpNew.rdoNewAppServicePlan.getSelection()) {
model.setCreatingNewAppServicePlan(true);
model.setAppServicePlanName(cpNew.txtAppServicePlanName.getText());
Region selectedLocation = getSelectedLocation();
if (selectedLocation != null) {
model.setLocationName(selectedLocation.getLabel());
} else {
model.setLocationName(null);
}
PricingTier selectedPricingTier = getSelectedPricingTier();
if (selectedPricingTier != null) {
model.setPricingSkuTier(selectedPricingTier.getTier());
model.setPricingSkuSize(selectedPricingTier.getSize());
} else {
model.setPricingSkuTier(null);
model.setPricingSkuSize(null);
}
} else if (cpNew.rdoExistingAppServicePlan.getSelection()) {
model.setCreatingNewAppServicePlan(false);
IAppServicePlan selectedAsp = getSelectedAppServicePlan();
if (selectedAsp != null) {
model.setAppServicePlanId(selectedAsp.id());
} else {
model.setAppServicePlanId(null);
}
}
}
}
use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.
the class PublishWebAppOnLinuxDialog method execute.
private void execute() {
Operation operation = TelemetryManager.createOperation(WEBAPP, DEPLOY_WEBAPP_CONTAINER);
Observable.fromCallable(() -> {
ConsoleLogger.info("Starting job ... ");
operation.start();
if (basePath == null) {
ConsoleLogger.error("Project base path is null.");
throw new FileNotFoundException("Project base path is null.");
}
// locate artifact to specified location
String targetFilePath = model.getTargetPath();
ConsoleLogger.info(String.format("Locating artifact ... [%s]", targetFilePath));
// validate dockerfile
Path targetDockerfile = Paths.get(model.getDockerFilePath());
ConsoleLogger.info(String.format("Validating dockerfile ... [%s]", targetDockerfile));
if (!targetDockerfile.toFile().exists()) {
throw new FileNotFoundException("Dockerfile not found.");
}
// replace placeholder if exists
String content = new String(Files.readAllBytes(targetDockerfile));
content = content.replaceAll(Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER, Paths.get(basePath).toUri().relativize(Paths.get(targetFilePath).toUri()).getPath());
Files.write(targetDockerfile, content.getBytes());
// build image
PrivateRegistryImageSetting acrInfo = model.getPrivateRegistryImageSetting();
ConsoleLogger.info(String.format("Building image ... [%s]", acrInfo.getImageTagWithServerUrl()));
DockerClient docker = DefaultDockerClient.fromEnv().build();
DockerUtil.ping(docker);
DockerUtil.buildImage(docker, acrInfo.getImageTagWithServerUrl(), targetDockerfile.getParent(), targetDockerfile.getFileName().toString(), new DockerProgressHandler());
// push to ACR
ConsoleLogger.info(String.format("Pushing to ACR ... [%s] ", acrInfo.getServerUrl()));
DockerUtil.pushImage(docker, acrInfo.getServerUrl(), acrInfo.getUsername(), acrInfo.getPassword(), acrInfo.getImageTagWithServerUrl(), new DockerProgressHandler());
// deploy
if (model.isCreatingNewWebAppOnLinux()) {
// create new WebApp
ConsoleLogger.info(String.format("Creating new WebApp ... [%s]", model.getWebAppName()));
IWebApp app = AzureWebAppMvpModel.getInstance().createAzureWebAppWithPrivateRegistryImage(model);
if (app != null && app.name() != null) {
ConsoleLogger.info(String.format("URL: http://%s.azurewebsites.net/", app.name()));
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
}
} else {
// update WebApp
ConsoleLogger.info(String.format("Updating WebApp ... [%s]", model.getWebAppName()));
IWebApp app = AzureWebAppMvpModel.getInstance().updateWebAppOnDocker(model.getWebAppId(), acrInfo);
if (app != null && app.name() != null) {
ConsoleLogger.info(String.format("URL: http://%s.azurewebsites.net/", app.name()));
}
}
return null;
}).subscribeOn(SchedulerProviderFactory.getInstance().getSchedulerProvider().io()).subscribe(ret -> {
ConsoleLogger.info("Job done");
if (model.isCreatingNewWebAppOnLinux() && AzureUIRefreshCore.listeners != null) {
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH, null));
}
sendTelemetry(true, null);
operation.complete();
}, err -> {
err.printStackTrace();
ConsoleLogger.error(err.getMessage());
EventUtil.logError(operation, ErrorType.systemError, new Exception(err), null, null);
operation.complete();
sendTelemetry(false, err.getMessage());
});
}
use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.
the class AzureWebAppMvpModel method deployArtifactsToWebApp.
@AzureOperation(name = "webapp|artifact.upload", params = { "file.getName()", "deployTarget.name()" }, type = AzureOperation.Type.SERVICE)
public void deployArtifactsToWebApp(@NotNull final IWebAppBase deployTarget, @NotNull final File file, boolean isDeployToRoot, @NotNull final IProgressIndicator progressIndicator) {
if (!(deployTarget instanceof IWebApp || deployTarget instanceof IWebAppDeploymentSlot)) {
final String error = "the deployment target is not a valid (deployment slot of) Web App";
final String action = "select a valid Web App or deployment slot to deploy the artifact";
throw new AzureToolkitRuntimeException(error, action);
}
// stop target app service
String stopMessage = deployTarget instanceof IWebApp ? STOP_WEB_APP : STOP_DEPLOYMENT_SLOT;
progressIndicator.setText(stopMessage);
deployTarget.stop();
final DeployType deployType = getDeployTypeByWebContainer(deployTarget.getRuntime().getWebContainer());
// java se runtime will always deploy to root
if (isDeployToRoot || Objects.equals(deployTarget.getRuntime().getWebContainer(), com.microsoft.azure.toolkit.lib.appservice.model.WebContainer.JAVA_SE)) {
deployTarget.deploy(deployType, file);
} else {
final String webappPath = String.format("webapps/%s", FilenameUtils.getBaseName(file.getName()).replaceAll("#", StringUtils.EMPTY));
deployTarget.deploy(deployType, file, webappPath);
}
String successMessage = deployTarget instanceof IWebApp ? DEPLOY_SUCCESS_WEB_APP : DEPLOY_SUCCESS_DEPLOYMENT_SLOT;
progressIndicator.setText(successMessage);
deployTarget.start();
}
use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.
the class SettingPanel method renderWebAppOnLinuxList.
@Override
public void renderWebAppOnLinuxList(List<IWebApp> webAppOnLinuxList) {
btnRefresh.setEnabled(true);
webAppTable.getEmptyText().setText(TABLE_EMPTY_MESSAGE);
final List<IWebApp> sortedList = webAppOnLinuxList.stream().sorted((a, b) -> a.subscriptionId().compareToIgnoreCase(b.subscriptionId())).collect(Collectors.toList());
cachedWebAppList = sortedList;
if (cachedWebAppList.size() > 0) {
final DefaultTableModel model = (DefaultTableModel) webAppTable.getModel();
model.getDataVector().clear();
for (final IWebApp resource : sortedList) {
model.addRow(new String[] { resource.name(), resource.resourceGroup() });
}
}
// select active web app
for (int index = 0; index < cachedWebAppList.size(); index++) {
if (StringUtils.equals(cachedWebAppList.get(index).id(), defaultWebAppId)) {
webAppTable.setRowSelectionInterval(index, index);
// defaultWebAppId = null; // clear to select nothing in future refreshing
break;
}
}
}
use of com.microsoft.azure.toolkit.lib.appservice.service.IWebApp in project azure-tools-for-java by Microsoft.
the class WebAppConfiguration method saveModel.
public void saveModel(final WebAppComboBoxModel webAppComboBoxModel) {
setWebAppId(webAppComboBoxModel.getResourceId());
setWebAppName(webAppComboBoxModel.getAppName());
setResourceGroup(webAppComboBoxModel.getResourceGroup());
setSubscriptionId(webAppComboBoxModel.getSubscriptionId());
if (webAppComboBoxModel.isNewCreateResource()) {
setCreatingNew(true);
final WebAppSettingModel settingModel = webAppComboBoxModel.getWebAppSettingModel();
setCreatingResGrp(settingModel.isCreatingResGrp());
setCreatingAppServicePlan(settingModel.isCreatingAppServicePlan());
setAppServicePlanName(settingModel.getAppServicePlanName());
setRegion(settingModel.getRegion());
setPricing(settingModel.getPricing());
setAppServicePlanId(settingModel.getAppServicePlanId());
saveRuntime(settingModel.getRuntime());
setCreatingResGrp(settingModel.isCreatingResGrp());
setCreatingAppServicePlan(settingModel.isCreatingAppServicePlan());
webAppSettingModel.setEnableApplicationLog(settingModel.isEnableApplicationLog());
webAppSettingModel.setApplicationLogLevel(settingModel.getApplicationLogLevel());
webAppSettingModel.setEnableWebServerLogging(settingModel.isEnableWebServerLogging());
webAppSettingModel.setWebServerLogQuota(settingModel.getWebServerLogQuota());
webAppSettingModel.setWebServerRetentionPeriod(settingModel.getWebServerRetentionPeriod());
webAppSettingModel.setEnableDetailedErrorMessage(settingModel.isEnableDetailedErrorMessage());
webAppSettingModel.setEnableFailedRequestTracing(settingModel.isEnableFailedRequestTracing());
} else {
setCreatingNew(false);
final IWebApp webApp = webAppComboBoxModel.getResource();
if (webApp != null) {
saveRuntime(webApp.getRuntime());
setAppServicePlanId(webApp.entity().getAppServicePlanId());
setRegion(webApp.entity().getRegion().getName());
}
}
}
Aggregations