Skip to content

Commit

Permalink
Fix function refresh and list app service plan issues (#4582)
Browse files Browse the repository at this point in the history
* Fix new function will trigger webapp refresh events

* Bump azure version and fix app service list issues

* Fix checkstyle
  • Loading branch information
Flanker32 authored Sep 7, 2020
1 parent f3b1ecd commit 173fdd7
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ depLocation=dependencies/
excp=Exception in getClasspathEntries
azureSDKcontainerID=com.microsoft.azuretools.SDK_CONTAINER
sdkID=com.microsoft.azuretools.sdk
sdkJar=dependencies/azure-1.35.1.jar
sdkJar=dependencies/azure-1.36.2.jar
jstDep=org.eclipse.jst.component.dependency
aiCheckBoxTxt=Enable telemetry with Application Insights
webxmlPath=WebContent/WEB-INF/web.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ lblVersion=Version :
libNotAvail=Library is not available.
notFound=Not found
sdkID=com.microsoft.azuretools.sdk
sdkJar=dependencies/azure-1.35.1.jar
sdkJar=dependencies/azure-1.36.2.jar
title=Microsoft Azure Libraries for Java
verNotAvail=The selected version is not available.
version1=Microsoft Azure Libraries for Java, version %s.%s.%s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ err=Error
prefFileName=WAEclipsePlugin
bundleName=org.eclipse.core.runtime
sdkLibBundleName=com.microsoftopentechnologies.windowsazure.tools.sdk
sdkLibBaseJar=dependencies/azure-1.35.1.jar
sdkLibBaseJar=dependencies/azure-1.36.2.jar
SDKLocErrMsg=Error occurred while retrieving path of Azure libraries
resCLExWkspRfrsh=Exception while refresh of workspace.
cmhLblStrgAcc=Storage Accounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.microsoft.azure.management.applicationinsights.v2015_05_01.ApplicationInsightsComponent;
import com.microsoft.azure.management.appservice.FunctionApp;
import com.microsoft.azure.management.appservice.OperatingSystem;
import com.microsoft.azuretools.authmanage.AuthMethodManager;
import com.microsoft.azuretools.telemetry.AppInsightsClient;
import com.microsoft.azuretools.telemetrywrapper.EventType;
import com.microsoft.azuretools.telemetrywrapper.EventUtil;
Expand Down Expand Up @@ -275,14 +274,12 @@ public void run(ProgressIndicator progressIndicator) {
EventUtil.logEvent(EventType.info, operation, properties);
bindingApplicationInsights(functionConfiguration);
final CreateFunctionHandler createFunctionHandler = new CreateFunctionHandler(functionConfiguration);
createFunctionHandler.execute();
result = AuthMethodManager.getInstance().getAzureClient(functionConfiguration.getSubscription()).appServices().functionApps()
.getByResourceGroup(functionConfiguration.getResourceGroup(), functionConfiguration.getAppName());
result = createFunctionHandler.execute();
ApplicationManager.getApplication().invokeLater(() -> {
sendTelemetry(true, null);
if (AzureUIRefreshCore.listeners != null) {
AzureUIRefreshCore.execute(new AzureUIRefreshEvent(AzureUIRefreshEvent.EventType.REFRESH,
null));
result));
}
});
DefaultLoader.getIdeHelper().invokeLater(() -> FunctionCreationDialog.super.doOKAction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public CreateFunctionHandler(IAppServiceContext ctx) {
this.ctx = ctx;
}

public void execute() throws IOException, AzureExecutionException {
public FunctionApp execute() throws IOException, AzureExecutionException {
final FunctionApp app = getFunctionApp();
if (app == null) {
createFunctionApp();
return createFunctionApp();
} else {
throw new AzureExecutionException(String.format(TARGET_FUNCTION_APP_ALREADY_EXISTS, ctx.getAppName()));
}
Expand All @@ -91,13 +91,14 @@ public void execute() throws IOException, AzureExecutionException {

// region Create or update Azure Functions

private void createFunctionApp() throws IOException, AzureExecutionException {
private FunctionApp createFunctionApp() throws IOException, AzureExecutionException {
Log.prompt(FUNCTION_APP_CREATE_START);
final FunctionRuntimeHandler runtimeHandler = getFunctionRuntimeHandler();
final WithCreate withCreate = runtimeHandler.defineAppWithRuntime();
configureAppSettings(withCreate::withAppSettings, getAppSettingsWithDefaultValue());
withCreate.create();
FunctionApp result = withCreate.create();
Log.prompt(String.format(FUNCTION_APP_CREATED, ctx.getAppName()));
return result;
}

private void configureAppSettings(final Consumer<Map> withAppSettings, final Map appSettings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public void fillResourceGroup(@NotNull List<ResourceGroup> resourceGroups) {

@Override
public void fillAppServicePlan(@NotNull List<AppServicePlan> appServicePlans) {
updateConfiguration();
cbExistAppServicePlan.removeAllItems();
appServicePlans.stream()
.filter(item -> Comparing.equal(item.operatingSystem(), webAppConfiguration.getOS()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

public class PluginHelper {

private static final String AZURE_ARTIFACT = "azure-1.35.1.jar";
private static final String AZURE_ARTIFACT = "azure-1.36.2.jar";

/**
* @return resource filename in plugin's directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ public void run() {
}

private static boolean isFunctionModuleEvent(Object eventObject) {
return eventObject == null || FunctionModule.class.getName().equals(eventObject);
return eventObject != null && eventObject instanceof FunctionApp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public List<AppServicePlan> listAppServicePlanBySubscriptionIdAndResourceGroupNa
* List app service plan by subscription id.
*/
public List<AppServicePlan> listAppServicePlanBySubscriptionId(String sid) throws IOException {
return AuthMethodManager.getInstance().getAzureClient(sid).appServices().appServicePlans().list();
return AuthMethodManager.getInstance().getAzureClient(sid).appServices().appServicePlans().list(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public List<AppServicePlan> listAppServicePlanBySubscriptionIdAndResourceGroupNa
* List app service plan by subscription id.
*/
public List<AppServicePlan> listAppServicePlanBySubscriptionId(String sid) throws IOException {
return AuthMethodManager.getInstance().getAzureClient(sid).appServices().appServicePlans().list();
return AuthMethodManager.getInstance().getAzureClient(sid).appServices().appServicePlans().list(true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void testGetWebAppById() {

try {
WebApp result = azureWebAppMvpModel.getWebAppById(MOCK_SUBSCRIPTION, "test");
assert(result.toString()).equals("testApp");
assert (result.toString()).equals("testApp");
} catch (Exception e) {
fail();
}
Expand Down Expand Up @@ -156,15 +156,15 @@ public void testCreateWebAppNewSrvPlan() {
when(withOS.withOperatingSystem(OperatingSystem.WINDOWS)).thenReturn(withCreate);

WebApp.DefinitionStages.Blank def = mock(WebApp.DefinitionStages.Blank.class);
WebApp.DefinitionStages.WithNewAppServicePlan with = mock(WebApp.DefinitionStages.WithNewAppServicePlan.class);
WebApp.DefinitionStages.WithNewAppServicePlan with = mock(WebApp.DefinitionStages.WithNewAppServicePlan.class);
WebApp.DefinitionStages.NewAppServicePlanWithGroup withGrp = mock(WebApp.DefinitionStages.NewAppServicePlanWithGroup.class);
when(webAppsMock.define(settingModel.getWebAppName())).thenReturn(def);
when(def.withRegion(settingModel.getRegion())).thenReturn(withGrp);
when(withGrp.withNewResourceGroup(settingModel.getResourceGroup())).thenReturn(with);

try {
azureWebAppMvpModel.createWebAppOnWindows(settingModel);
}catch (Exception e) {
} catch (Exception e) {
}

verify(with, times(1)).withNewWindowsPlan(withCreate);
Expand All @@ -188,7 +188,7 @@ public void testCreateWebAppExistingSrvPlan() {
WebApp.DefinitionStages.ExistingWindowsPlanWithGroup withGrp = mock(WebApp.DefinitionStages.ExistingWindowsPlanWithGroup.class);
when(def.withExistingWindowsPlan(srvPlan)).thenReturn(withGrp);

try{
try {
azureWebAppMvpModel.createWebAppOnWindows(settingModel);
} catch (Exception e) {
}
Expand Down Expand Up @@ -221,9 +221,9 @@ public void testCreateWebAppOnLinuxExistingSrvPlan() {
WebApp.DefinitionStages.ExistingLinuxPlanWithGroup withGrp = mock(WebApp.DefinitionStages.ExistingLinuxPlanWithGroup.class);
when(def.withExistingLinuxPlan(srvPlan)).thenReturn(withGrp);

try{
try {
azureWebAppMvpModel.createWebAppWithPrivateRegistryImage(model);
} catch(Exception e) {
} catch (Exception e) {
}

verify(withGrp, times(1)).withExistingResourceGroup(anyString());
Expand Down Expand Up @@ -293,11 +293,11 @@ public Page<AppServicePlan> nextPage(String nextPageLink) throws RestException,
public void testListAppServicePlanBySubscriptionId() {
try {
azureWebAppMvpModel.listAppServicePlanBySubscriptionId(MOCK_SUBSCRIPTION);
}catch(Exception e) {
} catch (Exception e) {
printException(e);
}

verify(appSrvPlans, times(1)).list();
verify(appSrvPlans, times(1)).list(true);
}

@Test
Expand Down Expand Up @@ -458,7 +458,7 @@ private void printException(Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String sStackTrace = sw.toString(); // stack trace as a string
System.out.println(sStackTrace);
String stacktrace = sw.toString(); // stack trace as a string
System.out.println(stacktrace);
}
}
2 changes: 1 addition & 1 deletion Utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<kotlin.version>1.3.72</kotlin.version>
<kotlin.jvmTargetVersion>1.8</kotlin.jvmTargetVersion>
<jackson.version>2.11.1</jackson.version>
<azure.version>1.35.1</azure.version>
<azure.version>1.36.2</azure.version>
<docker.client.version>8.16.0</docker.client.version>
<azure.client.version>1.7.5</azure.client.version>
<azure.keyvault.version>1.2.4</azure.keyvault.version>
Expand Down

0 comments on commit 173fdd7

Please sign in to comment.