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

Prompt when Kafka detected but no spring-cloud-azure dependency found #27

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions cli/azd/internal/appdetect/appdetect.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ func (a AzureDepStorageAccount) ResourceDisplay() string {
return "Azure Storage Account"
}

type SpringCloudAzureDep struct {
}

func (a SpringCloudAzureDep) ResourceDisplay() string {
return "Spring Cloud Azure Starter"
}

type Project struct {
// The language associated with the project.
Language Language
Expand Down
4 changes: 4 additions & 0 deletions cli/azd/internal/appdetect/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ func detectDependencies(mavenProject *mavenProject, project *Project) (*Project,
UseKafka: true,
})
}

if dep.GroupId == "com.azure.spring" && dep.ArtifactId == "spring-cloud-azure-starter" {
project.AzureDeps = append(project.AzureDeps, SpringCloudAzureDep{})
}
}

if len(databaseDepMap) > 0 {
Expand Down
55 changes: 54 additions & 1 deletion cli/azd/internal/repository/app_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repository

import (
"context"
"errors"
"fmt"
"maps"
"os"
Expand Down Expand Up @@ -128,10 +129,30 @@ func (i *Initializer) InitFromApp(
i.console.StopSpinner(ctx, title, input.StepDone)

var prjAppHost []appdetect.Project
for _, prj := range projects {
for index, prj := range projects {
if prj.Language == appdetect.DotNetAppHost {
prjAppHost = append(prjAppHost, prj)
}

if prj.Language == appdetect.Java {
var hasKafkaDep bool
var hasSpringCloudAzureDep bool
for _, dep := range prj.AzureDeps {
if eventHubs, ok := dep.(appdetect.AzureDepEventHubs); ok && eventHubs.UseKafka {
hasKafkaDep = true
}
if _, ok := dep.(appdetect.SpringCloudAzureDep); ok {
hasSpringCloudAzureDep = true
}
}

if hasKafkaDep && !hasSpringCloudAzureDep {
err := processSpringCloudAzureDepByPrompt(i.console, ctx, &projects[index])
if err != nil {
return err
}
}
}
}

if len(prjAppHost) > 1 {
Expand Down Expand Up @@ -768,3 +789,35 @@ func ServiceFromDetect(

return svc, nil
}

func processSpringCloudAzureDepByPrompt(console input.Console, ctx context.Context, project *appdetect.Project) error {
continueOption, err := console.Select(ctx, input.ConsoleOptions{
Message: "Detected Kafka dependency but no spring-cloud-azure-starter found. Select an option",
Options: []string{
"Exit then I will manually add this dependency",
"Continue without this dependency, and provision Azure Event Hubs for Kafka",
"Continue without this dependency, and not provision Azure Event Hubs for Kafka",
},
})
if err != nil {
return err
}

switch continueOption {
case 0:
return errors.New("you have to manually add dependency com.azure.spring:spring-cloud-azure-starter by following https://github.com/Azure/azure-sdk-for-java/wiki/Spring-Versions-Mapping")
case 1:
return nil
case 2:
// remove Kafka Azure Dep
var result []appdetect.AzureDep
for _, dep := range project.AzureDeps {
if eventHubs, ok := dep.(appdetect.AzureDepEventHubs); !(ok && eventHubs.UseKafka) {
result = append(result, dep)
}
}
project.AzureDeps = result
return nil
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems it will still be provisioned even if customer chosen option 2.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rujche I don't think so. Currently it's still []Project returned from detectors, not the DetectConfirm. So we only remove it from AzureDeps, no need to remove deps and remove Azure services.

}
return nil
}