-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce TexeraWorkflowCompilingService for Workflow Compilation (#2796
) This PR adds a standalone web service called `TexeraWorkflowCompilingService`. ## The purpose of having a standalone compilation service Separate the Texera Workflow Compilation with Workflow Execution. ## The configuration of this service ### 1. Web Server Config All the configuration items are put in `core/amber/src/main/resources/texera-compiler-web-config.yml`. By default, this server runs at port 9090. ### 2. Application Config This service shares the same application configuration file, i.e. `core/amber/src/main/resources/application.conf`. To ensure that JWT token can be recognized by both `TexeraWebApplication` and `TexeraWorkflowCompilingService`, `user-sys.jwt.256-bit-secret` must NOT be set as random, instead it must be set as a fixed 256-bit string. ## The Endpoint provided by `TexeraWorkflowCompilingService` A single endpoint is provided by this web application: ``` POST /api/texera/compilation/{wid} ``` - request format: the serialized workflow json string - response: - physicalPlan: Option[PhysicalPlan] // the physical plan of the workflow, if None, the compilation is failed - operatorInputSchemas: Map[String, List[Option[List[Attribute]]]]. // from `OpId` to list of `Schema`(List of attributes) indexed by port id - operatorErrors: Map[String, String] // from `OpId` to error of this operator ## Future TODO after this PR 1. Use this web service when GUI is doing the workflow editing, maintain the physical plan in GUI. 2. Change all the deployment scripts, including `terminate-daemon.sh`, `deploy-daemon.sh` and `Dockerfile` to launch & terminate this web service 3. Clean up the code in `core/amber/src/main/scala/edu/uci/ics/texera/workflow/common/workflow/WorkflowCompiler.scala` and `core/amber/src/main/scala/edu/uci/ics/texera/web/service/WorkflowExecutionService.scala`
- Loading branch information
1 parent
effcccf
commit 4446179
Showing
11 changed files
with
316 additions
and
6 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
core/amber/src/main/resources/texera-compiling-service-web-config.yml
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,42 @@ | ||
server: | ||
# modify applicationContextPath if you want the root path to be the name of the application | ||
# for example, set it to /twitter, then the url will become texera.ics.uci.edu:port/twitter | ||
applicationContextPath: / | ||
applicationConnectors: | ||
- type: http | ||
port: 9090 | ||
adminConnectors: | ||
- type: http | ||
port: 9091 | ||
requestLog: | ||
type: classic | ||
timeZone: UTC | ||
appenders: | ||
- type: console | ||
- type: file | ||
currentLogFilename: ../log/access.log | ||
threshold: ALL | ||
queueSize: 512 | ||
discardingThreshold: 0 | ||
archive: true | ||
archivedLogFilenamePattern: ../log/access-%d{yyyy-MM-dd}.log.gz | ||
archivedFileCount: 7 | ||
bufferSize: 8KiB | ||
immediateFlush: true | ||
logging: | ||
level: INFO | ||
loggers: | ||
"io.dropwizard": INFO | ||
appenders: | ||
- type: console | ||
logFormat: "[%date{ISO8601}] [%level] [%logger] [%thread] - %msg %n" | ||
- type: file | ||
currentLogFilename: ../log/texera-workflow-compiling-service.log | ||
threshold: ALL | ||
queueSize: 512 | ||
discardingThreshold: 0 | ||
archive: false | ||
timeZone: UTC | ||
logFormat: "[%date{ISO8601}] [%level] [%logger] [%thread] - %msg %n" | ||
bufferSize: 8KiB | ||
immediateFlush: true |
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
83 changes: 83 additions & 0 deletions
83
core/amber/src/main/scala/edu/uci/ics/texera/web/TexeraWorkflowCompilingService.scala
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,83 @@ | ||
package edu.uci.ics.texera.web | ||
|
||
import com.fasterxml.jackson.module.scala.DefaultScalaModule | ||
import com.github.toastshaman.dropwizard.auth.jwt.JwtAuthFilter | ||
import com.typesafe.scalalogging.LazyLogging | ||
import edu.uci.ics.amber.engine.common.AmberConfig | ||
import edu.uci.ics.texera.Utils | ||
import edu.uci.ics.texera.web.TexeraWebApplication.parseArgs | ||
import edu.uci.ics.texera.web.auth.JwtAuth.jwtConsumer | ||
import edu.uci.ics.texera.web.auth.{ | ||
GuestAuthFilter, | ||
SessionUser, | ||
UserAuthenticator, | ||
UserRoleAuthorizer | ||
} | ||
import edu.uci.ics.texera.web.resource.WorkflowCompilationResource | ||
import io.dropwizard.auth.{AuthDynamicFeature, AuthValueFactoryProvider} | ||
import io.dropwizard.setup.{Bootstrap, Environment} | ||
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature | ||
|
||
object TexeraWorkflowCompilingService { | ||
def main(args: Array[String]): Unit = { | ||
val argMap = parseArgs(args) | ||
|
||
new TexeraWorkflowCompilingService().run( | ||
"server", | ||
Utils.amberHomePath | ||
.resolve("src") | ||
.resolve("main") | ||
.resolve("resources") | ||
.resolve("texera-compiling-service-web-config.yml") | ||
.toString | ||
) | ||
} | ||
} | ||
|
||
class TexeraWorkflowCompilingService | ||
extends io.dropwizard.Application[TexeraWorkflowCompilingServiceConfiguration] | ||
with LazyLogging { | ||
override def initialize( | ||
bootstrap: Bootstrap[TexeraWorkflowCompilingServiceConfiguration] | ||
): Unit = { | ||
// register scala module to dropwizard default object mapper | ||
bootstrap.getObjectMapper.registerModule(DefaultScalaModule) | ||
} | ||
|
||
override def run( | ||
configuration: TexeraWorkflowCompilingServiceConfiguration, | ||
environment: Environment | ||
): Unit = { | ||
// serve backend at /api/texera | ||
environment.jersey.setUrlPattern("/api/texera/*") | ||
|
||
// register the compilation endpoint | ||
environment.jersey.register(classOf[WorkflowCompilationResource]) | ||
|
||
// Add JWT Auth layer (without session) | ||
if (AmberConfig.isUserSystemEnabled) { | ||
environment.jersey.register( | ||
new AuthDynamicFeature( | ||
new JwtAuthFilter.Builder[SessionUser]() | ||
.setJwtConsumer(jwtConsumer) | ||
.setRealm("realm") | ||
.setPrefix("Bearer") | ||
.setAuthenticator(UserAuthenticator) | ||
.setAuthorizer(UserRoleAuthorizer) | ||
.buildAuthFilter() | ||
) | ||
) | ||
} else { | ||
environment.jersey.register( | ||
new AuthDynamicFeature( | ||
new GuestAuthFilter.Builder().setAuthorizer(UserRoleAuthorizer).buildAuthFilter() | ||
) | ||
) | ||
} | ||
|
||
environment.jersey.register( | ||
new AuthValueFactoryProvider.Binder[SessionUser](classOf[SessionUser]) | ||
) | ||
environment.jersey.register(classOf[RolesAllowedDynamicFeature]) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...er/src/main/scala/edu/uci/ics/texera/web/TexeraWorkflowCompilingServiceConfiguration.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,6 @@ | ||
package edu.uci.ics.texera.web; | ||
|
||
import io.dropwizard.Configuration; | ||
|
||
public class TexeraWorkflowCompilingServiceConfiguration extends Configuration { | ||
} |
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
61 changes: 61 additions & 0 deletions
61
core/amber/src/main/scala/edu/uci/ics/texera/web/resource/WorkflowCompilationResource.scala
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,61 @@ | ||
package edu.uci.ics.texera.web.resource | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import edu.uci.ics.amber.engine.common.virtualidentity.WorkflowIdentity | ||
import edu.uci.ics.texera.Utils | ||
import edu.uci.ics.texera.web.model.websocket.request.LogicalPlanPojo | ||
import edu.uci.ics.texera.workflow.common.WorkflowContext | ||
import edu.uci.ics.texera.workflow.common.tuple.schema.Attribute | ||
import edu.uci.ics.texera.workflow.common.workflow.{PhysicalPlan, WorkflowCompiler} | ||
import org.jooq.types.UInteger | ||
|
||
import javax.annotation.security.RolesAllowed | ||
import javax.ws.rs.{Consumes, POST, Path, PathParam, Produces} | ||
import javax.ws.rs.core.MediaType | ||
|
||
case class WorkflowCompilationResponse( | ||
physicalPlan: Option[PhysicalPlan], | ||
operatorInputSchemas: Map[String, List[Option[List[Attribute]]]], | ||
operatorErrors: Map[String, String] | ||
) | ||
|
||
@Consumes(Array(MediaType.APPLICATION_JSON)) | ||
@Produces(Array(MediaType.APPLICATION_JSON)) | ||
@RolesAllowed(Array("REGULAR", "ADMIN")) | ||
@Path("/compilation") | ||
class WorkflowCompilationResource extends LazyLogging { | ||
@POST | ||
@Path("/{wid}") | ||
def compileWorkflow( | ||
workflowStr: String, | ||
@PathParam("wid") wid: UInteger | ||
): WorkflowCompilationResponse = { | ||
val logicalPlanPojo = Utils.objectMapper.readValue(workflowStr, classOf[LogicalPlanPojo]) | ||
|
||
val context = new WorkflowContext( | ||
workflowId = WorkflowIdentity(wid.toString.toLong) | ||
) | ||
|
||
// compile the pojo using WorkflowCompiler | ||
val workflowCompilationResult = | ||
new WorkflowCompiler(context).compile(logicalPlanPojo) | ||
// return the result | ||
WorkflowCompilationResponse( | ||
physicalPlan = workflowCompilationResult.physicalPlan, | ||
operatorInputSchemas = workflowCompilationResult.operatorIdToInputSchemas.map { | ||
case (operatorIdentity, schemas) => | ||
val opId = operatorIdentity.id | ||
val attributes = schemas.map { schema => | ||
if (schema.isEmpty) | ||
None | ||
else | ||
Some(schema.get.attributes) | ||
} | ||
(opId, attributes) | ||
}, | ||
operatorErrors = workflowCompilationResult.operatorIdToError.map { | ||
case (operatorIdentity, error) => (operatorIdentity.id, error.toString) | ||
} | ||
) | ||
} | ||
} |
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
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
Oops, something went wrong.