-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Domain endpoint for compiling templates to schemas #63
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8806f40
Add Domain Repository class for Domain management
Swiddis fa8e832
Hook up compilation types to domain map
Swiddis 9ff1395
Relocate domain creation test
Swiddis 03353bb
Add url handler for domain requests
Swiddis afd6938
Isolate domain request handler
Swiddis 75de77b
Create domain in domain rest handler
Swiddis f96564a
Add changes for creation test
Swiddis ebde5e4
Fix object creation collision handling
Swiddis ba1ca40
Implement Domain GET request
Swiddis bcaaa9e
Merge remote-tracking branch 'upstream/main' into schema-compilation
Swiddis bde50fc
Separate compilation type and domain resource
Swiddis ce02952
Expand schema compilation validation
Swiddis 7e9e2ee
Document schema compilation workflow
Swiddis 9daa1c2
Update endpoint.md
Swiddis 33ea20d
Move domain compilation to dedicated class
Swiddis 8e447e5
Apply PR feedback
Swiddis e7dad58
Fix newline
Swiddis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Schema Compilation Workflow | ||
|
||
To use a GraphQL Schema with data, there are two main steps: | ||
|
||
- Adding Entities: Creating `schemaEntityType`s that will make up the Schema | ||
- Compilation: Generating a `schemaDomainType` | ||
|
||
## Adding Entities | ||
|
||
Entities can be created, updated, modified, and deleted through the `/_plugins/_simpleschema/object` endpoint. | ||
Creation is done by `POST`ing to this endpoint with a Json object. | ||
The object must have a `type` of `schemaEntityType`. | ||
|
||
```json | ||
{ | ||
"schemaEntityType": { | ||
"name": "Author", | ||
"objectId": "testAuthorObject", | ||
"type": "schemaEntityType", | ||
"catalog": ["library"], | ||
"content": "type Author { id: ID! \n name: String! \n born: DateTime! \n died: DateTime \n nationality: String! \n books: [Book] \n }" | ||
} | ||
} | ||
``` | ||
|
||
When the object is created, if one is not provided, it will be assigned an `objectId` primary key. | ||
|
||
## Compilation | ||
|
||
Compiled GraphQL Schemas are stored as `Domain` resources, | ||
available at the `/_plugins/_simpleschema/domain` endpoint. | ||
As `Domain`s must be uniquely named, they are given an `objectId` instead of a `name`. | ||
Swiddis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Provide the entity list as a list of `objectId`s to be used in compilation. | ||
|
||
```json | ||
{ | ||
"objectId": "testSchema", | ||
Swiddis marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change objectId to name |
||
"catalog": ["library"], | ||
"entityList": ["testAuthorObject", "testBookObject"] | ||
} | ||
``` |
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
37 changes: 37 additions & 0 deletions
37
service/src/main/kotlin/org/opensearch/simpleschema/action/CreateSimpleSchemaDomainAction.kt
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,37 @@ | ||
package org.opensearch.simpleschema.action | ||
|
||
import org.opensearch.action.ActionType | ||
import org.opensearch.action.support.ActionFilters | ||
import org.opensearch.client.Client | ||
import org.opensearch.common.inject.Inject | ||
import org.opensearch.common.xcontent.NamedXContentRegistry | ||
import org.opensearch.commons.authuser.User | ||
import org.opensearch.transport.TransportService | ||
|
||
internal class CreateSimpleSchemaDomainAction @Inject constructor( | ||
transportService: TransportService, | ||
client: Client, | ||
actionFilters: ActionFilters, | ||
val xContentRegistry: NamedXContentRegistry | ||
) : PluginBaseAction<CreateSimpleSchemaDomainRequest, CreateSimpleSchemaDomainResponse>( | ||
NAME, | ||
transportService, | ||
client, | ||
actionFilters, | ||
::CreateSimpleSchemaDomainRequest | ||
) { | ||
companion object { | ||
private const val NAME = "cluster:admin/opensearch/simpleschema/domain/create" | ||
internal val ACTION_TYPE = ActionType(NAME, ::CreateSimpleSchemaDomainResponse) | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
override fun executeRequest( | ||
request: CreateSimpleSchemaDomainRequest, | ||
user: User? | ||
): CreateSimpleSchemaDomainResponse { | ||
return SimpleSchemaDomainActions.create(request, user) | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...ice/src/main/kotlin/org/opensearch/simpleschema/action/CreateSimpleSchemaDomainRequest.kt
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,106 @@ | ||
package org.opensearch.simpleschema.action | ||
|
||
import org.opensearch.action.ActionRequest | ||
import org.opensearch.action.ActionRequestValidationException | ||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.Writeable | ||
import org.opensearch.common.xcontent.ToXContentObject | ||
import org.opensearch.common.xcontent.XContentParser | ||
import org.opensearch.common.xcontent.XContentBuilder | ||
import org.opensearch.common.xcontent.ToXContent | ||
import org.opensearch.common.xcontent.XContentParserUtils | ||
import org.opensearch.commons.utils.logger | ||
import org.opensearch.commons.utils.stringList | ||
import org.opensearch.simpleschema.domain.DomainRepository | ||
import org.opensearch.simpleschema.domain.DomainResource | ||
import org.opensearch.simpleschema.model.RestTag | ||
import org.opensearch.simpleschema.model.SchemaCompilationType | ||
import java.io.IOException | ||
|
||
internal class CreateSimpleSchemaDomainRequest : ActionRequest, ToXContentObject { | ||
val name: String | ||
val entities: List<String> | ||
|
||
companion object { | ||
private val log by logger(CreateSimpleSchemaDomainRequest::class.java) | ||
|
||
/** | ||
* reader to create instance of class from writable. | ||
*/ | ||
val reader = Writeable.Reader { CreateSimpleSchemaDomainRequest(it) } | ||
|
||
/** | ||
* Creator used in REST communication. | ||
* @param parser XContentParser to deserialize data from. | ||
*/ | ||
@JvmStatic | ||
@Throws(IOException::class) | ||
fun parse(parser: XContentParser): CreateSimpleSchemaDomainRequest { | ||
var name: String? = null | ||
var entities: List<String>? = null | ||
|
||
XContentParserUtils.ensureExpectedToken( | ||
XContentParser.Token.START_OBJECT, | ||
parser.currentToken(), | ||
parser | ||
) | ||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
val fieldName = parser.currentName() | ||
parser.nextToken() | ||
when (fieldName) { | ||
RestTag.NAME_FIELD -> name = parser.text() | ||
RestTag.ENTITY_LIST_FIELD -> entities = parser.stringList() | ||
else -> { | ||
parser.skipChildren() | ||
log.info("Unexpected field: $fieldName, while parsing CreateDomainRequest") | ||
} | ||
} | ||
} | ||
name ?: throw IllegalArgumentException("Required field '${RestTag.NAME_FIELD}' is absent") | ||
entities ?: throw IllegalArgumentException("Required field '${RestTag.ENTITY_LIST_FIELD}' is absent") | ||
return CreateSimpleSchemaDomainRequest(name, entities) | ||
} | ||
} | ||
|
||
constructor(name: String, entities: List<String>) { | ||
this.name = name | ||
this.entities = entities | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Throws(IOException::class) | ||
constructor(input: StreamInput) : super(input) { | ||
name = input.readString() | ||
entities = input.readStringList() | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
override fun validate(): ActionRequestValidationException? { | ||
// TODO currently no validation | ||
return null | ||
Swiddis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder { | ||
builder!! | ||
builder.startObject() | ||
.field(RestTag.NAME_FIELD, name) | ||
.field(RestTag.ENTITY_LIST_FIELD, entities) | ||
val domain = DomainRepository.getDomain(name) | ||
if (domain != null) { | ||
builder.field("domain") | ||
domain.toXContent(builder, params) | ||
} | ||
return builder.endObject() | ||
} | ||
|
||
fun toObjectData(): SchemaCompilationType { | ||
return SchemaCompilationType(name, entities, null, null) | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...ce/src/main/kotlin/org/opensearch/simpleschema/action/CreateSimpleSchemaDomainResponse.kt
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,62 @@ | ||
package org.opensearch.simpleschema.action | ||
|
||
import org.opensearch.common.io.stream.StreamInput | ||
import org.opensearch.common.io.stream.StreamOutput | ||
import org.opensearch.common.io.stream.Writeable | ||
import org.opensearch.common.xcontent.ToXContent | ||
import org.opensearch.common.xcontent.XContentBuilder | ||
import org.opensearch.common.xcontent.XContentParser | ||
import org.opensearch.common.xcontent.XContentParserUtils | ||
import org.opensearch.commons.utils.logger | ||
import org.opensearch.simpleschema.domain.DomainRepository | ||
import org.opensearch.simpleschema.model.BaseResponse | ||
import org.opensearch.simpleschema.model.RestTag | ||
import java.io.IOException | ||
|
||
internal class CreateSimpleSchemaDomainResponse : BaseResponse { | ||
private var objectId: String | ||
Swiddis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private var name: String | ||
private var entities: List<String> | ||
|
||
/** | ||
* constructor for creating the class | ||
* @param id the id of the created Object | ||
*/ | ||
constructor(objectId: String, name: String, entities: List<String>) { | ||
this.objectId = objectId | ||
this.name = name | ||
this.entities = entities | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Throws(IOException::class) | ||
constructor(input: StreamInput) : super(input) { | ||
objectId = input.readString() | ||
name = input.readString() | ||
entities = input.readStringList() | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Throws(IOException::class) | ||
override fun writeTo(output: StreamOutput) { | ||
output.writeString(objectId) | ||
output.writeString(name) | ||
output.writeStringArray(entities.toTypedArray()) | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
override fun toXContent(builder: XContentBuilder?, params: ToXContent.Params?): XContentBuilder { | ||
builder!! | ||
return builder.startObject() | ||
.field(RestTag.OBJECT_ID_FIELD, objectId) | ||
.field(RestTag.NAME_FIELD, name) | ||
.field(RestTag.ENTITY_LIST_FIELD, entities) | ||
.endObject() | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
service/src/main/kotlin/org/opensearch/simpleschema/action/GetSimpleSchemaDomainAction.kt
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,37 @@ | ||
package org.opensearch.simpleschema.action | ||
|
||
import org.opensearch.action.ActionType | ||
import org.opensearch.action.support.ActionFilters | ||
import org.opensearch.client.Client | ||
import org.opensearch.common.inject.Inject | ||
import org.opensearch.common.xcontent.NamedXContentRegistry | ||
import org.opensearch.commons.authuser.User | ||
import org.opensearch.transport.TransportService | ||
|
||
internal class GetSimpleSchemaDomainAction @Inject constructor( | ||
transportService: TransportService, | ||
client: Client, | ||
actionFilters: ActionFilters, | ||
val xContentRegistry: NamedXContentRegistry | ||
) : PluginBaseAction<GetSimpleSchemaDomainRequest, GetSimpleSchemaDomainResponse>( | ||
NAME, | ||
transportService, | ||
client, | ||
actionFilters, | ||
::GetSimpleSchemaDomainRequest | ||
) { | ||
companion object { | ||
private const val NAME = "cluster:admin/opensearch/simpleschema/domain/get" | ||
internal val ACTION_TYPE = ActionType(NAME, ::GetSimpleSchemaDomainResponse) | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
override fun executeRequest( | ||
request: GetSimpleSchemaDomainRequest, | ||
user: User? | ||
): GetSimpleSchemaDomainResponse { | ||
return SimpleSchemaDomainActions.get(request, user) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change objectId to name