Skip to content

Commit a158e4c

Browse files
committed
[raft/scd] Add scd Raftstore opintents
1 parent ab29330 commit a158e4c

8 files changed

Lines changed: 1104 additions & 396 deletions

File tree

pkg/models/geo.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package models
22

33
import (
4+
"encoding/json"
5+
"fmt"
46
"time"
57

68
"github.com/golang/geo/s2"
@@ -72,6 +74,83 @@ type Volume3D struct {
7274
Footprint Geometry
7375
}
7476

77+
type Volume3DJSON struct {
78+
AltitudeHi *float32 `json:"AltitudeHi,omitempty"`
79+
AltitudeLo *float32 `json:"AltitudeLo,omitempty"`
80+
Footprint *geometryJSON `json:"Footprint,omitempty"`
81+
}
82+
83+
type geometryType string
84+
85+
const (
86+
circle geometryType = "circle"
87+
polygon geometryType = "polygon"
88+
cells geometryType = "cells"
89+
)
90+
91+
// geometryJSON is a helper struct for marshaling and unmarshaling Geometry types to/from JSON.
92+
type geometryJSON struct {
93+
Type geometryType `json:"type"`
94+
Polygon *GeoPolygon `json:"polygon,omitempty"`
95+
Circle *GeoCircle `json:"circle,omitempty"`
96+
Cells []s2.CellID `json:"cells,omitempty"`
97+
}
98+
99+
func (v Volume3D) MarshalJSON() ([]byte, error) {
100+
w := Volume3DJSON{AltitudeHi: v.AltitudeHi, AltitudeLo: v.AltitudeLo}
101+
if v.Footprint != nil {
102+
switch f := v.Footprint.(type) {
103+
case *GeoPolygon:
104+
w.Footprint = &geometryJSON{Type: polygon, Polygon: f}
105+
106+
case *GeoCircle:
107+
w.Footprint = &geometryJSON{Type: circle, Circle: f}
108+
109+
case precomputedCellGeometry:
110+
cellsResult := make([]s2.CellID, 0, len(f))
111+
for id := range f {
112+
cellsResult = append(cellsResult, id)
113+
}
114+
w.Footprint = &geometryJSON{Type: cells, Cells: cellsResult}
115+
116+
default:
117+
return nil, fmt.Errorf("Volume3D: unsupported Footprint type %T for JSON marshaling", v.Footprint)
118+
}
119+
}
120+
121+
return json.Marshal(w)
122+
}
123+
124+
func (v *Volume3D) UnmarshalJSON(data []byte) error {
125+
var w Volume3DJSON
126+
if err := json.Unmarshal(data, &w); err != nil {
127+
return err
128+
}
129+
v.AltitudeHi = w.AltitudeHi
130+
v.AltitudeLo = w.AltitudeLo
131+
if w.Footprint != nil {
132+
switch w.Footprint.Type {
133+
case polygon:
134+
v.Footprint = w.Footprint.Polygon
135+
136+
case circle:
137+
v.Footprint = w.Footprint.Circle
138+
139+
case cells:
140+
pcg := make(precomputedCellGeometry, len(w.Footprint.Cells))
141+
for _, id := range w.Footprint.Cells {
142+
pcg[id] = struct{}{}
143+
}
144+
145+
v.Footprint = pcg
146+
default:
147+
return fmt.Errorf("Volume3D: unknown geometry type %q", w.Footprint.Type)
148+
}
149+
}
150+
151+
return nil
152+
}
153+
75154
// Geometry models a geometry.
76155
type Geometry interface {
77156
// CalculateCovering returns an s2 cell covering for a geometry.

pkg/scd/constraints_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (a *Server) DeleteConstraintReference(ctx context.Context, req *restapi.Del
8282
// Return response to client
8383
response = &restapi.ChangeConstraintReferenceResponse{
8484
ConstraintReference: *old.ToRest(),
85-
Subscribers: makeSubscribersToNotify(subs),
85+
Subscribers: repos.MakeSubscribersToNotify(subs),
8686
}
8787

8888
return nil
@@ -300,7 +300,7 @@ func (a *Server) PutConstraintReference(ctx context.Context, manager string, ent
300300
// Return response to client
301301
response = &restapi.ChangeConstraintReferenceResponse{
302302
ConstraintReference: *constraint.ToRest(),
303-
Subscribers: makeSubscribersToNotify(subs),
303+
Subscribers: repos.MakeSubscribersToNotify(subs),
304304
}
305305

306306
return nil

0 commit comments

Comments
 (0)