Skip to content

Commit

Permalink
adding rawstring in fluresponse from flumonitor to put in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu144141 committed Oct 6, 2016
1 parent a268640 commit 044667a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
16 changes: 8 additions & 8 deletions app/services/flu_svc/flu_output/flu_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func sendBackResp(projectIdsToSend []uuid.UUID) {

} else {
completedFLUs := deleteFromFeedLinePipe(projectId, fluOutObj)
go putDbLog(completedFLUs, "Invalid FLU Resp ", *fluResp)
go putDbLog(completedFLUs, "ERROR", *fluResp)
}
}

Expand Down Expand Up @@ -158,10 +158,10 @@ func getFluOutputObj(flp feedLineValue) (fluOutputObj []fluOutputStruct) {
return
}

func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*Response, status_codes.StatusCode) {
func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*FluResponse, status_codes.StatusCode) {

if len(fluProjectResp) < 1 {
return &Response{}, status_codes.NoFluToSend
return &FluResponse{}, status_codes.NoFluToSend
}

plog.Info("Flu output", "sendBackToClient", projectId)
Expand All @@ -170,7 +170,7 @@ func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*R
fpsModel, err := fpsRepo.Get(projectId)
if utilities.IsValidError(err) {
plog.Error("DB Error:", err)
return &Response{}, status_codes.UnknownFailure
return &FluResponse{}, status_codes.UnknownFailure
}

url := fpsModel.PostBackUrl
Expand All @@ -182,7 +182,7 @@ func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*R
jsonBytes, err := json.Marshal(sendResp)
if err != nil {
plog.Error("JSON Marshalling Error:", err)
return &Response{}, status_codes.UnknownFailure
return &FluResponse{}, status_codes.UnknownFailure
}
jsonBytes = utilities.ReplaceEscapeCharacters(jsonBytes)
plog.Trace("Sending JSON:", string(jsonBytes))
Expand All @@ -202,7 +202,7 @@ func sendBackToClient(projectId uuid.UUID, fluProjectResp []fluOutputStruct) (*R
resp, err := client.Do(req)
if err != nil {
plog.Error("HTTP Error:", err)
return &Response{}, status_codes.UnknownFailure
return &FluResponse{}, status_codes.UnknownFailure
}

fluResp, status := validationErrorCallback(resp)
Expand All @@ -223,7 +223,7 @@ func addSendBackAuth(req *http.Request, fpsModel models.ProjectConfiguration, bo
}
}

func validationErrorCallback(resp *http.Response) (*Response, status_codes.StatusCode) {
func validationErrorCallback(resp *http.Response) (*FluResponse, status_codes.StatusCode) {
defer resp.Body.Close()

fluResp := ParseFluResponse(resp)
Expand All @@ -234,7 +234,7 @@ func validationErrorCallback(resp *http.Response) (*Response, status_codes.Statu
} else {
//If any invalid flu response code is in our InvalidationCodeArray, then we log[ERROR] it
for _, invalidFlu := range fluResp.Invalid_Flus {
if IsValidInternalError(invalidFlu.Flu_Id) {
if IsValidInternalError(invalidFlu.Error) {
return fluResp, status_codes.FluRespFailure
}
}
Expand Down
8 changes: 5 additions & 3 deletions app/services/flu_svc/flu_output/flu_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ import (
"github.com/crowdflux/angel/app/plog"
)

func ParseFluResponse(resp *http.Response) *Response {
fluResp := &Response{}
func ParseFluResponse(resp *http.Response) *FluResponse {
fluResp := &FluResponse{}
fluResp.HttpStatusCode = resp.StatusCode

body, _ := ioutil.ReadAll(resp.Body)
plog.Info("response Status:", resp.Status)
plog.Info("response Headers:", resp.Header)
plog.Info("response Headers:", resp)
plog.Info("response Body:", string(body))
fluResp.RawResponse = string(body)
err := json.Unmarshal(body, fluResp)
if err != nil {

Expand Down Expand Up @@ -78,7 +79,8 @@ func IsValidInternalError(internalCode string) bool {
return false
}

func putDbLog(completedFLUs []models.FeedLineUnit, message string, resp Response) {
func putDbLog(completedFLUs []models.FeedLineUnit, message string, resp FluResponse) {

dbLogArr := make([]models.FeedLineLog, len(completedFLUs))
jsObj := models.JsonF{}
jsonBytes, _ := json.Marshal(resp)
Expand Down
3 changes: 2 additions & 1 deletion app/services/flu_svc/flu_output/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package flu_output
import "github.com/crowdflux/angel/app/models/status_codes"

//TODO rest will be added later
type Response struct {
type FluResponse struct {
HttpStatusCode int
FluStatusCode status_codes.StatusCode
Invalid_Flus []invalidFlu `json:"invalid_flus"`
RawResponse string
}
type invalidFlu struct {
Flu_Id string `json:"flu_id"`
Expand Down

0 comments on commit 044667a

Please sign in to comment.