Skip to content

Commit

Permalink
Merge branch 'main' into golang-multiarch-support
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokponkumar authored Jan 15, 2023
2 parents 8c95e18 + 1cb2304 commit 24e630c
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 62 deletions.
9 changes: 7 additions & 2 deletions graph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ import (
)

// content is our static web server content.
//
//go:embed web/build/*
var content embed.FS

// StartServer starts the graph server and web UI to display the nodes and edges.
func StartServer(graph graphtypes.GraphT, port int32) error {
jsonBytes, err := json.Marshal(graph)
if err != nil {
logrus.Fatalf("failed to marshal the graph to json. Error: %q", err)
return fmt.Errorf("failed to marshal the graph to json. Error: %w", err)
}
router := mux.NewRouter()
sub, _ := fs.Sub(content, "web/build")
sub, err := fs.Sub(content, "web/build")
if err != nil {
return fmt.Errorf("failed to create a filesystem from the embedded static files. Error: %w", err)
}
router.Path("/graph.json").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if _, err := w.Write(jsonBytes); err != nil {
logrus.Errorf("failed to write the json bytes out to the response. Actual:\n%s\nError: %q", string(jsonBytes), err)
}
Expand Down
125 changes: 66 additions & 59 deletions qaengine/httprestengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package qaengine
import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -68,8 +67,8 @@ func (h *HTTPRESTEngine) StartEngine() error {
}
// Create the REST router.
r := mux.NewRouter()
r.HandleFunc(currentProblemURLPrefix, h.problemHandler).Methods("GET")
r.HandleFunc(currentSolutionURLPrefix, h.solutionHandler).Methods("POST")
r.HandleFunc(currentProblemURLPrefix, h.getQuestionHandler).Methods("GET")
r.HandleFunc(currentSolutionURLPrefix, h.postSolutionHandler).Methods("POST")

http.Handle("/", r)
qaportstr := cast.ToString(h.port)
Expand All @@ -95,87 +94,93 @@ func (*HTTPRESTEngine) IsInteractiveEngine() bool {

// FetchAnswer fetches the answer using a REST service
func (h *HTTPRESTEngine) FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) {
logrus.Trace("HTTPRESTEngine.FetchAnswer start")
defer logrus.Trace("HTTPRESTEngine.FetchAnswer end")
if err := ValidateProblem(prob); err != nil {
logrus.Errorf("the QA problem object is invalid. Error: %q", err)
return prob, err
return prob, fmt.Errorf("the QA problem object is invalid. Error: %w", err)
}
if prob.Answer != nil {
return prob, nil
}
logrus.Debugf("Passing problem to HTTP REST QA Engine ID: '%s' desc: '%s'", prob.ID, prob.Desc)
h.problemChan <- prob
logrus.Debugf("sent the current question into the problem channel: %+v", prob)
prob = <-h.answerChan
logrus.Debugf("received a solution from the problem channel: %+v", prob)
if prob.Answer == nil {
logrus.Debugf("Passing problem to HTTP REST QA Engine ID: %s, desc: %s", prob.ID, prob.Desc)
h.problemChan <- prob
prob = <-h.answerChan
if prob.Answer == nil {
return prob, fmt.Errorf("failed to resolve the QA problem: %+v", prob)
return prob, fmt.Errorf("failed to resolve the QA problem: %+v", prob)
}
if prob.Type != qatypes.MultiSelectSolutionFormType {
return prob, nil
}
otherAnsPresent := false
ans, err := common.ConvertInterfaceToSliceOfStrings(prob.Answer)
if err != nil {
return prob, fmt.Errorf("failed to convert the answer from an interface to a slice of strings. Error: %w", err)
}
newAns := []string{}
for _, a := range ans {
if a == qatypes.OtherAnswer {
otherAnsPresent = true
} else {
newAns = append(newAns, a)
}
if prob.Type == qatypes.MultiSelectSolutionFormType {
otherAnsPresent := false
ans, err := common.ConvertInterfaceToSliceOfStrings(prob.Answer)
if err != nil {
logrus.Errorf("Unable to process answer : %s", err)
return prob, err
}
newAns := []string{}
for _, a := range ans {
if a == qatypes.OtherAnswer {
otherAnsPresent = true
} else {
newAns = append(newAns, a)
}
}
if otherAnsPresent {
multilineAns := ""
multilineProb := deepcopy.DeepCopy(prob).(qatypes.Problem)
multilineProb.Type = qatypes.MultilineInputSolutionFormType
multilineProb.Default = ""
h.problemChan <- multilineProb
multilineProb = <-h.answerChan
multilineAns = multilineProb.Answer.(string)
for _, lineAns := range strings.Split(multilineAns, "\n") {
lineAns = strings.TrimSpace(lineAns)
if lineAns != "" {
newAns = common.AppendIfNotPresent(newAns, lineAns)
}
}
}
if otherAnsPresent {
multilineAns := ""
multilineProb := deepcopy.DeepCopy(prob).(qatypes.Problem)
multilineProb.Type = qatypes.MultilineInputSolutionFormType
multilineProb.Default = ""
h.problemChan <- multilineProb
multilineProb = <-h.answerChan
multilineAns = multilineProb.Answer.(string)
for _, lineAns := range strings.Split(multilineAns, "\n") {
lineAns = strings.TrimSpace(lineAns)
if lineAns != "" {
newAns = common.AppendIfNotPresent(newAns, lineAns)
}
prob.Answer = newAns
}
}
prob.Answer = newAns
return prob, nil
}

// problemHandler returns the current problem being handled
func (h *HTTPRESTEngine) problemHandler(w http.ResponseWriter, r *http.Request) {
// getQuestionHandler blocks until it gets a question and returns it as json.
func (h *HTTPRESTEngine) getQuestionHandler(w http.ResponseWriter, r *http.Request) {
logrus.Trace("problemHandler start")
defer logrus.Trace("problemHandler end")
logrus.Debug("Looking for a problem fron HTTP REST service")
// if currently problem is resolved
if h.currentProblem.Answer != nil || h.currentProblem.ID == "" {
// Pick the next problem off the channel
h.currentProblem = <-h.problemChan
}
logrus.Debugf("QA Engine serves problem id: %s, desc: %s", h.currentProblem.ID, h.currentProblem.Desc)
logrus.Debugf("QA Engine serves problem id: '%s' desc: '%s'", h.currentProblem.ID, h.currentProblem.Desc)
// Send the problem to the request.
_ = json.NewEncoder(w).Encode(h.currentProblem)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(h.currentProblem); err != nil {
logrus.Errorf("failed to encode the current problem as json and send the response. Error: %q", err)
return
}
}

// solutionHandler accepts solution for a single open problem.
func (h *HTTPRESTEngine) solutionHandler(w http.ResponseWriter, r *http.Request) {
// postSolutionHandler accepts solution for the current question.
func (h *HTTPRESTEngine) postSolutionHandler(w http.ResponseWriter, r *http.Request) {
logrus.Trace("solutionHandler start")
defer logrus.Trace("solutionHandler end")
logrus.Debugf("QA Engine reading solution: %+v", r.Body)
// Read out the solution
body, err := io.ReadAll(r.Body)
if err != nil {
errstr := fmt.Sprintf("Error in reading posted solution: %s", err)
http.Error(w, "errstr", http.StatusInternalServerError)
logrus.Errorf(errstr)
return
}
var prob qatypes.Problem
if err := json.Unmarshal(body, &prob); err != nil {
errstr := fmt.Sprintf("Error in un-marshalling solution in QA engine: %s", err)
http.Error(w, errstr, http.StatusInternalServerError)
if err := json.NewDecoder(r.Body).Decode(&prob); err != nil {
errstr := fmt.Sprintf("failed to decode the request body as solution json. Error: %q", err)
http.Error(w, errstr, http.StatusBadRequest)
logrus.Errorf(errstr)
return
}
logrus.Debugf("QA Engine receives solution: %+v", prob)
logrus.Debugf("QA Engine received the solution: %+v", prob)
if h.currentProblem.ID != prob.ID {
errstr := fmt.Sprintf("the solution's problem ID doesn't match the current problem. Expected: %s Actual %s", h.currentProblem.ID, prob.ID)
errstr := fmt.Sprintf("the solution's problem ID doesn't match the current problem. Expected: '%s' Actual '%s'", h.currentProblem.ID, prob.ID)
http.Error(w, errstr, http.StatusNotAcceptable)
logrus.Errorf(errstr)
return
Expand All @@ -186,5 +191,7 @@ func (h *HTTPRESTEngine) solutionHandler(w http.ResponseWriter, r *http.Request)
logrus.Errorf(errstr)
return
}
h.answerChan <- h.currentProblem
logrus.Debugf("QA Engine set the solution as the answer: %+v", h.currentProblem)
w.WriteHeader(http.StatusNoContent)
go func() { h.answerChan <- h.currentProblem }()
}
4 changes: 3 additions & 1 deletion transformer/dockerfilegenerator/java/zuulanalyser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package java

import (
"strings"

"github.com/konveyor/move2kube/common"
"github.com/konveyor/move2kube/environment"
irtypes "github.com/konveyor/move2kube/types/ir"
Expand Down Expand Up @@ -62,7 +64,7 @@ func (t *ZuulAnalyser) Init(tc transformertypes.Transformer, env *environment.En
}
for servicename, routepath := range z.ZuulSpec.RouteSpec {
// TODO: routepath (ant style) to regex
routepath = routepath[:len(routepath)-2]
routepath = strings.TrimSuffix(routepath, "**")
t.services[servicename] = routepath
}
}
Expand Down

0 comments on commit 24e630c

Please sign in to comment.