-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add entity and storage classes for user metadata (#477)
- Loading branch information
Showing
33 changed files
with
983 additions
and
13 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...etadata/src/functionalTest/java/com/netflix/metacat/metadata/store/data/package-info.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,22 @@ | ||
/* | ||
* | ||
* Copyright 2021 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/** | ||
* Metacat Metadata test classes. | ||
*/ | ||
package com.netflix.metacat.metadata.store.data; |
18 changes: 18 additions & 0 deletions
18
...com/netflix/metacat/metadata/store/data/repositories/CrdbDataMetadataRepositoryTests.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,18 @@ | ||
//CHECKSTYLE:OFF | ||
package com.netflix.metacat.metadata.store.data.repositories; | ||
|
||
import com.netflix.metacat.metadata.store.configs.UserMetadataStoreConfig; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(classes = {UserMetadataStoreConfig.class}) | ||
@ActiveProfiles(profiles = {"usermetadata-crdb"}) | ||
@Transactional | ||
@AutoConfigureDataJpa | ||
public class CrdbDataMetadataRepositoryTests extends DataMetadataRepositoryTests { | ||
} |
18 changes: 18 additions & 0 deletions
18
...tflix/metacat/metadata/store/data/repositories/CrdbDefinitionMetadataRepositoryTests.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,18 @@ | ||
//CHECKSTYLE:OFF | ||
package com.netflix.metacat.metadata.store.data.repositories; | ||
|
||
import com.netflix.metacat.metadata.store.configs.UserMetadataStoreConfig; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(classes = {UserMetadataStoreConfig.class}) | ||
@ActiveProfiles(profiles = {"usermetadata-crdb"}) | ||
@Transactional | ||
@AutoConfigureDataJpa | ||
public class CrdbDefinitionMetadataRepositoryTests extends DefinitionMetadataRepositoryTests { | ||
} |
22 changes: 22 additions & 0 deletions
22
...unctionalTest/java/com/netflix/metacat/metadata/store/data/repositories/package-info.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,22 @@ | ||
/* | ||
* | ||
* Copyright 2021 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/** | ||
* Metacat Metadata repository test classes. | ||
*/ | ||
package com.netflix.metacat.metadata.store.data.repositories; |
23 changes: 23 additions & 0 deletions
23
metacat-metadata/src/functionalTest/resources/application-usermetadata-crdb.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,23 @@ | ||
spring: | ||
datasource: | ||
platform: crdb | ||
url: jdbc:postgresql:https://127.0.0.1:26257/defaultdb?sslmode=disable | ||
username: admin | ||
password: | ||
schema: classpath:/crdb/schema.sql | ||
initialization-mode: always | ||
driverClassName: org.postgresql.Driver | ||
hikari: | ||
connection-timeout: 5000 # 5 seconds | ||
max-lifetime: 580000 # 9 minutes 40 seconds | ||
data-source-properties: | ||
loginTimeout: 5 # 5 seconds | ||
socketTimeout: 30 # 30 seconds | ||
ApplicationName: polaris | ||
|
||
jpa: | ||
hibernate: | ||
ddl-auto: none | ||
properties: | ||
hibernate: | ||
dialect: org.hibernate.dialect.PostgreSQLDialect |
30 changes: 30 additions & 0 deletions
30
metacat-metadata/src/functionalTest/resources/crdb/schema.sql
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,30 @@ | ||
drop table if exists definition_metadata; | ||
drop table if exists data_metadata; | ||
|
||
create table definition_metadata ( | ||
id UUID NOT NULL DEFAULT gen_random_uuid(), | ||
name STRING(1024) not null, | ||
data JSON, | ||
version INT not null, | ||
is_deleted BOOL default FALSE not null, | ||
created_by STRING(255) not null, | ||
created_date TIMESTAMP not null, | ||
last_updated_by STRING(255) not null, | ||
last_updated_date TIMESTAMP not null, | ||
primary key (id), | ||
constraint definition_metadata_uq unique (name) | ||
); | ||
|
||
create table data_metadata ( | ||
id UUID NOT NULL DEFAULT gen_random_uuid(), | ||
uri STRING(4096) not null, | ||
data JSON, | ||
version INT not null, | ||
is_deleted BOOL default FALSE not null, | ||
created_by STRING(255) not null, | ||
created_date TIMESTAMP not null, | ||
last_updated_by STRING(255) not null, | ||
last_updated_date TIMESTAMP not null, | ||
primary key (id), | ||
constraint data_metadata_uq unique (uri) | ||
); |
40 changes: 40 additions & 0 deletions
40
metacat-metadata/src/main/java/com/netflix/metacat/metadata/UserMetadataServiceImpl.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,40 @@ | ||
package com.netflix.metacat.metadata; | ||
|
||
import com.netflix.metacat.common.json.MetacatJson; | ||
import com.netflix.metacat.common.server.properties.Config; | ||
import com.netflix.metacat.common.server.usermetadata.BaseUserMetadataService; | ||
import com.netflix.metacat.common.server.usermetadata.MetadataInterceptor; | ||
import com.netflix.metacat.metadata.store.UserMetadataStoreService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* The Hibernate-based User metadata service implementation. | ||
* | ||
* @author rveeramacheneni | ||
*/ | ||
public class UserMetadataServiceImpl extends BaseUserMetadataService { | ||
|
||
private final UserMetadataStoreService userMetadataStoreService; | ||
private final MetacatJson metacatJson; | ||
private final Config config; | ||
private final MetadataInterceptor metadataInterceptor; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param userMetadataStoreService The User metadata store service. | ||
* @param metacatJson The Metacat jackson JSON mapper. | ||
* @param config The config. | ||
* @param metadataInterceptor The metadata interceptor. | ||
*/ | ||
@Autowired | ||
public UserMetadataServiceImpl(final UserMetadataStoreService userMetadataStoreService, | ||
final MetacatJson metacatJson, | ||
final Config config, | ||
final MetadataInterceptor metadataInterceptor) { | ||
this.userMetadataStoreService = userMetadataStoreService; | ||
this.metacatJson = metacatJson; | ||
this.config = config; | ||
this.metadataInterceptor = metadataInterceptor; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -17,6 +17,6 @@ | |
*/ | ||
|
||
/** | ||
* Metacat Metadata classes. | ||
* Metacat User metadata classes. | ||
*/ | ||
package com.netflix.metacat.metadata; |
12 changes: 0 additions & 12 deletions
12
metacat-metadata/src/main/java/com/netflix/metacat/metadata/store/MetadataConnector.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...t-metadata/src/main/java/com/netflix/metacat/metadata/store/UserMetadataStoreService.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,32 @@ | ||
package com.netflix.metacat.metadata.store; | ||
|
||
import com.netflix.metacat.metadata.store.data.repositories.DataMetadataRepository; | ||
import com.netflix.metacat.metadata.store.data.repositories.DefinitionMetadataRepository; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
/** | ||
* Storage interface for user metadata entity operations. | ||
* | ||
* @author rveeramacheneni | ||
*/ | ||
@Slf4j | ||
public class UserMetadataStoreService { | ||
|
||
private final DefinitionMetadataRepository definitionMetadataRepository; | ||
private final DataMetadataRepository dataMetadataRepository; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param definitionMetadataRepository The definition metadata repository. | ||
* @param dataMetadataRepository The data metadata repository. | ||
*/ | ||
@Autowired | ||
public UserMetadataStoreService(@NonNull final DefinitionMetadataRepository definitionMetadataRepository, | ||
@NonNull final DataMetadataRepository dataMetadataRepository) { | ||
this.definitionMetadataRepository = definitionMetadataRepository; | ||
this.dataMetadataRepository = dataMetadataRepository; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ata/src/main/java/com/netflix/metacat/metadata/store/configs/UserMetadataStoreConfig.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,48 @@ | ||
package com.netflix.metacat.metadata.store.configs; | ||
|
||
import com.netflix.metacat.common.json.MetacatJson; | ||
import com.netflix.metacat.common.json.MetacatJsonLocator; | ||
import com.netflix.metacat.metadata.store.UserMetadataStoreService; | ||
import com.netflix.metacat.metadata.store.data.repositories.DataMetadataRepository; | ||
import com.netflix.metacat.metadata.store.data.repositories.DefinitionMetadataRepository; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.domain.EntityScan; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
/** | ||
* The user metadata store config. | ||
* | ||
* @author rveeramacheneni | ||
*/ | ||
@Configuration | ||
@EntityScan("com.netflix.metacat.metadata.store.data.*") | ||
@EnableJpaRepositories("com.netflix.metacat.metadata.store.data.*") | ||
public class UserMetadataStoreConfig { | ||
|
||
/** | ||
* The user metadata store service. | ||
* | ||
* @param definitionMetadataRepository The definition metadata repository. | ||
* @param dataMetadataRepository The data metadata repository. | ||
* @return the constructed bean. | ||
*/ | ||
@Bean | ||
public UserMetadataStoreService userMetadataStoreService( | ||
final DefinitionMetadataRepository definitionMetadataRepository, | ||
final DataMetadataRepository dataMetadataRepository) { | ||
return new UserMetadataStoreService(definitionMetadataRepository, dataMetadataRepository); | ||
} | ||
|
||
/** | ||
* Store metacat JSON Handler. | ||
* | ||
* @return The JSON handler | ||
*/ | ||
@Bean | ||
@ConditionalOnMissingBean(MetacatJson.class) | ||
public MetacatJson metacatJson() { | ||
return new MetacatJsonLocator(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
metacat-metadata/src/main/java/com/netflix/metacat/metadata/store/configs/package-info.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,22 @@ | ||
/* | ||
* | ||
* Copyright 2021 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/** | ||
* User metadata store config classes. | ||
*/ | ||
package com.netflix.metacat.metadata.store.configs; |
40 changes: 40 additions & 0 deletions
40
...src/main/java/com/netflix/metacat/metadata/store/data/converters/ObjectNodeConverter.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,40 @@ | ||
package com.netflix.metacat.metadata.store.data.converters; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.netflix.metacat.common.json.MetacatJson; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
|
||
/** | ||
* Attribute converter for Jackson ObjectNode type. | ||
* | ||
* @author rveeramacheneni | ||
*/ | ||
@Slf4j | ||
@Converter(autoApply = true) | ||
@SuppressWarnings("PMD") | ||
public class ObjectNodeConverter implements AttributeConverter<ObjectNode, String> { | ||
private final MetacatJson metacatJson; | ||
|
||
/** | ||
* Ctor. | ||
* | ||
* @param metacatJson the Jackson object mapper. | ||
*/ | ||
public ObjectNodeConverter(@NonNull final MetacatJson metacatJson) { | ||
this.metacatJson = metacatJson; | ||
} | ||
|
||
@Override | ||
public String convertToDatabaseColumn(final ObjectNode attribute) { | ||
return attribute == null ? null : attribute.toString(); | ||
} | ||
|
||
@Override | ||
public ObjectNode convertToEntityAttribute(final String dbData) { | ||
return dbData == null ? null : metacatJson.parseJsonObject(dbData); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../main/java/com/netflix/metacat/metadata/store/data/converters/QualifiedNameConverter.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,28 @@ | ||
package com.netflix.metacat.metadata.store.data.converters; | ||
|
||
import com.netflix.metacat.common.QualifiedName; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
|
||
/** | ||
* The attribute converter for the QualifiedName type. | ||
* | ||
* @author rveeramacheneni | ||
*/ | ||
@Slf4j | ||
@Converter(autoApply = true) | ||
@SuppressWarnings("PMD") | ||
public class QualifiedNameConverter implements AttributeConverter<QualifiedName, String> { | ||
|
||
@Override | ||
public String convertToDatabaseColumn(final QualifiedName attribute) { | ||
return attribute == null ? null : attribute.toString(); | ||
} | ||
|
||
@Override | ||
public QualifiedName convertToEntityAttribute(final String dbData) { | ||
return dbData == null ? null : QualifiedName.fromString(dbData); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...tadata/src/main/java/com/netflix/metacat/metadata/store/data/converters/package-info.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,22 @@ | ||
/* | ||
* | ||
* Copyright 2021 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/** | ||
* Metacat Metadata converter classes. | ||
*/ | ||
package com.netflix.metacat.metadata.store.data.converters; |
Oops, something went wrong.