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:57 UTC
[3/4] AMBARI-5704. Pig View Cleanup. (mahadev)
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();
+ }
}