1717package org .apache .solr .handler .admin ;
1818
1919import static org .apache .solr .common .params .CommonParams .NAME ;
20- import static org .apache .solr .handler .configsets .UploadConfigSetFileAPI .FILEPATH_PLACEHOLDER ;
2120
2221import java .lang .invoke .MethodHandles ;
2322import java .util .ArrayList ;
2423import java .util .Collection ;
2524import java .util .HashMap ;
2625import java .util .List ;
27- import java .util .Map ;
28- import org .apache .solr .api .AnnotatedApi ;
2926import org .apache .solr .api .Api ;
3027import org .apache .solr .api .JerseyResource ;
31- import org .apache .solr .api .PayloadObj ;
32- import org .apache .solr .client .solrj . request . beans . CreateConfigPayload ;
28+ import org .apache .solr .client . api .model . CloneConfigsetRequestBody ;
29+ import org .apache .solr .client .api . model . SolrJerseyResponse ;
3330import org .apache .solr .cloud .ConfigSetCmds ;
3431import org .apache .solr .common .SolrException ;
3532import org .apache .solr .common .SolrException .ErrorCode ;
3633import org .apache .solr .common .params .ConfigSetParams ;
3734import org .apache .solr .common .params .ConfigSetParams .ConfigSetAction ;
38- import org .apache .solr .common .params .DefaultSolrParams ;
39- import org .apache .solr .common .params .ModifiableSolrParams ;
4035import org .apache .solr .common .params .SolrParams ;
4136import org .apache .solr .core .CoreContainer ;
4237import org .apache .solr .handler .RequestHandlerBase ;
4338import org .apache .solr .handler .api .V2ApiUtils ;
44- import org .apache .solr .handler .configsets .CreateConfigSetAPI ;
45- import org .apache .solr .handler .configsets .DeleteConfigSetAPI ;
39+ import org .apache .solr .handler .configsets .CloneConfigSet ;
40+ import org .apache .solr .handler .configsets .ConfigSetAPIBase ;
41+ import org .apache .solr .handler .configsets .DeleteConfigSet ;
4642import org .apache .solr .handler .configsets .ListConfigSets ;
47- import org .apache .solr .handler .configsets .UploadConfigSetAPI ;
48- import org .apache .solr .handler .configsets .UploadConfigSetFileAPI ;
49- import org .apache .solr .request .DelegatingSolrQueryRequest ;
43+ import org .apache .solr .handler .configsets .UploadConfigSet ;
5044import org .apache .solr .request .SolrQueryRequest ;
5145import org .apache .solr .response .SolrQueryResponse ;
5246import org .apache .solr .security .AuthorizationContext ;
@@ -96,51 +90,30 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
9690
9791 switch (action ) {
9892 case DELETE :
99- final DeleteConfigSetAPI deleteConfigSetAPI = new DeleteConfigSetAPI (coreContainer );
100- final SolrQueryRequest v2DeleteReq =
101- new DelegatingSolrQueryRequest (req ) {
102- @ Override
103- public Map <String , String > getPathTemplateValues () {
104- return Map .of (
105- DeleteConfigSetAPI .CONFIGSET_NAME_PLACEHOLDER ,
106- req .getParams ().required ().get (NAME ));
107- }
108- };
109- deleteConfigSetAPI .deleteConfigSet (v2DeleteReq , rsp );
93+ final DeleteConfigSet deleteConfigSetAPI = new DeleteConfigSet (coreContainer , req , rsp );
94+ final var deleteResponse =
95+ deleteConfigSetAPI .deleteConfigSet (req .getParams ().required ().get (NAME ));
96+ V2ApiUtils .squashIntoSolrResponseWithoutHeader (rsp , deleteResponse );
11097 break ;
11198 case UPLOAD :
112- final SolrQueryRequest v2UploadReq =
113- new DelegatingSolrQueryRequest (req ) {
114- @ Override
115- public Map <String , String > getPathTemplateValues () {
116- final Map <String , String > templateValsByName = new HashMap <>();
117-
118- templateValsByName .put (
119- UploadConfigSetAPI .CONFIGSET_NAME_PLACEHOLDER ,
120- req .getParams ().required ().get (NAME ));
121- if (!req .getParams ().get (ConfigSetParams .FILE_PATH , "" ).isEmpty ()) {
122- templateValsByName .put (
123- FILEPATH_PLACEHOLDER , req .getParams ().get (ConfigSetParams .FILE_PATH ));
124- }
125- return templateValsByName ;
126- }
127-
128- // Set the v1 default vals where they differ from v2's
129- @ Override
130- public SolrParams getParams () {
131- final ModifiableSolrParams v1Defaults = new ModifiableSolrParams ();
132- v1Defaults .add (ConfigSetParams .OVERWRITE , "false" );
133- v1Defaults .add (ConfigSetParams .CLEANUP , "false" );
134- return new DefaultSolrParams (super .getParams (), v1Defaults );
135- }
136- };
99+ final var uploadApi = new UploadConfigSet (coreContainer , req , rsp );
100+ final var configSetName = req .getParams ().required ().get (NAME );
101+ final var overwrite = req .getParams ().getBool (ConfigSetParams .OVERWRITE , false );
102+ final var cleanup = req .getParams ().getBool (ConfigSetParams .CLEANUP , false );
103+ final var configSetData = ConfigSetAPIBase .ensureNonEmptyInputStream (req );
104+ SolrJerseyResponse uploadResponse ;
137105 if (req .getParams ()
138106 .get (ConfigSetParams .FILE_PATH , "" )
139107 .isEmpty ()) { // Uploading a whole configset
140- new UploadConfigSetAPI (coreContainer ).uploadConfigSet (v2UploadReq , rsp );
108+ uploadResponse =
109+ uploadApi .uploadConfigSet (configSetName , overwrite , cleanup , configSetData );
141110 } else { // Uploading a single file
142- new UploadConfigSetFileAPI (coreContainer ).updateConfigSetFile (v2UploadReq , rsp );
111+ final var filePath = req .getParams ().get (ConfigSetParams .FILE_PATH );
112+ uploadResponse =
113+ uploadApi .uploadConfigSetFile (
114+ configSetName , filePath , overwrite , cleanup , configSetData );
143115 }
116+ V2ApiUtils .squashIntoSolrResponseWithoutHeader (rsp , uploadResponse );
144117 break ;
145118 case LIST :
146119 final ListConfigSets listConfigSetsAPI = new ListConfigSets (coreContainer );
@@ -153,12 +126,14 @@ public SolrParams getParams() {
153126 }
154127
155128 // Map v1 parameters into v2 format and process request
156- final CreateConfigPayload createPayload = new CreateConfigPayload ();
157- createPayload .name = newConfigSetName ;
129+ final var requestBody = new CloneConfigsetRequestBody ();
130+ requestBody .name = newConfigSetName ;
158131 if (req .getParams ().get (ConfigSetCmds .BASE_CONFIGSET ) != null ) {
159- createPayload .baseConfigSet = req .getParams ().get (ConfigSetCmds .BASE_CONFIGSET );
132+ requestBody .baseConfigSet = req .getParams ().get (ConfigSetCmds .BASE_CONFIGSET );
133+ } else {
134+ requestBody .baseConfigSet = "_default" ;
160135 }
161- createPayload .properties = new HashMap <>();
136+ requestBody .properties = new HashMap <>();
162137 req .getParams ().stream ()
163138 .filter (entry -> entry .getKey ().startsWith (ConfigSetCmds .CONFIG_SET_PROPERTY_PREFIX ))
164139 .forEach (
@@ -167,10 +142,11 @@ public SolrParams getParams() {
167142 entry .getKey ().substring (ConfigSetCmds .CONFIG_SET_PROPERTY_PREFIX .length ());
168143 final Object value =
169144 (entry .getValue ().length == 1 ) ? entry .getValue ()[0 ] : entry .getValue ();
170- createPayload .properties .put (newKey , value );
145+ requestBody .properties .put (newKey , value );
171146 });
172- final CreateConfigSetAPI createConfigSetAPI = new CreateConfigSetAPI (coreContainer );
173- createConfigSetAPI .create (new PayloadObj <>("create" , null , createPayload , req , rsp ));
147+ final CloneConfigSet createConfigSetAPI = new CloneConfigSet (coreContainer , req , rsp );
148+ final var createResponse = createConfigSetAPI .cloneExistingConfigSet (requestBody );
149+ V2ApiUtils .squashIntoSolrResponseWithoutHeader (rsp , createResponse );
174150 break ;
175151 default :
176152 throw new IllegalStateException ("Unexpected ConfigSetAction detected: " + action );
@@ -207,18 +183,13 @@ public Boolean registerV2() {
207183
208184 @ Override
209185 public Collection <Api > getApis () {
210- final List <Api > apis = new ArrayList <>();
211- apis .addAll (AnnotatedApi .getApis (new CreateConfigSetAPI (coreContainer )));
212- apis .addAll (AnnotatedApi .getApis (new DeleteConfigSetAPI (coreContainer )));
213- apis .addAll (AnnotatedApi .getApis (new UploadConfigSetAPI (coreContainer )));
214- apis .addAll (AnnotatedApi .getApis (new UploadConfigSetFileAPI (coreContainer )));
215-
216- return apis ;
186+ return new ArrayList <>();
217187 }
218188
219189 @ Override
220190 public Collection <Class <? extends JerseyResource >> getJerseyResources () {
221- return List .of (ListConfigSets .class );
191+ return List .of (
192+ ListConfigSets .class , CloneConfigSet .class , DeleteConfigSet .class , UploadConfigSet .class );
222193 }
223194
224195 @ Override
0 commit comments