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.client.solrj.util.SolrIdentifierValidator.validateCollectionName;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.spi.json.JacksonJsonProvider;
import com.jayway.jsonpath.spi.json.JsonProvider;
import com.jayway.jsonpath.spi.mapper.JacksonMappingProvider;
import com.jayway.jsonpath.spi.mapper.MappingProvider;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.lucene.util.SuppressForbidden;
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.impl.JsonMapResponseParser;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.RequestWriter;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.BlobRepository;
import org.apache.solr.filestore.DistribFileStore;
import org.apache.solr.filestore.FileStoreAPI;
import org.apache.solr.packagemanager.SolrPackage.Manifest;
import org.apache.solr.util.SolrJacksonAnnotationInspector;
public class PackageUtils {
/** Represents a version which denotes the latest version available at the moment. */
public static String LATEST = "latest";
public static String PACKAGE_PATH = "/api/cluster/package";
public static String CLUSTER_PLUGINS_PATH = "/api/cluster/plugin";
public static String REPOSITORIES_ZK_PATH = "/repositories.json";
public static String CLUSTERPROPS_PATH = "/api/cluster/zk/data/clusterprops.json";
public static Configuration jsonPathConfiguration() {
MappingProvider provider = new JacksonMappingProvider();
JsonProvider jsonProvider = new JacksonJsonProvider();
Configuration c =
Configuration.builder()
.jsonProvider(jsonProvider)
.mappingProvider(provider)
.options(com.jayway.jsonpath.Option.REQUIRE_PROPERTIES)
.build();
return c;
}
public static ObjectMapper getMapper() {
return new ObjectMapper().setAnnotationIntrospector(new SolrJacksonAnnotationInspector());
}
/**
* Uploads a file to the package store / file store of Solr.
*
* @param client A Solr client
* @param buffer File contents
* @param name Name of the file as it will appear in the file store (can be hierarchical)
* @param sig Signature digest (public key should be separately uploaded to ZK)
*/
public static void postFile(SolrClient client, ByteBuffer buffer, String name, String sig)
throws SolrServerException, IOException {
String resource = "/api/cluster/files" + name;
ModifiableSolrParams params = new ModifiableSolrParams();
if (sig != null) {
params.add("sig", sig);
}
GenericSolrRequest request =
new GenericSolrRequest(SolrRequest.METHOD.PUT, resource, params) {
@Override
public RequestWriter.ContentWriter getContentWriter(String expectedType) {
return new RequestWriter.ContentWriter() {
public final ByteBuffer payload = buffer;
@Override
public void write(OutputStream os) throws IOException {
if (payload == null) return;
Channels.newChannel(os).write(payload);
}
@Override
public String getContentType() {
return "application/octet-stream";
}
};
}
};
NamedList