Skip to content

Commit

Permalink
clear tags to work around messed-up tags in mgmt SDK (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
xscript authored Aug 9, 2017
1 parent 5197b58 commit b39ff58
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,17 @@ public static boolean isPrivateRegistryImage(final ContainerSetting containerSet
return StringUtils.isNotEmpty(containerSetting.getServerId()) &&
StringUtils.isNotEmpty(containerSetting.getRegistryUrl());
}

/**
* Work Around:
* When a web app is created from Azure Portal, there are hidden tags associated with the app.
* It will be messed up when calling "update" API.
* An issue is logged at https://github.com/Azure/azure-sdk-for-java/issues/1755 .
* Remove all tags here to make it work.
*
* @param app
*/
public static void clearTags(final WebApp app) {
app.inner().withTags(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public WebApp.DefinitionStages.WithCreate defineAppWithRunTime() throws MojoExec
public WebApp.Update updateAppRuntime() throws MojoExecutionException {
final WebApp app = mojo.getWebApp();
WebAppUtils.assureWindowsWebApp(app);
WebAppUtils.clearTags(app);

final WebApp.Update update = app.update();
update.withJavaVersion(mojo.getJavaVersion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.microsoft.azure.management.appservice.WebApp;
import com.microsoft.azure.maven.webapp.AbstractWebAppMojo;
import com.microsoft.azure.maven.webapp.WebAppUtils;
import org.apache.maven.plugin.MojoExecutionException;

public class NullRuntimeHandlerImpl implements RuntimeHandler {
Expand All @@ -26,6 +27,8 @@ public WebApp.DefinitionStages.WithCreate defineAppWithRunTime() throws MojoExec

@Override
public WebApp.Update updateAppRuntime() throws MojoExecutionException {
return mojo.getWebApp().update();
final WebApp app = mojo.getWebApp();
WebAppUtils.clearTags(app);
return app.update();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public WebApp.DefinitionStages.WithCreate defineAppWithRunTime() throws MojoExec
public WebApp.Update updateAppRuntime() throws MojoExecutionException {
final WebApp app = mojo.getWebApp();
WebAppUtils.assureLinuxWebApp(app);
WebAppUtils.clearTags(app);

final ContainerSetting containerSetting = mojo.getContainerSettings();
final Server server = Utils.getServer(mojo.getSettings(), containerSetting.getServerId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public WebApp.DefinitionStages.WithCreate defineAppWithRunTime() throws MojoExec
public WebApp.Update updateAppRuntime() throws MojoExecutionException {
final WebApp app = mojo.getWebApp();
WebAppUtils.assureLinuxWebApp(app);
WebAppUtils.clearTags(app);

final ContainerSetting containerSetting = mojo.getContainerSettings();
final Server server = Utils.getServer(mojo.getSettings(), containerSetting.getServerId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public WebApp.DefinitionStages.WithCreate defineAppWithRunTime() throws MojoExec
public WebApp.Update updateAppRuntime() throws MojoExecutionException {
final WebApp app = mojo.getWebApp();
WebAppUtils.assureLinuxWebApp(app);
WebAppUtils.clearTags(app);

final ContainerSetting containerSetting = mojo.getContainerSettings();
return app.update().withPublicDockerHubImage(containerSetting.getImageName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.microsoft.azure.maven.webapp.handlers;

import com.microsoft.azure.management.appservice.WebApp;
import com.microsoft.azure.management.appservice.implementation.SiteInner;
import com.microsoft.azure.maven.webapp.AbstractWebAppMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Before;
Expand Down Expand Up @@ -47,9 +48,11 @@ public void defineAppWithRunTime() throws Exception {

@Test
public void updateAppRuntime() throws Exception {
final WebApp.Update update = mock(WebApp.Update.class);
final WebApp app = mock(WebApp.class);
final WebApp.Update update = mock(WebApp.Update.class);
when(app.update()).thenReturn(update);
final SiteInner siteInner = mock(SiteInner.class);
when(app.inner()).thenReturn(siteInner);
when(mojo.getWebApp()).thenReturn(app);

assertSame(update, handler.updateAppRuntime());
Expand Down

0 comments on commit b39ff58

Please sign in to comment.