You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by va...@apache.org on 2023/01/15 12:19:23 UTC

[incubator-hugegraph] 01/01: remove hguegraph.store and LicenseVerify

This is an automated email from the ASF dual-hosted git repository.

vaughn pushed a commit to branch zy_dev
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git

commit 9fcd5edac501298615be47f45629d37eab02e431
Author: vaughn <va...@apache.org>
AuthorDate: Sun Jan 15 20:19:01 2023 +0800

    remove hguegraph.store and LicenseVerify
---
 .../hugegraph/auth/HugeFactoryAuthProxy.java       |   4 -
 .../org/apache/hugegraph/core/GraphManager.java    |   7 -
 .../apache/hugegraph/license/LicenseVerifier.java  | 130 -----------
 .../hugegraph/license/LicenseVerifyManager.java    | 249 ---------------------
 .../src/assembly/static/bin/hugegraph-server.sh    |   5 +
 .../assembly/static/conf/hugegraph-server.keystore | Bin 1733 -> 0 bytes
 .../src/main/resources/verify-license.json         |   7 -
 7 files changed, 5 insertions(+), 397 deletions(-)

diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeFactoryAuthProxy.java b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeFactoryAuthProxy.java
index 585ae7d06..e2b9ccfcc 100644
--- a/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeFactoryAuthProxy.java
+++ b/hugegraph-api/src/main/java/org/apache/hugegraph/auth/HugeFactoryAuthProxy.java
@@ -33,7 +33,6 @@ import org.apache.hugegraph.StandardHugeGraph;
 import org.apache.hugegraph.backend.cache.CacheManager;
 import org.apache.hugegraph.backend.tx.AbstractTransaction;
 import org.apache.hugegraph.concurrent.LockManager;
-import org.apache.hugegraph.license.LicenseVerifier;
 import org.apache.hugegraph.metrics.ServerReporter;
 import org.apache.hugegraph.schema.SchemaElement;
 import org.apache.hugegraph.schema.SchemaManager;
@@ -184,8 +183,6 @@ public final class HugeFactoryAuthProxy {
         Reflection.registerMethodsToFilter(CacheManager.class, "access$0", "scheduleTimer", "instance");
         Reflection.registerFieldsToFilter(org.apache.hugegraph.concurrent.LockManager.class, "INSTANCE", "lockGroupMap");
         Reflection.registerMethodsToFilter(org.apache.hugegraph.concurrent.LockManager.class, "instance");
-        Reflection.registerFieldsToFilter(LicenseVerifier.class, "LOG", "LICENSE_PARAM_PATH", "INSTANCE", "CHECK_INTERVAL", "lastCheckTime", "verifyParam", "manager");
-        Reflection.registerMethodsToFilter(LicenseVerifier.class, "buildVerifyParam", "initLicenseParam", "verifyPublicCert", "instance");
         Reflection.registerFieldsToFilter(ServerReporter.class, "instance", "gauges", "counters", "histograms", "meters", "timers");
         Reflection.registerMethodsToFilter(ServerReporter.class, "instance", "instance");
         Reflection.registerFieldsToFilter(com.codahale.metrics.ScheduledReporter.class, "LOG", "FACTORY_ID", "registry", "executor", "shutdownExecutorOnStop", "disabledMetricAttributes", "scheduledFuture", "filter", "durationFactor", "durationUnit", "rateFactor", "rateUnit");
@@ -261,7 +258,6 @@ public final class HugeFactoryAuthProxy {
 
         registerPrivateActions(CacheManager.class);
         registerPrivateActions(LockManager.class);
-        registerPrivateActions(LicenseVerifier.class);
         registerPrivateActions(ServerReporter.class);
         registerPrivateActions(JsonSerializer.class);
         registerPrivateActions(HugeVertexStepStrategy.class);
diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java
index ee221865c..57a99b732 100644
--- a/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java
+++ b/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java
@@ -36,7 +36,6 @@ import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
 import org.apache.hugegraph.auth.HugeFactoryAuthProxy;
 import org.apache.hugegraph.auth.HugeGraphAuthProxy;
 import org.apache.hugegraph.config.ServerOptions;
-import org.apache.hugegraph.license.LicenseVerifier;
 import org.apache.hugegraph.metrics.MetricsUtil;
 import org.apache.hugegraph.metrics.ServerReporter;
 import org.apache.hugegraph.serializer.JsonSerializer;
@@ -105,8 +104,6 @@ public final class GraphManager {
 
         this.loadGraphs(ConfigUtil.scanGraphsDir(this.graphsDir));
 
-        // this.installLicense(conf, "");
-
         // Start RPC-Server for raft-rpc/auth-rpc/cache-notify-rpc...
         this.startRpcServer();
 
@@ -331,10 +328,6 @@ public final class GraphManager {
         return this.authenticator;
     }
 
-    @SuppressWarnings("unused")
-    private void installLicense(HugeConfig config, String md5) {
-        LicenseVerifier.instance().install(config, this, md5);
-    }
 
     private void closeTx(final Set<String> graphSourceNamesToCloseTxOn,
                          final Transaction.Status tx) {
diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/license/LicenseVerifier.java b/hugegraph-api/src/main/java/org/apache/hugegraph/license/LicenseVerifier.java
deleted file mode 100644
index dc6c845ef..000000000
--- a/hugegraph-api/src/main/java/org/apache/hugegraph/license/LicenseVerifier.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * 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.hugegraph.license;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.time.Duration;
-import java.time.Instant;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.slf4j.Logger;
-
-import org.apache.hugegraph.HugeException;
-import org.apache.hugegraph.config.HugeConfig;
-import org.apache.hugegraph.core.GraphManager;
-import org.apache.hugegraph.util.Log;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-public class LicenseVerifier {
-
-    private static final Logger LOG = Log.logger(LicenseVerifier.class);
-
-    private static final String LICENSE_PARAM_PATH = "/verify-license.json";
-
-    private static volatile LicenseVerifier INSTANCE = null;
-
-    private static final Duration CHECK_INTERVAL = Duration.ofMinutes(10);
-    private volatile Instant lastCheckTime = Instant.now();
-
-    private final LicenseInstallParam installParam;
-    private final LicenseVerifyManager manager;
-
-    private LicenseVerifier() {
-        this.installParam = buildInstallParam(LICENSE_PARAM_PATH);
-        this.manager = new LicenseVerifyManager(this.installParam);
-    }
-
-    public static LicenseVerifier instance() {
-        if (INSTANCE == null) {
-            synchronized (LicenseVerifier.class) {
-                if (INSTANCE == null) {
-                    INSTANCE = new LicenseVerifier();
-                }
-            }
-        }
-        return INSTANCE;
-    }
-
-    public synchronized void install(HugeConfig config,
-                                     GraphManager graphManager,
-                                     String md5) {
-        this.manager.config(config);
-        this.manager.graphManager(graphManager);
-        LicenseManager licenseManager = this.manager.licenseManager();
-        try {
-            licenseManager.uninstallLicense();
-            this.verifyPublicCert(md5);
-            LicenseParams params = licenseManager.installLicense();
-            LOG.info("The license '{}' is successfully installed for '{}', " +
-                     "the term of validity is from {} to {}",
-                     params.subject(), params.consumerType(),
-                     params.notBefore(), params.notAfter());
-        } catch (Exception e) {
-            LOG.error("Failed to install license", e);
-            throw new HugeException("Failed to install license", e);
-        }
-    }
-
-    public void verifyIfNeeded() {
-        Instant now = Instant.now();
-        Duration interval = Duration.between(this.lastCheckTime, now);
-        if (!interval.minus(CHECK_INTERVAL).isNegative()) {
-            this.verify();
-            this.lastCheckTime = now;
-        }
-    }
-
-    public void verify() {
-        try {
-            LicenseParams params = this.manager.licenseManager()
-                                               .verifyLicense();
-            LOG.info("The license verification passed, " +
-                     "the term of validity is from {} to {}",
-                     params.notBefore(), params.notAfter());
-        } catch (Exception e) {
-            LOG.error("Failed to verify license", e);
-            throw new HugeException("Failed to verify license", e);
-        }
-    }
-
-    private void verifyPublicCert(String expectMD5) {
-        String path = this.installParam.publicKeyPath();
-        try (InputStream is = LicenseVerifier.class.getResourceAsStream(path)) {
-            String actualMD5 = DigestUtils.md5Hex(is);
-            if (!actualMD5.equals(expectMD5)) {
-                throw new HugeException("Invalid public cert");
-            }
-        } catch (IOException e) {
-            LOG.error("Failed to read public cert", e);
-            throw new HugeException("Failed to read public cert", e);
-        }
-    }
-
-    private static LicenseInstallParam buildInstallParam(String path) {
-        // NOTE: can't use JsonUtil due to it bind tinkerpop jackson
-        ObjectMapper mapper = new ObjectMapper();
-        try (InputStream stream =
-             LicenseVerifier.class.getResourceAsStream(path)) {
-            return mapper.readValue(stream, LicenseInstallParam.class);
-        } catch (IOException e) {
-            throw new HugeException("Failed to read json stream to %s",
-                                    LicenseInstallParam.class);
-        }
-    }
-}
diff --git a/hugegraph-api/src/main/java/org/apache/hugegraph/license/LicenseVerifyManager.java b/hugegraph-api/src/main/java/org/apache/hugegraph/license/LicenseVerifyManager.java
deleted file mode 100644
index 14d78d7fc..000000000
--- a/hugegraph-api/src/main/java/org/apache/hugegraph/license/LicenseVerifyManager.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * 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.hugegraph.license;
-
-import java.lang.management.ManagementFactory;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.List;
-
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-
-import org.apache.hugegraph.HugeException;
-import org.apache.hugegraph.config.CoreOptions;
-import org.apache.hugegraph.config.HugeConfig;
-import org.apache.hugegraph.config.ServerOptions;
-import org.apache.hugegraph.core.GraphManager;
-import org.apache.hugegraph.util.Bytes;
-import org.apache.hugegraph.util.E;
-import org.apache.hugegraph.util.Log;
-import org.apache.hugegraph.util.VersionUtil;
-import org.apache.hugegraph.version.CoreVersion;
-import com.sun.management.OperatingSystemMXBean;
-
-public class LicenseVerifyManager {
-
-    private static final Logger LOG = Log.logger(LicenseVerifyManager.class);
-
-    private final LicenseManager licenseManager;
-    private final MachineInfo machineInfo;
-
-    private HugeConfig config;
-    private GraphManager graphManager;
-
-    public LicenseVerifyManager(LicenseInstallParam param) {
-        this.licenseManager = LicenseManagerFactory.create(param,
-                                                           this::validate);
-        this.machineInfo = new MachineInfo();
-    }
-
-    public LicenseManager licenseManager() {
-        return this.licenseManager;
-    }
-
-    public void config(HugeConfig config) {
-        this.config = config;
-    }
-
-    public HugeConfig config() {
-        E.checkState(this.config != null,
-                     "License verify manager has not been installed");
-        return this.config;
-    }
-
-    public void graphManager(GraphManager graphManager) {
-        this.graphManager = graphManager;
-    }
-
-    public GraphManager graphManager() {
-        E.checkState(this.graphManager != null,
-                     "License verify manager has not been installed");
-        return this.graphManager;
-    }
-
-    private synchronized void validate(LicenseParams params) {
-        // Verify the customized license parameters.
-        String serverId = this.getServerId();
-        LOG.debug("Verify server id '{}'", serverId);
-        LicenseExtraParam param = params.matchParam(serverId);
-        if (param == null) {
-            throw new HugeException("The current server id is not authorized");
-        }
-
-        this.checkVersion(param);
-        this.checkGraphs(param);
-        this.checkIpAndMac(param);
-        this.checkCpu(param);
-        this.checkRam(param);
-        this.checkThreads(param);
-        this.checkMemory(param);
-    }
-
-    private String getServerId() {
-        return this.config().get(ServerOptions.SERVER_ID);
-    }
-
-    private void checkVersion(LicenseExtraParam param) {
-        String expectVersion = param.version();
-        if (StringUtils.isEmpty(expectVersion)) {
-            return;
-        }
-        VersionUtil.Version acutalVersion = CoreVersion.VERSION;
-        if (acutalVersion.compareTo(VersionUtil.Version.of(expectVersion)) > 0) {
-            throw newLicenseException(
-                  "The server's version '%s' exceeded the authorized '%s'",
-                  acutalVersion.get(), expectVersion);
-        }
-    }
-
-    private void checkGraphs(LicenseExtraParam param) {
-        int expectGraphs = param.graphs();
-        if (expectGraphs == LicenseExtraParam.NO_LIMIT) {
-            return;
-        }
-        int actualGraphs = this.graphManager().graphs().size();
-        if (actualGraphs > expectGraphs) {
-            throw newLicenseException(
-                  "The server's graphs '%s' exceeded the authorized '%s'",
-                  actualGraphs, expectGraphs);
-        }
-    }
-
-    private void checkIpAndMac(LicenseExtraParam param) {
-        String expectIp = param.ip();
-        boolean matched = false;
-        List<String> actualIps = this.machineInfo.getIpAddress();
-        for (String actualIp : actualIps) {
-            if (StringUtils.isEmpty(expectIp) ||
-                actualIp.equalsIgnoreCase(expectIp)) {
-                matched = true;
-                break;
-            }
-        }
-        if (!matched) {
-            throw newLicenseException(
-                  "The server's ip '%s' doesn't match the authorized '%s'",
-                  actualIps, expectIp);
-        }
-
-        String expectMac = param.mac();
-        if (StringUtils.isEmpty(expectMac)) {
-            return;
-        }
-
-        // The mac must be not empty here
-        if (!StringUtils.isEmpty(expectIp)) {
-            String actualMac;
-            try {
-                actualMac = this.machineInfo.getMacByInetAddress(
-                            InetAddress.getByName(expectIp));
-            } catch (UnknownHostException e) {
-                throw newLicenseException(
-                      "Failed to get mac address for ip '%s'", expectIp);
-            }
-            String expectFormatMac = expectMac.replaceAll(":", "-");
-            String actualFormatMac = actualMac.replaceAll(":", "-");
-            if (!actualFormatMac.equalsIgnoreCase(expectFormatMac)) {
-                throw newLicenseException(
-                      "The server's mac '%s' doesn't match the authorized '%s'",
-                      actualMac, expectMac);
-            }
-        } else {
-            String expectFormatMac = expectMac.replaceAll(":", "-");
-            List<String> actualMacs = this.machineInfo.getMacAddress();
-            matched = false;
-            for (String actualMac : actualMacs) {
-                String actualFormatMac = actualMac.replaceAll(":", "-");
-                if (actualFormatMac.equalsIgnoreCase(expectFormatMac)) {
-                    matched = true;
-                    break;
-                }
-            }
-            if (!matched) {
-                throw newLicenseException(
-                      "The server's macs %s don't match the authorized '%s'",
-                      actualMacs, expectMac);
-            }
-        }
-    }
-
-    private void checkCpu(LicenseExtraParam param) {
-        int expectCpus = param.cpus();
-        if (expectCpus == LicenseExtraParam.NO_LIMIT) {
-            return;
-        }
-        int actualCpus = CoreOptions.CPUS;
-        if (actualCpus > expectCpus) {
-            throw newLicenseException(
-                  "The server's cpus '%s' exceeded the limit '%s'",
-                  actualCpus, expectCpus);
-        }
-    }
-
-    private void checkRam(LicenseExtraParam param) {
-        // Unit MB
-        int expectRam = param.ram();
-        if (expectRam == LicenseExtraParam.NO_LIMIT) {
-            return;
-        }
-        OperatingSystemMXBean mxBean = (OperatingSystemMXBean) ManagementFactory
-                                       .getOperatingSystemMXBean();
-        long actualRam = mxBean.getTotalPhysicalMemorySize() / Bytes.MB;
-        if (actualRam > expectRam) {
-            throw newLicenseException(
-                  "The server's ram(MB) '%s' exceeded the limit(MB) '%s'",
-                  actualRam, expectRam);
-        }
-    }
-
-    private void checkThreads(LicenseExtraParam param) {
-        int expectThreads = param.threads();
-        if (expectThreads == LicenseExtraParam.NO_LIMIT) {
-            return;
-        }
-        int actualThreads = this.config().get(ServerOptions.MAX_WORKER_THREADS);
-        if (actualThreads > expectThreads) {
-            throw newLicenseException(
-                  "The server's max threads '%s' exceeded limit '%s'",
-                  actualThreads, expectThreads);
-        }
-    }
-
-    private void checkMemory(LicenseExtraParam param) {
-        // Unit MB
-        int expectMemory = param.memory();
-        if (expectMemory == LicenseExtraParam.NO_LIMIT) {
-            return;
-        }
-        /*
-         * NOTE: this max memory will be slightly smaller than XMX,
-         * because only one survivor will be used
-         */
-        long actualMemory = Runtime.getRuntime().maxMemory() / Bytes.MB;
-        if (actualMemory > expectMemory) {
-            throw newLicenseException(
-                  "The server's max heap memory(MB) '%s' exceeded the " +
-                  "limit(MB) '%s'", actualMemory, expectMemory);
-        }
-    }
-
-    private HugeException newLicenseException(String message, Object... args) {
-        return new HugeException(message, args);
-    }
-}
diff --git a/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh b/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh
index 95df66cec..3e6b5727f 100644
--- a/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh
+++ b/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh
@@ -66,6 +66,11 @@ MAX_MEM=$((32 * 1024))
 MIN_MEM=$((1 * 512))
 MIN_JAVA_VERSION=8
 
+# download binary file
+if [[ ! -e ${CONF}/hugegraph-server.keystore  ]]; then
+  wget -P "${CONF}"/hugegraph-server.keystore https://github.com/apache/incubator-hugegraph-doc/blob/master/dist/commons/hugegraph-server.keystore
+fi
+
 # Add the slf4j-log4j12 binding
 CP=$(find -L $LIB -name 'log4j-slf4j-impl*.jar' | sort | tr '\n' ':')
 # Add the jars in lib that start with "hugegraph"
diff --git a/hugegraph-dist/src/assembly/static/conf/hugegraph-server.keystore b/hugegraph-dist/src/assembly/static/conf/hugegraph-server.keystore
deleted file mode 100644
index e60c6b4c4..000000000
Binary files a/hugegraph-dist/src/assembly/static/conf/hugegraph-server.keystore and /dev/null differ
diff --git a/hugegraph-dist/src/main/resources/verify-license.json b/hugegraph-dist/src/main/resources/verify-license.json
deleted file mode 100644
index fed0968a8..000000000
--- a/hugegraph-dist/src/main/resources/verify-license.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
-  "subject": "hugegraph-license",
-  "public_alias": "publiccert",
-  "store_ticket": "803b6cc3-d144-47e8-948f-ec8b39c8881e",
-  "publickey_path": "/public-certs.store",
-  "license_path": "conf/hugegraph-community.license"
-}