Search in sources :

Example 6 with ForemanSetupException

use of org.apache.drill.exec.work.foreman.ForemanSetupException in project drill by apache.

the class CreateFunctionHandler method getPlan.

/**
   * Registers UDFs dynamically. Process consists of several steps:
   * <ol>
   * <li>Registering jar in jar registry to ensure that several jars with the same name is not registered.</li>
   * <li>Binary and source jars validation and back up.</li>
   * <li>Validation against local function registry.</li>
   * <li>Validation against remote function registry.</li>
   * <li>Remote function registry update.</li>
   * <li>Copying of jars to registry area and clean up.</li>
   * </ol>
   *
   * UDFs registration is allowed only if dynamic UDFs support is enabled.
   *
   * @return - Single row indicating list of registered UDFs, or error message otherwise.
   */
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ForemanSetupException, IOException {
    if (!context.getOption(ExecConstants.DYNAMIC_UDF_SUPPORT_ENABLED).bool_val) {
        throw UserException.validationError().message("Dynamic UDFs support is disabled.").build(logger);
    }
    RemoteFunctionRegistry remoteRegistry = context.getRemoteFunctionRegistry();
    JarManager jarManager = new JarManager(sqlNode, remoteRegistry);
    boolean inProgress = false;
    try {
        final String action = remoteRegistry.addToJars(jarManager.getBinaryName(), RemoteFunctionRegistry.Action.REGISTRATION);
        if (!(inProgress = action == null)) {
            return DirectPlan.createDirectPlan(context, false, String.format("Jar with %s name is used. Action: %s", jarManager.getBinaryName(), action));
        }
        jarManager.initRemoteBackup();
        List<String> functions = validateAgainstLocalRegistry(jarManager, context.getFunctionRegistry());
        initRemoteRegistration(functions, jarManager, remoteRegistry);
        jarManager.deleteQuietlyFromStagingArea();
        return DirectPlan.createDirectPlan(context, true, String.format("The following UDFs in jar %s have been registered:\n%s", jarManager.getBinaryName(), functions));
    } catch (Exception e) {
        logger.error("Error during UDF registration", e);
        return DirectPlan.createDirectPlan(context, false, e.getMessage());
    } finally {
        if (inProgress) {
            remoteRegistry.removeFromJars(jarManager.getBinaryName());
        }
        jarManager.cleanUp();
    }
}
Also used : RemoteFunctionRegistry(org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) FunctionValidationException(org.apache.drill.exec.exception.FunctionValidationException) JarValidationException(org.apache.drill.exec.exception.JarValidationException) IOException(java.io.IOException) ForemanSetupException(org.apache.drill.exec.work.foreman.ForemanSetupException) VersionMismatchException(org.apache.drill.exec.exception.VersionMismatchException)

Aggregations

ForemanSetupException (org.apache.drill.exec.work.foreman.ForemanSetupException)6 IOException (java.io.IOException)3 UserException (org.apache.drill.common.exceptions.UserException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 SchemaPlus (org.apache.calcite.schema.SchemaPlus)2 RelConversionException (org.apache.calcite.tools.RelConversionException)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)2 RemoteFunctionRegistry (org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry)2 FragmentRoot (org.apache.drill.exec.physical.base.FragmentRoot)2 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)2 IndexedFragmentNode (org.apache.drill.exec.planner.fragment.Materializer.IndexedFragmentNode)2 PlanFragment (org.apache.drill.exec.proto.BitControl.PlanFragment)2 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)2 FragmentHandle (org.apache.drill.exec.proto.ExecProtos.FragmentHandle)2 QueryWorkUnit (org.apache.drill.exec.work.QueryWorkUnit)2 Table (org.apache.calcite.schema.Table)1 SqlCharStringLiteral (org.apache.calcite.sql.SqlCharStringLiteral)1 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)1 SqlNode (org.apache.calcite.sql.SqlNode)1