From 2215fa62eb85921bf2d5e6b0112cf9dd3dfc8ce1 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Wed, 5 Jun 2024 15:56:33 -0400 Subject: [PATCH 01/25] Added logs to trace logs --- manager/handlers/call_maker.go | 1 + manager/handlers/ocpp201/trigger_message_result.go | 4 ++++ manager/handlers/router.go | 3 +++ manager/sync/triggers.go | 1 + 4 files changed, 9 insertions(+) diff --git a/manager/handlers/call_maker.go b/manager/handlers/call_maker.go index f9e3982..fa360eb 100644 --- a/manager/handlers/call_maker.go +++ b/manager/handlers/call_maker.go @@ -22,6 +22,7 @@ type OcppCallMaker struct { func (b OcppCallMaker) Send(ctx context.Context, chargeStationId string, request ocpp.Request) error { action, ok := b.Actions[reflect.TypeOf(request)] + slog.Info("[TEST] we are in Send() in call_maker.go", "action", action) if !ok { return fmt.Errorf("unknown request type: %T", request) } diff --git a/manager/handlers/ocpp201/trigger_message_result.go b/manager/handlers/ocpp201/trigger_message_result.go index 8c34057..1b9378a 100644 --- a/manager/handlers/ocpp201/trigger_message_result.go +++ b/manager/handlers/ocpp201/trigger_message_result.go @@ -18,6 +18,8 @@ type TriggerMessageResultHandler struct { func (i TriggerMessageResultHandler) HandleCallResult(ctx context.Context, chargeStationId string, request ocpp.Request, response ocpp.Response, state any) error { req := request.(*ocpp201.TriggerMessageRequestJson) + slog.Info("[TEST] we are in HandleCallResult() in trigger_message_result.go") + status := ocpp201.TriggerMessageStatusEnumTypeNotImplemented span := trace.SpanFromContext(ctx) @@ -39,8 +41,10 @@ func (i TriggerMessageResultHandler) HandleCallResult(ctx context.Context, charg } if status == ocpp201.TriggerMessageStatusEnumTypeAccepted { + slog.Info("[TEST] we are in HandleCallResult() in trigger_message_result.go 111111111") return i.Store.DeleteChargeStationTriggerMessage(ctx, chargeStationId) } else { + slog.Info("[TEST] we are in HandleCallResult() in trigger_message_result.go 2222222222") err := i.Store.SetChargeStationTriggerMessage(ctx, chargeStationId, &store.ChargeStationTriggerMessage{ TriggerMessage: store.TriggerMessage(req.RequestedMessage), TriggerStatus: store.TriggerStatus(status), diff --git a/manager/handlers/router.go b/manager/handlers/router.go index c60fc71..72a2b8e 100644 --- a/manager/handlers/router.go +++ b/manager/handlers/router.go @@ -54,9 +54,11 @@ func (r Router) Handle(ctx context.Context, chargeStationId string, msg *transpo } func (r Router) route(ctx context.Context, chargeStationId string, message *transport.Message) error { + slog.Info("[TEST] we are in route() in router.go", "action", message.Action) switch message.MessageType { case transport.MessageTypeCall: route, ok := r.CallRoutes[message.Action] + slog.Info("[TEST] we are in route() in router.go, in MessageTypeCall", "route", route) if !ok { return fmt.Errorf("routing request: %w", transport.NewError(transport.ErrorNotImplemented, fmt.Errorf("%s not implemented", message.Action))) } @@ -101,6 +103,7 @@ func (r Router) route(ctx context.Context, chargeStationId string, message *tran } case transport.MessageTypeCallResult: route, ok := r.CallResultRoutes[message.Action] + slog.Info("[TEST] we are in route() in router.go, in MessageTypeCallResult", "route", route) if !ok { return fmt.Errorf("routing request: %w", transport.NewError(transport.ErrorNotImplemented, fmt.Errorf("%s result not implemented", message.Action))) } diff --git a/manager/sync/triggers.go b/manager/sync/triggers.go index 42939b4..ec4cbc0 100644 --- a/manager/sync/triggers.go +++ b/manager/sync/triggers.go @@ -49,6 +49,7 @@ func SyncTriggers(ctx context.Context, span.SetAttributes(attribute.Int("sync.trigger.count", len(triggerMessages))) for _, pendingTriggerMessage := range triggerMessages { func() { + slog.Info("[TEST] we are in SyncTriggers() in triggers.go", "pendingTriggerMessage", pendingTriggerMessage) ctx, span := tracer.Start(ctx, "sync trigger", trace.WithSpanKind(trace.SpanKindInternal), trace.WithAttributes( attribute.String("chargeStationId", pendingTriggerMessage.ChargeStationId), From ced0553785c4e965761314dab036d5b4e899150e Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Wed, 5 Jun 2024 16:05:54 -0400 Subject: [PATCH 02/25] Added in slog import --- manager/handlers/ocpp201/trigger_message_result.go | 1 + 1 file changed, 1 insertion(+) diff --git a/manager/handlers/ocpp201/trigger_message_result.go b/manager/handlers/ocpp201/trigger_message_result.go index 1b9378a..a547c7f 100644 --- a/manager/handlers/ocpp201/trigger_message_result.go +++ b/manager/handlers/ocpp201/trigger_message_result.go @@ -9,6 +9,7 @@ import ( "github.com/thoughtworks/maeve-csms/manager/store" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" + "golang.org/x/exp/slog" ) type TriggerMessageResultHandler struct { From 42c5313addda8d441d8e022ed83738de1c3fed8f Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Wed, 5 Jun 2024 16:39:11 -0400 Subject: [PATCH 03/25] Added more logs --- manager/api/server.go | 2 ++ manager/sync/triggers.go | 6 +++++- manager/transport/mqtt/listener.go | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/manager/api/server.go b/manager/api/server.go index 2b2867d..23b2dcd 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -14,6 +14,7 @@ import ( "github.com/thoughtworks/maeve-csms/manager/ocpp" "github.com/thoughtworks/maeve-csms/manager/store" "k8s.io/utils/clock" + "golang.org/x/exp/slog" ) type Server struct { @@ -149,6 +150,7 @@ func (s *Server) LookupChargeStationAuth(w http.ResponseWriter, r *http.Request, } func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, csId string) { + slog.Info("[TEST] in TriggerChargeStation!") req := new(ChargeStationTrigger) if err := render.Bind(r, req); err != nil { _ = render.Render(w, r, ErrInvalidRequest(err)) diff --git a/manager/sync/triggers.go b/manager/sync/triggers.go index ec4cbc0..1f223dc 100644 --- a/manager/sync/triggers.go +++ b/manager/sync/triggers.go @@ -33,10 +33,12 @@ func SyncTriggers(ctx context.Context, return case <-time.After(runEvery): func() { + slog.Info("[TEST] we are in SyncTriggers() in triggers.go 1") ctx, span := tracer.Start(ctx, "sync triggers", trace.WithSpanKind(trace.SpanKindInternal), trace.WithAttributes(attribute.String("sync.trigger.previous", previousChargeStationId))) defer span.End() triggerMessages, err := engine.ListChargeStationTriggerMessages(ctx, 50, previousChargeStationId) + slog.Info("[TEST] we are in SyncTriggers() in triggers.go 2", "triggerMessages", triggerMessages) if err != nil { span.RecordError(err) return @@ -47,9 +49,11 @@ func SyncTriggers(ctx context.Context, previousChargeStationId = "" } span.SetAttributes(attribute.Int("sync.trigger.count", len(triggerMessages))) + slog.Info("[TEST] we are in SyncTriggers() in triggers.go 3") for _, pendingTriggerMessage := range triggerMessages { func() { - slog.Info("[TEST] we are in SyncTriggers() in triggers.go", "pendingTriggerMessage", pendingTriggerMessage) + slog.Info("[TEST] we are in SyncTriggers() in triggers.go4") + slog.Info("[TEST] pendingTriggerMessage", pendingTriggerMessage) ctx, span := tracer.Start(ctx, "sync trigger", trace.WithSpanKind(trace.SpanKindInternal), trace.WithAttributes( attribute.String("chargeStationId", pendingTriggerMessage.ChargeStationId), diff --git a/manager/transport/mqtt/listener.go b/manager/transport/mqtt/listener.go index 8b1e099..0421400 100644 --- a/manager/transport/mqtt/listener.go +++ b/manager/transport/mqtt/listener.go @@ -139,6 +139,8 @@ func (l *Listener) Connect(ctx context.Context, ocppVersion transport.OcppVersio return } + slog.Info("[TEST] In listener.go", "action", msg.Action) + // add additional span attributes version, _ := strings.CutPrefix(string(ocppVersion), "ocpp") span.SetAttributes( From ba0f2f08e01a64da8f9dd2e304eebcd6fcd05c51 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 10:39:46 -0400 Subject: [PATCH 04/25] Added in charging profile types, and tried to add the route to our router --- manager/api/api.gen.go | 139 ++++++++++++++++++++++++++++++++++++++++- manager/api/render.go | 4 ++ manager/api/server.go | 18 +++++- 3 files changed, 158 insertions(+), 3 deletions(-) diff --git a/manager/api/api.gen.go b/manager/api/api.gen.go index 6f8c987..dcef177 100644 --- a/manager/api/api.gen.go +++ b/manager/api/api.gen.go @@ -13,7 +13,7 @@ import ( "path" "strings" "time" - + "log/slog" "github.com/deepmap/oapi-codegen/pkg/runtime" "github.com/getkin/kin-openapi/openapi3" "github.com/go-chi/chi/v5" @@ -299,6 +299,109 @@ type Token struct { VisualNumber *string `json:"visualNumber,omitempty"` } +////////////////////////////// +// Charging Profile Structs // +////////////////////////////// + +type ChargingProfile struct { + Id int + StackLevel int + ChargingProfilePurpose ChargingProfilePurposeEnumType + ChargingProfileKind ChargingProfileKindEnumType + RecurrencyKind RecurrencyKindEnumType + ValidFrom time.Time + ValidTo time.Time + TransactionId int + ChargingSchedule ChargingProfileType +} + +type ChargingProfilePurposeEnumType string + +const ( + ChargingStationExternalConstraints ChargingProfilePurposeEnumType = "ChargingStationExternalConstraints" + ChargingStationMaxProfile ChargingProfilePurposeEnumType = "ChargingStationMaxProfile" + TxDefaultProfile ChargingProfilePurposeEnumType = "TxDefaultProfile" + TxProfile ChargingProfilePurposeEnumType = "TxProfile" +) + +type ChargingProfileKindEnumType string + +const ( + Absolute ChargingProfileKindEnumType = "Absolute" + Recurring ChargingProfileKindEnumType = "Recurring" + Relative ChargingProfileKindEnumType = "Relative" +) + +type RecurrencyKindEnumType string + +const ( + Daily RecurrencyKindEnumType = "Daily" + Weekly RecurrencyKindEnumType = "Weekly" +) + +type ChargingProfileType struct { + Id int + StartSchedule time.Time + Duration int + ChargingRateUnit ChargingRateUnitEnumType + MinChargingRate float64 + ChargingSchedulePeriod ChargingSchedulePeriodType + SalesTariff SalesTariffType +} + +type ChargingRateUnitEnumType string + +const ( + W ChargingRateUnitEnumType = "W" + a ChargingRateUnitEnumType = "A" +) + +type ChargingSchedulePeriodType struct { + StartPeriod int + Limit float64 + NumberPhases int + PhaseToUse int +} + +type SalesTariffType struct { + Id int + SalesTariffDescription string + NumEPriceLevels int + SalesTariffEntry SalesTariffEntryType +} + +type SalesTariffEntryType struct { + EPriceLevel int + RelativeTimeInterval RelativeTimeIntervalType + ConsumptionCost ConsumptionCostType +} + +type RelativeTimeIntervalType struct { + Start int + Duration int +} + +type ConsumptionCostType struct { + StartValue float64 + Cost CostType +} + +type CostType struct { + CostKind CostKindEnumType + Amount int + AmountMultiplier int +} + +type CostKindEnumType string + +const ( + CarbonDioxideEmission CostKindEnumType = "CarbonDioxideEmission" + RelativePricePercentage CostKindEnumType = "RelativePricePercentage" + RenewableGenerationPercentage CostKindEnumType = "RenewableGenerationPercentage" +) + + + // TokenCacheMode Indicates what type of token caching is allowed type TokenCacheMode string @@ -361,6 +464,10 @@ type ServerInterface interface { // (POST /cs/{csId}/trigger) TriggerChargeStation(w http.ResponseWriter, r *http.Request, csId string) + + // (POST /cs/{csId}/setchargingprofile) + SetChargingProfile(w http.ResponseWriter, r *http.Request, csId string) + // Registers a location with the CSMS // (POST /location/{locationId}) RegisterLocation(w http.ResponseWriter, r *http.Request, locationId string) @@ -584,6 +691,33 @@ func (siw *ServerInterfaceWrapper) TriggerChargeStation(w http.ResponseWriter, r handler.ServeHTTP(w, r.WithContext(ctx)) } +// SetChargingProfile operation middleware +func (siw *ServerInterfaceWrapper) SetChargingProfile(w http.ResponseWriter, r *http.Request) { + slog.Info("[TEST] in charging profile middleware!") + ctx := r.Context() + + var err error + + // ------------- Path parameter "csId" ------------- + var csId string + + err = runtime.BindStyledParameterWithLocation("simple", false, "csId", runtime.ParamLocationPath, chi.URLParam(r, "csId"), &csId) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "csId", Err: err}) + return + } + + var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.SetChargingProfile(w, r, csId) + }) + + for i := len(siw.HandlerMiddlewares) - 1; i >= 0; i-- { + handler = siw.HandlerMiddlewares[i](handler) + } + + handler.ServeHTTP(w, r.WithContext(ctx)) +} + // RegisterLocation operation middleware func (siw *ServerInterfaceWrapper) RegisterLocation(w http.ResponseWriter, r *http.Request) { ctx := r.Context() @@ -839,6 +973,9 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl r.Group(func(r chi.Router) { r.Post(options.BaseURL+"/cs/{csId}/trigger", wrapper.TriggerChargeStation) }) + r.Group(func(r chi.Router) { + r.Post(options.BaseURL+"/cs/{csId}/setchargingprofile", wrapper.SetChargingProfile) + }) r.Group(func(r chi.Router) { r.Post(options.BaseURL+"/location/{locationId}", wrapper.RegisterLocation) }) diff --git a/manager/api/render.go b/manager/api/render.go index 9a422e6..6a32d87 100644 --- a/manager/api/render.go +++ b/manager/api/render.go @@ -24,6 +24,10 @@ func (c ChargeStationTrigger) Bind(r *http.Request) error { return nil } +func (c ChargingProfile) Bind(r *http.Request) error { + return nil +} + func (t Token) Bind(r *http.Request) error { return nil } diff --git a/manager/api/server.go b/manager/api/server.go index 2b2867d..8b8d072 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -4,11 +4,13 @@ package api import ( "fmt" - handlers "github.com/thoughtworks/maeve-csms/manager/handlers/ocpp201" - "github.com/thoughtworks/maeve-csms/manager/ocpi" + "log/slog" "net/http" "time" + handlers "github.com/thoughtworks/maeve-csms/manager/handlers/ocpp201" + "github.com/thoughtworks/maeve-csms/manager/ocpi" + "github.com/getkin/kin-openapi/openapi3" "github.com/go-chi/render" "github.com/thoughtworks/maeve-csms/manager/ocpp" @@ -167,6 +169,18 @@ func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, cs w.WriteHeader(http.StatusCreated) } +func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId string) { + slog.Info("[TEST] In server.go, SetChargingProfile()") + req := new(ChargingProfile) + slog.Info("[TEST] req:", req) + if err := render.Bind(r, req); err != nil { + _ = render.Render(w, r, ErrInvalidRequest(err)) + return + } + + w.WriteHeader(http.StatusCreated) +} + func (s *Server) SetToken(w http.ResponseWriter, r *http.Request) { req := new(Token) if err := render.Bind(r, req); err != nil { From 1bb5e81646275e683c962b2e641f54b936b54dd8 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 10:51:15 -0400 Subject: [PATCH 05/25] Changed position of import to hopefully prevent error --- manager/api/api.gen.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/manager/api/api.gen.go b/manager/api/api.gen.go index dcef177..c45cc69 100644 --- a/manager/api/api.gen.go +++ b/manager/api/api.gen.go @@ -4,6 +4,7 @@ package api import ( + "log/slog" "bytes" "compress/gzip" "encoding/base64" @@ -13,7 +14,7 @@ import ( "path" "strings" "time" - "log/slog" + "github.com/deepmap/oapi-codegen/pkg/runtime" "github.com/getkin/kin-openapi/openapi3" "github.com/go-chi/chi/v5" @@ -693,7 +694,7 @@ func (siw *ServerInterfaceWrapper) TriggerChargeStation(w http.ResponseWriter, r // SetChargingProfile operation middleware func (siw *ServerInterfaceWrapper) SetChargingProfile(w http.ResponseWriter, r *http.Request) { - slog.Info("[TEST] in charging profile middleware!") + slog.Info("[TEST] in charging profile") ctx := r.Context() var err error From 227840a2fe9e8808f6b421b0c50b0e56c19f3652 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 10:53:04 -0400 Subject: [PATCH 06/25] got rid of slog, trying fmt --- manager/api/api.gen.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manager/api/api.gen.go b/manager/api/api.gen.go index c45cc69..7e3cbf1 100644 --- a/manager/api/api.gen.go +++ b/manager/api/api.gen.go @@ -4,7 +4,6 @@ package api import ( - "log/slog" "bytes" "compress/gzip" "encoding/base64" @@ -694,7 +693,7 @@ func (siw *ServerInterfaceWrapper) TriggerChargeStation(w http.ResponseWriter, r // SetChargingProfile operation middleware func (siw *ServerInterfaceWrapper) SetChargingProfile(w http.ResponseWriter, r *http.Request) { - slog.Info("[TEST] in charging profile") + fmt.Printf("[TEST] in charging middleware!") ctx := r.Context() var err error From eea2298fcaedbeebb7d1c8fd1c335c6b4b384c7d Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 10:55:09 -0400 Subject: [PATCH 07/25] got rid of more slogs, changed to fmt --- manager/api/server.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manager/api/server.go b/manager/api/server.go index 8b8d072..4c3a325 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -4,7 +4,6 @@ package api import ( "fmt" - "log/slog" "net/http" "time" @@ -170,9 +169,10 @@ func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, cs } func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId string) { - slog.Info("[TEST] In server.go, SetChargingProfile()") + fmt.Printf("[TEST] In server.go, SetChargingProfile()") req := new(ChargingProfile) - slog.Info("[TEST] req:", req) + fmt.Printf("%+v\n", req) + if err := render.Bind(r, req); err != nil { _ = render.Render(w, r, ErrInvalidRequest(err)) return From 40bb05dab799b5425aaf12f6d42211723a482ca9 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 11:09:51 -0400 Subject: [PATCH 08/25] Trying new import for slog --- manager/api/api.gen.go | 3 ++- manager/api/server.go | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/manager/api/api.gen.go b/manager/api/api.gen.go index 7e3cbf1..0712be2 100644 --- a/manager/api/api.gen.go +++ b/manager/api/api.gen.go @@ -13,6 +13,7 @@ import ( "path" "strings" "time" + "golang.org/x/exp/slog" "github.com/deepmap/oapi-codegen/pkg/runtime" "github.com/getkin/kin-openapi/openapi3" @@ -693,7 +694,7 @@ func (siw *ServerInterfaceWrapper) TriggerChargeStation(w http.ResponseWriter, r // SetChargingProfile operation middleware func (siw *ServerInterfaceWrapper) SetChargingProfile(w http.ResponseWriter, r *http.Request) { - fmt.Printf("[TEST] in charging middleware!") + slog.Info("[TEST] in charging middleware!") ctx := r.Context() var err error diff --git a/manager/api/server.go b/manager/api/server.go index f7a92aa..fbad723 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -14,8 +14,8 @@ import ( "github.com/go-chi/render" "github.com/thoughtworks/maeve-csms/manager/ocpp" "github.com/thoughtworks/maeve-csms/manager/store" - "k8s.io/utils/clock" "golang.org/x/exp/slog" + "k8s.io/utils/clock" ) type Server struct { @@ -171,9 +171,9 @@ func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, cs } func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId string) { - fmt.Printf("[TEST] In server.go, SetChargingProfile()") + slog.Info("[TEST] In server.go, SetChargingProfile()") req := new(ChargingProfile) - fmt.Printf("%+v\n", req) + slog.Info("[TEST] req:", req) if err := render.Bind(r, req); err != nil { _ = render.Render(w, r, ErrInvalidRequest(err)) From 46182ff09ec366e1b146418847ffb518e9ef628a Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 12:00:39 -0400 Subject: [PATCH 09/25] changed logs to see http body --- manager/api/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manager/api/server.go b/manager/api/server.go index fbad723..d3b9783 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -173,7 +173,7 @@ func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, cs func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId string) { slog.Info("[TEST] In server.go, SetChargingProfile()") req := new(ChargingProfile) - slog.Info("[TEST] req:", req) + slog.Info("[TEST] r.Body:", r.Body) if err := render.Bind(r, req); err != nil { _ = render.Render(w, r, ErrInvalidRequest(err)) From 6af2e289b2f12b5177bddc47f3e4f7be1b9a7500 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 12:21:20 -0400 Subject: [PATCH 10/25] changed the logs --- manager/api/render.go | 4 +++- manager/api/server.go | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/manager/api/render.go b/manager/api/render.go index 6a32d87..59e7d91 100644 --- a/manager/api/render.go +++ b/manager/api/render.go @@ -2,7 +2,9 @@ package api -import "net/http" +import ( + "net/http" +) func (c ChargeStationAuth) Bind(r *http.Request) error { return nil diff --git a/manager/api/server.go b/manager/api/server.go index d3b9783..bab2765 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -173,13 +173,14 @@ func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, cs func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId string) { slog.Info("[TEST] In server.go, SetChargingProfile()") req := new(ChargingProfile) - slog.Info("[TEST] r.Body:", r.Body) if err := render.Bind(r, req); err != nil { _ = render.Render(w, r, ErrInvalidRequest(err)) return } + slog.Info("[TEST] req:", req) + w.WriteHeader(http.StatusCreated) } From 81c8d8c45b9c0809a0bd21e70eb8576de282cb7e Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 13:55:02 -0400 Subject: [PATCH 11/25] Attempting to make a call to Send --- manager/api/api.gen.go | 6 +++--- manager/api/render.go | 2 +- manager/api/server.go | 23 ++++++++++++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/manager/api/api.gen.go b/manager/api/api.gen.go index 0712be2..7c85ffb 100644 --- a/manager/api/api.gen.go +++ b/manager/api/api.gen.go @@ -304,7 +304,7 @@ type Token struct { // Charging Profile Structs // ////////////////////////////// -type ChargingProfile struct { +type ChargingProfileType struct { Id int StackLevel int ChargingProfilePurpose ChargingProfilePurposeEnumType @@ -313,7 +313,7 @@ type ChargingProfile struct { ValidFrom time.Time ValidTo time.Time TransactionId int - ChargingSchedule ChargingProfileType + ChargingSchedule ChargingScheduleType } type ChargingProfilePurposeEnumType string @@ -340,7 +340,7 @@ const ( Weekly RecurrencyKindEnumType = "Weekly" ) -type ChargingProfileType struct { +type ChargingScheduleType struct { Id int StartSchedule time.Time Duration int diff --git a/manager/api/render.go b/manager/api/render.go index 59e7d91..e1c064b 100644 --- a/manager/api/render.go +++ b/manager/api/render.go @@ -26,7 +26,7 @@ func (c ChargeStationTrigger) Bind(r *http.Request) error { return nil } -func (c ChargingProfile) Bind(r *http.Request) error { +func (c ChargingProfileType) Bind(r *http.Request) error { return nil } diff --git a/manager/api/server.go b/manager/api/server.go index bab2765..df56639 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -3,10 +3,12 @@ package api import ( + "context" "fmt" "net/http" "time" + "github.com/thoughtworks/maeve-csms/manager/config" handlers "github.com/thoughtworks/maeve-csms/manager/handlers/ocpp201" "github.com/thoughtworks/maeve-csms/manager/ocpi" @@ -170,9 +172,16 @@ func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, cs w.WriteHeader(http.StatusCreated) } +type SetChargingProfileRequestJson struct { + EvseId int + ChargingProfileType ChargingProfileType +} + +func (*SetChargingProfileRequestJson) IsRequest() {} + func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId string) { slog.Info("[TEST] In server.go, SetChargingProfile()") - req := new(ChargingProfile) + req := new(ChargingProfileType) if err := render.Bind(r, req); err != nil { _ = render.Render(w, r, ErrInvalidRequest(err)) @@ -181,6 +190,18 @@ func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId slog.Info("[TEST] req:", req) + // Get the transport.Emitter so that we can send messages + cfg := config.DefaultConfig + settings, _ := config.Configure(context.Background(), &cfg) + + // Define the call maker + v201CallMaker := handlers.NewCallMaker(settings.MsgEmitter) + + request := SetChargingProfileRequestJson{EvseId: 0, ChargingProfileType: *req} + + // Send the call + v201CallMaker.Send(context.Background(), csId, &request) + w.WriteHeader(http.StatusCreated) } From a9c3fd8725817b28947442f88cc82357f1164a1c Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 14:05:00 -0400 Subject: [PATCH 12/25] Got rid of error handling temporarily to see if my call will go through --- manager/handlers/call_maker.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/manager/handlers/call_maker.go b/manager/handlers/call_maker.go index fa360eb..61ef564 100644 --- a/manager/handlers/call_maker.go +++ b/manager/handlers/call_maker.go @@ -5,12 +5,12 @@ package handlers import ( "context" "encoding/json" - "fmt" + "reflect" + "github.com/google/uuid" "github.com/thoughtworks/maeve-csms/manager/ocpp" "github.com/thoughtworks/maeve-csms/manager/transport" "golang.org/x/exp/slog" - "reflect" ) // OcppCallMaker is an implementation of the CallMaker interface for a specific set of OCPP messages. @@ -21,11 +21,11 @@ type OcppCallMaker struct { } func (b OcppCallMaker) Send(ctx context.Context, chargeStationId string, request ocpp.Request) error { - action, ok := b.Actions[reflect.TypeOf(request)] + action, _ := b.Actions[reflect.TypeOf(request)] slog.Info("[TEST] we are in Send() in call_maker.go", "action", action) - if !ok { - return fmt.Errorf("unknown request type: %T", request) - } + // if !ok { + // return fmt.Errorf("unknown request type: %T", request) + // } requestBytes, err := json.Marshal(request) if err != nil { From 27bed6130b8060cffd9878373c27895352dc0126 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 17:46:19 -0400 Subject: [PATCH 13/25] Fixed the typing so that we now use their types they defined, and got it to work with the current code I have. Also added in a few new structs to handle the request/response of the call, and started working on the handler function to deal with the response --- manager/api/api.gen.go | 204 +++++++++--------- manager/api/server.go | 10 +- .../request_start_transaction_result.go | 1 + .../ocpp201/set_charging_profile_result.go | 36 ++++ .../ocpp201/set_charging_profile_request.go | 8 + .../ocpp201/set_charging_profile_response.go | 19 ++ 6 files changed, 170 insertions(+), 108 deletions(-) create mode 100644 manager/handlers/ocpp201/set_charging_profile_result.go create mode 100644 manager/ocpp/ocpp201/set_charging_profile_request.go create mode 100644 manager/ocpp/ocpp201/set_charging_profile_response.go diff --git a/manager/api/api.gen.go b/manager/api/api.gen.go index 7c85ffb..e95941f 100644 --- a/manager/api/api.gen.go +++ b/manager/api/api.gen.go @@ -18,6 +18,7 @@ import ( "github.com/deepmap/oapi-codegen/pkg/runtime" "github.com/getkin/kin-openapi/openapi3" "github.com/go-chi/chi/v5" + "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" ) // Defines values for ChargeStationInstallCertificatesCertificatesStatus. @@ -300,106 +301,109 @@ type Token struct { VisualNumber *string `json:"visualNumber,omitempty"` } -////////////////////////////// -// Charging Profile Structs // -////////////////////////////// - -type ChargingProfileType struct { - Id int - StackLevel int - ChargingProfilePurpose ChargingProfilePurposeEnumType - ChargingProfileKind ChargingProfileKindEnumType - RecurrencyKind RecurrencyKindEnumType - ValidFrom time.Time - ValidTo time.Time - TransactionId int - ChargingSchedule ChargingScheduleType -} - -type ChargingProfilePurposeEnumType string - -const ( - ChargingStationExternalConstraints ChargingProfilePurposeEnumType = "ChargingStationExternalConstraints" - ChargingStationMaxProfile ChargingProfilePurposeEnumType = "ChargingStationMaxProfile" - TxDefaultProfile ChargingProfilePurposeEnumType = "TxDefaultProfile" - TxProfile ChargingProfilePurposeEnumType = "TxProfile" -) - -type ChargingProfileKindEnumType string - -const ( - Absolute ChargingProfileKindEnumType = "Absolute" - Recurring ChargingProfileKindEnumType = "Recurring" - Relative ChargingProfileKindEnumType = "Relative" -) - -type RecurrencyKindEnumType string - -const ( - Daily RecurrencyKindEnumType = "Daily" - Weekly RecurrencyKindEnumType = "Weekly" -) - -type ChargingScheduleType struct { - Id int - StartSchedule time.Time - Duration int - ChargingRateUnit ChargingRateUnitEnumType - MinChargingRate float64 - ChargingSchedulePeriod ChargingSchedulePeriodType - SalesTariff SalesTariffType -} - -type ChargingRateUnitEnumType string - -const ( - W ChargingRateUnitEnumType = "W" - a ChargingRateUnitEnumType = "A" -) - -type ChargingSchedulePeriodType struct { - StartPeriod int - Limit float64 - NumberPhases int - PhaseToUse int -} - -type SalesTariffType struct { - Id int - SalesTariffDescription string - NumEPriceLevels int - SalesTariffEntry SalesTariffEntryType -} - -type SalesTariffEntryType struct { - EPriceLevel int - RelativeTimeInterval RelativeTimeIntervalType - ConsumptionCost ConsumptionCostType -} - -type RelativeTimeIntervalType struct { - Start int - Duration int -} - -type ConsumptionCostType struct { - StartValue float64 - Cost CostType -} - -type CostType struct { - CostKind CostKindEnumType - Amount int - AmountMultiplier int -} - -type CostKindEnumType string - -const ( - CarbonDioxideEmission CostKindEnumType = "CarbonDioxideEmission" - RelativePricePercentage CostKindEnumType = "RelativePricePercentage" - RenewableGenerationPercentage CostKindEnumType = "RenewableGenerationPercentage" -) +// ////////////////////////////// +// // Charging Profile Structs // +// ////////////////////////////// + +type ChargingProfileType ocpp201.ChargingProfileType + + +// type ChargingProfileType struct { +// Id int +// StackLevel int +// ChargingProfilePurpose ChargingProfilePurposeEnumType +// ChargingProfileKind ChargingProfileKindEnumType +// RecurrencyKind RecurrencyKindEnumType +// ValidFrom time.Time +// ValidTo time.Time +// TransactionId int +// ChargingSchedule ChargingScheduleType +// } + +// type ChargingProfilePurposeEnumType string + +// const ( +// ChargingStationExternalConstraints ChargingProfilePurposeEnumType = "ChargingStationExternalConstraints" +// ChargingStationMaxProfile ChargingProfilePurposeEnumType = "ChargingStationMaxProfile" +// TxDefaultProfile ChargingProfilePurposeEnumType = "TxDefaultProfile" +// TxProfile ChargingProfilePurposeEnumType = "TxProfile" +// ) + +// type ChargingProfileKindEnumType string + +// const ( +// Absolute ChargingProfileKindEnumType = "Absolute" +// Recurring ChargingProfileKindEnumType = "Recurring" +// Relative ChargingProfileKindEnumType = "Relative" +// ) + +// type RecurrencyKindEnumType string + +// const ( +// Daily RecurrencyKindEnumType = "Daily" +// Weekly RecurrencyKindEnumType = "Weekly" +// ) + +// type ChargingScheduleType struct { +// Id int +// StartSchedule time.Time +// Duration int +// ChargingRateUnit ChargingRateUnitEnumType +// MinChargingRate float64 +// ChargingSchedulePeriod ChargingSchedulePeriodType +// SalesTariff SalesTariffType +// } + +// type ChargingRateUnitEnumType string + +// const ( +// W ChargingRateUnitEnumType = "W" +// a ChargingRateUnitEnumType = "A" +// ) + +// type ChargingSchedulePeriodType struct { +// StartPeriod int +// Limit float64 +// NumberPhases int +// PhaseToUse int +// } + +// type SalesTariffType struct { +// Id int +// SalesTariffDescription string +// NumEPriceLevels int +// SalesTariffEntry SalesTariffEntryType +// } + +// type SalesTariffEntryType struct { +// EPriceLevel int +// RelativeTimeInterval RelativeTimeIntervalType +// ConsumptionCost ConsumptionCostType +// } + +// type RelativeTimeIntervalType struct { +// Start int +// Duration int +// } + +// type ConsumptionCostType struct { +// StartValue float64 +// Cost CostType +// } + +// type CostType struct { +// CostKind CostKindEnumType +// Amount int +// AmountMultiplier int +// } + +// type CostKindEnumType string + +// const ( +// CarbonDioxideEmission CostKindEnumType = "CarbonDioxideEmission" +// RelativePricePercentage CostKindEnumType = "RelativePricePercentage" +// RenewableGenerationPercentage CostKindEnumType = "RenewableGenerationPercentage" +// ) diff --git a/manager/api/server.go b/manager/api/server.go index df56639..fe94761 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -15,6 +15,7 @@ import ( "github.com/getkin/kin-openapi/openapi3" "github.com/go-chi/render" "github.com/thoughtworks/maeve-csms/manager/ocpp" + "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "github.com/thoughtworks/maeve-csms/manager/store" "golang.org/x/exp/slog" "k8s.io/utils/clock" @@ -172,13 +173,6 @@ func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, cs w.WriteHeader(http.StatusCreated) } -type SetChargingProfileRequestJson struct { - EvseId int - ChargingProfileType ChargingProfileType -} - -func (*SetChargingProfileRequestJson) IsRequest() {} - func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId string) { slog.Info("[TEST] In server.go, SetChargingProfile()") req := new(ChargingProfileType) @@ -197,7 +191,7 @@ func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId // Define the call maker v201CallMaker := handlers.NewCallMaker(settings.MsgEmitter) - request := SetChargingProfileRequestJson{EvseId: 0, ChargingProfileType: *req} + request := ocpp201.SetChargingProfileRequestJson{EvseId: 0, ChargingProfileType: ocpp201.ChargingProfileType(*req)} // Send the call v201CallMaker.Send(context.Background(), csId, &request) diff --git a/manager/handlers/ocpp201/request_start_transaction_result.go b/manager/handlers/ocpp201/request_start_transaction_result.go index 2f2b388..a3c90a2 100644 --- a/manager/handlers/ocpp201/request_start_transaction_result.go +++ b/manager/handlers/ocpp201/request_start_transaction_result.go @@ -4,6 +4,7 @@ package ocpp201 import ( "context" + "github.com/thoughtworks/maeve-csms/manager/ocpp" types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "go.opentelemetry.io/otel/attribute" diff --git a/manager/handlers/ocpp201/set_charging_profile_result.go b/manager/handlers/ocpp201/set_charging_profile_result.go new file mode 100644 index 0000000..e62d873 --- /dev/null +++ b/manager/handlers/ocpp201/set_charging_profile_result.go @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 + +package ocpp201 + +import ( + "context" + + "github.com/thoughtworks/maeve-csms/manager/ocpp" + types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" + "golang.org/x/exp/slog" +) + +type SetChargingProfileResultHandler struct{} + +func (h SetChargingProfileResultHandler) HandleCallResult(ctx context.Context, chargeStationId string, request ocpp.Request, response ocpp.Response, state any) error { + // req := request.(*types.RequestStartTransactionRequestJson) + // resp := response.(*types.RequestStartTransactionResponseJson) + resp := response.(*types.SetChargingProfileResponseJson) + + slog.Info("[TEST] in scp_result.go, got response:", resp) + + // span := trace.SpanFromContext(ctx) + + // span.SetAttributes( + // attribute.Int("request_start.remote_start_id", req.RemoteStartId), + // attribute.String("request_start.status", string(resp.Status))) + + // if resp.TransactionId != nil { + // span.SetAttributes( + // attribute.String("request_start.transaction_id", *resp.TransactionId)) + // } + + // Do something here ^^^ above is template from request_start_transaction_result.go + + return nil +} diff --git a/manager/ocpp/ocpp201/set_charging_profile_request.go b/manager/ocpp/ocpp201/set_charging_profile_request.go new file mode 100644 index 0000000..c74d83f --- /dev/null +++ b/manager/ocpp/ocpp201/set_charging_profile_request.go @@ -0,0 +1,8 @@ +package ocpp201 + +type SetChargingProfileRequestJson struct { + EvseId int + ChargingProfileType ChargingProfileType +} + +func (*SetChargingProfileRequestJson) IsRequest() {} diff --git a/manager/ocpp/ocpp201/set_charging_profile_response.go b/manager/ocpp/ocpp201/set_charging_profile_response.go new file mode 100644 index 0000000..d712147 --- /dev/null +++ b/manager/ocpp/ocpp201/set_charging_profile_response.go @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: Apache-2.0 + +package ocpp201 + +import "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" + +type ChargingProfileStatusEnumType string + +const ( + Accepted ChargingProfileStatusEnumType = "Accepted" + Rejected ChargingProfileStatusEnumType = "Rejected" +) + +type SetChargingProfileResponseJson struct { + Status ChargingProfileStatusEnumType + StatusInfo ocpp201.StatusInfoType +} + +func (*SetChargingProfileResponseJson) IsResponse() {} From 6df4a80856217a2324540b709ae3c27ff63382ff Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 18:02:17 -0400 Subject: [PATCH 14/25] Added our request into the callmaker actions so it won't error. Also fixed up a cyclic import bug --- manager/handlers/call_maker.go | 9 +++++---- manager/handlers/ocpp201/routing.go | 8 +++++--- .../ocpp201/set_charging_profile_result.go | 18 ++---------------- .../ocpp201/set_charging_profile_response.go | 4 +--- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/manager/handlers/call_maker.go b/manager/handlers/call_maker.go index 61ef564..f84ec86 100644 --- a/manager/handlers/call_maker.go +++ b/manager/handlers/call_maker.go @@ -21,11 +21,12 @@ type OcppCallMaker struct { } func (b OcppCallMaker) Send(ctx context.Context, chargeStationId string, request ocpp.Request) error { - action, _ := b.Actions[reflect.TypeOf(request)] + action, ok := b.Actions[reflect.TypeOf(request)] slog.Info("[TEST] we are in Send() in call_maker.go", "action", action) - // if !ok { - // return fmt.Errorf("unknown request type: %T", request) - // } + if !ok { + slog.Error("unknown request type", request) + return nil + } requestBytes, err := json.Marshal(request) if err != nil { diff --git a/manager/handlers/ocpp201/routing.go b/manager/handlers/ocpp201/routing.go index d4759f6..868c1fe 100644 --- a/manager/handlers/ocpp201/routing.go +++ b/manager/handlers/ocpp201/routing.go @@ -3,16 +3,17 @@ package ocpp201 import ( + "io/fs" + "reflect" + "time" + "github.com/thoughtworks/maeve-csms/manager/handlers" "github.com/thoughtworks/maeve-csms/manager/ocpp" "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "github.com/thoughtworks/maeve-csms/manager/services" "github.com/thoughtworks/maeve-csms/manager/store" "github.com/thoughtworks/maeve-csms/manager/transport" - "io/fs" "k8s.io/utils/clock" - "reflect" - "time" ) func NewRouter(emitter transport.Emitter, @@ -306,6 +307,7 @@ func NewCallMaker(e transport.Emitter) *handlers.OcppCallMaker { reflect.TypeOf(&ocpp201.SetVariablesRequestJson{}): "SetVariables", reflect.TypeOf(&ocpp201.TriggerMessageRequestJson{}): "TriggerMessage", reflect.TypeOf(&ocpp201.UnlockConnectorRequestJson{}): "UnlockConnector", + reflect.TypeOf(&ocpp201.SetChargingProfileRequestJson{}): "SetChargingProfile", }, } } diff --git a/manager/handlers/ocpp201/set_charging_profile_result.go b/manager/handlers/ocpp201/set_charging_profile_result.go index e62d873..73e109f 100644 --- a/manager/handlers/ocpp201/set_charging_profile_result.go +++ b/manager/handlers/ocpp201/set_charging_profile_result.go @@ -13,24 +13,10 @@ import ( type SetChargingProfileResultHandler struct{} func (h SetChargingProfileResultHandler) HandleCallResult(ctx context.Context, chargeStationId string, request ocpp.Request, response ocpp.Response, state any) error { - // req := request.(*types.RequestStartTransactionRequestJson) - // resp := response.(*types.RequestStartTransactionResponseJson) + req := request.(*types.SetChargingProfileRequestJson) resp := response.(*types.SetChargingProfileResponseJson) - slog.Info("[TEST] in scp_result.go, got response:", resp) - - // span := trace.SpanFromContext(ctx) - - // span.SetAttributes( - // attribute.Int("request_start.remote_start_id", req.RemoteStartId), - // attribute.String("request_start.status", string(resp.Status))) - - // if resp.TransactionId != nil { - // span.SetAttributes( - // attribute.String("request_start.transaction_id", *resp.TransactionId)) - // } - - // Do something here ^^^ above is template from request_start_transaction_result.go + slog.Info("[TEST] in scp_result.go, got response:", resp, "[TEST] From request:", req) return nil } diff --git a/manager/ocpp/ocpp201/set_charging_profile_response.go b/manager/ocpp/ocpp201/set_charging_profile_response.go index d712147..9ff2c4e 100644 --- a/manager/ocpp/ocpp201/set_charging_profile_response.go +++ b/manager/ocpp/ocpp201/set_charging_profile_response.go @@ -2,8 +2,6 @@ package ocpp201 -import "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" - type ChargingProfileStatusEnumType string const ( @@ -13,7 +11,7 @@ const ( type SetChargingProfileResponseJson struct { Status ChargingProfileStatusEnumType - StatusInfo ocpp201.StatusInfoType + StatusInfo StatusInfoType } func (*SetChargingProfileResponseJson) IsResponse() {} From fd4dad5ecbcea19ae12b11d1589556f77221b041 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Fri, 7 Jun 2024 18:14:31 -0400 Subject: [PATCH 15/25] added in todo so I don't forget --- manager/handlers/router.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manager/handlers/router.go b/manager/handlers/router.go index 72a2b8e..8f5646f 100644 --- a/manager/handlers/router.go +++ b/manager/handlers/router.go @@ -7,13 +7,14 @@ import ( "encoding/json" "errors" "fmt" + "io/fs" + "github.com/santhosh-tekuri/jsonschema" "github.com/thoughtworks/maeve-csms/manager/schemas" "github.com/thoughtworks/maeve-csms/manager/transport" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" "golang.org/x/exp/slog" - "io/fs" ) // Router is the primary implementation of the transport.Router interface. @@ -29,6 +30,9 @@ func (r Router) Handle(ctx context.Context, chargeStationId string, msg *transpo span := trace.SpanFromContext(ctx) err := r.route(ctx, chargeStationId, msg) + + // TODO: Route setChargingProfile message here! + if err != nil { slog.Error("unable to route message", slog.String("chargeStationId", chargeStationId), slog.String("action", msg.Action), "err", err) span.SetStatus(codes.Error, "routing request failed") From ff3999abb4a2dac0253e736430f58ba7ffae48ac Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Sat, 8 Jun 2024 11:43:36 -0400 Subject: [PATCH 16/25] Added more context to how we can deal with the EVerest response to setChargingProfile if we needed to --- manager/handlers/router.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manager/handlers/router.go b/manager/handlers/router.go index 8f5646f..8f99665 100644 --- a/manager/handlers/router.go +++ b/manager/handlers/router.go @@ -31,7 +31,8 @@ func (r Router) Handle(ctx context.Context, chargeStationId string, msg *transpo err := r.route(ctx, chargeStationId, msg) - // TODO: Route setChargingProfile message here! + // ^^^ r.route goes into the transport.MessageTypeCallError switch statement, returns error b/c EVerest returns not implemented + // TODO: Handle setChargingProfile response here if we want to do more on CSMS side! if err != nil { slog.Error("unable to route message", slog.String("chargeStationId", chargeStationId), slog.String("action", msg.Action), "err", err) From 1b3f432f486f9b8a9d0244335231589479b5c96d Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Wed, 12 Jun 2024 11:53:31 -0400 Subject: [PATCH 17/25] Fixed typo in charging profile struct and added new comments --- manager/api/server.go | 2 +- manager/ocpp/ocpp201/set_charging_profile_request.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/manager/api/server.go b/manager/api/server.go index fe94761..eafd524 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -191,7 +191,7 @@ func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId // Define the call maker v201CallMaker := handlers.NewCallMaker(settings.MsgEmitter) - request := ocpp201.SetChargingProfileRequestJson{EvseId: 0, ChargingProfileType: ocpp201.ChargingProfileType(*req)} + request := ocpp201.SetChargingProfileRequestJson{EvseId: 0, ChargingProfile: ocpp201.ChargingProfileType(*req)} // Send the call v201CallMaker.Send(context.Background(), csId, &request) diff --git a/manager/ocpp/ocpp201/set_charging_profile_request.go b/manager/ocpp/ocpp201/set_charging_profile_request.go index c74d83f..21d610e 100644 --- a/manager/ocpp/ocpp201/set_charging_profile_request.go +++ b/manager/ocpp/ocpp201/set_charging_profile_request.go @@ -1,8 +1,8 @@ package ocpp201 type SetChargingProfileRequestJson struct { - EvseId int - ChargingProfileType ChargingProfileType + EvseId int + ChargingProfile ChargingProfileType } func (*SetChargingProfileRequestJson) IsRequest() {} From e55f24ea6847aef5d9d89039d78138c935388dff Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Mon, 17 Jun 2024 10:05:50 -0400 Subject: [PATCH 18/25] Added in work around for setChargingProfile so that we give EVerest data with lowercase values --- manager/handlers/call_maker.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/manager/handlers/call_maker.go b/manager/handlers/call_maker.go index f84ec86..40c5ba9 100644 --- a/manager/handlers/call_maker.go +++ b/manager/handlers/call_maker.go @@ -9,6 +9,7 @@ import ( "github.com/google/uuid" "github.com/thoughtworks/maeve-csms/manager/ocpp" + "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "github.com/thoughtworks/maeve-csms/manager/transport" "golang.org/x/exp/slog" ) @@ -20,6 +21,11 @@ type OcppCallMaker struct { Actions map[reflect.Type]string // the OCPP Action associated with a specific ocpp.Request object } +type SetChargingProfileRequestJsonFix struct { + evseId int + chargingProfile interface{} +} + func (b OcppCallMaker) Send(ctx context.Context, chargeStationId string, request ocpp.Request) error { action, ok := b.Actions[reflect.TypeOf(request)] slog.Info("[TEST] we are in Send() in call_maker.go", "action", action) @@ -28,7 +34,24 @@ func (b OcppCallMaker) Send(ctx context.Context, chargeStationId string, request return nil } - requestBytes, err := json.Marshal(request) + var reqData interface{} + reqData = request + + if action == "SetChargingProfile" { + slog.Info("[TEST] in send(), SetChargingProfile case") + if req, ok := request.(*ocpp201.SetChargingProfileRequestJson); ok { + test := SetChargingProfileRequestJsonFix{ + evseId: req.EvseId, + chargingProfile: req.ChargingProfile, + } + reqData = test + slog.Info("[TEST] in send(), SetChargingProfile case, new data now saved:", reqData) + } else { + slog.Error("[TEST] ERROR IN TYPE ASSERTION") + } + } + + requestBytes, err := json.Marshal(reqData) if err != nil { return err } From e665a0e104e6cd173a559eb835a5f87cd2790d96 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Mon, 17 Jun 2024 10:25:47 -0400 Subject: [PATCH 19/25] added in new log --- manager/handlers/call_maker.go | 1 + 1 file changed, 1 insertion(+) diff --git a/manager/handlers/call_maker.go b/manager/handlers/call_maker.go index 40c5ba9..a3963a4 100644 --- a/manager/handlers/call_maker.go +++ b/manager/handlers/call_maker.go @@ -44,6 +44,7 @@ func (b OcppCallMaker) Send(ctx context.Context, chargeStationId string, request evseId: req.EvseId, chargingProfile: req.ChargingProfile, } + slog.Info("[TEST] in send(), SetChargingProfile case, new data is now:", test) reqData = test slog.Info("[TEST] in send(), SetChargingProfile case, new data now saved:", reqData) } else { From 8c22c88451b3e96af26d6defe7bc958b659faab9 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Mon, 17 Jun 2024 10:59:15 -0400 Subject: [PATCH 20/25] commented out old changes, added in json mapping in struct --- manager/handlers/call_maker.go | 35 +++++++++---------- .../ocpp201/set_charging_profile_request.go | 4 +-- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/manager/handlers/call_maker.go b/manager/handlers/call_maker.go index a3963a4..1f28276 100644 --- a/manager/handlers/call_maker.go +++ b/manager/handlers/call_maker.go @@ -9,7 +9,6 @@ import ( "github.com/google/uuid" "github.com/thoughtworks/maeve-csms/manager/ocpp" - "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "github.com/thoughtworks/maeve-csms/manager/transport" "golang.org/x/exp/slog" ) @@ -34,25 +33,25 @@ func (b OcppCallMaker) Send(ctx context.Context, chargeStationId string, request return nil } - var reqData interface{} - reqData = request + // var reqData interface{} + // reqData = request - if action == "SetChargingProfile" { - slog.Info("[TEST] in send(), SetChargingProfile case") - if req, ok := request.(*ocpp201.SetChargingProfileRequestJson); ok { - test := SetChargingProfileRequestJsonFix{ - evseId: req.EvseId, - chargingProfile: req.ChargingProfile, - } - slog.Info("[TEST] in send(), SetChargingProfile case, new data is now:", test) - reqData = test - slog.Info("[TEST] in send(), SetChargingProfile case, new data now saved:", reqData) - } else { - slog.Error("[TEST] ERROR IN TYPE ASSERTION") - } - } + // if action == "SetChargingProfile" { + // slog.Info("[TEST] in send(), SetChargingProfile case") + // if req, ok := request.(*ocpp201.SetChargingProfileRequestJson); ok { + // test := SetChargingProfileRequestJsonFix{ + // evseId: req.EvseId, + // chargingProfile: req.ChargingProfile, + // } + // slog.Info("[TEST] in send(), SetChargingProfile case, new data is now:", test) + // reqData = test + // slog.Info("[TEST] in send(), SetChargingProfile case, new data now saved:", reqData) + // } else { + // slog.Error("[TEST] ERROR IN TYPE ASSERTION") + // } + // } - requestBytes, err := json.Marshal(reqData) + requestBytes, err := json.Marshal(request) if err != nil { return err } diff --git a/manager/ocpp/ocpp201/set_charging_profile_request.go b/manager/ocpp/ocpp201/set_charging_profile_request.go index 21d610e..71bac3a 100644 --- a/manager/ocpp/ocpp201/set_charging_profile_request.go +++ b/manager/ocpp/ocpp201/set_charging_profile_request.go @@ -1,8 +1,8 @@ package ocpp201 type SetChargingProfileRequestJson struct { - EvseId int - ChargingProfile ChargingProfileType + EvseId int `json:"evseId"` + ChargingProfile ChargingProfileType `json:"chargingProfile"` } func (*SetChargingProfileRequestJson) IsRequest() {} From 0269ebdec342ad23b02107f42e54d72cccb87644 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Mon, 17 Jun 2024 11:09:46 -0400 Subject: [PATCH 21/25] Got rid of temporary fix, added in more json fields --- manager/handlers/call_maker.go | 18 ------------------ .../ocpp201/set_charging_profile_response.go | 4 ++-- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/manager/handlers/call_maker.go b/manager/handlers/call_maker.go index 1f28276..79d8b99 100644 --- a/manager/handlers/call_maker.go +++ b/manager/handlers/call_maker.go @@ -33,24 +33,6 @@ func (b OcppCallMaker) Send(ctx context.Context, chargeStationId string, request return nil } - // var reqData interface{} - // reqData = request - - // if action == "SetChargingProfile" { - // slog.Info("[TEST] in send(), SetChargingProfile case") - // if req, ok := request.(*ocpp201.SetChargingProfileRequestJson); ok { - // test := SetChargingProfileRequestJsonFix{ - // evseId: req.EvseId, - // chargingProfile: req.ChargingProfile, - // } - // slog.Info("[TEST] in send(), SetChargingProfile case, new data is now:", test) - // reqData = test - // slog.Info("[TEST] in send(), SetChargingProfile case, new data now saved:", reqData) - // } else { - // slog.Error("[TEST] ERROR IN TYPE ASSERTION") - // } - // } - requestBytes, err := json.Marshal(request) if err != nil { return err diff --git a/manager/ocpp/ocpp201/set_charging_profile_response.go b/manager/ocpp/ocpp201/set_charging_profile_response.go index 9ff2c4e..af1ee97 100644 --- a/manager/ocpp/ocpp201/set_charging_profile_response.go +++ b/manager/ocpp/ocpp201/set_charging_profile_response.go @@ -10,8 +10,8 @@ const ( ) type SetChargingProfileResponseJson struct { - Status ChargingProfileStatusEnumType - StatusInfo StatusInfoType + Status ChargingProfileStatusEnumType `json:"status"` + StatusInfo StatusInfoType `json:"statusInfo"` } func (*SetChargingProfileResponseJson) IsResponse() {} From 385a1734f13dbc4f4e4ce1895529d640623ae1b5 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Tue, 18 Jun 2024 11:16:25 -0400 Subject: [PATCH 22/25] Cleaned up extraneous comments and log statements --- manager/api/api.gen.go | 104 ------------------ .../ocpp201/trigger_message_result.go | 6 +- manager/handlers/router.go | 1 - manager/sync/triggers.go | 9 +- manager/transport/mqtt/listener.go | 11 +- 5 files changed, 9 insertions(+), 122 deletions(-) diff --git a/manager/api/api.gen.go b/manager/api/api.gen.go index e95941f..d9ffcb7 100644 --- a/manager/api/api.gen.go +++ b/manager/api/api.gen.go @@ -301,112 +301,8 @@ type Token struct { VisualNumber *string `json:"visualNumber,omitempty"` } -// ////////////////////////////// -// // Charging Profile Structs // -// ////////////////////////////// - type ChargingProfileType ocpp201.ChargingProfileType - -// type ChargingProfileType struct { -// Id int -// StackLevel int -// ChargingProfilePurpose ChargingProfilePurposeEnumType -// ChargingProfileKind ChargingProfileKindEnumType -// RecurrencyKind RecurrencyKindEnumType -// ValidFrom time.Time -// ValidTo time.Time -// TransactionId int -// ChargingSchedule ChargingScheduleType -// } - -// type ChargingProfilePurposeEnumType string - -// const ( -// ChargingStationExternalConstraints ChargingProfilePurposeEnumType = "ChargingStationExternalConstraints" -// ChargingStationMaxProfile ChargingProfilePurposeEnumType = "ChargingStationMaxProfile" -// TxDefaultProfile ChargingProfilePurposeEnumType = "TxDefaultProfile" -// TxProfile ChargingProfilePurposeEnumType = "TxProfile" -// ) - -// type ChargingProfileKindEnumType string - -// const ( -// Absolute ChargingProfileKindEnumType = "Absolute" -// Recurring ChargingProfileKindEnumType = "Recurring" -// Relative ChargingProfileKindEnumType = "Relative" -// ) - -// type RecurrencyKindEnumType string - -// const ( -// Daily RecurrencyKindEnumType = "Daily" -// Weekly RecurrencyKindEnumType = "Weekly" -// ) - -// type ChargingScheduleType struct { -// Id int -// StartSchedule time.Time -// Duration int -// ChargingRateUnit ChargingRateUnitEnumType -// MinChargingRate float64 -// ChargingSchedulePeriod ChargingSchedulePeriodType -// SalesTariff SalesTariffType -// } - -// type ChargingRateUnitEnumType string - -// const ( -// W ChargingRateUnitEnumType = "W" -// a ChargingRateUnitEnumType = "A" -// ) - -// type ChargingSchedulePeriodType struct { -// StartPeriod int -// Limit float64 -// NumberPhases int -// PhaseToUse int -// } - -// type SalesTariffType struct { -// Id int -// SalesTariffDescription string -// NumEPriceLevels int -// SalesTariffEntry SalesTariffEntryType -// } - -// type SalesTariffEntryType struct { -// EPriceLevel int -// RelativeTimeInterval RelativeTimeIntervalType -// ConsumptionCost ConsumptionCostType -// } - -// type RelativeTimeIntervalType struct { -// Start int -// Duration int -// } - -// type ConsumptionCostType struct { -// StartValue float64 -// Cost CostType -// } - -// type CostType struct { -// CostKind CostKindEnumType -// Amount int -// AmountMultiplier int -// } - -// type CostKindEnumType string - -// const ( -// CarbonDioxideEmission CostKindEnumType = "CarbonDioxideEmission" -// RelativePricePercentage CostKindEnumType = "RelativePricePercentage" -// RenewableGenerationPercentage CostKindEnumType = "RenewableGenerationPercentage" -// ) - - - // TokenCacheMode Indicates what type of token caching is allowed type TokenCacheMode string diff --git a/manager/handlers/ocpp201/trigger_message_result.go b/manager/handlers/ocpp201/trigger_message_result.go index a547c7f..ab9bcfa 100644 --- a/manager/handlers/ocpp201/trigger_message_result.go +++ b/manager/handlers/ocpp201/trigger_message_result.go @@ -4,12 +4,12 @@ package ocpp201 import ( "context" + "github.com/thoughtworks/maeve-csms/manager/ocpp" "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "github.com/thoughtworks/maeve-csms/manager/store" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" - "golang.org/x/exp/slog" ) type TriggerMessageResultHandler struct { @@ -19,8 +19,6 @@ type TriggerMessageResultHandler struct { func (i TriggerMessageResultHandler) HandleCallResult(ctx context.Context, chargeStationId string, request ocpp.Request, response ocpp.Response, state any) error { req := request.(*ocpp201.TriggerMessageRequestJson) - slog.Info("[TEST] we are in HandleCallResult() in trigger_message_result.go") - status := ocpp201.TriggerMessageStatusEnumTypeNotImplemented span := trace.SpanFromContext(ctx) @@ -42,10 +40,8 @@ func (i TriggerMessageResultHandler) HandleCallResult(ctx context.Context, charg } if status == ocpp201.TriggerMessageStatusEnumTypeAccepted { - slog.Info("[TEST] we are in HandleCallResult() in trigger_message_result.go 111111111") return i.Store.DeleteChargeStationTriggerMessage(ctx, chargeStationId) } else { - slog.Info("[TEST] we are in HandleCallResult() in trigger_message_result.go 2222222222") err := i.Store.SetChargeStationTriggerMessage(ctx, chargeStationId, &store.ChargeStationTriggerMessage{ TriggerMessage: store.TriggerMessage(req.RequestedMessage), TriggerStatus: store.TriggerStatus(status), diff --git a/manager/handlers/router.go b/manager/handlers/router.go index 8f99665..edad945 100644 --- a/manager/handlers/router.go +++ b/manager/handlers/router.go @@ -31,7 +31,6 @@ func (r Router) Handle(ctx context.Context, chargeStationId string, msg *transpo err := r.route(ctx, chargeStationId, msg) - // ^^^ r.route goes into the transport.MessageTypeCallError switch statement, returns error b/c EVerest returns not implemented // TODO: Handle setChargingProfile response here if we want to do more on CSMS side! if err != nil { diff --git a/manager/sync/triggers.go b/manager/sync/triggers.go index 1f223dc..d799786 100644 --- a/manager/sync/triggers.go +++ b/manager/sync/triggers.go @@ -5,6 +5,8 @@ package sync import ( "context" "fmt" + "time" + "github.com/thoughtworks/maeve-csms/manager/handlers" "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp16" "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" @@ -13,7 +15,6 @@ import ( "go.opentelemetry.io/otel/trace" "golang.org/x/exp/slog" "k8s.io/utils/clock" - "time" ) func SyncTriggers(ctx context.Context, @@ -33,12 +34,11 @@ func SyncTriggers(ctx context.Context, return case <-time.After(runEvery): func() { - slog.Info("[TEST] we are in SyncTriggers() in triggers.go 1") ctx, span := tracer.Start(ctx, "sync triggers", trace.WithSpanKind(trace.SpanKindInternal), trace.WithAttributes(attribute.String("sync.trigger.previous", previousChargeStationId))) defer span.End() triggerMessages, err := engine.ListChargeStationTriggerMessages(ctx, 50, previousChargeStationId) - slog.Info("[TEST] we are in SyncTriggers() in triggers.go 2", "triggerMessages", triggerMessages) + slog.Info("[TEST] we are in SyncTriggers() in triggers.go", "triggerMessages", triggerMessages) if err != nil { span.RecordError(err) return @@ -49,11 +49,8 @@ func SyncTriggers(ctx context.Context, previousChargeStationId = "" } span.SetAttributes(attribute.Int("sync.trigger.count", len(triggerMessages))) - slog.Info("[TEST] we are in SyncTriggers() in triggers.go 3") for _, pendingTriggerMessage := range triggerMessages { func() { - slog.Info("[TEST] we are in SyncTriggers() in triggers.go4") - slog.Info("[TEST] pendingTriggerMessage", pendingTriggerMessage) ctx, span := tracer.Start(ctx, "sync trigger", trace.WithSpanKind(trace.SpanKindInternal), trace.WithAttributes( attribute.String("chargeStationId", pendingTriggerMessage.ChargeStationId), diff --git a/manager/transport/mqtt/listener.go b/manager/transport/mqtt/listener.go index 0421400..e256483 100644 --- a/manager/transport/mqtt/listener.go +++ b/manager/transport/mqtt/listener.go @@ -5,6 +5,11 @@ import ( "encoding/json" "errors" "fmt" + "math/rand" + "net/url" + "strings" + "time" + "github.com/eclipse/paho.golang/autopaho" "github.com/eclipse/paho.golang/paho" "github.com/thoughtworks/maeve-csms/manager/transport" @@ -16,10 +21,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace/noop" "golang.org/x/exp/slog" - "math/rand" - "net/url" - "strings" - "time" ) type Listener struct { @@ -139,8 +140,6 @@ func (l *Listener) Connect(ctx context.Context, ocppVersion transport.OcppVersio return } - slog.Info("[TEST] In listener.go", "action", msg.Action) - // add additional span attributes version, _ := strings.CutPrefix(string(ocppVersion), "ocpp") span.SetAttributes( From c053e519f75ceb14fb053600c9faad726fd9dc10 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Tue, 18 Jun 2024 13:15:18 -0400 Subject: [PATCH 23/25] Updated API.md with setChargingProfile documentation --- manager/api/API.md | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/manager/api/API.md b/manager/api/API.md index f246093..e050f12 100644 --- a/manager/api/API.md +++ b/manager/api/API.md @@ -271,6 +271,49 @@ This operation does not require authentication This operation does not require authentication +## setChargingProfile + + + +`POST /cs/{csId}/setchargingprofile` + +> Body parameter + +```json +{ + "" +} +``` + +

Parameters

+ +|Name|In|Type|Required|Description| +|---|---|---|---|---| +|csId|path|string|true|The charge station identifier| +|body|body|[ChargineProfileType](#schemaChargingProfileType)|true|none| + +> Example responses + +> default Response + +```json +{ + "status": "string", + "error": "string" +} +``` + +

Responses

+ +|Status|Meaning|Description|Schema| +|---|---|---|---| +|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|OK|None| +|default|Default|Unexpected error|[Status](#schemastatus)| + + + ## setToken @@ -838,6 +881,46 @@ Trigger a charge station action |trigger|SignChargingStationCertificate| |trigger|SignCombinedCertificate| +

ChargingProfileType

+ + + + + + +```json + +{ + "id": int, + "stackLevel": int, + "chargingProfilePurpose": "ChargingProfilePurposeEnumType", + "chargingProfileKind": "ChargingProfileKindEnumType", + "recurrencyKind": "RecurrencyKindEnumType", + "validFrom": "dateTime", + "validTo": "dateTime", + "transactionId": "identifierString[0..36]", + "chargingSchedule": "ChargingScheduleType" +} + +``` + +Send charging profile to charging station + +### Properties ### +See OCPP 2.0.1 Specification for ChargingProfileType + +|Name|Type|Required|Restrictions|Description| +|---|---|---|---|---| +|id|int|true|none|none| +|stackLevel|int|true|none|none| +|chargingProfilePurpose|ChargingProfilePurposeEnumType|true|none|none| +|chargingProfileKind|ChargingProfileKindEnumType|true|none|none| +|recurrencyKind|RecurrencyKindEnumType|false|none|none| +|validFrom|dateTime|false|none|none| +|validTo|dateTime|false|none|none| +|transactionId|identifierString[0..36]|false|none|none| +|chargingSchedule|ChargingScheduleType|true|none|none| +

Token

From 9d9a3fcec1329b87a2391b8313bafc3fa68597f9 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Thu, 20 Jun 2024 14:05:11 -0400 Subject: [PATCH 24/25] Changes logs from info to debug, added API TRACE as the tag --- manager/api/api.gen.go | 2 +- manager/api/server.go | 6 +++--- manager/handlers/call_maker.go | 7 +------ manager/handlers/ocpp201/set_charging_profile_result.go | 2 +- manager/handlers/router.go | 6 +++--- manager/sync/triggers.go | 2 +- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/manager/api/api.gen.go b/manager/api/api.gen.go index d9ffcb7..f65beea 100644 --- a/manager/api/api.gen.go +++ b/manager/api/api.gen.go @@ -594,7 +594,7 @@ func (siw *ServerInterfaceWrapper) TriggerChargeStation(w http.ResponseWriter, r // SetChargingProfile operation middleware func (siw *ServerInterfaceWrapper) SetChargingProfile(w http.ResponseWriter, r *http.Request) { - slog.Info("[TEST] in charging middleware!") + slog.Debug("[API TRACE] in charging middleware!") ctx := r.Context() var err error diff --git a/manager/api/server.go b/manager/api/server.go index eafd524..3780382 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -154,7 +154,7 @@ func (s *Server) LookupChargeStationAuth(w http.ResponseWriter, r *http.Request, } func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, csId string) { - slog.Info("[TEST] in TriggerChargeStation!") + slog.Debug("[API TRACE] in TriggerChargeStation!") req := new(ChargeStationTrigger) if err := render.Bind(r, req); err != nil { _ = render.Render(w, r, ErrInvalidRequest(err)) @@ -174,7 +174,7 @@ func (s *Server) TriggerChargeStation(w http.ResponseWriter, r *http.Request, cs } func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId string) { - slog.Info("[TEST] In server.go, SetChargingProfile()") + slog.Debug("[API TRACE] In server.go, SetChargingProfile()") req := new(ChargingProfileType) if err := render.Bind(r, req); err != nil { @@ -182,7 +182,7 @@ func (s *Server) SetChargingProfile(w http.ResponseWriter, r *http.Request, csId return } - slog.Info("[TEST] req:", req) + slog.Debug("[API TRACE] req:", req) // Get the transport.Emitter so that we can send messages cfg := config.DefaultConfig diff --git a/manager/handlers/call_maker.go b/manager/handlers/call_maker.go index 79d8b99..39304d9 100644 --- a/manager/handlers/call_maker.go +++ b/manager/handlers/call_maker.go @@ -20,14 +20,9 @@ type OcppCallMaker struct { Actions map[reflect.Type]string // the OCPP Action associated with a specific ocpp.Request object } -type SetChargingProfileRequestJsonFix struct { - evseId int - chargingProfile interface{} -} - func (b OcppCallMaker) Send(ctx context.Context, chargeStationId string, request ocpp.Request) error { action, ok := b.Actions[reflect.TypeOf(request)] - slog.Info("[TEST] we are in Send() in call_maker.go", "action", action) + slog.Debug("[API TRACE] we are in Send() in call_maker.go", "action", action) if !ok { slog.Error("unknown request type", request) return nil diff --git a/manager/handlers/ocpp201/set_charging_profile_result.go b/manager/handlers/ocpp201/set_charging_profile_result.go index 73e109f..9651ef8 100644 --- a/manager/handlers/ocpp201/set_charging_profile_result.go +++ b/manager/handlers/ocpp201/set_charging_profile_result.go @@ -16,7 +16,7 @@ func (h SetChargingProfileResultHandler) HandleCallResult(ctx context.Context, c req := request.(*types.SetChargingProfileRequestJson) resp := response.(*types.SetChargingProfileResponseJson) - slog.Info("[TEST] in scp_result.go, got response:", resp, "[TEST] From request:", req) + slog.Debug("[API TRACE] in scp_result.go, got response:", resp, "[API TRACE] From request:", req) return nil } diff --git a/manager/handlers/router.go b/manager/handlers/router.go index edad945..92b835b 100644 --- a/manager/handlers/router.go +++ b/manager/handlers/router.go @@ -58,11 +58,11 @@ func (r Router) Handle(ctx context.Context, chargeStationId string, msg *transpo } func (r Router) route(ctx context.Context, chargeStationId string, message *transport.Message) error { - slog.Info("[TEST] we are in route() in router.go", "action", message.Action) + slog.Debug("[API TRACE] we are in route() in router.go", "action", message.Action) switch message.MessageType { case transport.MessageTypeCall: route, ok := r.CallRoutes[message.Action] - slog.Info("[TEST] we are in route() in router.go, in MessageTypeCall", "route", route) + slog.Debug("[API TRACE] we are in route() in router.go, in MessageTypeCall", "route", route) if !ok { return fmt.Errorf("routing request: %w", transport.NewError(transport.ErrorNotImplemented, fmt.Errorf("%s not implemented", message.Action))) } @@ -107,7 +107,7 @@ func (r Router) route(ctx context.Context, chargeStationId string, message *tran } case transport.MessageTypeCallResult: route, ok := r.CallResultRoutes[message.Action] - slog.Info("[TEST] we are in route() in router.go, in MessageTypeCallResult", "route", route) + slog.Debug("[API TRACE] we are in route() in router.go, in MessageTypeCallResult", "route", route) if !ok { return fmt.Errorf("routing request: %w", transport.NewError(transport.ErrorNotImplemented, fmt.Errorf("%s result not implemented", message.Action))) } diff --git a/manager/sync/triggers.go b/manager/sync/triggers.go index d799786..fe67699 100644 --- a/manager/sync/triggers.go +++ b/manager/sync/triggers.go @@ -38,7 +38,7 @@ func SyncTriggers(ctx context.Context, trace.WithAttributes(attribute.String("sync.trigger.previous", previousChargeStationId))) defer span.End() triggerMessages, err := engine.ListChargeStationTriggerMessages(ctx, 50, previousChargeStationId) - slog.Info("[TEST] we are in SyncTriggers() in triggers.go", "triggerMessages", triggerMessages) + slog.Debug("[API TRACE] we are in SyncTriggers() in triggers.go", "triggerMessages", triggerMessages) if err != nil { span.RecordError(err) return From 8b42be91a7377acc2dceab83963b3522f4a40648 Mon Sep 17 00:00:00 2001 From: louisg1337 Date: Thu, 20 Jun 2024 14:35:42 -0400 Subject: [PATCH 25/25] Reverted changes linter made to packages --- manager/api/render.go | 4 +--- manager/api/server.go | 10 ++++------ manager/handlers/call_maker.go | 3 +-- .../ocpp201/request_start_transaction_result.go | 1 - manager/handlers/ocpp201/routing.go | 7 +++---- .../handlers/ocpp201/set_charging_profile_result.go | 1 - manager/handlers/ocpp201/trigger_message_result.go | 1 - manager/handlers/router.go | 3 +-- manager/sync/triggers.go | 3 +-- manager/transport/mqtt/listener.go | 9 ++++----- 10 files changed, 15 insertions(+), 27 deletions(-) diff --git a/manager/api/render.go b/manager/api/render.go index e1c064b..5481b5c 100644 --- a/manager/api/render.go +++ b/manager/api/render.go @@ -2,9 +2,7 @@ package api -import ( - "net/http" -) +import "net/http" func (c ChargeStationAuth) Bind(r *http.Request) error { return nil diff --git a/manager/api/server.go b/manager/api/server.go index 3780382..fe55641 100644 --- a/manager/api/server.go +++ b/manager/api/server.go @@ -3,20 +3,18 @@ package api import ( - "context" "fmt" - "net/http" - "time" - - "github.com/thoughtworks/maeve-csms/manager/config" handlers "github.com/thoughtworks/maeve-csms/manager/handlers/ocpp201" "github.com/thoughtworks/maeve-csms/manager/ocpi" - + "net/http" + "time" + "context" "github.com/getkin/kin-openapi/openapi3" "github.com/go-chi/render" "github.com/thoughtworks/maeve-csms/manager/ocpp" "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "github.com/thoughtworks/maeve-csms/manager/store" + "github.com/thoughtworks/maeve-csms/manager/config" "golang.org/x/exp/slog" "k8s.io/utils/clock" ) diff --git a/manager/handlers/call_maker.go b/manager/handlers/call_maker.go index 39304d9..de70bcf 100644 --- a/manager/handlers/call_maker.go +++ b/manager/handlers/call_maker.go @@ -5,12 +5,11 @@ package handlers import ( "context" "encoding/json" - "reflect" - "github.com/google/uuid" "github.com/thoughtworks/maeve-csms/manager/ocpp" "github.com/thoughtworks/maeve-csms/manager/transport" "golang.org/x/exp/slog" + "reflect" ) // OcppCallMaker is an implementation of the CallMaker interface for a specific set of OCPP messages. diff --git a/manager/handlers/ocpp201/request_start_transaction_result.go b/manager/handlers/ocpp201/request_start_transaction_result.go index a3c90a2..2f2b388 100644 --- a/manager/handlers/ocpp201/request_start_transaction_result.go +++ b/manager/handlers/ocpp201/request_start_transaction_result.go @@ -4,7 +4,6 @@ package ocpp201 import ( "context" - "github.com/thoughtworks/maeve-csms/manager/ocpp" types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "go.opentelemetry.io/otel/attribute" diff --git a/manager/handlers/ocpp201/routing.go b/manager/handlers/ocpp201/routing.go index 868c1fe..06b0d2f 100644 --- a/manager/handlers/ocpp201/routing.go +++ b/manager/handlers/ocpp201/routing.go @@ -3,17 +3,16 @@ package ocpp201 import ( - "io/fs" - "reflect" - "time" - "github.com/thoughtworks/maeve-csms/manager/handlers" "github.com/thoughtworks/maeve-csms/manager/ocpp" "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "github.com/thoughtworks/maeve-csms/manager/services" "github.com/thoughtworks/maeve-csms/manager/store" "github.com/thoughtworks/maeve-csms/manager/transport" + "io/fs" "k8s.io/utils/clock" + "reflect" + "time" ) func NewRouter(emitter transport.Emitter, diff --git a/manager/handlers/ocpp201/set_charging_profile_result.go b/manager/handlers/ocpp201/set_charging_profile_result.go index 9651ef8..bb17b18 100644 --- a/manager/handlers/ocpp201/set_charging_profile_result.go +++ b/manager/handlers/ocpp201/set_charging_profile_result.go @@ -4,7 +4,6 @@ package ocpp201 import ( "context" - "github.com/thoughtworks/maeve-csms/manager/ocpp" types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "golang.org/x/exp/slog" diff --git a/manager/handlers/ocpp201/trigger_message_result.go b/manager/handlers/ocpp201/trigger_message_result.go index ab9bcfa..8c34057 100644 --- a/manager/handlers/ocpp201/trigger_message_result.go +++ b/manager/handlers/ocpp201/trigger_message_result.go @@ -4,7 +4,6 @@ package ocpp201 import ( "context" - "github.com/thoughtworks/maeve-csms/manager/ocpp" "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" "github.com/thoughtworks/maeve-csms/manager/store" diff --git a/manager/handlers/router.go b/manager/handlers/router.go index 92b835b..50e23b9 100644 --- a/manager/handlers/router.go +++ b/manager/handlers/router.go @@ -7,14 +7,13 @@ import ( "encoding/json" "errors" "fmt" - "io/fs" - "github.com/santhosh-tekuri/jsonschema" "github.com/thoughtworks/maeve-csms/manager/schemas" "github.com/thoughtworks/maeve-csms/manager/transport" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/trace" "golang.org/x/exp/slog" + "io/fs" ) // Router is the primary implementation of the transport.Router interface. diff --git a/manager/sync/triggers.go b/manager/sync/triggers.go index fe67699..64f5514 100644 --- a/manager/sync/triggers.go +++ b/manager/sync/triggers.go @@ -5,8 +5,6 @@ package sync import ( "context" "fmt" - "time" - "github.com/thoughtworks/maeve-csms/manager/handlers" "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp16" "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201" @@ -15,6 +13,7 @@ import ( "go.opentelemetry.io/otel/trace" "golang.org/x/exp/slog" "k8s.io/utils/clock" + "time" ) func SyncTriggers(ctx context.Context, diff --git a/manager/transport/mqtt/listener.go b/manager/transport/mqtt/listener.go index e256483..8b1e099 100644 --- a/manager/transport/mqtt/listener.go +++ b/manager/transport/mqtt/listener.go @@ -5,11 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "math/rand" - "net/url" - "strings" - "time" - "github.com/eclipse/paho.golang/autopaho" "github.com/eclipse/paho.golang/paho" "github.com/thoughtworks/maeve-csms/manager/transport" @@ -21,6 +16,10 @@ import ( "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace/noop" "golang.org/x/exp/slog" + "math/rand" + "net/url" + "strings" + "time" ) type Listener struct {