Search in sources :

Example 6 with InterpreterException

use of org.apache.zeppelin.interpreter.InterpreterException in project zeppelin by apache.

the class MockInterpreterA method interpret.

@Override
public InterpreterResult interpret(String st, InterpreterContext context) {
    try {
        Thread.sleep(Long.parseLong(st));
        this.lastSt = st;
    } catch (NumberFormatException | InterruptedException e) {
        throw new InterpreterException(e);
    }
    return new InterpreterResult(Code.SUCCESS, st);
}
Also used : InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult)

Example 7 with InterpreterException

use of org.apache.zeppelin.interpreter.InterpreterException in project zeppelin by apache.

the class JDBCInterpreter method getConnection.

public Connection getConnection(String propertyKey, InterpreterContext interpreterContext) throws ClassNotFoundException, SQLException, InterpreterException, IOException {
    final String user = interpreterContext.getAuthenticationInfo().getUser();
    Connection connection;
    if (propertyKey == null || basePropretiesMap.get(propertyKey) == null) {
        return null;
    }
    JDBCUserConfigurations jdbcUserConfigurations = getJDBCConfiguration(user);
    setUserProperty(propertyKey, interpreterContext);
    final Properties properties = jdbcUserConfigurations.getPropertyMap(propertyKey);
    final String url = properties.getProperty(URL_KEY);
    if (isEmpty(property.getProperty("zeppelin.jdbc.auth.type"))) {
        connection = getConnectionFromPool(url, user, propertyKey, properties);
    } else {
        UserGroupInformation.AuthenticationMethod authType = JDBCSecurityImpl.getAuthtype(property);
        switch(authType) {
            case KERBEROS:
                if (user == null) {
                    connection = getConnectionFromPool(url, user, propertyKey, properties);
                } else {
                    if (url.trim().startsWith("jdbc:hive")) {
                        StringBuilder connectionUrl = new StringBuilder(url);
                        Integer lastIndexOfUrl = connectionUrl.indexOf("?");
                        if (lastIndexOfUrl == -1) {
                            lastIndexOfUrl = connectionUrl.length();
                        }
                        boolean hasProxyUser = property.containsKey("hive.proxy.user");
                        if (!hasProxyUser || !property.getProperty("hive.proxy.user").equals("false")) {
                            logger.debug("Using hive proxy user");
                            connectionUrl.insert(lastIndexOfUrl, ";hive.server2.proxy.user=" + user + ";");
                        }
                        connection = getConnectionFromPool(connectionUrl.toString(), user, propertyKey, properties);
                    } else {
                        UserGroupInformation ugi = null;
                        try {
                            ugi = UserGroupInformation.createProxyUser(user, UserGroupInformation.getCurrentUser());
                        } catch (Exception e) {
                            logger.error("Error in getCurrentUser", e);
                            StringBuilder stringBuilder = new StringBuilder();
                            stringBuilder.append(e.getMessage()).append("\n");
                            stringBuilder.append(e.getCause());
                            throw new InterpreterException(stringBuilder.toString());
                        }
                        final String poolKey = propertyKey;
                        try {
                            connection = ugi.doAs(new PrivilegedExceptionAction<Connection>() {

                                @Override
                                public Connection run() throws Exception {
                                    return getConnectionFromPool(url, user, poolKey, properties);
                                }
                            });
                        } catch (Exception e) {
                            logger.error("Error in doAs", e);
                            StringBuilder stringBuilder = new StringBuilder();
                            stringBuilder.append(e.getMessage()).append("\n");
                            stringBuilder.append(e.getCause());
                            throw new InterpreterException(stringBuilder.toString());
                        }
                    }
                }
                break;
            default:
                connection = getConnectionFromPool(url, user, propertyKey, properties);
        }
    }
    propertyKeySqlCompleterMap.put(propertyKey, createSqlCompleter(connection));
    return connection;
}
Also used : InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) Connection(java.sql.Connection) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Properties(java.util.Properties) TTransportException(org.apache.thrift.transport.TTransportException) SQLException(java.sql.SQLException) InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) IOException(java.io.IOException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 8 with InterpreterException

use of org.apache.zeppelin.interpreter.InterpreterException in project zeppelin by apache.

the class MockInterpreterB method interpret.

@Override
public InterpreterResult interpret(String st, InterpreterContext context) {
    MockInterpreterA intpA = getInterpreterA();
    String intpASt = intpA.getLastStatement();
    long timeToSleep = Long.parseLong(st);
    if (intpASt != null) {
        timeToSleep += Long.parseLong(intpASt);
    }
    try {
        Thread.sleep(timeToSleep);
    } catch (NumberFormatException | InterruptedException e) {
        throw new InterpreterException(e);
    }
    return new InterpreterResult(Code.SUCCESS, Long.toString(timeToSleep));
}
Also used : InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult)

Example 9 with InterpreterException

use of org.apache.zeppelin.interpreter.InterpreterException in project zeppelin by apache.

the class InterpreterRestApi method updateSetting.

@PUT
@Path("setting/{settingId}")
@ZeppelinApi
public Response updateSetting(String message, @PathParam("settingId") String settingId) {
    logger.info("Update interpreterSetting {}", settingId);
    try {
        UpdateInterpreterSettingRequest request = gson.fromJson(message, UpdateInterpreterSettingRequest.class);
        interpreterSettingManager.setPropertyAndRestart(settingId, request.getOption(), request.getProperties(), request.getDependencies());
    } catch (InterpreterException e) {
        logger.error("Exception in InterpreterRestApi while updateSetting ", e);
        return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
    } catch (IOException e) {
        logger.error("Exception in InterpreterRestApi while updateSetting ", e);
        return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
    }
    InterpreterSetting setting = interpreterSettingManager.get(settingId);
    if (setting == null) {
        return new JsonResponse<>(Status.NOT_FOUND, "", settingId).build();
    }
    return new JsonResponse<>(Status.OK, "", setting).build();
}
Also used : InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) UpdateInterpreterSettingRequest(org.apache.zeppelin.rest.message.UpdateInterpreterSettingRequest) IOException(java.io.IOException) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) PUT(javax.ws.rs.PUT)

Example 10 with InterpreterException

use of org.apache.zeppelin.interpreter.InterpreterException in project zeppelin by apache.

the class InterpreterRestApi method newSettings.

/**
   * Add new interpreter setting
   *
   * @param message NewInterpreterSettingRequest
   */
@POST
@Path("setting")
@ZeppelinApi
public Response newSettings(String message) {
    try {
        NewInterpreterSettingRequest request = gson.fromJson(message, NewInterpreterSettingRequest.class);
        if (request == null) {
            return new JsonResponse<>(Status.BAD_REQUEST).build();
        }
        Properties p = new Properties();
        p.putAll(request.getProperties());
        InterpreterSetting interpreterSetting = interpreterSettingManager.createNewSetting(request.getName(), request.getGroup(), request.getDependencies(), request.getOption(), p);
        logger.info("new setting created with {}", interpreterSetting.getId());
        return new JsonResponse<>(Status.OK, "", interpreterSetting).build();
    } catch (InterpreterException | IOException e) {
        logger.error("Exception in InterpreterRestApi while creating ", e);
        return new JsonResponse<>(Status.NOT_FOUND, e.getMessage(), ExceptionUtils.getStackTrace(e)).build();
    }
}
Also used : InterpreterException(org.apache.zeppelin.interpreter.InterpreterException) InterpreterSetting(org.apache.zeppelin.interpreter.InterpreterSetting) NewInterpreterSettingRequest(org.apache.zeppelin.rest.message.NewInterpreterSettingRequest) IOException(java.io.IOException) Properties(java.util.Properties) JsonResponse(org.apache.zeppelin.server.JsonResponse) Path(javax.ws.rs.Path) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) POST(javax.ws.rs.POST)

Aggregations

InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)19 IOException (java.io.IOException)5 ZeppelinApi (org.apache.zeppelin.annotation.ZeppelinApi)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Method (java.lang.reflect.Method)3 Path (javax.ws.rs.Path)3 InterpreterContextRunner (org.apache.zeppelin.interpreter.InterpreterContextRunner)3 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)3 InterpreterSetting (org.apache.zeppelin.interpreter.InterpreterSetting)3 JsonResponse (org.apache.zeppelin.server.JsonResponse)3 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 PUT (javax.ws.rs.PUT)2 TTransportException (org.apache.thrift.transport.TTransportException)2 AngularObject (org.apache.zeppelin.display.AngularObject)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 Field (java.lang.reflect.Field)1 URL (java.net.URL)1