henrib commented on code in PR #4194:
URL: https://github.com/apache/hive/pull/4194#discussion_r1175629261


##########
standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/properties/PropertyManager.java:
##########
@@ -0,0 +1,576 @@
+/*
+ * 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.hadoop.hive.metastore.properties;
+
+
+import org.apache.commons.jexl3.JexlBuilder;
+import org.apache.commons.jexl3.JexlContext;
+import org.apache.commons.jexl3.JexlEngine;
+import org.apache.commons.jexl3.JexlException;
+import org.apache.commons.jexl3.JexlExpression;
+import org.apache.commons.jexl3.JexlFeatures;
+import org.apache.commons.jexl3.introspection.JexlPermissions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Constructor;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.UUID;
+import java.util.function.Function;
+
+/**
+ * A property manager.
+ * <p>
+ * This handles operations at the higher functional level; an instance is 
created per-session and
+ * drives queries and updates in a transactional manner.
+ * </p>
+ * <p>
+ * The manager ties the property schemas into one namespace; all property maps 
it handles must and will use
+ * one of its known schema.
+ * </p>
+ */
+public abstract class PropertyManager {
+  /** The logger. */
+  public static final Logger LOGGER = 
LoggerFactory.getLogger(PropertyManager.class);
+  /** The set of dirty maps. */
+  protected Map<String, PropertyMap> dirtyMaps = new HashMap<>();
+  /** This manager namespace. */
+  protected final String namespace;
+  /** The property map store. */
+  protected final PropertyStore store;
+  /** A Jexl engine for convenience. */
+  static final JexlEngine JEXL;
+  static {
+    JexlFeatures features = new JexlFeatures()
+        .sideEffect(false)
+        .sideEffectGlobal(false);
+    JexlPermissions p = JexlPermissions.RESTRICTED
+        .compose("org.apache.hadoop.hive.metastore.properties.*");
+    JEXL = new JexlBuilder()
+        .features(features)
+        .permissions(p)
+        .create();
+  }
+
+  /**
+   * The map of defined managers.
+   */
+  private static final Map<String, Constructor<? extends PropertyManager>> 
NSMANAGERS = new HashMap<>();
+
+  /**
+   * Declares a property manager class.
+   * @param ns the namespace
+   * @param pmClazz the property mamanger class
+   */
+  public static boolean declare(String ns, Class<? extends PropertyManager> 
pmClazz) {
+    try {
+      synchronized(NSMANAGERS) {
+        Constructor<? extends PropertyManager> ctor = NSMANAGERS.get(ns);
+        if (ctor == null) {
+          ctor = pmClazz.getConstructor(String.class, PropertyStore.class);
+          NSMANAGERS.put(ns, ctor);
+          return true;
+        } else {
+          if (!Objects.equals(ctor.getDeclaringClass(), pmClazz)) {
+            LOGGER.error("namespace {} is already declared for {}", ns, 
pmClazz.getCanonicalName());
+          }
+        }
+      }
+    } catch(NoSuchMethodException xnom ) {
+      LOGGER.error("namespace declaration failed: " + ns + ", " + 
pmClazz.getCanonicalName(),
+          xnom);
+    }
+    return false;
+  }
+
+  /**
+   * Creates an instance of manager using its declared namespace.
+   * @param namespace the manager&quot;s namespace
+   * @param store the property store
+   * @return a property manager instance
+   */
+  public static PropertyManager create(String namespace, PropertyStore store) {
+    final Constructor<? extends PropertyManager> ctor;
+    synchronized(NSMANAGERS) {
+      ctor = NSMANAGERS.get(namespace);
+    }
+    if (ctor != null) {
+      try {
+        return ctor.newInstance(namespace, store);
+      } catch(Exception xany) {
+        LOGGER.error("property manager creation failed "+ namespace, xany);
+      }
+    } else {
+      LOGGER.error("no such property manager namespace is declared " + 
namespace);

Review Comment:
   Made it throw errors.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to