Skip to content

Commit

Permalink
Revert "segregate primary and submap state in getall (#351)" (#376)
Browse files Browse the repository at this point in the history
This reverts commit 8ab3bf3.

The reefer application depends on the previous structure of actor
state, where the primary and submap state was not strictly segregated.

Signed-off-by: David Grove <groved@us.ibm.com>
  • Loading branch information
dgrove-oss committed May 5, 2023
1 parent 117b6b9 commit c87a479
Showing 1 changed file with 69 additions and 65 deletions.
134 changes: 69 additions & 65 deletions core/internal/runtime/routes-state.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ func nestedEntryKeyPrefix(key string) string {
// Check to see if the state of the actor instance indicated by `actorType` and `actorId`
// contains an entry for `key`/`subkey`.
//
// Consumes:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateExistsResult
// 404: response404
// 500: response500
// Consumes:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateExistsResult
// 404: response404
// 500: response500
//
func routeImplContainsKey(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var mangledEntryKey string
if subkey := ps.ByName("subkey"); subkey != "" {
Expand Down Expand Up @@ -133,15 +134,16 @@ func routeImplContainsKey(w http.ResponseWriter, r *http.Request, ps httprouter.
// The operation will not return until the state has been updated.
// The result of the operation is `1` if a new entry was created and `0` if an existing entry was updated.
//
// Consumes:
// - application/json
// Produces:
// - text/plain
// Schemes: http
// Responses:
// 201: response201
// 204: response204
// 500: response500
// Consumes:
// - application/json
// Produces:
// - text/plain
// Schemes: http
// Responses:
// 201: response201
// 204: response204
// 500: response500
//
func routeImplSet(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var mangledEntryKey string
if subkey := ps.ByName("subkey"); subkey != "" {
Expand Down Expand Up @@ -198,13 +200,14 @@ func routeImplSet(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
// unless the boolean query parameter `nilOnAbsent` is set to `true`,
// in which case a `200` reponse with a `nil` response body will be returned.
//
// Produces:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateGetResult
// 404: response404
// 500: response500
// Produces:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateGetResult
// 404: response404
// 500: response500
//
func routeImplGet(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var mangledEntryKey string
if subkey := ps.ByName("subkey"); subkey != "" {
Expand Down Expand Up @@ -247,15 +250,16 @@ func routeImplGet(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
// <li>size: return the number of entries the key actor map</li>
// </ul>
//
// Consumes:
// - application/json
// Produces:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateSubmapOps
// 404: response404
// 500: response500
// Consumes:
// - application/json
// Produces:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateSubmapOps
// 404: response404
// 500: response500
//
func routeImplSubmapOps(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var op submapOp
if err := json.Unmarshal([]byte(ReadAll(r)), &op); err != nil {
Expand Down Expand Up @@ -399,12 +403,13 @@ func subMapScan(stateKey string, mapName string, op func(key string, value strin
// The result of the operation is `1` if an entry was actually removed and
// `0` if there was no entry for `key`.
//
// Schemes: http
// Produces:
// - text/plain
// Responses:
// 200: response200StateDeleteResult
// 500: response500
// Schemes: http
// Produces:
// - text/plain
// Responses:
// 200: response200StateDeleteResult
// 500: response500
//
func routeImplDel(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var mangledEntryKey string
if subkey := ps.ByName("subkey"); subkey != "" {
Expand All @@ -428,12 +433,13 @@ func routeImplDel(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
// The state of the actor instance indicated by `actorType` and `actorId`
// will be returned as the response body.
//
// Produces:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateGetAllResult
// 500: response500
// Produces:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateGetAllResult
// 500: response500
//
func routeImplGetAll(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
state, err := actorGetAllState(ps.ByName("type"), ps.ByName("id"))
if err != nil {
Expand All @@ -453,7 +459,6 @@ func actorGetAllState(actorType string, actorID string) (map[string]interface{},
// reply has type map[string]string
// we unmarshal the values then marshal the map
m := map[string]interface{}{}
submaps := map[string]map[string]interface{}{}
for i, s := range reply {
var v interface{}
json.Unmarshal([]byte(s), &v)
Expand All @@ -463,15 +468,12 @@ func actorGetAllState(actorType string, actorID string) (map[string]interface{},
if subkey == config.Separator {
m[key] = v
} else {
if submaps[key] == nil {
submaps[key] = map[string]interface{}{}
if m[key] == nil {
m[key] = map[string]interface{}{}
}
submaps[key][subkey] = v
(m[key].(map[string]interface{}))[subkey] = v
}
}
if len(submaps) > 0 {
m["submaps"] = submaps
}
return m, nil
}

Expand All @@ -488,15 +490,16 @@ func actorGetAllState(actorType string, actorID string) (map[string]interface{},
// The result of the operation will contain the number of state elements
// removed and updated.
//
// Consumes:
// - application/json
// Produces:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateUpdate
// 404: response404
// 500: response500
// Consumes:
// - application/json
// Produces:
// - application/json
// Schemes: http
// Responses:
// 200: response200StateUpdate
// 404: response404
// 500: response500
//
func routeImplStateUpdate(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var op stateUpdateOp
var err error
Expand Down Expand Up @@ -578,11 +581,12 @@ func routeImplStateUpdate(w http.ResponseWriter, r *http.Request, ps httprouter.
// The state of the actor instance indicated by `actorType` and `actorId`
// will be deleted.
//
// Schemes: http
// Responses:
// 200: response200StateDeleteResult
// 404: response404
// 500: response500
// Schemes: http
// Responses:
// 200: response200StateDeleteResult
// 404: response404
// 500: response500
//
func routeImplDelAll(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
if reply, err := store.Del(ctx, stateKey(ps.ByName("type"), ps.ByName("id"))); err == store.ErrNil {
http.Error(w, "Not Found", http.StatusNotFound)
Expand Down

0 comments on commit c87a479

Please sign in to comment.