List of usage examples for org.apache.hadoop.conf Configuration writeXml
public void writeXml(Writer out) throws IOException
From source file:org.apache.oozie.client.TestOozieCLI.java
License:Apache License
private String createConfigFile(String appPath) throws Exception { String path = getTestCaseDir() + "/" + getName() + ".xml"; Configuration conf = new Configuration(false); conf.set(OozieClient.APP_PATH, appPath); conf.set(OozieClient.RERUN_SKIP_NODES, "node"); OutputStream os = new FileOutputStream(path); conf.writeXml(os); os.close();/* w w w . j a v a 2 s . co m*/ return path; }
From source file:org.apache.oozie.client.TestOozieCLI.java
License:Apache License
private String createCoodrConfigFile(String appPath) throws Exception { String path = getTestCaseDir() + "/" + getName() + ".xml"; Configuration conf = new Configuration(false); conf.set(OozieClient.COORDINATOR_APP_PATH, appPath); OutputStream os = new FileOutputStream(path); conf.writeXml(os); os.close();// w w w. j av a 2s . co m return path; }
From source file:org.apache.oozie.coord.TestHCatELFunctions.java
License:Apache License
@Test public void testHCatExists() throws Exception { dropTable("db1", "table1", true); dropDatabase("db1", true); createDatabase("db1"); createTable("db1", "table1", "year,month,dt,country"); addPartition("db1", "table1", "year=2012;month=12;dt=02;country=us"); Configuration protoConf = new Configuration(); protoConf.set(OozieClient.USER_NAME, getTestUser()); protoConf.set("hadoop.job.ugi", getTestUser() + "," + "group"); Configuration conf = new XConfiguration(); conf.set(OozieClient.APP_PATH, "appPath"); conf.set(OozieClient.USER_NAME, getTestUser()); conf.set("test.dir", getTestCaseDir()); conf.set("partition1", getHCatURI("db1", "table1", "dt=02").toString()); conf.set("partition2", getHCatURI("db1", "table1", "dt=05").toString()); LiteWorkflowApp def = new LiteWorkflowApp("name", "<workflow-app/>", new StartNodeDef(LiteWorkflowStoreService.LiteControlNodeHandler.class, "end")) .addNode(new EndNodeDef("end", LiteWorkflowStoreService.LiteControlNodeHandler.class)); LiteWorkflowInstance job = new LiteWorkflowInstance(def, conf, "wfId"); WorkflowJobBean wf = new WorkflowJobBean(); wf.setId(job.getId());//from ww w . ja v a2 s . co m wf.setAppName("name"); wf.setAppPath("appPath"); wf.setUser(getTestUser()); wf.setGroup("group"); wf.setWorkflowInstance(job); ByteArrayOutputStream baos = new ByteArrayOutputStream(); protoConf.writeXml(baos); wf.setProtoActionConf(baos.toString()); WorkflowActionBean action = new WorkflowActionBean(); action.setId("actionId"); action.setName("actionName"); ELEvaluator eval = Services.get().get(ELService.class).createEvaluator("workflow"); DagELFunctions.configureEvaluator(eval, wf, action); assertEquals(true, (boolean) eval.evaluate("${hcat:exists(wf:conf('partition1'))}", Boolean.class)); assertEquals(false, (boolean) eval.evaluate("${hcat:exists(wf:conf('partition2'))}", Boolean.class)); dropTable("db1", "table1", true); dropDatabase("db1", true); }
From source file:org.apache.oozie.service.TestHCatAccessorService.java
License:Apache License
@Test public void testGetHCatConfLocal() throws Exception { File hcatConfFile = new File(getTestCaseConfDir(), "hive-site.xml"); assertFalse(hcatConfFile.exists());/*from w w w . ja v a 2s .c om*/ assertNull(services.get(HCatAccessorService.class).getHCatConf()); Configuration hcatConf = new Configuration(false); hcatConf.set("A", "a"); hcatConf.writeXml(new FileOutputStream(hcatConfFile)); assertTrue(hcatConfFile.exists()); services.destroy(); services = super.setupServicesForHCatalog(); Configuration conf = services.getConf(); conf.set("oozie.service.HCatAccessorService.hcat.configuration", hcatConfFile.getAbsolutePath()); services.init(); Configuration hcatConfLoaded = services.get(HCatAccessorService.class).getHCatConf(); assertEquals("a", hcatConfLoaded.get("A")); }
From source file:org.apache.oozie.service.TestHCatAccessorService.java
License:Apache License
@Test public void testGetHCatConfHDFS() throws Exception { Path hcatConfPath = new Path(getFsTestCaseDir(), "hive-site.xml"); assertFalse(getFileSystem().exists(hcatConfPath)); assertNull(services.get(HCatAccessorService.class).getHCatConf()); Configuration hcatConf = new Configuration(false); hcatConf.set("A", "a"); FSDataOutputStream out = getFileSystem().create(hcatConfPath); hcatConf.writeXml(out); out.close();//from w w w. ja v a 2 s .c o m assertTrue(getFileSystem().exists(hcatConfPath)); services.destroy(); services = super.setupServicesForHCatalog(); Configuration conf = services.getConf(); conf.set("oozie.service.HCatAccessorService.hcat.configuration", hcatConfPath.toUri().toString()); services.init(); Configuration hcatConfLoaded = services.get(HCatAccessorService.class).getHCatConf(); assertEquals("a", hcatConfLoaded.get("A")); }
From source file:org.apache.oozie.servlet.TestJobsServlet.java
License:Apache License
public void testSubmit() throws Exception { //runTest("/jobs", BaseJobsServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { runTest("/v0/jobs", V0JobsServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { public Void call() throws Exception { MockDagEngineService.reset(); String appPath = getFsTestCaseDir().toString() + "/app"; FileSystem fs = getFileSystem(); Path jobXmlPath = new Path(appPath, "workflow.xml"); fs.create(jobXmlPath);/*from ww w. ja v a2s . c om*/ int wfCount = MockDagEngineService.workflows.size(); Configuration jobConf = new XConfiguration(); jobConf.set(OozieClient.USER_NAME, getTestUser()); jobConf.set(OozieClient.APP_PATH, appPath); Map<String, String> params = new HashMap<String, String>(); URL url = createURL("", params); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); jobConf.writeXml(conn.getOutputStream()); assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); JSONObject obj = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); assertEquals(MockDagEngineService.JOB_ID + wfCount + MockDagEngineService.JOB_ID_END, obj.get(JsonTags.JOB_ID)); assertFalse(MockDagEngineService.started.get(wfCount)); wfCount++; jobConf = new XConfiguration(); jobConf.set(OozieClient.USER_NAME, getTestUser()); jobConf.set(OozieClient.APP_PATH, appPath); params = new HashMap<String, String>(); params.put(RestConstants.ACTION_PARAM, RestConstants.JOB_ACTION_START); url = createURL("", params); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); jobConf.writeXml(conn.getOutputStream()); assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); obj = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); assertEquals(MockDagEngineService.JOB_ID + wfCount + MockDagEngineService.JOB_ID_END, obj.get(JsonTags.JOB_ID)); assertTrue(MockDagEngineService.started.get(wfCount)); Services services = Services.get(); DagEngine de = services.get(DagEngineService.class).getDagEngine(getTestUser()); StringReader sr = new StringReader(de.getJob(MockDagEngineService.JOB_ID + wfCount).getConf()); Configuration conf1 = new XConfiguration(sr); return null; } }); }
From source file:org.apache.oozie.servlet.TestJobsServlet.java
License:Apache License
public void testDiffUser() throws Exception { //runTest("/jobs", BaseJobsServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { runTest("/v0/jobs", V0JobsServletWithDefUser.class, IS_SECURITY_ENABLED, new Callable<Void>() { public Void call() throws Exception { MockDagEngineService.reset(); String appPath = getFsTestCaseDir().toString() + "/app"; FileSystem fs = getFileSystem(); Path jobXmlPath = new Path(appPath, "workflow.xml"); fs.create(jobXmlPath);/*from ww w .j ava 2s . co m*/ Configuration jobConf = new XConfiguration(); jobConf.set(OozieClient.USER_NAME, getTestUser()); jobConf.set(OozieClient.APP_PATH, appPath); Map<String, String> params = new HashMap<String, String>(); URL url = createURL("", params); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); jobConf.writeXml(conn.getOutputStream()); assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); assertEquals(getTestUser2(), MockDagEngineService.user); return null; } }); }
From source file:org.apache.oozie.servlet.TestV0JobServlet.java
License:Apache License
private void _testAction(final String action, final Configuration conf) throws Exception { runTest("/v0/job/*", V0JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { public Void call() throws Exception { MockDagEngineService.reset(); Map<String, String> params = new HashMap<String, String>(); params.put(RestConstants.ACTION_PARAM, action); URL url = createURL(MockDagEngineService.JOB_ID + 1, params); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("PUT"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true);// w w w. j a v a2 s . co m if (conf != null) { conf.writeXml(conn.getOutputStream()); } if (conf == null || conf.get(OozieClient.USER_NAME) != null) { assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode()); assertEquals(action, MockDagEngineService.did); } else { assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); } MockDagEngineService.reset(); params = new HashMap<String, String>(); params.put(RestConstants.ACTION_PARAM, action); url = createURL(MockDagEngineService.JOB_ID + (MockDagEngineService.workflows.size() + 1) + MockDagEngineService.JOB_ID_END, params); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("PUT"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); if (conf != null) { conf.writeXml(conn.getOutputStream()); } if (conf == null || conf.get(OozieClient.USER_NAME) != null) { assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); assertEquals(action, MockDagEngineService.did); } else { assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); } return null; } }); }
From source file:org.apache.oozie.servlet.TestV1JobServlet.java
License:Apache License
private void _testAction(final String action, final Configuration conf) throws Exception { runTest("/v1/job/*", V1JobServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { public Void call() throws Exception { MockCoordinatorEngineService.reset(); Map<String, String> params = new HashMap<String, String>(); params.put(RestConstants.ACTION_PARAM, action); URL url = createURL(MockCoordinatorEngineService.JOB_ID + 1, params); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("PUT"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true);/*from www .j a v a 2 s . com*/ if (conf != null) { conf.writeXml(conn.getOutputStream()); } if (conf == null || conf.get(OozieClient.USER_NAME) != null) { assertEquals(HttpServletResponse.SC_OK, conn.getResponseCode()); assertEquals(action, MockCoordinatorEngineService.did); } else { assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); } MockCoordinatorEngineService.reset(); params = new HashMap<String, String>(); params.put(RestConstants.ACTION_PARAM, action); url = createURL( MockCoordinatorEngineService.JOB_ID + (MockCoordinatorEngineService.coordJobs.size() + 1), params); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("PUT"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); if (conf != null) { conf.writeXml(conn.getOutputStream()); } if (conf == null || conf.get(OozieClient.USER_NAME) != null) { assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); assertEquals(action, MockCoordinatorEngineService.did); } else { assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); } return null; } }); }
From source file:org.apache.oozie.servlet.TestV1JobsServlet.java
License:Apache License
public void testSubmit() throws Exception { runTest("/v1/jobs", V1JobsServlet.class, IS_SECURITY_ENABLED, new Callable<Void>() { public Void call() throws Exception { MockDagEngineService.reset(); String appPath = getFsTestCaseDir().toString() + "/app"; FileSystem fs = getFileSystem(); Path jobXmlPath = new Path(appPath, "workflow.xml"); fs.create(jobXmlPath);// w w w . j a v a 2 s .c o m int wfCount = MockDagEngineService.workflows.size(); Configuration jobConf = new XConfiguration(); jobConf.set(OozieClient.USER_NAME, getTestUser()); jobConf.set(OozieClient.APP_PATH, appPath); Map<String, String> params = new HashMap<String, String>(); URL url = createURL("", params); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); jobConf.writeXml(conn.getOutputStream()); assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); JSONObject obj = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); assertEquals(MockDagEngineService.JOB_ID + wfCount + MockDagEngineService.JOB_ID_END, obj.get(JsonTags.JOB_ID)); assertFalse(MockDagEngineService.started.get(wfCount)); wfCount++; jobConf = new XConfiguration(); jobConf.set(OozieClient.USER_NAME, getTestUser()); jobConf.set(OozieClient.APP_PATH, appPath); params = new HashMap<String, String>(); params.put(RestConstants.ACTION_PARAM, RestConstants.JOB_ACTION_START); url = createURL("", params); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); jobConf.writeXml(conn.getOutputStream()); assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); obj = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); assertEquals(MockDagEngineService.JOB_ID + wfCount + MockDagEngineService.JOB_ID_END, obj.get(JsonTags.JOB_ID)); assertTrue(MockDagEngineService.started.get(wfCount)); Services services = Services.get(); DagEngine de = services.get(DagEngineService.class).getDagEngine(getTestUser()); StringReader sr = new StringReader(de.getJob(MockDagEngineService.JOB_ID + wfCount).getConf()); Configuration conf1 = new XConfiguration(sr); wfCount++; jobConf = new XConfiguration(); jobConf.set(OozieClient.USER_NAME, getTestUser()); params = new HashMap<String, String>(); url = createURL("", params); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); jobConf.writeXml(conn.getOutputStream()); assertEquals(HttpServletResponse.SC_BAD_REQUEST, conn.getResponseCode()); Path libPath1 = new Path(getFsTestCaseDir(), "libpath1"); fs.mkdirs(libPath1); Path jobXmlPath1 = new Path(libPath1, "workflow.xml"); fs.create(jobXmlPath1); jobConf = new XConfiguration(); jobConf.set(OozieClient.USER_NAME, getTestUser()); jobConf.set(OozieClient.LIBPATH, libPath1.toString()); params = new HashMap<String, String>(); url = createURL("", params); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); jobConf.writeXml(conn.getOutputStream()); assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); obj = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); assertEquals(MockDagEngineService.JOB_ID + wfCount + MockDagEngineService.JOB_ID_END, obj.get(JsonTags.JOB_ID)); assertFalse(MockDagEngineService.started.get(wfCount)); wfCount++; Path libPath2 = new Path(getFsTestCaseDir(), "libpath2"); fs.mkdirs(libPath2); jobConf = new XConfiguration(); jobConf.set(OozieClient.USER_NAME, getTestUser()); jobConf.set(OozieClient.LIBPATH, libPath1.toString() + "," + libPath2.toString()); params = new HashMap<String, String>(); url = createURL("", params); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("content-type", RestConstants.XML_CONTENT_TYPE); conn.setDoOutput(true); jobConf.writeXml(conn.getOutputStream()); assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); assertEquals(HttpServletResponse.SC_CREATED, conn.getResponseCode()); obj = (JSONObject) JSONValue.parse(new InputStreamReader(conn.getInputStream())); assertEquals(MockDagEngineService.JOB_ID + wfCount + MockDagEngineService.JOB_ID_END, obj.get(JsonTags.JOB_ID)); assertFalse(MockDagEngineService.started.get(wfCount)); wfCount++; return null; } }); }