You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ma...@apache.org on 2014/05/07 21:38:55 UTC

[1/4] AMBARI-5704. Pig View Cleanup. (mahadev)

Repository: ambari
Updated Branches:
  refs/heads/branch-1.6.0 40e5707bd -> c64261e26


http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java
index a8a8c34..6cf4bd7 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/JobTest.java
@@ -38,373 +38,373 @@ import java.util.HashMap;
 import static org.easymock.EasyMock.*;
 
 public class JobTest extends BasePigTest {
-    private JobService jobService;
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-        jobService = getService(JobService.class, handler, context);
-    }
-
-    @Override
-    @After
-    public void tearDown() throws Exception {
-        super.tearDown();
-        jobService.getResourceManager().setTempletonApi(null);
-        JobService.setHdfsApi(null);
-    }
-
-    private Response doCreateJob(String title, String pigScript, String templetonArguments) {
-        return doCreateJob(title, pigScript, templetonArguments, null);
-    }
-
-    private Response doCreateJob(String title, String pigScript, String templetonArguments, String forcedContent) {
-        JobService.PigJobRequest request = new JobService.PigJobRequest();
-        request.job = new PigJob();
-        request.job.setTitle(title);
-        request.job.setPigScript(pigScript);
-        request.job.setTempletonArguments(templetonArguments);
-        request.job.setForcedContent(forcedContent);
-
-        UriInfo uriInfo = createNiceMock(UriInfo.class);
-        URI uri = UriBuilder.fromUri("http://host/a/b").build();
-        expect(uriInfo.getAbsolutePath()).andReturn(uri);
-
-        HttpServletResponse resp_obj = createStrictMock(HttpServletResponse.class);
-
-        resp_obj.setHeader(eq("Location"), anyString());
-
-        replay(uriInfo, resp_obj);
-        return jobService.runJob(request, resp_obj, uriInfo);
-    }
-
-    @Test
-    public void testSubmitJob() throws Exception {
-        HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
-        expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
-
-        ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
-
-        FSDataOutputStream stream = new FSDataOutputStream(do_stream);
-        expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
-        replay(hdfsApi);
-        JobService.setHdfsApi(hdfsApi);
-
-        TempletonApi api = createNiceMock(TempletonApi.class);
-        jobService.getResourceManager().setTempletonApi(api);
-        TempletonApi.JobData data = api.new JobData();
-        expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
-        replay(api);
-
-        Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
-
-        Assert.assertEquals("-useHCatalog", do_stream.toString());
-        Assert.assertEquals(201, response.getStatus());
-
-        JSONObject obj = (JSONObject)response.getEntity();
-        Assert.assertTrue(obj.containsKey("job"));
-        Assert.assertNotNull(((PigJob) obj.get("job")).getId());
-        Assert.assertFalse(((PigJob) obj.get("job")).getId().isEmpty());
-        Assert.assertTrue(((PigJob) obj.get("job")).getStatusDir().startsWith("/tmp/.pigjobs/admin/test"));
-
-        PigJob job = ((PigJob) obj.get("job"));
-        Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
-        Assert.assertTrue(job.isInProgress());
-    }
-
-    @Test
-    public void testSubmitJobNoArguments() throws Exception {
-        HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
-        expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
-
-        ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
-
-        FSDataOutputStream stream = new FSDataOutputStream(do_stream);
-        expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
-        replay(hdfsApi);
-        JobService.setHdfsApi(hdfsApi);
-
-        TempletonApi api = createNiceMock(TempletonApi.class);
-        jobService.getResourceManager().setTempletonApi(api);
-        TempletonApi.JobData data = api.new JobData();
-        expect(api.runPigQuery((File) anyObject(), anyString(), (String) isNull())).andReturn(data);
-        replay(api);
-
-        Response response = doCreateJob("Test", "/tmp/script.pig", null);
-
-        Assert.assertEquals("", do_stream.toString());
-        Assert.assertEquals(201, response.getStatus());
-
-        JSONObject obj = (JSONObject)response.getEntity();
-        Assert.assertTrue(obj.containsKey("job"));
-        Assert.assertNotNull(((PigJob) obj.get("job")).getId());
-        Assert.assertFalse(((PigJob) obj.get("job")).getId().isEmpty());
-        Assert.assertTrue(((PigJob) obj.get("job")).getStatusDir().startsWith("/tmp/.pigjobs/admin/test"));
-
-        PigJob job = ((PigJob) obj.get("job"));
-        Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
-        Assert.assertTrue(job.isInProgress());
-    }
-
-    @Test
-    public void testSubmitJobNoFile() throws Exception {
-        HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
-        expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
-
-        ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
-
-        FSDataOutputStream stream = new FSDataOutputStream(do_stream);
-        expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
-        replay(hdfsApi);
-        JobService.setHdfsApi(hdfsApi);
-
-        TempletonApi api = createNiceMock(TempletonApi.class);
-        jobService.getResourceManager().setTempletonApi(api);
-        TempletonApi.JobData data = api.new JobData();
-        expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
-        replay(api);
-
-        Response response = doCreateJob("Test", null, "-useHCatalog");
-        Assert.assertEquals(400, response.getStatus());
-        JSONObject obj = (JSONObject)response.getEntity();
-        Assert.assertTrue(((String)obj.get("message")).contains("No pigScript file or forcedContent specifed;"));
-    }
-
-    @Test
-    public void testSubmitJobForcedContent() throws Exception {
-        HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
-
-        ByteArrayOutputStream baScriptStream = new ByteArrayOutputStream();
-        ByteArrayOutputStream baTempletonArgsStream = new ByteArrayOutputStream();
-
-        FSDataOutputStream scriptStream = new FSDataOutputStream(baScriptStream);
-        FSDataOutputStream templetonArgsStream = new FSDataOutputStream(baTempletonArgsStream);
-        expect(hdfsApi.create(endsWith("script.pig"), eq(true))).andReturn(scriptStream);
-        expect(hdfsApi.create(endsWith("params"), eq(true))).andReturn(templetonArgsStream);
-        replay(hdfsApi);
-        JobService.setHdfsApi(hdfsApi);
-
-        TempletonApi api = createNiceMock(TempletonApi.class);
-        jobService.getResourceManager().setTempletonApi(api);
-        TempletonApi.JobData data = api.new JobData();
-        expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
-        replay(api);
-
-        Response response = doCreateJob("Test", null, "-useHCatalog", "pwd");  // with forcedContent
-        Assert.assertEquals(201, response.getStatus());
-        Assert.assertEquals("-useHCatalog", baTempletonArgsStream.toString());
-        Assert.assertEquals("pwd", baScriptStream.toString());
-    }
-
-    @Test
-    public void testSubmitJobNoTitle() throws Exception {
-        HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
-        expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
-
-        ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
-
-        FSDataOutputStream stream = new FSDataOutputStream(do_stream);
-        expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
-        replay(hdfsApi);
-        JobService.setHdfsApi(hdfsApi);
-
-        TempletonApi api = createNiceMock(TempletonApi.class);
-        jobService.getResourceManager().setTempletonApi(api);
-        TempletonApi.JobData data = api.new JobData();
-        expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
-        replay(api);
-
-        Response response = doCreateJob(null, "/tmp/1.pig", "-useHCatalog");
-        Assert.assertEquals(400, response.getStatus());
-        JSONObject obj = (JSONObject)response.getEntity();
-        Assert.assertTrue(((String)obj.get("message")).contains("No title specifed"));
-    }
-
-    @Test
-    public void testSubmitJobFailed() throws Exception {
-        HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
-        expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(false);
-
-        ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
-
-        FSDataOutputStream stream = new FSDataOutputStream(do_stream);
-        expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
-        replay(hdfsApi);
-        JobService.setHdfsApi(hdfsApi);
-
-        TempletonApi api = createNiceMock(TempletonApi.class);
-        jobService.getResourceManager().setTempletonApi(api);
-        TempletonApi.JobData data = api.new JobData();
-        expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
-        replay(api);
-
-        Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
-        Assert.assertEquals(500, response.getStatus());
-        JSONObject obj = (JSONObject)response.getEntity();
-        Assert.assertTrue(((String)obj.get("message")).contains("Can't copy"));
-    }
-
-    @Test
-    public void testSubmitJobTempletonError() throws Exception {
-        HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
-        expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
-
-        ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
-
-        FSDataOutputStream stream = new FSDataOutputStream(do_stream);
-        expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
-        replay(hdfsApi);
-        JobService.setHdfsApi(hdfsApi);
-
-        TempletonApi api = createNiceMock(TempletonApi.class);
-        jobService.getResourceManager().setTempletonApi(api);
-        TempletonApi.JobData data = api.new JobData();
-        // Templeton returns 500 e.g.
-        expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andThrow(new IOException());
-        replay(api);
-
-        Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
-        Assert.assertEquals(500, response.getStatus());
-        JSONObject obj = (JSONObject)response.getEntity();
-        Assert.assertTrue(((String) obj.get("message")).contains("Templeton"));
-    }
-
-    @Test
-    public void testKillJob() throws Exception {
-        HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
-        expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
-
-        ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
-
-        FSDataOutputStream stream = new FSDataOutputStream(do_stream);
-        expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
-        replay(hdfsApi);
-        JobService.setHdfsApi(hdfsApi);
-
-        TempletonApi api = createStrictMock(TempletonApi.class);
-        jobService.getResourceManager().setTempletonApi(api);
-        TempletonApi.JobData data = api.new JobData();
-        data.id = "job_id_##";
-        expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
-        replay(api);
-
-        Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
-        Assert.assertEquals(201, response.getStatus());
-
-        reset(api);
-        api.killJob(eq("job_id_##"));
-        replay(api);
-        JSONObject obj = (JSONObject)response.getEntity();
-        PigJob job = ((PigJob)obj.get("job"));
-        response = jobService.killJob(job.getId());
-        Assert.assertEquals(204, response.getStatus());
-    }
-
-    @Test
-    public void testJobStatusFlow() throws Exception {
-        HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
-        expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
-
-        ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
-
-        FSDataOutputStream stream = new FSDataOutputStream(do_stream);
-        expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
-        replay(hdfsApi);
-        JobService.setHdfsApi(hdfsApi);
-
-        TempletonApi api = createNiceMock(TempletonApi.class);
-        jobService.getResourceManager().setTempletonApi(api);
-        TempletonApi.JobData data = api.new JobData();
-        data.id = "job_id_#";
-        expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
-        replay(api);
-
-        Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
-
-        Assert.assertEquals("-useHCatalog", do_stream.toString());
-        Assert.assertEquals(201, response.getStatus());
-
-        PigJob job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
-        Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
-        Assert.assertTrue(job.isInProgress());
-
-        // Retrieve status:
-        // SUBMITTED
-        reset(api);
-        TempletonApi.JobInfo info = api.new JobInfo();
-        expect(api.checkJob(eq("job_id_#"))).andReturn(info);
-        replay(api);
-        response = jobService.getJob(job.getId());
-        Assert.assertEquals(200, response.getStatus());
-        job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
-        Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
-
-        // RUNNING
-        reset(api);
-        info = api.new JobInfo();
-        info.status = new HashMap<String, Object>();
-        info.status.put("runState", (double)PigJob.RUN_STATE_RUNNING);
-        info.percentComplete = "30% complete";
-        expect(api.checkJob(eq("job_id_#"))).andReturn(info);
-        replay(api);
-        response = jobService.getJob(job.getId());
-        Assert.assertEquals(200, response.getStatus());
-        job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
-        Assert.assertEquals(PigJob.Status.RUNNING, job.getStatus());
-        Assert.assertTrue(job.isInProgress());
-        Assert.assertEquals(30, (Object) job.getPercentComplete());
-
-        // SUCCEED
-        reset(api);
-        info = api.new JobInfo();
-        info.status = new HashMap<String, Object>();
-        info.status.put("runState", (double)PigJob.RUN_STATE_SUCCEEDED);
-        expect(api.checkJob(eq("job_id_#"))).andReturn(info);
-        replay(api);
-        response = jobService.getJob(job.getId());
-        Assert.assertEquals(200, response.getStatus());
-        job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
-        Assert.assertEquals(PigJob.Status.COMPLETED, job.getStatus());
-        Assert.assertFalse(job.isInProgress());
-        Assert.assertNull(job.getPercentComplete());
-
-        // PREP
-        reset(api);
-        info = api.new JobInfo();
-        info.status = new HashMap<String, Object>();
-        info.status.put("runState", (double)PigJob.RUN_STATE_PREP);
-        expect(api.checkJob(eq("job_id_#"))).andReturn(info);
-        replay(api);
-        response = jobService.getJob(job.getId());
-        Assert.assertEquals(200, response.getStatus());
-        job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
-        Assert.assertEquals(PigJob.Status.RUNNING, job.getStatus());
-
-        // FAILED
-        reset(api);
-        info = api.new JobInfo();
-        info.status = new HashMap<String, Object>();
-        info.status.put("runState", (double)PigJob.RUN_STATE_FAILED);
-        expect(api.checkJob(eq("job_id_#"))).andReturn(info);
-        replay(api);
-        response = jobService.getJob(job.getId());
-        Assert.assertEquals(200, response.getStatus());
-        job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
-        Assert.assertEquals(PigJob.Status.FAILED, job.getStatus());
-        Assert.assertFalse(job.isInProgress());
-
-        // KILLED
-        reset(api);
-        info = api.new JobInfo();
-        info.status = new HashMap<String, Object>();
-        info.status.put("runState", (double)PigJob.RUN_STATE_KILLED);
-        expect(api.checkJob(eq("job_id_#"))).andReturn(info);
-        replay(api);
-        response = jobService.getJob(job.getId());
-        Assert.assertEquals(200, response.getStatus());
-        job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
-        Assert.assertEquals(PigJob.Status.KILLED, job.getStatus());
-        Assert.assertFalse(job.isInProgress());
-    }
+  private JobService jobService;
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    jobService = getService(JobService.class, handler, context);
+  }
+
+  @Override
+  @After
+  public void tearDown() throws Exception {
+    super.tearDown();
+    jobService.getResourceManager().setTempletonApi(null);
+    JobService.setHdfsApi(null);
+  }
+
+  private Response doCreateJob(String title, String pigScript, String templetonArguments) {
+    return doCreateJob(title, pigScript, templetonArguments, null);
+  }
+
+  private Response doCreateJob(String title, String pigScript, String templetonArguments, String forcedContent) {
+    JobService.PigJobRequest request = new JobService.PigJobRequest();
+    request.job = new PigJob();
+    request.job.setTitle(title);
+    request.job.setPigScript(pigScript);
+    request.job.setTempletonArguments(templetonArguments);
+    request.job.setForcedContent(forcedContent);
+
+    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    URI uri = UriBuilder.fromUri("http://host/a/b").build();
+    expect(uriInfo.getAbsolutePath()).andReturn(uri);
+
+    HttpServletResponse resp_obj = createStrictMock(HttpServletResponse.class);
+
+    resp_obj.setHeader(eq("Location"), anyString());
+
+    replay(uriInfo, resp_obj);
+    return jobService.runJob(request, resp_obj, uriInfo);
+  }
+
+  @Test
+  public void testSubmitJob() throws Exception {
+    HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
+    expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
+
+    ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
+
+    FSDataOutputStream stream = new FSDataOutputStream(do_stream);
+    expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
+    replay(hdfsApi);
+    JobService.setHdfsApi(hdfsApi);
+
+    TempletonApi api = createNiceMock(TempletonApi.class);
+    jobService.getResourceManager().setTempletonApi(api);
+    TempletonApi.JobData data = api.new JobData();
+    expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
+    replay(api);
+
+    Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
+
+    Assert.assertEquals("-useHCatalog", do_stream.toString());
+    Assert.assertEquals(201, response.getStatus());
+
+    JSONObject obj = (JSONObject)response.getEntity();
+    Assert.assertTrue(obj.containsKey("job"));
+    Assert.assertNotNull(((PigJob) obj.get("job")).getId());
+    Assert.assertFalse(((PigJob) obj.get("job")).getId().isEmpty());
+    Assert.assertTrue(((PigJob) obj.get("job")).getStatusDir().startsWith("/tmp/.pigjobs/admin/test"));
+
+    PigJob job = ((PigJob) obj.get("job"));
+    Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
+    Assert.assertTrue(job.isInProgress());
+  }
+
+  @Test
+  public void testSubmitJobNoArguments() throws Exception {
+    HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
+    expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
+
+    ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
+
+    FSDataOutputStream stream = new FSDataOutputStream(do_stream);
+    expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
+    replay(hdfsApi);
+    JobService.setHdfsApi(hdfsApi);
+
+    TempletonApi api = createNiceMock(TempletonApi.class);
+    jobService.getResourceManager().setTempletonApi(api);
+    TempletonApi.JobData data = api.new JobData();
+    expect(api.runPigQuery((File) anyObject(), anyString(), (String) isNull())).andReturn(data);
+    replay(api);
+
+    Response response = doCreateJob("Test", "/tmp/script.pig", null);
+
+    Assert.assertEquals("", do_stream.toString());
+    Assert.assertEquals(201, response.getStatus());
+
+    JSONObject obj = (JSONObject)response.getEntity();
+    Assert.assertTrue(obj.containsKey("job"));
+    Assert.assertNotNull(((PigJob) obj.get("job")).getId());
+    Assert.assertFalse(((PigJob) obj.get("job")).getId().isEmpty());
+    Assert.assertTrue(((PigJob) obj.get("job")).getStatusDir().startsWith("/tmp/.pigjobs/admin/test"));
+
+    PigJob job = ((PigJob) obj.get("job"));
+    Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
+    Assert.assertTrue(job.isInProgress());
+  }
+
+  @Test
+  public void testSubmitJobNoFile() throws Exception {
+    HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
+    expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
+
+    ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
+
+    FSDataOutputStream stream = new FSDataOutputStream(do_stream);
+    expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
+    replay(hdfsApi);
+    JobService.setHdfsApi(hdfsApi);
+
+    TempletonApi api = createNiceMock(TempletonApi.class);
+    jobService.getResourceManager().setTempletonApi(api);
+    TempletonApi.JobData data = api.new JobData();
+    expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
+    replay(api);
+
+    Response response = doCreateJob("Test", null, "-useHCatalog");
+    Assert.assertEquals(400, response.getStatus());
+    JSONObject obj = (JSONObject)response.getEntity();
+    Assert.assertTrue(((String)obj.get("message")).contains("No pigScript file or forcedContent specifed;"));
+  }
+
+  @Test
+  public void testSubmitJobForcedContent() throws Exception {
+    HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
+
+    ByteArrayOutputStream baScriptStream = new ByteArrayOutputStream();
+    ByteArrayOutputStream baTempletonArgsStream = new ByteArrayOutputStream();
+
+    FSDataOutputStream scriptStream = new FSDataOutputStream(baScriptStream);
+    FSDataOutputStream templetonArgsStream = new FSDataOutputStream(baTempletonArgsStream);
+    expect(hdfsApi.create(endsWith("script.pig"), eq(true))).andReturn(scriptStream);
+    expect(hdfsApi.create(endsWith("params"), eq(true))).andReturn(templetonArgsStream);
+    replay(hdfsApi);
+    JobService.setHdfsApi(hdfsApi);
+
+    TempletonApi api = createNiceMock(TempletonApi.class);
+    jobService.getResourceManager().setTempletonApi(api);
+    TempletonApi.JobData data = api.new JobData();
+    expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
+    replay(api);
+
+    Response response = doCreateJob("Test", null, "-useHCatalog", "pwd");  // with forcedContent
+    Assert.assertEquals(201, response.getStatus());
+    Assert.assertEquals("-useHCatalog", baTempletonArgsStream.toString());
+    Assert.assertEquals("pwd", baScriptStream.toString());
+  }
+
+  @Test
+  public void testSubmitJobNoTitle() throws Exception {
+    HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
+    expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
+
+    ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
+
+    FSDataOutputStream stream = new FSDataOutputStream(do_stream);
+    expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
+    replay(hdfsApi);
+    JobService.setHdfsApi(hdfsApi);
+
+    TempletonApi api = createNiceMock(TempletonApi.class);
+    jobService.getResourceManager().setTempletonApi(api);
+    TempletonApi.JobData data = api.new JobData();
+    expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
+    replay(api);
+
+    Response response = doCreateJob(null, "/tmp/1.pig", "-useHCatalog");
+    Assert.assertEquals(400, response.getStatus());
+    JSONObject obj = (JSONObject)response.getEntity();
+    Assert.assertTrue(((String)obj.get("message")).contains("No title specifed"));
+  }
+
+  @Test
+  public void testSubmitJobFailed() throws Exception {
+    HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
+    expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(false);
+
+    ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
+
+    FSDataOutputStream stream = new FSDataOutputStream(do_stream);
+    expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
+    replay(hdfsApi);
+    JobService.setHdfsApi(hdfsApi);
+
+    TempletonApi api = createNiceMock(TempletonApi.class);
+    jobService.getResourceManager().setTempletonApi(api);
+    TempletonApi.JobData data = api.new JobData();
+    expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
+    replay(api);
+
+    Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
+    Assert.assertEquals(500, response.getStatus());
+    JSONObject obj = (JSONObject)response.getEntity();
+    Assert.assertTrue(((String)obj.get("message")).contains("Can't copy"));
+  }
+
+  @Test
+  public void testSubmitJobTempletonError() throws Exception {
+    HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
+    expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
+
+    ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
+
+    FSDataOutputStream stream = new FSDataOutputStream(do_stream);
+    expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
+    replay(hdfsApi);
+    JobService.setHdfsApi(hdfsApi);
+
+    TempletonApi api = createNiceMock(TempletonApi.class);
+    jobService.getResourceManager().setTempletonApi(api);
+    TempletonApi.JobData data = api.new JobData();
+    // Templeton returns 500 e.g.
+    expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andThrow(new IOException());
+    replay(api);
+
+    Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
+    Assert.assertEquals(500, response.getStatus());
+    JSONObject obj = (JSONObject)response.getEntity();
+    Assert.assertTrue(((String) obj.get("message")).contains("Templeton"));
+  }
+
+  @Test
+  public void testKillJob() throws Exception {
+    HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
+    expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
+
+    ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
+
+    FSDataOutputStream stream = new FSDataOutputStream(do_stream);
+    expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
+    replay(hdfsApi);
+    JobService.setHdfsApi(hdfsApi);
+
+    TempletonApi api = createStrictMock(TempletonApi.class);
+    jobService.getResourceManager().setTempletonApi(api);
+    TempletonApi.JobData data = api.new JobData();
+    data.id = "job_id_##";
+    expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
+    replay(api);
+
+    Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
+    Assert.assertEquals(201, response.getStatus());
+
+    reset(api);
+    api.killJob(eq("job_id_##"));
+    replay(api);
+    JSONObject obj = (JSONObject)response.getEntity();
+    PigJob job = ((PigJob)obj.get("job"));
+    response = jobService.killJob(job.getId());
+    Assert.assertEquals(204, response.getStatus());
+  }
+
+  @Test
+  public void testJobStatusFlow() throws Exception {
+    HdfsApi hdfsApi = createNiceMock(HdfsApi.class);
+    expect(hdfsApi.copy(eq("/tmp/script.pig"), startsWith("/tmp/.pigjobs/"))).andReturn(true);
+
+    ByteArrayOutputStream do_stream = new ByteArrayOutputStream();
+
+    FSDataOutputStream stream = new FSDataOutputStream(do_stream);
+    expect(hdfsApi.create(anyString(), eq(true))).andReturn(stream);
+    replay(hdfsApi);
+    JobService.setHdfsApi(hdfsApi);
+
+    TempletonApi api = createNiceMock(TempletonApi.class);
+    jobService.getResourceManager().setTempletonApi(api);
+    TempletonApi.JobData data = api.new JobData();
+    data.id = "job_id_#";
+    expect(api.runPigQuery((File) anyObject(), anyString(), eq("-useHCatalog"))).andReturn(data);
+    replay(api);
+
+    Response response = doCreateJob("Test", "/tmp/script.pig", "-useHCatalog");
+
+    Assert.assertEquals("-useHCatalog", do_stream.toString());
+    Assert.assertEquals(201, response.getStatus());
+
+    PigJob job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
+    Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
+    Assert.assertTrue(job.isInProgress());
+
+    // Retrieve status:
+    // SUBMITTED
+    reset(api);
+    TempletonApi.JobInfo info = api.new JobInfo();
+    expect(api.checkJob(eq("job_id_#"))).andReturn(info);
+    replay(api);
+    response = jobService.getJob(job.getId());
+    Assert.assertEquals(200, response.getStatus());
+    job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
+    Assert.assertEquals(PigJob.Status.SUBMITTED, job.getStatus());
+
+    // RUNNING
+    reset(api);
+    info = api.new JobInfo();
+    info.status = new HashMap<String, Object>();
+    info.status.put("runState", (double)PigJob.RUN_STATE_RUNNING);
+    info.percentComplete = "30% complete";
+    expect(api.checkJob(eq("job_id_#"))).andReturn(info);
+    replay(api);
+    response = jobService.getJob(job.getId());
+    Assert.assertEquals(200, response.getStatus());
+    job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
+    Assert.assertEquals(PigJob.Status.RUNNING, job.getStatus());
+    Assert.assertTrue(job.isInProgress());
+    Assert.assertEquals(30, (Object) job.getPercentComplete());
+
+    // SUCCEED
+    reset(api);
+    info = api.new JobInfo();
+    info.status = new HashMap<String, Object>();
+    info.status.put("runState", (double)PigJob.RUN_STATE_SUCCEEDED);
+    expect(api.checkJob(eq("job_id_#"))).andReturn(info);
+    replay(api);
+    response = jobService.getJob(job.getId());
+    Assert.assertEquals(200, response.getStatus());
+    job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
+    Assert.assertEquals(PigJob.Status.COMPLETED, job.getStatus());
+    Assert.assertFalse(job.isInProgress());
+    Assert.assertNull(job.getPercentComplete());
+
+    // PREP
+    reset(api);
+    info = api.new JobInfo();
+    info.status = new HashMap<String, Object>();
+    info.status.put("runState", (double)PigJob.RUN_STATE_PREP);
+    expect(api.checkJob(eq("job_id_#"))).andReturn(info);
+    replay(api);
+    response = jobService.getJob(job.getId());
+    Assert.assertEquals(200, response.getStatus());
+    job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
+    Assert.assertEquals(PigJob.Status.RUNNING, job.getStatus());
+
+    // FAILED
+    reset(api);
+    info = api.new JobInfo();
+    info.status = new HashMap<String, Object>();
+    info.status.put("runState", (double)PigJob.RUN_STATE_FAILED);
+    expect(api.checkJob(eq("job_id_#"))).andReturn(info);
+    replay(api);
+    response = jobService.getJob(job.getId());
+    Assert.assertEquals(200, response.getStatus());
+    job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
+    Assert.assertEquals(PigJob.Status.FAILED, job.getStatus());
+    Assert.assertFalse(job.isInProgress());
+
+    // KILLED
+    reset(api);
+    info = api.new JobInfo();
+    info.status = new HashMap<String, Object>();
+    info.status.put("runState", (double)PigJob.RUN_STATE_KILLED);
+    expect(api.checkJob(eq("job_id_#"))).andReturn(info);
+    replay(api);
+    response = jobService.getJob(job.getId());
+    Assert.assertEquals(200, response.getStatus());
+    job = ((PigJob) ((JSONObject)response.getEntity()).get("job"));
+    Assert.assertEquals(PigJob.Status.KILLED, job.getStatus());
+    Assert.assertFalse(job.isInProgress());
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java
index 55a6d20..9eacbee 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestHDFSUnmanaged.java
@@ -39,71 +39,71 @@ import java.util.Map;
 import static org.easymock.EasyMock.*;
 
 public class ScriptTestHDFSUnmanaged extends HDFSTest {
-    private ScriptService scriptService;
-
-    @BeforeClass
-    public static void startUp() throws Exception {
-        HDFSTest.startUp(); // super
-    }
-
-    @AfterClass
-    public static void shutDown() throws Exception {
-        HDFSTest.shutDown(); // super
-        FileService.setHdfsApi(null); //cleanup API connection
-    }
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        handler = createNiceMock(ViewResourceHandler.class);
-        context = createNiceMock(ViewContext.class);
-        FileService.setHdfsApi(null); //cleanup API connection
-        StorageUtil.setStorage(null);
-    }
-
-    @Test(expected=WebServiceException.class)
-    public void createScriptAutoCreateNoScriptsPath() throws IOException, InterruptedException {
-        Map<String, String> properties = new HashMap<String, String>();
-        baseDir = new File(DATA_DIRECTORY)
-                .getAbsoluteFile();
-        pigStorageFile = new File("./target/BasePigTest/storage.dat")
-                .getAbsoluteFile();
-
-        properties.put("dataworker.storagePath", pigStorageFile.toString());
+  private ScriptService scriptService;
+
+  @BeforeClass
+  public static void startUp() throws Exception {
+    HDFSTest.startUp(); // super
+  }
+
+  @AfterClass
+  public static void shutDown() throws Exception {
+    HDFSTest.shutDown(); // super
+    FileService.setHdfsApi(null); //cleanup API connection
+  }
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    handler = createNiceMock(ViewResourceHandler.class);
+    context = createNiceMock(ViewContext.class);
+    FileService.setHdfsApi(null); //cleanup API connection
+    StorageUtil.setStorage(null);
+  }
+
+  @Test(expected=WebServiceException.class)
+  public void createScriptAutoCreateNoScriptsPath() throws IOException, InterruptedException {
+    Map<String, String> properties = new HashMap<String, String>();
+    baseDir = new File(DATA_DIRECTORY)
+        .getAbsoluteFile();
+    pigStorageFile = new File("./target/BasePigTest/storage.dat")
+        .getAbsoluteFile();
+
+    properties.put("dataworker.storagePath", pigStorageFile.toString());
 //        properties.put("dataworker.userScriptsPath", "/tmp/.pigscripts");
-        properties.put("dataworker.defaultFs", hdfsURI);
+    properties.put("dataworker.defaultFs", hdfsURI);
 
-        expect(context.getProperties()).andReturn(properties).anyTimes();
-        expect(context.getUsername()).andReturn("ambari-qa").anyTimes();
+    expect(context.getProperties()).andReturn(properties).anyTimes();
+    expect(context.getUsername()).andReturn("ambari-qa").anyTimes();
 
-        replay(handler, context);
-        scriptService = getService(ScriptService.class, handler, context);
+    replay(handler, context);
+    scriptService = getService(ScriptService.class, handler, context);
 
-        doCreateScript("Test", null);
-    }
+    doCreateScript("Test", null);
+  }
 
-    @Test
-    public void createScriptAutoCreateNoStoragePath() throws IOException, InterruptedException {
-        Map<String, String> properties = new HashMap<String, String>();
-        baseDir = new File(DATA_DIRECTORY)
-                .getAbsoluteFile();
-        pigStorageFile = new File("./target/BasePigTest/storage.dat")
-                .getAbsoluteFile();
+  @Test
+  public void createScriptAutoCreateNoStoragePath() throws IOException, InterruptedException {
+    Map<String, String> properties = new HashMap<String, String>();
+    baseDir = new File(DATA_DIRECTORY)
+        .getAbsoluteFile();
+    pigStorageFile = new File("./target/BasePigTest/storage.dat")
+        .getAbsoluteFile();
 
 //        properties.put("dataworker.storagePath", pigStorageFile.toString());
-        properties.put("dataworker.userScriptsPath", "/tmp/.pigscripts");
-        properties.put("dataworker.defaultFs", hdfsURI);
+    properties.put("dataworker.userScriptsPath", "/tmp/.pigscripts");
+    properties.put("dataworker.defaultFs", hdfsURI);
 
-        expect(context.getProperties()).andReturn(properties).anyTimes();
-        expect(context.getUsername()).andReturn("ambari-qa").anyTimes();
+    expect(context.getProperties()).andReturn(properties).anyTimes();
+    expect(context.getUsername()).andReturn("ambari-qa").anyTimes();
 
-        replay(handler, context);
+    replay(handler, context);
 
-        Storage storage = StorageUtil.getStorage(context);
-        Assert.assertEquals(InstanceKeyValueStorage.class.getSimpleName(), storage.getClass().getSimpleName());
-    }
+    Storage storage = StorageUtil.getStorage(context);
+    Assert.assertEquals(InstanceKeyValueStorage.class.getSimpleName(), storage.getClass().getSimpleName());
+  }
 
-    private Response doCreateScript(String title, String path) {
-        return ScriptTest.doCreateScript(title, path, scriptService);
-    }
+  private Response doCreateScript(String title, String path) {
+    return ScriptTest.doCreateScript(title, path, scriptService);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java
index 61d0004..a6138b5 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/ScriptTestUnmanaged.java
@@ -51,42 +51,42 @@ import static org.easymock.EasyMock.*;
  * Tests without HDFS and predefined properties
  */
 public class ScriptTestUnmanaged extends BasePigTest {
-    private ScriptService scriptService;
-    private File pigStorageFile;
-    private File baseDir;
+  private ScriptService scriptService;
+  private File pigStorageFile;
+  private File baseDir;
 
-    @AfterClass
-    public static void shutDown() throws Exception {
-        FileService.setHdfsApi(null); //cleanup API connection
-    }
+  @AfterClass
+  public static void shutDown() throws Exception {
+    FileService.setHdfsApi(null); //cleanup API connection
+  }
 
-    @Before
-    public void setUp() throws Exception {
-        handler = createNiceMock(ViewResourceHandler.class);
-        context = createNiceMock(ViewContext.class);
+  @Before
+  public void setUp() throws Exception {
+    handler = createNiceMock(ViewResourceHandler.class);
+    context = createNiceMock(ViewContext.class);
 
-        baseDir = new File(DATA_DIRECTORY)
-                .getAbsoluteFile();
-        pigStorageFile = new File("./target/BasePigTest/storage.dat")
-                .getAbsoluteFile();
-    }
+    baseDir = new File(DATA_DIRECTORY)
+        .getAbsoluteFile();
+    pigStorageFile = new File("./target/BasePigTest/storage.dat")
+        .getAbsoluteFile();
+  }
 
-    private Response doCreateScript(String title, String path) {
-        return ScriptTest.doCreateScript(title, path, scriptService);
-    }
+  private Response doCreateScript(String title, String path) {
+    return ScriptTest.doCreateScript(title, path, scriptService);
+  }
 
-    @Test(expected=WebServiceException.class)
-    public void createScriptAutoCreateNoDefaultFS() {
-        Map<String, String> properties = new HashMap<String, String>();
-        properties.put("dataworker.storagePath", pigStorageFile.toString());
-        properties.put("dataworker.userScriptsPath", "/tmp/.pigscripts");
+  @Test(expected=WebServiceException.class)
+  public void createScriptAutoCreateNoDefaultFS() {
+    Map<String, String> properties = new HashMap<String, String>();
+    properties.put("dataworker.storagePath", pigStorageFile.toString());
+    properties.put("dataworker.userScriptsPath", "/tmp/.pigscripts");
 
-        expect(context.getProperties()).andReturn(properties).anyTimes();
-        expect(context.getUsername()).andReturn("ambari-qa").anyTimes();
+    expect(context.getProperties()).andReturn(properties).anyTimes();
+    expect(context.getUsername()).andReturn("ambari-qa").anyTimes();
 
-        replay(handler, context);
-        scriptService = getService(ScriptService.class, handler, context);
+    replay(handler, context);
+    scriptService = getService(ScriptService.class, handler, context);
 
-        doCreateScript("Test", null);
-    }
+    doCreateScript("Test", null);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/UDFTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/UDFTest.java b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/UDFTest.java
index 533499a..6d33fd4 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/UDFTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/UDFTest.java
@@ -36,81 +36,81 @@ import static org.easymock.EasyMock.*;
 import static org.easymock.EasyMock.replay;
 
 public class UDFTest extends BasePigTest {
-    private UDFService udfService;
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-        udfService = getService(UDFService.class, handler, context);
-    }
-
-    private Response doCreateUDF() {
-        UDFService.UDFRequest request = new UDFService.UDFRequest();
-        request.udf = new UDF();
-        request.udf.setPath("/tmp/udf.jar");
-        request.udf.setName("TestUDF");
-
-        UriInfo uriInfo = createNiceMock(UriInfo.class);
-        URI uri = UriBuilder.fromUri("http://host/a/b").build();
-        expect(uriInfo.getAbsolutePath()).andReturn(uri);
-
-        HttpServletResponse resp_obj = createNiceMock(HttpServletResponse.class);
-
-        resp_obj.setHeader(eq("Location"), anyString());
-
-        replay(uriInfo, resp_obj);
-        return udfService.createUDF(request, resp_obj, uriInfo);
-    }
-
-    @Test
-    public void createUDF() {
-        Response response = doCreateUDF();
-        Assert.assertEquals(201, response.getStatus());
-
-        JSONObject obj = (JSONObject)response.getEntity();
-        Assert.assertTrue(obj.containsKey("udf"));
-        Assert.assertNotNull(((UDF) obj.get("udf")).getId());
-        Assert.assertFalse(((UDF) obj.get("udf")).getId().isEmpty());
-    }
-
-    @Test
-    public void udfNotFound() {
-        Response response2 = udfService.getUDF("4242");
-        Assert.assertEquals(404, response2.getStatus());
-    }
-
-    @Test
-    public void updateUDF() {
-        Response createdUDF = doCreateUDF();
-        String createdUdfId = ((UDF) ((JSONObject) createdUDF.getEntity()).get("udf")).getId();
-
-        UDFService.UDFRequest request = new UDFService.UDFRequest();
-        request.udf = new UDF();
-        request.udf.setPath("/tmp/updatedUDF.jar");
-        request.udf.setName("TestUDF2");
-
-        Response response = udfService.updateUDF(request, createdUdfId);
-        Assert.assertEquals(204, response.getStatus());
-
-        Response response2 = udfService.getUDF(createdUdfId);
-        Assert.assertEquals(200, response2.getStatus());
-
-        JSONObject obj = ((JSONObject) response2.getEntity());
-        Assert.assertTrue(obj.containsKey("udf"));
-        Assert.assertEquals(((UDF) obj.get("udf")).getName(), request.udf.getName());
-        Assert.assertEquals(((UDF) obj.get("udf")).getPath(), request.udf.getPath());
-    }
-
-    @Test
-    public void deleteUDF() {
-        Response createdUDF = doCreateUDF();
-        String createdUdfId = ((UDF) ((JSONObject) createdUDF.getEntity()).get("udf")).getId();
-
-        Response response = udfService.deleteUDF(createdUdfId);
-        Assert.assertEquals(204, response.getStatus());
-
-        Response response2 = udfService.getUDF(createdUdfId);
-        Assert.assertEquals(404, response2.getStatus());
-    }
+  private UDFService udfService;
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    udfService = getService(UDFService.class, handler, context);
+  }
+
+  private Response doCreateUDF() {
+    UDFService.UDFRequest request = new UDFService.UDFRequest();
+    request.udf = new UDF();
+    request.udf.setPath("/tmp/udf.jar");
+    request.udf.setName("TestUDF");
+
+    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    URI uri = UriBuilder.fromUri("http://host/a/b").build();
+    expect(uriInfo.getAbsolutePath()).andReturn(uri);
+
+    HttpServletResponse resp_obj = createNiceMock(HttpServletResponse.class);
+
+    resp_obj.setHeader(eq("Location"), anyString());
+
+    replay(uriInfo, resp_obj);
+    return udfService.createUDF(request, resp_obj, uriInfo);
+  }
+
+  @Test
+  public void createUDF() {
+    Response response = doCreateUDF();
+    Assert.assertEquals(201, response.getStatus());
+
+    JSONObject obj = (JSONObject)response.getEntity();
+    Assert.assertTrue(obj.containsKey("udf"));
+    Assert.assertNotNull(((UDF) obj.get("udf")).getId());
+    Assert.assertFalse(((UDF) obj.get("udf")).getId().isEmpty());
+  }
+
+  @Test
+  public void udfNotFound() {
+    Response response2 = udfService.getUDF("4242");
+    Assert.assertEquals(404, response2.getStatus());
+  }
+
+  @Test
+  public void updateUDF() {
+    Response createdUDF = doCreateUDF();
+    String createdUdfId = ((UDF) ((JSONObject) createdUDF.getEntity()).get("udf")).getId();
+
+    UDFService.UDFRequest request = new UDFService.UDFRequest();
+    request.udf = new UDF();
+    request.udf.setPath("/tmp/updatedUDF.jar");
+    request.udf.setName("TestUDF2");
+
+    Response response = udfService.updateUDF(request, createdUdfId);
+    Assert.assertEquals(204, response.getStatus());
+
+    Response response2 = udfService.getUDF(createdUdfId);
+    Assert.assertEquals(200, response2.getStatus());
+
+    JSONObject obj = ((JSONObject) response2.getEntity());
+    Assert.assertTrue(obj.containsKey("udf"));
+    Assert.assertEquals(((UDF) obj.get("udf")).getName(), request.udf.getName());
+    Assert.assertEquals(((UDF) obj.get("udf")).getPath(), request.udf.getPath());
+  }
+
+  @Test
+  public void deleteUDF() {
+    Response createdUDF = doCreateUDF();
+    String createdUdfId = ((UDF) ((JSONObject) createdUDF.getEntity()).get("udf")).getId();
+
+    Response response = udfService.deleteUDF(createdUdfId);
+    Assert.assertEquals(204, response.getStatus());
+
+    Response response2 = udfService.getUDF(createdUdfId);
+    Assert.assertEquals(404, response2.getStatus());
+  }
 }


[3/4] AMBARI-5704. Pig View Cleanup. (mahadev)

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceProvider.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceProvider.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceProvider.java
index 9981952..eb2d962 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceProvider.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceProvider.java
@@ -29,72 +29,75 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+/**
+ * Resource provider for Jobs
+ */
 public class JobResourceProvider implements ResourceProvider<PigJob> {
-    @Inject
-    ViewContext context;
+  @Inject
+  ViewContext context;
 
-    protected JobResourceManager resourceManager = null;
+  protected JobResourceManager resourceManager = null;
 
-    protected synchronized JobResourceManager getResourceManager() {
-        if (resourceManager == null) {
-            resourceManager = new JobResourceManager(context);
-        }
-        return resourceManager;
+  protected synchronized JobResourceManager getResourceManager() {
+    if (resourceManager == null) {
+      resourceManager = new JobResourceManager(context);
     }
+    return resourceManager;
+  }
 
-    @Override
-    public PigJob getResource(String resourceId, Set<String> strings) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        try {
-            return getResourceManager().read(resourceId);
-        } catch (ItemNotFound itemNotFound) {
-            throw new NoSuchResourceException(resourceId);
-        }
+  @Override
+  public PigJob getResource(String resourceId, Set<String> strings) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    try {
+      return getResourceManager().read(resourceId);
+    } catch (ItemNotFound itemNotFound) {
+      throw new NoSuchResourceException(resourceId);
     }
+  }
 
-    @Override
-    public Set<PigJob> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        return new HashSet<PigJob>(getResourceManager().readAll(
-                new OnlyOwnersFilteringStrategy(this.context.getUsername())));
-    }
+  @Override
+  public Set<PigJob> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    return new HashSet<PigJob>(getResourceManager().readAll(
+        new OnlyOwnersFilteringStrategy(this.context.getUsername())));
+  }
 
-    @Override
-    public void createResource(String s, Map<String, Object> stringObjectMap) throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException {
-        PigJob job = null;
-        try {
-            job = new PigJob(stringObjectMap);
-        } catch (InvocationTargetException e) {
-            throw new SystemException("error on creating resource", e);
-        } catch (IllegalAccessException e) {
-            throw new SystemException("error on creating resource", e);
-        }
-        getResourceManager().create(job);
+  @Override
+  public void createResource(String s, Map<String, Object> stringObjectMap) throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException {
+    PigJob job = null;
+    try {
+      job = new PigJob(stringObjectMap);
+    } catch (InvocationTargetException e) {
+      throw new SystemException("error on creating resource", e);
+    } catch (IllegalAccessException e) {
+      throw new SystemException("error on creating resource", e);
     }
+    getResourceManager().create(job);
+  }
 
-    @Override
-    public boolean updateResource(String resourceId, Map<String, Object> stringObjectMap) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        PigJob job = null;
-        try {
-            job = new PigJob(stringObjectMap);
-        } catch (InvocationTargetException e) {
-            throw new SystemException("error on updating resource", e);
-        } catch (IllegalAccessException e) {
-            throw new SystemException("error on updating resource", e);
-        }
-        try {
-            getResourceManager().update(job, resourceId);
-        } catch (ItemNotFound itemNotFound) {
-            throw new NoSuchResourceException(resourceId);
-        }
-        return true;
+  @Override
+  public boolean updateResource(String resourceId, Map<String, Object> stringObjectMap) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    PigJob job = null;
+    try {
+      job = new PigJob(stringObjectMap);
+    } catch (InvocationTargetException e) {
+      throw new SystemException("error on updating resource", e);
+    } catch (IllegalAccessException e) {
+      throw new SystemException("error on updating resource", e);
+    }
+    try {
+      getResourceManager().update(job, resourceId);
+    } catch (ItemNotFound itemNotFound) {
+      throw new NoSuchResourceException(resourceId);
     }
+    return true;
+  }
 
-    @Override
-    public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        try {
-            getResourceManager().delete(resourceId);
-        } catch (ItemNotFound itemNotFound) {
-            throw new NoSuchResourceException(resourceId);
-        }
-        return true;
+  @Override
+  public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    try {
+      getResourceManager().delete(resourceId);
+    } catch (ItemNotFound itemNotFound) {
+      throw new NoSuchResourceException(resourceId);
     }
+    return true;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobService.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobService.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobService.java
index 23705e9..429cbfc 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobService.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobService.java
@@ -51,193 +51,204 @@ import java.util.concurrent.Callable;
  *      callback from Templeton
  */
 public class JobService extends BaseService {
-    @Inject
-    ViewResourceHandler handler;
-
-    protected JobResourceManager resourceManager = null;
-
-    public synchronized JobResourceManager getResourceManager() {
-        if (resourceManager == null) {
-            resourceManager = new JobResourceManager(context);
-        }
-        return resourceManager;
+  @Inject
+  ViewResourceHandler handler;
+
+  protected JobResourceManager resourceManager = null;
+
+  /**
+   * Get resource manager object
+   * @return resource manager object
+   */
+  public synchronized JobResourceManager getResourceManager() {
+    if (resourceManager == null) {
+      resourceManager = new JobResourceManager(context);
     }
-
-    public synchronized void setResourceManager(JobResourceManager resourceManager) {
-        this.resourceManager = resourceManager;
+    return resourceManager;
+  }
+
+  /**
+   * Set resource manager object
+   * @param resourceManager resource manager object
+   */
+  public synchronized void setResourceManager(JobResourceManager resourceManager) {
+    this.resourceManager = resourceManager;
+  }
+
+  /**
+   * Get single item
+   */
+  @GET
+  @Path("{jobId}")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response getJob(@PathParam("jobId") String jobId) {
+    PigJob job = null;
+    try {
+      job = getResourceManager().read(jobId);
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
-
-    /**
-     * Get single item
-     */
-    @GET
-    @Path("{jobId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response getJob(@PathParam("jobId") String jobId) {
-        PigJob job = null;
-        try {
-            job = getResourceManager().read(jobId);
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-        getResourceManager().retrieveJobStatus(job);
-        JSONObject object = new JSONObject();
-        object.put("job", job);
-        return Response.ok(object).build();
+    getResourceManager().retrieveJobStatus(job);
+    JSONObject object = new JSONObject();
+    object.put("job", job);
+    return Response.ok(object).build();
+  }
+
+  /**
+   * Get single item
+   */
+  @DELETE
+  @Path("{jobId}")
+  public Response killJob(@PathParam("jobId") String jobId) throws IOException {
+    PigJob job = null;
+    try {
+      job = getResourceManager().read(jobId);
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
-
-    /**
-     * Get single item
-     */
-    @DELETE
-    @Path("{jobId}")
-    public Response killJob(@PathParam("jobId") String jobId) throws IOException {
-        PigJob job = null;
-        try {
+    getResourceManager().killJob(job);
+    return Response.status(204).build();
+  }
+
+  /**
+   * Callback from templeton
+   */
+  @GET
+  @Path("{jobId}/notify")
+  public Response jobCompletionNotification(@Context HttpHeaders headers,
+                                            @Context UriInfo ui,
+                                            @PathParam("jobId") final String jobId) {
+    PigJob job = null;
+    try {
+      job = getResourceManager().ignorePermissions(new Callable<PigJob>() {
+        public PigJob call() throws Exception {
+          PigJob job = null;
+          try {
             job = getResourceManager().read(jobId);
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
+          } catch (ItemNotFound itemNotFound) {
+            return null;
+          }
+          return job;
         }
-        getResourceManager().killJob(job);
-        return Response.status(204).build();
+      });
+    } catch (Exception e) {
+      return Response.status(500).build();
     }
-
-    /**
-     * Callback from templeton
-     */
-    @GET
-    @Path("{jobId}/notify")
-    public Response jobCompletionNotification(@Context HttpHeaders headers,
-                                              @Context UriInfo ui,
-                                              @PathParam("jobId") final String jobId) {
-        PigJob job = null;
-        try {
-            job = getResourceManager().ignorePermissions(new Callable<PigJob>() {
-                public PigJob call() throws Exception {
-                    PigJob job = null;
-                    try {
-                        job = getResourceManager().read(jobId);
-                    } catch (ItemNotFound itemNotFound) {
-                        return null;
-                    }
-                    return job;
-                }
-            });
-        } catch (Exception e) {
-            return Response.status(500).build();
-        }
-        if (job == null)
-            return Response.status(404).build();
-
-        getResourceManager().retrieveJobStatus(job);
-        return Response.ok().build();
+    if (job == null)
+      return Response.status(404).build();
+
+    getResourceManager().retrieveJobStatus(job);
+    return Response.ok().build();
+  }
+
+  @GET
+  @Path("{jobId}/results/{fileName}")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response jobExitCode(@Context HttpHeaders headers,
+                              @Context UriInfo ui,
+                              @PathParam("jobId") String jobId,
+                              @PathParam("fileName") String fileName,
+                              @QueryParam("page") Long page) {
+    PigJob job = null;
+    try {
+      job = getResourceManager().read(jobId);
+    } catch (ItemNotFound itemNotFound) {
+      return Response.ok("No such job").status(404).build();
     }
-
-    @GET
-    @Path("{jobId}/results/{fileName}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response jobExitCode(@Context HttpHeaders headers,
-                                @Context UriInfo ui,
-                                @PathParam("jobId") String jobId,
-                                @PathParam("fileName") String fileName,
-                                @QueryParam("page") Long page) {
-        PigJob job = null;
-        try {
-            job = getResourceManager().read(jobId);
-        } catch (ItemNotFound itemNotFound) {
-            return Response.ok("No such job").status(404).build();
-        }
-        try {
-            String filePath = job.getStatusDir() + "/" + fileName;
-            LOG.debug("Reading file " + filePath);
-            FilePaginator paginator = new FilePaginator(filePath, context);
-
-            if (page == null)
-                page = 0L;
-
-            FileResource file = new FileResource();
-            file.filePath = filePath;
-            file.fileContent = paginator.readPage(page);
-            file.hasNext = paginator.pageCount() > page + 1;
-            file.page = page;
-            file.pageCount = paginator.pageCount();
-
-            JSONObject object = new JSONObject();
-            object.put("file", file);
-            return Response.ok(object).status(200).build();
-        } catch (IOException e) {
-            return Response.ok(e.getMessage()).status(404).build();
-        } catch (InterruptedException e) {
-            return Response.ok(e.getMessage()).status(404).build();
-        }
+    try {
+      String filePath = job.getStatusDir() + "/" + fileName;
+      LOG.debug("Reading file " + filePath);
+      FilePaginator paginator = new FilePaginator(filePath, context);
+
+      if (page == null)
+        page = 0L;
+
+      FileResource file = new FileResource();
+      file.setFilePath(filePath);
+      file.setFileContent(paginator.readPage(page));
+      file.setHasNext(paginator.pageCount() > page + 1);
+      file.setPage(page);
+      file.setPageCount(paginator.pageCount());
+
+      JSONObject object = new JSONObject();
+      object.put("file", file);
+      return Response.ok(object).status(200).build();
+    } catch (IOException e) {
+      return Response.ok(e.getMessage()).status(404).build();
+    } catch (InterruptedException e) {
+      return Response.ok(e.getMessage()).status(404).build();
     }
-
-    /**
-     * Get all jobs
-     */
-    @GET
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response getJobList(@Context HttpHeaders headers, @Context UriInfo ui) {
-        List allJobs = getResourceManager().readAll(
-                new OnlyOwnersFilteringStrategy(this.context.getUsername()));
-
-        JSONObject object = new JSONObject();
-        object.put("jobs", allJobs);
-        return Response.ok(object).build();
+  }
+
+  /**
+   * Get all jobs
+   */
+  @GET
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response getJobList(@Context HttpHeaders headers, @Context UriInfo ui) {
+    List allJobs = getResourceManager().readAll(
+        new OnlyOwnersFilteringStrategy(this.context.getUsername()));
+
+    JSONObject object = new JSONObject();
+    object.put("jobs", allJobs);
+    return Response.ok(object).build();
+  }
+
+  /**
+   * Create job
+   */
+  @POST
+  @Consumes(MediaType.APPLICATION_JSON)
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response runJob(PigJobRequest request, @Context HttpServletResponse response,
+                         @Context UriInfo ui) {
+    if (!request.validatePOST()) {
+      return badRequestResponse(request.explainPOST());
+    }
+    try {
+      getResourceManager().create(request.job);
+    } catch (IllegalArgumentException e) {
+      return badRequestResponse(e.getMessage());
+    } catch (WebServiceException e) {
+      return serverErrorResponse(e.getMessage());
     }
 
-    /**
-     * Create job
-     */
-    @POST
-    @Consumes(MediaType.APPLICATION_JSON)
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response runJob(PigJobRequest request, @Context HttpServletResponse response,
-                               @Context UriInfo ui) {
-        if (!request.validatePOST()) {
-            return badRequestResponse(request.explainPOST());
-        }
-        try {
-            getResourceManager().create(request.job);
-        } catch (IllegalArgumentException e) {
-            return badRequestResponse(e.getMessage());
-        } catch (WebServiceException e) {
-            return serverErrorResponse(e.getMessage());
-        }
-
-        PigJob job = null;
-
-        try {
-            job = getResourceManager().read(request.job.getId());
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-
-        response.setHeader("Location",
-                String.format("%s/%s", ui.getAbsolutePath().toString(), request.job.getId()));
+    PigJob job = null;
 
-        JSONObject object = new JSONObject();
-        object.put("job", job);
-        return Response.ok(object).status(201).build();
+    try {
+      job = getResourceManager().read(request.job.getId());
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
 
-    public static class PigJobRequest {
-        public PigJob job;
-
-        public String explainPOST() {
-            StringBuilder result = new StringBuilder();
-            if ((job.getPigScript() == null || job.getPigScript().isEmpty()) &&
-                    (job.getForcedContent() == null || job.getForcedContent().isEmpty()))
-                result.append("No pigScript file or forcedContent specifed;");
-            if (job.getTitle() == null || job.getTitle().isEmpty())
-                result.append("No title specifed;");
-            if (job.getId() != null && !job.getTitle().isEmpty())
-                result.append("ID should not exists in creation request;");
-            return result.toString();
-        }
+    response.setHeader("Location",
+        String.format("%s/%s", ui.getAbsolutePath().toString(), request.job.getId()));
+
+    JSONObject object = new JSONObject();
+    object.put("job", job);
+    return Response.ok(object).status(201).build();
+  }
+
+  /**
+   * Wrapper object for json mapping
+   */
+  public static class PigJobRequest {
+    public PigJob job;
+
+    public String explainPOST() {
+      StringBuilder result = new StringBuilder();
+      if ((job.getPigScript() == null || job.getPigScript().isEmpty()) &&
+          (job.getForcedContent() == null || job.getForcedContent().isEmpty()))
+        result.append("No pigScript file or forcedContent specifed;");
+      if (job.getTitle() == null || job.getTitle().isEmpty())
+        result.append("No title specifed;");
+      if (job.getId() != null && !job.getTitle().isEmpty())
+        result.append("ID should not exists in creation request;");
+      return result.toString();
+    }
 
-        public boolean validatePOST() {
-            return explainPOST().isEmpty();
-        }
+    public boolean validatePOST() {
+      return explainPOST().isEmpty();
     }
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/models/PigJob.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/models/PigJob.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/models/PigJob.java
index e49c267..f55da93 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/models/PigJob.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/models/PigJob.java
@@ -37,217 +37,217 @@ import java.util.Map;
  * SUBMITTED   SUBMIT_FAILED
  *     |
  *     |
-  *   [GET result from job/:job_id]
+ *   [GET result from job/:job_id]
  *     |            |             |
  * COMPLETED      KILLED        FAILED
  */
 public class PigJob implements Serializable, PersonalResource {
 
-    public enum Status {
-        UNKNOWN,
-        SUBMITTING, SUBMITTED, RUNNING,  // in progress
-        SUBMIT_FAILED, COMPLETED, FAILED, KILLED  // finished
-    }
-
-    public boolean isInProgress() {
-        return status == Status.SUBMITTED || status == Status.SUBMITTING ||
-                status == Status.RUNNING;
-    }
-
-    public static final int RUN_STATE_RUNNING = 1;
-    public static final int RUN_STATE_SUCCEEDED = 2;
-    public static final int RUN_STATE_FAILED = 3;
-    public static final int RUN_STATE_PREP = 4;
-    public static final int RUN_STATE_KILLED = 5;
-
-    public PigJob() {
-    }
-
-    public PigJob(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException {
-        BeanUtils.populate(this, stringObjectMap);
-    }
-
-    String id = null;
-    String scriptId = null;
-
-    // cloned script data
-    String pigScript = null;
-    String pythonScript = null;
-    String title = null;
-    String templetonArguments = null;
-    String owner;
-
-    // job info
-    String forcedContent = null;
-
-    /**
-     * jobType possible values:
-     * null - regular execute
-     * "explain"
-     * "syntax_check"
-     */
-    String jobType = null;
-
-    /**
-     * Additional file to use in Explain job
-     */
-    String sourceFile = null;
-    String sourceFileContent = null;
-
-    String statusDir;
-    Long dateStarted = 0L;
-    String jobId = null;
-
-    // status fields (not reliable)
-    Status status = Status.UNKNOWN;
-    Integer percentComplete = null;
-
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (!(o instanceof PigJob)) return false;
-
-        PigJob pigScript = (PigJob) o;
-
-        if (!id.equals(pigScript.id)) return false;
-
-        return true;
-    }
-
-    @Override
-    public int hashCode() {
-        return id.hashCode();
-    }
-
-    @Override
-    public String getId() {
-        return id;
-    }
-
-    @Override
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    @Override
-    public String getOwner() {
-        return owner;
-    }
-
-    @Override
-    public void setOwner(String owner) {
-        this.owner = owner;
-    }
-
-    public Status getStatus() {
-        return status;
-    }
-
-    public void setStatus(Status status) {
-        this.status = status;
-    }
-
-    public String getScriptId() {
-        return scriptId;
-    }
-
-    public void setScriptId(String scriptId) {
-        this.scriptId = scriptId;
-    }
-
-    public String getTempletonArguments() {
-        return templetonArguments;
-    }
-
-    public void setTempletonArguments(String templetonArguments) {
-        this.templetonArguments = templetonArguments;
-    }
-
-    public String getPigScript() {
-        return pigScript;
-    }
-
-    public void setPigScript(String pigScript) {
-        this.pigScript = pigScript;
-    }
-
-    public String getJobId() {
-        return jobId;
-    }
-
-    public void setJobId(String jobId) {
-        this.jobId = jobId;
-    }
-
-    public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
-    public void setStatusDir(String statusDir) {
-        this.statusDir = statusDir;
-    }
-
-    public String getStatusDir() {
-        return statusDir;
-    }
-
-    public Long getDateStarted() {
-        return dateStarted;
-    }
-
-    public void setDateStarted(Long dateStarted) {
-        this.dateStarted = dateStarted;
-    }
-
-    public Integer getPercentComplete() {
-        return percentComplete;
-    }
+  public enum Status {
+    UNKNOWN,
+    SUBMITTING, SUBMITTED, RUNNING,  // in progress
+    SUBMIT_FAILED, COMPLETED, FAILED, KILLED  // finished
+  }
+
+  public boolean isInProgress() {
+    return status == Status.SUBMITTED || status == Status.SUBMITTING ||
+        status == Status.RUNNING;
+  }
+
+  public static final int RUN_STATE_RUNNING = 1;
+  public static final int RUN_STATE_SUCCEEDED = 2;
+  public static final int RUN_STATE_FAILED = 3;
+  public static final int RUN_STATE_PREP = 4;
+  public static final int RUN_STATE_KILLED = 5;
+
+  public PigJob() {
+  }
+
+  public PigJob(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException {
+    BeanUtils.populate(this, stringObjectMap);
+  }
+
+  private String id = null;
+  private String scriptId = null;
+
+  // cloned script data
+  private String pigScript = null;
+  private String pythonScript = null;
+  private String title = null;
+  private String templetonArguments = null;
+  private String owner;
+
+  // job info
+  private String forcedContent = null;
+
+  /**
+   * jobType possible values:
+   * null - regular execute
+   * "explain"
+   * "syntax_check"
+   */
+  private String jobType = null;
+
+  /**
+   * Additional file to use in Explain job
+   */
+  private String sourceFile = null;
+  private String sourceFileContent = null;
+
+  private String statusDir;
+  private Long dateStarted = 0L;
+  private String jobId = null;
+
+  // status fields (not reliable)
+  private Status status = Status.UNKNOWN;
+  private Integer percentComplete = null;
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof PigJob)) return false;
+
+    PigJob pigScript = (PigJob) o;
+
+    if (!id.equals(pigScript.id)) return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    return id.hashCode();
+  }
+
+  @Override
+  public String getId() {
+    return id;
+  }
+
+  @Override
+  public void setId(String id) {
+    this.id = id;
+  }
+
+  @Override
+  public String getOwner() {
+    return owner;
+  }
+
+  @Override
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
+
+  public Status getStatus() {
+    return status;
+  }
+
+  public void setStatus(Status status) {
+    this.status = status;
+  }
+
+  public String getScriptId() {
+    return scriptId;
+  }
+
+  public void setScriptId(String scriptId) {
+    this.scriptId = scriptId;
+  }
+
+  public String getTempletonArguments() {
+    return templetonArguments;
+  }
+
+  public void setTempletonArguments(String templetonArguments) {
+    this.templetonArguments = templetonArguments;
+  }
+
+  public String getPigScript() {
+    return pigScript;
+  }
+
+  public void setPigScript(String pigScript) {
+    this.pigScript = pigScript;
+  }
+
+  public String getJobId() {
+    return jobId;
+  }
+
+  public void setJobId(String jobId) {
+    this.jobId = jobId;
+  }
+
+  public String getTitle() {
+    return title;
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public void setStatusDir(String statusDir) {
+    this.statusDir = statusDir;
+  }
+
+  public String getStatusDir() {
+    return statusDir;
+  }
+
+  public Long getDateStarted() {
+    return dateStarted;
+  }
+
+  public void setDateStarted(Long dateStarted) {
+    this.dateStarted = dateStarted;
+  }
+
+  public Integer getPercentComplete() {
+    return percentComplete;
+  }
 
-    public void setPercentComplete(Integer percentComplete) {
-        this.percentComplete = percentComplete;
-    }
-
-    public String getPythonScript() {
-        return pythonScript;
-    }
-
-    public void setPythonScript(String pythonScript) {
-        this.pythonScript = pythonScript;
-    }
-
-    public String getForcedContent() {
-        return forcedContent;
-    }
-
-    public void setForcedContent(String forcedContent) {
-        this.forcedContent = forcedContent;
-    }
-
-    public String getJobType() {
-        return jobType;
-    }
-
-    public void setJobType(String jobType) {
-        this.jobType = jobType;
-    }
-
-    public String getSourceFileContent() {
-        return sourceFileContent;
-    }
+  public void setPercentComplete(Integer percentComplete) {
+    this.percentComplete = percentComplete;
+  }
+
+  public String getPythonScript() {
+    return pythonScript;
+  }
+
+  public void setPythonScript(String pythonScript) {
+    this.pythonScript = pythonScript;
+  }
+
+  public String getForcedContent() {
+    return forcedContent;
+  }
+
+  public void setForcedContent(String forcedContent) {
+    this.forcedContent = forcedContent;
+  }
+
+  public String getJobType() {
+    return jobType;
+  }
+
+  public void setJobType(String jobType) {
+    this.jobType = jobType;
+  }
+
+  public String getSourceFileContent() {
+    return sourceFileContent;
+  }
 
-    public void setSourceFileContent(String sourceFileContent) {
-        this.sourceFileContent = sourceFileContent;
-    }
+  public void setSourceFileContent(String sourceFileContent) {
+    this.sourceFileContent = sourceFileContent;
+  }
 
-    public String getSourceFile() {
-        return sourceFile;
-    }
+  public String getSourceFile() {
+    return sourceFile;
+  }
 
-    public void setSourceFile(String sourceFile) {
-        this.sourceFile = sourceFile;
-    }
+  public void setSourceFile(String sourceFile) {
+    this.sourceFile = sourceFile;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/utils/JobPolling.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/utils/JobPolling.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/utils/JobPolling.java
index 31eabae..bc633b2 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/utils/JobPolling.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/utils/JobPolling.java
@@ -40,104 +40,107 @@ import java.util.concurrent.TimeUnit;
  * killed, changed progress and so on.
  */
 public class JobPolling implements Runnable {
-    private final static Logger LOG =
-            LoggerFactory.getLogger(JobPolling.class);
+  private final static Logger LOG =
+      LoggerFactory.getLogger(JobPolling.class);
 
-    /**
-     * We should limit count of concurrent calls to templeton
-     * to avoid high load on component
-     */
-    private static final int WORKER_COUNT = 2;
+  /**
+   * We should limit count of concurrent calls to templeton
+   * to avoid high load on component
+   */
+  private static final int WORKER_COUNT = 2;
 
-    private static final int POLLING_DELAY = 10*60;  // 10 minutes
+  private static final int POLLING_DELAY = 10*60;  // 10 minutes
 
-    /**
-     * In LONG_JOB_THRESHOLD seconds job reschedules polling from POLLING_DELAY to LONG_POLLING_DELAY
-     */
-    private static final int LONG_POLLING_DELAY = 60*60; // 1 hour
-    private static final int LONG_JOB_THRESHOLD = 60*60; // 1 hour
+  /**
+   * In LONG_JOB_THRESHOLD seconds job reschedules polling from POLLING_DELAY to LONG_POLLING_DELAY
+   */
+  private static final int LONG_POLLING_DELAY = 60*60; // 1 hour
+  private static final int LONG_JOB_THRESHOLD = 60*60; // 1 hour
 
-    private static final ScheduledExecutorService pollWorkersPool = Executors.newScheduledThreadPool(WORKER_COUNT);
+  private static final ScheduledExecutorService pollWorkersPool = Executors.newScheduledThreadPool(WORKER_COUNT);
 
-    private static final Map<String, JobPolling> jobPollers = new HashMap<String, JobPolling>();
+  private static final Map<String, JobPolling> jobPollers = new HashMap<String, JobPolling>();
 
-    private JobResourceManager resourceManager = null;
-    private final ViewContext context;
-    private PigJob job;
-    private volatile ScheduledFuture<?> thisFuture;
+  private JobResourceManager resourceManager = null;
+  private final ViewContext context;
+  private PigJob job;
+  private volatile ScheduledFuture<?> thisFuture;
 
-    private JobPolling(ViewContext context, PigJob job) {
-        this.context = context;
-        this.job = job;
-    }
+  private JobPolling(ViewContext context, PigJob job) {
+    this.context = context;
+    this.job = job;
+  }
 
-    protected synchronized JobResourceManager getResourceManager() {
-        if (resourceManager == null) {
-            resourceManager = new JobResourceManager(context);
-        }
-        return resourceManager;
+  protected synchronized JobResourceManager getResourceManager() {
+    if (resourceManager == null) {
+      resourceManager = new JobResourceManager(context);
     }
-
-    public void run() {
-        LOG.debug("Polling job status " + job.getJobId() + " #" + job.getId());
-        try {
-            job = getResourceManager().read(job.getId());
-        } catch (ItemNotFound itemNotFound) {
-            LOG.error("Job " + job.getJobId() + " does not exist! Polling canceled");
-            thisFuture.cancel(false);
-            return;
-        }
-        getResourceManager().retrieveJobStatus(job);
-
-        Long time = System.currentTimeMillis() / 1000L;
-        if (time - job.getDateStarted() > LONG_JOB_THRESHOLD) {
-            LOG.debug("Job becomes long.. Rescheduling polling to longer period");
-            // If job running longer than LONG_JOB_THRESHOLD, reschedule
-            // it to poll every LONG_POLLING_DELAY instead of POLLING_DELAY
-            thisFuture.cancel(false);
-            scheduleJobPolling(true);
-        }
-
-        switch (job.getStatus()) {
-            case SUBMIT_FAILED:
-            case COMPLETED:
-            case FAILED:
-            case KILLED:
-                LOG.debug("Job finished. Polling canceled");
-                thisFuture.cancel(false);
-                break;
-            default:
-        }
+    return resourceManager;
+  }
+
+  /**
+   * Do polling
+   */
+  public void run() {
+    LOG.debug("Polling job status " + job.getJobId() + " #" + job.getId());
+    try {
+      job = getResourceManager().read(job.getId());
+    } catch (ItemNotFound itemNotFound) {
+      LOG.error("Job " + job.getJobId() + " does not exist! Polling canceled");
+      thisFuture.cancel(false);
+      return;
     }
-
-    private void scheduleJobPolling(boolean longDelay) {
-        if (!longDelay) {
-            thisFuture = pollWorkersPool.scheduleWithFixedDelay(this,
-                    POLLING_DELAY, POLLING_DELAY, TimeUnit.SECONDS);
-        } else {
-            thisFuture = pollWorkersPool.scheduleWithFixedDelay(this,
-                    LONG_POLLING_DELAY, LONG_POLLING_DELAY, TimeUnit.SECONDS);
-        }
+    getResourceManager().retrieveJobStatus(job);
+
+    Long time = System.currentTimeMillis() / 1000L;
+    if (time - job.getDateStarted() > LONG_JOB_THRESHOLD) {
+      LOG.debug("Job becomes long.. Rescheduling polling to longer period");
+      // If job running longer than LONG_JOB_THRESHOLD, reschedule
+      // it to poll every LONG_POLLING_DELAY instead of POLLING_DELAY
+      thisFuture.cancel(false);
+      scheduleJobPolling(true);
     }
 
-    private void scheduleJobPolling() {
-        scheduleJobPolling(false);
+    switch (job.getStatus()) {
+      case SUBMIT_FAILED:
+      case COMPLETED:
+      case FAILED:
+      case KILLED:
+        LOG.debug("Job finished. Polling canceled");
+        thisFuture.cancel(false);
+        break;
+      default:
     }
-
-    /**
-     * Schedule job polling
-     * @param context ViewContext of web app
-     * @param job job instance
-     * @return returns false if already scheduled
-     */
-    public static boolean pollJob(ViewContext context, PigJob job) {
-        if (jobPollers.get(job.getJobId()) == null) {
-            LOG.debug("Setting up polling for " + job.getJobId());
-            JobPolling polling = new JobPolling(context, job);
-            polling.scheduleJobPolling();
-            jobPollers.put(job.getJobId(), polling);
-            return true;
-        }
-        return false;
+  }
+
+  private void scheduleJobPolling(boolean longDelay) {
+    if (!longDelay) {
+      thisFuture = pollWorkersPool.scheduleWithFixedDelay(this,
+          POLLING_DELAY, POLLING_DELAY, TimeUnit.SECONDS);
+    } else {
+      thisFuture = pollWorkersPool.scheduleWithFixedDelay(this,
+          LONG_POLLING_DELAY, LONG_POLLING_DELAY, TimeUnit.SECONDS);
+    }
+  }
+
+  private void scheduleJobPolling() {
+    scheduleJobPolling(false);
+  }
+
+  /**
+   * Schedule job polling
+   * @param context ViewContext of web app
+   * @param job job instance
+   * @return returns false if already scheduled
+   */
+  public static boolean pollJob(ViewContext context, PigJob job) {
+    if (jobPollers.get(job.getJobId()) == null) {
+      LOG.debug("Setting up polling for " + job.getJobId());
+      JobPolling polling = new JobPolling(context, job);
+      polling.scheduleJobPolling();
+      jobPollers.put(job.getJobId(), polling);
+      return true;
     }
+    return false;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceManager.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceManager.java
index 9714d27..f98bdab 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceManager.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceManager.java
@@ -33,69 +33,76 @@ import java.io.IOException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
+/**
+ * Object that provides CRUD operations for script objects
+ */
 public class ScriptResourceManager extends PersonalCRUDResourceManager<PigScript> {
-    private final static Logger LOG =
-            LoggerFactory.getLogger(ScriptResourceManager.class);
+  private final static Logger LOG =
+      LoggerFactory.getLogger(ScriptResourceManager.class);
 
-    public ScriptResourceManager(ViewContext context) {
-        super(PigScript.class, context);
-    }
+  /**
+   * Constructor
+   * @param context View Context instance
+   */
+  public ScriptResourceManager(ViewContext context) {
+    super(PigScript.class, context);
+  }
 
-    @Override
-    public PigScript create(PigScript object) {
-        super.create(object);
-        if (object.getPigScript() == null || object.getPigScript().isEmpty()) {
-            createDefaultScriptFile(object);
-        }
-        return object;
+  @Override
+  public PigScript create(PigScript object) {
+    super.create(object);
+    if (object.getPigScript() == null || object.getPigScript().isEmpty()) {
+      createDefaultScriptFile(object);
     }
+    return object;
+  }
 
-    private void createDefaultScriptFile(PigScript object) {
-        String userScriptsPath = context.getProperties().get("dataworker.userScriptsPath");
-        if (userScriptsPath == null) {
-            String msg = "dataworker.userScriptsPath is not configured!";
-            LOG.error(msg);
-            throw new WebServiceException(msg);
-        }
-        int checkId = 0;
+  private void createDefaultScriptFile(PigScript object) {
+    String userScriptsPath = context.getProperties().get("dataworker.userScriptsPath");
+    if (userScriptsPath == null) {
+      String msg = "dataworker.userScriptsPath is not configured!";
+      LOG.error(msg);
+      throw new WebServiceException(msg);
+    }
+    int checkId = 0;
 
-        boolean fileCreated;
-        String newFilePath;
-        do {
-            String normalizedName = object.getTitle().replaceAll("[^a-zA-Z0-9 ]+", "").replaceAll(" ", "_").toLowerCase();
-            String timestamp = new SimpleDateFormat("yyyy-MM-dd_hh-mm").format(new Date());
-            newFilePath = String.format(userScriptsPath +
-                    "/%s/%s-%s%s.pig", context.getUsername(),
-                    normalizedName, timestamp, (checkId == 0)?"":"_"+checkId);
-            LOG.debug("Trying to create new file " + newFilePath);
+    boolean fileCreated;
+    String newFilePath;
+    do {
+      String normalizedName = object.getTitle().replaceAll("[^a-zA-Z0-9 ]+", "").replaceAll(" ", "_").toLowerCase();
+      String timestamp = new SimpleDateFormat("yyyy-MM-dd_hh-mm").format(new Date());
+      newFilePath = String.format(userScriptsPath +
+              "/%s/%s-%s%s.pig", context.getUsername(),
+          normalizedName, timestamp, (checkId == 0)?"":"_"+checkId);
+      LOG.debug("Trying to create new file " + newFilePath);
 
-            try {
-                FSDataOutputStream stream = BaseService.getHdfsApi(context).create(newFilePath, false);
-                stream.close();
-                fileCreated = true;
-                LOG.debug("File created successfully!");
-            } catch (FileAlreadyExistsException e) {
-                fileCreated = false;
-                LOG.debug("File already exists. Trying next id");
-            } catch (IOException e) {
-                try {
-                    delete(object.getId());
-                } catch (ItemNotFound itemNotFound) {
-                    throw new WebServiceException("Error in creation, during clean up: " + itemNotFound.toString(), itemNotFound);
-                }
-                throw new WebServiceException("Error in creation: " + e.toString(), e);
-            } catch (InterruptedException e) {
-                try {
-                    delete(object.getId());
-                } catch (ItemNotFound itemNotFound) {
-                    throw new WebServiceException("Error in creation, during clean up: " + itemNotFound.toString(), itemNotFound);
-                }
-                throw new WebServiceException("Error in creation: " + e.toString(), e);
-            }
-            checkId += 1;
-        } while (!fileCreated);
+      try {
+        FSDataOutputStream stream = BaseService.getHdfsApi(context).create(newFilePath, false);
+        stream.close();
+        fileCreated = true;
+        LOG.debug("File created successfully!");
+      } catch (FileAlreadyExistsException e) {
+        fileCreated = false;
+        LOG.debug("File already exists. Trying next id");
+      } catch (IOException e) {
+        try {
+          delete(object.getId());
+        } catch (ItemNotFound itemNotFound) {
+          throw new WebServiceException("Error in creation, during clean up: " + itemNotFound.toString(), itemNotFound);
+        }
+        throw new WebServiceException("Error in creation: " + e.toString(), e);
+      } catch (InterruptedException e) {
+        try {
+          delete(object.getId());
+        } catch (ItemNotFound itemNotFound) {
+          throw new WebServiceException("Error in creation, during clean up: " + itemNotFound.toString(), itemNotFound);
+        }
+        throw new WebServiceException("Error in creation: " + e.toString(), e);
+      }
+      checkId += 1;
+    } while (!fileCreated);
 
-        object.setPigScript(newFilePath);
-        getPigStorage().store(object);
-    }
+    object.setPigScript(newFilePath);
+    getPigStorage().store(object);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceProvider.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceProvider.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceProvider.java
index 478a460..6313183 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceProvider.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptResourceProvider.java
@@ -30,74 +30,77 @@ import org.slf4j.LoggerFactory;
 import java.lang.reflect.InvocationTargetException;
 import java.util.*;
 
+/**
+ * Resource provider for Scripts
+ */
 public class ScriptResourceProvider implements ResourceProvider<PigScript> {
-    @Inject
-    ViewContext context;
+  @Inject
+  ViewContext context;
 
-    protected ScriptResourceManager resourceManager = null;
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(ScriptResourceProvider.class);
+  protected ScriptResourceManager resourceManager = null;
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(ScriptResourceProvider.class);
 
-    protected synchronized PersonalCRUDResourceManager<PigScript> getResourceManager() {
-        if (resourceManager == null) {
-            resourceManager = new ScriptResourceManager(context);
-        }
-        return resourceManager;
+  protected synchronized PersonalCRUDResourceManager<PigScript> getResourceManager() {
+    if (resourceManager == null) {
+      resourceManager = new ScriptResourceManager(context);
     }
+    return resourceManager;
+  }
 
-    @Override
-    public PigScript getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        try {
-            return getResourceManager().read(resourceId);
-        } catch (ItemNotFound itemNotFound) {
-            throw new NoSuchResourceException(resourceId);
-        }
+  @Override
+  public PigScript getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    try {
+      return getResourceManager().read(resourceId);
+    } catch (ItemNotFound itemNotFound) {
+      throw new NoSuchResourceException(resourceId);
     }
+  }
 
-    @Override
-    public Set<PigScript> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        return new HashSet<PigScript>(getResourceManager().readAll(
-                new OnlyOwnersFilteringStrategy(this.context.getUsername())));
-    }
+  @Override
+  public Set<PigScript> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    return new HashSet<PigScript>(getResourceManager().readAll(
+        new OnlyOwnersFilteringStrategy(this.context.getUsername())));
+  }
 
-    @Override
-    public void createResource(String s, Map<String, Object> stringObjectMap) throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException {
-        PigScript script = null;
-        try {
-            script = new PigScript(stringObjectMap);
-        } catch (InvocationTargetException e) {
-            throw new SystemException("error on creating resource", e);
-        } catch (IllegalAccessException e) {
-            throw new SystemException("error on creating resource", e);
-        }
-        getResourceManager().create(script);
+  @Override
+  public void createResource(String s, Map<String, Object> stringObjectMap) throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException {
+    PigScript script = null;
+    try {
+      script = new PigScript(stringObjectMap);
+    } catch (InvocationTargetException e) {
+      throw new SystemException("error on creating resource", e);
+    } catch (IllegalAccessException e) {
+      throw new SystemException("error on creating resource", e);
     }
+    getResourceManager().create(script);
+  }
 
-    @Override
-    public boolean updateResource(String resourceId, Map<String, Object> stringObjectMap) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        PigScript script = null;
-        try {
-            script = new PigScript(stringObjectMap);
-        } catch (InvocationTargetException e) {
-            throw new SystemException("error on updating resource", e);
-        } catch (IllegalAccessException e) {
-            throw new SystemException("error on updating resource", e);
-        }
-        try {
-            getResourceManager().update(script, resourceId);
-        } catch (ItemNotFound itemNotFound) {
-            throw new NoSuchResourceException(resourceId);
-        }
-        return true;
+  @Override
+  public boolean updateResource(String resourceId, Map<String, Object> stringObjectMap) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    PigScript script = null;
+    try {
+      script = new PigScript(stringObjectMap);
+    } catch (InvocationTargetException e) {
+      throw new SystemException("error on updating resource", e);
+    } catch (IllegalAccessException e) {
+      throw new SystemException("error on updating resource", e);
+    }
+    try {
+      getResourceManager().update(script, resourceId);
+    } catch (ItemNotFound itemNotFound) {
+      throw new NoSuchResourceException(resourceId);
     }
+    return true;
+  }
 
-    @Override
-    public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        try {
-            getResourceManager().delete(resourceId);
-        } catch (ItemNotFound itemNotFound) {
-            throw new NoSuchResourceException(resourceId);
-        }
-        return true;
+  @Override
+  public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    try {
+      getResourceManager().delete(resourceId);
+    } catch (ItemNotFound itemNotFound) {
+      throw new NoSuchResourceException(resourceId);
     }
+    return true;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptService.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptService.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptService.java
index c07f985..07ee1de 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptService.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/ScriptService.java
@@ -46,109 +46,112 @@ import java.util.List;
  *      get all scripts of current user
  */
 public class ScriptService extends BaseService {
-    @Inject
-    ViewResourceHandler handler;
-
-    protected ScriptResourceManager resourceManager = null;
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(ScriptService.class);
-
-    protected synchronized PersonalCRUDResourceManager<PigScript> getResourceManager() {
-        if (resourceManager == null) {
-            resourceManager = new ScriptResourceManager(context);
-        }
-        return resourceManager;
-    }
+  @Inject
+  ViewResourceHandler handler;
 
-    /**
-     * Get single item
-     */
-    @GET
-    @Path("{scriptId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response getScript(@PathParam("scriptId") String scriptId) {
-        PigScript script = null;
-        try {
-            script = getResourceManager().read(scriptId);
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-        JSONObject object = new JSONObject();
-        object.put("script", script);
-        return Response.ok(object).build();
-    }
+  protected ScriptResourceManager resourceManager = null;
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(ScriptService.class);
 
-    /**
-     * Delete single item
-     */
-    @DELETE
-    @Path("{scriptId}")
-    public Response deleteScript(@PathParam("scriptId") String scriptId) {
-        try {
-            getResourceManager().delete(scriptId);
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-        return Response.status(204).build();
+  protected synchronized PersonalCRUDResourceManager<PigScript> getResourceManager() {
+    if (resourceManager == null) {
+      resourceManager = new ScriptResourceManager(context);
     }
-
-    /**
-     * Get all scripts
-     */
-    @GET
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response getScriptList() {
-        LOG.debug("Getting all scripts");
-        List allScripts = getResourceManager().readAll(
-                new OnlyOwnersFilteringStrategy(this.context.getUsername()));
-
-        JSONObject object = new JSONObject();
-        object.put("scripts", allScripts);
-        return Response.ok(object).build();
+    return resourceManager;
+  }
+
+  /**
+   * Get single item
+   */
+  @GET
+  @Path("{scriptId}")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response getScript(@PathParam("scriptId") String scriptId) {
+    PigScript script = null;
+    try {
+      script = getResourceManager().read(scriptId);
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
-
-    /**
-     * Update item
-     */
-    @PUT
-    @Path("{scriptId}")
-    @Consumes(MediaType.APPLICATION_JSON)
-    public Response updateScript(PigScriptRequest request,
-                                 @PathParam("scriptId") String scriptId) {
-        try {
-            getResourceManager().update(request.script, scriptId);
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-        return Response.status(204).build();
+    JSONObject object = new JSONObject();
+    object.put("script", script);
+    return Response.ok(object).build();
+  }
+
+  /**
+   * Delete single item
+   */
+  @DELETE
+  @Path("{scriptId}")
+  public Response deleteScript(@PathParam("scriptId") String scriptId) {
+    try {
+      getResourceManager().delete(scriptId);
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
-
-    /**
-     * Create script
-     */
-    @POST
-    @Consumes(MediaType.APPLICATION_JSON)
-    public Response saveScript(PigScriptRequest request, @Context HttpServletResponse response,
-                               @Context UriInfo ui) {
-        getResourceManager().create(request.script);
-
-        PigScript script = null;
-
-        try {
-            script = getResourceManager().read(request.script.getId());
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-
-        response.setHeader("Location",
-                String.format("%s/%s", ui.getAbsolutePath().toString(), request.script.getId()));
-
-        JSONObject object = new JSONObject();
-        object.put("script", script);
-        return Response.ok(object).status(201).build();
+    return Response.status(204).build();
+  }
+
+  /**
+   * Get all scripts
+   */
+  @GET
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response getScriptList() {
+    LOG.debug("Getting all scripts");
+    List allScripts = getResourceManager().readAll(
+        new OnlyOwnersFilteringStrategy(this.context.getUsername()));
+
+    JSONObject object = new JSONObject();
+    object.put("scripts", allScripts);
+    return Response.ok(object).build();
+  }
+
+  /**
+   * Update item
+   */
+  @PUT
+  @Path("{scriptId}")
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response updateScript(PigScriptRequest request,
+                               @PathParam("scriptId") String scriptId) {
+    try {
+      getResourceManager().update(request.script, scriptId);
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
-
-    public static class PigScriptRequest {
-        public PigScript script;
+    return Response.status(204).build();
+  }
+
+  /**
+   * Create script
+   */
+  @POST
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response saveScript(PigScriptRequest request, @Context HttpServletResponse response,
+                             @Context UriInfo ui) {
+    getResourceManager().create(request.script);
+
+    PigScript script = null;
+
+    try {
+      script = getResourceManager().read(request.script.getId());
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
+
+    response.setHeader("Location",
+        String.format("%s/%s", ui.getAbsolutePath().toString(), request.script.getId()));
+
+    JSONObject object = new JSONObject();
+    object.put("script", script);
+    return Response.ok(object).status(201).build();
+  }
+
+  /**
+   * Wrapper object for json mapping
+   */
+  public static class PigScriptRequest {
+    public PigScript script;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/models/PigScript.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/models/PigScript.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/models/PigScript.java
index 1c69adb..44e625a 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/models/PigScript.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/scripts/models/PigScript.java
@@ -30,102 +30,102 @@ import java.util.Map;
  * Bean to represent script
  */
 public class PigScript implements Serializable, PersonalResource {
-    String id;
+  private String id;
 
-    String title = "";
-    String pigScript = "";
-    String pythonScript = "";
-    String templetonArguments = "";
-    Date dateCreated;
-    String owner = "";
+  private String title = "";
+  private String pigScript = "";
+  private String pythonScript = "";
+  private String templetonArguments = "";
+  private Date dateCreated;
+  private String owner = "";
 
-    boolean opened = false;
+  private boolean opened = false;
 
-    public PigScript() {
-    }
+  public PigScript() {
+  }
 
-    public PigScript(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException {
-        BeanUtils.populate(this, stringObjectMap);
-    }
+  public PigScript(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException {
+    BeanUtils.populate(this, stringObjectMap);
+  }
 
-    @Override
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (!(o instanceof PigScript)) return false;
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof PigScript)) return false;
 
-        PigScript pigScript = (PigScript) o;
+    PigScript pigScript = (PigScript) o;
 
-        if (!id.equals(pigScript.id)) return false;
+    if (!id.equals(pigScript.id)) return false;
 
-        return true;
-    }
+    return true;
+  }
 
-    @Override
-    public int hashCode() {
-        return id.hashCode();
-    }
+  @Override
+  public int hashCode() {
+    return id.hashCode();
+  }
 
-    public String getId() {
-        return id;
-    }
+  public String getId() {
+    return id;
+  }
 
-    public void setId(String id) {
-        this.id = id;
-    }
+  public void setId(String id) {
+    this.id = id;
+  }
 
-    public String getTitle() {
-        return title;
-    }
+  public String getTitle() {
+    return title;
+  }
 
-    public void setTitle(String title) {
-        this.title = title;
-    }
+  public void setTitle(String title) {
+    this.title = title;
+  }
 
-    public String getPigScript() {
-        return pigScript;
-    }
+  public String getPigScript() {
+    return pigScript;
+  }
 
-    public void setPigScript(String pigScript) {
-        this.pigScript = pigScript;
-    }
+  public void setPigScript(String pigScript) {
+    this.pigScript = pigScript;
+  }
 
-    public String getTempletonArguments() {
-        return templetonArguments;
-    }
+  public String getTempletonArguments() {
+    return templetonArguments;
+  }
 
-    public void setTempletonArguments(String templetonArguments) {
-        this.templetonArguments = templetonArguments;
-    }
+  public void setTempletonArguments(String templetonArguments) {
+    this.templetonArguments = templetonArguments;
+  }
 
-    public Date getDateCreated() {
-        return dateCreated;
-    }
+  public Date getDateCreated() {
+    return dateCreated;
+  }
 
-    public void setDateCreated(Date dateCreated) {
-        this.dateCreated = dateCreated;
-    }
+  public void setDateCreated(Date dateCreated) {
+    this.dateCreated = dateCreated;
+  }
 
-    public boolean isOpened() {
-        return opened;
-    }
+  public boolean isOpened() {
+    return opened;
+  }
 
-    public void setOpened(boolean opened) {
-        this.opened = opened;
-    }
+  public void setOpened(boolean opened) {
+    this.opened = opened;
+  }
 
-    public String getOwner() {
-        return owner;
-    }
+  public String getOwner() {
+    return owner;
+  }
 
-    public void setOwner(String owner) {
-        this.owner = owner;
-    }
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
 
-    public String getPythonScript() {
-        return pythonScript;
-    }
+  public String getPythonScript() {
+    return pythonScript;
+  }
 
-    public void setPythonScript(String pythonScript) {
-        this.pythonScript = pythonScript;
-    }
+  public void setPythonScript(String pythonScript) {
+    this.pythonScript = pythonScript;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceManager.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceManager.java
index 62e389e..b0f9ffa 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceManager.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceManager.java
@@ -24,11 +24,18 @@ import org.apache.ambari.view.pig.resources.udf.models.UDF;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Object that provides CRUD operations for script objects
+ */
 public class UDFResourceManager extends PersonalCRUDResourceManager<UDF> {
-    private final static Logger LOG =
-            LoggerFactory.getLogger(UDFResourceManager.class);
+  private final static Logger LOG =
+      LoggerFactory.getLogger(UDFResourceManager.class);
 
-    public UDFResourceManager(ViewContext context) {
-        super(UDF.class, context);
-    }
+  /**
+   * Constructor
+   * @param context View Context instance
+   */
+  public UDFResourceManager(ViewContext context) {
+    super(UDF.class, context);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceProvider.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceProvider.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceProvider.java
index 3069ddd..c9a8c7b 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceProvider.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFResourceProvider.java
@@ -32,74 +32,77 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+/**
+ * Resource provider for UDFs
+ */
 public class UDFResourceProvider implements ResourceProvider<UDF> {
-    @Inject
-    ViewContext context;
+  @Inject
+  ViewContext context;
 
-    protected UDFResourceManager resourceManager = null;
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(UDFResourceProvider.class);
+  protected UDFResourceManager resourceManager = null;
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(UDFResourceProvider.class);
 
-    protected synchronized PersonalCRUDResourceManager<UDF> getResourceManager() {
-        if (resourceManager == null) {
-            resourceManager = new UDFResourceManager(context);
-        }
-        return resourceManager;
+  protected synchronized PersonalCRUDResourceManager<UDF> getResourceManager() {
+    if (resourceManager == null) {
+      resourceManager = new UDFResourceManager(context);
     }
+    return resourceManager;
+  }
 
-    @Override
-    public UDF getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        try {
-            return getResourceManager().read(resourceId);
-        } catch (ItemNotFound itemNotFound) {
-            throw new NoSuchResourceException(resourceId);
-        }
+  @Override
+  public UDF getResource(String resourceId, Set<String> properties) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    try {
+      return getResourceManager().read(resourceId);
+    } catch (ItemNotFound itemNotFound) {
+      throw new NoSuchResourceException(resourceId);
     }
+  }
 
-    @Override
-    public Set<UDF> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        return new HashSet<UDF>(getResourceManager().readAll(
-                new OnlyOwnersFilteringStrategy(this.context.getUsername())));
-    }
+  @Override
+  public Set<UDF> getResources(ReadRequest readRequest) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    return new HashSet<UDF>(getResourceManager().readAll(
+        new OnlyOwnersFilteringStrategy(this.context.getUsername())));
+  }
 
-    @Override
-    public void createResource(String s, Map<String, Object> stringObjectMap) throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException {
-        UDF udf = null;
-        try {
-            udf = new UDF(stringObjectMap);
-        } catch (InvocationTargetException e) {
-            throw new SystemException("error on creating resource", e);
-        } catch (IllegalAccessException e) {
-            throw new SystemException("error on creating resource", e);
-        }
-        getResourceManager().create(udf);
+  @Override
+  public void createResource(String s, Map<String, Object> stringObjectMap) throws SystemException, ResourceAlreadyExistsException, NoSuchResourceException, UnsupportedPropertyException {
+    UDF udf = null;
+    try {
+      udf = new UDF(stringObjectMap);
+    } catch (InvocationTargetException e) {
+      throw new SystemException("error on creating resource", e);
+    } catch (IllegalAccessException e) {
+      throw new SystemException("error on creating resource", e);
     }
+    getResourceManager().create(udf);
+  }
 
-    @Override
-    public boolean updateResource(String resourceId, Map<String, Object> stringObjectMap) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        UDF udf = null;
-        try {
-            udf = new UDF(stringObjectMap);
-        } catch (InvocationTargetException e) {
-            throw new SystemException("error on updating resource", e);
-        } catch (IllegalAccessException e) {
-            throw new SystemException("error on updating resource", e);
-        }
-        try {
-            getResourceManager().update(udf, resourceId);
-        } catch (ItemNotFound itemNotFound) {
-            throw new NoSuchResourceException(resourceId);
-        }
-        return true;
+  @Override
+  public boolean updateResource(String resourceId, Map<String, Object> stringObjectMap) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    UDF udf = null;
+    try {
+      udf = new UDF(stringObjectMap);
+    } catch (InvocationTargetException e) {
+      throw new SystemException("error on updating resource", e);
+    } catch (IllegalAccessException e) {
+      throw new SystemException("error on updating resource", e);
+    }
+    try {
+      getResourceManager().update(udf, resourceId);
+    } catch (ItemNotFound itemNotFound) {
+      throw new NoSuchResourceException(resourceId);
     }
+    return true;
+  }
 
-    @Override
-    public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
-        try {
-            getResourceManager().delete(resourceId);
-        } catch (ItemNotFound itemNotFound) {
-            throw new NoSuchResourceException(resourceId);
-        }
-        return true;
+  @Override
+  public boolean deleteResource(String resourceId) throws SystemException, NoSuchResourceException, UnsupportedPropertyException {
+    try {
+      getResourceManager().delete(resourceId);
+    } catch (ItemNotFound itemNotFound) {
+      throw new NoSuchResourceException(resourceId);
     }
+    return true;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFService.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFService.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFService.java
index d8b24bc..7ea8f03 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFService.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/UDFService.java
@@ -48,109 +48,112 @@ import java.util.List;
  *      Required: path, name
  */
 public class UDFService extends BaseService {
-    @Inject
-    ViewResourceHandler handler;
-
-    protected UDFResourceManager resourceManager = null;
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(UDFService.class);
-
-    protected synchronized PersonalCRUDResourceManager<UDF> getResourceManager() {
-        if (resourceManager == null) {
-            resourceManager = new UDFResourceManager(context);
-        }
-        return resourceManager;
-    }
+  @Inject
+  ViewResourceHandler handler;
 
-    /**
-     * Get single item
-     */
-    @GET
-    @Path("{udfId}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response getUDF(@PathParam("udfId") String udfId) {
-        UDF udf = null;
-        try {
-            udf = getResourceManager().read(udfId);
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-        JSONObject object = new JSONObject();
-        object.put("udf", udf);
-        return Response.ok(object).build();
-    }
+  protected UDFResourceManager resourceManager = null;
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(UDFService.class);
 
-    /**
-     * Delete single item
-     */
-    @DELETE
-    @Path("{udfId}")
-    public Response deleteUDF(@PathParam("udfId") String udfId) {
-        try {
-            getResourceManager().delete(udfId);
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-        return Response.status(204).build();
+  protected synchronized PersonalCRUDResourceManager<UDF> getResourceManager() {
+    if (resourceManager == null) {
+      resourceManager = new UDFResourceManager(context);
     }
-
-    /**
-     * Get all UDFs
-     */
-    @GET
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response getUDFList(@Context UriInfo ui) {
-        LOG.debug("Getting all UDFs");
-        List allUDFs = getResourceManager().readAll(
-                new OnlyOwnersFilteringStrategy(this.context.getUsername()));
-
-        JSONObject object = new JSONObject();
-        object.put("udfs", allUDFs);
-        return Response.ok(object).build();
+    return resourceManager;
+  }
+
+  /**
+   * Get single item
+   */
+  @GET
+  @Path("{udfId}")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response getUDF(@PathParam("udfId") String udfId) {
+    UDF udf = null;
+    try {
+      udf = getResourceManager().read(udfId);
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
-
-    /**
-     * Update item
-     */
-    @PUT
-    @Path("{udfId}")
-    @Consumes(MediaType.APPLICATION_JSON)
-    public Response updateUDF(UDFRequest request,
-                                 @PathParam("udfId") String udfId) {
-        try {
-            getResourceManager().update(request.udf, udfId);
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-        return Response.status(204).build();
+    JSONObject object = new JSONObject();
+    object.put("udf", udf);
+    return Response.ok(object).build();
+  }
+
+  /**
+   * Delete single item
+   */
+  @DELETE
+  @Path("{udfId}")
+  public Response deleteUDF(@PathParam("udfId") String udfId) {
+    try {
+      getResourceManager().delete(udfId);
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
-
-    /**
-     * Create UDF
-     */
-    @POST
-    @Consumes(MediaType.APPLICATION_JSON)
-    public Response createUDF(UDFRequest request, @Context HttpServletResponse response,
-                               @Context UriInfo ui) {
-        getResourceManager().create(request.udf);
-
-        UDF udf = null;
-
-        try {
-            udf = getResourceManager().read(request.udf.getId());
-        } catch (ItemNotFound itemNotFound) {
-            return Response.status(404).build();
-        }
-
-        response.setHeader("Location",
-                String.format("%s/%s", ui.getAbsolutePath().toString(), request.udf.getId()));
-
-        JSONObject object = new JSONObject();
-        object.put("udf", udf);
-        return Response.ok(object).status(201).build();
+    return Response.status(204).build();
+  }
+
+  /**
+   * Get all UDFs
+   */
+  @GET
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response getUDFList(@Context UriInfo ui) {
+    LOG.debug("Getting all UDFs");
+    List allUDFs = getResourceManager().readAll(
+        new OnlyOwnersFilteringStrategy(this.context.getUsername()));
+
+    JSONObject object = new JSONObject();
+    object.put("udfs", allUDFs);
+    return Response.ok(object).build();
+  }
+
+  /**
+   * Update item
+   */
+  @PUT
+  @Path("{udfId}")
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response updateUDF(UDFRequest request,
+                            @PathParam("udfId") String udfId) {
+    try {
+      getResourceManager().update(request.udf, udfId);
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
-
-    public static class UDFRequest {
-        public UDF udf;
+    return Response.status(204).build();
+  }
+
+  /**
+   * Create UDF
+   */
+  @POST
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response createUDF(UDFRequest request, @Context HttpServletResponse response,
+                            @Context UriInfo ui) {
+    getResourceManager().create(request.udf);
+
+    UDF udf = null;
+
+    try {
+      udf = getResourceManager().read(request.udf.getId());
+    } catch (ItemNotFound itemNotFound) {
+      return Response.status(404).build();
     }
+
+    response.setHeader("Location",
+        String.format("%s/%s", ui.getAbsolutePath().toString(), request.udf.getId()));
+
+    JSONObject object = new JSONObject();
+    object.put("udf", udf);
+    return Response.ok(object).status(201).build();
+  }
+
+  /**
+   * Wrapper object for json mapping
+   */
+  public static class UDFRequest {
+    public UDF udf;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/models/UDF.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/models/UDF.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/models/UDF.java
index 0a18329..adbabcb 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/models/UDF.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/udf/models/UDF.java
@@ -29,51 +29,51 @@ import java.util.Map;
  * Bean to represent User Defined Functions
  */
 public class UDF implements Serializable, PersonalResource {
-    String id;
-    String path;
-    String name;
-    String owner;
+  private String id;
+  private String path;
+  private String name;
+  private String owner;
 
-    public UDF() {
-    }
+  public UDF() {
+  }
 
-    public UDF(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException {
-        BeanUtils.populate(this, stringObjectMap);
-    }
+  public UDF(Map<String, Object> stringObjectMap) throws InvocationTargetException, IllegalAccessException {
+    BeanUtils.populate(this, stringObjectMap);
+  }
 
-    @Override
-    public String getId() {
-        return id;
-    }
+  @Override
+  public String getId() {
+    return id;
+  }
 
-    @Override
-    public void setId(String id) {
-        this.id = id;
-    }
+  @Override
+  public void setId(String id) {
+    this.id = id;
+  }
 
-    @Override
-    public String getOwner() {
-        return owner;
-    }
+  @Override
+  public String getOwner() {
+    return owner;
+  }
 
-    @Override
-    public void setOwner(String owner) {
-        this.owner = owner;
-    }
+  @Override
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
 
-    public String getPath() {
-        return path;
-    }
+  public String getPath() {
+    return path;
+  }
 
-    public void setPath(String path) {
-        this.path = path;
-    }
+  public void setPath(String path) {
+    this.path = path;
+  }
 
-    public String getName() {
-        return name;
-    }
+  public String getName() {
+    return name;
+  }
 
-    public void setName(String name) {
-        this.name = name;
-    }
+  public void setName(String name) {
+    this.name = name;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/BaseService.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/BaseService.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/BaseService.java
index b37c518..06e00c2 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/BaseService.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/BaseService.java
@@ -35,83 +35,95 @@ import java.io.IOException;
 import java.util.HashMap;
 
 
+/**
+ * Parent service
+ */
 public class BaseService {
-    @Inject
-    protected ViewContext context;
-
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(BaseService.class);
-
-    private Storage storage;
+  @Inject
+  protected ViewContext context;
 
-    public Storage getStorage() {
-        if (this.storage == null) {
-            storage = StorageUtil.getStorage(context);
-        }
-        return storage;
-    }
-
-    public void setStorage(Storage storage) {
-        this.storage = storage;
-    }
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(BaseService.class);
 
-    private static HdfsApi hdfsApi = null;
-
-    public static HdfsApi getHdfsApi(ViewContext context) {
-        if (hdfsApi == null) {
-            Thread.currentThread().setContextClassLoader(null);
-
-            String userName = context.getUsername();
-
-            String defaultFS = context.getProperties().get("dataworker.defaultFs");
-            if (defaultFS == null) {
-                String message = "dataworker.defaultFs is not configured!";
-                LOG.error(message);
-                throw new WebServiceException(message);
-            }
-
-            try {
-                hdfsApi = new HdfsApi(defaultFS, userName);
-                LOG.info("HdfsApi connected OK");
-            } catch (IOException e) {
-                String message = "HdfsApi IO error: " + e.getMessage();
-                LOG.error(message);
-                throw new WebServiceException(message, e);
-            } catch (InterruptedException e) {
-                String message = "HdfsApi Interrupted error: " + e.getMessage();
-                LOG.error(message);
-                throw new WebServiceException(message, e);
-            }
-        }
-        return hdfsApi;
-    }
+  private Storage storage;
 
-    public HdfsApi getHdfsApi()  {
-        return getHdfsApi(context);
+  protected Storage getStorage() {
+    if (this.storage == null) {
+      storage = StorageUtil.getStorage(context);
     }
-
-    public static HdfsApi setHdfsApi(HdfsApi api)  {
-        return hdfsApi = api;
-    }
-
-    public static Response badRequestResponse(String message) {
-        HashMap<String, Object> response = new HashMap<String, Object>();
-        response.put("message", message);
-        response.put("status", 400);
-        return Response.status(400).entity(new JSONObject(response)).type(MediaType.APPLICATION_JSON).build();
-    }
-
-    public static Response serverErrorResponse(String message) {
-        HashMap<String, Object> response = new HashMap<String, Object>();
-        response.put("message", message);
-        response.put("status", 500);
-        return Response.status(500).entity(new JSONObject(response)).type(MediaType.APPLICATION_JSON).build();
-    }
-
-    public static Response notFoundResponse(String message) {
-        HashMap<String, Object> response = new HashMap<String, Object>();
-        response.put("message", message);
-        response.put("status", 404);
-        return Response.status(404).entity(new JSONObject(response)).type(MediaType.APPLICATION_JSON).build();
+    return storage;
+  }
+
+  protected void setStorage(Storage storage) {
+    this.storage = storage;
+  }
+
+  private static HdfsApi hdfsApi = null;
+
+  /**
+   * Returns HdfsApi object
+   * @param context View Context instance
+   * @return Hdfs business delegate object
+   */
+  public static HdfsApi getHdfsApi(ViewContext context) {
+    if (hdfsApi == null) {
+      Thread.currentThread().setContextClassLoader(null);
+
+      String userName = context.getUsername();
+
+      String defaultFS = context.getProperties().get("dataworker.defaultFs");
+      if (defaultFS == null) {
+        String message = "dataworker.defaultFs is not configured!";
+        LOG.error(message);
+        throw new WebServiceException(message);
+      }
+
+      try {
+        hdfsApi = new HdfsApi(defaultFS, userName);
+        LOG.info("HdfsApi connected OK");
+      } catch (IOException e) {
+        String message = "HdfsApi IO error: " + e.getMessage();
+        LOG.error(message);
+        throw new WebServiceException(message, e);
+      } catch (InterruptedException e) {
+        String message = "HdfsApi Interrupted error: " + e.getMessage();
+        LOG.error(message);
+        throw new WebServiceException(message, e);
+      }
     }
+    return hdfsApi;
+  }
+
+  protected HdfsApi getHdfsApi()  {
+    return getHdfsApi(context);
+  }
+
+  /**
+   * Set HdfsApi delegate
+   * @param api HdfsApi instance
+   */
+  public static void setHdfsApi(HdfsApi api)  {
+    hdfsApi = api;
+  }
+
+  protected static Response badRequestResponse(String message) {
+    HashMap<String, Object> response = new HashMap<String, Object>();
+    response.put("message", message);
+    response.put("status", 400);
+    return Response.status(400).entity(new JSONObject(response)).type(MediaType.APPLICATION_JSON).build();
+  }
+
+  protected static Response serverErrorResponse(String message) {
+    HashMap<String, Object> response = new HashMap<String, Object>();
+    response.put("message", message);
+    response.put("status", 500);
+    return Response.status(500).entity(new JSONObject(response)).type(MediaType.APPLICATION_JSON).build();
+  }
+
+  protected static Response notFoundResponse(String message) {
+    HashMap<String, Object> response = new HashMap<String, Object>();
+    response.put("message", message);
+    response.put("status", 404);
+    return Response.status(404).entity(new JSONObject(response)).type(MediaType.APPLICATION_JSON).build();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/HelpService.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/HelpService.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/HelpService.java
index c5f1721..61662b8 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/HelpService.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/services/HelpService.java
@@ -27,30 +27,46 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.*;
 
+/**
+ * Help service
+ */
 public class HelpService extends BaseService {
-    private ViewContext context;
-    private ViewResourceHandler handler;
+  private ViewContext context;
+  private ViewResourceHandler handler;
 
-    public HelpService(ViewContext context, ViewResourceHandler handler) {
-        super();
-        this.context = context;
-        this.handler = handler;
-    }
+  /**
+   * Constructor
+   * @param context View Context instance
+   * @param handler View Resource Handler instance
+   */
+  public HelpService(ViewContext context, ViewResourceHandler handler) {
+    super();
+    this.context = context;
+    this.handler = handler;
+  }
 
-    @GET
-    @Path("/config")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response config(){
-        JSONObject object = new JSONObject();
-        String fs = context.getProperties().get("dataworker.defaultFs");
-        object.put("dataworker.defaultFs", fs);
-        return Response.ok(object).build();
-    }
+  /**
+   * View configuration
+   * @return configuration of HDFS
+   */
+  @GET
+  @Path("/config")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response config(){
+    JSONObject object = new JSONObject();
+    String fs = context.getProperties().get("dataworker.defaultFs");
+    object.put("dataworker.defaultFs", fs);
+    return Response.ok(object).build();
+  }
 
-    @GET
-    @Path("/version")
-    @Produces(MediaType.TEXT_PLAIN)
-    public Response version(){
-        return Response.ok("0.0.1-SNAPSHOT").build();
-    }
+  /**
+   * Version
+   * @return version
+   */
+  @GET
+  @Path("/version")
+  @Produces(MediaType.TEXT_PLAIN)
+  public Response version(){
+    return Response.ok("0.0.1-SNAPSHOT").build();
+  }
 }


[2/4] AMBARI-5704. Pig View Cleanup. (mahadev)

Posted by ma...@apache.org.
http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/Request.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/Request.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/Request.java
index de9142f..a23f008 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/Request.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/Request.java
@@ -19,21 +19,16 @@
 package org.apache.ambari.view.pig.templeton.client;
 
 import com.google.gson.Gson;
-import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.WebResource;
 import com.sun.jersey.core.util.MultivaluedMapImpl;
-import org.apache.ambari.view.URLStreamProvider;
 import org.apache.ambari.view.ViewContext;
 import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriBuilder;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.StringWriter;
-import java.net.URI;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -42,172 +37,207 @@ import java.util.Map;
  * @param <RESPONSE> data type to deserialize response from JSON
  */
 public class Request<RESPONSE> {
-    protected final Class<RESPONSE> responseClass;
-    protected final ViewContext context;
-    protected final WebResource resource;
-
-    protected final Gson gson = new Gson();
-
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(Request.class);
-
-    public Request(WebResource resource, Class<RESPONSE> responseClass, ViewContext context) {
-        this.resource = resource;
-        this.responseClass = responseClass;
-        this.context = context;
-    }
-
-    /**
-     * Main implementation of GET request
-     * @param resource resource
-     * @return unmarshalled response data
-     */
-    public RESPONSE get(WebResource resource) throws IOException {
-        LOG.debug("GET " + resource.toString());
-
-        InputStream inputStream = context.getURLStreamProvider().readFrom(resource.toString(), "GET",
-                null, new HashMap<String, String>());
-
-        String responseJson = IOUtils.toString(inputStream);
-        LOG.debug(String.format("RESPONSE => %s", responseJson));
-        return gson.fromJson(responseJson, responseClass);
-    }
-
-    public RESPONSE get() throws IOException {
-        return get(this.resource);
-    }
-
-    public RESPONSE get(MultivaluedMapImpl params) throws IOException {
-        return get(this.resource.queryParams(params));
-    }
-
-    /**
-     * Main implementation of POST request
-     * @param resource resource
-     * @param data post body
-     * @return unmarshalled response data
-     */
-    public RESPONSE post(WebResource resource, MultivaluedMapImpl data) throws IOException {
-        LOG.debug("POST " + resource.toString());
-        LOG.debug("data: " + data.toString());
-
-        UriBuilder builder = UriBuilder.fromPath("host/");
-        for(String key : data.keySet()) {
-            for(String value : data.get(key))
-                builder.queryParam(key, value);
-        }
-
-        if (data != null)
-            LOG.debug("... data: " + builder.build().getRawQuery());
-
-        Map<String, String> headers = new HashMap<String, String>();
-        headers.put("Content-Type", "application/x-www-form-urlencoded");
-
-        InputStream inputStream = context.getURLStreamProvider().readFrom(resource.toString(),
-                "POST", builder.build().getRawQuery(), headers);
-        String responseJson = IOUtils.toString(inputStream);
-
-        LOG.debug(String.format("RESPONSE => %s", responseJson));
-        return gson.fromJson(responseJson, responseClass);
-    }
-
-    public RESPONSE post(MultivaluedMapImpl data) throws IOException {
-        return post(resource, data);
-    }
-
-    public RESPONSE post() throws IOException {
-        return post(resource, new MultivaluedMapImpl());
-    }
-
-    public RESPONSE post(MultivaluedMapImpl params, MultivaluedMapImpl data) throws IOException {
-        return post(resource.queryParams(params), data);
-    }
-
-    public static void main(String[] args) {
-        UriBuilder builder = UriBuilder.fromPath("host/");
-        builder.queryParam("aa", "/tmp/.pigjobs/hue/test111_17-03-2014-16-50-37");
-        System.out.println(builder.build().getRawQuery());
-    }
-
-    /**
-     * Main implementation of PUT request
-     * @param resource resource
-     * @param data put body
-     * @return unmarshalled response data
-     */
-    public RESPONSE put(WebResource resource, MultivaluedMapImpl data) throws IOException {
-        LOG.debug("PUT " + resource.toString());
-
-        UriBuilder builder = UriBuilder.fromPath("host/");
-        for(String key : data.keySet()) {
-            for(String value : data.get(key))
-                builder.queryParam(key, value);
-        }
-
-        if (data != null)
-            LOG.debug("... data: " + builder.build().getRawQuery());
-
-        Map<String, String> headers = new HashMap<String, String>();
-        headers.put("Content-Type", "application/x-www-form-urlencoded");
-
-        InputStream inputStream = context.getURLStreamProvider().readFrom(resource.toString(),
-                "PUT", builder.build().getRawQuery(), headers);
-        String responseJson = IOUtils.toString(inputStream);
-
-        LOG.debug(String.format("RESPONSE => %s", responseJson));
-        return gson.fromJson(responseJson, responseClass);
-    }
-
-    public RESPONSE put(MultivaluedMapImpl data) throws IOException {
-        return put(resource, data);
-    }
-
-    public RESPONSE put() throws IOException {
-        return put(resource, new MultivaluedMapImpl());
-    }
-
-    public RESPONSE put(MultivaluedMapImpl params, MultivaluedMapImpl data) throws IOException {
-        return put(resource.queryParams(params), data);
-    }
-
-    /**
-     * Main implementation of DELETE request
-     * @param resource resource
-     * @param data delete body
-     * @return unmarshalled response data
-     */
-    public RESPONSE delete(WebResource resource, MultivaluedMapImpl data) throws IOException {
-        LOG.debug("DELETE " + resource.toString());
-
-        UriBuilder builder = UriBuilder.fromPath("host/");
-        for(String key : data.keySet()) {
-            for(String value : data.get(key))
-                builder.queryParam(key, value);
-        }
-
-        if (data != null)
-            LOG.debug("... data: " + builder.build().getRawQuery());
-
-        Map<String, String> headers = new HashMap<String, String>();
-        headers.put("Content-Type", "application/x-www-form-urlencoded");
-
-        InputStream inputStream = context.getURLStreamProvider().readFrom(resource.toString(),
-                "DELETE", builder.build().getRawQuery(), headers);
-        String responseJson = IOUtils.toString(inputStream);
-
-        LOG.debug(String.format("RESPONSE => %s", responseJson));
-        return gson.fromJson(responseJson, responseClass);
-    }
-
-    public RESPONSE delete(MultivaluedMapImpl data) throws IOException {
-        return delete(resource, data);
-    }
-
-    public RESPONSE delete() throws IOException {
-        return delete(resource, new MultivaluedMapImpl());
-    }
-
-    public RESPONSE delete(MultivaluedMapImpl params, MultivaluedMapImpl data) throws IOException {
-        return delete(resource.queryParams(params), data);
-    }
+  protected final Class<RESPONSE> responseClass;
+  protected final ViewContext context;
+  protected final WebResource resource;
+
+  protected final Gson gson = new Gson();
+
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(Request.class);
+
+  /**
+   * Constructor
+   * @param resource object that represents resource
+   * @param responseClass model class
+   * @param context View Context instance
+   */
+  public Request(WebResource resource, Class<RESPONSE> responseClass, ViewContext context) {
+    this.resource = resource;
+    this.responseClass = responseClass;
+    this.context = context;
+  }
+
+  /**
+   * Main implementation of GET request
+   * @param resource resource
+   * @return unmarshalled response data
+   */
+  public RESPONSE get(WebResource resource) throws IOException {
+    LOG.debug("GET " + resource.toString());
+
+    InputStream inputStream = context.getURLStreamProvider().readFrom(resource.toString(), "GET",
+        null, new HashMap<String, String>());
+
+    String responseJson = IOUtils.toString(inputStream);
+    LOG.debug(String.format("RESPONSE => %s", responseJson));
+    return gson.fromJson(responseJson, responseClass);
+  }
+
+  /**
+   * Make GET request
+   * @see #get(WebResource)
+   */
+  public RESPONSE get() throws IOException {
+    return get(this.resource);
+  }
+
+  /**
+   * Make GET request
+   * @see #get(WebResource)
+   */
+  public RESPONSE get(MultivaluedMapImpl params) throws IOException {
+    return get(this.resource.queryParams(params));
+  }
+
+  /**
+   * Main implementation of POST request
+   * @param resource resource
+   * @param data post body
+   * @return unmarshalled response data
+   */
+  public RESPONSE post(WebResource resource, MultivaluedMapImpl data) throws IOException {
+    LOG.debug("POST " + resource.toString());
+    LOG.debug("data: " + data.toString());
+
+    UriBuilder builder = UriBuilder.fromPath("host/");
+    for(String key : data.keySet()) {
+      for(String value : data.get(key))
+        builder.queryParam(key, value);
+    }
+
+    if (data != null)
+      LOG.debug("... data: " + builder.build().getRawQuery());
+
+    Map<String, String> headers = new HashMap<String, String>();
+    headers.put("Content-Type", "application/x-www-form-urlencoded");
+
+    InputStream inputStream = context.getURLStreamProvider().readFrom(resource.toString(),
+        "POST", builder.build().getRawQuery(), headers);
+    String responseJson = IOUtils.toString(inputStream);
+
+    LOG.debug(String.format("RESPONSE => %s", responseJson));
+    return gson.fromJson(responseJson, responseClass);
+  }
+
+  /**
+   * @see #post(WebResource, MultivaluedMapImpl)
+   */
+  public RESPONSE post(MultivaluedMapImpl data) throws IOException {
+    return post(resource, data);
+  }
+
+  /**
+   * @see #post(WebResource, MultivaluedMapImpl)
+   */
+  public RESPONSE post() throws IOException {
+    return post(resource, new MultivaluedMapImpl());
+  }
+
+  /**
+   * @see #post(WebResource, MultivaluedMapImpl)
+   */
+  public RESPONSE post(MultivaluedMapImpl params, MultivaluedMapImpl data) throws IOException {
+    return post(resource.queryParams(params), data);
+  }
+
+  /**
+   * Main implementation of PUT request
+   * @param resource resource
+   * @param data put body
+   * @return unmarshalled response data
+   */
+  public RESPONSE put(WebResource resource, MultivaluedMapImpl data) throws IOException {
+    LOG.debug("PUT " + resource.toString());
+
+    UriBuilder builder = UriBuilder.fromPath("host/");
+    for(String key : data.keySet()) {
+      for(String value : data.get(key))
+        builder.queryParam(key, value);
+    }
+
+    if (data != null)
+      LOG.debug("... data: " + builder.build().getRawQuery());
+
+    Map<String, String> headers = new HashMap<String, String>();
+    headers.put("Content-Type", "application/x-www-form-urlencoded");
+
+    InputStream inputStream = context.getURLStreamProvider().readFrom(resource.toString(),
+        "PUT", builder.build().getRawQuery(), headers);
+    String responseJson = IOUtils.toString(inputStream);
+
+    LOG.debug(String.format("RESPONSE => %s", responseJson));
+    return gson.fromJson(responseJson, responseClass);
+  }
+
+  /**
+   * @see #put(WebResource, MultivaluedMapImpl)
+   */
+  public RESPONSE put(MultivaluedMapImpl data) throws IOException {
+    return put(resource, data);
+  }
+
+  /**
+   * @see #put(WebResource, MultivaluedMapImpl)
+   */
+  public RESPONSE put() throws IOException {
+    return put(resource, new MultivaluedMapImpl());
+  }
+
+  /**
+   * @see #put(WebResource, MultivaluedMapImpl)
+   */
+  public RESPONSE put(MultivaluedMapImpl params, MultivaluedMapImpl data) throws IOException {
+    return put(resource.queryParams(params), data);
+  }
+
+  /**
+   * Main implementation of DELETE request
+   * @param resource resource
+   * @param data delete body
+   * @return unmarshalled response data
+   */
+  public RESPONSE delete(WebResource resource, MultivaluedMapImpl data) throws IOException {
+    LOG.debug("DELETE " + resource.toString());
+
+    UriBuilder builder = UriBuilder.fromPath("host/");
+    for(String key : data.keySet()) {
+      for(String value : data.get(key))
+        builder.queryParam(key, value);
+    }
+
+    if (data != null)
+      LOG.debug("... data: " + builder.build().getRawQuery());
+
+    Map<String, String> headers = new HashMap<String, String>();
+    headers.put("Content-Type", "application/x-www-form-urlencoded");
+
+    InputStream inputStream = context.getURLStreamProvider().readFrom(resource.toString(),
+        "DELETE", builder.build().getRawQuery(), headers);
+    String responseJson = IOUtils.toString(inputStream);
+
+    LOG.debug(String.format("RESPONSE => %s", responseJson));
+    return gson.fromJson(responseJson, responseClass);
+  }
+
+  /**
+   * @see #delete(WebResource, MultivaluedMapImpl)
+   */
+  public RESPONSE delete(MultivaluedMapImpl data) throws IOException {
+    return delete(resource, data);
+  }
+
+  /**
+   * @see #delete(WebResource, MultivaluedMapImpl)
+   */
+  public RESPONSE delete() throws IOException {
+    return delete(resource, new MultivaluedMapImpl());
+  }
+
+  /**
+   * @see #delete(WebResource, MultivaluedMapImpl)
+   */
+  public RESPONSE delete(MultivaluedMapImpl params, MultivaluedMapImpl data) throws IOException {
+    return delete(resource.queryParams(params), data);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonApi.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonApi.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonApi.java
index 9675a1e..4fe61cd 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonApi.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonApi.java
@@ -40,125 +40,163 @@ import java.util.Map;
  * Templeton Business Delegate
  */
 public class TempletonApi {
-    private final Gson gson = new Gson();
-
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(TempletonApi.class);
-
-    protected WebResource service;
-    private String username;
-    private String doAs;
-    private ViewContext context;
-
-    /**
-     * TempletonApi constructor
-     * @param api dataworker.templeton_url
-     * @param username templeton username
-     * @param doAs doAs argument
-     * @param context context with URLStreamProvider
-     */
-    public TempletonApi(String api, String username, String doAs, ViewContext context) {
-        this.username = username;
-        this.doAs = doAs;
-        this.context = context;
-        ClientConfig config = new DefaultClientConfig();
-        config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
-        Client client = Client.create(config);
-        this.service = client.resource(api);
+  private final Gson gson = new Gson();
+
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(TempletonApi.class);
+
+  protected WebResource service;
+  private String username;
+  private String doAs;
+  private ViewContext context;
+
+  /**
+   * TempletonApi constructor
+   * @param api dataworker.templeton_url
+   * @param username templeton username
+   * @param doAs doAs argument
+   * @param context context with URLStreamProvider
+   */
+  public TempletonApi(String api, String username, String doAs, ViewContext context) {
+    this.username = username;
+    this.doAs = doAs;
+    this.context = context;
+    ClientConfig config = new DefaultClientConfig();
+    config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
+    Client client = Client.create(config);
+    this.service = client.resource(api);
+  }
+
+  /**
+   * @see #TempletonApi(String,String,String,ViewContext)
+   */
+  public TempletonApi(String api, String username, ViewContext context) {
+    this(api, username, username, context);
+  }
+
+  /**
+   * Create and queue a Pig job.
+   * @param execute String containing an entire, short pig program to run. (e.g. pwd)
+   * @param pigFile HDFS file name of a pig program to run. (One of either "execute" or "file" is required )
+   * @param statusDir A directory where Templeton will write the status of the Pig job. If
+   *                  provided, it is the caller's responsibility to remove this directory when done.
+   * @param arg Set a program argument. Optional None
+   * @return id A string containing the job ID similar to "job_201110132141_0001".
+   *         info A JSON object containing the information returned when the job was queued.
+   */
+  public JobData runPigQuery(String execute, File pigFile, String statusDir, String arg) throws IOException {
+    MultivaluedMapImpl data = new MultivaluedMapImpl();
+    if (execute != null)
+      data.add("execute", execute);
+    if (pigFile != null)
+      data.add("file", pigFile.toString());
+    if (statusDir != null)
+      data.add("statusdir", statusDir);
+    if (arg != null && !arg.isEmpty()) {
+      for(String arg1 : arg.split("\t")) {
+        data.add("arg", arg1);
+      }
     }
 
-    public TempletonApi(String api, String username, ViewContext context) {
-        this(api, username, username, context);
-    }
-
-    /**
-     * Create and queue a Pig job.
-     * @param execute String containing an entire, short pig program to run. (e.g. pwd)
-     * @param pigFile HDFS file name of a pig program to run. (One of either "execute" or "file" is required )
-     * @param statusDir A directory where Templeton will write the status of the Pig job. If
-     *                  provided, it is the caller's responsibility to remove this directory when done.
-     * @param arg Set a program argument. Optional None
-     * @return id A string containing the job ID similar to "job_201110132141_0001".
-     *         info A JSON object containing the information returned when the job was queued.
-     */
-    public JobData runPigQuery(String execute, File pigFile, String statusDir, String arg) throws IOException {
-        MultivaluedMapImpl data = new MultivaluedMapImpl();
-        if (execute != null)
-            data.add("execute", execute);
-        if (pigFile != null)
-            data.add("file", pigFile.toString());
-        if (statusDir != null)
-            data.add("statusdir", statusDir);
-        if (arg != null && !arg.isEmpty()) {
-            for(String arg1 : arg.split("\t")) {
-                data.add("arg", arg1);
-            }
-        }
-
-        TempletonRequest<JobData> request =
-                new TempletonRequest<JobData>(service.path("pig"), JobData.class, username, doAs, context);
-
-        return request.post(data);
-    }
-
-    public JobData runPigQuery(File pigFile, String statusDir, String arg) throws IOException {
-        return runPigQuery(null, pigFile, statusDir, arg);
-    }
-
-    public JobData runPigQuery(String execute, String statusDir, String arg) throws IOException {
-        return runPigQuery(execute, null, statusDir, arg);
-    }
-
-    public JobData runPigQuery(String execute) throws IOException {
-        return runPigQuery(execute, null, null, null);
-    }
-
-    public JobInfo checkJob(String jobId) throws IOException {
-        TempletonRequest<JobInfo> request =
-                new TempletonRequest<JobInfo>(service.path("jobs").path(jobId), JobInfo.class, username, context);
-
-        return request.get();
-    }
-
-    public void killJob(String jobId) throws IOException {
-        TempletonRequest<JobInfo> request =
-                new TempletonRequest<JobInfo>(service.path("jobs").path(jobId), JobInfo.class, username, context);
-
-        try {
-             request.delete();
-        } catch (IOException e) {
-            //TODO: remove this after HIVE-5835 resolved
-            LOG.debug("Ignoring 500 response from webhcat (see HIVE-5835)");
-        }
-    }
-
-    public Status status() throws IOException {
-        TempletonRequest<Status> request =
-                new TempletonRequest<Status>(service.path("status"), Status.class,
-                username, doAs, context);
-        return request.get();
-    }
-
-    public class Status {
-        public String status;
-        public String version;
-    }
-
-    public class JobData {
-        public String id;
-    }
-
-    public class JobInfo {
-        public Map<String, Object> status;
-        public Map<String, Object> profile;
-        public Map<String, Object> userargs;
-
-        public String id;
-        public String parentId;
-        public String percentComplete;
-        public Integer exitValue;
-        public String user;
-        public String callback;
-        public String completed;
+    TempletonRequest<JobData> request =
+        new TempletonRequest<JobData>(service.path("pig"), JobData.class, username, doAs, context);
+
+    return request.post(data);
+  }
+
+  /**
+   * @see #runPigQuery(String, java.io.File, String, String)
+   */
+  public JobData runPigQuery(File pigFile, String statusDir, String arg) throws IOException {
+    return runPigQuery(null, pigFile, statusDir, arg);
+  }
+
+  /**
+   * @see #runPigQuery(String, java.io.File, String, String)
+   */
+  public JobData runPigQuery(String execute, String statusDir, String arg) throws IOException {
+    return runPigQuery(execute, null, statusDir, arg);
+  }
+
+  /**
+   * @see #runPigQuery(String, java.io.File, String, String)
+   */
+  public JobData runPigQuery(String execute) throws IOException {
+    return runPigQuery(execute, null, null, null);
+  }
+
+  /**
+   * Get Job information
+   * @param jobId templeton job identifier
+   * @return JobInfo object
+   * @throws IOException
+   */
+  public JobInfo checkJob(String jobId) throws IOException {
+    TempletonRequest<JobInfo> request =
+        new TempletonRequest<JobInfo>(service.path("jobs").path(jobId), JobInfo.class, username, context);
+
+    return request.get();
+  }
+
+  /**
+   * Kill templeton job
+   * @param jobId templeton job identifier
+   * @throws IOException
+   */
+  public void killJob(String jobId) throws IOException {
+    TempletonRequest<JobInfo> request =
+        new TempletonRequest<JobInfo>(service.path("jobs").path(jobId), JobInfo.class, username, context);
+
+    try {
+      request.delete();
+    } catch (IOException e) {
+      //TODO: remove this after HIVE-5835 resolved
+      LOG.debug("Ignoring 500 response from webhcat (see HIVE-5835)");
     }
+  }
+
+  /**
+   * Get templeton status (version)
+   * @return templeton status
+   * @throws IOException
+   */
+  public Status status() throws IOException {
+    TempletonRequest<Status> request =
+        new TempletonRequest<Status>(service.path("status"), Status.class,
+            username, doAs, context);
+    return request.get();
+  }
+
+  /**
+   * Wrapper for json mapping of status request
+   */
+  public class Status {
+    public String status;
+    public String version;
+  }
+
+  /**
+   * Wrapper for json mapping of runPigQuery request
+   * @see #runPigQuery(String, java.io.File, String, String)
+   */
+  public class JobData {
+    public String id;
+  }
+
+  /**
+   * Wrapper for json mapping of job status
+   */
+  public class JobInfo {
+    public Map<String, Object> status;
+    public Map<String, Object> profile;
+    public Map<String, Object> userargs;
+
+    public String id;
+    public String parentId;
+    public String percentComplete;
+    public Integer exitValue;
+    public String user;
+    public String callback;
+    public String completed;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonRequest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonRequest.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonRequest.java
index 38ec211..8b8b89e 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonRequest.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/templeton/client/TempletonRequest.java
@@ -32,49 +32,68 @@ import java.io.IOException;
  * @param <RESPONSE> data type to deserialize response from JSON
  */
 public class TempletonRequest<RESPONSE> extends Request<RESPONSE> {
-    private String username;
-    private String doAs;
+  private String username;
+  private String doAs;
 
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(TempletonRequest.class);
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(TempletonRequest.class);
 
-    public TempletonRequest(WebResource resource, Class<RESPONSE> responseClass,
-                            String username, ViewContext context) {
-        this(resource, responseClass, username, username, context);
-    }
+  /**
+   * Constructor
+   * @param resource object that represents resource
+   * @param responseClass model class
+   * @param context View Context instance
+   * @param username user.name of templeton. user.name will be equal to doAs value
+   */
+  public TempletonRequest(WebResource resource, Class<RESPONSE> responseClass,
+                          String username, ViewContext context) {
+    this(resource, responseClass, username, username, context);
+  }
 
-    public TempletonRequest(WebResource resource, Class<RESPONSE> responseClass,
-                            String username, String doAs, ViewContext context) {
-        super(resource, responseClass, context);
-        this.username = username;
-        this.doAs = doAs;
-    }
+  /**
+   * Constructor
+   * @param resource object that represents resource
+   * @param responseClass model class
+   * @param context View Context instance
+   * @param username user.name of templeton
+   * @param doAs doAs user for templeton
+   */
+  public TempletonRequest(WebResource resource, Class<RESPONSE> responseClass,
+                          String username, String doAs, ViewContext context) {
+    super(resource, responseClass, context);
+    this.username = username;
+    this.doAs = doAs;
+  }
 
-    public RESPONSE get(WebResource resource) throws IOException {
-        MultivaluedMapImpl params = new MultivaluedMapImpl();
-        params.add("user.name", username);
-        params.add("doAs", doAs);
-        return super.get(resource.queryParams(params));
-    }
+  @Override
+  public RESPONSE get(WebResource resource) throws IOException {
+    MultivaluedMapImpl params = new MultivaluedMapImpl();
+    params.add("user.name", username);
+    params.add("doAs", doAs);
+    return super.get(resource.queryParams(params));
+  }
 
-    public RESPONSE put(WebResource resource, MultivaluedMapImpl data) throws IOException {
-        MultivaluedMapImpl params = new MultivaluedMapImpl();
-        params.add("user.name", username);
-        params.add("doAs", doAs);
-        return super.put(resource.queryParams(params), data);
-    }
+  @Override
+  public RESPONSE put(WebResource resource, MultivaluedMapImpl data) throws IOException {
+    MultivaluedMapImpl params = new MultivaluedMapImpl();
+    params.add("user.name", username);
+    params.add("doAs", doAs);
+    return super.put(resource.queryParams(params), data);
+  }
 
-    public RESPONSE delete(WebResource resource, MultivaluedMapImpl data) throws IOException {
-        MultivaluedMapImpl params = new MultivaluedMapImpl();
-        params.add("user.name", username);
-        params.add("doAs", doAs);
-        return super.delete(resource.queryParams(params), data);
-    }
+  @Override
+  public RESPONSE delete(WebResource resource, MultivaluedMapImpl data) throws IOException {
+    MultivaluedMapImpl params = new MultivaluedMapImpl();
+    params.add("user.name", username);
+    params.add("doAs", doAs);
+    return super.delete(resource.queryParams(params), data);
+  }
 
-    public RESPONSE post(WebResource resource, MultivaluedMapImpl data) throws IOException {
-        MultivaluedMapImpl params = new MultivaluedMapImpl();
-        params.add("user.name", username);
-        params.add("doAs", doAs);
-        return super.post(resource.queryParams(params), data);
-    }
+  @Override
+  public RESPONSE post(WebResource resource, MultivaluedMapImpl data) throws IOException {
+    MultivaluedMapImpl params = new MultivaluedMapImpl();
+    params.add("user.name", username);
+    params.add("doAs", doAs);
+    return super.post(resource.queryParams(params), data);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/FilePaginator.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/FilePaginator.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/FilePaginator.java
index 9312204..2d49c97 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/FilePaginator.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/FilePaginator.java
@@ -28,56 +28,81 @@ import java.util.Arrays;
 
 import static java.lang.Math.ceil;
 
+/**
+ * Pagination for HDFS file implementation
+ */
 public class FilePaginator {
-    private static int PAGE_SIZE = 1*1024*1024;  // 1MB
+  private static int PAGE_SIZE = 1*1024*1024;  // 1MB
 
-    private String filePath;
-    private HdfsApi hdfsApi;
+  private String filePath;
+  private HdfsApi hdfsApi;
 
-    public FilePaginator(String filePath, ViewContext context) {
-        this.filePath = filePath;
-        hdfsApi = BaseService.getHdfsApi(context);
-    }
+  /**
+   * Constructor
+   * @param filePath Path to file on HDFS
+   * @param context View Context instance
+   */
+  public FilePaginator(String filePath, ViewContext context) {
+    this.filePath = filePath;
+    hdfsApi = BaseService.getHdfsApi(context);
+  }
 
-    public static void setPageSize(int PAGE_SIZE) {
-        FilePaginator.PAGE_SIZE = PAGE_SIZE;
-    }
+  /**
+   * Set page size
+   * @param PAGE_SIZE size
+   */
+  public static void setPageSize(int PAGE_SIZE) {
+    FilePaginator.PAGE_SIZE = PAGE_SIZE;
+  }
 
-    public long pageCount() throws IOException, InterruptedException {
-        return (long)
-                ceil( hdfsApi.getFileStatus(filePath).getLen() / ((double)PAGE_SIZE) );
-    }
+  /**
+   * Get page count
+   * @return page count
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public long pageCount() throws IOException, InterruptedException {
+    return (long)
+        ceil( hdfsApi.getFileStatus(filePath).getLen() / ((double)PAGE_SIZE) );
+  }
 
-    public String readPage(long page) throws IOException, InterruptedException {
-        FSDataInputStream stream = hdfsApi.open(filePath);
-        try {
-            stream.seek(page * PAGE_SIZE);
-        } catch (IOException e) {
-            throw new IllegalArgumentException("Page " + page + " does not exists");
-        }
+  /**
+   * Read one page of size PAGE_SIZE
+   * @param page page index
+   * @return data in UTF-8
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public String readPage(long page) throws IOException, InterruptedException {
+    FSDataInputStream stream = hdfsApi.open(filePath);
+    try {
+      stream.seek(page * PAGE_SIZE);
+    } catch (IOException e) {
+      throw new IllegalArgumentException("Page " + page + " does not exists");
+    }
 
-        byte[] buffer = new byte[PAGE_SIZE];
-        int readCount = 0;
-        int read = 0;
-        while(read < PAGE_SIZE) {
-            try {
-                readCount = stream.read(buffer, read, PAGE_SIZE-read);
-            } catch (IOException e) {
-                stream.close();
-                throw e;
-            }
-            if (readCount == -1)
-                break;
-            read += readCount;
-        }
-        if (read != 0) {
-            byte[] readData = Arrays.copyOfRange(buffer, 0, read);
-            return new String(readData, Charset.forName("UTF-8"));
-        } else {
-            if (page == 0) {
-                return "";
-            }
-            throw new IllegalArgumentException("Page " + page + " does not exists");
-        }
+    byte[] buffer = new byte[PAGE_SIZE];
+    int readCount = 0;
+    int read = 0;
+    while(read < PAGE_SIZE) {
+      try {
+        readCount = stream.read(buffer, read, PAGE_SIZE-read);
+      } catch (IOException e) {
+        stream.close();
+        throw e;
+      }
+      if (readCount == -1)
+        break;
+      read += readCount;
+    }
+    if (read != 0) {
+      byte[] readData = Arrays.copyOfRange(buffer, 0, read);
+      return new String(readData, Charset.forName("UTF-8"));
+    } else {
+      if (page == 0) {
+        return "";
+      }
+      throw new IllegalArgumentException("Page " + page + " does not exists");
     }
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/HdfsApi.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/HdfsApi.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/HdfsApi.java
index 9068475..3c698d2 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/HdfsApi.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/utils/HdfsApi.java
@@ -36,154 +36,226 @@ import org.json.simple.JSONArray;
 
 import java.util.LinkedHashMap;
 
+/**
+ * HDFS Business Delegate
+ */
 public class HdfsApi {
-    private Configuration conf = new Configuration();
-
-    private FileSystem fs;
-    private UserGroupInformation ugi;
-
-    public HdfsApi(String defaultFs, String username) throws IOException,
-        InterruptedException {
-        Thread.currentThread().setContextClassLoader(null);
-        conf.set("fs.hdfs.impl", DistributedFileSystem.class.getName());
-        conf.set("fs.webhdfs.impl", WebHdfsFileSystem.class.getName());
-        conf.set("fs.file.impl", "org.apache.hadoop.fs.LocalFileSystem");
-        fs = FileSystem.get(URI.create(defaultFs), conf);
-        ugi = UserGroupInformation.createProxyUser(username,
-            UserGroupInformation.getLoginUser());
-    }
+  private Configuration conf = new Configuration();
 
-    public FileStatus[] listdir(final String path) throws FileNotFoundException,
-        IOException, InterruptedException {
-        return ugi.doAs(new PrivilegedExceptionAction<FileStatus[]>() {
-            public FileStatus[] run() throws FileNotFoundException, Exception {
-                return fs.listStatus(new Path(path));
-            }
-        });
-    }
+  private FileSystem fs;
+  private UserGroupInformation ugi;
 
-    public FileStatus getFileStatus(final String path) throws IOException,
-        FileNotFoundException, InterruptedException {
-        return ugi.doAs(new PrivilegedExceptionAction<FileStatus>() {
-            public FileStatus run() throws FileNotFoundException, IOException {
-                return fs.getFileStatus(new Path(path));
-            }
-        });
-    }
+  /**
+   * Constructor
+   * @param defaultFs hdfs uri
+   * @param username user.name
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public HdfsApi(String defaultFs, String username) throws IOException,
+      InterruptedException {
+    Thread.currentThread().setContextClassLoader(null);
+    conf.set("fs.hdfs.impl", DistributedFileSystem.class.getName());
+    conf.set("fs.webhdfs.impl", WebHdfsFileSystem.class.getName());
+    conf.set("fs.file.impl", "org.apache.hadoop.fs.LocalFileSystem");
+    fs = FileSystem.get(URI.create(defaultFs), conf);
+    ugi = UserGroupInformation.createProxyUser(username,
+        UserGroupInformation.getLoginUser());
+  }
 
-    public boolean mkdir(final String path) throws IOException,
-        InterruptedException {
-        return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
-            public Boolean run() throws Exception {
-                return fs.mkdirs(new Path(path));
-            }
-        });
-    }
+  /**
+   * List dir operation
+   * @param path path
+   * @return array of FileStatus objects
+   * @throws FileNotFoundException
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public FileStatus[] listdir(final String path) throws FileNotFoundException,
+      IOException, InterruptedException {
+    return ugi.doAs(new PrivilegedExceptionAction<FileStatus[]>() {
+      public FileStatus[] run() throws FileNotFoundException, Exception {
+        return fs.listStatus(new Path(path));
+      }
+    });
+  }
 
-    public boolean rename(final String src, final String dst) throws IOException,
-        InterruptedException {
-        return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
-            public Boolean run() throws Exception {
-                return fs.rename(new Path(src), new Path(dst));
-            }
-        });
-    }
+  /**
+   * Get file status
+   * @param path path
+   * @return file status
+   * @throws IOException
+   * @throws FileNotFoundException
+   * @throws InterruptedException
+   */
+  public FileStatus getFileStatus(final String path) throws IOException,
+      FileNotFoundException, InterruptedException {
+    return ugi.doAs(new PrivilegedExceptionAction<FileStatus>() {
+      public FileStatus run() throws FileNotFoundException, IOException {
+        return fs.getFileStatus(new Path(path));
+      }
+    });
+  }
 
-    public boolean delete(final String path, final boolean recursive)
-        throws IOException, InterruptedException {
-        return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
-            public Boolean run() throws Exception {
-                return fs.delete(new Path(path), recursive);
-            }
-        });
-    }
+  /**
+   * Make directory
+   * @param path path
+   * @return success
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public boolean mkdir(final String path) throws IOException,
+      InterruptedException {
+    return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
+      public Boolean run() throws Exception {
+        return fs.mkdirs(new Path(path));
+      }
+    });
+  }
 
-    public FSDataOutputStream create(final String path, final boolean overwrite)
-        throws IOException, InterruptedException {
-        return ugi.doAs(new PrivilegedExceptionAction<FSDataOutputStream>() {
-            public FSDataOutputStream run() throws Exception {
-                return fs.create(new Path(path), overwrite);
-            }
-        });
-    }
+  /**
+   * Rename
+   * @param src source path
+   * @param dst destination path
+   * @return success
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public boolean rename(final String src, final String dst) throws IOException,
+      InterruptedException {
+    return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
+      public Boolean run() throws Exception {
+        return fs.rename(new Path(src), new Path(dst));
+      }
+    });
+  }
 
-    public FSDataInputStream open(final String path) throws IOException,
-        InterruptedException {
-        return ugi.doAs(new PrivilegedExceptionAction<FSDataInputStream>() {
-            public FSDataInputStream run() throws Exception {
-                return fs.open(new Path(path));
-            }
-        });
-    }
+  /**
+   * Delete
+   * @param path path
+   * @param recursive delete recursive
+   * @return success
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public boolean delete(final String path, final boolean recursive)
+      throws IOException, InterruptedException {
+    return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
+      public Boolean run() throws Exception {
+        return fs.delete(new Path(path), recursive);
+      }
+    });
+  }
 
-    public boolean copy(final String src, final String dest) throws IOException,
-            InterruptedException {
-        return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
-            public Boolean run() throws Exception {
-                return FileUtil.copy(fs, new Path(src), fs, new Path(dest), false, conf);
-            }
-        });
-    }
+  /**
+   * Create file
+   * @param path path
+   * @param overwrite overwrite existent file
+   * @return output stream
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public FSDataOutputStream create(final String path, final boolean overwrite)
+      throws IOException, InterruptedException {
+    return ugi.doAs(new PrivilegedExceptionAction<FSDataOutputStream>() {
+      public FSDataOutputStream run() throws Exception {
+        return fs.create(new Path(path), overwrite);
+      }
+    });
+  }
 
-    /**
-     * Converts a Hadoop permission into a Unix permission symbolic representation
-     * (i.e. -rwxr--r--) or default if the permission is NULL.
-     *
-     * @param p
-     *          Hadoop permission.
-     * @return the Unix permission symbolic representation or default if the
-     *         permission is NULL.
-     */
-    private static String permissionToString(FsPermission p) {
-        return (p == null) ? "default" : "-" + p.getUserAction().SYMBOL
-            + p.getGroupAction().SYMBOL + p.getOtherAction().SYMBOL;
-    }
+  /**
+   * Open file
+   * @param path path
+   * @return input stream
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public FSDataInputStream open(final String path) throws IOException,
+      InterruptedException {
+    return ugi.doAs(new PrivilegedExceptionAction<FSDataInputStream>() {
+      public FSDataInputStream run() throws Exception {
+        return fs.open(new Path(path));
+      }
+    });
+  }
 
-    /**
-     * Converts a Hadoop <code>FileStatus</code> object into a JSON array object.
-     * It replaces the <code>SCHEME://HOST:PORT</code> of the path with the
-     * specified URL.
-     * <p/>
-     *
-     * @param status
-     *          Hadoop file status.
-     * @return The JSON representation of the file status.
-     */
-
-    public static Map<String, Object> fileStatusToJSON(FileStatus status) {
-        Map<String, Object> json = new LinkedHashMap<String, Object>();
-        json.put("path", status.getPath().toString());
-        json.put("isDirectory", status.isDirectory());
-        json.put("len", status.getLen());
-        json.put("owner", status.getOwner());
-        json.put("group", status.getGroup());
-        json.put("permission", permissionToString(status.getPermission()));
-        json.put("accessTime", status.getAccessTime());
-        json.put("modificationTime", status.getModificationTime());
-        json.put("blockSize", status.getBlockSize());
-        json.put("replication", status.getReplication());
-        return json;
-    }
+  /**
+   * Copy file
+   * @param src source path
+   * @param dest destination path
+   * @return success
+   * @throws IOException
+   * @throws InterruptedException
+   */
+  public boolean copy(final String src, final String dest) throws IOException,
+      InterruptedException {
+    return ugi.doAs(new PrivilegedExceptionAction<Boolean>() {
+      public Boolean run() throws Exception {
+        return FileUtil.copy(fs, new Path(src), fs, new Path(dest), false, conf);
+      }
+    });
+  }
+
+  /**
+   * Converts a Hadoop permission into a Unix permission symbolic representation
+   * (i.e. -rwxr--r--) or default if the permission is NULL.
+   *
+   * @param p
+   *          Hadoop permission.
+   * @return the Unix permission symbolic representation or default if the
+   *         permission is NULL.
+   */
+  private static String permissionToString(FsPermission p) {
+    return (p == null) ? "default" : "-" + p.getUserAction().SYMBOL
+        + p.getGroupAction().SYMBOL + p.getOtherAction().SYMBOL;
+  }
+
+  /**
+   * Converts a Hadoop <code>FileStatus</code> object into a JSON array object.
+   * It replaces the <code>SCHEME://HOST:PORT</code> of the path with the
+   * specified URL.
+   * <p/>
+   *
+   * @param status
+   *          Hadoop file status.
+   * @return The JSON representation of the file status.
+   */
+
+  public static Map<String, Object> fileStatusToJSON(FileStatus status) {
+    Map<String, Object> json = new LinkedHashMap<String, Object>();
+    json.put("path", status.getPath().toString());
+    json.put("isDirectory", status.isDirectory());
+    json.put("len", status.getLen());
+    json.put("owner", status.getOwner());
+    json.put("group", status.getGroup());
+    json.put("permission", permissionToString(status.getPermission()));
+    json.put("accessTime", status.getAccessTime());
+    json.put("modificationTime", status.getModificationTime());
+    json.put("blockSize", status.getBlockSize());
+    json.put("replication", status.getReplication());
+    return json;
+  }
 
-    /**
-     * Converts a Hadoop <code>FileStatus</code> array into a JSON array object.
-     * It replaces the <code>SCHEME://HOST:PORT</code> of the path with the
-     * specified URL.
-     * <p/>
-     *
-     * @param status
-     *          Hadoop file status array.
-     * @return The JSON representation of the file status array.
-     */
-    @SuppressWarnings("unchecked")
-    public static JSONArray fileStatusToJSON(FileStatus[] status) {
-        JSONArray json = new JSONArray();
-        if (status != null) {
-            for (FileStatus s : status) {
-                json.add(fileStatusToJSON(s));
-            }
-        }
-        return json;
+  /**
+   * Converts a Hadoop <code>FileStatus</code> array into a JSON array object.
+   * It replaces the <code>SCHEME://HOST:PORT</code> of the path with the
+   * specified URL.
+   * <p/>
+   *
+   * @param status
+   *          Hadoop file status array.
+   * @return The JSON representation of the file status array.
+   */
+  @SuppressWarnings("unchecked")
+  public static JSONArray fileStatusToJSON(FileStatus[] status) {
+    JSONArray json = new JSONArray();
+    if (status != null) {
+      for (FileStatus s : status) {
+        json.add(fileStatusToJSON(s));
+      }
     }
+    return json;
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/BasePigTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/BasePigTest.java b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/BasePigTest.java
index 7a237d7..7352157 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/BasePigTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/BasePigTest.java
@@ -33,64 +33,64 @@ import java.util.Map;
 import static org.easymock.EasyMock.*;
 
 public abstract class BasePigTest {
-    protected ViewResourceHandler handler;
-    protected ViewContext context;
-    protected static File pigStorageFile;
-    protected static File baseDir;
+  protected ViewResourceHandler handler;
+  protected ViewContext context;
+  protected static File pigStorageFile;
+  protected static File baseDir;
 
-    protected static String DATA_DIRECTORY = "./target/PigTest";
+  protected static String DATA_DIRECTORY = "./target/PigTest";
 
-    @BeforeClass
-    public static void startUp() throws Exception {
-        File baseDir = new File(DATA_DIRECTORY)
-                .getAbsoluteFile();
-        FileUtil.fullyDelete(baseDir);
-    }
+  @BeforeClass
+  public static void startUp() throws Exception {
+    File baseDir = new File(DATA_DIRECTORY)
+        .getAbsoluteFile();
+    FileUtil.fullyDelete(baseDir);
+  }
 
-    @Before
-    public void setUp() throws Exception {
-        handler = createNiceMock(ViewResourceHandler.class);
-        context = createNiceMock(ViewContext.class);
+  @Before
+  public void setUp() throws Exception {
+    handler = createNiceMock(ViewResourceHandler.class);
+    context = createNiceMock(ViewContext.class);
 
-        Map<String, String> properties = new HashMap<String, String>();
-        baseDir = new File(DATA_DIRECTORY)
-                .getAbsoluteFile();
-        pigStorageFile = new File("./target/BasePigTest/storage.dat")
-                .getAbsoluteFile();
+    Map<String, String> properties = new HashMap<String, String>();
+    baseDir = new File(DATA_DIRECTORY)
+        .getAbsoluteFile();
+    pigStorageFile = new File("./target/BasePigTest/storage.dat")
+        .getAbsoluteFile();
 
-        properties.put("dataworker.storagePath", pigStorageFile.toString());
-        properties.put("dataworker.templeton_url", "localhost:50111/templeton/v1");
-        properties.put("dataworker.templeton_user", "admin");
-        properties.put("dataworker.userScriptsPath", "/tmp/.pigscripts");
-        properties.put("dataworker.pigJobsPath", "/tmp/.pigjobs");
+    properties.put("dataworker.storagePath", pigStorageFile.toString());
+    properties.put("dataworker.templeton_url", "localhost:50111/templeton/v1");
+    properties.put("dataworker.templeton_user", "admin");
+    properties.put("dataworker.userScriptsPath", "/tmp/.pigscripts");
+    properties.put("dataworker.pigJobsPath", "/tmp/.pigjobs");
 
-        setupProperties(properties, baseDir);
+    setupProperties(properties, baseDir);
 
-        expect(context.getProperties()).andReturn(properties).anyTimes();
-        expect(context.getUsername()).andReturn("ambari-qa").anyTimes();
+    expect(context.getProperties()).andReturn(properties).anyTimes();
+    expect(context.getUsername()).andReturn("ambari-qa").anyTimes();
 
-        replay(handler, context);
-    }
+    replay(handler, context);
+  }
 
-    protected void setupProperties(Map<String, String> properties, File baseDir) throws Exception {
+  protected void setupProperties(Map<String, String> properties, File baseDir) throws Exception {
 
-    }
+  }
 
-    @After
-    public void tearDown() throws Exception {
+  @After
+  public void tearDown() throws Exception {
 
-    }
+  }
 
-    protected static <T> T getService(Class<T> clazz,
+  protected static <T> T getService(Class<T> clazz,
                                     final ViewResourceHandler viewResourceHandler,
                                     final ViewContext viewInstanceContext) {
-        Injector viewInstanceInjector = Guice.createInjector(new AbstractModule() {
-            @Override
-            protected void configure() {
-                bind(ViewResourceHandler.class).toInstance(viewResourceHandler);
-                bind(ViewContext.class).toInstance(viewInstanceContext);
-            }
-        });
-        return viewInstanceInjector.getInstance(clazz);
-    }
+    Injector viewInstanceInjector = Guice.createInjector(new AbstractModule() {
+      @Override
+      protected void configure() {
+        bind(ViewResourceHandler.class).toInstance(viewResourceHandler);
+        bind(ViewContext.class).toInstance(viewInstanceContext);
+      }
+    });
+    return viewInstanceInjector.getInstance(clazz);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/HDFSTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/HDFSTest.java b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/HDFSTest.java
index 214c6ef..85a67f6 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/HDFSTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/HDFSTest.java
@@ -28,33 +28,33 @@ import java.io.File;
 import java.util.Map;
 
 public abstract class HDFSTest extends BasePigTest {
-    protected static MiniDFSCluster hdfsCluster;
-    protected static String hdfsURI;
-
-    @BeforeClass
-    public static void startUp() throws Exception {
-        BasePigTest.startUp(); // super
-        File hdfsDir = new File("./target/PigTest/hdfs/")
-                .getAbsoluteFile();
-        FileUtil.fullyDelete(hdfsDir);
-
-        Configuration conf = new Configuration();
-        conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, hdfsDir.getAbsolutePath());
-
-        MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf);
-        hdfsCluster = builder.build();
-        hdfsURI = hdfsCluster.getURI().toString();
-    }
-
-    @AfterClass
-    public static void shutDown() throws Exception {
-        hdfsCluster.shutdown();
-        hdfsCluster = null;
-    }
-
-    @Override
-    protected void setupProperties(Map<String, String> properties, File baseDir) throws Exception {
-        super.setupProperties(properties, baseDir);
-        properties.put("dataworker.defaultFs", hdfsURI);
-    }
+  protected static MiniDFSCluster hdfsCluster;
+  protected static String hdfsURI;
+
+  @BeforeClass
+  public static void startUp() throws Exception {
+    BasePigTest.startUp(); // super
+    File hdfsDir = new File("./target/PigTest/hdfs/")
+        .getAbsoluteFile();
+    FileUtil.fullyDelete(hdfsDir);
+
+    Configuration conf = new Configuration();
+    conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, hdfsDir.getAbsolutePath());
+
+    MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf);
+    hdfsCluster = builder.build();
+    hdfsURI = hdfsCluster.getURI().toString();
+  }
+
+  @AfterClass
+  public static void shutDown() throws Exception {
+    hdfsCluster.shutdown();
+    hdfsCluster = null;
+  }
+
+  @Override
+  protected void setupProperties(Map<String, String> properties, File baseDir) throws Exception {
+    super.setupProperties(properties, baseDir);
+    properties.put("dataworker.defaultFs", hdfsURI);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java
index 1e78ee6..3ebb4f4 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/FileTest.java
@@ -36,168 +36,168 @@ import java.util.UUID;
 import static org.easymock.EasyMock.*;
 
 public class FileTest extends HDFSTest {
-    private final static int PAGINATOR_PAGE_SIZE = 4;
-    private FileService fileService;
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-        fileService = getService(FileService.class, handler, context);
-        FilePaginator.setPageSize(PAGINATOR_PAGE_SIZE);
-    }
-
-    @BeforeClass
-    public static void startUp() throws Exception {
-        HDFSTest.startUp(); // super
-    }
-
-    @AfterClass
-    public static void shutDown() throws Exception {
-        HDFSTest.shutDown(); // super
-        FileService.setHdfsApi(null); //cleanup API connection
-    }
-
-    private Response doCreateFile() throws IOException, InterruptedException {
-        replay(handler, context);
-        return doCreateFile("luke", "i'm your father");
-    }
-
-    private Response doCreateFile(String name, String content) throws IOException, InterruptedException {
-        return doCreateFile(name, content, "/tmp/");
-    }
-
-    private Response doCreateFile(String name, String content, String filePath) throws IOException, InterruptedException {
-        FileService.FileResourceRequest request = new FileService.FileResourceRequest();
-        request.file = new FileResource();
-        request.file.filePath = filePath + name;
-        request.file.fileContent = content;
-
-        HttpServletResponse resp_obj = createNiceMock(HttpServletResponse.class);
-        resp_obj.setHeader(eq("Location"), anyString());
-
-        UriInfo uriInfo = createNiceMock(UriInfo.class);
-        URI uri = UriBuilder.fromUri("http://host/a/b").build();
-        expect(uriInfo.getAbsolutePath()).andReturn(uri);
-
-        replay(resp_obj, uriInfo);
-        return fileService.createFile(request, resp_obj, uriInfo);
-    }
-
-    @Test
-    public void testCreateFile() throws IOException, InterruptedException {
-        String name = UUID.randomUUID().toString().replaceAll("-", "");
-        Response response = doCreateFile(name, "12323");
-        Assert.assertEquals(204, response.getStatus());
-
-        String name2 = UUID.randomUUID().toString().replaceAll("-", "");
-        Response response2 = doCreateFile(name2, "12323");
-        Assert.assertEquals(204, response2.getStatus());
-    }
-
-    @Test
-    public void testCreateFilePathNotExists() throws IOException, InterruptedException {
-        Response response = doCreateFile("Luke", null, "/non/existent/path/");
-        Assert.assertEquals(204, response.getStatus());  // path created automatically
-
-        Response response2 = doCreateFile("Leia", null, "/tmp/");
-        Assert.assertEquals(204, response2.getStatus());
-
-        Response response3 = doCreateFile("Leia", null, "/tmp/"); // file already exists
-        Assert.assertEquals(400, response3.getStatus());
-    }
-
-    @Test
-    public void testUpdateFileContent() throws Exception {
-        String name = UUID.randomUUID().toString().replaceAll("-", "");
-        String filePath = "/tmp/" + name;
-
-        Response createdFile = doCreateFile(name, "some content");
-        FileService.FileResourceRequest request = new FileService.FileResourceRequest();
-        request.file = new FileResource();
-        request.file.filePath = filePath;
-        request.file.fileContent = "1234567890";  // 10 bytes, 3*(4b page)
-
-        Response response = fileService.updateFile(request, filePath);
-        Assert.assertEquals(204, response.getStatus());
-
-        Response response2 = fileService.getFile(filePath, 0L);
-        Assert.assertEquals(200, response2.getStatus());
-
-        JSONObject obj = ((JSONObject) response2.getEntity());
-        Assert.assertTrue(obj.containsKey("file"));
-        Assert.assertEquals("1234", ((FileResource) obj.get("file")).fileContent);
-    }
-
-    @Test
-    public void testPagination() throws Exception {
-        String name = UUID.randomUUID().toString().replaceAll("-", "");
-        String filePath = "/tmp/" + name;
-
-        doCreateFile(name, "1234567890");
-
-        Response response = fileService.getFile(filePath, 0L);
-        Assert.assertEquals(200, response.getStatus());
-
-        JSONObject obj = ((JSONObject) response.getEntity());
-        Assert.assertTrue(obj.containsKey("file"));
-        Assert.assertEquals("1234", ((FileResource) obj.get("file")).fileContent);
-        Assert.assertEquals(3, ((FileResource) obj.get("file")).pageCount);
-        Assert.assertEquals(0, ((FileResource) obj.get("file")).page);
-        Assert.assertTrue(((FileResource) obj.get("file")).hasNext);
-        Assert.assertEquals(filePath, ((FileResource) obj.get("file")).filePath);
-
-        response = fileService.getFile(filePath, 1L);
-        Assert.assertEquals(200, response.getStatus());
-
-        obj = ((JSONObject) response.getEntity());
-        Assert.assertEquals("5678", ((FileResource) obj.get("file")).fileContent);
-        Assert.assertEquals(1, ((FileResource) obj.get("file")).page);
-        Assert.assertTrue(((FileResource) obj.get("file")).hasNext);
-
-        response = fileService.getFile(filePath, 2L);
-        Assert.assertEquals(200, response.getStatus());
-
-        obj = ((JSONObject) response.getEntity());
-        Assert.assertEquals("90", ((FileResource) obj.get("file")).fileContent);
-        Assert.assertEquals(2, ((FileResource) obj.get("file")).page);
-        Assert.assertFalse(((FileResource) obj.get("file")).hasNext);
-
-        response = fileService.getFile(filePath, 3L);
-        Assert.assertEquals(400, response.getStatus()); //page not found
-    }
-
-    @Test
-    public void testZeroLengthFile() throws Exception {
-        String name = UUID.randomUUID().toString().replaceAll("-", "");
-        String filePath = "/tmp/" + name;
-
-        doCreateFile(name, "");
-
-        Response response = fileService.getFile(filePath, 0L);
-        Assert.assertEquals(200, response.getStatus());
-        JSONObject obj = ((JSONObject) response.getEntity());
-        Assert.assertEquals("", ((FileResource) obj.get("file")).fileContent);
-        Assert.assertEquals(0, ((FileResource) obj.get("file")).page);
-        Assert.assertFalse(((FileResource) obj.get("file")).hasNext);
-    }
-
-    @Test
-    public void testFileNotFound() throws IOException, InterruptedException {
-        Response response1 = fileService.getFile("/tmp/notExistentFile", 2L);
-        Assert.assertEquals(404, response1.getStatus());
-    }
-
-    @Test
-    public void testDeleteFile() throws IOException, InterruptedException {
-        String name = UUID.randomUUID().toString().replaceAll("-", "");
-        String filePath = "/tmp/" + name;
-        Response createdFile = doCreateFile(name, "some content");
-
-        Response response = fileService.deleteFile(filePath);
-        Assert.assertEquals(204, response.getStatus());
-
-        Response response2 = fileService.getFile(filePath, 0L);
-        Assert.assertEquals(404, response2.getStatus());
-    }
+  private final static int PAGINATOR_PAGE_SIZE = 4;
+  private FileService fileService;
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    fileService = getService(FileService.class, handler, context);
+    FilePaginator.setPageSize(PAGINATOR_PAGE_SIZE);
+  }
+
+  @BeforeClass
+  public static void startUp() throws Exception {
+    HDFSTest.startUp(); // super
+  }
+
+  @AfterClass
+  public static void shutDown() throws Exception {
+    HDFSTest.shutDown(); // super
+    FileService.setHdfsApi(null); //cleanup API connection
+  }
+
+  private Response doCreateFile() throws IOException, InterruptedException {
+    replay(handler, context);
+    return doCreateFile("luke", "i'm your father");
+  }
+
+  private Response doCreateFile(String name, String content) throws IOException, InterruptedException {
+    return doCreateFile(name, content, "/tmp/");
+  }
+
+  private Response doCreateFile(String name, String content, String filePath) throws IOException, InterruptedException {
+    FileService.FileResourceRequest request = new FileService.FileResourceRequest();
+    request.file = new FileResource();
+    request.file.setFilePath(filePath + name);
+    request.file.setFileContent(content);
+
+    HttpServletResponse resp_obj = createNiceMock(HttpServletResponse.class);
+    resp_obj.setHeader(eq("Location"), anyString());
+
+    UriInfo uriInfo = createNiceMock(UriInfo.class);
+    URI uri = UriBuilder.fromUri("http://host/a/b").build();
+    expect(uriInfo.getAbsolutePath()).andReturn(uri);
+
+    replay(resp_obj, uriInfo);
+    return fileService.createFile(request, resp_obj, uriInfo);
+  }
+
+  @Test
+  public void testCreateFile() throws IOException, InterruptedException {
+    String name = UUID.randomUUID().toString().replaceAll("-", "");
+    Response response = doCreateFile(name, "12323");
+    Assert.assertEquals(204, response.getStatus());
+
+    String name2 = UUID.randomUUID().toString().replaceAll("-", "");
+    Response response2 = doCreateFile(name2, "12323");
+    Assert.assertEquals(204, response2.getStatus());
+  }
+
+  @Test
+  public void testCreateFilePathNotExists() throws IOException, InterruptedException {
+    Response response = doCreateFile("Luke", null, "/non/existent/path/");
+    Assert.assertEquals(204, response.getStatus());  // path created automatically
+
+    Response response2 = doCreateFile("Leia", null, "/tmp/");
+    Assert.assertEquals(204, response2.getStatus());
+
+    Response response3 = doCreateFile("Leia", null, "/tmp/"); // file already exists
+    Assert.assertEquals(400, response3.getStatus());
+  }
+
+  @Test
+  public void testUpdateFileContent() throws Exception {
+    String name = UUID.randomUUID().toString().replaceAll("-", "");
+    String filePath = "/tmp/" + name;
+
+    Response createdFile = doCreateFile(name, "some content");
+    FileService.FileResourceRequest request = new FileService.FileResourceRequest();
+    request.file = new FileResource();
+    request.file.setFilePath(filePath);
+    request.file.setFileContent("1234567890");  // 10 bytes, 3*(4b page)
+
+    Response response = fileService.updateFile(request, filePath);
+    Assert.assertEquals(204, response.getStatus());
+
+    Response response2 = fileService.getFile(filePath, 0L);
+    Assert.assertEquals(200, response2.getStatus());
+
+    JSONObject obj = ((JSONObject) response2.getEntity());
+    Assert.assertTrue(obj.containsKey("file"));
+    Assert.assertEquals("1234", ((FileResource) obj.get("file")).getFileContent());
+  }
+
+  @Test
+  public void testPagination() throws Exception {
+    String name = UUID.randomUUID().toString().replaceAll("-", "");
+    String filePath = "/tmp/" + name;
+
+    doCreateFile(name, "1234567890");
+
+    Response response = fileService.getFile(filePath, 0L);
+    Assert.assertEquals(200, response.getStatus());
+
+    JSONObject obj = ((JSONObject) response.getEntity());
+    Assert.assertTrue(obj.containsKey("file"));
+    Assert.assertEquals("1234", ((FileResource) obj.get("file")).getFileContent());
+    Assert.assertEquals(3, ((FileResource) obj.get("file")).getPageCount());
+    Assert.assertEquals(0, ((FileResource) obj.get("file")).getPage());
+    Assert.assertTrue(((FileResource) obj.get("file")).isHasNext());
+    Assert.assertEquals(filePath, ((FileResource) obj.get("file")).getFilePath());
+
+    response = fileService.getFile(filePath, 1L);
+    Assert.assertEquals(200, response.getStatus());
+
+    obj = ((JSONObject) response.getEntity());
+    Assert.assertEquals("5678", ((FileResource) obj.get("file")).getFileContent());
+    Assert.assertEquals(1, ((FileResource) obj.get("file")).getPage());
+    Assert.assertTrue(((FileResource) obj.get("file")).isHasNext());
+
+    response = fileService.getFile(filePath, 2L);
+    Assert.assertEquals(200, response.getStatus());
+
+    obj = ((JSONObject) response.getEntity());
+    Assert.assertEquals("90", ((FileResource) obj.get("file")).getFileContent());
+    Assert.assertEquals(2, ((FileResource) obj.get("file")).getPage());
+    Assert.assertFalse(((FileResource) obj.get("file")).isHasNext());
+
+    response = fileService.getFile(filePath, 3L);
+    Assert.assertEquals(400, response.getStatus()); //page not found
+  }
+
+  @Test
+  public void testZeroLengthFile() throws Exception {
+    String name = UUID.randomUUID().toString().replaceAll("-", "");
+    String filePath = "/tmp/" + name;
+
+    doCreateFile(name, "");
+
+    Response response = fileService.getFile(filePath, 0L);
+    Assert.assertEquals(200, response.getStatus());
+    JSONObject obj = ((JSONObject) response.getEntity());
+    Assert.assertEquals("", ((FileResource) obj.get("file")).getFileContent());
+    Assert.assertEquals(0, ((FileResource) obj.get("file")).getPage());
+    Assert.assertFalse(((FileResource) obj.get("file")).isHasNext());
+  }
+
+  @Test
+  public void testFileNotFound() throws IOException, InterruptedException {
+    Response response1 = fileService.getFile("/tmp/notExistentFile", 2L);
+    Assert.assertEquals(404, response1.getStatus());
+  }
+
+  @Test
+  public void testDeleteFile() throws IOException, InterruptedException {
+    String name = UUID.randomUUID().toString().replaceAll("-", "");
+    String filePath = "/tmp/" + name;
+    Response createdFile = doCreateFile(name, "some content");
+
+    Response response = fileService.deleteFile(filePath);
+    Assert.assertEquals(204, response.getStatus());
+
+    Response response2 = fileService.getFile(filePath, 0L);
+    Assert.assertEquals(404, response2.getStatus());
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java
index 5d633dc..167317d 100644
--- a/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java
+++ b/contrib/views/pig/src/test/java/org/apache/ambari/view/pig/test/HelpTest.java
@@ -27,33 +27,33 @@ import org.junit.*;
 import javax.ws.rs.core.Response;
 
 public class HelpTest extends HDFSTest {
-    private HelpService helpService;
-
-    @Override
-    @Before
-    public void setUp() throws Exception {
-        super.setUp();
-        helpService = new HelpService(context, handler);
-    }
-
-    @BeforeClass
-    public static void startUp() throws Exception {
-        HDFSTest.startUp(); // super
-    }
-
-    @AfterClass
-    public static void shutDown() throws Exception {
-        HDFSTest.shutDown(); // super
-        FileService.setHdfsApi(null); //cleanup API connection
-    }
-
-    @Test
-    public void configTest() {
-        Response response = helpService.config();
-        Assert.assertEquals(200, response.getStatus());
-
-        JSONObject obj = (JSONObject)response.getEntity();
-        Assert.assertTrue(obj.containsKey("dataworker.defaultFs"));
-        Assert.assertEquals(hdfsURI, obj.get("dataworker.defaultFs"));
-    }
+  private HelpService helpService;
+
+  @Override
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    helpService = new HelpService(context, handler);
+  }
+
+  @BeforeClass
+  public static void startUp() throws Exception {
+    HDFSTest.startUp(); // super
+  }
+
+  @AfterClass
+  public static void shutDown() throws Exception {
+    HDFSTest.shutDown(); // super
+    FileService.setHdfsApi(null); //cleanup API connection
+  }
+
+  @Test
+  public void configTest() {
+    Response response = helpService.config();
+    Assert.assertEquals(200, response.getStatus());
+
+    JSONObject obj = (JSONObject)response.getEntity();
+    Assert.assertTrue(obj.containsKey("dataworker.defaultFs"));
+    Assert.assertEquals(hdfsURI, obj.get("dataworker.defaultFs"));
+  }
 }


[4/4] git commit: AMBARI-5704. Pig View Cleanup. (mahadev)

Posted by ma...@apache.org.
AMBARI-5704. Pig View Cleanup. (mahadev)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c64261e2
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c64261e2
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c64261e2

Branch: refs/heads/branch-1.6.0
Commit: c64261e26961f1d290821c0098e08c8b69f51606
Parents: 40e5707
Author: Mahadev Konar <ma...@apache.org>
Authored: Wed May 7 12:38:42 2014 -0700
Committer: Mahadev Konar <ma...@apache.org>
Committed: Wed May 7 12:38:42 2014 -0700

----------------------------------------------------------------------
 .../ambari/view/pig/PigServiceRouter.java       |  29 +-
 .../persistence/InstanceKeyValueStorage.java    | 130 ++--
 .../view/pig/persistence/KeyValueStorage.java   | 232 +++---
 .../pig/persistence/LocalKeyValueStorage.java   |  52 +-
 .../persistence/PersistentConfiguration.java    |  31 +-
 .../ambari/view/pig/persistence/Storage.java    |  51 +-
 .../utils/ContextConfigurationAdapter.java      | 445 +++++------
 .../persistence/utils/FilteringStrategy.java    |  10 +-
 .../view/pig/persistence/utils/Indexed.java     |  16 +-
 .../pig/persistence/utils/ItemNotFound.java     |   3 +
 .../utils/OnlyOwnersFilteringStrategy.java      |  18 +-
 .../view/pig/persistence/utils/Owned.java       |  16 +-
 .../view/pig/persistence/utils/StorageUtil.java |  57 +-
 .../view/pig/resources/CRUDResourceManager.java | 118 +--
 .../resources/PersonalCRUDResourceManager.java  |  89 ++-
 .../resources/SharedCRUDResourceManager.java    |  31 +-
 .../view/pig/resources/files/FileResource.java  |  53 +-
 .../view/pig/resources/files/FileService.java   | 161 ++--
 .../pig/resources/jobs/JobResourceManager.java  | 422 ++++++-----
 .../pig/resources/jobs/JobResourceProvider.java | 113 +--
 .../view/pig/resources/jobs/JobService.java     | 359 ++++-----
 .../view/pig/resources/jobs/models/PigJob.java  | 408 +++++-----
 .../pig/resources/jobs/utils/JobPolling.java    | 175 ++---
 .../scripts/ScriptResourceManager.java          | 121 +--
 .../scripts/ScriptResourceProvider.java         | 117 +--
 .../pig/resources/scripts/ScriptService.java    | 199 ++---
 .../pig/resources/scripts/models/PigScript.java | 146 ++--
 .../pig/resources/udf/UDFResourceManager.java   |  17 +-
 .../pig/resources/udf/UDFResourceProvider.java  | 117 +--
 .../view/pig/resources/udf/UDFService.java      | 199 ++---
 .../view/pig/resources/udf/models/UDF.java      |  74 +-
 .../ambari/view/pig/services/BaseService.java   | 158 ++--
 .../ambari/view/pig/services/HelpService.java   |  60 +-
 .../view/pig/templeton/client/Request.java      | 376 +++++-----
 .../view/pig/templeton/client/TempletonApi.java | 274 ++++---
 .../pig/templeton/client/TempletonRequest.java  |  95 ++-
 .../ambari/view/pig/utils/FilePaginator.java    | 113 +--
 .../apache/ambari/view/pig/utils/HdfsApi.java   | 344 +++++----
 .../org/apache/ambari/view/pig/BasePigTest.java |  90 +--
 .../org/apache/ambari/view/pig/HDFSTest.java    |  58 +-
 .../apache/ambari/view/pig/test/FileTest.java   | 328 ++++-----
 .../apache/ambari/view/pig/test/HelpTest.java   |  58 +-
 .../apache/ambari/view/pig/test/JobTest.java    | 738 +++++++++----------
 .../view/pig/test/ScriptTestHDFSUnmanaged.java  | 112 +--
 .../view/pig/test/ScriptTestUnmanaged.java      |  60 +-
 .../apache/ambari/view/pig/test/UDFTest.java    | 154 ++--
 46 files changed, 3766 insertions(+), 3261 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PigServiceRouter.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PigServiceRouter.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PigServiceRouter.java
index e1098e7..14f3b4a 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PigServiceRouter.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/PigServiceRouter.java
@@ -29,20 +29,27 @@ import org.slf4j.LoggerFactory;
 
 import javax.ws.rs.Path;
 
+/**
+ * Pig service
+ */
 public class PigServiceRouter {
-    @Inject
-    ViewContext context;
+  @Inject
+  ViewContext context;
 
-    @Inject
-    protected ViewResourceHandler handler;
+  @Inject
+  protected ViewResourceHandler handler;
 
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(PigServiceRouter.class);
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(PigServiceRouter.class);
 
-    private Storage storage = null;
+  private Storage storage = null;
 
-    @Path("/help")
-    public HelpService help(){
-        return new HelpService(context, handler);
-    }
+  /**
+   * Help service
+   * @return help service
+   */
+  @Path("/help")
+  public HelpService help(){
+    return new HelpService(context, handler);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/InstanceKeyValueStorage.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/InstanceKeyValueStorage.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/InstanceKeyValueStorage.java
index 101dcb9..a5ccc35 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/InstanceKeyValueStorage.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/InstanceKeyValueStorage.java
@@ -31,77 +31,85 @@ import org.slf4j.LoggerFactory;
  * Path to file should be in 'dataworker.storagePath' parameter
  */
 public class InstanceKeyValueStorage extends KeyValueStorage {
-    private final static Logger LOG =
-            LoggerFactory.getLogger(InstanceKeyValueStorage.class);
+  private final static Logger LOG =
+      LoggerFactory.getLogger(InstanceKeyValueStorage.class);
 
-    private ContextConfigurationAdapter config = null;
-    private int VALUE_LENGTH_LIMIT = 254;
+  private ContextConfigurationAdapter config = null;
+  private int VALUE_LENGTH_LIMIT = 254;
 
-    public InstanceKeyValueStorage(ViewContext context) {
-        super(context);
-    }
+  /**
+   * Constructor.
+   * @param context View Context instance
+   */
+  public InstanceKeyValueStorage(ViewContext context) {
+    super(context);
+  }
 
-    @Override
-    protected synchronized Configuration getConfig() {
-        if (config == null) {
-            config = new ContextConfigurationAdapter(context);
-        }
-        return config;
+  /**
+   * Returns config instance, adapter to Persistence API
+   * @return config instance
+   */
+  @Override
+  protected synchronized Configuration getConfig() {
+    if (config == null) {
+      config = new ContextConfigurationAdapter(context);
     }
+    return config;
+  }
 
-    /**
-     * Value is limited to 256 symbols, this code splits value into chunks and saves them as <key>#<chunk_id>
-     * @param modelPropName key
-     * @param json value
-     */
-    protected void write(String modelPropName, String json) {
-        int saved = 0;
-        int page = 1;
-        while (saved < json.length()) {
-            int end = Math.min(saved + VALUE_LENGTH_LIMIT, json.length());
-            String substring = json.substring(saved, end);
-            getConfig().setProperty(modelPropName + "#" + page, substring);
-            saved += VALUE_LENGTH_LIMIT;
-            page += 1;
-            LOG.debug("Chunk saved: " + modelPropName + "#" + page + "=" + substring);
-        }
-        getConfig().setProperty(modelPropName, page - 1);
-        LOG.debug("Write finished: " + modelPropName + " pages:" + (page - 1));
+  /**
+   * Value is limited to 256 symbols, this code splits value into chunks and saves them as <key>#<chunk_id>
+   * @param modelPropName key
+   * @param json value
+   */
+  protected void write(String modelPropName, String json) {
+    int saved = 0;
+    int page = 1;
+    while (saved < json.length()) {
+      int end = Math.min(saved + VALUE_LENGTH_LIMIT, json.length());
+      String substring = json.substring(saved, end);
+      getConfig().setProperty(modelPropName + "#" + page, substring);
+      saved += VALUE_LENGTH_LIMIT;
+      page += 1;
+      LOG.debug("Chunk saved: " + modelPropName + "#" + page + "=" + substring);
     }
+    getConfig().setProperty(modelPropName, page - 1);
+    LOG.debug("Write finished: " + modelPropName + " pages:" + (page - 1));
+  }
 
-    /**
-     * Read chunked value (keys format <key>#<chunk_id>)
-     * @param modelPropName key
-     * @return value
-     */
-    protected String read(String modelPropName) {
-        StringBuilder result = new StringBuilder();
-        int pages = getConfig().getInt(modelPropName);
-        LOG.debug("Read started: " + modelPropName + " pages:" + pages);
-
-        for(int page = 1; page <= pages; page++) {
-            String substring = getConfig().getString(modelPropName + "#" + page);
-            LOG.debug("Chunk read: " + modelPropName + "#" + page + "=" + substring);
-            if (substring != null) {
-                result.append(substring);
-            }
-        }
+  /**
+   * Read chunked value (keys format <key>#<chunk_id>)
+   * @param modelPropName key
+   * @return value
+   */
+  protected String read(String modelPropName) {
+    StringBuilder result = new StringBuilder();
+    int pages = getConfig().getInt(modelPropName);
+    LOG.debug("Read started: " + modelPropName + " pages:" + pages);
 
-        return result.toString();
+    for(int page = 1; page <= pages; page++) {
+      String substring = getConfig().getString(modelPropName + "#" + page);
+      LOG.debug("Chunk read: " + modelPropName + "#" + page + "=" + substring);
+      if (substring != null) {
+        result.append(substring);
+      }
     }
 
-    /**
-     * Remove chunked value (keys format <key>#<chunk_id>)
-     * @param modelPropName key
-     */
-    protected void clear(String modelPropName) {
-        int pages = getConfig().getInt(modelPropName);
-        LOG.debug("Clean started: " + modelPropName + " pages:" + pages);
+    return result.toString();
+  }
+
+  /**
+   * Remove chunked value (keys format <key>#<chunk_id>)
+   * @param modelPropName key
+   */
+  protected void clear(String modelPropName) {
+    int pages = getConfig().getInt(modelPropName);
+    LOG.debug("Clean started: " + modelPropName + " pages:" + pages);
 
-        for(int page = 1; page <= pages; page++) {
-            getConfig().clearProperty(modelPropName + "#" + page);
-            LOG.debug("Chunk clean: " + modelPropName + "#" + page);
-        }
-        getConfig().clearProperty(modelPropName);
+    for(int page = 1; page <= pages; page++) {
+      getConfig().clearProperty(modelPropName + "#" + page);
+      LOG.debug("Chunk clean: " + modelPropName + "#" + page);
     }
+    getConfig().clearProperty(modelPropName);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/KeyValueStorage.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/KeyValueStorage.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/KeyValueStorage.java
index db18680..1f5fe7f 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/KeyValueStorage.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/KeyValueStorage.java
@@ -32,123 +32,131 @@ import java.util.ArrayList;
 import java.util.List;
 
 /**
- * Engine storing objects to key-value storage
+ * Engine for storing objects to key-value storage
  */
 public abstract class KeyValueStorage implements Storage {
-    private final static Logger LOG =
-            LoggerFactory.getLogger(KeyValueStorage.class);
-    protected final Gson gson = new Gson();
-    protected ViewContext context;
-
-    public KeyValueStorage(ViewContext context) {
-        this.context = context;
+  private final static Logger LOG =
+      LoggerFactory.getLogger(KeyValueStorage.class);
+  protected final Gson gson = new Gson();
+  protected ViewContext context;
+
+  /**
+   * Constructor
+   * @param context View Context instance
+   */
+  public KeyValueStorage(ViewContext context) {
+    this.context = context;
+  }
+
+  /**
+   * Returns config instance, adapter to Persistence API
+   * @return config instance
+   */
+  protected abstract Configuration getConfig();
+
+  @Override
+  public synchronized void store(Indexed obj) {
+    String modelIndexingPropName = getIndexPropertyName(obj.getClass());
+
+    if (obj.getId() == null) {
+      int lastIndex = getConfig().getInt(modelIndexingPropName, 0);
+      lastIndex ++;
+      getConfig().setProperty(modelIndexingPropName, lastIndex);
+      obj.setId(Integer.toString(lastIndex));
     }
 
-    protected abstract Configuration getConfig();
-
-    @Override
-    public synchronized void store(Indexed obj) {
-        String modelIndexingPropName = getIndexPropertyName(obj.getClass());
-
-        if (obj.getId() == null) {
-            int lastIndex = getConfig().getInt(modelIndexingPropName, 0);
-            lastIndex ++;
-            getConfig().setProperty(modelIndexingPropName, lastIndex);
-            obj.setId(Integer.toString(lastIndex));
-        }
-
-        String modelPropName = getItemPropertyName(obj.getClass(), Integer.parseInt(obj.getId()));
-        String json = serialize(obj);
-        write(modelPropName, json);
+    String modelPropName = getItemPropertyName(obj.getClass(), Integer.parseInt(obj.getId()));
+    String json = serialize(obj);
+    write(modelPropName, json);
+  }
+
+  @Override
+  public <T extends Indexed> T load(Class<T> model, int id) throws ItemNotFound {
+    String modelPropName = getItemPropertyName(model, id);
+    LOG.debug(String.format("Loading %s", modelPropName));
+    if (getConfig().containsKey(modelPropName)) {
+      String json = read(modelPropName);
+      LOG.debug(String.format("json: %s", json));
+      return deserialize(model, json);
+    } else {
+      throw new ItemNotFound();
     }
-
-    @Override
-    public <T extends Indexed> T load(Class<T> model, int id) throws ItemNotFound {
-        String modelPropName = getItemPropertyName(model, id);
-        LOG.debug(String.format("Loading %s", modelPropName));
-        if (getConfig().containsKey(modelPropName)) {
-            String json = read(modelPropName);
-            LOG.debug(String.format("json: %s", json));
-            return deserialize(model, json);
-        } else {
-            throw new ItemNotFound();
+  }
+
+  /**
+   * Write json to storage
+   * @param modelPropName key
+   * @param json value
+   */
+  protected void write(String modelPropName, String json) {
+    getConfig().setProperty(modelPropName, json);
+  }
+
+  /**
+   * Read json from storage
+   * @param modelPropName key
+   * @return value
+   */
+  protected String read(String modelPropName) {
+    return getConfig().getString(modelPropName);
+  }
+
+  /**
+   * Remove line from storage
+   * @param modelPropName key
+   */
+  protected void clear(String modelPropName) {
+    getConfig().clearProperty(modelPropName);
+  }
+
+  protected String serialize(Indexed obj) {
+    return gson.toJson(obj);
+  }
+
+  protected <T extends Indexed> T deserialize(Class<T> model, String json) {
+    return gson.fromJson(json, model);
+  }
+
+  @Override
+  public synchronized <T extends Indexed> List<T> loadAll(Class<T> model, FilteringStrategy filter) {
+    ArrayList<T> list = new ArrayList<T>();
+    String modelIndexingPropName = getIndexPropertyName(model);
+    LOG.debug(String.format("Loading all %s-s", model.getName()));
+    int lastIndex = getConfig().getInt(modelIndexingPropName, 0);
+    for(int i=1; i<=lastIndex; i++) {
+      try {
+        T item = load(model, i);
+        if ((filter == null) || filter.isConform(item)) {
+          list.add(item);
         }
+      } catch (ItemNotFound ignored) {
+      }
     }
-
-    /**
-     * Write json to storage
-     * @param modelPropName key
-     * @param json value
-     */
-    protected void write(String modelPropName, String json) {
-        getConfig().setProperty(modelPropName, json);
-    }
-
-    /**
-     * Read json from storage
-     * @param modelPropName key
-     * @return value
-     */
-    protected String read(String modelPropName) {
-        return getConfig().getString(modelPropName);
-    }
-
-    /**
-     * Remove line from storage
-     * @param modelPropName key
-     */
-    protected void clear(String modelPropName) {
-        getConfig().clearProperty(modelPropName);
-    }
-
-    protected String serialize(Indexed obj) {
-        return gson.toJson(obj);
-    }
-
-    protected <T extends Indexed> T deserialize(Class<T> model, String json) {
-        return gson.fromJson(json, model);
-    }
-
-    @Override
-    public synchronized <T extends Indexed> List<T> loadAll(Class<T> model, FilteringStrategy filter) {
-        ArrayList<T> list = new ArrayList<T>();
-        String modelIndexingPropName = getIndexPropertyName(model);
-        LOG.debug(String.format("Loading all %s-s", model.getName()));
-        int lastIndex = getConfig().getInt(modelIndexingPropName, 0);
-        for(int i=1; i<=lastIndex; i++) {
-            try {
-                T item = load(model, i);
-                if ((filter == null) || filter.is_conform(item)) {
-                    list.add(item);
-                }
-            } catch (ItemNotFound ignored) {
-            }
-        }
-        return list;
-    }
-
-    @Override
-    public synchronized <T extends Indexed> List<T> loadAll(Class<T> model) {
-        return loadAll(model, new OnlyOwnersFilteringStrategy(this.context.getUsername()));
-    }
-
-    @Override
-    public synchronized void delete(Class model, int id) {
-        LOG.debug(String.format("Deleting %s:%d", model.getName(), id));
-        String modelPropName = getItemPropertyName(model, id);
-        clear(modelPropName);
-    }
-
-    @Override
-    public boolean exists(Class model, int id) {
-        return getConfig().containsKey(getItemPropertyName(model, id));
-    }
-
-    private String getIndexPropertyName(Class model) {
-        return String.format("%s:index", model.getName());
-    }
-
-    private String getItemPropertyName(Class model, int id) {
-        return String.format("%s.%d", model.getName(), id);
-    }
+    return list;
+  }
+
+  @Override
+  public synchronized <T extends Indexed> List<T> loadAll(Class<T> model) {
+    return loadAll(model, new OnlyOwnersFilteringStrategy(this.context.getUsername()));
+  }
+
+  @Override
+  public synchronized void delete(Class model, int id) {
+    LOG.debug(String.format("Deleting %s:%d", model.getName(), id));
+    String modelPropName = getItemPropertyName(model, id);
+    clear(modelPropName);
+  }
+
+  @Override
+  public boolean exists(Class model, int id) {
+    return getConfig().containsKey(getItemPropertyName(model, id));
+  }
+
+  private String getIndexPropertyName(Class model) {
+    return String.format("%s:index", model.getName());
+  }
+
+  private String getItemPropertyName(Class model, int id) {
+    return String.format("%s.%d", model.getName(), id);
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/LocalKeyValueStorage.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/LocalKeyValueStorage.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/LocalKeyValueStorage.java
index 54dcb7f..8a1952b 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/LocalKeyValueStorage.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/LocalKeyValueStorage.java
@@ -31,31 +31,39 @@ import javax.xml.ws.WebServiceException;
  * Path to file should be in 'dataworker.storagePath' parameter
  */
 public class LocalKeyValueStorage extends KeyValueStorage {
-    private final static Logger LOG =
-            LoggerFactory.getLogger(LocalKeyValueStorage.class);
+  private final static Logger LOG =
+      LoggerFactory.getLogger(LocalKeyValueStorage.class);
 
-    private PersistentConfiguration config = null;
+  private PersistentConfiguration config = null;
 
-    public LocalKeyValueStorage(ViewContext context) {
-        super(context);
-    }
+  /**
+   * Constructor
+   * @param context View Context instance
+   */
+  public LocalKeyValueStorage(ViewContext context) {
+    super(context);
+  }
 
-    @Override
-    protected synchronized PersistentConfiguration getConfig() {
-        if (config == null) {
-            String fileName = context.getProperties().get("dataworker.storagePath");
-            if (fileName == null) {
-                String msg = "dataworker.storagePath is not configured!";
-                LOG.error(msg);
-                throw new WebServiceException(msg);
-            }
-            try {
-                config = new PersistentConfiguration(fileName);
-            } catch (ConfigurationException e) {
-                e.printStackTrace();
-            }
-        }
-        return config;
+  /**
+   * Returns config instance
+   * @return config instance
+   */
+  @Override
+  protected synchronized PersistentConfiguration getConfig() {
+    if (config == null) {
+      String fileName = context.getProperties().get("dataworker.storagePath");
+      if (fileName == null) {
+        String msg = "dataworker.storagePath is not configured!";
+        LOG.error(msg);
+        throw new WebServiceException(msg);
+      }
+      try {
+        config = new PersistentConfiguration(fileName);
+      } catch (ConfigurationException e) {
+        e.printStackTrace();
+      }
     }
+    return config;
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/PersistentConfiguration.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/PersistentConfiguration.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/PersistentConfiguration.java
index 7e191f2..c3748c7 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/PersistentConfiguration.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/PersistentConfiguration.java
@@ -24,19 +24,28 @@ import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
 
 import java.io.File;
 
+/**
+ * Configuration enables all necessary options for PropertiesConfiguration:
+ * auto-save, auto-reloading, no delimiter parsing and other
+ */
 public class PersistentConfiguration extends PropertiesConfiguration {
-    public PersistentConfiguration(String fileName) throws ConfigurationException {
-        super();
+  /**
+   * Constructor
+   * @param fileName path to data file
+   * @throws ConfigurationException
+   */
+  public PersistentConfiguration(String fileName) throws ConfigurationException {
+    super();
 
-        File config = new File(fileName);
-        setFile(config);
-        this.setAutoSave(true);
-        this.setReloadingStrategy(new FileChangedReloadingStrategy());
-        this.setDelimiterParsingDisabled(true);
-        this.setListDelimiter((char) 0);
+    File config = new File(fileName);
+    setFile(config);
+    this.setAutoSave(true);
+    this.setReloadingStrategy(new FileChangedReloadingStrategy());
+    this.setDelimiterParsingDisabled(true);
+    this.setListDelimiter((char) 0);
 
-        if (config.exists()) {
-            this.load();
-        }
+    if (config.exists()) {
+      this.load();
     }
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/Storage.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/Storage.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/Storage.java
index 1507918..da9cfc3 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/Storage.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/Storage.java
@@ -24,16 +24,55 @@ import org.apache.ambari.view.pig.persistence.utils.ItemNotFound;
 
 import java.util.List;
 
+/**
+ * Object storage interface
+ */
 public interface Storage {
-    void store(Indexed obj);
+  /**
+   * Persist object to DB. It should be Indexed
+   * @param obj object to save
+   */
+  void store(Indexed obj);
 
-    <T extends Indexed> T load(Class<T> model, int id) throws ItemNotFound;
+  /**
+   * Load object
+   * @param model bean class
+   * @param id identifier
+   * @param <T> bean class
+   * @return bean instance
+   * @throws ItemNotFound thrown if item with id was not found in DB
+   */
+  <T extends Indexed> T load(Class<T> model, int id) throws ItemNotFound;
 
-    <T extends Indexed> List<T> loadAll(Class<T> model, FilteringStrategy filter);
+  /**
+   * Load all objects of given bean class
+   * @param model bean class
+   * @param filter filtering strategy (return only those objects that conform condition)
+   * @param <T> bean class
+   * @return list of filtered objects
+   */
+  <T extends Indexed> List<T> loadAll(Class<T> model, FilteringStrategy filter);
 
-    <T extends Indexed> List<T> loadAll(Class<T> model);
+  /**
+   * Load all objects of given bean class
+   * @param model bean class
+   * @param <T> bean class
+   * @return list of all objects
+   */
+  <T extends Indexed> List<T> loadAll(Class<T> model);
 
-    void delete(Class model, int id);
+  /**
+   * Delete object
+   * @param model bean class
+   * @param id identifier
+   */
+  void delete(Class model, int id);
 
-    boolean exists(Class model, int id);
+  /**
+   * Check is object exists
+   * @param model bean class
+   * @param id identifier
+   * @return true if exists
+   */
+  boolean exists(Class model, int id);
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ContextConfigurationAdapter.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ContextConfigurationAdapter.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ContextConfigurationAdapter.java
index 829905d..d49a921 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ContextConfigurationAdapter.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ContextConfigurationAdapter.java
@@ -27,224 +27,231 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
 
+/**
+ * Persistence API to Apache Configuration adapter
+ */
 public class ContextConfigurationAdapter implements Configuration {
-    private ViewContext context;
-
-    public ContextConfigurationAdapter(ViewContext context) {
-        this.context = context;
-    }
-
-    @Override
-    public Configuration subset(String prefix) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean isEmpty() {
-        return context.getInstanceData().isEmpty();
-    }
-
-    @Override
-    public boolean containsKey(String s) {
-        return context.getInstanceData().containsKey(s);
-    }
-
-    @Override
-    public void addProperty(String s, Object o) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public void setProperty(String s, Object o) {
-        context.putInstanceData(s, o.toString());
-    }
-
-    @Override
-    public void clearProperty(String key) {
-        context.removeInstanceData(key);
-    }
-
-    @Override
-    public void clear() {
-        for (String key : context.getInstanceData().keySet())
-            context.removeInstanceData(key);
-    }
-
-    @Override
-    public Object getProperty(String key) {
-        return context.getInstanceData(key);
-    }
-
-    @Override
-    public Iterator getKeys(String s) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public Iterator getKeys() {
-        return context.getInstanceData().keySet().iterator();
-    }
-
-    @Override
-    public Properties getProperties(String s) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean getBoolean(String s) {
-        return getBoolean(s, null);
-    }
-
-    @Override
-    public boolean getBoolean(String s, boolean b) {
-        return getBoolean(s, (Boolean)b);
-    }
-
-    @Override
-    public Boolean getBoolean(String s, Boolean aBoolean) {
-        String data = context.getInstanceData(s);
-        return (data != null)?Boolean.parseBoolean(data):aBoolean;
-    }
-
-    @Override
-    public byte getByte(String s) {
-        return getByte(s, null);
-    }
-
-    @Override
-    public byte getByte(String s, byte b) {
-        return getByte(s, (Byte)b);
-    }
-
-    @Override
-    public Byte getByte(String s, Byte aByte) {
-        String data = context.getInstanceData(s);
-        return (data != null)?Byte.parseByte(data):aByte;
-    }
-
-    @Override
-    public double getDouble(String s) {
-        return getDouble(s, null);
-    }
-
-    @Override
-    public double getDouble(String s, double v) {
-        return getDouble(s, (Double)v);
-    }
-
-    @Override
-    public Double getDouble(String s, Double aDouble) {
-        String data = context.getInstanceData(s);
-        return (data != null)?Double.parseDouble(data):aDouble;
-    }
-
-    @Override
-    public float getFloat(String s) {
-        return getFloat(s, null);
-    }
-
-    @Override
-    public float getFloat(String s, float v) {
-        return getFloat(s, (Float)v);
-    }
-
-    @Override
-    public Float getFloat(String s, Float aFloat) {
-        String data = context.getInstanceData(s);
-        return (data != null)?Float.parseFloat(data):aFloat;
-    }
-
-    @Override
-    public int getInt(String s) {
-        return getInteger(s, null);
-    }
-
-    @Override
-    public int getInt(String s, int i) {
-        return getInteger(s, i);
-    }
-
-    @Override
-    public Integer getInteger(String s, Integer integer) {
-        String data = context.getInstanceData(s);
-        return (data != null)?Integer.parseInt(data):integer;
-    }
-
-    @Override
-    public long getLong(String s) {
-        return getLong(s, null);
-    }
-
-    @Override
-    public long getLong(String s, long l) {
-        return getLong(s, (Long)l);
-    }
-
-    @Override
-    public Long getLong(String s, Long aLong) {
-        String data = context.getInstanceData(s);
-        return (data != null)?Long.parseLong(data):aLong;
-    }
-
-    @Override
-    public short getShort(String s) {
-        return getShort(s, null);
-    }
-
-    @Override
-    public short getShort(String s, short i) {
-        return getShort(s, (Short)i);
-    }
-
-    @Override
-    public Short getShort(String s, Short aShort) {
-        String data = context.getInstanceData(s);
-        return (data != null)?Short.parseShort(data):aShort;
-    }
-
-    @Override
-    public BigDecimal getBigDecimal(String s) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public BigDecimal getBigDecimal(String s, BigDecimal bigDecimal) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public BigInteger getBigInteger(String s) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public BigInteger getBigInteger(String s, BigInteger bigInteger) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public String getString(String s) {
-        return context.getInstanceData(s);
-    }
-
-    @Override
-    public String getString(String s, String s2) {
-        String data = getString(s);
-        return (data != null)?data:s2;
-    }
-
-    @Override
-    public String[] getStringArray(String s) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public List getList(String s) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public List getList(String s, List list) {
-        throw new UnsupportedOperationException();
-    }
+  private ViewContext context;
+
+  /**
+   * Constructor of adapter
+   * @param context View Context
+   */
+  public ContextConfigurationAdapter(ViewContext context) {
+    this.context = context;
+  }
+
+  @Override
+  public Configuration subset(String prefix) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public boolean isEmpty() {
+    return context.getInstanceData().isEmpty();
+  }
+
+  @Override
+  public boolean containsKey(String s) {
+    return context.getInstanceData().containsKey(s);
+  }
+
+  @Override
+  public void addProperty(String s, Object o) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void setProperty(String s, Object o) {
+    context.putInstanceData(s, o.toString());
+  }
+
+  @Override
+  public void clearProperty(String key) {
+    context.removeInstanceData(key);
+  }
+
+  @Override
+  public void clear() {
+    for (String key : context.getInstanceData().keySet())
+      context.removeInstanceData(key);
+  }
+
+  @Override
+  public Object getProperty(String key) {
+    return context.getInstanceData(key);
+  }
+
+  @Override
+  public Iterator getKeys(String s) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public Iterator getKeys() {
+    return context.getInstanceData().keySet().iterator();
+  }
+
+  @Override
+  public Properties getProperties(String s) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public boolean getBoolean(String s) {
+    return getBoolean(s, null);
+  }
+
+  @Override
+  public boolean getBoolean(String s, boolean b) {
+    return getBoolean(s, (Boolean)b);
+  }
+
+  @Override
+  public Boolean getBoolean(String s, Boolean aBoolean) {
+    String data = context.getInstanceData(s);
+    return (data != null)?Boolean.parseBoolean(data):aBoolean;
+  }
+
+  @Override
+  public byte getByte(String s) {
+    return getByte(s, null);
+  }
+
+  @Override
+  public byte getByte(String s, byte b) {
+    return getByte(s, (Byte)b);
+  }
+
+  @Override
+  public Byte getByte(String s, Byte aByte) {
+    String data = context.getInstanceData(s);
+    return (data != null)?Byte.parseByte(data):aByte;
+  }
+
+  @Override
+  public double getDouble(String s) {
+    return getDouble(s, null);
+  }
+
+  @Override
+  public double getDouble(String s, double v) {
+    return getDouble(s, (Double)v);
+  }
+
+  @Override
+  public Double getDouble(String s, Double aDouble) {
+    String data = context.getInstanceData(s);
+    return (data != null)?Double.parseDouble(data):aDouble;
+  }
+
+  @Override
+  public float getFloat(String s) {
+    return getFloat(s, null);
+  }
+
+  @Override
+  public float getFloat(String s, float v) {
+    return getFloat(s, (Float)v);
+  }
+
+  @Override
+  public Float getFloat(String s, Float aFloat) {
+    String data = context.getInstanceData(s);
+    return (data != null)?Float.parseFloat(data):aFloat;
+  }
+
+  @Override
+  public int getInt(String s) {
+    return getInteger(s, null);
+  }
+
+  @Override
+  public int getInt(String s, int i) {
+    return getInteger(s, i);
+  }
+
+  @Override
+  public Integer getInteger(String s, Integer integer) {
+    String data = context.getInstanceData(s);
+    return (data != null)?Integer.parseInt(data):integer;
+  }
+
+  @Override
+  public long getLong(String s) {
+    return getLong(s, null);
+  }
+
+  @Override
+  public long getLong(String s, long l) {
+    return getLong(s, (Long)l);
+  }
+
+  @Override
+  public Long getLong(String s, Long aLong) {
+    String data = context.getInstanceData(s);
+    return (data != null)?Long.parseLong(data):aLong;
+  }
+
+  @Override
+  public short getShort(String s) {
+    return getShort(s, null);
+  }
+
+  @Override
+  public short getShort(String s, short i) {
+    return getShort(s, (Short)i);
+  }
+
+  @Override
+  public Short getShort(String s, Short aShort) {
+    String data = context.getInstanceData(s);
+    return (data != null)?Short.parseShort(data):aShort;
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String s) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String s, BigDecimal bigDecimal) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public BigInteger getBigInteger(String s) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public BigInteger getBigInteger(String s, BigInteger bigInteger) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public String getString(String s) {
+    return context.getInstanceData(s);
+  }
+
+  @Override
+  public String getString(String s, String s2) {
+    String data = getString(s);
+    return (data != null)?data:s2;
+  }
+
+  @Override
+  public String[] getStringArray(String s) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public List getList(String s) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public List getList(String s, List list) {
+    throw new UnsupportedOperationException();
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/FilteringStrategy.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/FilteringStrategy.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/FilteringStrategy.java
index 75a0953..acc247d 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/FilteringStrategy.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/FilteringStrategy.java
@@ -18,6 +18,14 @@
 
 package org.apache.ambari.view.pig.persistence.utils;
 
+/**
+ * Filtering strategy for stored objects
+ */
 public interface FilteringStrategy {
-    boolean is_conform(Indexed item);
+  /**
+   * Check whether item conforms chosen filter or not
+   * @param item item to check
+   * @return true if item conforms this filter
+   */
+  boolean isConform(Indexed item);
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Indexed.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Indexed.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Indexed.java
index cbe2016..110260d 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Indexed.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Indexed.java
@@ -18,7 +18,19 @@
 
 package org.apache.ambari.view.pig.persistence.utils;
 
+/**
+ * Interface to represent item with identifier
+ */
 public interface Indexed {
-    String getId();
-    void setId(String id);
+  /**
+   * Get the ID
+   * @return ID
+   */
+  String getId();
+
+  /**
+   * Set ID
+   * @param id ID
+   */
+  void setId(String id);
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ItemNotFound.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ItemNotFound.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ItemNotFound.java
index df56036..00f4d35 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ItemNotFound.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/ItemNotFound.java
@@ -18,5 +18,8 @@
 
 package org.apache.ambari.view.pig.persistence.utils;
 
+/**
+ * Thrown when item was not found in DB
+ */
 public class ItemNotFound extends Exception {
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/OnlyOwnersFilteringStrategy.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/OnlyOwnersFilteringStrategy.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/OnlyOwnersFilteringStrategy.java
index 7964cf7..46801f1 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/OnlyOwnersFilteringStrategy.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/OnlyOwnersFilteringStrategy.java
@@ -19,15 +19,15 @@
 package org.apache.ambari.view.pig.persistence.utils;
 
 public class OnlyOwnersFilteringStrategy implements FilteringStrategy {
-    private final String username;
+  private final String username;
 
-    public OnlyOwnersFilteringStrategy(String username) {
-        this.username = username;
-    }
+  public OnlyOwnersFilteringStrategy(String username) {
+    this.username = username;
+  }
 
-    @Override
-    public boolean is_conform(Indexed item) {
-        Owned object = (Owned) item;
-        return object.getOwner().compareTo(username) == 0;
-    }
+  @Override
+  public boolean isConform(Indexed item) {
+    Owned object = (Owned) item;
+    return object.getOwner().compareTo(username) == 0;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Owned.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Owned.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Owned.java
index 30918a2..352f490 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Owned.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/Owned.java
@@ -18,7 +18,19 @@
 
 package org.apache.ambari.view.pig.persistence.utils;
 
+/**
+ * Interface to represent item with owner
+ */
 public interface Owned {
-    String getOwner();
-    void setOwner(String owner);
+  /**
+   * Get the owner
+   * @return owner
+   */
+  String getOwner();
+
+  /**
+   * Set owner
+   * @param owner owner
+   */
+  void setOwner(String owner);
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/StorageUtil.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/StorageUtil.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/StorageUtil.java
index 0c7b25b..245ad54 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/StorageUtil.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/persistence/utils/StorageUtil.java
@@ -25,29 +25,46 @@ import org.apache.ambari.view.pig.persistence.Storage;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * Storage factory, creates storage of Local or Persistence API type.
+ * Type depends on context configuration: if "dataworker.storagePath" is set,
+ * storage of Local type will be created.  Otherwise, Persistence API will be used.
+ *
+ * Storage is singleton.
+ */
 public class StorageUtil {
-    private static Storage storageInstance = null;
+  private static Storage storageInstance = null;
 
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(StorageUtil.class);
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(StorageUtil.class);
 
-    public synchronized static Storage getStorage(ViewContext context) {
-        if (storageInstance == null) {
-            String fileName = context.getProperties().get("dataworker.storagePath");
-            if (fileName != null) {
-                LOG.debug("Using local storage in " + fileName + " to store data");
-                // If specifed, use LocalKeyValueStorage - key-value file based storage
-                storageInstance = new LocalKeyValueStorage(context);
-            } else {
-                LOG.debug("Using Persistence API to store data");
-                // If not specifed, use ambari-views Persistence API
-                storageInstance = new InstanceKeyValueStorage(context);
-            }
-        }
-        return storageInstance;
+  /**
+   * Get storage instance. If one is not created, creates instance.
+   * @param context View Context instance
+   * @return storage instance
+   */
+  public synchronized static Storage getStorage(ViewContext context) {
+    if (storageInstance == null) {
+      String fileName = context.getProperties().get("dataworker.storagePath");
+      if (fileName != null) {
+        LOG.debug("Using local storage in " + fileName + " to store data");
+        // If specifed, use LocalKeyValueStorage - key-value file based storage
+        storageInstance = new LocalKeyValueStorage(context);
+      } else {
+        LOG.debug("Using Persistence API to store data");
+        // If not specifed, use ambari-views Persistence API
+        storageInstance = new InstanceKeyValueStorage(context);
+      }
     }
+    return storageInstance;
+  }
 
-    public static void setStorage(Storage storage) {
-        storageInstance = storage;
-    }
+  /**
+   * Set storage to use across all application.
+   * Used in unit tests.
+   * @param storage storage instance
+   */
+  public static void setStorage(Storage storage) {
+    storageInstance = storage;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/CRUDResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/CRUDResourceManager.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/CRUDResourceManager.java
index 9319d3b..b4a2059 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/CRUDResourceManager.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/CRUDResourceManager.java
@@ -32,60 +32,92 @@ import java.util.List;
  * @param <T> Data type with ID
  */
 abstract public class CRUDResourceManager<T extends Indexed> {
-    private Storage storage = null;
+  private Storage storage = null;
 
-    protected final Class<T> resourceClass;
+  protected final Class<T> resourceClass;
 
-    public CRUDResourceManager(Class<T> responseClass) {
-        this.resourceClass = responseClass;
-    }
-    // CRUD operations
+  /**
+   * Constructor
+   * @param responseClass model class
+   */
+  public CRUDResourceManager(Class<T> responseClass) {
+    this.resourceClass = responseClass;
+  }
+  // CRUD operations
 
-    public T create(T object) {
-        object.setId(null);
-        return this.save(object);
-    }
+  /**
+   * Create operation
+   * @param object object
+   * @return model object
+   */
+  public T create(T object) {
+    object.setId(null);
+    return this.save(object);
+  }
 
-    public T read(String id) throws ItemNotFound {
-        T object = null;
-        object = getPigStorage().load(this.resourceClass, Integer.parseInt(id));
-        if (!checkPermissions(object))
-            throw new ItemNotFound();
-        return object;
-    }
+  /**
+   * Read operation
+   * @param id identifier
+   * @return model object
+   * @throws ItemNotFound
+   */
+  public T read(String id) throws ItemNotFound {
+    T object = null;
+    object = getPigStorage().load(this.resourceClass, Integer.parseInt(id));
+    if (!checkPermissions(object))
+      throw new ItemNotFound();
+    return object;
+  }
 
-    public List<T> readAll(FilteringStrategy filteringStrategy) {
-        return getPigStorage().loadAll(this.resourceClass, filteringStrategy);
-    }
+  /**
+   * Read all objects
+   * @param filteringStrategy filtering strategy
+   * @return list of filtered objects
+   */
+  public List<T> readAll(FilteringStrategy filteringStrategy) {
+    return getPigStorage().loadAll(this.resourceClass, filteringStrategy);
+  }
 
-    public T update(T newObject, String id) throws ItemNotFound {
-        newObject.setId(id);
-        this.save(newObject);
-        return newObject;
-    }
+  /**
+   * Update operation
+   * @param newObject new object
+   * @param id identifier of previous object
+   * @return model object
+   * @throws ItemNotFound
+   */
+  public T update(T newObject, String id) throws ItemNotFound {
+    newObject.setId(id);
+    this.save(newObject);
+    return newObject;
+  }
 
-    public void delete(String resourceId) throws ItemNotFound {
-        int id = Integer.parseInt(resourceId);
-        if (!getPigStorage().exists(this.resourceClass, id)) {
-            throw new ItemNotFound();
-        }
-        getPigStorage().delete(this.resourceClass, id);
+  /**
+   * Delete operation
+   * @param resourceId object identifier
+   * @throws ItemNotFound
+   */
+  public void delete(String resourceId) throws ItemNotFound {
+    int id = Integer.parseInt(resourceId);
+    if (!getPigStorage().exists(this.resourceClass, id)) {
+      throw new ItemNotFound();
     }
+    getPigStorage().delete(this.resourceClass, id);
+  }
 
-    // UTILS
+  // UTILS
 
-    protected T save(T object) {
-        getPigStorage().store(object);
-        return object;
-    }
+  protected T save(T object) {
+    getPigStorage().store(object);
+    return object;
+  }
 
-    protected Storage getPigStorage() {
-        if (storage == null) {
-            storage = StorageUtil.getStorage(getContext());
-        }
-        return storage;
+  protected Storage getPigStorage() {
+    if (storage == null) {
+      storage = StorageUtil.getStorage(getContext());
     }
+    return storage;
+  }
 
-    protected abstract boolean checkPermissions(T object);
-    protected abstract ViewContext getContext();
+  protected abstract boolean checkPermissions(T object);
+  protected abstract ViewContext getContext();
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/PersonalCRUDResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/PersonalCRUDResourceManager.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/PersonalCRUDResourceManager.java
index ffccfd9..650d9a2 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/PersonalCRUDResourceManager.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/PersonalCRUDResourceManager.java
@@ -29,53 +29,62 @@ import java.util.concurrent.Callable;
  * @param <T> Data type with ID and Owner
  */
 public class PersonalCRUDResourceManager<T extends PersonalResource> extends CRUDResourceManager<T> {
-    protected ViewContext context;
-    protected boolean ignorePermissions = false;
+  protected ViewContext context;
+  protected boolean ignorePermissions = false;
 
-    public PersonalCRUDResourceManager(Class<T> responseClass, ViewContext context) {
-        super(responseClass);
-        this.context = context;
-    }
-
-    public T update(T newObject, String id) throws ItemNotFound {
-        T object = getPigStorage().load(this.resourceClass, Integer.parseInt(id));
-        if (object.getOwner().compareTo(this.context.getUsername()) != 0) {
-            throw new ItemNotFound();
-        }
+  /**
+   * Constructor
+   * @param responseClass model class
+   * @param context View Context instance
+   */
+  public PersonalCRUDResourceManager(Class<T> responseClass, ViewContext context) {
+    super(responseClass);
+    this.context = context;
+  }
 
-        newObject.setOwner(this.context.getUsername());
-        return super.update(newObject, id);
+  @Override
+  public T update(T newObject, String id) throws ItemNotFound {
+    T object = getPigStorage().load(this.resourceClass, Integer.parseInt(id));
+    if (object.getOwner().compareTo(this.context.getUsername()) != 0) {
+      throw new ItemNotFound();
     }
 
-    public T save(T object) {
-        object.setOwner(this.context.getUsername());
-        return super.save(object);
-    }
+    newObject.setOwner(this.context.getUsername());
+    return super.update(newObject, id);
+  }
 
-    @Override
-    protected boolean checkPermissions(T object) {
-        if (ignorePermissions)
-            return true;
-        return object.getOwner().compareTo(this.context.getUsername()) == 0;
-    }
+  @Override
+  public T save(T object) {
+    object.setOwner(this.context.getUsername());
+    return super.save(object);
+  }
 
-    @Override
-    protected ViewContext getContext() {
-        return context;
-    }
+  @Override
+  protected boolean checkPermissions(T object) {
+    if (ignorePermissions)
+      return true;
+    return object.getOwner().compareTo(this.context.getUsername()) == 0;
+  }
 
-    public <T> T ignorePermissions(String fakeUser, Callable<T> actions) throws Exception {
-        ignorePermissions = true;
-        T result;
-        try {
-            result = actions.call();
-        } finally {
-            ignorePermissions = false;
-        }
-        return result;
-    }
+  @Override
+  protected ViewContext getContext() {
+    return context;
+  }
 
-    public <T> T ignorePermissions(Callable<T> actions) throws Exception {
-        return ignorePermissions("", actions);
+  /**
+   * Execute action ignoring objects owner
+   * @param actions callable to execute
+   * @return value returned from actions
+   * @throws Exception
+   */
+  public <T> T ignorePermissions(Callable<T> actions) throws Exception {
+    ignorePermissions = true;
+    T result;
+    try {
+      result = actions.call();
+    } finally {
+      ignorePermissions = false;
     }
+    return result;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/SharedCRUDResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/SharedCRUDResourceManager.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/SharedCRUDResourceManager.java
index be89d36..3b7a173 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/SharedCRUDResourceManager.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/SharedCRUDResourceManager.java
@@ -26,20 +26,25 @@ import org.apache.ambari.view.pig.persistence.utils.Indexed;
  * @param <T> Data type with ID
  */
 public class SharedCRUDResourceManager<T extends Indexed> extends CRUDResourceManager<T> {
-    protected ViewContext context;
+  protected ViewContext context;
 
-    public SharedCRUDResourceManager(Class<T> responseClass, ViewContext context) {
-        super(responseClass);
-        this.context = context;
-    }
+  /**
+   * Constructor
+   * @param responseClass model class
+   * @param context View Context instance
+   */
+  public SharedCRUDResourceManager(Class<T> responseClass, ViewContext context) {
+    super(responseClass);
+    this.context = context;
+  }
 
-    @Override
-    protected boolean checkPermissions(T object) {
-        return true; //everyone has permission
-    }
+  @Override
+  protected boolean checkPermissions(T object) {
+    return true; //everyone has permission
+  }
 
-    @Override
-    protected ViewContext getContext() {
-        return context;
-    }
+  @Override
+  protected ViewContext getContext() {
+    return context;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileResource.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileResource.java
index 9ae45c7..ef8b2ad 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileResource.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileResource.java
@@ -18,10 +18,53 @@
 
 package org.apache.ambari.view.pig.resources.files;
 
+/**
+ * File bean
+ */
 public class FileResource {
-    public String filePath;
-    public String fileContent;
-    public boolean hasNext;
-    public long page;
-    public long pageCount;
+  private String filePath;
+  private String fileContent;
+  private boolean hasNext;
+  private long page;
+  private long pageCount;
+
+  public String getFilePath() {
+    return filePath;
+  }
+
+  public void setFilePath(String filePath) {
+    this.filePath = filePath;
+  }
+
+  public String getFileContent() {
+    return fileContent;
+  }
+
+  public void setFileContent(String fileContent) {
+    this.fileContent = fileContent;
+  }
+
+  public boolean isHasNext() {
+    return hasNext;
+  }
+
+  public void setHasNext(boolean hasNext) {
+    this.hasNext = hasNext;
+  }
+
+  public long getPage() {
+    return page;
+  }
+
+  public void setPage(long page) {
+    this.page = page;
+  }
+
+  public long getPageCount() {
+    return pageCount;
+  }
+
+  public void setPageCount(long pageCount) {
+    this.pageCount = pageCount;
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileService.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileService.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileService.java
index c36c582..292c1be 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileService.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/files/FileService.java
@@ -47,95 +47,98 @@ import java.io.IOException;
  *      update file content
  */
 public class FileService extends BaseService {
-    @Inject
-    ViewResourceHandler handler;
+  @Inject
+  ViewResourceHandler handler;
 
-    protected final static Logger LOG =
-            LoggerFactory.getLogger(FileService.class);
+  protected final static Logger LOG =
+      LoggerFactory.getLogger(FileService.class);
 
-    /**
-     * Get single item
-     */
-    @GET
-    @Path("{filePath:.*}")
-    @Produces(MediaType.APPLICATION_JSON)
-    public Response getFile(@PathParam("filePath") String filePath, @QueryParam("page") Long page) throws IOException, InterruptedException {
-        LOG.debug("Reading file " + filePath);
-        try {
-            FilePaginator paginator = new FilePaginator(filePath, context);
+  /**
+   * Get single item
+   */
+  @GET
+  @Path("{filePath:.*}")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response getFile(@PathParam("filePath") String filePath, @QueryParam("page") Long page) throws IOException, InterruptedException {
+    LOG.debug("Reading file " + filePath);
+    try {
+      FilePaginator paginator = new FilePaginator(filePath, context);
 
-            if (page == null)
-                page = 0L;
+      if (page == null)
+        page = 0L;
 
-            FileResource file = new FileResource();
-            file.filePath = filePath;
-            file.fileContent = paginator.readPage(page);
-            file.hasNext = paginator.pageCount() > page + 1;
-            file.page = page;
-            file.pageCount = paginator.pageCount();
+      FileResource file = new FileResource();
+      file.setFilePath(filePath);
+      file.setFileContent(paginator.readPage(page));
+      file.setHasNext(paginator.pageCount() > page + 1);
+      file.setPage(page);
+      file.setPageCount(paginator.pageCount());
 
-            JSONObject object = new JSONObject();
-            object.put("file", file);
-            return Response.ok(object).status(200).build();
-        } catch (FileNotFoundException e) {
-            return notFoundResponse(e.toString());
-        } catch (IllegalArgumentException e) {
-            return badRequestResponse(e.toString());
-        }
+      JSONObject object = new JSONObject();
+      object.put("file", file);
+      return Response.ok(object).status(200).build();
+    } catch (FileNotFoundException e) {
+      return notFoundResponse(e.toString());
+    } catch (IllegalArgumentException e) {
+      return badRequestResponse(e.toString());
     }
+  }
 
-    /**
-     * Delete single item
-     */
-    @DELETE
-    @Path("{filePath:.*}")
-    public Response deleteFile(@PathParam("filePath") String filePath) throws IOException, InterruptedException {
-        LOG.debug("Deleting file " + filePath);
-        if (getHdfsApi().delete(filePath, false)) {
-            return Response.status(204).build();
-        }
-        return notFoundResponse("FileSystem.delete returned false");
+  /**
+   * Delete single item
+   */
+  @DELETE
+  @Path("{filePath:.*}")
+  public Response deleteFile(@PathParam("filePath") String filePath) throws IOException, InterruptedException {
+    LOG.debug("Deleting file " + filePath);
+    if (getHdfsApi().delete(filePath, false)) {
+      return Response.status(204).build();
     }
+    return notFoundResponse("FileSystem.delete returned false");
+  }
 
-    /**
-     * Update item
-     */
-    @PUT
-    @Path("{filePath:.*}")
-    @Consumes(MediaType.APPLICATION_JSON)
-    public Response updateFile(FileResourceRequest request,
-                               @PathParam("filePath") String filePath) throws IOException, InterruptedException {
-        LOG.debug("Rewriting file " + filePath);
-        FSDataOutputStream output = getHdfsApi().create(filePath, true);
-        output.writeBytes(request.file.fileContent);
-        output.close();
-        return Response.status(204).build();
-    }
+  /**
+   * Update item
+   */
+  @PUT
+  @Path("{filePath:.*}")
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response updateFile(FileResourceRequest request,
+                             @PathParam("filePath") String filePath) throws IOException, InterruptedException {
+    LOG.debug("Rewriting file " + filePath);
+    FSDataOutputStream output = getHdfsApi().create(filePath, true);
+    output.writeBytes(request.file.getFileContent());
+    output.close();
+    return Response.status(204).build();
+  }
 
-    /**
-     * Create script
-     */
-    @POST
-    @Consumes(MediaType.APPLICATION_JSON)
-    public Response createFile(FileResourceRequest request,
-                               @Context HttpServletResponse response, @Context UriInfo ui)
-            throws IOException, InterruptedException {
-        LOG.debug("Creating file " + request.file.filePath);
-        try {
-            FSDataOutputStream output = getHdfsApi().create(request.file.filePath, false);
-            if (request.file.fileContent != null) {
-                output.writeBytes(request.file.fileContent);
-            }
-            output.close();
-        } catch (FileAlreadyExistsException e) {
-            return badRequestResponse(e.toString());
-        }
-        response.setHeader("Location",
-                String.format("%s/%s", ui.getAbsolutePath().toString(), request.file.filePath));
-        return Response.status(204).build();
+  /**
+   * Create script
+   */
+  @POST
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response createFile(FileResourceRequest request,
+                             @Context HttpServletResponse response, @Context UriInfo ui)
+      throws IOException, InterruptedException {
+    LOG.debug("Creating file " + request.file.getFilePath());
+    try {
+      FSDataOutputStream output = getHdfsApi().create(request.file.getFilePath(), false);
+      if (request.file.getFileContent() != null) {
+        output.writeBytes(request.file.getFileContent());
+      }
+      output.close();
+    } catch (FileAlreadyExistsException e) {
+      return badRequestResponse(e.toString());
     }
+    response.setHeader("Location",
+        String.format("%s/%s", ui.getAbsolutePath().toString(), request.file.getFilePath()));
+    return Response.status(204).build();
+  }
 
-    public static class FileResourceRequest {
-        public FileResource file;
-    }
+  /**
+   * Wrapper object for json mapping
+   */
+  public static class FileResourceRequest {
+    public FileResource file;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c64261e2/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceManager.java
----------------------------------------------------------------------
diff --git a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceManager.java b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceManager.java
index 67a038b..abc2ddd 100644
--- a/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceManager.java
+++ b/contrib/views/pig/src/main/java/org/apache/ambari/view/pig/resources/jobs/JobResourceManager.java
@@ -44,237 +44,257 @@ import java.util.regex.Pattern;
  * CRUD overridden to support
  */
 public class JobResourceManager extends PersonalCRUDResourceManager<PigJob> {
-    protected TempletonApi api;
+  protected TempletonApi api;
 
-    private final static Logger LOG =
-            LoggerFactory.getLogger(JobResourceManager.class);
+  private final static Logger LOG =
+      LoggerFactory.getLogger(JobResourceManager.class);
 
-    public JobResourceManager(ViewContext context) {
-        super(PigJob.class, context);
-        setupPolling();
-    }
+  /**
+   * Constructor
+   * @param context View Context instance
+   */
+  public JobResourceManager(ViewContext context) {
+    super(PigJob.class, context);
+    setupPolling();
+  }
 
-    public TempletonApi getTempletonApi() {
-        if (api == null) {
-            api = new TempletonApi(context.getProperties().get("dataworker.templeton_url"),
-                    getTempletonUser(), getTempletonUser(), context);
-        }
-        return api;
+  /**
+   * Get templeton api business delegate
+   * @return templeton api business delegate
+   */
+  public TempletonApi getTempletonApi() {
+    if (api == null) {
+      api = new TempletonApi(context.getProperties().get("dataworker.templeton_url"),
+          getTempletonUser(), getTempletonUser(), context);
     }
+    return api;
+  }
 
-    public void setTempletonApi(TempletonApi api) {
-        this.api = api;
-    }
+  /**
+   * Set templeton api business delegate
+   * @param api templeton api business delegate
+   */
+  public void setTempletonApi(TempletonApi api) {
+    this.api = api;
+  }
 
-    private void setupPolling() {
-        List<PigJob> notCompleted = this.readAll(new FilteringStrategy() {
-            @Override
-            public boolean is_conform(Indexed item) {
-                PigJob job = (PigJob) item;
-                return job.isInProgress();
-            }
-        });
+  private void setupPolling() {
+    List<PigJob> notCompleted = this.readAll(new FilteringStrategy() {
+      @Override
+      public boolean isConform(Indexed item) {
+        PigJob job = (PigJob) item;
+        return job.isInProgress();
+      }
+    });
 
-        for(PigJob job : notCompleted) {
-            JobPolling.pollJob(context, job);
-        }
+    for(PigJob job : notCompleted) {
+      JobPolling.pollJob(context, job);
     }
+  }
 
-    @Override
-    public PigJob create(PigJob object) {
-        object.setStatus(PigJob.Status.SUBMITTING);
-        PigJob job = super.create(object);
-        LOG.debug("Submitting job...");
+  @Override
+  public PigJob create(PigJob object) {
+    object.setStatus(PigJob.Status.SUBMITTING);
+    PigJob job = super.create(object);
+    LOG.debug("Submitting job...");
 
-        try {
-            submitJob(object);
-        } catch (RuntimeException e) {
-            object.setStatus(PigJob.Status.SUBMIT_FAILED);
-            save(object);
-            LOG.debug("Job submit FAILED");
-            throw e;
-        }
-        LOG.debug("Job submit OK");
-        object.setStatus(PigJob.Status.SUBMITTED);
-        save(object);
-        return job;
+    try {
+      submitJob(object);
+    } catch (RuntimeException e) {
+      object.setStatus(PigJob.Status.SUBMIT_FAILED);
+      save(object);
+      LOG.debug("Job submit FAILED");
+      throw e;
     }
+    LOG.debug("Job submit OK");
+    object.setStatus(PigJob.Status.SUBMITTED);
+    save(object);
+    return job;
+  }
 
-    public void killJob(PigJob object) throws IOException {
-        LOG.debug("Killing job...");
+  /**
+   * Kill Templeton Job
+   * @param object job object
+   * @throws IOException network error
+   */
+  public void killJob(PigJob object) throws IOException {
+    LOG.debug("Killing job...");
 
-        try {
-            getTempletonApi().killJob(object.getJobId());
-        } catch (IOException e) {
-            LOG.debug("Job kill FAILED");
-            throw e;
-        }
-        LOG.debug("Job kill OK");
+    try {
+      getTempletonApi().killJob(object.getJobId());
+    } catch (IOException e) {
+      LOG.debug("Job kill FAILED");
+      throw e;
     }
+    LOG.debug("Job kill OK");
+  }
 
-    /**
-     * Running job
-     * @param job job bean
-     */
-    private void submitJob(PigJob job) {
-        String date = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss").format(new Date());
-        String statusdir = String.format(context.getProperties().get("dataworker.pigJobsPath") +
-                "/%s/%s_%s", getTempletonUser(),
-                job.getTitle().toLowerCase().replaceAll("[^a-zA-Z0-9 ]+", "").replace(" ", "_"),
-                date);
+  /**
+   * Running job
+   * @param job job bean
+   */
+  private void submitJob(PigJob job) {
+    String date = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss").format(new Date());
+    String statusdir = String.format(context.getProperties().get("dataworker.pigJobsPath") +
+            "/%s/%s_%s", getTempletonUser(),
+        job.getTitle().toLowerCase().replaceAll("[^a-zA-Z0-9 ]+", "").replace(" ", "_"),
+        date);
 
-        String newPigScriptPath = statusdir + "/script.pig";
-        String newSourceFilePath = statusdir + "/source.pig";
-        String newPythonScriptPath = statusdir + "/udf.py";
-        String templetonParamsFilePath = statusdir + "/params";
-        try {
-            // additional file can be passed to copy into work directory
-            if (job.getSourceFileContent() != null && !job.getSourceFileContent().isEmpty()) {
-                String sourceFileContent = job.getSourceFileContent();
-                job.setSourceFileContent(null); // we should not store content in DB
-                save(job);
+    String newPigScriptPath = statusdir + "/script.pig";
+    String newSourceFilePath = statusdir + "/source.pig";
+    String newPythonScriptPath = statusdir + "/udf.py";
+    String templetonParamsFilePath = statusdir + "/params";
+    try {
+      // additional file can be passed to copy into work directory
+      if (job.getSourceFileContent() != null && !job.getSourceFileContent().isEmpty()) {
+        String sourceFileContent = job.getSourceFileContent();
+        job.setSourceFileContent(null); // we should not store content in DB
+        save(job);
 
-                FSDataOutputStream stream = BaseService.getHdfsApi(context).create(newSourceFilePath, true);
-                stream.writeBytes(sourceFileContent);
-                stream.close();
-            } else {
-                if (job.getSourceFile() != null && !job.getSourceFile().isEmpty()) {
-                    // otherwise, just copy original file
-                    if (!BaseService.getHdfsApi(context).copy(job.getSourceFile(), newSourceFilePath)) {
-                        throw new WebServiceException("Can't copy source file from " + job.getSourceFile() +
-                                " to " + newPigScriptPath);
-                    }
-                }
-            }
-        } catch (IOException e) {
-            throw new WebServiceException("Can't create/copy source file: " + e.toString(), e);
-        } catch (InterruptedException e) {
-            throw new WebServiceException("Can't create/copy source file: " + e.toString(), e);
+        FSDataOutputStream stream = BaseService.getHdfsApi(context).create(newSourceFilePath, true);
+        stream.writeBytes(sourceFileContent);
+        stream.close();
+      } else {
+        if (job.getSourceFile() != null && !job.getSourceFile().isEmpty()) {
+          // otherwise, just copy original file
+          if (!BaseService.getHdfsApi(context).copy(job.getSourceFile(), newSourceFilePath)) {
+            throw new WebServiceException("Can't copy source file from " + job.getSourceFile() +
+                " to " + newPigScriptPath);
+          }
         }
+      }
+    } catch (IOException e) {
+      throw new WebServiceException("Can't create/copy source file: " + e.toString(), e);
+    } catch (InterruptedException e) {
+      throw new WebServiceException("Can't create/copy source file: " + e.toString(), e);
+    }
 
-        try {
-            // content can be passed from front-end with substituted arguments
-            if (job.getForcedContent() != null && !job.getForcedContent().isEmpty()) {
-                String forcedContent = job.getForcedContent();
-                // variable for sourceFile can be passed from front-ent
-                forcedContent = forcedContent.replace("${sourceFile}",
-                        context.getProperties().get("dataworker.defaultFs") + newSourceFilePath);
-                job.setForcedContent(null); // we should not store content in DB
-                save(job);
-
-                FSDataOutputStream stream = BaseService.getHdfsApi(context).create(newPigScriptPath, true);
-                stream.writeBytes(forcedContent);
-                stream.close();
-            } else {
-                // otherwise, just copy original file
-                if (!BaseService.getHdfsApi(context).copy(job.getPigScript(), newPigScriptPath)) {
-                    throw new WebServiceException("Can't copy pig script file from " + job.getPigScript() +
-                                                    " to " + newPigScriptPath);
-                }
-            }
-        } catch (IOException e) {
-            throw new WebServiceException("Can't create/copy pig script file: " + e.toString(), e);
-        } catch (InterruptedException e) {
-            throw new WebServiceException("Can't create/copy pig script file: " + e.toString(), e);
-        }
+    try {
+      // content can be passed from front-end with substituted arguments
+      if (job.getForcedContent() != null && !job.getForcedContent().isEmpty()) {
+        String forcedContent = job.getForcedContent();
+        // variable for sourceFile can be passed from front-ent
+        forcedContent = forcedContent.replace("${sourceFile}",
+            context.getProperties().get("dataworker.defaultFs") + newSourceFilePath);
+        job.setForcedContent(null); // we should not store content in DB
+        save(job);
 
-        if (job.getPythonScript() != null && !job.getPythonScript().isEmpty()) {
-            try {
-                if (!BaseService.getHdfsApi(context).copy(job.getPythonScript(), newPythonScriptPath)) {
-                    throw new WebServiceException("Can't copy python udf script file from " + job.getPythonScript() +
-                            " to " + newPythonScriptPath);
-                }
-            } catch (IOException e) {
-                throw new WebServiceException("Can't create/copy python udf file: " + e.toString(), e);
-            } catch (InterruptedException e) {
-                throw new WebServiceException("Can't create/copy python udf file: " + e.toString(), e);
-            }
+        FSDataOutputStream stream = BaseService.getHdfsApi(context).create(newPigScriptPath, true);
+        stream.writeBytes(forcedContent);
+        stream.close();
+      } else {
+        // otherwise, just copy original file
+        if (!BaseService.getHdfsApi(context).copy(job.getPigScript(), newPigScriptPath)) {
+          throw new WebServiceException("Can't copy pig script file from " + job.getPigScript() +
+              " to " + newPigScriptPath);
         }
+      }
+    } catch (IOException e) {
+      throw new WebServiceException("Can't create/copy pig script file: " + e.toString(), e);
+    } catch (InterruptedException e) {
+      throw new WebServiceException("Can't create/copy pig script file: " + e.toString(), e);
+    }
 
-        try {
-            FSDataOutputStream stream = BaseService.getHdfsApi(context).create(templetonParamsFilePath, true);
-            if (job.getTempletonArguments() != null) {
-                stream.writeBytes(job.getTempletonArguments());
-            }
-            stream.close();
-        } catch (IOException e) {
-            throw new WebServiceException("Can't create params file: " + e.toString(), e);
-        } catch (InterruptedException e) {
-            throw new WebServiceException("Can't create params file: " + e.toString(), e);
+    if (job.getPythonScript() != null && !job.getPythonScript().isEmpty()) {
+      try {
+        if (!BaseService.getHdfsApi(context).copy(job.getPythonScript(), newPythonScriptPath)) {
+          throw new WebServiceException("Can't copy python udf script file from " + job.getPythonScript() +
+              " to " + newPythonScriptPath);
         }
-        job.setPigScript(newPigScriptPath);
+      } catch (IOException e) {
+        throw new WebServiceException("Can't create/copy python udf file: " + e.toString(), e);
+      } catch (InterruptedException e) {
+        throw new WebServiceException("Can't create/copy python udf file: " + e.toString(), e);
+      }
+    }
 
-        job.setStatusDir(statusdir);
-        job.setDateStarted(System.currentTimeMillis() / 1000L);
+    try {
+      FSDataOutputStream stream = BaseService.getHdfsApi(context).create(templetonParamsFilePath, true);
+      if (job.getTempletonArguments() != null) {
+        stream.writeBytes(job.getTempletonArguments());
+      }
+      stream.close();
+    } catch (IOException e) {
+      throw new WebServiceException("Can't create params file: " + e.toString(), e);
+    } catch (InterruptedException e) {
+      throw new WebServiceException("Can't create params file: " + e.toString(), e);
+    }
+    job.setPigScript(newPigScriptPath);
 
-        TempletonApi.JobData data = null;
-        try {
-            data = getTempletonApi().runPigQuery(new File(job.getPigScript()), statusdir, job.getTempletonArguments());
-        } catch (IOException templetonBadResponse) {
-            String msg = String.format("Templeton bad response: %s", templetonBadResponse.toString());
-            LOG.debug(msg);
-            throw new WebServiceException(msg, templetonBadResponse);
-        }
-        job.setJobId(data.id);
+    job.setStatusDir(statusdir);
+    job.setDateStarted(System.currentTimeMillis() / 1000L);
 
-        JobPolling.pollJob(context, job);
+    TempletonApi.JobData data = null;
+    try {
+      data = getTempletonApi().runPigQuery(new File(job.getPigScript()), statusdir, job.getTempletonArguments());
+    } catch (IOException templetonBadResponse) {
+      String msg = String.format("Templeton bad response: %s", templetonBadResponse.toString());
+      LOG.debug(msg);
+      throw new WebServiceException(msg, templetonBadResponse);
     }
+    job.setJobId(data.id);
 
-    public void retrieveJobStatus(PigJob job) {
-        TempletonApi.JobInfo info = null;
-        try {
-            info = getTempletonApi().checkJob(job.getJobId());
-        } catch (IOException e) {
-            LOG.warn(String.format("IO Exception: %s", e));
-            return;
-        }
+    JobPolling.pollJob(context, job);
+  }
 
-        if (info.status != null && (info.status.containsKey("runState"))) {
-            //TODO: retrieve from RM
-            int runState = ((Double) info.status.get("runState")).intValue();
-            switch (runState) {
-                case PigJob.RUN_STATE_KILLED:
-                    LOG.debug(String.format("Job KILLED: %s", job.getJobId()));
-                    job.setStatus(PigJob.Status.KILLED);
-                    break;
-                case PigJob.RUN_STATE_FAILED:
-                    LOG.debug(String.format("Job FAILED: %s", job.getJobId()));
-                    job.setStatus(PigJob.Status.FAILED);
-                    break;
-                case PigJob.RUN_STATE_PREP:
-                case PigJob.RUN_STATE_RUNNING:
-                    job.setStatus(PigJob.Status.RUNNING);
-                    break;
-                case PigJob.RUN_STATE_SUCCEEDED:
-                    LOG.debug(String.format("Job COMPLETED: %s", job.getJobId()));
-                    job.setStatus(PigJob.Status.COMPLETED);
-                    break;
-                default:
-                    LOG.debug(String.format("Job in unknown state: %s", job.getJobId()));
-                    job.setStatus(PigJob.Status.UNKNOWN);
-                    break;
-            }
-        }
-        Pattern pattern = Pattern.compile("\\d+");
-        Matcher matcher = null;
-        if (info.percentComplete != null) {
-            matcher = pattern.matcher(info.percentComplete);
-        }
-        if (matcher != null && matcher.find()) {
-            job.setPercentComplete(Integer.valueOf(matcher.group()));
-        } else {
-            job.setPercentComplete(null);
-        }
-        save(job);
+  /**
+   * Get job status
+   * @param job job object
+   */
+  public void retrieveJobStatus(PigJob job) {
+    TempletonApi.JobInfo info = null;
+    try {
+      info = getTempletonApi().checkJob(job.getJobId());
+    } catch (IOException e) {
+      LOG.warn(String.format("IO Exception: %s", e));
+      return;
     }
 
-    /**
-     * Extension point to use different usernames in templeton
-     * requests instead of logged in user
-     * @return username in templeton
-     */
-    private String getTempletonUser() {
-        return context.getProperties().get("dataworker.templeton_user");
-//        return context.getTempletonUser();
+    if (info.status != null && (info.status.containsKey("runState"))) {
+      //TODO: retrieve from RM
+      int runState = ((Double) info.status.get("runState")).intValue();
+      switch (runState) {
+        case PigJob.RUN_STATE_KILLED:
+          LOG.debug(String.format("Job KILLED: %s", job.getJobId()));
+          job.setStatus(PigJob.Status.KILLED);
+          break;
+        case PigJob.RUN_STATE_FAILED:
+          LOG.debug(String.format("Job FAILED: %s", job.getJobId()));
+          job.setStatus(PigJob.Status.FAILED);
+          break;
+        case PigJob.RUN_STATE_PREP:
+        case PigJob.RUN_STATE_RUNNING:
+          job.setStatus(PigJob.Status.RUNNING);
+          break;
+        case PigJob.RUN_STATE_SUCCEEDED:
+          LOG.debug(String.format("Job COMPLETED: %s", job.getJobId()));
+          job.setStatus(PigJob.Status.COMPLETED);
+          break;
+        default:
+          LOG.debug(String.format("Job in unknown state: %s", job.getJobId()));
+          job.setStatus(PigJob.Status.UNKNOWN);
+          break;
+      }
+    }
+    Pattern pattern = Pattern.compile("\\d+");
+    Matcher matcher = null;
+    if (info.percentComplete != null) {
+      matcher = pattern.matcher(info.percentComplete);
     }
+    if (matcher != null && matcher.find()) {
+      job.setPercentComplete(Integer.valueOf(matcher.group()));
+    } else {
+      job.setPercentComplete(null);
+    }
+    save(job);
+  }
+
+  /**
+   * Extension point to use different usernames in templeton
+   * requests instead of logged in user
+   * @return username in templeton
+   */
+  private String getTempletonUser() {
+    return context.getProperties().get("dataworker.templeton_user");
+  }
 }