Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE issues in telemetry #4703

Merged
merged 3 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public void update(AnActionEvent event) {
}

private void runConfiguration(Module module) {
// todo: investigate when will module be null
if (module == null) {
return;
}
final Project project = module.getProject();
final RunManagerEx manager = RunManagerEx.getInstanceEx(project);
final ConfigurationFactory factory = new FunctionDeploymentConfigurationFactory(configType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public void update(AnActionEvent event) {
}

private void runConfiguration(Module module) {
// todo: investigate when will module be null
if (module == null) {
return;
}
final Project project = module.getProject();
final RunManagerEx manager = RunManagerEx.getInstanceEx(project);
final ConfigurationFactory factory = new FunctionRunConfigurationFactory(configType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static Map<String, FunctionConfiguration> prepareStagingFolder(Path stagi

final List<File> jarFiles = new ArrayList<>();
OrderEnumerator.orderEntries(module).productionOnly().forEachLibrary(lib -> {
if (ArrayUtils.contains(lib.getName().split("\\:"), FUNCTION_JAVA_LIBRARY_ARTIFACT_ID)) {
if (StringUtils.isNotEmpty(lib.getName()) && ArrayUtils.contains(lib.getName().split("\\:"), FUNCTION_JAVA_LIBRARY_ARTIFACT_ID)) {
return true;
}

Expand Down Expand Up @@ -337,6 +337,9 @@ private static Binding getBinding(final Project project, JvmAnnotation annotatio

private static Binding getUserDefinedBinding(final Project project, PsiAnnotation annotation) throws AzureExecutionException {
PsiJavaCodeReferenceElement referenceElement = annotation.getNameReferenceElement();
if (referenceElement == null) {
return null;
}
PsiAnnotation customBindingAnnotation =
AnnotationUtil.findAnnotation((PsiModifierListOwner) referenceElement.resolve(),
AZURE_FUNCTION_CUSTOM_BINDING_CLASS);
Expand Down Expand Up @@ -427,7 +430,7 @@ private static void copyFilesWithDefaultContent(Path sourcePath, File dest, Stri
if (src != null && src.exists()) {
FileUtils.copyFile(src, dest);
} else {
FileUtils.write(src, defaultContent, Charset.defaultCharset());
FileUtils.write(dest, defaultContent, Charset.defaultCharset());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

public class FunctionDeploymentState extends AzureRunProfileState<WebAppBase> {

private static final String TARGET_FUNCTION_DOES_NOT_EXIST =
"Target function does not exist, please select a valid function in function deployment run configuration.";

private FunctionDeployConfiguration functionDeployConfiguration;
private final FunctionDeployModel deployModel;
private File stagingFolder;
Expand All @@ -72,6 +75,9 @@ public WebAppBase executeSteps(@NotNull RunProcessHandler processHandler
// Update run time information by function app
final FunctionApp functionApp = AzureFunctionMvpModel.getInstance()
.getFunctionById(functionDeployConfiguration.getSubscriptionId(), functionDeployConfiguration.getFunctionId());
if (functionApp == null) {
throw new AzureExecutionException(TARGET_FUNCTION_DOES_NOT_EXIST);
}
final AppServicePlan appServicePlan = AppServiceUtils.getAppServicePlanByAppService(functionApp);
final IntelliJFunctionRuntimeConfiguration runtimeConfiguration = new IntelliJFunctionRuntimeConfiguration();
runtimeConfiguration.setOs(appServicePlan.operatingSystem() == OperatingSystem.WINDOWS ? "windows" : "linux");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.management.appservice.FunctionApp;
import com.microsoft.azure.management.appservice.FunctionApp.Update;
import com.microsoft.intellij.runner.functions.library.IAppServiceContext;
import com.microsoft.intellij.runner.functions.deploy.FunctionDeployModel;
import com.microsoft.intellij.runner.functions.library.IPrompter;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -93,17 +93,16 @@ public class DeployFunctionHandler {
+ "function information (Attempt %d/%d)...";

private static final OperatingSystemEnum DEFAULT_OS = OperatingSystemEnum.Windows;
private IAppServiceContext ctx;
private FunctionDeployModel ctx;
Flanker32 marked this conversation as resolved.
Show resolved Hide resolved
private IPrompter prompter;

public DeployFunctionHandler(IAppServiceContext ctx, IPrompter prompter) {
public DeployFunctionHandler(FunctionDeployModel ctx, IPrompter prompter) {
Preconditions.checkNotNull(ctx);
this.ctx = ctx;
this.prompter = prompter;
}

public FunctionApp execute() throws Exception {

final FunctionApp app = getFunctionApp();
updateFunctionAppSettings(app);
final DeployTarget deployTarget = new DeployTarget(app, DeployTargetType.FUNCTION);
Expand Down Expand Up @@ -220,14 +219,12 @@ private boolean isDedicatedPricingTier() {
return AppServiceUtils.getPricingTierFromString(ctx.getPricingTier()) != null;
}

private FunctionApp getFunctionApp() {
private FunctionApp getFunctionApp() throws AzureExecutionException {
try {
return ctx.getAzureClient().appServices().functionApps().getByResourceGroup(ctx.getResourceGroup(),
ctx.getAppName());
} catch (Exception ex) {
// Swallow exception for non-existing Azure Functions
return ctx.getAzureClient().appServices().functionApps().getById(ctx.getFunctionId());
} catch (IOException e) {
throw new AzureExecutionException("Failed to get azure client");
}
return null;
}

// region get App Settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private static class LazyLoader {
* identity/implementation/IdentityClient.java#L366
*/
private Pair<String, OffsetDateTime> getAccessTokenViaCli(String tid, @Nullable String resource) throws IOException {
if (!PATTERN_TENANT.matcher(tid).matches()) {
if (StringUtils.isEmpty(tid) || !PATTERN_TENANT.matcher(tid).matches()) {
throw new InvalidParameterException(String.format("[%s] is not a valid tenant ID", tid));
} else if (StringUtils.isNotEmpty(resource) && !PATTERN_RESOURCE.matcher(resource).matches()) {
throw new InvalidParameterException(String.format("[%s] is not a valid resource endpoint", resource));
Expand Down