Skip to content

Commit

Permalink
feat(EdrCache): module docs
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed May 24, 2023
1 parent 06706e2 commit f8afe79
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
30 changes: 30 additions & 0 deletions edc-extensions/edr-cache-sql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# SQL-based `EndpointDataReferenceCache` extension

This extensions provide a persistent implementation of `EndpointDataReferenceCache`.

It will store in the database this fields:

- tranferProcessId
- agreementId
- assetId
- edrId

It represent a single EDR negotiation done with the new Control Plane Adapter APIs.

The EDR itself it is stored in the participant vault with a prefixed key `edr:<edrId>`.

**_Note that the SQL statements (DDL) are specific to and only tested with PostgreSQL. Using it with other RDBMS may
work but might have unexpected side effects!_**

## 1. Table schema

see [schema.sql](docs/schema.sql).


## 2. Configuration

| Key | Description | Mandatory | Default |
|:---------------------------------------|:----------------------------------|-----------|---------|
| edc.datasource.edr.name | Datasource used by this extension | | edr |


Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.spi.security.Vault;
import org.eclipse.edc.spi.types.TypeManager;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.edc.sql.testfixtures.PostgresqlStoreSetupExtension;
import org.eclipse.tractusx.edc.edr.spi.EndpointDataReferenceCache;
import org.eclipse.tractusx.edc.edr.spi.EndpointDataReferenceCacheBaseTest;
Expand All @@ -34,7 +33,7 @@
import java.sql.SQLException;
import java.time.Clock;

import static org.eclipse.tractusx.edc.edr.store.sql.SqlEndpointDataReferenceCache.VAULT_PREFIX;
import static org.eclipse.tractusx.edc.edr.spi.TestFunctions.edr;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -58,18 +57,14 @@ void setUp(PostgresqlStoreSetupExtension extension) throws IOException {

when(vault.deleteSecret(any())).thenReturn(Result.success());
when(vault.storeSecret(any(), any())).thenReturn(Result.success());
when(vault.resolveSecret(any())).then(a -> edrJson(a.getArgument(0)));

cache = new SqlEndpointDataReferenceCache(extension.getDataSourceRegistry(), extension.getDatasourceName(), extension.getTransactionContext(), statements, typeManager.getMapper(), vault, clock);
var schema = Files.readString(Paths.get("./docs/schema.sql"));
extension.runQuery(schema);

}

@Override
protected void onBeforeEdrSave(EndpointDataReference edr) {
when(vault.resolveSecret(VAULT_PREFIX + edr.getId())).thenReturn(typeManager.writeValueAsString(edr));
}

@AfterEach
void tearDown(PostgresqlStoreSetupExtension extension) throws SQLException {
extension.runQuery("DROP TABLE " + statements.getEdrTable() + " CASCADE");
Expand All @@ -80,4 +75,9 @@ protected EndpointDataReferenceCache getStore() {
return cache;
}


private String edrJson(String id) {
return typeManager.writeValueAsString(edr(id.split(":")[1]));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void save() {
var edrId = "edr1";

var edr = edr(edrId);
onBeforeEdrSave(edr);
var entry = edrEntry(assetId, randomUUID().toString(), tpId);

getStore().save(entry, edr);
Expand Down Expand Up @@ -127,9 +126,5 @@ void deleteByTransferProcessId_shouldReturnError_whenNotFound() {
.extracting(StoreResult::reason)
.isEqualTo(StoreFailure.Reason.NOT_FOUND);
}

protected void onBeforeEdrSave(EndpointDataReference edr) {

}


}

0 comments on commit f8afe79

Please sign in to comment.