You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by am...@apache.org on 2014/11/13 12:49:50 UTC
[23/50] incubator-lens git commit: Fixed errors when shutting down
server in case of failed init
Fixed errors when shutting down server in case of failed init
Project: http://git-wip-us.apache.org/repos/asf/incubator-lens/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-lens/commit/b690a923
Tree: http://git-wip-us.apache.org/repos/asf/incubator-lens/tree/b690a923
Diff: http://git-wip-us.apache.org/repos/asf/incubator-lens/diff/b690a923
Branch: refs/heads/toapache
Commit: b690a923612e9e2fd58e909ad4f22ded164841f3
Parents: fab4c56
Author: jdhok <ja...@inmobi.com>
Authored: Tue Nov 11 12:21:09 2014 +0530
Committer: jdhok <ja...@inmobi.com>
Committed: Tue Nov 11 12:21:09 2014 +0530
----------------------------------------------------------------------
.../apache/lens/server/EventServiceImpl.java | 20 +++----
.../org/apache/lens/server/LensServices.java | 34 ++++++------
.../apache/lens/server/MetricsServiceImpl.java | 17 ++++--
.../lens/server/TestStartupOnMetastoreDown.java | 56 ++++++++++++++++++++
4 files changed, 98 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/b690a923/lens-server/src/main/java/org/apache/lens/server/EventServiceImpl.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/EventServiceImpl.java b/lens-server/src/main/java/org/apache/lens/server/EventServiceImpl.java
index 736b2d5..aadd0e1 100644
--- a/lens-server/src/main/java/org/apache/lens/server/EventServiceImpl.java
+++ b/lens-server/src/main/java/org/apache/lens/server/EventServiceImpl.java
@@ -197,19 +197,21 @@ public class EventServiceImpl extends AbstractService implements LensEventServic
*/
@Override
public void stop() {
- List<Runnable> pending = eventHandlerPool.shutdownNow();
- if (pending != null && !pending.isEmpty()) {
- StringBuilder pendingMsg = new StringBuilder("Pending Events:");
- for (Runnable handler : pending) {
- if (handler instanceof EventHandler) {
- pendingMsg.append(((EventHandler) handler).event.getEventId()).append(",");
+ if (eventHandlerPool != null) {
+ List<Runnable> pending = eventHandlerPool.shutdownNow();
+ if (pending != null && !pending.isEmpty()) {
+ StringBuilder pendingMsg = new StringBuilder("Pending Events:");
+ for (Runnable handler : pending) {
+ if (handler instanceof EventHandler) {
+ pendingMsg.append(((EventHandler) handler).event.getEventId()).append(",");
+ }
}
+ LOG.info("Event listener service stopped while " + pending.size() + " events still pending");
+ LOG.info(pendingMsg.toString());
}
- LOG.info("Event listener service stopped while " + pending.size() + " events still pending");
- LOG.info(pendingMsg.toString());
}
- super.stop();
LOG.info("Event service stopped");
+ super.stop();
}
public Map<Class<? extends LensEvent>, List<LensEventListener>> getEventListeners() {
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/b690a923/lens-server/src/main/java/org/apache/lens/server/LensServices.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/LensServices.java b/lens-server/src/main/java/org/apache/lens/server/LensServices.java
index f345b72..fe2fc75 100644
--- a/lens-server/src/main/java/org/apache/lens/server/LensServices.java
+++ b/lens-server/src/main/java/org/apache/lens/server/LensServices.java
@@ -266,24 +266,26 @@ public class LensServices extends CompositeService implements ServiceProvider {
*/
private synchronized void persistLensServiceState() throws IOException {
if (conf.getBoolean(LensConfConstants.SERVER_RESTART_ENABLED, LensConfConstants.DEFAULT_SERVER_RESTART_ENABLED)) {
- FileSystem fs = persistDir.getFileSystem(conf);
- LOG.info("Persisting server state in " + persistDir);
-
- for (LensService service : lensServices) {
- LOG.info("Persisting state of service:" + service.getName());
- Path serviceWritePath = new Path(persistDir, service.getName() + ".out");
- ObjectOutputStream out = null;
- try {
- out = new ObjectOutputStream(fs.create(serviceWritePath));
- service.writeExternal(out);
- } finally {
- if (out != null) {
- out.close();
+ if (persistDir != null) {
+ FileSystem fs = persistDir.getFileSystem(conf);
+ LOG.info("Persisting server state in " + persistDir);
+
+ for (LensService service : lensServices) {
+ LOG.info("Persisting state of service:" + service.getName());
+ Path serviceWritePath = new Path(persistDir, service.getName() + ".out");
+ ObjectOutputStream out = null;
+ try {
+ out = new ObjectOutputStream(fs.create(serviceWritePath));
+ service.writeExternal(out);
+ } finally {
+ if (out != null) {
+ out.close();
+ }
}
+ Path servicePath = getServicePersistPath(service);
+ fs.rename(serviceWritePath, servicePath);
+ LOG.info("Persisted service " + service.getName() + " to " + servicePath);
}
- Path servicePath = getServicePersistPath(service);
- fs.rename(serviceWritePath, servicePath);
- LOG.info("Persisted service " + service.getName() + " to " + servicePath);
}
} else {
LOG.info("Server restart is not enabled. Not persisting the server state");
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/b690a923/lens-server/src/main/java/org/apache/lens/server/MetricsServiceImpl.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/MetricsServiceImpl.java b/lens-server/src/main/java/org/apache/lens/server/MetricsServiceImpl.java
index 01cbb16..b0774e0 100644
--- a/lens-server/src/main/java/org/apache/lens/server/MetricsServiceImpl.java
+++ b/lens-server/src/main/java/org/apache/lens/server/MetricsServiceImpl.java
@@ -279,11 +279,20 @@ public class MetricsServiceImpl extends AbstractService implements MetricsServic
public synchronized void stop() {
// unregister
LensEventService eventService = (LensEventService) LensServices.get().getService(LensEventService.NAME);
- eventService.removeListener(queryStatusListener);
- queryStatusListener.stop();
- for (ScheduledReporter reporter : reporters) {
- reporter.stop();
+ if (eventService != null) {
+ eventService.removeListener(queryStatusListener);
+ }
+
+ if (queryStatusListener != null) {
+ queryStatusListener.stop();
}
+
+ if (reporters != null) {
+ for (ScheduledReporter reporter : reporters) {
+ reporter.stop();
+ }
+ }
+
LOG.info("Stopped metrics service");
super.stop();
}
http://git-wip-us.apache.org/repos/asf/incubator-lens/blob/b690a923/lens-server/src/test/java/org/apache/lens/server/TestStartupOnMetastoreDown.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/TestStartupOnMetastoreDown.java b/lens-server/src/test/java/org/apache/lens/server/TestStartupOnMetastoreDown.java
new file mode 100644
index 0000000..2254bd8
--- /dev/null
+++ b/lens-server/src/test/java/org/apache/lens/server/TestStartupOnMetastoreDown.java
@@ -0,0 +1,56 @@
+/**
+ * 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestStartupOnMetastoreDown {
+ private static Log LOG = LogFactory.getLog(TestStartupOnMetastoreDown.class);
+
+ // @Test
+ public void testServicesStartOnMetastoreDown() throws Exception {
+ LensServices services = new LensServices(LensServices.LENS_SERVICES_NAME);
+ HiveConf hiveConf = new HiveConf();
+
+ // Set metastore uri to an invalid location
+ hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://localhost:49153");
+
+ try {
+ services.init(hiveConf);
+ Assert.fail("Expected init to fail because of invalid metastore config");
+ } catch (Throwable th) {
+ Assert.assertTrue(th.getMessage().contains(
+ "Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient"));
+ } finally {
+ try {
+ services.stop();
+ } catch (Exception exc) {
+ LOG.error("Error stopping services", exc);
+ Assert.fail("services.stop() got unexpected exception " + exc);
+ }
+ Hive.closeCurrent();
+ }
+ }
+
+}