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

feat(irs-api):[#199] register policy definition for certain bpnls #802

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8028ac4
feat(irs-api):[#199] register policy definition for certain bpnls
ds-psosnowski Mar 5, 2024
1898634
feat(irs-api):[#199] merge and conflicts resolve
ds-psosnowski Mar 5, 2024
c65f58e
feat(irs-api):[#199] added changelog entry
ds-psosnowski Mar 11, 2024
f9a886b
feat(irs-api):[#199] added test
ds-psosnowski Mar 12, 2024
4975d01
feat(irs-api):[#199] update
ds-psosnowski Mar 12, 2024
eba7540
feat(irs-api):[#199] added tests
ds-psosnowski Mar 13, 2024
dcdd24e
feat(irs-api):[#199] test clean up
ds-psosnowski Mar 13, 2024
58a3212
feat(impl): [#199] Harden test and clean method signature
dsmf Mar 13, 2024
9340fb4
feat(impl): [#199] Fix warnings
dsmf Mar 13, 2024
05ec245
feat(impl): [#199] Deduplicate by extraction to findBpnsByPolicyId
dsmf Mar 13, 2024
038b85a
feat(impl): [#199] Avoid too many methods by extraction to helper class
dsmf Mar 13, 2024
c999b0a
feat(impl): [#199] Add tests
dsmf Mar 13, 2024
6a32fde
feat(irs-api):[#199] corrections after review
ds-psosnowski Mar 14, 2024
eea278b
feat(irs-api):[#199] corrections after review
ds-psosnowski Mar 14, 2024
29b7560
feat(irs-api):[#199] added test
ds-psosnowski Mar 14, 2024
f6626c1
Merge branch 'main' into feature/#199-register-policy-definition-for-…
dsmf Mar 15, 2024
a2f32d9
feat(irs-api):[#199] corrections after review
ds-psosnowski Mar 18, 2024
be88258
feat(irs):[#199] corrections after review
ds-psosnowski Mar 19, 2024
c4a4de9
feat(irs):[#199] main merge
ds-psosnowski Mar 19, 2024
4758554
feat(irs):[#199] corrections after review
ds-psosnowski Mar 22, 2024
df7a662
Merge branch 'main' into feature/#199-register-policy-definition-for-…
ds-psosnowski Mar 22, 2024
2d4e1cb
feat(irs):[#199] updated insomnia collection
ds-psosnowski Mar 22, 2024
2962615
feat(irs):[#199] sonar issues fix
ds-psosnowski Mar 22, 2024
740b188
feat(irs):[#199] sonar issues fix
ds-psosnowski Mar 22, 2024
13136f5
feat(irs):[#199] changed spaces in irs request collection
ds-psosnowski Mar 22, 2024
20c7e49
feat(irs):[#199] revert white signs in request collection
ds-psosnowski Mar 22, 2024
e0ab6b3
feat(irs):[#199] changed spaces to tabs in irs request collection
ds-psosnowski Mar 22, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ _**For better traceability add the corresponding GitHub issue number in each cha
- Added AssetAdministrationShellDescriptor specificAssetIds support for externalSubjectId required for data provisioning
- Registering a job - aspects array is now accepting full urn of aspect model instead of name only, eg. 'urn:bamm:io.catenax.single_level_bom_as_built:2.0.0#SingleLevelBomAsBuilt' instead 'SingleLevelBomAsBuilt'. #439
- Changed the version of irs-registry-client from 1.6.0-SNAPSHOT to 1.6.0
- Policies can now be registered for certain bpnls. #199


## Fixed
- Fixed missing timeouts including configuration. #448
Expand Down
2 changes: 0 additions & 2 deletions charts/irs-helm/templates/configmap-spring-app-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ data:
{{- end }}
{{- end }}

apiAllowedBpn: {{ tpl (.Values.bpn | default "") . | quote }}
dsmf marked this conversation as resolved.
Show resolved Hide resolved

{{- if .Values.config.content }}
{{- tpl (toYaml .Values.config.content) . | nindent 4 }}
{{- end }}
120 changes: 78 additions & 42 deletions docs/src/api/irs-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,15 @@ paths:
/irs/policies:
get:
description: Lists the registered policies that should be accepted in EDC negotiation.
operationId: getAllowedPolicies
operationId: getAllowedPoliciesByBpn
parameters:
- name: bpnls
in: query
required: false
schema:
type: array
items:
type: string
responses:
"200":
content:
Expand Down Expand Up @@ -823,7 +831,7 @@ paths:
$ref: '#/components/schemas/ErrorResponse'
description: Authorization refused by server.
security:
- api_key: []
- api_key: [ ]
summary: Lists the registered policies that should be accepted in EDC negotiation.
tags:
- Item Relationship Service
Expand Down Expand Up @@ -871,16 +879,15 @@ paths:
summary: Register a policy that should be accepted in EDC negotiation.
tags:
- Item Relationship Service
/irs/policies/{policyId}:
delete:
description: Removes a policy that should no longer be accepted in EDC negotiation.
operationId: deleteAllowedPolicy
parameters:
- in: path
name: policyId
required: true
schema:
type: string
put:
description: Updates an existing policy.
operationId: updateAllowedPolicy
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UpdatePolicyRequest'
required: true
responses:
"200":
description: OK
Expand All @@ -892,7 +899,7 @@ paths:
$ref: '#/components/examples/error-response-400'
schema:
$ref: '#/components/schemas/ErrorResponse'
description: Policy deletion failed.
description: Policy update failed.
"401":
content:
application/json:
Expand All @@ -912,25 +919,20 @@ paths:
$ref: '#/components/schemas/ErrorResponse'
description: Authorization refused by server.
security:
- api_key: []
summary: Removes a policy that should no longer be accepted in EDC negotiation.
- api_key: [ ]
summary: Updates an existing policy.
tags:
- Item Relationship Service
put:
description: Updates an existing policy with new validUntil value.
operationId: updateAllowedPolicy
/irs/policies/{policyId}:
delete:
description: Removes a policy that should no longer be accepted in EDC negotiation.
operationId: deleteAllowedPolicy
parameters:
- in: path
name: policyId
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UpdatePolicyRequest'
required: true
responses:
"200":
description: OK
Expand All @@ -942,7 +944,7 @@ paths:
$ref: '#/components/examples/error-response-400'
schema:
$ref: '#/components/schemas/ErrorResponse'
description: Policy update failed.
description: Policy deletion failed.
"401":
content:
application/json:
Expand All @@ -963,7 +965,7 @@ paths:
description: Authorization refused by server.
security:
- api_key: []
summary: Updates an existing policy with new validUntil value.
summary: Removes a policy that should no longer be accepted in EDC negotiation.
tags:
- Item Relationship Service
components:
Expand Down Expand Up @@ -1736,9 +1738,9 @@ components:
description: Request to add a policy
properties:
payload:
type: object
additionalProperties:
$ref: '#/components/schemas/JsonValue'
type: array
items:
$ref: '#/components/schemas/JsonObject'
example:
payload:
'@context':
Expand All @@ -1758,23 +1760,14 @@ components:
'@id': 'odrl:eq'
'odrl:rightOperand': ID 3.1 Trace
validUntil: '2025-12-12T23:59:59.999Z'
properties:
empty:
type: boolean
valueType:
type: string
enum:
- 'ARRAY'
- 'OBJECT'
- 'STRING'
- 'NUMBER'
- 'TRUE'
- 'FALSE'
- 'NULL'
validUntil:
type: string
format: date-time
description: Timestamp after which the policy will no longer be accepted in negotiations
businessPartnerNumbers:
type: array
items:
type: string
required:
- payload
- validUntil
Expand Down Expand Up @@ -2237,6 +2230,41 @@ components:
items:
$ref: '#/components/schemas/Tombstone'
maxItems: 2147483647
JsonObject:
type: object
additionalProperties: false
properties:
valueType:
type: string
enum:
- 'ARRAY'
- 'OBJECT'
- 'STRING'
- 'NUMBER'
- 'TRUE'
- 'FALSE'
- 'NULL'
empty:
type: boolean
example:
payload:
'@context':
odrl: http://www.w3.org/ns/odrl/2/
'@id': policy-id
policy:
'odrl:permission':
- 'odrl:action': USE
'odrl:constraint':
'odrl:and':
- 'odrl:leftOperand': Membership
'odrl:operator':
'@id': 'odrl:eq'
'odrl:rightOperand': active
- 'odrl:leftOperand': PURPOSE
'odrl:operator':
'@id': 'odrl:eq'
'odrl:rightOperand': ID 3.1 Trace
validUntil: '2025-12-12T23:59:59.999Z'
JsonValue:
type: object
additionalProperties: false
Expand Down Expand Up @@ -2938,6 +2966,14 @@ components:
additionalProperties: false
description: Request to add a policy
properties:
businessPartnerNumbers:
type: array
items:
type: string
policiesIds:
ds-psosnowski marked this conversation as resolved.
Show resolved Hide resolved
type: array
items:
type: string
validUntil:
type: string
format: date-time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,22 @@ protected SubmodelDescriptor requestSubmodel(final EdcSubmodelFacade submodelFac
log.debug("Using dspEndpoint of subprotocolBody '{}' to get submodel payload", subprotocolBody);
return submodelFacade.getSubmodelPayload(dspEndpoint.get(),
digitalTwinRegistryEndpoint.getProtocolInformation().getHref(),
extractAssetId(subprotocolBody));
extractAssetId(subprotocolBody), bpn);
} else {
log.info("SubprotocolBody does not contain '{}'. Using Discovery Service as fallback.", DSP_ENDPOINT);
final List<String> connectorEndpoints = connectorEndpointsService.fetchConnectorEndpoints(bpn);

return getSubmodel(submodelFacade, digitalTwinRegistryEndpoint, connectorEndpoints);
return getSubmodel(submodelFacade, digitalTwinRegistryEndpoint, connectorEndpoints, bpn);
}
}

private SubmodelDescriptor getSubmodel(final EdcSubmodelFacade submodelFacade, final Endpoint digitalTwinRegistryEndpoint,
final List<String> connectorEndpoints) throws EdcClientException {
final List<String> connectorEndpoints, final String bpn) throws EdcClientException {
for (final String connectorEndpoint : connectorEndpoints) {
try {
return submodelFacade.getSubmodelPayload(connectorEndpoint,
digitalTwinRegistryEndpoint.getProtocolInformation().getHref(),
extractAssetId(digitalTwinRegistryEndpoint.getProtocolInformation().getSubprotocolBody()));
extractAssetId(digitalTwinRegistryEndpoint.getProtocolInformation().getSubprotocolBody()), bpn);
} catch (EdcClientException e) {
log.info("EdcClientException while accessing digitalTwinRegistryEndpoint '{}'", connectorEndpoint, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
@Configuration
public class RegistryConfiguration {

private static final String DEFAULT = "default";

@Bean
@ConditionalOnProperty(prefix = "digitalTwinRegistry", name = "type", havingValue = "central")
public CentralDigitalTwinRegistryService centralDigitalTwinRegistryService(final DigitalTwinRegistryClient client) {
Expand Down Expand Up @@ -78,7 +80,7 @@ public DecentralDigitalTwinRegistryService decentralDigitalTwinRegistryService(

final EdcEndpointReferenceRetriever endpointReferenceRetriever = (edcConnectorEndpoint, assetType, assetValue) -> {
try {
return facade.getEndpointReferencesForAsset(edcConnectorEndpoint, assetType, assetValue);
return facade.getEndpointReferencesForAsset(edcConnectorEndpoint, assetType, assetValue, DEFAULT);
} catch (EdcClientException e) {
throw new EdcRetrieverException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void receiveNotification(
final EdcNotification<NotificationContent> edcRequest = edcRequest(notificationId, originalNotificationId,
senderEdc, senderBpn, recipientBpn, notificationContent);

final var response = edcSubmodelFacade.sendNotification(recipientUrl, "ess-response-asset", edcRequest);
final var response = edcSubmodelFacade.sendNotification(recipientUrl, "ess-response-asset", edcRequest, recipientBpn);
if (!response.deliveredSuccessfully()) {
throw new EdcClientException(
"EDC Provider did not accept message with notificationId " + notificationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void sendEdcNotification(final EdcNotification<InvestigationNotificationC
originalNotificationId, essLocalEdcEndpoint, localBpn, recipientBpn, notificationContent);

final var response = edcSubmodelFacade.sendNotification(connectorEndpoint, "ess-response-asset",
responseNotification);
responseNotification, bpn);
if (!response.deliveredSuccessfully()) {
throw new EdcClientException(
"EDC Provider did not accept message with notificationId " + notificationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ private String sendEdcNotification(final String bpn, final String url, final Lis
final EdcNotificationResponse response;
if (isRecursiveMockAsset || isNotMockAsset) {
log.debug("Sending recursive notification");
response = edcSubmodelFacade.sendNotification(url, "notify-request-asset-recursive", notification);
response = edcSubmodelFacade.sendNotification(url, "notify-request-asset-recursive", notification, bpn);
} else {
log.debug("Sending mock recursive notification");
response = edcSubmodelFacade.sendNotification(url, "notify-request-asset", notification);
response = edcSubmodelFacade.sendNotification(url, "notify-request-asset", notification, bpn);
}
if (response.deliveredSuccessfully()) {
log.info("Successfully sent notification with id '{}' to EDC endpoint '{}'.", notificationId, url);
Expand Down
4 changes: 1 addition & 3 deletions irs-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,4 @@ ess:
url: "${IRS_URL:}" # IRS Url to connect with
discovery:
mockEdcResult: { } # Mocked BPN Investigation results
mockRecursiveEdcAsset: # Mocked BPN Recursive Investigation results

apiAllowedBpn: ${API_ALLOWED_BPN:BPNL00000001CRHK} # BPN value that is allowed to access IRS API
mockRecursiveEdcAsset: # Mocked BPN Recursive Investigation results
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public Optional<byte[]> getBlob(final String sourceBlobName) {
return Optional.ofNullable(store.get(sourceBlobName));
}

@Override
public Map<String, byte[]> getAllBlobs() {
return store;
}

@Override
public Collection<byte[]> findBlobByPrefix(final String prefix) {
return store.entrySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void setUp() {
@Test
void shouldUseDspEndpointIfPresent() throws EdcClientException {
// Arrange
when(submodelFacade.getSubmodelPayload(any(), any(), any())).thenReturn(new SubmodelDescriptor("cid", "test"));
when(submodelFacade.getSubmodelPayload(any(), any(), any(), any())).thenReturn(new SubmodelDescriptor("cid", "test"));
final Endpoint endpoint = Endpoint.builder()
.protocolInformation(ProtocolInformation.builder()
.href("http://dataplane.test/123")
Expand All @@ -77,17 +77,17 @@ void shouldUseDspEndpointIfPresent() throws EdcClientException {

// Assert
assertThat(submodel).isEqualTo("test");
verify(submodelFacade, times(1)).getSubmodelPayload("http://edc.test", "http://dataplane.test/123", "123");
verify(submodelFacade, times(1)).getSubmodelPayload("http://edc.test", "http://dataplane.test/123", "123", "BPN123");
}

@Test
void shouldUseDiscoveryFinderIfDspEndpointNotPresent() throws EdcClientException {
// Arrange
final String connector1 = "http://edc.test1";
final String connector2 = "http://edc.test2";
when(submodelFacade.getSubmodelPayload(eq(connector1), any(), any())).thenThrow(
when(submodelFacade.getSubmodelPayload(eq(connector1), any(), any(), any())).thenThrow(
new EdcClientException("test"));
when(submodelFacade.getSubmodelPayload(eq(connector2), any(), any())).thenReturn(new SubmodelDescriptor("cid", "test"));
when(submodelFacade.getSubmodelPayload(eq(connector2), any(), any(), any())).thenReturn(new SubmodelDescriptor("cid", "test"));
when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(List.of(connector1, connector2));
final String dataplaneUrl = "http://dataplane.test/123";
final Endpoint endpoint = Endpoint.builder()
Expand All @@ -104,8 +104,8 @@ void shouldUseDiscoveryFinderIfDspEndpointNotPresent() throws EdcClientException

// Assert
assertThat(submodel).isEqualTo("test");
verify(submodelFacade, times(1)).getSubmodelPayload(connector1, dataplaneUrl, "123");
verify(submodelFacade, times(1)).getSubmodelPayload(connector2, dataplaneUrl, "123");
verify(submodelFacade, times(1)).getSubmodelPayload(connector1, dataplaneUrl, "123", "BPN123");
verify(submodelFacade, times(1)).getSubmodelPayload(connector2, dataplaneUrl, "123", "BPN123");
verify(connectorEndpointsService, times(1)).fetchConnectorEndpoints(bpn);
}

Expand All @@ -114,7 +114,7 @@ void shouldThrowGenericEdcClientExceptionIfAllEndpointsThrowExceptions() throws
// Arrange
final String connector1 = "http://edc.test1";
final String connector2 = "http://edc.test2";
when(submodelFacade.getSubmodelPayload(any(), any(), any())).thenThrow(new EdcClientException("test"));
when(submodelFacade.getSubmodelPayload(any(), any(), any(), any())).thenThrow(new EdcClientException("test"));
when(connectorEndpointsService.fetchConnectorEndpoints(any())).thenReturn(List.of(connector1, connector2));
final String dataplaneUrl = "http://dataplane.test/123";
final Endpoint endpoint = Endpoint.builder()
Expand All @@ -131,8 +131,8 @@ void shouldThrowGenericEdcClientExceptionIfAllEndpointsThrowExceptions() throws
bpn));

// Assert
verify(submodelFacade, times(1)).getSubmodelPayload(connector1, dataplaneUrl, "123");
verify(submodelFacade, times(1)).getSubmodelPayload(connector2, dataplaneUrl, "123");
verify(submodelFacade, times(1)).getSubmodelPayload(connector1, dataplaneUrl, "123", "BPN123");
verify(submodelFacade, times(1)).getSubmodelPayload(connector2, dataplaneUrl, "123", "BPN123");
verify(connectorEndpointsService, times(1)).fetchConnectorEndpoints(bpn);
}
}
Loading