You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by jd...@apache.org on 2014/12/15 17:17:55 UTC
incubator-lens git commit: LENS-104 Expose session interface in
server-api (Jothi Padmanabhan via jdhok)
Repository: incubator-lens
Updated Branches:
refs/heads/master f9cbfe260 -> d98c43201
LENS-104 Expose session interface in server-api (Jothi Padmanabhan via jdhok)
Project: http://git-wip-us.apache.org/repos/asf/incubator-lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-lens/commit/d98c4320
Tree: http://git-wip-us.apache.org/repos/asf/incubator-lens/tree/d98c4320
Diff: http://git-wip-us.apache.org/repos/asf/incubator-lens/diff/d98c4320
Branch: refs/heads/master
Commit: d98c432016b7b061d85b77e16a8faffd58572490
Parents: f9cbfe2
Author: jdhok <ja...@inmobi.com>
Authored: Mon Dec 15 21:47:36 2014 +0530
Committer: jdhok <ja...@inmobi.com>
Committed: Mon Dec 15 21:47:36 2014 +0530
----------------------------------------------------------------------
.../java/org/apache/lens/ml/TestMLResource.java | 3 +-
.../lens/server/api/session/SessionService.java | 119 +++++++++++++++++++
.../lens/server/session/HiveSessionService.java | 67 +++--------
.../lens/server/session/SessionResource.java | 5 +-
.../lens/server/ui/SessionUIResource.java | 7 +-
.../server/session/TestSessionResource.java | 5 +-
6 files changed, 147 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/d98c4320/lens-ml-lib/src/test/java/org/apache/lens/ml/TestMLResource.java
----------------------------------------------------------------------
diff --git a/lens-ml-lib/src/test/java/org/apache/lens/ml/TestMLResource.java b/lens-ml-lib/src/test/java/org/apache/lens/ml/TestMLResource.java
index a0abe93..d1318fc 100644
--- a/lens-ml-lib/src/test/java/org/apache/lens/ml/TestMLResource.java
+++ b/lens-ml-lib/src/test/java/org/apache/lens/ml/TestMLResource.java
@@ -51,6 +51,7 @@ import org.apache.lens.server.LensServerConf;
import org.apache.lens.server.api.LensConfConstants;
import org.apache.lens.server.api.ServiceProvider;
import org.apache.lens.server.api.ServiceProviderFactory;
+import org.apache.lens.server.api.session.SessionService;
import org.apache.lens.server.ml.MLApp;
import org.apache.lens.server.ml.MLService;
import org.apache.lens.server.ml.MLServiceImpl;
@@ -109,7 +110,7 @@ public class TestMLResource extends LensJerseyTest {
public void setUp() throws Exception {
super.setUp();
setServiceProvider();
- HiveSessionService sessionService = serviceProvider.getService(HiveSessionService.NAME);
+ HiveSessionService sessionService = serviceProvider.getService(SessionService.NAME);
this.sessionHandle = sessionService.openSession("foo@localhost", "bar", new HashMap<String, String>());
mlClient = new LensMLClient(connectionParams, sessionHandle);
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/d98c4320/lens-server-api/src/main/java/org/apache/lens/server/api/session/SessionService.java
----------------------------------------------------------------------
diff --git a/lens-server-api/src/main/java/org/apache/lens/server/api/session/SessionService.java b/lens-server-api/src/main/java/org/apache/lens/server/api/session/SessionService.java
new file mode 100644
index 0000000..67b694a
--- /dev/null
+++ b/lens-server-api/src/main/java/org/apache/lens/server/api/session/SessionService.java
@@ -0,0 +1,119 @@
+/**
+ * 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.lens.server.api.session;
+
+import org.apache.lens.api.LensException;
+import org.apache.lens.api.LensSessionHandle;
+
+import java.util.List;
+import java.util.Map;
+
+public interface SessionService {
+
+ /** The Constant NAME. */
+ public static final String NAME = "session";
+
+ /**
+ * Open session.
+ *
+ * @param username the username
+ * @param password the password
+ * @param configuration the configuration
+ * @return the lens session handle
+ * @throws LensException the lens exception
+ */
+
+ public LensSessionHandle openSession(String username, String password, Map<String, String> configuration)
+ throws LensException;
+
+ /**
+ * Restore session from previous instance of lens server.
+ *
+ * @param sessionHandle the session handle
+ * @param userName the user name
+ * @param password the password
+ * @throws LensException the lens exception
+ */
+
+ public void restoreSession(LensSessionHandle sessionHandle, String userName, String password) throws LensException;
+
+ /**
+ * Close session.
+ *
+ * @param sessionHandle the session handle
+ * @throws LensException the lens exception
+ */
+
+ public void closeSession(LensSessionHandle sessionHandle) throws LensException;
+
+ /**
+ * Adds the resource.
+ *
+ * @param sessionHandle the session handle
+ * @param type the type
+ * @param path the path
+ * @throws LensException the lens exception
+ */
+
+ public void addResource(LensSessionHandle sessionHandle, String type, String path);
+
+ /**
+ * Delete resource.
+ *
+ * @param sessionHandle the session handle
+ * @param type the type
+ * @param path the path
+ * @throws LensException the lens exception
+ */
+
+ public void deleteResource(LensSessionHandle sessionHandle, String type, String path);
+
+
+ /**
+ * Gets the all session parameters.
+ *
+ * @param sessionHandle the sessionid
+ * @param verbose the verbose
+ * @param key the key
+ * @return the all session parameters
+ * @throws LensException the lens exception
+ */
+ public List<String> getAllSessionParameters(LensSessionHandle sessionHandle, boolean verbose, String key)
+ throws LensException;
+
+ /**
+ * Sets the session parameter.
+ *
+ * @param sessionHandle the sessionid
+ * @param key the key
+ * @param value the value
+ */
+ public void setSessionParameter(LensSessionHandle sessionHandle, String key, String value);
+
+ /**
+ * Adds the resource to all services.
+ *
+ * @param sessionHandle the sessionid
+ * @param type the type
+ * @param path the path
+ * @return the number of services that the resource has been added to
+ */
+ public int addResourceToAllServices(LensSessionHandle sessionHandle, String type, String path);
+}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/d98c4320/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java b/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java
index f45fe3c..7641232 100644
--- a/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java
+++ b/lens-server/src/main/java/org/apache/lens/server/session/HiveSessionService.java
@@ -30,6 +30,7 @@ import org.apache.lens.api.LensSessionHandle;
import org.apache.lens.server.LensService;
import org.apache.lens.server.LensServices;
import org.apache.lens.server.api.LensConfConstants;
+import org.apache.lens.server.api.session.SessionService;
import org.apache.lens.server.query.QueryExecutionServiceImpl;
import javax.ws.rs.NotFoundException;
@@ -45,13 +46,11 @@ import java.util.concurrent.TimeUnit;
/**
* The Class HiveSessionService.
*/
-public class HiveSessionService extends LensService {
+public class HiveSessionService extends LensService implements SessionService {
/** The Constant LOG. */
public static final Log LOG = LogFactory.getLog(HiveSessionService.class);
- /** The Constant NAME. */
- public static final String NAME = "session";
/** The restorable sessions. */
private List<LensSessionImpl.LensSessionPersistInfo> restorableSessions;
@@ -73,15 +72,7 @@ public class HiveSessionService extends LensService {
}
/**
- * Adds the resource to all services.
- *
- * @param sessionid
- * the sessionid
- * @param type
- * the type
- * @param path
- * the path
- * @return the int
+ * @inheritDoc
*/
public int addResourceToAllServices(LensSessionHandle sessionid, String type, String path) {
int numAdded = 0;
@@ -102,12 +93,10 @@ public class HiveSessionService extends LensService {
return numAdded;
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.lens.server.LensService#addResource(org.apache.lens.api.LensSessionHandle, java.lang.String,
- * java.lang.String)
+ /**
+ * @inheritDoc
*/
+ @Override
public void addResource(LensSessionHandle sessionid, String type, String path) {
String command = "add " + type.toLowerCase() + " " + path;
try {
@@ -120,12 +109,10 @@ public class HiveSessionService extends LensService {
}
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.lens.server.LensService#deleteResource(org.apache.lens.api.LensSessionHandle, java.lang.String,
- * java.lang.String)
+ /**
+ * @inheritDoc
*/
+ @Override
public void deleteResource(LensSessionHandle sessionid, String type, String path) {
String command = "delete " + type.toLowerCase() + " " + path;
try {
@@ -173,11 +160,10 @@ public class HiveSessionService extends LensService {
}
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.lens.server.LensService#openSession(java.lang.String, java.lang.String, java.util.Map)
+ /**
+ * @inheritDoc
*/
+ @Override
public LensSessionHandle openSession(String username, String password, Map<String, String> configuration)
throws LensException {
LensSessionHandle sessionid = super.openSession(username, password, configuration);
@@ -194,18 +180,9 @@ public class HiveSessionService extends LensService {
}
/**
- * Gets the all session parameters.
- *
- * @param sessionid
- * the sessionid
- * @param verbose
- * the verbose
- * @param key
- * the key
- * @return the all session parameters
- * @throws LensException
- * the lens exception
+ * @inheritDoc
*/
+ @Override
public List<String> getAllSessionParameters(LensSessionHandle sessionid, boolean verbose, String key)
throws LensException {
List<String> result = new ArrayList<String>();
@@ -235,15 +212,9 @@ public class HiveSessionService extends LensService {
}
/**
- * Sets the session parameter.
- *
- * @param sessionid
- * the sessionid
- * @param key
- * the key
- * @param value
- * the value
+ * @inheritDoc
*/
+ @Override
public void setSessionParameter(LensSessionHandle sessionid, String key, String value) {
setSessionParameter(sessionid, key, value, true);
}
@@ -389,10 +360,8 @@ public class HiveSessionService extends LensService {
LOG.info("Session service recovered " + sessionMap.size() + " sessions");
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.lens.server.LensService#closeSession(org.apache.lens.api.LensSessionHandle)
+ /**
+ * @inheritDoc
*/
@Override
public void closeSession(LensSessionHandle sessionHandle) throws LensException {
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/d98c4320/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java b/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java
index 4d4bb53..b3cf2c3 100644
--- a/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java
+++ b/lens-server/src/main/java/org/apache/lens/server/session/SessionResource.java
@@ -44,6 +44,7 @@ import org.apache.lens.api.StringList;
import org.apache.lens.api.APIResult.Status;
import org.apache.lens.server.LensService;
import org.apache.lens.server.LensServices;
+import org.apache.lens.server.api.session.SessionService;
import org.glassfish.jersey.media.multipart.FormDataParam;
/**
@@ -58,7 +59,7 @@ public class SessionResource {
public static final Log LOG = LogFactory.getLog(SessionResource.class);
/** The session service. */
- private HiveSessionService sessionService;
+ private SessionService sessionService;
/**
* API to know if session service is up and running
@@ -78,7 +79,7 @@ public class SessionResource {
* the lens exception
*/
public SessionResource() throws LensException {
- sessionService = (HiveSessionService) LensServices.get().getService("session");
+ sessionService = (SessionService) LensServices.get().getService("session");
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/d98c4320/lens-server/src/main/java/org/apache/lens/server/ui/SessionUIResource.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/ui/SessionUIResource.java b/lens-server/src/main/java/org/apache/lens/server/ui/SessionUIResource.java
index 29dc669..1e75879 100644
--- a/lens-server/src/main/java/org/apache/lens/server/ui/SessionUIResource.java
+++ b/lens-server/src/main/java/org/apache/lens/server/ui/SessionUIResource.java
@@ -26,8 +26,7 @@ import org.apache.lens.api.LensException;
import org.apache.lens.api.LensSessionHandle;
import org.apache.lens.api.APIResult.Status;
import org.apache.lens.server.LensServices;
-import org.apache.lens.server.session.HiveSessionService;
-import org.apache.lens.server.session.SessionResource;
+import org.apache.lens.server.api.session.SessionService;
import org.glassfish.jersey.media.multipart.FormDataParam;
import javax.ws.rs.*;
@@ -51,7 +50,7 @@ public class SessionUIResource {
public static HashMap<UUID, LensSessionHandle> openSessions = new HashMap<UUID, LensSessionHandle>();
/** The session service. */
- private HiveSessionService sessionService;
+ private SessionService sessionService;
/**
* API to know if session service is up and running
@@ -71,7 +70,7 @@ public class SessionUIResource {
* the lens exception
*/
public SessionUIResource() throws LensException {
- sessionService = (HiveSessionService) LensServices.get().getService("session");
+ sessionService = (SessionService) LensServices.get().getService("session");
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/d98c4320/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java b/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java
index 10f65b2..109b36d 100644
--- a/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java
+++ b/lens-server/src/test/java/org/apache/lens/server/session/TestSessionResource.java
@@ -30,8 +30,7 @@ import org.apache.lens.api.APIResult.Status;
import org.apache.lens.server.LensJerseyTest;
import org.apache.lens.server.LensServices;
import org.apache.lens.server.api.LensConfConstants;
-import org.apache.lens.server.session.HiveSessionService;
-import org.apache.lens.server.session.SessionApp;
+import org.apache.lens.server.api.session.SessionService;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
@@ -260,7 +259,7 @@ public class TestSessionResource extends LensJerseyTest {
Assert.assertNotNull(handle);
// verify aux jars are loaded
- HiveSessionService service = (HiveSessionService) LensServices.get().getService(HiveSessionService.NAME);
+ HiveSessionService service = (HiveSessionService) LensServices.get().getService(SessionService.NAME);
ClassLoader loader = service.getSession(handle).getSessionState().getConf().getClassLoader();
boolean found = false;
for (URL path : ((URLClassLoader) loader).getURLs()) {