HADOOP-12615. Fix NPE in MiniKMS.start(). Contributed by Wei-Chiu Chuang.
Change-Id: Ie3e148bd1401618b1737a577957298bf622891f4
This commit is contained in:
parent
5104077e1f
commit
f5756a2038
@ -543,6 +543,8 @@ Trunk (Unreleased)
|
|||||||
HADOOP-12638. UnsatisfiedLinkError while checking ISA-L in checknative
|
HADOOP-12638. UnsatisfiedLinkError while checking ISA-L in checknative
|
||||||
command. (Kai Sasaki via Colin P. McCabe)
|
command. (Kai Sasaki via Colin P. McCabe)
|
||||||
|
|
||||||
|
HADOOP-12615. Fix NPE in MiniKMS.start(). (Wei-Chiu Chuang via zhz)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-7761. Improve the performance of raw comparisons. (todd)
|
HADOOP-7761. Improve the performance of raw comparisons. (todd)
|
||||||
|
@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceStability;
|
import org.apache.hadoop.classification.InterfaceStability;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
@InterfaceStability.Evolving
|
@InterfaceStability.Evolving
|
||||||
public class ThreadUtil {
|
public class ThreadUtil {
|
||||||
|
|
||||||
@ -46,4 +49,31 @@ public static void sleepAtLeastIgnoreInterrupts(long millis) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method that returns a resource as inputstream from the
|
||||||
|
* classpath.
|
||||||
|
* <p>
|
||||||
|
* It first attempts to use the Thread's context classloader and if not
|
||||||
|
* set it uses the class' classloader.
|
||||||
|
*
|
||||||
|
* @param resourceName resource to retrieve.
|
||||||
|
*
|
||||||
|
* @throws IOException thrown if resource cannot be loaded
|
||||||
|
* @return inputstream with the resource.
|
||||||
|
*/
|
||||||
|
public static InputStream getResourceAsStream(String resourceName)
|
||||||
|
throws IOException {
|
||||||
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||||
|
if (cl == null) {
|
||||||
|
throw new IOException("Can not read resource file '" + resourceName +
|
||||||
|
"' because class loader of the current thread is null");
|
||||||
|
}
|
||||||
|
InputStream is = cl.getResourceAsStream(resourceName);
|
||||||
|
if (is == null) {
|
||||||
|
throw new IOException("Can not read resource file '" +
|
||||||
|
resourceName + "'");
|
||||||
|
}
|
||||||
|
return is;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,11 +43,7 @@ protected VersionInfo(String component) {
|
|||||||
String versionInfoFile = component + "-version-info.properties";
|
String versionInfoFile = component + "-version-info.properties";
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
try {
|
try {
|
||||||
is = Thread.currentThread().getContextClassLoader()
|
is = ThreadUtil.getResourceAsStream(versionInfoFile);
|
||||||
.getResourceAsStream(versionInfoFile);
|
|
||||||
if (is == null) {
|
|
||||||
throw new IOException("Resource not found");
|
|
||||||
}
|
|
||||||
info.load(is);
|
info.load(is);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LogFactory.getLog(getClass()).warn("Could not read '" +
|
LogFactory.getLog(getClass()).warn("Could not read '" +
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
import org.apache.hadoop.crypto.key.kms.KMSRESTConstants;
|
import org.apache.hadoop.crypto.key.kms.KMSRESTConstants;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.security.ssl.SslSocketConnectorSecure;
|
import org.apache.hadoop.security.ssl.SslSocketConnectorSecure;
|
||||||
|
import org.apache.hadoop.util.ThreadUtil;
|
||||||
import org.mortbay.jetty.Connector;
|
import org.mortbay.jetty.Connector;
|
||||||
import org.mortbay.jetty.Server;
|
import org.mortbay.jetty.Server;
|
||||||
import org.mortbay.jetty.security.SslSocketConnector;
|
import org.mortbay.jetty.security.SslSocketConnector;
|
||||||
@ -34,6 +35,7 @@
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
@ -149,16 +151,26 @@ public MiniKMS(String kmsConfDir, String log4ConfFile, String keyStore,
|
|||||||
this.inPort = inPort;
|
this.inPort = inPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void copyResource(String inputResourceName, File outputFile) throws
|
||||||
|
IOException {
|
||||||
|
InputStream is = null;
|
||||||
|
OutputStream os = null;
|
||||||
|
try {
|
||||||
|
is = ThreadUtil.getResourceAsStream(inputResourceName);
|
||||||
|
os = new FileOutputStream(outputFile);
|
||||||
|
IOUtils.copy(is, os);
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(is);
|
||||||
|
IOUtils.closeQuietly(os);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||||
System.setProperty(KMSConfiguration.KMS_CONFIG_DIR, kmsConfDir);
|
System.setProperty(KMSConfiguration.KMS_CONFIG_DIR, kmsConfDir);
|
||||||
File aclsFile = new File(kmsConfDir, "kms-acls.xml");
|
File aclsFile = new File(kmsConfDir, "kms-acls.xml");
|
||||||
if (!aclsFile.exists()) {
|
if (!aclsFile.exists()) {
|
||||||
InputStream is = cl.getResourceAsStream("mini-kms-acls-default.xml");
|
copyResource("mini-kms-acls-default.xml", aclsFile);
|
||||||
OutputStream os = new FileOutputStream(aclsFile);
|
|
||||||
IOUtils.copy(is, os);
|
|
||||||
is.close();
|
|
||||||
os.close();
|
|
||||||
}
|
}
|
||||||
File coreFile = new File(kmsConfDir, "core-site.xml");
|
File coreFile = new File(kmsConfDir, "core-site.xml");
|
||||||
if (!coreFile.exists()) {
|
if (!coreFile.exists()) {
|
||||||
@ -195,11 +207,7 @@ public void start() throws Exception {
|
|||||||
"/kms-webapp/WEB-INF");
|
"/kms-webapp/WEB-INF");
|
||||||
webInf.mkdirs();
|
webInf.mkdirs();
|
||||||
new File(webInf, "web.xml").delete();
|
new File(webInf, "web.xml").delete();
|
||||||
InputStream is = cl.getResourceAsStream("kms-webapp/WEB-INF/web.xml");
|
copyResource("kms-webapp/WEB-INF/web.xml", new File(webInf, "web.xml"));
|
||||||
OutputStream os = new FileOutputStream(new File(webInf, "web.xml"));
|
|
||||||
IOUtils.copy(is, os);
|
|
||||||
is.close();
|
|
||||||
os.close();
|
|
||||||
webappPath = webInf.getParentFile().getAbsolutePath();
|
webappPath = webInf.getParentFile().getAbsolutePath();
|
||||||
} else {
|
} else {
|
||||||
webappPath = cl.getResource("kms-webapp").getPath();
|
webappPath = cl.getResource("kms-webapp").getPath();
|
||||||
|
@ -19,11 +19,15 @@
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FilterOutputStream;
|
import java.io.FilterOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
|
||||||
import org.apache.hadoop.crypto.key.kms.server.KMS.KMSOp;
|
import org.apache.hadoop.crypto.key.kms.server.KMS.KMSOp;
|
||||||
|
import org.apache.hadoop.io.IOUtils;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
|
import org.apache.hadoop.util.ThreadUtil;
|
||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.PropertyConfigurator;
|
import org.apache.log4j.PropertyConfigurator;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -52,15 +56,17 @@ public void setOutputStream(OutputStream out) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() throws IOException {
|
||||||
originalOut = System.err;
|
originalOut = System.err;
|
||||||
memOut = new ByteArrayOutputStream();
|
memOut = new ByteArrayOutputStream();
|
||||||
filterOut = new FilterOut(memOut);
|
filterOut = new FilterOut(memOut);
|
||||||
capturedOut = new PrintStream(filterOut);
|
capturedOut = new PrintStream(filterOut);
|
||||||
System.setErr(capturedOut);
|
System.setErr(capturedOut);
|
||||||
PropertyConfigurator.configure(Thread.currentThread().
|
InputStream is =
|
||||||
getContextClassLoader()
|
ThreadUtil.getResourceAsStream("log4j-kmsaudit.properties");
|
||||||
.getResourceAsStream("log4j-kmsaudit.properties"));
|
PropertyConfigurator.configure(is);
|
||||||
|
IOUtils.closeStream(is);
|
||||||
|
|
||||||
this.kmsAudit = new KMSAudit(1000);
|
this.kmsAudit = new KMSAudit(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -389,6 +390,32 @@ private void initDirectoryService() throws Exception {
|
|||||||
ds.getAdminSession().add(entry);
|
ds.getAdminSession().add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method that returns a resource as inputstream from the
|
||||||
|
* classpath.
|
||||||
|
* <p>
|
||||||
|
* It first attempts to use the Thread's context classloader and if not
|
||||||
|
* set it uses the class' classloader.
|
||||||
|
*
|
||||||
|
* @param resourceName resource to retrieve.
|
||||||
|
*
|
||||||
|
* @throws IOException thrown if resource cannot be loaded
|
||||||
|
* @return inputstream with the resource.
|
||||||
|
*/
|
||||||
|
public static InputStream getResourceAsStream(String resourceName)
|
||||||
|
throws IOException {
|
||||||
|
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||||
|
if (cl == null) {
|
||||||
|
cl = MiniKdc.class.getClassLoader();
|
||||||
|
}
|
||||||
|
InputStream is = cl.getResourceAsStream(resourceName);
|
||||||
|
if (is == null) {
|
||||||
|
throw new IOException("Can not read resource file '" +
|
||||||
|
resourceName + "'");
|
||||||
|
}
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
private void initKDCServer() throws Exception {
|
private void initKDCServer() throws Exception {
|
||||||
String orgName= conf.getProperty(ORG_NAME);
|
String orgName= conf.getProperty(ORG_NAME);
|
||||||
String orgDomain = conf.getProperty(ORG_DOMAIN);
|
String orgDomain = conf.getProperty(ORG_DOMAIN);
|
||||||
@ -400,8 +427,7 @@ private void initKDCServer() throws Exception {
|
|||||||
map.put("3", orgDomain.toUpperCase(Locale.ENGLISH));
|
map.put("3", orgDomain.toUpperCase(Locale.ENGLISH));
|
||||||
map.put("4", bindAddress);
|
map.put("4", bindAddress);
|
||||||
|
|
||||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
InputStream is1 = getResourceAsStream("minikdc.ldiff");
|
||||||
InputStream is1 = cl.getResourceAsStream("minikdc.ldiff");
|
|
||||||
|
|
||||||
SchemaManager schemaManager = ds.getSchemaManager();
|
SchemaManager schemaManager = ds.getSchemaManager();
|
||||||
LdifReader reader = null;
|
LdifReader reader = null;
|
||||||
@ -443,7 +469,7 @@ private void initKDCServer() throws Exception {
|
|||||||
kdc.start();
|
kdc.start();
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
InputStream is2 = cl.getResourceAsStream("minikdc-krb5.conf");
|
InputStream is2 = getResourceAsStream("minikdc-krb5.conf");
|
||||||
|
|
||||||
BufferedReader r = null;
|
BufferedReader r = null;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user