Skip to content
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

C2-2432: implement create namespace (database) command #88

Merged
merged 4 commits into from
Feb 10, 2023

Conversation

ivansenic
Copy link
Contributor

Implementation of the create namespace (database) command, allows creation of the new Cassandra keyspace.

Since there were no specifications for this command, I created a general endpoint that is a simple v1. I also did a small refactoring of the command hierarchy, so that is clear that each endpoint can get specific command (currently you could send a create collection command to a documents endpoint btw).

Other than that, it's pretty simple with a lot of tests and swagger updates.

@ivansenic ivansenic requested a review from a team as a code owner February 9, 2023 15:10
@Consumes(MediaType.APPLICATION_JSON)
@SecurityRequirement(name = OpenApiConstants.SecuritySchemes.TOKEN)
@Tag(ref = "General")
public class GeneralResource {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this as NamespaceResource? General resource doesn't convey what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not fit, we already have a DatabaseResource I followed the logic:

  • /v1 - GeneralResurce
  • /v1/{database} - DatabaseResource
  • /v1/{database}/{collection} - CollectionResource

That would mean that we would have database resource and namespace resource, but they are both actually the same..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be

/v1 - GeneralResource
/v1/{namespace} - NamespaceResource
/v1/{namespace}/{collection} - CollectionResource

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK but this database to namespace change is huge and needs a separate PR imo.. WIll create a ticket..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#93

@Override
public Operation resolveCommand(CommandContext ctx, CreateDatabaseCommand command) {
String replicationMap = getReplicationMap(command.options());
return new CreateDatabaseOperation(command.name(), replicationMap);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail for Astra DB because create key space is disabled, can we have this Operation injected, so we can create custom implementation for Astra?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to have it injected we can have if/else here based on the prop, just return different op for astra

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we handle this in other APIs? Do we actually have Astra-specific code in those APIs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, operation simply fails on Astra with an error message. But I think our ITs must be excluding keyspace creation tests.

If I remember correctly, integration tests also cannot actually reliably detect running on Astra/CNDB; it is considered "DSE" as far as C-3.11/C-4/DSE classification is concerned. So we mostly have longer exclusion lists in maven pom.xmls on cndb side (or similar CI yaml files) to skip what needs to be skipped.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and our other APIs do not implement any logic to restrict access to creating keyspaces. The enforcement of this in Astra is through permission checks, such that any request to create a keyspace currently gets an "unauthorized" error. This is a function of the authorization provider at a lower tier of the architecture (i.e. enforced in coordinator).

Therefore what has been implemented here is fine. We do not need or want a custom implementation of this operation for Astra. If Astra changes its policy in the future to allow keyspace creation, the operation will succeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In CNDB integration tests we have -Dstargate.auth.astra_allowed_orgs=testOrganization.. The whitelisted organizations can create keyspaces..

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about the architecture to give this a full review, but looks good overall. My only concern is naming: createDatabase() or createNamespace()? Or createKeyspace()? I see 'database' and 'namespace' used in this PR.

@jeffreyscarpenter
Copy link
Contributor

Since there were no specifications for this command, I created a general endpoint that is a simple v1.

While not a full specification, there is at least a partial one: https://github.com/stargate/jsonapi/blob/main/docs/jsonapi-network-spec.textile#namespace-endpoint

Copy link
Contributor

@tatu-at-datastax tatu-at-datastax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general (and great testing!) but we do need to figure out what to do wrt Astra and inability to actually create keyspaces via Bridge/cql.

@jeffreyscarpenter
Copy link
Contributor

jeffreyscarpenter commented Feb 9, 2023

we do need to figure out what to do wrt Astra and inability to actually create keyspaces via Bridge/cql.

Referencing my other comment above, no changes are required.

@ivansenic
Copy link
Contributor Author

I don't know enough about the architecture to give this a full review, but looks good overall. My only concern is naming: createDatabase() or createNamespace()? Or createKeyspace()? I see 'database' and 'namespace' used in this PR.

@vkarpov15 To be addressed in #93

@ivansenic
Copy link
Contributor Author

Since there were no specifications for this command, I created a general endpoint that is a simple v1.

While not a full specification, there is at least a partial one: https://github.com/stargate/jsonapi/blob/main/docs/jsonapi-network-spec.textile#namespace-endpoint

@jeffreyscarpenter The spec you pointed are for the /v1/{namespace} endpoint. I created a new endpoint /v1. For that one there is no spec, the complete create namespace was left from spec because Aaron said that's out of the scope..

@ivansenic ivansenic merged commit a58e4df into main Feb 10, 2023
@ivansenic ivansenic deleted the ise-c2-2432-create-namespace branch February 10, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants