Skip to content

Commit

Permalink
React code review
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTing committed Apr 17, 2020
1 parent f23afab commit 66c66f0
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@

package org.apache.submarine.server.api.job;

import java.io.InputStream;
// import java.io.InputStream;

/**
* Interface for getting logs of job.
*/
public interface JobLogHandler {
String getLog(Job job);
InputStream getLogStream(Job job);
public class JobLog {
String podName;
String podLog;

public String getPodName() {
return podName;
}

public void setPodName(String name) {
podName = name;
}

public String getPodLog() {
return podLog;
}

public void setPodLog(String string) {
podLog = string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

package org.apache.submarine.server.api.job;

import java.util.List;

import org.apache.submarine.commons.utils.SubmarineConfiguration;
import org.apache.submarine.commons.utils.exception.SubmarineRuntimeException;
import org.apache.submarine.server.api.spec.JobSpec;

/**
* The submitter should implement this interface.
*/
public interface JobSubmitter extends JobLogHandler {
public interface JobSubmitter {
/**
* Initialize the submitter related code
*/
Expand Down Expand Up @@ -70,4 +72,6 @@ public interface JobSubmitter extends JobLogHandler {
* @throws SubmarineRuntimeException running error
*/
Job deleteJob(JobSpec jobSpec) throws SubmarineRuntimeException;

List<JobLog> getJobLog(JobSpec jobSpec) throws SubmarineRuntimeException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.submarine.server.api.job.JobSubmitter;
import org.apache.submarine.server.api.job.Job;
import org.apache.submarine.server.api.job.JobId;
import org.apache.submarine.server.api.job.JobLog;
import org.apache.submarine.server.api.spec.JobSpec;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -170,6 +171,23 @@ public Job deleteJob(String id) throws SubmarineRuntimeException {
return job;
}

/**
* Get job log
* @param id job id
* @return object
* @throws SubmarineRuntimeException the service error
*/
public List<JobLog> getJobLog(String id) throws SubmarineRuntimeException {
checkJobId(id);
Job job = cachedJobMap.get(id);
JobSpec spec = job.getSpec();
JobSubmitter jobSubmitter = getSubmitter(spec.getSubmitterSpec().getType());
Job patchJob = jobSubmitter.findJob(spec);
job.rebuild(patchJob);

return jobSubmitter.getJobLog(spec);
}

public JobSubmitter getSubmitter(String type) throws SubmarineRuntimeException {
JobSubmitter submitter = submitterManager.getSubmitterByType(type);
if (submitter == null) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.submarine.commons.utils.exception.SubmarineRuntimeException;
import org.apache.submarine.server.job.JobManager;
import org.apache.submarine.server.api.job.Job;
import org.apache.submarine.server.api.job.JobLog;
import org.apache.submarine.server.api.spec.JobSpec;
import org.apache.submarine.server.response.JsonResponse;

Expand Down Expand Up @@ -133,6 +134,33 @@ public Response deleteJob(@PathParam(RestConstants.JOB_ID) String id) {
}
}

/*
@GET
@Path("/log")
public Response listlog(@QueryParam("status") String status) {
try {
List<Job> jobList = jobManager.listJobsByStatus(status);
for (Job job : jobList) {
jobManager.getJobLog(job.getName());
}
return new JsonResponse.Builder<List<Job>>(Response.Status.OK).result(jobList).build();
} catch (SubmarineRuntimeException e) {
return parseJobServiceException(e);
}
}
*/

@GET
@Path("/logs/{id}")
public Response getlog(@PathParam(RestConstants.JOB_ID) String id) {
try {
List<JobLog> jobLogList = jobManager.getJobLog(id);
return new JsonResponse.Builder<List<JobLog>>(Response.Status.OK).result(jobLogList).build();
} catch (SubmarineRuntimeException e) {
return parseJobServiceException(e);
}
}

private Response parseJobServiceException(SubmarineRuntimeException e) {
return new JsonResponse.Builder<String>(e.getCode()).message(e.getMessage()).build();
}
Expand Down

This file was deleted.

0 comments on commit 66c66f0

Please sign in to comment.