Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Merge "Bug 2055: Handle shard not initialized resiliently"
[controller.git]
/
opendaylight
/
config
/
shutdown-impl
/
src
/
main
/
java
/
org
/
opendaylight
/
controller
/
config
/
yang
/
shutdown
/
impl
/
ShutdownServiceImpl.java
diff --git
a/opendaylight/config/shutdown-impl/src/main/java/org/opendaylight/controller/config/yang/shutdown/impl/ShutdownServiceImpl.java
b/opendaylight/config/shutdown-impl/src/main/java/org/opendaylight/controller/config/yang/shutdown/impl/ShutdownServiceImpl.java
index f9622192fec873f3fc01c1396aa4c06ccb8f1624..7d97fcd9643bf049289770fb4a5d40d001919065 100644
(file)
--- a/
opendaylight/config/shutdown-impl/src/main/java/org/opendaylight/controller/config/yang/shutdown/impl/ShutdownServiceImpl.java
+++ b/
opendaylight/config/shutdown-impl/src/main/java/org/opendaylight/controller/config/yang/shutdown/impl/ShutdownServiceImpl.java
@@
-8,15
+8,14
@@
package org.opendaylight.controller.config.yang.shutdown.impl;
import com.google.common.base.Optional;
package org.opendaylight.controller.config.yang.shutdown.impl;
import com.google.common.base.Optional;
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
import org.opendaylight.controller.config.shutdown.ShutdownService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opendaylight.controller.config.shutdown.ShutdownService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadInfo;
-
public class ShutdownServiceImpl implements ShutdownService, AutoCloseable {
private final ShutdownService impl;
private final ShutdownRuntimeRegistration registration;
public class ShutdownServiceImpl implements ShutdownService, AutoCloseable {
private final ShutdownService impl;
private final ShutdownRuntimeRegistration registration;
@@
-42,7
+41,7
@@
public class ShutdownServiceImpl implements ShutdownService, AutoCloseable {
}
class Impl implements ShutdownService {
}
class Impl implements ShutdownService {
- private static final Logger
logger
= LoggerFactory.getLogger(Impl.class);
+ private static final Logger
LOG
= LoggerFactory.getLogger(Impl.class);
private final String secret;
private final Bundle systemBundle;
private final String secret;
private final Bundle systemBundle;
@@
-53,27
+52,27
@@
class Impl implements ShutdownService {
@Override
public void shutdown(String inputSecret, Long maxWaitTime, Optional<String> reason) {
@Override
public void shutdown(String inputSecret, Long maxWaitTime, Optional<String> reason) {
-
logger
.warn("Shutdown issued with secret {} and reason {}", inputSecret, reason);
+
LOG
.warn("Shutdown issued with secret {} and reason {}", inputSecret, reason);
try {
Thread.sleep(1000); // prevent brute force attack
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
try {
Thread.sleep(1000); // prevent brute force attack
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
-
logger
.warn("Shutdown process interrupted", e);
+
LOG
.warn("Shutdown process interrupted", e);
}
if (this.secret.equals(inputSecret)) {
}
if (this.secret.equals(inputSecret)) {
-
logger
.info("Server is shutting down");
+
LOG
.info("Server is shutting down");
// actual work:
Thread stopSystemBundleThread = new StopSystemBundleThread(systemBundle);
stopSystemBundleThread.start();
if (maxWaitTime != null && maxWaitTime > 0) {
Thread systemExitThread = new CallSystemExitThread(maxWaitTime);
// actual work:
Thread stopSystemBundleThread = new StopSystemBundleThread(systemBundle);
stopSystemBundleThread.start();
if (maxWaitTime != null && maxWaitTime > 0) {
Thread systemExitThread = new CallSystemExitThread(maxWaitTime);
-
logger
.debug("Scheduling {}", systemExitThread);
+
LOG
.debug("Scheduling {}", systemExitThread);
systemExitThread.start();
}
// end
} else {
systemExitThread.start();
}
// end
} else {
-
logger
.warn("Unauthorized attempt to shut down server");
+
LOG
.warn("Unauthorized attempt to shut down server");
throw new IllegalArgumentException("Invalid secret");
}
}
throw new IllegalArgumentException("Invalid secret");
}
}
@@
-81,8
+80,7
@@
class Impl implements ShutdownService {
}
class StopSystemBundleThread extends Thread {
}
class StopSystemBundleThread extends Thread {
- private static final Logger logger = LoggerFactory.getLogger(StopSystemBundleThread.class);
- public static final String CONFIG_MANAGER_SYMBOLIC_NAME = "org.opendaylight.controller.config-manager";
+ private static final Logger LOG = LoggerFactory.getLogger(StopSystemBundleThread.class);
private final Bundle systemBundle;
StopSystemBundleThread(Bundle systemBundle) {
private final Bundle systemBundle;
StopSystemBundleThread(Bundle systemBundle) {
@@
-95,35
+93,18
@@
class StopSystemBundleThread extends Thread {
try {
// wait so that JMX response is received
Thread.sleep(1000);
try {
// wait so that JMX response is received
Thread.sleep(1000);
- // first try to stop config-manager
- Bundle configManager = findConfigManager();
- if (configManager != null){
- logger.debug("Stopping config-manager");
- configManager.stop();
- Thread.sleep(1000);
- }
- logger.debug("Stopping system bundle");
+ LOG.debug("Stopping system bundle");
systemBundle.stop();
} catch (BundleException e) {
systemBundle.stop();
} catch (BundleException e) {
-
logger
.warn("Can not stop OSGi server", e);
+
LOG
.warn("Can not stop OSGi server", e);
} catch (InterruptedException e) {
} catch (InterruptedException e) {
-
logger
.warn("Shutdown process interrupted", e);
+
LOG
.warn("Shutdown process interrupted", e);
}
}
}
}
-
- private Bundle findConfigManager() {
- for(Bundle bundle: systemBundle.getBundleContext().getBundles()){
- if (CONFIG_MANAGER_SYMBOLIC_NAME.equals(bundle.getSymbolicName())) {
- return bundle;
- }
- }
- return null;
- }
-
}
class CallSystemExitThread extends Thread {
}
class CallSystemExitThread extends Thread {
- private static final Logger
logger
= LoggerFactory.getLogger(CallSystemExitThread.class);
+ private static final Logger
LOG
= LoggerFactory.getLogger(CallSystemExitThread.class);
private final long maxWaitTime;
CallSystemExitThread(long maxWaitTime) {
super("call-system-exit-daemon");
private final long maxWaitTime;
CallSystemExitThread(long maxWaitTime) {
super("call-system-exit-daemon");
@@
-146,7
+127,7
@@
class CallSystemExitThread extends Thread {
try {
// wait specified time
Thread.sleep(maxWaitTime);
try {
// wait specified time
Thread.sleep(maxWaitTime);
-
logger
.error("Since some threads are still running, server is going to shut down via System.exit(1) !");
+
LOG
.error("Since some threads are still running, server is going to shut down via System.exit(1) !");
// do a thread dump
ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
StringBuffer sb = new StringBuffer();
// do a thread dump
ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
StringBuffer sb = new StringBuffer();
@@
-154,10
+135,10
@@
class CallSystemExitThread extends Thread {
sb.append(info);
sb.append("\n");
}
sb.append(info);
sb.append("\n");
}
-
logger
.warn("Thread dump:{}", sb);
+
LOG
.warn("Thread dump:{}", sb);
System.exit(1);
} catch (InterruptedException e) {
System.exit(1);
} catch (InterruptedException e) {
-
logger
.warn("Interrupted, not going to call System.exit(1)");
+
LOG
.warn("Interrupted, not going to call System.exit(1)");
}
}
}
}
}
}