Esempio n. 1
0
        /// <exception cref="System.Exception"/>
        public virtual void Start()
        {
            ClassLoader cl = Thread.CurrentThread().GetContextClassLoader();

            Runtime.SetProperty(KMSConfiguration.KmsConfigDir, kmsConfDir);
            FilePath aclsFile = new FilePath(kmsConfDir, "kms-acls.xml");

            if (!aclsFile.Exists())
            {
                InputStream  @is = cl.GetResourceAsStream("mini-kms-acls-default.xml");
                OutputStream os  = new FileOutputStream(aclsFile);
                IOUtils.Copy(@is, os);
                @is.Close();
                os.Close();
            }
            FilePath coreFile = new FilePath(kmsConfDir, "core-site.xml");

            if (!coreFile.Exists())
            {
                Configuration core   = new Configuration();
                TextWriter    writer = new FileWriter(coreFile);
                core.WriteXml(writer);
                writer.Close();
            }
            FilePath kmsFile = new FilePath(kmsConfDir, "kms-site.xml");

            if (!kmsFile.Exists())
            {
                Configuration kms = new Configuration(false);
                kms.Set(KMSConfiguration.KeyProviderUri, "jceks://file@" + new Path(kmsConfDir, "kms.keystore"
                                                                                    ).ToUri());
                kms.Set("hadoop.kms.authentication.type", "simple");
                TextWriter writer = new FileWriter(kmsFile);
                kms.WriteXml(writer);
                writer.Close();
            }
            Runtime.SetProperty("log4j.configuration", log4jConfFile);
            jetty = CreateJettyServer(keyStore, keyStorePassword, inPort);
            // we need to do a special handling for MiniKMS to work when in a dir and
            // when in a JAR in the classpath thanks to Jetty way of handling of webapps
            // when they are in the a DIR, WAR or JAR.
            Uri webXmlUrl = cl.GetResource("kms-webapp/WEB-INF/web.xml");

            if (webXmlUrl == null)
            {
                throw new RuntimeException("Could not find kms-webapp/ dir in test classpath");
            }
            bool   webXmlInJar = webXmlUrl.AbsolutePath.Contains(".jar!/");
            string webappPath;

            if (webXmlInJar)
            {
                FilePath webInf = new FilePath("target/" + UUID.RandomUUID().ToString() + "/kms-webapp/WEB-INF"
                                               );
                webInf.Mkdirs();
                new FilePath(webInf, "web.xml").Delete();
                InputStream  @is = cl.GetResourceAsStream("kms-webapp/WEB-INF/web.xml");
                OutputStream os  = new FileOutputStream(new FilePath(webInf, "web.xml"));
                IOUtils.Copy(@is, os);
                @is.Close();
                os.Close();
                webappPath = webInf.GetParentFile().GetAbsolutePath();
            }
            else
            {
                webappPath = cl.GetResource("kms-webapp").AbsolutePath;
            }
            WebAppContext context = new WebAppContext(webappPath, "/kms");

            if (webXmlInJar)
            {
                context.SetClassLoader(cl);
            }
            jetty.AddHandler(context);
            jetty.Start();
            kmsURL = new Uri(GetJettyURL(jetty), "kms");
        }