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

Adds BaSyx Gateway Component #450

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
20 changes: 20 additions & 0 deletions .github/workflows/basyx_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,23 @@ jobs:
- name: Stop environment
if: always()
run: docker compose --project-directory ./ci down
test-basyx-gateway:
runs-on: ubuntu-latest
name: Gateway Test
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
cache: maven
- name: Start environment
run: docker compose --project-directory ./ci up -d --wait
- name: Build BaSyx
run: mvn clean install ${MVN_ARGS_BUILD_BASYX}
- name: Test AAS Discovery Service
run: mvn test -f "basyx.gateway/pom.xml"
- name: Stop environment
if: always()
run: docker compose --project-directory ./ci down
26 changes: 26 additions & 0 deletions .github/workflows/docker_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,29 @@ jobs:

- name: Clean up
run: exit 0

build-test-gateway:
runs-on: ubuntu-latest
name: Gateway - Build and Start Docker Image
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
cache: maven
- name: Build BaSyx
run: |
mvn clean install ${MVN_ARGS_BUILD_BASYX_NO_TESTS}

- name: Build Gateway Docker Image
run: |
mvn package -DskipTests -Ddocker.namespace=test --pl "org.eclipse.digitaltwin.basyx:basyx.gateway.component"

- name: Test Gateway Docker Image
run: chmod +x ./.github/workflows/scripts/build_start_docker_image.sh && ./.github/workflows/scripts/build_start_docker_image.sh test/basyx-gateway ${VERSION} test_basyx_gateway

- name: Clean up
run: exit 0
46 changes: 46 additions & 0 deletions basyx.gateway/basyx.gateway-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.gateway</artifactId>
<version>${revision}</version>
</parent>

<artifactId>basyx.gateway-core</artifactId>
<name>BaSyx Gateway HTTP</name>
<description>BaSyx Gateway HTTP</description>
<dependencies>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasrepository-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasregistry-client-native</artifactId>
<version>2.0.0-milestone-04</version>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.aas4j</groupId>
<artifactId>aas4j-model</artifactId>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>5.15.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>5.15.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (C) 2024 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.gateway.core;

import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.basyx.aasrepository.client.ConnectedAasRepository;
import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException;
import org.eclipse.digitaltwin.basyx.gateway.core.exception.BaSyxComponentNotHealthyException;
import org.eclipse.digitaltwin.basyx.gateway.core.registryintegration.AASRegistryIntegrator;
import org.eclipse.digitaltwin.basyx.gateway.core.utils.GatewayUtils;

/**
* Default implementation of the Gateway interface
*
* @author fried
*/
public class DefaultGateway implements Gateway {

private final GatewayUtils utils = new GatewayUtils();

@Override
public void createAAS(AssetAdministrationShell aas, String aasRepository, String aasRegistry) throws BaSyxComponentNotHealthyException {
utils.validateRepository(aasRepository);

ConnectedAasRepository aasRepo = new ConnectedAasRepository(aasRepository);
aasRepo.createAas(aas);

if (!GatewayUtils.isRegistryDefined(aasRegistry)) {
return;
}

utils.validateRegistry(aasRegistry);

try {
AASRegistryIntegrator integrator = new AASRegistryIntegrator(aasRegistry);
integrator.registerAAS(aas, aasRepository);
} catch (RepositoryRegistryLinkException e) {
utils.handleRegistryLinkException(aasRepo, aas, aasRepository, aasRegistry, e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.eclipse.digitaltwin.basyx.gateway.core;

import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.basyx.gateway.core.exception.BaSyxComponentNotHealthyException;

/**
* Gateway Interface
*
* @author fried
*/
public interface Gateway {

public void createAAS(AssetAdministrationShell aas, String aasRepository, String aasRegistry) throws BaSyxComponentNotHealthyException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.eclipse.digitaltwin.basyx.gateway.core;

import org.eclipse.digitaltwin.basyx.gateway.core.Gateway;

/**
* Factory interface to create a Gateway instance
*
* @author fried
*/
public interface GatewayFactory {
public Gateway create();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (C) 2024 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.gateway.core.exception;

public class BaSyxComponentNotHealthyException extends RuntimeException{

public BaSyxComponentNotHealthyException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (C) 2024 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.gateway.core.exception;

public class RegistryUnavailableException extends RuntimeException{

public RegistryUnavailableException(String msg){
super(msg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.eclipse.digitaltwin.basyx.gateway.core.feature;

import org.eclipse.digitaltwin.basyx.core.BaSyxFeature;
import org.eclipse.digitaltwin.basyx.gateway.core.GatewayFactory;

/**
* Basic interface for Gateway Features
*
* @author fried
*/
public interface GatewayFeature extends BaSyxFeature<GatewayFactory> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*******************************************************************************
* Copyright (C) 2024 the Eclipse BaSyx Authors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
******************************************************************************/

package org.eclipse.digitaltwin.basyx.gateway.core.registryintegration;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell;
import org.eclipse.digitaltwin.basyx.aasregistry.client.ApiException;
import org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi;
import org.eclipse.digitaltwin.basyx.aasregistry.client.model.AssetAdministrationShellDescriptor;
import org.eclipse.digitaltwin.basyx.aasregistry.main.client.factory.AasDescriptorFactory;
import org.eclipse.digitaltwin.basyx.aasregistry.main.client.mapper.AttributeMapper;
import org.eclipse.digitaltwin.basyx.core.exceptions.RepositoryRegistryLinkException;
import org.eclipse.digitaltwin.basyx.http.Aas4JHTTPSerializationExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import java.util.List;

/**
* Helper class to integrate AAS into a Registry
*
* @author fried
*/
public class AASRegistryIntegrator {
private final String aasRegistryUrl;
private Logger logger = LoggerFactory.getLogger(AASRegistryIntegrator.class);


public AASRegistryIntegrator(String aasRegistryURL){
this.aasRegistryUrl = aasRegistryURL;
}

public void registerAAS(AssetAdministrationShell aas, String aasURL){
integrateAasWithRegistry(aas, aasRegistryUrl, aasURL);
}


private static AttributeMapper getAttributeMapper() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder().serializationInclusion(JsonInclude.Include.NON_NULL);
Aas4JHTTPSerializationExtension extension = new Aas4JHTTPSerializationExtension();
extension.extend(builder);
ObjectMapper objectMapper = builder.build();
AttributeMapper attributeMapper = new AttributeMapper(objectMapper);
return attributeMapper;
}

private void integrateAasWithRegistry(AssetAdministrationShell shell,String aasRegistryUrl, String aasRepositoryUrl) throws RepositoryRegistryLinkException {
List<String> aasRepositoryURLs = List.of(aasRepositoryUrl);
AttributeMapper attributeMapper = getAttributeMapper();

AssetAdministrationShellDescriptor descriptor = new AasDescriptorFactory(shell, aasRepositoryURLs, attributeMapper).create();

RegistryAndDiscoveryInterfaceApi registryApi = new RegistryAndDiscoveryInterfaceApi(aasRegistryUrl);

try {
registryApi.postAssetAdministrationShellDescriptor(descriptor);

} catch (ApiException e) {
throw new RepositoryRegistryLinkException(shell.getId(), e);
}
logger.info("Shell '{}' has been automatically linked with the Registry", shell.getId());
}
}
Loading