public DeploymentSlot getDeploymentSlot(final WebApp app, final String slotName) { DeploymentSlot slot = null; if (StringUtils.isNotEmpty(slotName)) { try { slot = app.deploymentSlots().getByName(slotName); } catch (NoSuchElementException deploymentSlotNotExistException) { } } return slot; }
@Override public void renderChildren(@NotNull final List<ResourceEx<WebApp>> resourceExes) { for (final ResourceEx<WebApp> resourceEx : resourceExes) { final WebApp app = resourceEx.getResource(); final WebAppNode node = new WebAppNode(this, resourceEx.getSubscriptionId(), app.id(), app.name(), app.state(), app.defaultHostName(), app.operatingSystem().toString(), new HashMap<String, String>() { { put("regionName", app.regionName()); } }); addChildNode(node); node.refreshItems(); } } }
public static void uploadWebConfig(WebApp webApp, InputStream fileStream, IProgressIndicator indicator) throws IOException { FTPClient ftp = null; try { if(indicator != null) indicator.setText("Stopping the service..."); webApp.stop(); PublishingProfile pp = webApp.getPublishingProfile(); ftp = getFtpConnection(pp); if(indicator != null) indicator.setText("Uploading " + webConfigFilename + "..."); uploadFileToFtp(ftp, ftpRootPath + webConfigFilename, fileStream, indicator); if(indicator != null) indicator.setText("Starting the service..."); webApp.start(); } finally { if (ftp != null && ftp.isConnected()) { ftp.disconnect(); } } }
/** * Check if the web app is a Windows or Linux Java configured web app. * Docker web apps are not included. */ public static boolean isJavaWebApp(@NotNull WebApp webApp) { return (webApp.operatingSystem() == OperatingSystem.WINDOWS && webApp.javaVersion() != JavaVersion.OFF) || (webApp.operatingSystem() == OperatingSystem.LINUX && StringUtils.containsIgnoreCase(webApp.linuxFxVersion(), "jre8")); }
/** * Download publish profile of web app. * * @param sid subscription id * @param webAppId webapp id * @param filePath file path to save publish profile * @return status indicating whether it is successful or not * @throws Exception exception */ public boolean getPublishingProfileXmlWithSecrets(String sid, String webAppId, String filePath) throws Exception { WebApp app = getWebAppById(sid, webAppId); File file = new File(Paths.get(filePath, app.name() + "_" + System.currentTimeMillis() + ".PublishSettings") .toString()); file.createNewFile(); try (InputStream inputStream = app.manager().inner().webApps() .listPublishingProfileXmlWithSecrets(app.resourceGroupName(), app.name(), PublishingProfileFormat.FTP); OutputStream outputStream = new FileOutputStream(file); ) { IOUtils.copy(inputStream, outputStream); return true; } catch (IOException e) { e.printStackTrace(); return false; } }
/** * Download publish profile of deployment slot. */ public boolean getSlotPublishingProfileXmlWithSecrets(final String sid, final String webAppId, final String slotName, final String filePath) throws Exception { final WebApp app = getWebAppById(sid, webAppId); final DeploymentSlot slot = app.deploymentSlots().getByName(slotName); final File file = new File(Paths.get(filePath, slotName + "_" + System.currentTimeMillis() + ".PublishSettings") .toString()); file.createNewFile(); try (final InputStream inputStream = slot.manager().inner().webApps() .listPublishingProfileXmlWithSecretsSlot(slot.resourceGroupName(), app.name(), slotName, PublishingProfileFormat.FTP); OutputStream outputStream = new FileOutputStream(file); ) { IOUtils.copy(inputStream, outputStream); return true; } catch (IOException e) { e.printStackTrace(); return false; } }
switch (webApp.operatingSystem()) { case WINDOWS: webContainer = webApp.javaContainer() == null ? null : webApp.javaContainer().toLowerCase(); return String.format("%s %s (Java%s)", StringUtils.capitalize(webContainer), webApp.javaContainerVersion(), webApp.javaVersion().toString()); case LINUX: final String linuxVersion = webApp.linuxFxVersion(); if (linuxVersion == null) { return DEFAULT_VALUE_WHEN_VERSION_INVALID;
@Override public void renderDeploymentSlots(@NotNull final List<DeploymentSlot> slots) { slots.forEach(slot -> addChildNode( new DeploymentSlotNode(slot.id(), slot.parent().id(), slot.parent().name(), this, slot.name(), slot.state(), slot.operatingSystem().toString(), this.subscriptionId, slot.defaultHostName()))); } }
@Override public WebApp.Update updateAppRuntime(final WebApp app) throws Exception { WebAppUtils.assureLinuxWebApp(app); WebAppUtils.clearTags(app); return app.update().withPublicDockerHubImage(image); } }
@Override public String gitUrl() { String repoName; if (parent instanceof DeploymentSlot) { repoName = ((DeploymentSlot) parent).parent().name() + ".git"; } else { repoName = parent.name() + ".git"; } if (!gitUrl.startsWith("https://")) { gitUrl = "https://" + gitUrl; } return gitUrl + "/" + repoName; }
public void afterDeployArtifacts() throws Exception { if (isAppStopped) { info(START_APP); getWebApp().start(); isAppStopped = false; info(START_APP_DONE); } } }
/** * List web apps on linux by subscription id. */ public List<ResourceEx<WebApp>> listWebAppsOnLinux(@NotNull final String subscriptionId, final boolean force) { return listWebApps(subscriptionId, force) .stream() .filter(resourceEx -> OperatingSystem.LINUX.equals(resourceEx.getResource().operatingSystem())) .collect(Collectors.toList()); }
public void beforeDeployArtifacts() throws Exception { if (isStopAppDuringDeployment()) { info(STOP_APP); getWebApp().stop(); // workaround for the resources release problem. // More details: https://github.com/Microsoft/azure-maven-plugins/issues/191 TimeUnit.SECONDS.sleep(10 /* 10 seconds */); isAppStopped = true; info(STOP_APP_DONE); } }
public static void deleteAppService(WebAppDetails webAppDetails) throws IOException { AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager(); Azure azure = azureManager.getAzure(webAppDetails.subscriptionDetail.getSubscriptionId()); azure.webApps().deleteById(webAppDetails.webApp.id()); // check asp still exists AppServicePlan asp = azure.appServices().appServicePlans().getById(webAppDetails.appServicePlan.id()); System.out.println("asp is " + (asp == null ? "null -> removing form cache" : asp.name())); // update cache AzureModelController.removeWebAppFromResourceGroup(webAppDetails.resourceGroup, webAppDetails.webApp); if (asp == null) { AzureModelController.removeAppServicePlanFromResourceGroup(webAppDetails.appServicePlanResourceGroup, webAppDetails.appServicePlan); } }
/** * API to create a new Deployment Slot by setting model. */ public DeploymentSlot createDeploymentSlot(@NotNull WebAppSettingModel model) throws Exception { final WebApp app = getWebAppById(model.getSubscriptionId(), model.getWebAppId()); final String name = model.getNewSlotName(); final String configurationSource = model.getNewSlotConfigurationSource(); final DeploymentSlot.DefinitionStages.Blank definedSlot = app.deploymentSlots().define(name); if (configurationSource.equals(app.name())) { return definedSlot.withConfigurationFromParent().create(); } final DeploymentSlot configurationSourceSlot = app.deploymentSlots() .list() .stream() .filter(s -> configurationSource.equals(s.name())) .findAny() .orElse(null); if (configurationSourceSlot != null) { return definedSlot.withConfigurationFromDeploymentSlot(configurationSourceSlot).create(); } else { return definedSlot.withBrandNewConfiguration().create(); } }
@Override public Update updateAppRuntime(WebApp app) throws Exception { WebAppUtils.assureLinuxWebApp(app); WebAppUtils.clearTags(app); return app.update().withBuiltInImage(runtime); } }
@Override public Observable<Indexable> createAsync() { final HostNameBinding self = this; Func1<HostNameBindingInner, HostNameBinding> mapper = new Func1<HostNameBindingInner, HostNameBinding>() { @Override public HostNameBinding call(HostNameBindingInner hostNameBindingInner) { setInner(hostNameBindingInner); return self; } }; Observable<HostNameBinding> hostNameBindingObservable; if (parent instanceof DeploymentSlot) { hostNameBindingObservable = this.parent().manager().inner().webApps().createOrUpdateHostNameBindingSlotAsync( parent().resourceGroupName(), ((DeploymentSlot) parent).parent().name(), name, parent().name(), inner()).map(mapper); } else { hostNameBindingObservable = this.parent().manager().inner().webApps().createOrUpdateHostNameBindingAsync( parent().resourceGroupName(), parent().name(), name, inner()).map(mapper); } return hostNameBindingObservable.map(new Func1<HostNameBinding, Indexable>() { @Override public Indexable call(HostNameBinding hostNameBinding) { return hostNameBinding; } }); }
public void startWebApp(String sid, String appid) throws IOException { AuthMethodManager.getInstance().getAzureClient(sid).webApps().getById(appid).start(); }
/** * List web apps on windows by subscription id. */ public List<ResourceEx<WebApp>> listWebAppsOnWindows(@NotNull final String subscriptionId, final boolean force) { return listWebApps(subscriptionId, force) .stream() .filter(resourceEx -> OperatingSystem.WINDOWS.equals((resourceEx.getResource().operatingSystem()))) .collect(Collectors.toList()); }
public void stopWebApp(String sid, String appid) throws IOException { AuthMethodManager.getInstance().getAzureClient(sid).webApps().getById(appid).stop(); }