knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject [knox] branch master updated: KNOX-2130 - Handle InterruptedException better (#199)
Date Sun, 17 Nov 2019 14:53:33 GMT
This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b244d7  KNOX-2130 - Handle InterruptedException better (#199)
9b244d7 is described below

commit 9b244d7b4101f386bb71bc4244c77e37d0dfb0b5
Author: Kevin Risden <risdenk@users.noreply.github.com>
AuthorDate: Sun Nov 17 09:53:23 2019 -0500

    KNOX-2130 - Handle InterruptedException better (#199)
    
    Signed-off-by: Kevin Risden <krisden@apache.org>
---
 .../ambari/AmbariConfigurationMonitor.java         |  3 +-
 .../ha/dispatch/ConfigurableHADispatch.java        |  1 +
 .../gateway/ha/dispatch/DefaultHaDispatch.java     |  2 +-
 .../topology/impl/DefaultTopologyService.java      | 32 +++++++++-------------
 .../gateway/rm/dispatch/RMHaBaseDispatcher.java    |  1 +
 .../hdfs/dispatch/AbstractHdfsHaDispatch.java      |  4 +--
 .../org/apache/knox/gateway/shell/KnoxSession.java | 10 ++-----
 .../gateway/dispatch/KnoxSpnegoAuthScheme.java     |  3 +-
 .../services/security/impl/CMFMasterService.java   | 10 +++----
 .../main/java/org/apache/knox/test/TestUtils.java  |  7 ++---
 .../appender/JdbmStoreAndForwardAppender.java      |  7 +++--
 11 files changed, 35 insertions(+), 45 deletions(-)

diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
index fc8cc96..7867c6e 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
@@ -475,7 +475,6 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor
{
             this.interval = interval;
         }
 
-
         void stop() {
             isActive = false;
         }
@@ -521,7 +520,7 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor
{
                 try {
                     Thread.sleep(interval * 1000L);
                 } catch (InterruptedException e) {
-                    // Ignore
+                    Thread.currentThread().interrupt();
                 }
             }
         }
diff --git a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
index 137b131..a5425d8 100644
--- a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
+++ b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
@@ -116,6 +116,7 @@ public class ConfigurableHADispatch extends ConfigurableDispatch {
           Thread.sleep(failoverSleep);
         } catch ( InterruptedException e ) {
           LOG.failoverSleepFailed(getServiceRole(), e);
+          Thread.currentThread().interrupt();
         }
       }
       executeRequest(outboundRequest, inboundRequest, outboundResponse);
diff --git a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatch.java
b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatch.java
index d53747a..698427a 100644
--- a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatch.java
+++ b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/DefaultHaDispatch.java
@@ -114,6 +114,7 @@ public class DefaultHaDispatch extends DefaultDispatch {
           Thread.sleep(failoverSleep);
         } catch ( InterruptedException e ) {
           LOG.failoverSleepFailed(getServiceRole(), e);
+          Thread.currentThread().interrupt();
         }
       }
       executeRequest(outboundRequest, inboundRequest, outboundResponse);
@@ -126,5 +127,4 @@ public class DefaultHaDispatch extends DefaultDispatch {
       }
     }
   }
-
 }
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
index 85470f9..4a1101d 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
@@ -72,7 +72,6 @@ import javax.xml.bind.Marshaller;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.IOException;
-import java.net.URISyntaxException;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -87,9 +86,8 @@ import java.util.Set;
 
 import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
 
-public class DefaultTopologyService
-    extends FileAlterationListenerAdaptor
-    implements TopologyService, TopologyMonitor, TopologyProvider, FileFilter, FileAlterationListener,
ServiceDefinitionChangeListener {
+public class DefaultTopologyService extends FileAlterationListenerAdaptor implements TopologyService,
TopologyMonitor,
+    TopologyProvider, FileFilter, FileAlterationListener, ServiceDefinitionChangeListener
{
 
   private static final JAXBContext jaxbContext = getJAXBContext();
 
@@ -97,14 +95,11 @@ public class DefaultTopologyService
     AuditConstants.DEFAULT_AUDITOR_NAME, AuditConstants.KNOX_SERVICE_NAME,
     AuditConstants.KNOX_COMPONENT_NAME);
 
-  private static final List<String> SUPPORTED_TOPOLOGY_FILE_EXTENSIONS = new ArrayList<>();
-  static {
-    SUPPORTED_TOPOLOGY_FILE_EXTENSIONS.add("xml");
-    SUPPORTED_TOPOLOGY_FILE_EXTENSIONS.add("conf");
-  }
+  private static final List<String> SUPPORTED_TOPOLOGY_FILE_EXTENSIONS = Arrays.asList("xml",
"conf");
 
   private static GatewayMessages log = MessagesFactory.get(GatewayMessages.class);
-  private static DigesterLoader digesterLoader = newLoader(new KnoxFormatXmlTopologyRules(),
new AmbariFormatXmlTopologyRules());
+  private static DigesterLoader digesterLoader = newLoader(new KnoxFormatXmlTopologyRules(),
+      new AmbariFormatXmlTopologyRules());
   private List<FileAlterationMonitor> monitors = new ArrayList<>();
   private File topologiesDirectory;
   private File sharedProvidersDirectory;
@@ -133,7 +128,7 @@ public class DefaultTopologyService
     }
   }
 
-  private Topology loadTopology(File file) throws IOException, SAXException, URISyntaxException,
InterruptedException {
+  private Topology loadTopology(File file) throws IOException, SAXException, InterruptedException
{
     final long TIMEOUT = 250; //ms
     final long DELAY = 50; //ms
     log.loadingTopologyFile(file.getAbsolutePath());
@@ -155,7 +150,7 @@ public class DefaultTopologyService
     return topology;
   }
 
-  private Topology loadTopologyAttempt(File file) throws IOException, SAXException, URISyntaxException
{
+  private Topology loadTopologyAttempt(File file) throws IOException, SAXException {
     Topology topology;
     Digester digester = digesterLoader.newDigester();
     TopologyBuilder topologyBuilder = digester.parse(FileUtils.openInputStream(file));
@@ -207,10 +202,9 @@ public class DefaultTopologyService
             break;
           }
         } catch (InterruptedException e) {
-          auditor.audit(Action.REDEPLOY, topology.getName(), ResourceType.TOPOLOGY,
-              ActionOutcome.FAILURE);
+          auditor.audit(Action.REDEPLOY, topology.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE);
           log.failedToRedeployTopology(topology.getName(), e);
-          e.printStackTrace();
+          Thread.currentThread().interrupt();
         }
       }
     } catch (SAXException e) {
@@ -258,7 +252,7 @@ public class DefaultTopologyService
     return configDir.getAbsoluteFile();
   }
 
-  private void  initListener(FileAlterationMonitor  monitor,
+  private void initListener(FileAlterationMonitor  monitor,
                             File                   directory,
                             FileFilter             filter,
                             FileAlterationListener listener) {
@@ -268,7 +262,7 @@ public class DefaultTopologyService
     monitor.addObserver(observer);
   }
 
-  private void initListener(File directory, FileFilter filter, FileAlterationListener listener)
throws IOException, SAXException {
+  private void initListener(File directory, FileFilter filter, FileAlterationListener listener)
{
     // Increasing the monitoring interval to 5 seconds as profiling has shown
     // this is rather expensive in terms of generated garbage objects.
     initListener(new FileAlterationMonitor(5000L), directory, filter, listener);
@@ -691,8 +685,8 @@ public class DefaultTopologyService
       // Initialize the remote configuration monitor, if it has been configured
       remoteMonitor = RemoteConfigurationMonitorFactory.get(config);
 
-    } catch (IOException | SAXException io) {
-      throw new ServiceLifecycleException(io.getMessage());
+    } catch (IOException io) {
+      throw new ServiceLifecycleException(io.getMessage(), io);
     }
   }
 
diff --git a/gateway-service-rm/src/main/java/org/apache/knox/gateway/rm/dispatch/RMHaBaseDispatcher.java
b/gateway-service-rm/src/main/java/org/apache/knox/gateway/rm/dispatch/RMHaBaseDispatcher.java
index caec73a..b9438aa 100644
--- a/gateway-service-rm/src/main/java/org/apache/knox/gateway/rm/dispatch/RMHaBaseDispatcher.java
+++ b/gateway-service-rm/src/main/java/org/apache/knox/gateway/rm/dispatch/RMHaBaseDispatcher.java
@@ -135,6 +135,7 @@ class  RMHaBaseDispatcher extends DefaultDispatch {
                 Thread.sleep(failoverSleep);
              } catch (InterruptedException e) {
                 LOG.failoverSleepFailed(this.resourceRole, e);
+                Thread.currentThread().interrupt();
              }
           }
           executeRequest(outboundRequest, inboundRequest, outboundResponse);
diff --git a/gateway-service-webhdfs/src/main/java/org/apache/knox/gateway/hdfs/dispatch/AbstractHdfsHaDispatch.java
b/gateway-service-webhdfs/src/main/java/org/apache/knox/gateway/hdfs/dispatch/AbstractHdfsHaDispatch.java
index 97890fc..3e808fe 100644
--- a/gateway-service-webhdfs/src/main/java/org/apache/knox/gateway/hdfs/dispatch/AbstractHdfsHaDispatch.java
+++ b/gateway-service-webhdfs/src/main/java/org/apache/knox/gateway/hdfs/dispatch/AbstractHdfsHaDispatch.java
@@ -128,6 +128,7 @@ public abstract class AbstractHdfsHaDispatch extends HdfsHttpClientDispatch
{
                Thread.sleep(failoverSleep);
             } catch (InterruptedException e) {
                LOG.failoverSleepFailed(getResourceRole(), e);
+               Thread.currentThread().interrupt();
             }
          }
          LOG.failingOverRequest(outboundRequest.getURI().toString());
@@ -141,5 +142,4 @@ public abstract class AbstractHdfsHaDispatch extends HdfsHttpClientDispatch
{
          }
       }
    }
-
-}
\ No newline at end of file
+}
diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java
index bbfb288..470aa44 100644
--- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java
+++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/KnoxSession.java
@@ -83,6 +83,7 @@ import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
@@ -94,7 +95,6 @@ import java.util.concurrent.TimeoutException;
 import de.thetaphi.forbiddenapis.SuppressForbidden;
 
 public class KnoxSession implements Closeable {
-
   private static final String DEFAULT_JAAS_FILE = "/jaas.conf";
   public static final String JGSS_LOGIN_MOUDLE = "com.sun.security.jgss.initiate";
   public static final String END_CERTIFICATE = "-----END CERTIFICATE-----\n";
@@ -559,18 +559,16 @@ public class KnoxSession implements Closeable {
     try {
       shutdown();
     } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
       throw new KnoxShellException("Can not shutdown underlying resources", e);
     }
   }
 
   @Override
   public String toString() {
-    final StringBuilder sb = new StringBuilder("KnoxSession{base='");
-    sb.append(base).append("\'}");
-    return sb.toString();
+    return String.format(Locale.ROOT, "KnoxSession{base='%s'}", base);
   }
 
-
   private static final class JAASClientConfig extends Configuration {
 
     private static final Configuration baseConfig = Configuration.getConfiguration();
@@ -603,7 +601,6 @@ public class KnoxSession implements Closeable {
 
   @SuppressWarnings("PMD.AvoidAccessibilityAlteration")
   private static class ConfigurationFactory {
-
     private static final Class implClazz;
     static {
       // Oracle and OpenJDK use the Sun implementation
@@ -639,5 +636,4 @@ public class KnoxSession implements Closeable {
       return config;
     }
   }
-
 }
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/KnoxSpnegoAuthScheme.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/KnoxSpnegoAuthScheme.java
index 5498600..f6dac77 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/KnoxSpnegoAuthScheme.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/KnoxSpnegoAuthScheme.java
@@ -21,7 +21,6 @@ import org.apache.http.impl.auth.SPNegoScheme;
 import org.ietf.jgss.GSSException;
 
 public class KnoxSpnegoAuthScheme extends SPNegoScheme {
-
   private static long nano = Long.MIN_VALUE;
 
   public KnoxSpnegoAuthScheme( boolean stripPort ) {
@@ -43,7 +42,7 @@ public class KnoxSpnegoAuthScheme extends SPNegoScheme {
         try {
           Thread.sleep( 0 );
         } catch( InterruptedException e ) {
-          // Ignore it.
+          Thread.currentThread().interrupt();
         }
       }
       nano = now;
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
index 611e670..47f2f18 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
@@ -35,7 +35,7 @@ import java.util.Arrays;
 import java.util.List;
 
 public class CMFMasterService {
-  private static GatewaySpiMessages LOG = MessagesFactory.get( GatewaySpiMessages.class );
+  private static final GatewaySpiMessages LOG = MessagesFactory.get( GatewaySpiMessages.class
);
 
   private static final String MASTER_PASSPHRASE = "masterpassphrase";
   private static final String MASTER_PERSISTENCE_TAG = "#1.0# " + TimeStamp.getCurrentTime().toDateString();
@@ -132,8 +132,8 @@ public class CMFMasterService {
   }
 
   protected void persistMaster(char[] master, File masterFile) {
-    EncryptionResult atom = encryptMaster(master);
     try {
+      EncryptionResult atom = encryptMaster(master);
       ArrayList<String> lines = new ArrayList<>();
       lines.add(MASTER_PERSISTENCE_TAG);
 
@@ -151,13 +151,13 @@ public class CMFMasterService {
     }
   }
 
-  private EncryptionResult encryptMaster(char[] master) {
+  private EncryptionResult encryptMaster(char[] master) throws IOException {
     try {
       return encryptor.encrypt(new String(master));
     } catch (Exception e) {
       LOG.failedToEncryptMasterSecret(e);
+      throw new IOException(e);
     }
-    return null;
   }
 
   protected void initializeFromMaster(File masterFile) throws Exception {
@@ -201,4 +201,4 @@ public class CMFMasterService {
   private boolean isUnixEnv() {
     return (File.separatorChar == '/');
   }
-}
\ No newline at end of file
+}
diff --git a/gateway-test-utils/src/main/java/org/apache/knox/test/TestUtils.java b/gateway-test-utils/src/main/java/org/apache/knox/test/TestUtils.java
index 63429cb..dcf87b5 100644
--- a/gateway-test-utils/src/main/java/org/apache/knox/test/TestUtils.java
+++ b/gateway-test-utils/src/main/java/org/apache/knox/test/TestUtils.java
@@ -60,8 +60,7 @@ public class TestUtils {
   }
 
   public static String getResourceName( Class clazz, String name ) {
-    name = clazz.getName().replaceAll( "\\.", "/" ) + "/" + name;
-    return name;
+    return clazz.getName().replaceAll( "\\.", "/" ) + "/" + name;
   }
 
   public static URL getResourceUrl( Class clazz, String name ) throws FileNotFoundException
{
@@ -216,7 +215,7 @@ public class TestUtils {
       try {
         Thread.sleep( wait );
       } catch( InterruptedException e ) {
-        // Ignore.
+        Thread.currentThread().interrupt();
       }
     }
   }
@@ -231,6 +230,4 @@ public class TestUtils {
     LOG.debug( "execute: reponse=" + response );
     return response;
   }
-
-
 }
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
index b3d445e..865b34e 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/audit/log4j/appender/JdbmStoreAndForwardAppender.java
@@ -82,8 +82,11 @@ public class JdbmStoreAndForwardAppender extends AppenderSkeleton {
       queue.stop();
       forwarder.join();
       queue.close();
-    } catch( InterruptedException | IOException e ) {
-      throw new RuntimeException( e );
+    } catch(InterruptedException e) {
+      Thread.currentThread().interrupt();
+      throw new RuntimeException(e);
+    } catch(IOException e) {
+      throw new RuntimeException(e);
     }
   }
 


Mime
View raw message