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

Method runImpl

solr/core/src/java/org/apache/solr/cli/PackageTool.java:108–293  ·  view source on GitHub ↗
(CommandLine cli)

Source from the content-addressed store, hash-verified

106 public RepositoryManager repositoryManager;
107
108 @Override
109 @SuppressForbidden(
110 reason =
111 "We really need to print the stacktrace here, otherwise "
112 + "there shall be little else information to debug problems. Other SolrCLI tools "
113 + "don't print stack traces, hence special treatment is needed here."
114 + "Need to turn off logging, and SLF4J doesn't seem to provide for a way.")
115 public void runImpl(CommandLine cli) throws Exception {
116
117 // Need a logging free, clean output going through to the user.
118 Level oldLevel = LoggerContext.getContext(false).getRootLogger().getLevel();
119 Configurator.setRootLevel(Level.OFF);
120
121 try {
122 String solrUrl = CLIUtils.normalizeSolrUrl(cli);
123 String zkHost = CLIUtils.getZkHost(cli);
124 if (zkHost == null) {
125 throw new SolrException(ErrorCode.INVALID_STATE, "Package manager runs only in SolrCloud");
126 }
127
128 log.info("ZK: {}", zkHost);
129
130 String cmd = cli.getArgs()[0];
131
132 try (SolrClient solrClient = CLIUtils.getSolrClient(cli, true)) {
133 packageManager = new PackageManager(runtime, solrClient, solrUrl, zkHost);
134 try {
135 repositoryManager = new RepositoryManager(solrClient, packageManager);
136
137 switch (cmd) {
138 case "add-repo":
139 String repoName = cli.getArgs()[1];
140 String repoUrl = cli.getArgs()[2];
141 repositoryManager.addRepository(repoName, repoUrl);
142 printGreen("Added repository: " + repoName);
143 break;
144 case "add-key":
145 String keyFilename = cli.getArgs()[1];
146 Path path = Path.of(keyFilename);
147 repositoryManager.addKey(Files.readAllBytes(path), path.getFileName().toString());
148 break;
149 case "list-installed":
150 printGreen("Installed packages:\n-----");
151 for (SolrPackageInstance pkg : packageManager.fetchInstalledPackageInstances()) {
152 printGreen(pkg);
153 }
154 break;
155 case "list-available":
156 printGreen("Available packages:\n-----");
157 for (SolrPackage pkg : repositoryManager.getPackages()) {
158 printGreen(pkg.name + " \t\t" + pkg.description);
159 for (SolrPackageRelease version : pkg.versions) {
160 printGreen("\tVersion: " + version.version);
161 }
162 }
163 break;
164 case "list-deployed":
165 if (cli.hasOption(COLLECTION_OPTION)) {

Callers

nothing calls this directly

Calls 15

normalizeSolrUrlMethod · 0.95
getZkHostMethod · 0.95
getSolrClientMethod · 0.95
parsePackageVersionMethod · 0.95
validateCollectionsMethod · 0.95
addRepositoryMethod · 0.80
printGreenMethod · 0.80
addKeyMethod · 0.80
getFileNameMethod · 0.80
getPackagesDeployedMethod · 0.80

Tested by

no test coverage detected