Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
291 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/edu/washington/escience/myria/api/FunctionResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* | ||
*/ | ||
package edu.washington.escience.myria.api; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.ResponseBuilder; | ||
import javax.ws.rs.core.Response.Status; | ||
|
||
import org.apache.commons.httpclient.HttpStatus; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.wordnik.swagger.annotations.Api; | ||
import com.wordnik.swagger.annotations.ApiOperation; | ||
import com.wordnik.swagger.annotations.ApiResponse; | ||
import com.wordnik.swagger.annotations.ApiResponses; | ||
|
||
import edu.washington.escience.myria.DbException; | ||
import edu.washington.escience.myria.api.encoding.FunctionEncoding; | ||
import edu.washington.escience.myria.api.encoding.FunctionStatus; | ||
import edu.washington.escience.myria.parallel.Server; | ||
|
||
/** | ||
* | ||
*/ | ||
/** | ||
* This is the class that handles API calls to create or fetch functions. | ||
* | ||
*/ | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MyriaApiConstants.JSON_UTF_8) | ||
@Path("/function") | ||
@Api(value = "/function", description = "Operations on functions") | ||
public class FunctionResource { | ||
/** The Myria server running on the master. */ | ||
@Context | ||
private Server server; | ||
/** Information about the URL of the request. */ | ||
|
||
/** Logger. */ | ||
protected static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(FunctionResource.class); | ||
|
||
/** | ||
* @param queryId an optional query ID specifying which datasets to get. | ||
* @return a list of datasets. | ||
* @throws DbException if there is an error accessing the Catalog. | ||
*/ | ||
@GET | ||
public List<String> getFunctions() throws DbException { | ||
LOGGER.info("get functions!"); | ||
return server.getFunctions(); | ||
} | ||
|
||
/** | ||
* Creates an Function based on DbFunctionEncoding | ||
* | ||
* @POST | ||
*/ | ||
@POST | ||
@Path("/register") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
public Response createFunction(final FunctionEncoding encoding) throws DbException { | ||
LOGGER.info("register function!"); | ||
|
||
long queryId; | ||
try { | ||
queryId = | ||
server.createFunction(encoding.name, encoding.text, encoding.lang, encoding.workers, encoding.binary, | ||
encoding.inputSchema, encoding.outputSchema); | ||
|
||
} catch (Exception e) { | ||
throw new DbException(); | ||
} | ||
/* Build the response to return the queryId */ | ||
ResponseBuilder response = Response.ok(); | ||
return response.entity(queryId).build(); | ||
} | ||
|
||
@GET | ||
@ApiOperation(value = "get information about a function", response = FunctionStatus.class) | ||
@ApiResponses(value = { @ApiResponse(code = HttpStatus.SC_NOT_FOUND, message = "Function not found", response = String.class) }) | ||
@Produces({ MediaType.APPLICATION_OCTET_STREAM, MyriaApiConstants.JSON_UTF_8 }) | ||
@Path("/{name}") | ||
public Response getFunction(@PathParam("name") final String name) throws DbException, IOException { | ||
|
||
/* Assemble the name of the relation. */ | ||
String functionName = name; | ||
LOGGER.info("get function!"); | ||
|
||
LOGGER.info("looking for function with name: " + functionName); | ||
FunctionStatus status = server.getFunctionDetails(functionName); | ||
if (status == null) { | ||
/* Not found, throw a 404 (Not Found) */ | ||
throw new MyriaApiException(Status.NOT_FOUND, "That function was not found"); | ||
} | ||
|
||
return Response.ok(status).build(); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
src/edu/washington/escience/myria/api/encoding/FunctionStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* | ||
*/ | ||
package edu.washington.escience.myria.api.encoding; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import edu.washington.escience.myria.MyriaConstants; | ||
import edu.washington.escience.myria.Schema; | ||
|
||
/** | ||
* | ||
*/ | ||
public class FunctionStatus { | ||
/** | ||
* Instantiate a FunctionStatus with the provided values. | ||
* | ||
* @param name function name identifying the function. | ||
* @param inputSchema The {@link Schema} of the input to the function. | ||
* @param outputSchema The {@link Schema} of the input to the function. | ||
* @param text Text associated with the function. | ||
* @param lang language of the function. | ||
*/ | ||
@JsonCreator | ||
public FunctionStatus(@JsonProperty("name") final String name, @JsonProperty("inputSchema") final String inputSchema, | ||
@JsonProperty("outputSchema") final String outputSchema, @JsonProperty("text") final String text, | ||
@JsonProperty("lang") final MyriaConstants.FunctionLanguage lang) { | ||
this.name = name; | ||
this.outputSchema = outputSchema; | ||
this.inputSchema = inputSchema; | ||
this.text = text; | ||
this.lang = lang; | ||
|
||
} | ||
|
||
/** The name identifying the function. */ | ||
@JsonProperty | ||
private final String name; | ||
/** The {@link Schema} of the output tuples to the function. */ | ||
@JsonProperty | ||
private final String outputSchema; | ||
/** The {@link Schema} of the input tuples to the function. */ | ||
@JsonProperty | ||
private final String inputSchema; | ||
/** The text of the function */ | ||
@JsonProperty | ||
private final String text; | ||
/** The text of the function */ | ||
@JsonProperty | ||
private final MyriaConstants.FunctionLanguage lang; | ||
|
||
// @JsonProperty public URI uri; | ||
|
||
/** | ||
* @return The name identifying the function. | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* @return The {@link Schema} of the output tuples in the function. | ||
*/ | ||
public String getOutputSchema() { | ||
return outputSchema; | ||
} | ||
|
||
/** | ||
* @return The {@link Schema} of the input tuples in the function. | ||
*/ | ||
public String getInputSchema() { | ||
return inputSchema; | ||
} | ||
|
||
/** | ||
* @return get text associated with the function | ||
*/ | ||
public String getText() { | ||
return text; | ||
} | ||
|
||
/** | ||
* @return the language of function | ||
*/ | ||
public MyriaConstants.FunctionLanguage getLanguage() { | ||
return lang; | ||
} | ||
|
||
} |
Oops, something went wrong.