download:HBase+Spring Boot Actual distributed file storage

HBase is a distributed and scalable column database that implements big data storage based on Hadoop and provides random data read/write access. This course explains HBase cluster deployment, basic principles, advanced features, optimization policies, Dr Monitoring, development practices, and other HBase related open source projects (such as Phoenix and Sqoop). If you are interested, do not miss it.

This course is aimed at students who have some Java programming experience and want to learn about Apache open source project HBase and related tools

Technical reserve requirements familiar with Linux command/basic familiar with the Java programming language with the Spring framework/Boot understand Hadoop import cn. Hutool. Core. Collections. CollUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.CharsetUtil; import org.apache.hc.client5.http.config.RequestConfig; import org.apache.hc.client5.http.entity.UrlEncodedFormEntity; import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder; import org.apache.hc.client5.http.fluent.Form; import org.apache.hc.client5.http.fluent.Request; import org.apache.hc.client5.http.fluent.Response; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; import org.apache.hc.client5.http.ssl.NoopHostnameVerifier; import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.hc.core5.http.io.entity.HttpEntities; import org.apache.hc.core5.util.TimeValue; import org.apache.hc.core5.util.Timeout;

import javax.net.ssl.SSLContext;

import javax.net.ssl.SSLEngine;

import javax.net.ssl.TrustManager;

import javax.net.ssl.X509ExtendedTrustManager;

import java.io.File;

import java.io.IOException;

import java.net.Socket;

import java.nio.charset.Charset;

import java.security.KeyManagementException;

import java.security.NoSuchAlgorithmException;

import java.security.cert.X509Certificate;

import java.util.Map;

/ * *

  • @author sun

  • @date 2021-02-25

    **/

    public class HttpUtil {

    private static final int maxConnTotal = 200;

    private static final Timeout connectTimeout = Timeout.ofSeconds(10);

    private static final Timeout requestTimeout = Timeout.ofSeconds(30);

    public static String uploadFile(String urlString, Map<String, Object> paramMap) throws Exception {

    return uploadFile(urlString, null, paramMap, CharsetUtil.CHARSET_UTF_8)

    .returnContent()

    .asString(CharsetUtil.CHARSET_UTF_8);

    }

    public static String uploadFile(String urlString, Map<String, Object> paramMap, Charset charSet) throws Exception {

    return uploadFile(urlString, null, paramMap, charSet)

    .returnContent()

    .asString(charSet);

    }

    public static Response uploadFile(String urlString, Map<String, Object> handlerMap, Map<String, Object> paramMap) throws Exception {

    return uploadFile(urlString, handlerMap, paramMap, CharsetUtil.CHARSET_UTF_8);

    }

    public static Response uploadFile(String urlString, Map

    handlerMap, Map

    paramMap, Charset charSet) throws Exception { MultipartEntityBuilder builder = MultipartEntityBuilder.create().setCharset(charSet); Parammap. forEach((k, v) -> {if (v instanceof File) {File File = (File) v; builder.addBinaryBody(k, file, ContentType.MULTIPART_FORM_DATA.withCharset(charSet), FileUtil.getName(file)); } else { builder.addTextBody(k, v.toString(), ContentType.TEXT_PLAIN.withCharset(charSet)); }}); Request request = Request.post(urlString) .body(builder.build()); If (collutil.isnotempty (handlerMap)) {handlermap.foreach ((k, v) -> request.addHeader(k, v.tostring ())); } return call(request); }
    ,>
    ,>

    public static String post(String urlString, Map<String, Object> paramMap) throws Exception {

    return post(urlString, paramMap, CharsetUtil.CHARSET_UTF_8);

    }

    public static String post(String urlString, Map<String, Object> paramMap, Charset charSet) throws Exception {

    return post(urlString, null, paramMap, charSet)

    .returnContent()

    .asString(charSet);

    }

    public static Response post(String urlString, Map<String, Object> handlerMap, Map<String, Object> paramMap) throws Exception {

    return post(urlString, handlerMap, paramMap, CharsetUtil.CHARSET_UTF_8);

    }

    public static Response post(String urlString, Map

    handlerMap, Map

    paramMap, Charset charSet) throws Exception { Form form = Form.form(); if (CollUtil.isNotEmpty(paramMap)) { paramMap.forEach((k, v) -> form.add(k, v.toString())); } Request request = Request.post(urlString) .bodyForm(form.build(), charSet); If (collutil.isnotempty (handlerMap)) {handlermap.foreach ((k, v) -> request.addHeader(k, v.tostring ())); } return call(request); }
    ,>
    ,>

    public static String post(String urlString, String body) throws IOException {

    return post(urlString, body, CharsetUtil.CHARSET_UTF_8);

    }

    public static String post(String urlString, String body, Charset charSet) throws IOException {

    return post(urlString, null, body, charSet)

    .returnContent()

    .asString(charSet);

    }

    public static Response post(String urlString, Map<String, Object> handlerMap, String body) throws IOException {

    return post(urlString, handlerMap, body, CharsetUtil.CHARSET_UTF_8);

    }

    public static Response post(String urlString, Map

    handlerMap, String body, Charset charSet) throws IOException { HttpEntity httpEntity = HttpEntities.create(body, charSet); Request request = Request.post(urlString) .body(httpEntity); If (collutil.isnotempty (handlerMap)) {handlermap.foreach ((k, v) -> request.addHeader(k, v.tostring ())); } return call(request); }
    ,>

    public static String get(String urlString, Map<String, Object> paramMap) throws Exception {

    return get(urlString, paramMap, CharsetUtil.CHARSET_UTF_8);

    }

    public static String get(String urlString, Map<String, Object> paramMap, Charset charSet) throws Exception {

    return get(urlString, null, paramMap, charSet)

    .returnContent()

    .asString(charSet);

    }

    public static String get(String urlString, Map<String, Object> handlerMap, Map<String, Object> paramMap) throws Exception {

    return get(urlString, handlerMap, paramMap, CharsetUtil.CHARSET_UTF_8)

    .returnContent()

    .asString(CharsetUtil.CHARSET_UTF_8);

    }

    public static Response get(String urlString, Map

    handlerMap, Map

    paramMap, Charset charSet) throws Exception { Form form = Form.form(); if (CollUtil.isNotEmpty(paramMap)) { paramMap.forEach((k, v) -> form.add(k, v.toString())); } String paramStr = EntityUtils.toString(new UrlEncodedFormEntity(form.build(), charSet)); Request request = Request.get(urlString + ‘? ‘ + paramStr); If (collutil.isnotempty (handlerMap)) {handlermap.foreach ((k, v) -> request.addHeader(k, v.tostring ())); } return call(request); }
    ,>
    ,>

    public static Response call(Request request) throws IOException {

    return request.execute(Client.c);

    }

    private static class Client {

    private static final CloseableHttpClient c = HttpClientBuilder.create()

    .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()

    .setSSLSocketFactory(getSSLFactory())

    .setValidateAfterInactivity(TimeValue.ofSeconds(10))

    .setMaxConnPerRoute(maxConnTotal – 1)

    .setMaxConnTotal(maxConnTotal)

    .build())

    .evictIdleConnections(TimeValue.ofMinutes(1))

    .disableAutomaticRetries()

    .setDefaultRequestConfig(RequestConfig.custom()

    .setConnectTimeout(connectTimeout)

    .setConnectionRequestTimeout(requestTimeout)

    .build())

    .build();

    private static SSLConnectionSocketFactory getSSLFactory() { X509ExtendedTrustManager trustManager = new X509ExtendedTrustManager() { @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s, Socket socket) { } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s, Socket socket) { } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) { } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) { } @Override public void checkClientTrusted(X509Certificate[] arg0, String arg1) { } @Override public void checkServerTrusted(X509Certificate[] arg0, String arg1) { } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }}; SSLContext ctx = null; try { ctx = SSLContext.getInstance(&quot; TLS&quot;) ; ctx.init(null, new TrustManager[]{trustManager}, null); } catch (NoSuchAlgorithmException | KeyManagementException e) { e.printStackTrace(); } assert ctx ! = null; return new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE); }Copy the code

    }}