Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.packagemanager;
import static org.apache.solr.common.params.CommonParams.SYSTEM_INFO_PATH;
import static org.apache.solr.packagemanager.PackageUtils.getMapper;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.invoke.MethodHandles;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.solr.client.api.util.SolrVersion;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.RequestWriter;
import org.apache.solr.client.solrj.request.beans.PackagePayload;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.BlobRepository;
import org.apache.solr.filestore.FileStoreAPI;
import org.apache.solr.packagemanager.SolrPackage.Artifact;
import org.apache.solr.packagemanager.SolrPackage.SolrPackageRelease;
import org.apache.solr.pkg.PackageAPI;
import org.apache.solr.pkg.SolrPackageLoader;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** Handles most of the management of repositories and packages present in external repositories. */
public class RepositoryManager {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final PackageManager packageManager;
final SolrClient solrClient;
public RepositoryManager(SolrClient solrClient, PackageManager packageManager) {
this.packageManager = packageManager;
this.solrClient = solrClient;
}
public List getPackages() {
List list = new ArrayList<>(getPackagesMap().values());
Collections.sort(list);
return list;
}
/** Get a map of package name to {@link SolrPackage} objects */
public Map getPackagesMap() {
Map packagesMap = new HashMap<>();
for (PackageRepository repository : getRepositories()) {
packagesMap.putAll(repository.getPackages());
}
return packagesMap;
}
/** List of added repositories */
public List getRepositories() {
// TODO: Instead of fetching again and again, we should look for caching this
PackageRepository items[];
try {
items =
getMapper()
.readValue(
getRepositoriesJson(packageManager.zkClient), DefaultPackageRepository[].class);
} catch (IOException | KeeperException | InterruptedException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
List repositories = Arrays.asList(items);
for (PackageRepository updateRepository : repositories) {
updateRepository.refresh();
}
return repositories;
}
/** Add a repository to Solr */
public void addRepository(String repoName, String uri) throws Exception {
String existingRepositoriesJson = getRepositoriesJson(packageManager.zkClient);
log.info(existingRepositoriesJson);
@SuppressWarnings({"unchecked"})
List repos = getMapper().readValue(existingRepositoriesJson, List.class);
repos.add(new DefaultPackageRepository(repoName, uri));
if (packageManager.zkClient.exists(PackageUtils.REPOSITORIES_ZK_PATH, true) == false) {
packageManager.zkClient.create(
PackageUtils.REPOSITORIES_ZK_PATH,
getMapper().writeValueAsString(repos).getBytes(StandardCharsets.UTF_8),
CreateMode.PERSISTENT,
true);
} else {
packageManager.zkClient.setData(
PackageUtils.REPOSITORIES_ZK_PATH,
getMapper().writeValueAsString(repos).getBytes(StandardCharsets.UTF_8),
true);
}
try (InputStream is = new URL(uri + "/publickey.der").openStream()) {
addKey(is.readAllBytes(), repoName + ".der");
}
}
public void addKey(byte[] key, String destinationKeyFilename) throws Exception {
// get solr_home directory from info servlet
NamedList