MCPcopy Create free account
hub / github.com/apache/solr / runImpl

Method runImpl

solr/core/src/java/org/apache/solr/cli/ConfigTool.java:95–139  ·  view source on GitHub ↗
(CommandLine cli)

Source from the content-addressed store, hash-verified

93 }
94
95 @Override
96 public void runImpl(CommandLine cli) throws Exception {
97 String solrUrl = CLIUtils.normalizeSolrUrl(cli);
98 String action = cli.getOptionValue(ACTION_OPTION, "set-property");
99 String collection = cli.getOptionValue(COLLECTION_NAME_OPTION);
100 String property = cli.getOptionValue(PROPERTY_OPTION);
101 String value = cli.getOptionValue(VALUE_OPTION);
102
103 // value is required unless the property is one of the "unset-" type.
104 if (!action.contains("unset-") && value == null) {
105 throw new MissingArgumentException("'value' is a required option.");
106 }
107 Map<String, Object> jsonObj = new HashMap<>();
108 if (value != null) {
109 Map<String, String> setMap = new HashMap<>();
110 setMap.put(property, value);
111 jsonObj.put(action, setMap);
112 } else {
113 jsonObj.put(action, property);
114 }
115
116 CharArr arr = new CharArr();
117 (new JSONWriter(arr, 0)).write(jsonObj);
118 String jsonBody = arr.toString();
119
120 String updatePath = "/" + collection + "/config";
121
122 echo("\nPOSTing request to Config API: " + solrUrl + updatePath);
123 echoIfVerbose(jsonBody);
124
125 try (SolrClient solrClient =
126 CLIUtils.getSolrClient(solrUrl, cli.getOptionValue(CommonCLIOptions.CREDENTIALS_OPTION))) {
127 NamedList<Object> result = SolrCLI.postJsonToSolr(solrClient, updatePath, jsonBody);
128 Integer statusCode = (Integer) result._get(List.of("responseHeader", "status"), null);
129 if (statusCode == 0) {
130 if (value != null) {
131 echo("Successfully " + action + " " + property + " to " + value);
132 } else {
133 echo("Successfully " + action + " " + property);
134 }
135 } else {
136 throw new Exception("Failed to " + action + " property due to:\n" + result);
137 }
138 }
139 }
140}

Callers

nothing calls this directly

Calls 11

normalizeSolrUrlMethod · 0.95
toStringMethod · 0.95
getSolrClientMethod · 0.95
postJsonToSolrMethod · 0.95
echoMethod · 0.80
echoIfVerboseMethod · 0.80
putMethod · 0.65
writeMethod · 0.65
_getMethod · 0.65
containsMethod · 0.45
ofMethod · 0.45

Tested by

no test coverage detected