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

Storage: use JSON schema to structure data and spawn GraphQL interface #392

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5ecb68e
See next commit for commit information. Commited due to computer switch
LechoDecho Jun 21, 2021
b589d52
removed imports. Added jsonschema validator to adapter. Healthcheck i…
LechoDecho Jun 22, 2021
dbc8a71
reworked validation. Also convertring into a JSONObject works now
LechoDecho Jun 22, 2021
6f6c4fb
unwanted removal of a maven import
LechoDecho Jun 22, 2021
1869d12
fixed linting
LechoDecho Jun 23, 2021
2e114fd
validation now fully supported. Error messages are saved and show the…
LechoDecho Jun 26, 2021
42102ae
fixed pipeline interaction with warning status of data
LechoDecho Jun 27, 2021
eb43af0
Staged changes. Adding schema to pipline
LechoDecho Jun 30, 2021
88c0df3
added schema to pipeline UI. schema is stored inside the DB
LechoDecho Jul 4, 2021
724d784
schema is now correctly pushed into amqp
LechoDecho Jul 4, 2021
094ed65
maybe fixed integration test
LechoDecho Jul 6, 2021
4a92458
Model and DB integration for tranformed data by pipeline added. Valid…
LechoDecho Jul 7, 2021
09b4b7d
added ui support for pipeline healthstatus. API not available due to …
LechoDecho Jul 8, 2021
89a1683
small adjustments. Testing pipeline
LechoDecho Jul 8, 2021
da988fd
Pipeline UI is now reactive
LechoDecho Jul 10, 2021
88f3e0b
Adjusted error message handling for schema validation
LechoDecho Jul 11, 2021
0f2e1e9
merge conflict
LechoDecho Jul 11, 2021
ce228fa
Validator refactored and now interchangable. Tests added
LechoDecho Jul 11, 2021
dea7562
removed start.sh
LechoDecho Jul 11, 2021
d24fa64
refactoring. Validator has now a parent class for abstraction.
LechoDecho Jul 12, 2021
797dd36
Added CustomType for String arrays
LechoDecho Jul 28, 2021
82eed58
removed prints
LechoDecho Jul 28, 2021
9c84baa
removed STDOUT for tests
LechoDecho Jul 28, 2021
feec027
commented adminer
LechoDecho Jul 28, 2021
72369e1
Added first steps for schema to postgress support. WIP
LechoDecho Jul 31, 2021
ca8acf3
Insert algorithm added
LechoDecho Aug 7, 2021
13c9a5c
Merge
LechoDecho Aug 8, 2021
0c5c867
Merge branch 'WP5_PG' into WP5WITH4
LechoDecho Aug 8, 2021
374cf20
Merge branch 'main' into WP5WITH4
LechoDecho Aug 11, 2021
ca44add
merge
LechoDecho Aug 11, 2021
862df76
added WP4 and WP3
LechoDecho Aug 12, 2021
3362561
small fixes
LechoDecho Aug 12, 2021
6bf2c69
insertion added. Graphql added
LechoDecho Aug 14, 2021
ec085b3
schema is fully optional
LechoDecho Aug 14, 2021
5c88eb9
necessary step for renaming file
LechoDecho Aug 14, 2021
073406a
renamed file
LechoDecho Aug 14, 2021
999b2cf
schemas are editable now and better abstraction
LechoDecho Aug 20, 2021
8bb28a3
Add graphql service to CI
georg-schwarz Aug 23, 2021
2a4b4a1
CI: publish graphql image
georg-schwarz Aug 23, 2021
0b8b479
small fixes for docker-compose
LechoDecho Aug 23, 2021
99d442a
fix for the PGGeneration schema
LechoDecho Aug 23, 2021
f89460c
refactoring
LechoDecho Aug 23, 2021
5a0f625
Merge remote-tracking branch 'origin/main' into db-json-schema
f3l1x98 Dec 9, 2021
c874475
Fixed all linter issues
f3l1x98 Dec 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ods.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
docker-compose -f docker-compose.yml build storage
docker-compose -f docker-compose.yml build storage-db-liquibase
docker-compose -f docker-compose.yml build storage-mq
docker-compose -f docker-compose.yml build graphql

- name: Build Integration-test
run: |
Expand All @@ -117,10 +118,12 @@ jobs:
IMAGE_ID_STORAGE=$(sed -n 's/^DOCKER_REGISTRY=//p' .env)/storage
IMAGE_ID_LIQUIBASE=$(sed -n 's/^DOCKER_REGISTRY=//p' .env)/storage-db-liquibase
IMAGE_ID_STORAGEMQ=$(sed -n 's/^DOCKER_REGISTRY=//p' .env)/storage-mq
IMAGE_ID_STORAGE_GRAPHQL=$(sed -n 's/^DOCKER_REGISTRY=//p' .env)/storage-graphql

docker save $IMAGE_ID_STORAGE > storage_postgrest.tar
docker save $IMAGE_ID_LIQUIBASE > storage_liquibase.tar
docker save $IMAGE_ID_STORAGEMQ > storage_mq.tar
docker save $IMAGE_ID_STORAGE_GRAPHQL > storage_graphql.tar

- name: Upload Storage Docker image as artifact
uses: actions/upload-artifact@v1
Expand All @@ -140,6 +143,12 @@ jobs:
name: storagemq-artifact
path: storage_mq.tar

- name: Upload Storage-GraphQL Docker image as artifact
uses: actions/upload-artifact@v1
with:
name: storagegraphql-artifact
path: storage_graphql.tar

# The CDC-Test builds a cut-down image that would override the previously built production image
# Therefore it is executed after uploading the production image
- name: Consumer-side CDC-Test
Expand Down Expand Up @@ -477,13 +486,18 @@ jobs:
uses: actions/download-artifact@v1
with:
name: storagemq-artifact
- name: Download storage-graphql artifact
uses: actions/download-artifact@v1
with:
name: storagegraphql-artifact

- name: Load Docker Images from artifacts
run: |

docker load -i ./storage-artifact/storage_postgrest.tar
docker load -i ./liquibase-artifact/storage_liquibase.tar
docker load -i ./storagemq-artifact/storage_mq.tar
docker load -i ./storagegraphql-artifact/storage_graphql.tar

- name: Storage Push to registry
run: |
Expand All @@ -498,6 +512,7 @@ jobs:
IMAGE_ID_STORAGE=$(sed -n 's/^DOCKER_REGISTRY=//p' .env)/storage
IMAGE_ID_LIQUIBASE=$(sed -n 's/^DOCKER_REGISTRY=//p' .env)/storage-db-liquibase
IMAGE_ID_STORAGE_MQ=$(sed -n 's/^DOCKER_REGISTRY=//p' .env)/storage-mq
IMAGE_ID_STORAGE_GRAPHQL=$(sed -n 's/^DOCKER_REGISTRY=//p' .env)/storage-graphql

docker tag $IMAGE_ID_STORAGE $IMAGE_ID_STORAGE:$STORAGE_VERSION
docker tag $IMAGE_ID_STORAGE $IMAGE_ID_STORAGE:latest
Expand All @@ -508,6 +523,9 @@ jobs:
docker tag $IMAGE_ID_STORAGE_MQ $IMAGE_ID_STORAGE_MQ:$STORAGE_VERSION
docker tag $IMAGE_ID_STORAGE_MQ $IMAGE_ID_STORAGE_MQ:latest

docker tag $IMAGE_ID_STORAGE_GRAPHQL $IMAGE_ID_STORAGE_GRAPHQL:$STORAGE_VERSION
docker tag $IMAGE_ID_STORAGE_GRAPHQL $IMAGE_ID_STORAGE_GRAPHQL:latest

docker push $IMAGE_ID_STORAGE:$STORAGE_VERSION
docker push $IMAGE_ID_STORAGE:latest

Expand All @@ -517,6 +535,9 @@ jobs:
docker push $IMAGE_ID_STORAGE_MQ:$STORAGE_VERSION
docker push $IMAGE_ID_STORAGE_MQ:latest

docker push $IMAGE_ID_STORAGE_GRAPHQL:$STORAGE_VERSION
docker push $IMAGE_ID_STORAGE_GRAPHQL:latest

pipeline_upload:
name: Pipeline Publish
runs-on: ubuntu-18.04
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jvalue.ods.adapterservice.datasource.repository.DatasourceRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.everit.json.schema.ValidationException;

import org.jvalue.ods.adapterservice.datasource.validator.*;

Expand Down Expand Up @@ -100,7 +101,7 @@ public DataImport.MetaData trigger(Long id, RuntimeParameters runtimeParameters)
*/
@Transactional
DataImport.MetaData executeImport(Long id, RuntimeParameters runtimeParameters)
throws DatasourceNotFoundException, ImporterParameterException, InterpreterParameterException, IOException {
throws DatasourceNotFoundException, ImporterParameterException, InterpreterParameterException, IOException {
Datasource datasource = getDatasource(id);
DataImport dataImport = new DataImport(datasource, "", ValidationMetaData.HealthStatus.FAILED);
Validator validator = new JsonSchemaValidator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Object deepCopy(Object value) {
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
}

@Override
public boolean equals(Object x, Object y) throws HibernateException {
return x.equals(y);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package org.jvalue.ods.adapterservice.datasource.validator;

import org.jvalue.ods.adapterservice.datasource.validator.ValidationMetaData;
import org.jvalue.ods.adapterservice.datasource.model.*;
import org.jvalue.ods.adapterservice.datasource.model.exceptions.*;
import java.io.IOException;
import org.everit.json.schema.ValidationException;

import org.everit.json.schema.Schema;
import org.everit.json.schema.loader.SchemaLoader;

import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.Arrays;
import com.google.gson.Gson;

public class JsonSchemaValidator implements Validator {
Expand All @@ -29,7 +35,6 @@ public ValidationMetaData validate(DataImport dataImport){
else {
schema.validate(new JSONObject(dataImport.getData()));
}

validationMetaData.setHealthStatus(ValidationMetaData.HealthStatus.OK);
return validationMetaData;
} catch ( ValidationException e) {
Expand Down
21 changes: 16 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ services:
build: ./storage/storage-mq/
environment:
CONNECTION_RETRIES: 30
CONNECTION_BACKOFF_IN_MS: 2000
CONNECTION_BACKOFF_IN_MS: 20000

POSTGRES_HOST: storage-db
POSTGRES_PORT: 5432
Expand Down Expand Up @@ -221,15 +221,26 @@ services:
POSTGRES_DB: ods
POSTGRES_USER: ods_admin
POSTGRES_PASSWORD: ods_pw

graphql:
image: ${DOCKER_REGISTRY}/storage-graphql
build: ./storage/storage-graphql/
depends_on:
- storage-db
- storage-db-liquibase
ports:
- 5432:5432
command: ["--connection", postgres://ods_admin:ods_pw@storage-db:5432/ods, "--port", "5432", "--schema", "storage", "--append-plugins", "postgraphile-plugin-connection-filter"]

# Uncomment this if you want to persist the data.
# volumes:
# - "./pgdata:/var/lib/postgresql/data"

# Uncomment this if you want to manage the Postgres databases with adminer
# adminer: # management UI for Postgres
# image: adminer
# ports:
# - 8081:8080
adminer: # management UI for Postgres
image: adminer
ports:
- 8081:8080

storage-db-liquibase: # perform database migration on start up
image: ${DOCKER_REGISTRY}/storage-db-liquibase
Expand Down
2 changes: 2 additions & 0 deletions pipeline/src/pipeline-config/outboxEventPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ export async function publishCreation(
client: ClientBase,
pipelineId: number,
pipelineName: string,
schema?: Record<string, unknown>,
): Promise<string> {
const content = {
pipelineId: pipelineId,
pipelineName: pipelineName,
schema: schema != null ? schema : undefined,
};
return await insertEvent(client, AMQP_PIPELINE_CONFIG_CREATED_TOPIC, content);
}
Expand Down
1 change: 1 addition & 0 deletions pipeline/src/pipeline-config/pipelineConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class PipelineConfigManager {
client,
savedConfig.id,
savedConfig.metadata.displayName,
savedConfig.schema,
);
return savedConfig;
});
Expand Down
8 changes: 8 additions & 0 deletions storage/storage-graphql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:alpine

# Install PostGraphile and PostGraphile connection filter plugin
RUN npm install -g postgraphile
RUN npm install -g postgraphile-plugin-connection-filter

EXPOSE 5000
ENTRYPOINT ["postgraphile", "-n", "0.0.0.0"]
Empty file modified storage/storage-mq/cdct-consumer.sh
100644 → 100755
Empty file.
35 changes: 3 additions & 32 deletions storage/storage-mq/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions storage/storage-mq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@jvalue/node-dry-amqp": "0.1.2",
"@jvalue/node-dry-basics": "0.0.3",
"@jvalue/node-dry-pg": "1.2.1",
"@types/json-schema": "^7.0.9",
"cors": "^2.8.5",
"express": "^4.17.1"
},
Expand Down
9 changes: 9 additions & 0 deletions storage/storage-mq/src/api/pipelineConfigEventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { JsonSchemaElementBase, isDefined } from '../service/sharedHelper';
import { StorageStructureRepository } from '../storage-structure/storageStructureRepository';

export class PipelineConfigEventHandler {
Expand All @@ -11,6 +12,13 @@ export class PipelineConfigEventHandler {
await this.structureRepository.create(
pipelineCreatedEvent.pipelineId.toString(),
);
if (isDefined(pipelineCreatedEvent.schema)) {
await this.structureRepository.createForSchema(
pipelineCreatedEvent.schema,
pipelineCreatedEvent.pipelineName +
pipelineCreatedEvent.pipelineId.toString(),
);
}
}

async handleDeletion(
Expand All @@ -25,6 +33,7 @@ export class PipelineConfigEventHandler {
export interface PipelineCreatedEvent {
pipelineId: number;
pipelineName: string;
schema?: JsonSchemaElementBase;
}

export interface PipelineDeletedEvent {
Expand Down
15 changes: 14 additions & 1 deletion storage/storage-mq/src/api/pipelineExecutionEventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { JsonSchemaElementBase, isDefined } from '../service/sharedHelper';
import { StorageContentRepository } from '../storage-content/storageContentRepository';

export class PipelineExecutionEventHandler {
Expand All @@ -14,13 +15,25 @@ export class PipelineExecutionEventHandler {
data: pipelineExecutedEvent.data,
},
);
if (isDefined(pipelineExecutedEvent.schema)) {
await this.contentRepository.saveContentForSchema(
pipelineExecutedEvent.pipelineName +
pipelineExecutedEvent.pipelineId.toString(),
{
pipelineId: pipelineExecutedEvent.pipelineId,
timestamp: pipelineExecutedEvent.timestamp ?? new Date(),
data: pipelineExecutedEvent.data,
schema: pipelineExecutedEvent.schema,
},
);
}
}
}

export interface PipelineExecutedEvent {
pipelineId: number;
pipelineName: string;
data: unknown;
schema?: Record<string, unknown>;
schema?: JsonSchemaElementBase;
timestamp?: Date;
}
Loading