From fbb73eca2e052beb2492e763157051da9e9e38d2 Mon Sep 17 00:00:00 2001 From: Madhan Neethiraj Date: Tue, 30 Apr 2019 09:15:08 -0700 Subject: [PATCH] ImpalaPostExecHook infra --- .../impala/hooks/ImpalaHookContext.java | 30 +++++++ .../impala/hooks/ImpalaPostExecHook.java | 35 ++++++++ .../hooks/ImpalaPostExecHookFactory.java | 86 +++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 fe/src/main/java/org/apache/impala/hooks/ImpalaHookContext.java create mode 100644 fe/src/main/java/org/apache/impala/hooks/ImpalaPostExecHook.java create mode 100644 fe/src/main/java/org/apache/impala/hooks/ImpalaPostExecHookFactory.java diff --git a/fe/src/main/java/org/apache/impala/hooks/ImpalaHookContext.java b/fe/src/main/java/org/apache/impala/hooks/ImpalaHookContext.java new file mode 100644 index 000000000..81e6347ee --- /dev/null +++ b/fe/src/main/java/org/apache/impala/hooks/ImpalaHookContext.java @@ -0,0 +1,30 @@ +/** + * 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.impala.hooks; + +public class ImpalaHookContext { + private final String lineageString; + + public ImpalaHookContext(String lineageString) { + this.lineageString = lineageString; + } + + public String getLineageString() { + return lineageString; + } +} diff --git a/fe/src/main/java/org/apache/impala/hooks/ImpalaPostExecHook.java b/fe/src/main/java/org/apache/impala/hooks/ImpalaPostExecHook.java new file mode 100644 index 000000000..ab15047f0 --- /dev/null +++ b/fe/src/main/java/org/apache/impala/hooks/ImpalaPostExecHook.java @@ -0,0 +1,35 @@ +/** + * 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.impala.hooks; + +public abstract class ImpalaPostExecHook { + /** + * Initialization of Impala post-execution hook + */ + public abstract void init(); + + /** + * Cleanup of Impala post-execution hook + */ + public abstract void cleanUp(); + + /** + * Execute Impala post-hook + */ + public abstract void execute(ImpalaHookContext context); +} diff --git a/fe/src/main/java/org/apache/impala/hooks/ImpalaPostExecHookFactory.java b/fe/src/main/java/org/apache/impala/hooks/ImpalaPostExecHookFactory.java new file mode 100644 index 000000000..e81cc567c --- /dev/null +++ b/fe/src/main/java/org/apache/impala/hooks/ImpalaPostExecHookFactory.java @@ -0,0 +1,86 @@ +/** + * 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.impala.hooks; + +import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.conf.Configuration; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class ImpalaPostExecHookFactory { + public static final String CONFIG_POST_EXEC_HOOKS = "impala.post.exec.hooks"; + + private static final ImpalaPostExecHookFactory INSTANCE = new ImpalaPostExecHookFactory(); + + private List hooks = Collections.emptyList(); + + private ImpalaPostExecHookFactory() { + } + + public static ImpalaPostExecHookFactory getInstance() { + return INSTANCE; + } + + // to be called once during Impala startup + public void init(Configuration config) throws Exception { + List hooks = new ArrayList<>(); + + String confPostExecHooks = config.get(CONFIG_POST_EXEC_HOOKS); + + if (StringUtils.isNotEmpty(confPostExecHooks)) { + String[] postExecHooks = confPostExecHooks.split(","); + + for (String postExecHook : postExecHooks) { + Class clsHook = (Class) Class.forName(postExecHook); + + ImpalaPostExecHook hook = clsHook.newInstance(); + + hooks.add(hook); + } + } + + for (ImpalaPostExecHook hook : hooks) { + hook.init(); + } + + this.hooks = Collections.unmodifiableList(hooks); + } + + // to be called once during Impala shutdown + public void cleanUp() { + List hooks = this.hooks; + + this.hooks = Collections.emptyList(); + + for (ImpalaPostExecHook hook : hooks) { + hook.cleanUp(); + } + } + + public List getHooks() { + return hooks; + } + + public void executeHooks(ImpalaHookContext context) { + for (ImpalaPostExecHook hook : hooks) { + hook.execute(context); + } + } +} -- 2.19.2