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

Feature/1693 api v3 schema etc #2052

Merged
merged 60 commits into from
May 10, 2022
Merged

Conversation

dk1844
Copy link
Contributor

@dk1844 dk1844 commented Apr 14, 2022

Continuation of PR #2046

  • implements V3 API for MappingTables, Schemas, and PropDefs.

  • introduces Admin-level authorization for changing endpoints (POST/PUT/DELETE)

  • IT extended to support ⬆️ and also the test cases with incorrect auth-level (resulting with 403s)

  • Future work (not covered in this PR) = delete test cases (relies on assuring that the disable workflow works as expected) and used-in

Partially implements #1693

Release notes suggestion

/api-v3/{datasets|schemas|mapping-tables|property-defintions}/ Rest API V3 added. Includes checks on entities and is to be used externally. Schema is now updatable via entity payload as well (outside of attachment upload).

dk1844 added 30 commits March 7, 2022 15:35
…e contours, empty DatasetControllerV3 to test
 - login allowed at /api/login & /api-v3/login
 - v2/v3 BaseRestApiTest distinquished
…st and post-import + IT to prove correct behavior
…mport + IT to prove correct behavior - fix with common location processing with segment stripping (+normalization)
…ion} now works for # or 'latest' (IT = regression test)
…{name}/{version} and /{name}/latest - improved
…- supports latest for as version-expression, impl for datasets improved by actual existence checking + IT test cases for non-existing/non-latest queries
…properties - supports latest for as version-expression; get impl is unvalidated, put impl checks validity

 - login is now common, under /api/login for both v2 and v3 (did not work previously)
…properties - supports latest for as version-expression; get impl is unvalidated, put impl checks validity - extended for different validation cases

 - login is now common, under /api/login for both v2 and v3 (did not work previously)
…ture -> CompletableFuture (mistake reverted)
… added. IT mostly adjusted, but there are todos

 - DatasetServiceV3 introduced to carry difference in behavior to DatasetService. original entity validation has been divided into create-validation and regular-entity validation.
 - buildfix for VersionedModelServiceTest
…asets/dsName/version/rules, GET datasets/dsName/version/rules/# + IT
 - v2 ignores this added information
 - needs
Copy link
Contributor

@Zejnilovic Zejnilovic left a comment

Choose a reason for hiding this comment

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

I did not upload schema yet otherwise I think I check all the user facing paths.

current.setDescription(update.description).asInstanceOf[Schema]
}

/** final - override `updateWithFields` if needed */
Copy link
Contributor

Choose a reason for hiding this comment

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

What is updateWithFields ? I only see updateWithFieldsReplace or updateFields

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing, updateFields was previously named updateWithFields and this reference was not correctly affected by the change. Fixed.


import scala.concurrent.ExecutionContext.Implicits.global

@GetMapping(path = Array("/{name}/{version}/defaults"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for my ignorance. Why we need dedicated endpoint for mapping table defaults? Isn't it enough to be part of the mapping table entity?
Maybe more a question to @Zejnilovic, as I see it in the proposal doc too.

Copy link
Contributor

Choose a reason for hiding this comment

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

For GET - because spark-jobs pull that data on the run of the conformance rule, in the middle of the job.
For POST - so you do not have to always update the whole thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the proposal contained it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

GET - 👍
PUT - Why is this different from other partial properties? (Minor, can stay 😉 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sort of explained in person, the gist is: a special approach is warranted due to the fact that defaults are added in now. But true that the whole endpoint may not be strictly necessary for V3 API.

Since it was designed like this, I'd like to keep it, but removal should be quite easy. 😏


@PutMapping(path = Array("/{name}/{version}/defaults"))
@ResponseStatus(HttpStatus.CREATED)
@PreAuthorize("@authConstants.hasAdminRole(authentication)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the admin authorization requirement (multiple places)?

Copy link
Contributor Author

@dk1844 dk1844 May 5, 2022

Choose a reason for hiding this comment

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

This is a mistake I plan on fixing in #2055, because there are other changes to the admin authorization that need to be done (In short: I have moved the admin-auth to VersionedModelController, but it wrong as only the PropDefs should be admin-controlled)

I have fixed this in this PR already, there will be just touchups in #2055.

Comment on lines 78 to 85
for {
existingMtOpt <- forVersionExpression(name, version)(mappingTableService.getVersion)
existingMt = existingMtOpt.getOrElse(throw notFound())
updatedMtAndValidationOpt <- mappingTableService.addDefault(user.getUsername, name, existingMt.version, newDefault)
(updatedMt, validation) = updatedMtAndValidationOpt.getOrElse(throw notFound())
response = createdWithNameVersionLocationBuilder(name, updatedMt.version, request,
stripLastSegments = 3, suffix = s"/defaults").body(validation) // stripping: /{name}/{version}/defaults
} yield response
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like the same code as above?

Copy link
Contributor Author

@dk1844 dk1844 May 5, 2022

Choose a reason for hiding this comment

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

mt-ctrl-v3-diff

While not completely the same, there are not a lot of differences, I admit.
It did not seem like something worth generalizing to me (do you think it is?)

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤷 Up to you, sorry I missed the difference. On the other hand it suggests similarity. Counter argument is, if the code can be logically distilled not just some forced sub-function.

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, I have actually created a subfunction that seems to make sense. Hope you find it a tad better, @benedeki.

class PropertyDefinitionControllerV3 @Autowired()(propertyDefService: PropertyDefinitionService)
extends VersionedModelControllerV3(propertyDefService)

// super-class implementation is sufficient
Copy link
Collaborator

Choose a reason for hiding this comment

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

Appreciate the comment 😎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Glad you liked it, but I actually had to redo it

import za.co.absa.enceladus.rest_api.models.rest.exceptions.SchemaParsingException
import za.co.absa.enceladus.rest_api.repositories.RefCollection
import za.co.absa.enceladus.rest_api.services.v3.SchemaServiceV3
import za.co.absa.enceladus.rest_api.services.{AttachmentService, SchemaRegistryService, SchemaService}
Copy link
Collaborator

Choose a reason for hiding this comment

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

SchemaService is not used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, thanks, removed.

dk1844 added 4 commits May 5, 2022 12:39
…authentication)")` is now limited to changing endpoints of PropertyDefinitionControllerV3 (previously it was incorrectly used for all changing endpoints. IT updated. And specific check for the adminRole have been added to PropertyDefinitionControllerV3IntegrationSuite.
@dk1844 dk1844 requested a review from benedeki May 6, 2022 12:22
@dk1844 dk1844 requested a review from Zejnilovic May 9, 2022 08:13
benedeki
benedeki previously approved these changes May 9, 2022
Copy link
Collaborator

@benedeki benedeki left a comment

Choose a reason for hiding this comment

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

Just read the code. Comments are not blocking.


import scala.concurrent.ExecutionContext.Implicits.global

@GetMapping(path = Array("/{name}/{version}/defaults"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

GET - 👍
PUT - Why is this different from other partial properties? (Minor, can stay 😉 )

Comment on lines 78 to 85
for {
existingMtOpt <- forVersionExpression(name, version)(mappingTableService.getVersion)
existingMt = existingMtOpt.getOrElse(throw notFound())
updatedMtAndValidationOpt <- mappingTableService.addDefault(user.getUsername, name, existingMt.version, newDefault)
(updatedMt, validation) = updatedMtAndValidationOpt.getOrElse(throw notFound())
response = createdWithNameVersionLocationBuilder(name, updatedMt.version, request,
stripLastSegments = 3, suffix = s"/defaults").body(validation) // stripping: /{name}/{version}/defaults
} yield response
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤷 Up to you, sorry I missed the difference. On the other hand it suggests similarity. Counter argument is, if the code can be logically distilled not just some forced sub-function.

Base automatically changed from feature/1693-api-v3-versioned-model to develop-ver-3.0 May 9, 2022 08:49
… with `MappingTableControllerV3.withMappingTableToResponse`
% Conflicts:
%	rest-api/src/main/scala/za/co/absa/enceladus/rest_api/controllers/SchemaController.scala
%	rest-api/src/main/scala/za/co/absa/enceladus/rest_api/controllers/v3/VersionedModelControllerV3.scala
%	rest-api/src/main/scala/za/co/absa/enceladus/rest_api/services/SchemaService.scala
%	rest-api/src/main/scala/za/co/absa/enceladus/rest_api/services/VersionedModelService.scala
%	rest-api/src/test/scala/za/co/absa/enceladus/rest_api/integration/controllers/v3/DatasetControllerV3IntegrationSuite.scala
@sonarcloud
Copy link

sonarcloud bot commented May 9, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 24 Code Smells

No Coverage information No Coverage information
2.6% 2.6% Duplication

Copy link
Contributor

@Zejnilovic Zejnilovic left a comment

Choose a reason for hiding this comment

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

Tested the endpoints.
Code reviewed

@Zejnilovic Zejnilovic added the PR:tested Only for PR - PR was tested by a tester (person) label May 10, 2022
Copy link
Contributor

@AdrianOlosutean AdrianOlosutean 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

@dk1844 dk1844 merged commit 0576893 into develop-ver-3.0 May 10, 2022
@dk1844 dk1844 deleted the feature/1693-api-v3-schema-etc branch May 10, 2022 09:28
@dk1844 dk1844 linked an issue Jun 7, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR:tested Only for PR - PR was tested by a tester (person)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experimental API 3 - Versioned Model
4 participants