diff --git a/CHANGELOG.md b/CHANGELOG.md index c36398a8db..7bee32433c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added - DigitalTwinRegistryCreateShellService in irs-registry-client for creating shells in DTR directly +- POST /management/v2/contractagreements/request and GET /management/v2/contractagreements/{contractAgreementId}/negotiation to irs-edc-client lib +### Changed +- Change logo of irs ## [4.6.0] - 2024-02-20 ### Added diff --git a/README.md b/README.md index 7b85fdf5c6..ec895fba99 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# ![Item Relationship Service (IRS)](https://raw.githubusercontent.com/eclipse-tractusx/item-relationship-service/main/logo.png) +# ![Item Relationship Service (IRS)](https://github.com/eclipse-tractusx/item-relationship-service/blob/main/logo.png) + [![Apache 2 License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/eclipse-tractusx/item-relationship-service/blob/main/LICENSE) [![Build](https://github.com/eclipse-tractusx/item-relationship-service/actions/workflows/irs-build.yml/badge.svg)](https://github.com/eclipse-tractusx/item-relationship-service/actions/workflows/irs-build.yml) diff --git a/charts/irs-helm/templates/configmap-spring-app-config.yaml b/charts/irs-helm/templates/configmap-spring-app-config.yaml index c5811fc1a7..6c4c0fd430 100644 --- a/charts/irs-helm/templates/configmap-spring-app-config.yaml +++ b/charts/irs-helm/templates/configmap-spring-app-config.yaml @@ -108,6 +108,7 @@ data: contract-negotiation: {{ .Values.edc.controlplane.endpoint.contractnegotiation | default "/v2/contractnegotiations" | quote }} transfer-process: {{ .Values.edc.controlplane.endpoint.transferprocess | default "/v2/transferprocesses" | quote }} state-suffix: {{ .Values.edc.controlplane.endpoint.statesuffix | default "/state" | quote }} + contract-agreements: {{ .Values.edc.controlplane.endpoint.contractAgreements | default "/v2/contractagreements" | quote }} provider-suffix: {{ tpl .Values.edc.controlplane.provider.suffix . | quote }} catalog-limit: {{ .Values.edc.controlplane.catalog.limit }} catalog-page-size: {{ .Values.edc.controlplane.catalog.pagesize }} diff --git a/charts/irs-helm/values.yaml b/charts/irs-helm/values.yaml index a62c3cff2e..e3a2b759d6 100644 --- a/charts/irs-helm/values.yaml +++ b/charts/irs-helm/values.yaml @@ -177,6 +177,7 @@ edc: contractnegotiation: /v2/contractnegotiations # EDC consumer controlplane contract negotiation path transferprocess: /v2/transferprocesses # EDC consumer controlplane transfer process path statesuffix: /state # Path of the state suffix for contract negotiation and transfer process + contractAgreements: /v2/contractagreements # EDC consumer controlplane contract agreements path request: ttl: PT10M # Requests to controlplane will time out after this duration (see https://en.wikipedia.org/wiki/ISO_8601#Durations) provider: diff --git a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md index 8aa18a942d..372aa549da 100644 --- a/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md +++ b/docs/concept/#367-adapt-to-changes-of-industry-core/#367-adapt-to-changes-industry-core.md @@ -37,20 +37,17 @@ The product IRS MUST align with the Industry Code Standard CX-126 and CX-127. ## Version matrix -| Artefact | Version | Availability | link | -|----------------------------|---------|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| -| AAS | | | | -| PartAsPlanned | 1.0.1 | Mandatory | [PartAsPlanned 1.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.part_as_planned/1.0.1) | -| PartAsPlanned | 2.0.0 | Optional (Mandatory for next version of CX-0126) | [PartAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.part_as_planned/2.0.0) | -| SingleLevelBomAsPlanned | 1.1.0 | Mandatory | [SingleLevelBomAsPlanned 1.1.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_planned/1.1.0)] | -| SingleLevelBomAsPlanned | 2.0.0 | Optional (Mandatory for next version of CX-0126) | [SingleLevelBomAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_planned/2.2.0)] | -| SerialPart | 1.0.1 | Mandatory | [SerialPart 1.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.serial_part/1.0.1) | -| SerialPart | 2.0.0 | Optional | [SerialPart 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.serial_part/2.0.0) | -| Batch | 2.0.0 | Mandatory | [Batch 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.batch/2.0.0) | -| Batch | 2.0.1 | Optional | [Batch 2.0.1](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.batch/2.0.1) | -| JustInSequencePart | 2.0.0 | Optional | [JustInSequencePart 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.just_in_sequence_part/2.0.0) | -| SingleLevelBomAsBuilt | 2.0.0 | Mandatory | [SingleLevelBomAsBuilt 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_built/2.0.0) | -| PartSiteInformationAsBuilt | 1.0.0 | Integrated in Aspects JustInSequencePart / Batch / SerialPart | https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.shared.part_site_information_as_built/1.0.0 | + +|Artefact| Version | Availability | link | +|---|---------|--------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| +| AAS | | | | +|PartAsPlanned | 2.0.0 | Mandatory | [PartAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.part_as_planned/2.0.0) | +| SingleLevelBomAsPlanned| 2.0.0 | Mandatory | [SingleLevelBomAsPlanned 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_planned/2.0.0) | +| SerialPart| 3.0.0 | Mandatory | [SerialPart 3.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.serial_part/3.0.0) | +| Batch| 3.0.0 | Mandatory | [Batch 3.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.batch/3.0.0) | +| JustInSequencePart| 3.0.0 | Mandatory | [JustInSequencePart 3.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.just_in_sequence_part/3.0.0) | +| SingleLevelBomAsBuilt| 2.0.0 | Mandatory | [SingleLevelBomAsBuilt 2.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.single_level_bom_as_built/2.0.0) | +| PartSiteInformationAsBuilt| 1.0.0 | Integrated in Aspects JustInSequencePart / Batch / SerialPart | [PartSiteInformationAsBuilt 1.0.0](https://github.com/eclipse-tractusx/sldt-semantic-models/tree/main/io.catenax.shared.part_site_information_as_built/1.0.0) | - JustInSequencePart: https://github.com/eclipse-tractusx/sldt-semantic-models/pull/563 @@ -72,6 +69,9 @@ The product IRS MUST align with the Industry Code Standard CX-126 and CX-127. For serialized parts, batches, and JIS parts this will be deprecated with new version 3.x.x of AAS. ASS parameter assetLifecyclePhase will not be used anymore to detect BOMLifecycle. Parameter 'digitalTwinType' is used instead. +**assetLifecyclePhase is not used to detect BomLifecyle any more.** + + ### Use parameter 'digitalTwinType' to detect BOMLifecycle **Parameter 'digitalTwinType'** @@ -99,30 +99,23 @@ alt aas contains 'digitalTwinType' else digitalTwinType any other value or null BOMLifecycleDetector -->> IRS : throw Exception end -else aas contains 'assetLifecyclePhase' - alt assetLifecyclePhase="AsBuilt" - BOMLifecycleDetector -->> IRS : return asBuilt - else assetLifecyclePhase="AsPlanned" - BOMLifecycleDetector -->> IRS : return asPlanned - else assetLifecyclePhase any other value or null - BOMLifecycleDetector -->> IRS : throw Exception - end else IRS -->> BOMLifecycleDetector : throw Exception (BOMLifecylce could not be detected) - BOMLifecycleDetector -->> IRS : retrun BOMLifecyle + BOMLifecycleDetector -->> IRS : return BOMLifecyle end ```` #### Configuration of parameter 'digitalTwinType' Parameter is configurable for dDTR instance and has to be configured for integration test. +Setup dDTR registry on used environments. INT, DEV, PEN, STABLE - [Values.yaml](https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/values.yaml#L51) - [README.md](https://github.com/eclipse-tractusx/sldt-digital-twin-registry/blob/f438fe96a7ae1f1b920e8e4fb4114fb7af32643d/charts/registry/README.md#:~:text=externalSubjectIdWildcardAllowedTypes) values.yaml ````json - registry.externalSubjectIdWildcardAllowedTypes = manufacturerPartId,assetLifecyclePhase,digitalTwinType + registry.externalSubjectIdWildcardAllowedTypes = manufacturerPartId,digitalTwinType ```` @@ -186,7 +179,7 @@ values.yaml |manufacturerId | Mandatory | The Business Partner Number (BPNL) of the manufacturer of the part. | |manufacturerPartId | Mandatory | | |customerPartId | Optional | | -|assetLifecyclePhase | asPlanned(Mandatory) / asBuilt(Optional) | @Deprecated For serialized parts, batches, and JIS parts, use the value AsBuilt. For catalog parts in a Digital Twin As-Planned lifecycle phase, use the value AsPlanned. | +|assetLifecyclePhase | asPlanned(Mandatory) / asBuilt(Optional) | @Deprecated Not used any more. For serialized parts, batches, and JIS parts, use the value AsBuilt. For catalog parts in a Digital Twin As-Planned lifecycle phase, use the value AsPlanned. | |digitalTwinType | Mandatory | digitalTwinType="PartType" OR digitalTwinType="PartInstance" For parts on an instance level (e.g. serialized parts, batches, and JIS parts), use the value PartInstance. For parts on a part type level (e.g. catalog parts), use the value PartType. | | | # PartAsPlanned diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcConfiguration.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcConfiguration.java index 3eebea2e4a..019781a863 100644 --- a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcConfiguration.java +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/EdcConfiguration.java @@ -72,6 +72,7 @@ public static class EndpointConfig { private String policyDefinition; private String transferProcess; private String stateSuffix; + private String contractAgreements; } diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponse.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponse.java new file mode 100644 index 0000000000..45232cbc87 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/EdcContractAgreementsResponse.java @@ -0,0 +1,41 @@ +/******************************************************************************** + * Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2021,2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.irs.edc.client.contract.model; + +import java.util.List; + +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.ToString; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; + +/** + * EdcContractAgreementListWrapper used for wrapping the response of + * /management/v2/contractagreements/request where a List of {@link ContractAgreement} is returned. + */ +@ToString +@Builder +@RequiredArgsConstructor +@Getter +public class EdcContractAgreementsResponse { + private final List contractAgreementList; + +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/ContractAgreementException.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/ContractAgreementException.java new file mode 100644 index 0000000000..d8343e91d9 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/model/exception/ContractAgreementException.java @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2021,2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.irs.edc.client.contract.model.exception; + +import org.eclipse.tractusx.irs.edc.client.exceptions.EdcClientException; + +/** + * ContractAgreementException used for failures in + * {@link org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService} + */ +public class ContractAgreementException extends EdcClientException { + + public ContractAgreementException(final String message) { + super(message); + } +} diff --git a/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java new file mode 100644 index 0000000000..3064b5f5f3 --- /dev/null +++ b/irs-edc-client/src/main/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementService.java @@ -0,0 +1,86 @@ +/******************************************************************************** + * Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2021,2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.irs.edc.client.contract.service; + +import java.util.Arrays; +import java.util.List; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; +import org.eclipse.edc.spi.query.Criterion; +import org.eclipse.edc.spi.query.QuerySpec; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +/** + * EdcContractAgreementService used for contract agreements and contract agreement negotiation details + */ +@Slf4j +@RequiredArgsConstructor +public class EdcContractAgreementService { + + public static final String EDC_REQUEST_SUFFIX = "/request"; + public static final String EDC_ASSET_ID = "https://w3id.org/edc/v0.0.1/ns/assetId"; + private final EdcConfiguration config; + private final RestTemplate restTemplate; + + public List getContractAgreements(final String... contractAgreementIds) + throws ContractAgreementException { + + final QuerySpec querySpec = buildQuerySpec(contractAgreementIds); + final ResponseEntity edcContractAgreementListResponseEntity = restTemplate.postForEntity( + config.getControlplane().getEndpoint().getContractAgreements() + EDC_REQUEST_SUFFIX, querySpec, + EdcContractAgreementsResponse.class); + + final EdcContractAgreementsResponse contractAgreementListWrapper = edcContractAgreementListResponseEntity.getBody(); + if (contractAgreementListWrapper != null) { + return contractAgreementListWrapper.getContractAgreementList(); + } else { + throw new ContractAgreementException( + "Empty message body on edc response: " + edcContractAgreementListResponseEntity); + } + + } + + public ContractNegotiation getContractAgreementNegotiation(final String contractAgreementId) { + final ResponseEntity contractNegotiationResponseEntity = restTemplate.getForEntity( + config.getControlplane().getEndpoint().getContractAgreements() + "/" + contractAgreementId + + "/negotiation", ContractNegotiation.class); + return contractNegotiationResponseEntity.getBody(); + } + + private QuerySpec buildQuerySpec(final String... contractAgreementIds) { + + final List criterionList = Arrays.stream(contractAgreementIds) + .map(id -> Criterion.Builder.newInstance() + .operandLeft(EDC_ASSET_ID) + .operator("=") + .operandRight(id) + .build()) + .toList(); + return QuerySpec.Builder.newInstance().filter(criterionList).build(); + } + +} diff --git a/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java new file mode 100644 index 0000000000..38e14d5677 --- /dev/null +++ b/irs-edc-client/src/test/java/org/eclipse/tractusx/irs/edc/client/contract/service/EdcContractAgreementServiceTest.java @@ -0,0 +1,143 @@ +/******************************************************************************** + * Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2021,2024 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ +package org.eclipse.tractusx.irs.edc.client.contract.service; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; + +import java.util.List; + +import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; +import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; +import org.eclipse.edc.policy.model.Policy; +import org.eclipse.tractusx.irs.edc.client.EdcConfiguration; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Answers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +@ExtendWith(MockitoExtension.class) +class EdcContractAgreementServiceTest { + + @Mock + private RestTemplate restTemplate; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private EdcConfiguration edcConfiguration; + + private EdcContractAgreementService edcContractAgreementService; + + @BeforeEach + void setUp() { + this.edcContractAgreementService = new EdcContractAgreementService(edcConfiguration, restTemplate); + } + + @Test + void shouldReturnContractAgreements() throws ContractAgreementException { + //GIVEN + String[] contractAgreementIds = { "contractAgreementId" }; + when(edcConfiguration.getControlplane().getEndpoint().getContractAgreements()).thenReturn( + "/v2/contractagreements"); + + final ContractAgreement contractAgreement = ContractAgreement.Builder.newInstance() + .id("id") + .assetId("assetId") + .consumerId("consumerId") + .providerId("providerId") + .policy(Policy.Builder.newInstance() + .build()) + .build(); + final EdcContractAgreementsResponse edcContractAgreementsResponse = EdcContractAgreementsResponse.builder() + .contractAgreementList( + List.of(contractAgreement)) + .build(); + when(restTemplate.postForEntity(anyString(), any(), eq(EdcContractAgreementsResponse.class))).thenReturn( + ResponseEntity.ok(edcContractAgreementsResponse)); + + //WHEN + final List contractAgreements = edcContractAgreementService.getContractAgreements( + contractAgreementIds); + + //THEN + Mockito.verify(restTemplate) + .postForEntity(eq("/v2/contractagreements/request"), any(), + eq(EdcContractAgreementsResponse.class)); + assertNotNull(contractAgreements); + } + + @Test + void shouldThrowContractAgreementExceptionWhenResponseBodyIsEmtpy() { + //GIVEN + String[] contractAgreementIds = { "contractAgreementId" }; + when(edcConfiguration.getControlplane().getEndpoint().getContractAgreements()).thenReturn( + "/v2/contractagreements"); + + when(restTemplate.postForEntity(anyString(), any(), eq(EdcContractAgreementsResponse.class))).thenReturn( + ResponseEntity.ok().build()); + + //WHEN + final ContractAgreementException contractAgreementException = assertThrows(ContractAgreementException.class, + () -> edcContractAgreementService.getContractAgreements(contractAgreementIds)); + + //THEN + Mockito.verify(restTemplate) + .postForEntity(eq("/v2/contractagreements/request"), any(), + eq(EdcContractAgreementsResponse.class)); + assertEquals("Empty message body on edc response: <200 OK OK,[]>", contractAgreementException.getMessage()); + } + + @Test + void shouldReturnContractAgreementNegotiation() { + //GIVEN + String contractAgreementId = "contractAgreementId"; + when(edcConfiguration.getControlplane().getEndpoint().getContractAgreements()).thenReturn( + "/v2/contractagreements"); + + final ContractNegotiation contractAgreementNegotiationMock = ContractNegotiation.Builder.newInstance() + .id("id") + .counterPartyId("") + .counterPartyAddress("") + .protocol("") + .build(); + when(restTemplate.getForEntity(anyString(), eq(ContractNegotiation.class))).thenReturn( + ResponseEntity.ok(contractAgreementNegotiationMock)); + + //WHEN + final ContractNegotiation contractAgreementNegotiation = edcContractAgreementService.getContractAgreementNegotiation( + contractAgreementId); + + //THEN + Mockito.verify(restTemplate) + .getForEntity("/v2/contractagreements/contractAgreementId/negotiation", + ContractNegotiation.class); + assertNotNull(contractAgreementNegotiation); + } +} \ No newline at end of file diff --git a/local/deployment/irs-local/Chart.yaml b/local/deployment/irs-local/Chart.yaml new file mode 100644 index 0000000000..cd18449143 --- /dev/null +++ b/local/deployment/irs-local/Chart.yaml @@ -0,0 +1,31 @@ +# Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +# Copyright (c) 2021,2024 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# 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. +# +# SPDX-License-Identifier: Apache-2.0 + +apiVersion: v2 +name: irs-helm-local +description: IRS Helm chart for local Kubernetes +home: https://eclipse-tractusx.github.io/ +sources: + - https://github.com/eclipse-tractusx/item-relationship-service +type: application +version: 6.14.0 +appVersion: "4.5.0" + +dependencies: + - name: irs-helm + repository: https://eclipse-tractusx.github.io/item-relationship-service + version: 6.14.0 diff --git a/local/deployment/irs-local/README.md b/local/deployment/irs-local/README.md new file mode 100644 index 0000000000..20cccbd201 --- /dev/null +++ b/local/deployment/irs-local/README.md @@ -0,0 +1,113 @@ +# Item Relationship Service + +## Local deployment of IRS with minimum dependencies setup + +### Step 1: Prerequisites + +1. [Docker](https://docs.docker.com/get-docker/) is installed and the Docker deamon is running with at least 8GB of memory +2. [helm](https://helm.sh/docs/intro/install/) is installed +3. Any Kubernetes cluster is installed and running, eg. [Minikube](https://minikube.sigs.k8s.io/docs/start/) +4. [kubectl](https://kubernetes.io/docs/tasks/tools/) is installed + +### Step 2: Update and build the irs-helm chart + +```bash +$ helm dependency build +``` +You should see console output with messages like below: +```bash +Hang tight while we grab the latest from your chart repositories... +...Successfully got an update from the "irs" chart repository +...Successfully got an update from the "tractusx-dev" chart repository +...Successfully got an update from the "prometheus-community" chart repository +Update Complete. ⎈Happy Helming!⎈ +Saving 1 charts +Downloading irs-helm from repo https://eclipse-tractusx.github.io/item-relationship-service +Deleting outdated charts +``` +Please note that irs repository has to be added to helm repo list +```bash +$ helm repo add irs https://eclipse-tractusx.github.io/item-relationship-service +$ helm repo list +NAME URL +irs https://eclipse-tractusx.github.io/item-relationship-service +``` + +### Step 3: Installing the IRS + +#### 1. Start the cluster + +To deploy IRS on kubernetes with helm run + +```bash +$ helm install irs-local . +``` + +##### 1.1 Get the Status of the deployment + +Helm can give you feedback on the release status: + +```bash +$ helm list +NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION +irs-local default 1 2024-02-26 11:36:46.399546 +0100 CET deployed irs-helm-local-6.14.0 4.5.0 +``` +Kubectl can give you feedback on how the status of the deployment currently is, there should be two pods deployed - IRS and Minio: +```bash +$ kubectl get pods +NAME READY STATUS RESTARTS AGE +irs-local-minio-7cc78d8985-qggrx 1/1 Running 0 10m +irs-local-irs-helm-c84f98ffb-zg59z 1/1 Running 0 10m + +``` + +#### 2. Forward Ports + +When the deployment has been finished please use the command to forward the port: + +```bash +$ kubectl port-forward svc/irs-local-irs-helm 8080:8080 +``` + +After that you can access the Swagger UI page: + +* **IRS Swagger:** [http://localhost:8080/api/swagger-ui/index.html](http://localhost:8080/api/swagger-ui/index.html) + +## Testing the Item Relationship Service + +You can use any approach to access exposed by IRS API endpoints, for example mentioned above Swagger UI page. There is also prepared Insomnia collection with example calls to IRS, see [IRS_Request_Collection.json](../../testing/IRS_Request_Collection.json) + +### Valid Global Asset Ids for testing + +IRS is loading with mocked data from Testdata file, see [CX_Testdata.json](../../../irs-models/src/main/resources/test_data/CX_Testdata.json) + +### Valid test requests for testing + +You can use these snippets for testing purposes. + +```json +{ + "bomLifecycle": "asBuilt", + "lookupBPNs": true, + "direction": "downward", + "depth": 10, + "auditContractNegotiation": false, + "key": { + "globalAssetId": "urn:uuid:951f1ebf-ebcf-427c-8a4d-7fe1f67c8d58", + "bpn": "BPNL00000003B0Q0" + } +} +```` + +```json +{ + "aspects": [ + "SerialPart" + ], + "depth": 1, + "key": { + "globalAssetId": "urn:uuid:951f1ebf-ebcf-427c-8a4d-7fe1f67c8d58", + "bpn": "BPNL00000003B0Q0" + } +} +``` \ No newline at end of file diff --git a/local/deployment/irs-local/values.yaml b/local/deployment/irs-local/values.yaml new file mode 100644 index 0000000000..1efcafc82f --- /dev/null +++ b/local/deployment/irs-local/values.yaml @@ -0,0 +1,67 @@ +# Copyright (c) 2022,2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) +# Copyright (c) 2021,2024 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# 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. +# +# SPDX-License-Identifier: Apache-2.0 + +irs-helm: + ##################### + # IRS Configuration # + ##################### + irsUrl: "http://localhost:8080" + bpn: "BPNL000000000000" + apiKeyAdmin: "01234567890123456789" + apiKeyRegular: "09876543210987654321" + env: + - name: SPRING_PROFILES_ACTIVE + value: local + + digitalTwinRegistry: + type: central + discovery: + discoveryFinderUrl: https://localhost + semanticshub: + url: https://localhost + bpdm: + url: https://localhost + + minioUser: "testtest" + minioPassword: "testtest" + + resources: + limits: + cpu: "1000m" + memory: "500Mi" + requests: + cpu: "50m" + memory: "500Mi" + + ####################### + # Minio Configuration # + ####################### + minio: + rootUser: "testtest" + rootPassword: "testtest" + + ######################### + # Grafana Configuration # + ######################### + grafana: + enabled: false + + ############################ + # Prometheus Configuration # + ############################ + prometheus: + enabled: false diff --git a/logo.png b/logo.png index 14e1894060..4fddcbe559 100644 Binary files a/logo.png and b/logo.png differ