Skip to content

Commit

Permalink
Merge pull request #82 from catenax-ng/release1.5.1
Browse files Browse the repository at this point in the history
feat: Update DT asset creation
  • Loading branch information
SebastianBezold authored Nov 14, 2023
2 parents 952d080 + fc950a0 commit 5984cae
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 59 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased]
- The customer already gets an email from Portal and the third-Party-provider after the successful deployment that the SDE-Service is ready to use. If the connector End2End test is unsuccessful (this might be based on the cloud communication issue), the customer will be informed about the failing connectivity. This behavior might need to be clarified for the customer. We will change this behavior in the next release.

## [1.5.1] - 2023-10-16
### Changed
- Update DT asset creation for oauth secret information

## [1.5.0] - 2023-09-04

### Changed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ This service will help service provider to set up DFT/SDE with EDC and EDC as se
### Software Version

```shell
Application version: 1.5.0
Helm release version: 1.5.0
Application version: 1.5.1
Helm release version: 1.5.1
```

# Container images
Expand Down
4 changes: 2 additions & 2 deletions charts/orchestrator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ sources:
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.5.0
version: 1.5.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.5.0"
appVersion: "1.5.1"

dependencies:
- condition: postgresql.enabled
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</parent>
<groupId>org.eclipse.tractusx</groupId>
<artifactId>managed-service-orchestrator</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>
<name>managed-service-orchestrator</name>
<description>managed-service-orchestrator</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.eclipse.tractusx.autosetup.apiproxy;

import java.net.URI;
import java.util.List;
import java.util.Map;

import org.eclipse.tractusx.autosetup.portal.model.ServiceInstanceResultResponse;
Expand All @@ -37,8 +38,9 @@
@FeignClient(name = "EDCApiProxy", url = "placeholder")
public interface EDCApiProxy {

@PostMapping(value ="/v2/assets/request", consumes = MediaType.APPLICATION_JSON_VALUE)
public String getAssets(URI url, @RequestHeader Map<String, String> header);
@PostMapping(value = "/v2/assets/request", consumes = MediaType.APPLICATION_JSON_VALUE)
public List<Object> getAssets(URI url, @RequestHeader Map<String, String> header,
@RequestBody ObjectNode requestBody);

@PostMapping("/v2/assets")
@Headers("Content-Type: application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@

import java.io.InputStream;
import java.net.URI;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.text.StringSubstitutor;
import org.eclipse.tractusx.autosetup.exception.ServiceException;
import org.eclipse.tractusx.autosetup.model.Customer;
import org.springframework.stereotype.Component;
Expand All @@ -43,6 +47,7 @@
public class EDCProxyService {

private static final String CONTROL_PLANE_DATA_ENDPOINT = "controlPlaneDataEndpoint";
private static final String DATE_FORMATTER = "dd/MM/yyyy HH:mm:ss";

private final EDCApiProxy eDCApiProxy;

Expand All @@ -53,22 +58,25 @@ private Map<String, String> requestHeader(Map<String, String> inputData) {
}

@SneakyThrows
public String getAssets(Customer customerDetails, Map<String, String> inputData) {
public List<Object> getAssets(Customer customerDetails, Map<String, String> inputData) {
String dataURL = inputData.get(CONTROL_PLANE_DATA_ENDPOINT);
return eDCApiProxy.getAssets(new URI(dataURL), requestHeader(inputData));
String readValueAsTree = getSchemaFromFile("/edc-request-template/asset-request-filter.json");
ObjectNode requestBody = (ObjectNode) new ObjectMapper().readTree(readValueAsTree);
return eDCApiProxy.getAssets(new URI(dataURL), requestHeader(inputData), requestBody);
}

@SneakyThrows
public String createAsset(Customer customerDetails, Map<String, String> inputData) {

String dataURL = inputData.get(CONTROL_PLANE_DATA_ENDPOINT);
String uId = UUID.randomUUID().toString();
String orgName = customerDetails.getOrganizationName();
String baseUrl = inputData.get("dtregistryUrl");

inputData.put("assetId", uId);
LocalDateTime localdate = LocalDateTime.now();
String date = localdate.format(DateTimeFormatter.ofPattern(DATE_FORMATTER));
inputData.put("createdDate", date);
inputData.put("updateDate", date);
String readValueAsTree = getSchemaFromFile("/edc-request-template/asset.json");
String jsonString = String.format(readValueAsTree, uId, uId, orgName, baseUrl, baseUrl);

String jsonString = valueReplacer(readValueAsTree, inputData);
ObjectNode json = (ObjectNode) new ObjectMapper().readTree(jsonString);
eDCApiProxy.createAsset(new URI(dataURL), requestHeader(inputData), json);

Expand All @@ -77,26 +85,22 @@ public String createAsset(Customer customerDetails, Map<String, String> inputDat

@SneakyThrows
public String createPolicy(Customer customerDetails, Map<String, String> inputData) {

String uId = UUID.randomUUID().toString();

String readValueAsTree = getSchemaFromFile("/edc-request-template/policy.json");
String jsonString = String.format(readValueAsTree, uId);

inputData.put("policyId", uId);
String dataURL = inputData.get(CONTROL_PLANE_DATA_ENDPOINT);
String readValueAsTree = getSchemaFromFile("/edc-request-template/policy.json");
String jsonString = valueReplacer(readValueAsTree, inputData);
ObjectNode json = (ObjectNode) new ObjectMapper().readTree(jsonString);
eDCApiProxy.createPolicy(new URI(dataURL), requestHeader(inputData), json);
return uId;
}

@SneakyThrows
public String createContractDefination(Customer customerDetails, Map<String, String> inputData, String assetId,
String policyId) {
public String createContractDefination(Customer customerDetails, Map<String, String> inputData) {
String uId = UUID.randomUUID().toString();

inputData.put("contractPolicyId", uId);
String readValueAsTree = getSchemaFromFile("/edc-request-template/contract-defination.json");
String jsonString = String.format(readValueAsTree, uId, policyId, policyId, assetId);

String jsonString = valueReplacer(readValueAsTree, inputData);
String dataURL = inputData.get(CONTROL_PLANE_DATA_ENDPOINT);
ObjectNode json = (ObjectNode) new ObjectMapper().readTree(jsonString);
eDCApiProxy.createContractDefination(new URI(dataURL), requestHeader(inputData), json);
Expand Down Expand Up @@ -128,4 +132,9 @@ private String getSchemaFromFile(String schemaFile) {
}
}

private String valueReplacer(String requestTemplate, Map<String, String> inputData) {
StringSubstitutor stringSubstitutor1 = new StringSubstitutor(inputData);
return stringSubstitutor1.replace(requestTemplate);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import static org.eclipse.tractusx.autosetup.constant.AppNameConstant.DT_REGISTRY;

import java.util.List;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -117,9 +118,9 @@ public void dtRegistryRegistrationInEDC(Customer customerDetails, SelectedTools
WaitingTimeUtility.waitingTime(
tenantName + ": Waiting for EDC asset creation after DT setup to get connector pod up");

String asset = eDCProxyService.getAssets(customerDetails, inputData);
List<Object> asset = eDCProxyService.getAssets(customerDetails, inputData);

if (asset != null) {
if (asset != null && asset.isEmpty()) {
createEDCDTAsset(customerDetails, tool, inputData, triger);
}

Expand Down Expand Up @@ -156,8 +157,6 @@ private void createEDCAsset(Customer customerDetails, SelectedTools tool, Map<St

String assetId = eDCProxyService.createAsset(customerDetails, inputData);
log.info(tenantName + ":DT createEDCAsset created " + assetId);
inputData.put("assetId", assetId);

} catch (Exception ex) {
log.error(tenantName + ":DTRegistryManager createEDCAsset failed retry attempt: : {}",
RetrySynchronizationManager.getContext().getRetryCount() + 1);
Expand All @@ -183,7 +182,6 @@ private void createEDCPolicy(Customer customerDetails, SelectedTools tool, Map<S

String policyId = eDCProxyService.createPolicy(customerDetails, inputData);
log.info(tenantName + ":DT createEDCPolicy created :" + policyId);
inputData.put("policyId", policyId);

} catch (Exception ex) {

Expand All @@ -209,14 +207,7 @@ private void createContractDefination(Customer customerDetails, SelectedTools to
log.info(tenantName + ":DT createContractDefination creating");
try {

String assetId = inputData.get("assetId");
String policyId = inputData.get("policyId");

String contractPolicyId = eDCProxyService.createContractDefination(customerDetails, inputData, assetId,
policyId);

inputData.put("contractPolicyId", contractPolicyId);

String contractPolicyId = eDCProxyService.createContractDefination(customerDetails, inputData);
log.info(tenantName + ":DT CreateContractDefination created " + contractPolicyId);

} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public Map<String, String> uploadKeyandValues(Customer customerDetails, Selected

String encryptionkeysalias = openSSLClientManager.executeCommand("openssl rand -base64 16");
tenantVaultSecret = new HashMap<>();
encryptionkeysalias = encryptionkeysalias.replace("\n", "");
tenantVaultSecret.put(CONTENT, encryptionkeysalias);
uploadSecrete(tenantNameNamespace, ENCRYPTIONKEYS, tenantVaultSecret);

Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/edc-request-template/asset-request-filter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"@context": {
"edc": "https://w3id.org/edc/v0.0.1/ns/"
},
"@type": "QuerySpec",
"offset": 0,
"limit": 10,
"sortOrder": "DESC",
"sortField": "id",
"filterExpression": [
{
"edc:operandLeft": "https://w3id.org/edc/v0.0.1/ns/type",
"edc:operator": "=",
"edc:operandRight": "data.core.digitalTwinRegistry"
}
]
}
54 changes: 37 additions & 17 deletions src/main/resources/edc-request-template/asset.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
{
"@context": {},
"asset": {
"@type": "Asset",
"@id": "%s",
"properties": {
"id": "%s",
"type": "data.core.digitalTwinRegistry",
"name": "Digital Twin Registry Endpoint of provider %s",
"contenttype": "application/json",
"policy-id": "use-eu",
"publisher": "%s"
}
},
"dataAddress": {
"type": "HttpData",
"baseUrl": "%s"
}
"@context": {
"edc": "https://w3id.org/edc/v0.0.1/ns/",
"oauth2": "https://datatracker.ietf.org/doc/html/rfc6749",
"dcat": "https://www.w3.org/ns/dcat/",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"aas": "https://admin-shell.io/aas/API/3/0/",
"aas-registry": "aas:AssetAdministrationShellRegistryServiceSpecification/",
"aas-discovery": "aas:DiscoveryServiceSpecification/"
},
"@type": "edc:AssetEntryDto",
"edc:asset": {
"@type": "Asset",
"@id": "${assetId}",
"edc:properties": {
"edc:description": "Digital twin registry information",
"edc:id": "${assetId}",
"edc:name": "Digital twin registry information",
"edc:contenttype": "application/json",
"edc:version": "1.0.0",
"edc:publisher": "${tenantId}:${controlPlaneEndpoint}",
"edc:type": "data.core.digitalTwinRegistry",
"edc:modified": "${createdDate}",
"edc:creationDate": "${updateDate}"
}
},
"edc:dataAddress": {
"edc:type": "HttpData",
"edc:baseUrl": "${dtregistryUrl}",
"oauth2:tokenUrl": "${idpIssuerUri}",
"oauth2:clientId": "${keycloakAuthenticationClientId}",
"oauth2:clientSecretKey": "client-secret",
"edc:proxyMethod": "true",
"edc:proxyBody": "true",
"edc:proxyPath": "true",
"edc:proxyQueryParams": "true",
"edc:contentType": "application/json"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"@context": {},
"@id": "%s",
"@id": "${contractPolicyId}",
"@type": "ContractDefinition",
"accessPolicyId": "%s",
"contractPolicyId": "%s",
"accessPolicyId": "${policyId}",
"contractPolicyId": "${policyId}",
"assetsSelector": {
"@type": "CriterionDto",
"operandLeft": "https://w3id.org/edc/v0.0.1/ns/id",
"operator": "=",
"operandRight": "%s"
"operandRight": "${assetId}"
}
}
2 changes: 1 addition & 1 deletion src/main/resources/edc-request-template/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"odrl": "http://www.w3.org/ns/odrl/2/"
},
"@type": "PolicyDefinitionRequestDto",
"@id": "%s",
"@id": "${policyId}",
"policy": {
"@type": "Policy",
"odrl:permission": []
Expand Down

0 comments on commit 5984cae

Please sign in to comment.