@@ -16,147 +16,3 @@ pub mod cas_server;
1616pub mod schedulers;
1717pub mod serde_utils;
1818pub mod stores;
19-
20- use std:: any:: type_name;
21- use std:: collections:: HashMap ;
22- use std:: fmt;
23- use std:: marker:: PhantomData ;
24-
25- use serde:: de:: { MapAccess , SeqAccess , Visitor } ;
26- use serde:: { Deserialize , Deserializer } ;
27-
28- #[ derive( Debug , Clone , Deserialize ) ]
29- pub struct NamedConfig < Spec > {
30- pub name : String ,
31- #[ serde( flatten) ]
32- pub spec : Spec ,
33- }
34-
35- pub type StoreConfig = NamedConfig < stores:: StoreSpec > ;
36- pub type SchedulerConfig = NamedConfig < schedulers:: SchedulerSpec > ;
37-
38- // TODO(aaronmondal): Remove all the iterator impls and the Deserializer once we
39- // fully migrate to the new config schema.
40- pub type StoreConfigs = NamedConfigs < stores:: StoreSpec > ;
41- pub type SchedulerConfigs = NamedConfigs < schedulers:: SchedulerSpec > ;
42-
43- #[ derive( Debug ) ]
44- pub struct NamedConfigs < T > ( pub Vec < NamedConfig < T > > ) ;
45-
46- impl < T > NamedConfigs < T > {
47- pub fn iter ( & self ) -> std:: slice:: Iter < ' _ , NamedConfig < T > > {
48- self . 0 . iter ( )
49- }
50- }
51-
52- impl < T > IntoIterator for NamedConfigs < T > {
53- type Item = NamedConfig < T > ;
54- type IntoIter = std:: vec:: IntoIter < Self :: Item > ;
55-
56- fn into_iter ( self ) -> Self :: IntoIter {
57- self . 0 . into_iter ( )
58- }
59- }
60-
61- impl < ' a , T > IntoIterator for & ' a NamedConfigs < T > {
62- type Item = & ' a NamedConfig < T > ;
63- type IntoIter = std:: slice:: Iter < ' a , NamedConfig < T > > ;
64-
65- fn into_iter ( self ) -> Self :: IntoIter {
66- self . 0 . iter ( )
67- }
68- }
69-
70- struct NamedConfigsVisitor < T > {
71- phantom : PhantomData < T > ,
72- }
73-
74- impl < T > NamedConfigsVisitor < T > {
75- const fn new ( ) -> Self {
76- NamedConfigsVisitor {
77- phantom : PhantomData ,
78- }
79- }
80- }
81-
82- impl < ' de , T : Deserialize < ' de > > Visitor < ' de > for NamedConfigsVisitor < T > {
83- type Value = NamedConfigs < T > ;
84-
85- fn expecting ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
86- formatter. write_str ( "a sequence or map of named configs" )
87- }
88-
89- fn visit_seq < A > ( self , mut seq : A ) -> Result < Self :: Value , A :: Error >
90- where
91- A : SeqAccess < ' de > ,
92- {
93- let mut vec = Vec :: new ( ) ;
94- while let Some ( config) = seq. next_element ( ) ? {
95- vec. push ( config) ;
96- }
97- Ok ( NamedConfigs ( vec) )
98- }
99-
100- fn visit_map < M > ( self , mut access : M ) -> Result < Self :: Value , M :: Error >
101- where
102- M : MapAccess < ' de > ,
103- {
104- let config_type = if type_name :: < T > ( ) . contains ( "StoreSpec" ) {
105- "stores"
106- } else if type_name :: < T > ( ) . contains ( "SchedulerSpec" ) {
107- "schedulers"
108- } else {
109- "stores and schedulers"
110- } ;
111- eprintln ! (
112- r#"
113- WARNING: Using deprecated map format for {config_type}. Please migrate to the new array format:
114-
115- // Old:
116- "stores": {{
117- "SOMESTORE": {{
118- "memory": {{}}
119- }}
120- }},
121- "schedulers": {{
122- "SOMESCHEDULER": {{
123- "simple": {{}}
124- }}
125- }}
126-
127- // New:
128- "stores": [
129- {{
130- "name": "SOMESTORE",
131- "memory": {{}}
132- }}
133- ],
134- "schedulers": [
135- {{
136- "name": "SOMESCHEDULER",
137- "simple": {{}}
138- }}
139- ]
140- "#
141- ) ;
142-
143- let mut map = HashMap :: new ( ) ;
144- while let Some ( ( key, value) ) = access. next_entry ( ) ? {
145- map. insert ( key, value) ;
146- }
147- Ok ( NamedConfigs (
148- map. into_iter ( )
149- . map ( |( name, spec) | NamedConfig { name, spec } )
150- . collect ( ) ,
151- ) )
152- }
153- }
154-
155- impl < ' de , T : Deserialize < ' de > > Deserialize < ' de > for NamedConfigs < T > {
156- fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
157- where
158- D : Deserializer < ' de > ,
159- {
160- deserializer. deserialize_any ( NamedConfigsVisitor :: new ( ) )
161- }
162- }
0 commit comments