Skip to content

Commit

Permalink
Add entity and storage classes for user metadata (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
raveeram committed Nov 9, 2021
1 parent ff51438 commit 9a500ff
Show file tree
Hide file tree
Showing 33 changed files with 983 additions and 13 deletions.
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;
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 {
}
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 {
}
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;
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 metacat-metadata/src/functionalTest/resources/crdb/schema.sql
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)
);
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
*/

/**
* Metacat Metadata classes.
* Metacat User metadata classes.
*/
package com.netflix.metacat.metadata;

This file was deleted.

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;
}
}
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();
}
}
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;
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);
}
}
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);
}
}
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;
Loading

0 comments on commit 9a500ff

Please sign in to comment.