Skip to content

Commit

Permalink
cleaning up udf registration
Browse files Browse the repository at this point in the history
  • Loading branch information
parmitam committed Jun 28, 2016
1 parent 9c5d9e9 commit 99ed2c4
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 165 deletions.
1 change: 0 additions & 1 deletion python/MyriaPythonWorker/worker.py
Expand Up @@ -35,7 +35,6 @@ def main(infile, outfile):
print("python process done reading tuple, now writing ")
retval = func(tup)
write_with_length(retval, outfile, outputType)
#pickleSer.write_with_length(func(tup),outfile)
outfile.flush()


Expand Down
75 changes: 0 additions & 75 deletions src/edu/washington/escience/myria/api/DatasetResource.java
Expand Up @@ -47,7 +47,6 @@
import edu.washington.escience.myria.api.encoding.CreateViewEncoding;
import edu.washington.escience.myria.api.encoding.DatasetEncoding;
import edu.washington.escience.myria.api.encoding.DatasetStatus;
import edu.washington.escience.myria.api.encoding.FunctionEncoding;
import edu.washington.escience.myria.api.encoding.TipsyDatasetEncoding;
import edu.washington.escience.myria.coordinator.CatalogException;
import edu.washington.escience.myria.io.InputStreamSource;
Expand All @@ -62,8 +61,6 @@
import edu.washington.escience.myria.parallel.Server;
import edu.washington.escience.myria.storage.TupleBatch;

// remove once function encoding is complete

/**
* This is the class that handles API calls to create or fetch datasets.
*
Expand Down Expand Up @@ -415,78 +412,6 @@ public Response createView(final CreateViewEncoding encoding) throws DbException
return response.entity(queryId).build();
}

/**
* Creates an Function based on DbFunctionEncoding
*
* @POST
* @Path("/Function/")
* @Consumes(MediaType.APPLICATION_JSON) public Response createFunction(final CreateFunctionEncoding encoding) throws
* DbException { long queryId; try { queryId =
* server.createUDF(encoding.udfName, encoding.udfDefinition, encoding.workers);
* } catch (Exception e) { throw new DbException(); } // Build the response to
* return the queryId ResponseBuilder response = Response.ok(); return
* response.entity(queryId).build(); }
*/

/**
* Creates an function based on DbFunctionEncoding
*/
@POST
@Path("/function/")
@Consumes(MediaType.APPLICATION_JSON)
public Response createFunction(final FunctionEncoding encoding) throws DbException {
long queryId;
try {
LOGGER.info(encoding.name + "\t " + encoding.text + "\t " + encoding.lang + "\t " + encoding.workers);
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();
}

/**
* @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
@Path("/function/")
public List<String> getFunctions() throws DbException {
return server.getFunctions();
}

/**
* @param userName the user who owns the target relation.
* @param programName the program to which the target relation belongs.
* @param relationName the name of the target relation.
* @return metadata
* @throws DbException if there is an error in the database.
*/
@DELETE
@Path("/function/")
public Response deleteFunction(final String udf_name) throws DbException {

Boolean status = server.functionExists(udf_name);
if (status == false) {
/* function not found, throw a 404 (Not Found) */
throw new MyriaApiException(Status.NOT_FOUND, "That dataset was not found");
}

// delete command
try {
server.deleteFunction(udf_name);
} catch (Exception e) {
throw new DbException();
}
return Response.noContent().build();
}

/**
* @param dataset the dataset to be ingested.
* @return the created dataset resource.
Expand Down
111 changes: 111 additions & 0 deletions src/edu/washington/escience/myria/api/FunctionResource.java
@@ -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 src/edu/washington/escience/myria/api/encoding/FunctionStatus.java
@@ -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;
}

}

0 comments on commit 99ed2c4

Please sign in to comment.