Skip to content

Commit

Permalink
#123 Can now generate ES model artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrudin committed Dec 12, 2016
1 parent 37bf1db commit 1d7975f
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 5 deletions.
13 changes: 13 additions & 0 deletions examples/entity-services-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This project shows where Entity Services (part of ML9) model definitions can be stored so that ml-gradle can be used
to generate artifacts for the models. Generating artifacts depends on the application having been deployed
already as a REST API server is required. Thus, a typical workflow is:

1. Stub out a project with a build.gradle and gradle.properties file
2. Run "gradle mlDeploy" to deploy the application
3. Create one or more model definitions in ./data/entity-services
4. Run "gradle mlGenerateModelArtifacts" (should be able to abbreviate it as "gradle mlgen") to use Entity Services
to generate model artifacts for each of the model definitions
5. Run "gradle mlDeploy" to deploy all of the model artifacts, which will include creating a schemas database if one
doesn't exist already

You can of course shorten the last 2 steps to "gradle mlgen mldeploy".
3 changes: 3 additions & 0 deletions examples/entity-services-project/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id "com.marklogic.ml-gradle" version "2.5.0"
}
84 changes: 84 additions & 0 deletions examples/entity-services-project/data/entity-services/race.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"info": {
"title": "Race",
"version": "0.0.1",
"baseUri": "http://grechaw.github.io/entity-types",
"description":"This schema represents a Runner who runs Runs and has the potential of winning Races. We'll start with this entity-type, then decide on and populate instances, tie the data in with an external RDF-based model, and query it. There are interesting problems with the bare-bones approach in this entity-type."
},
"definitions": {
"Race": {
"properties": {
"name": {
"datatype": "string",
"description":"The name of the race."
},
"comprisedOfRuns": {
"datatype": "array",
"description":"An array of Runs that comprise the race.",
"items":{
"$ref": "#/definitions/Run"
}
},
"wonByRunner": {
"$ref":"#/definitions/Runner",
"description":"The (single) winner of the race. (rule) Should match the run of shortest duration."
},
"courseLength": {
"datatype":"decimal",
"description":"Length of the course in a scalar unit (decimal miles)"
}
},
"primaryKey":"name"
},
"Run": {
"properties": {
"id": {
"datatype": "string",
"description":"A unique id for the run. maybe date/runByRunner (assumes one run per day per person)"
},
"date": {
"datatype": "date",
"description":"The date on which the run occurred."
},
"distance": {
"datatype": "decimal",
"description":"The distance covered, in a scalar value."
},
"distanceLabel": {
"datatype": "string",
"description":"The distance covered, in a conventional notation."
},
"duration": {
"datatype": "dayTimeDuration",
"description":"The duration of the run."
},
"runByRunner": {
"$ref": "#/definitions/Runner"
}
},
"primaryKey":"id",
"required":["date","distance","duration","runByRunner"],
"rangeIndex":["date", "distance", "duration", "runByRunner"]
},
"Runner": {
"properties": {
"name": {
"datatype": "string",
"description":"The name of the runner. In this early model, unique and a PK."
},
"age": {
"datatype": "int",
"description":"age, in years."
},
"gender" : {
"datatype" : "string",
"description": "The gender of the runner (for the purposes of race categories.)"
}
},
"primaryKey": "name",
"wordLexicon": ["name"],
"required": ["name", "age"]
}
}
}

5 changes: 5 additions & 0 deletions examples/entity-services-project/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mlHost=localhost
mlAppName=es-gradle-example
mlRestPort=82345
mlUsername=admin
mlPassword=admin
4 changes: 2 additions & 2 deletions examples/local-testing-project/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
repositories {
mavenLocal()
jcenter()
mavenLocal()
}
dependencies {
classpath "com.marklogic:ml-gradle:${mlGradleVersion}"
Expand All @@ -12,8 +12,8 @@ apply plugin: "java"
apply plugin: "com.marklogic.ml-gradle"

repositories {
jcenter()
mavenLocal()
jcenter()
}

ext {
Expand Down
2 changes: 1 addition & 1 deletion examples/local-testing-project/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Set this to the version you used when running
# "gradle -Pversion=(something) publishToMavenLocal" on your local ml-gradle repo
mlGradleVersion=shell
mlGradleVersion=changeme

mlHost=localhost
mlAppName=example
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=com.marklogic
version=2.4.0
mlAppDeployerDependency=com.marklogic:ml-app-deployer:2.4.0
version=es2
mlAppDeployerDependency=com.marklogic:ml-app-deployer:es2
mlcpUtilDependency=com.marklogic:mlcp-util:0.3.0

4 changes: 4 additions & 0 deletions src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.marklogic.gradle
import com.marklogic.appdeployer.command.databases.DeployOtherDatabasesCommand
import com.marklogic.appdeployer.command.forests.DeployCustomForestsCommand
import com.marklogic.gradle.task.databases.DeleteCollectionTask
import com.marklogic.gradle.task.es.GenerateModelArtifactsTask
import com.marklogic.gradle.task.forests.DeployCustomForestsTask
import com.marklogic.gradle.task.groups.SetTraceEventsTask
import com.marklogic.gradle.task.qconsole.ExportWorkspacesTask
Expand Down Expand Up @@ -186,6 +187,9 @@ class MarkLogicPlugin implements Plugin<Project> {
project.task("mlCreateTransform", type: CreateTransformTask, group: devGroup, description: "Create a new transform in the modules transforms directory")
project.task("mlPrepareRestApiDependencies", type: PrepareRestApiDependenciesTask, group: devGroup, dependsOn: project.configurations["mlRestApi"], description: "Downloads (if necessary) and unzips in the build directory all mlRestApi dependencies")

String esGroup = "ml-gradle Entity Services"
project.task("mlGenerateModelArtifacts", type: GenerateModelArtifactsTask, group: esGroup, description: "Generate model artifacts for the Entity Services models in the default directory of ./data/entity-services")

String flexrepGroup = "ml-gradle Flexible Replication"
project.task("mlDeleteAllFlexrepConfigs", type: DeleteAllFlexrepConfigsTask, group: flexrepGroup, description: "Delete all Flexrep configs and their associated targets")
project.task("mlDeployFlexrep", type: DeployFlexrepTask, group: flexrepGroup, description: "Deploy Flexrep configs and targets in the configuration directory")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.marklogic.gradle.task.es

import com.marklogic.appdeployer.command.es.GenerateModelArtifactsCommand
import com.marklogic.gradle.task.MarkLogicTask
import org.gradle.api.tasks.TaskAction

class GenerateModelArtifactsTask extends MarkLogicTask {

@TaskAction
void generateModelArtifacts() {
new GenerateModelArtifactsCommand().execute(getCommandContext())
}
}

0 comments on commit 1d7975f

Please sign in to comment.