@Override public String toString() { return "LensConnection{" + "sessionHandle=" + sessionHandle.getPublicId() + '}'; } }
/** * Value of. * * @param sessionStr the session str * @return the lens session handle */ public static LensSessionHandle valueOf(String sessionStr) { return valueOf(sessionStr, LensSessionHandle.class); } }
/** * Gets the hive session handle. * * @param lensHandle the lens handle * @return the hive session handle */ public static SessionHandle getHiveSessionHandle(LensSessionHandle lensHandle) { return new SessionHandle(new HandleIdentifier(lensHandle.getPublicId(), lensHandle.getSecretId()), CLIService.SERVER_VERSION); }
HandleIdentifier handleIdentifier = new HandleIdentifier(sessionHandle.getPublicId(), sessionHandle.getSecretId()); SessionHandle hiveSessionHandle = new SessionHandle(new TSessionHandle(handleIdentifier.toTHandleIdentifier())); try { cliService.createSessionWithSessionHandle(hiveSessionHandle, userName, password, new HashMap<>()); LensSessionHandle restoredSession = new LensSessionHandle(hiveSessionHandle.getHandleIdentifier().getPublicId(), hiveSessionHandle.getHandleIdentifier().getSecretId()); SESSION_MAP.put(restoredSession.getPublicId().toString(), restoredSession);
throw new LensException(e); LensSessionHandle lensSessionHandle = new LensSessionHandle(sessionHandle.getHandleIdentifier().getPublicId(), sessionHandle.getHandleIdentifier().getSecretId()); SESSION_MAP.put(lensSessionHandle.getPublicId().toString(), lensSessionHandle); updateSessionsPerUser(username); return lensSessionHandle;
/** * Inits the persist info. * @param sessionConf the session conf */ private void initPersistInfo(Map<String, String> sessionConf) { persistInfo.setSessionHandle(new LensSessionHandle(getSessionHandle().getHandleIdentifier().getPublicId(), getSessionHandle().getHandleIdentifier().getSecretId())); persistInfo.setUsername(getUserName()); persistInfo.setPassword(getPassword()); persistInfo.setLastAccessTime(System.currentTimeMillis()); persistInfo.setSessionConf(sessionConf); persistInfo.setProxyUser(sessionConf.get(LensConfConstants.SESSION_PROXY_USER)); if (sessionConf != null) { for (Map.Entry<String, String> entry : sessionConf.entrySet()) { conf.set(entry.getKey(), entry.getValue()); } } }
@Override public void writeExternal(ObjectOutput out) throws IOException { out.writeUTF(sessionHandle.toString()); out.writeUTF(database == null ? "default" : database); out.writeUTF(username == null ? "" : username); out.writeUTF(password == null ? "" : password); out.writeInt(resources.size()); for (ResourceEntry resource : resources) { out.writeUTF(resource.getType()); out.writeUTF(resource.getUri()); } out.writeInt(config.size()); for (String key : config.keySet()) { out.writeUTF(key); out.writeUTF(config.get(key)); } out.writeLong(lastAccessTime); out.writeBoolean(markedForClose); out.writeUTF(proxyUser == null ? "" : proxyUser); }
new ArrayList<SchedulerJobInstanceRun>()); SchedulerJobInstanceRun run1 = new SchedulerJobInstanceRun(instanceHandle, 1, new LensSessionHandle(UUID.randomUUID(), UUID.randomUUID()), currentTime, currentTime, "/tmp/", QueryHandle.fromString(UUID.randomUUID().toString()), SchedulerJobInstanceState.WAITING); instances.put(firstInstance.getId(), firstInstance); new ArrayList<SchedulerJobInstanceRun>()); SchedulerJobInstanceRun run2 = new SchedulerJobInstanceRun(instanceHandle, 1, new LensSessionHandle(UUID.randomUUID(), UUID.randomUUID()), currentTime, currentTime, "/tmp/", QueryHandle.fromString(UUID.randomUUID().toString()), SchedulerJobInstanceState.WAITING); instances.put(secondInstance.getId(), secondInstance);
public int insertIntoJobInstanceRunTable(SchedulerJobInstanceRun instanceRun) throws SQLException { String insetSQL = "INSERT INTO " + JOB_INSTANCE_RUN_TABLE + " VALUES(?,?,?,?,?,?,?,?)"; return runner.update(insetSQL, instanceRun.getHandle().getHandleIdString(), instanceRun.getRunId(), instanceRun.getSessionHandle() == null ? "" : instanceRun.getSessionHandle().toString(), instanceRun.getStartTime(), instanceRun.getEndTime(), instanceRun.getResultPath(), instanceRun.getQueryHandle() == null ? "" : instanceRun.getQueryHandle().getHandleIdString(), instanceRun.getInstanceState().name()); }
@Override public String toString() { return "LensConnection{" + "sessionHandle=" + sessionHandle.getPublicId() + '}'; } }
/** * Value of. * * @param sessionStr the session str * @return the lens session handle */ public static LensSessionHandle valueOf(String sessionStr) { return valueOf(sessionStr, LensSessionHandle.class); } }
LensSessionHandle sessionHandle = new LensSessionHandle(UUID.randomUUID(), UUID.randomUUID()); String user = "user"; long now = System.currentTimeMillis();
/** * Checks for lens session. * * @param session the session * @return true, if successful */ public boolean hasLensSession(LensSessionHandle session) { return lensToHiveSession.containsKey(session.getPublicId().toString()); } }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { sessionHandle = LensSessionHandle.valueOf(in.readUTF()); database = in.readUTF(); username = in.readUTF(); password = in.readUTF(); int resSize = in.readInt(); resources.clear(); for (int i = 0; i < resSize; i++) { String type = in.readUTF(); String uri = in.readUTF(); resources.add(new ResourceEntry(type, uri)); } config.clear(); int cfgSize = in.readInt(); for (int i = 0; i < cfgSize; i++) { String key = in.readUTF(); String val = in.readUTF(); config.put(key, val); } lastAccessTime = in.readLong(); markedForClose = in.readBoolean(); proxyUser = in.readUTF(); } }
/** * Checks for lens session. * * @param session the session * @return true, if successful */ public boolean hasLensSession(LensSessionHandle session) { return lensToHiveSession.containsKey(session.getPublicId().toString()); } }
private List<SchedulerJobInstanceRun> processInstanceRun(List<Object[]> instanceRuns) throws SQLException { List<SchedulerJobInstanceRun> runList = new ArrayList<>(); for (Object[] run : instanceRuns) { // run[0] will contain the instanceID SchedulerJobInstanceHandle id = SchedulerJobInstanceHandle.fromString((String) run[0]); int runId = (Integer) run[1]; LensSessionHandle sessionHandle = LensSessionHandle.valueOf((String) run[2]); long starttime = (Long) run[3]; long endtime = (Long) run[4]; String resultPath = (String) run[5]; String queryHandleString = (String) run[6]; QueryHandle queryHandle = null; if (!queryHandleString.isEmpty()) { queryHandle = QueryHandle.fromString((String) run[6]); } SchedulerJobInstanceState instanceStatus = SchedulerJobInstanceState.valueOf((String) run[7]); SchedulerJobInstanceRun instanceRun = new SchedulerJobInstanceRun(id, runId, sessionHandle, starttime, endtime, resultPath, queryHandle, instanceStatus); runList.add(instanceRun); } return runList; }
@Override public boolean isOpen(LensSessionHandle sessionHandle) { return SESSION_MAP.containsKey(sessionHandle.getPublicId().toString()); }
protected void registerPredictUdf(LensSessionHandle sessionHandle, QueryRunner queryRunner) throws LensException { if (isUdfRegisterd(sessionHandle)) { // Already registered, nothing to do return; } log.info("Registering UDF for session " + sessionHandle.getPublicId().toString()); String regUdfQuery = "CREATE TEMPORARY FUNCTION " + HiveMLUDF.UDF_NAME + " AS '" + HiveMLUDF.class .getCanonicalName() + "'"; queryRunner.setQueryName("register_predict_udf_" + sessionHandle.getPublicId().toString()); QueryHandle udfQuery = queryRunner.runQuery(regUdfQuery); log.info("udf query handle is " + udfQuery); predictUdfStatus.put(sessionHandle, true); log.info("Predict UDF registered for session " + sessionHandle.getPublicId().toString()); }
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { int numSessions = in.readInt(); restorableSessions = new ArrayList<LensSessionImpl.LensSessionPersistInfo>(); for (int i = 0; i < numSessions; i++) { LensSessionImpl.LensSessionPersistInfo persistInfo = new LensSessionImpl.LensSessionPersistInfo(); persistInfo.readExternal(in); restorableSessions.add(persistInfo); SESSION_MAP.put(persistInfo.getSessionHandle().getPublicId().toString(), persistInfo.getSessionHandle()); } log.info("Session service recovered " + SESSION_MAP.size() + " sessions"); }
/** * Release. * * @param sessionHandle the session handle */ public void release(LensSessionHandle sessionHandle) { if (sessionHandle != null) { getSession(sessionHandle).release(); log.debug("Released lens session:{}", sessionHandle.getPublicId()); } }