Skip to content

Commit

Permalink
Merge pull request #388 from eclipse-basyx/development
Browse files Browse the repository at this point in the history
Updates Version to 1.5.0
  • Loading branch information
FrankSchnicke authored Oct 4, 2023
2 parents 1a2112a + f0b3dba commit b1bd2b6
Show file tree
Hide file tree
Showing 52 changed files with 2,014 additions and 1,205 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven-publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
packages: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/maven-run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- 27017:27017

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.lck
*.class
/basyx.components/basyx.components.docker/basyx.components.AASServer/fileSmeIdShort.xml
/basyx.components/basyx.components.docker/basyx.components.AASServer/mySubmodelId-fileSmeIdShort.xml
/basyx.components/basyx.components.docker/basyx.components.registry/.moquette_uuid

/components/basys.components/WebContent/WEB-INF/lib/jdbc/postgresql-42.2.2.jar
/components/basys.components/WebContent/WEB-INF/lib/jersey/ext/aopalliance-repackaged-2.5.0-b42.jar
/components/basys.components/WebContent/WEB-INF/lib/jersey/ext/cdi-api-1.1.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.eclipse.basyx</groupId>
<artifactId>basyx.components.docker</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
</parent>

<artifactId>basyx.components.AASServer</artifactId>
Expand Down Expand Up @@ -80,14 +80,14 @@
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.9.0</version>
<version>4.10.2</version>
</dependency>

<!-- Use Spring Data MongoDB for db data management -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.4.10</version>
<version>3.4.15</version>
</dependency>

<!-- Adds additional classes of the BaSys SDK for tests -->
Expand All @@ -108,7 +108,7 @@
<dependency>
<groupId>io.moquette</groupId>
<artifactId>moquette-broker</artifactId>
<version>0.16</version>
<version>0.17</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -121,14 +121,14 @@
<dependency>
<groupId>org.eclipse.basyx</groupId>
<artifactId>basyx.components.registry</artifactId>
<version>1.4.0</version>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.tngtech.keycloakmock</groupId>
<artifactId>mock</artifactId>
<scope>test</scope>
<version>0.13.0</version>
<version>0.15.2</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,24 @@
******************************************************************************/
package org.eclipse.basyx.components.aas;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServlet;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.catalina.Context;
import org.apache.catalina.core.StandardContext;
import org.apache.catalina.servlets.DefaultServlet;
import org.apache.catalina.startup.Tomcat;
import org.apache.commons.io.IOUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.eclipse.basyx.aas.aggregator.AASAggregatorAPIHelper;
Expand All @@ -61,7 +65,6 @@
import org.eclipse.basyx.components.aas.aascomponent.IAASServerFeature;
import org.eclipse.basyx.components.aas.aascomponent.InMemoryAASServerComponentFactory;
import org.eclipse.basyx.components.aas.aascomponent.MongoDBAASServerComponentFactory;
import org.eclipse.basyx.components.aas.aasx.AASXPackageManager;
import org.eclipse.basyx.components.aas.authorization.AuthorizedAASServerFeature;
import org.eclipse.basyx.components.aas.authorization.internal.AuthorizedAASServerFeatureFactory;
import org.eclipse.basyx.components.aas.authorization.internal.AuthorizedDefaultServlet;
Expand Down Expand Up @@ -93,6 +96,7 @@
import org.eclipse.basyx.vab.exception.provider.ProviderException;
import org.eclipse.basyx.vab.exception.provider.ResourceNotFoundException;
import org.eclipse.basyx.vab.modelprovider.VABPathTools;
import org.eclipse.basyx.vab.protocol.http.server.BaSyxChildContext;
import org.eclipse.basyx.vab.protocol.http.server.BaSyxContext;
import org.eclipse.basyx.vab.protocol.http.server.BaSyxHTTPServer;
import org.eclipse.basyx.vab.protocol.http.server.VABHTTPInterface;
Expand All @@ -107,7 +111,6 @@
*
* @author schnicke, espen, fried, fischer, danish, wege
*/
@SuppressWarnings("deprecation")
public class AASServerComponent implements IComponent {
private static Logger logger = LoggerFactory.getLogger(AASServerComponent.class);

Expand All @@ -121,16 +124,17 @@ public class AASServerComponent implements IComponent {
private BaSyxMongoDBConfiguration mongoDBConfig;
private BaSyxSecurityConfiguration securityConfig;

private List<IAASServerFeature> aasServerFeatureList = new ArrayList<IAASServerFeature>();

// Initial AASBundle
protected Collection<AASBundle> aasBundles;
private List<IAASServerFeature> aasServerFeatureList = new ArrayList<>();
protected List<Collection<AASBundle>> aasBundles = new ArrayList<>();

private IAASAggregator aggregator;
// Watcher for AAS Aggregator functionality
private boolean isAASXUploadEnabled = false;

private static final String PREFIX_SUBMODEL_PATH = "/aas/submodels/";
private static final String AASX_RES_FILE_CONTEXT_PATH = AASXToMetamodelConverter.TEMP_DIRECTORY;
private static final String AASX_RES_FILE_DOCBASE_PATH = VABPathTools.append(System.getProperty("java.io.tmpdir"), AASX_RES_FILE_CONTEXT_PATH);
private static final String AASX_RES_FILE_SERVLET_MAPPING_PATTERN = "/*";

/**
* Constructs an empty AAS server using the passed context
Expand Down Expand Up @@ -210,7 +214,8 @@ public void setRegistry(IAASRegistry registry) {
* The bundles that will be loaded during startup
*/
public void setAASBundles(Collection<AASBundle> aasBundles) {
this.aasBundles = aasBundles;
this.aasBundles = new ArrayList<>();
this.aasBundles.add(aasBundles);
}

/**
Expand All @@ -220,7 +225,9 @@ public void setAASBundles(Collection<AASBundle> aasBundles) {
* The bundle that will be loaded during startup
*/
public void setAASBundle(AASBundle aasBundle) {
this.aasBundles = Collections.singleton(aasBundle);
this.aasBundles = new ArrayList<>();
Collection<AASBundle> firstBundleSet = Collections.singleton(aasBundle);
this.aasBundles.add(firstBundleSet);
}

/**
Expand Down Expand Up @@ -251,11 +258,12 @@ public void startComponent() {

// An initial AAS has been loaded from the drive?
if (aasBundles != null) {
// 1. Also provide the files
context.addServletMapping("/files/*", createDefaultServlet());
createBasyxResourceDirectoryIfNotExists();

addAasxFilesResourceServlet(context);

// 2. Fix the file paths according to the servlet configuration
modifyFilePaths(contextConfig.getHostname(), contextConfig.getPort(), contextConfig.getContextPath());
modifyFilePaths(contextConfig.getHostname(), contextConfig.getPort(), getRootFilePathWithContext(contextConfig.getContextPath()));

registerWhitelistedSubmodels();
}
Expand All @@ -267,6 +275,10 @@ public void startComponent() {
registerPreexistingAASAndSMIfPossible();
}

private String getRootFilePathWithContext(String contextPath) {
return VABPathTools.append(contextPath, AASX_RES_FILE_CONTEXT_PATH);
}

private DefaultServlet createDefaultServlet() {
if (aasConfig.isAuthorizationEnabled()) {
final AuthorizedDefaultServletParams<?> params = getAuthorizedDefaultServletParams();
Expand Down Expand Up @@ -543,17 +555,18 @@ private Set<AASBundle> loadBundleFromJSON(String jsonPath) throws IOException {
return new JSONAASBundleFactory(jsonContent).create();
}

private static Set<AASBundle> loadBundleFromAASX(String aasxPath) throws IOException, ParserConfigurationException, SAXException, InvalidFormatException, URISyntaxException {
private static Set<AASBundle> loadBundleFromAASX(String aasxPath, String childFilePath) throws IOException, ParserConfigurationException, SAXException, InvalidFormatException, URISyntaxException {
logger.info("Loading aas from aasx \"" + aasxPath + "\"");

// Instantiate the aasx package manager
AASXToMetamodelConverter packageManager = new AASXPackageManager(aasxPath);

// Unpack the files referenced by the aas
packageManager.unzipRelatedFiles();
try (AASXToMetamodelConverter packageManager = new AASXToMetamodelConverter(aasxPath)) {
// Unpack the files referenced by the aas
packageManager.unzipRelatedFilesToChildPath(childFilePath);

// Retrieve the aas from the package
return packageManager.retrieveAASBundles();
// Retrieve the aas from the package
return packageManager.retrieveAASBundles();
}

}

private void addAASServerFeaturesToContext(BaSyxContext context) {
Expand All @@ -562,13 +575,21 @@ private void addAASServerFeaturesToContext(BaSyxContext context) {
}
}

private Collection<AASBundle> getFlatAASBundles() {
Collection<AASBundle> result = new ArrayList<AASBundle>();
for (Collection<AASBundle> bundle : this.aasBundles) {
result.addAll(bundle);
}
return result;
}

private VABHTTPInterface<?> createAggregatorServlet() {
aggregator = createAASAggregator();
loadAASBundles();

if (aasBundles != null) {
try (final var ignored = ElevatedCodeAuthentication.enterElevatedCodeAuthenticationArea()) {
AASBundleHelper.integrate(aggregator, aasBundles);
AASBundleHelper.integrate(aggregator, getFlatAASBundles());
}
}

Expand Down Expand Up @@ -614,30 +635,39 @@ private List<IAASServerDecorator> createAASServerDecoratorList() {
}

private void loadAASBundles() {
if (aasBundles != null) {
if (!aasBundles.isEmpty()) {
return;
}

List<String> aasSources = aasConfig.getAASSourceAsList();
aasBundles = loadAASFromSource(aasSources);
}

private Set<AASBundle> loadAASFromSource(List<String> aasSources) {
private List<Collection<AASBundle>> loadAASFromSource(List<String> aasSources) {
if (aasSources.isEmpty()) {
return Collections.emptySet();
return new ArrayList<>();
}

Set<AASBundle> aasBundlesSet = new HashSet<>();
List<Collection<AASBundle>> aasBundlesSet = new ArrayList<>();

aasSources.stream().map(this::loadBundleFromFile).forEach(aasBundlesSet::addAll);
for (int i = 0; i < aasSources.size(); i++) {
String aasSource = aasSources.get(i);
String subFilePath = getAASXFileSubPath(i);
Set<AASBundle> loadedBundles = loadBundleFromFile(aasSource, subFilePath);
aasBundlesSet.add(loadedBundles);
}

return aasBundlesSet;
}

private Set<AASBundle> loadBundleFromFile(String aasSource) {
private String getAASXFileSubPath(int aasxIndex) {
return "aasx" + Integer.toString(aasxIndex);
}

private Set<AASBundle> loadBundleFromFile(String aasSource, String childFilePath) {
try {
if (aasSource.endsWith(".aasx")) {
return loadBundleFromAASX(aasSource);
return loadBundleFromAASX(aasSource, childFilePath);
} else if (aasSource.endsWith(".json")) {
return loadBundleFromJSON(aasSource);
} else if (aasSource.endsWith(".xml")) {
Expand Down Expand Up @@ -730,7 +760,8 @@ private String getSMEndpoint(IIdentifier smId) {
}

private String getSMIdShortFromSMId(IIdentifier smId) {
for (AASBundle bundle : aasBundles) {
Collection<AASBundle> flatAasBundles = getFlatAASBundles();
for (AASBundle bundle : flatAasBundles) {
for (ISubmodel sm : bundle.getSubmodels()) {
if (smId.getId().equals(sm.getIdentification().getId())) {
return sm.getIdShort();
Expand All @@ -741,7 +772,8 @@ private String getSMIdShortFromSMId(IIdentifier smId) {
}

private String getAASIdFromSMId(IIdentifier smId) {
for (AASBundle bundle : aasBundles) {
Collection<AASBundle> flatAasBundles = getFlatAASBundles();
for (AASBundle bundle : flatAasBundles) {
for (ISubmodel sm : bundle.getSubmodels()) {
if (smId.getId().equals(sm.getIdentification().getId())) {
return bundle.getAAS().getIdentification().getId();
Expand All @@ -756,11 +788,18 @@ private String getAASIdFromSMId(IIdentifier smId) {
* configuration
*/
private void modifyFilePaths(String hostName, int port, String rootPath) {
rootPath = rootPath + "/files";
for (AASBundle bundle : aasBundles) {
for (int i = 0; i < aasBundles.size(); i++) {
Collection<AASBundle> bundleSet = aasBundles.get(i);
String bundleFileRootPath = VABPathTools.concatenatePaths(rootPath, getAASXFileSubPath(i), "files");
modifyFilePathsInBundleSet(bundleSet, hostName, port, bundleFileRootPath);
}
}

private void modifyFilePathsInBundleSet(Collection<AASBundle> bundleSet, String hostName, int port, String bundleFileRootPath) {
for (AASBundle bundle : bundleSet) {
Set<ISubmodel> submodels = bundle.getSubmodels();
for (ISubmodel sm : submodels) {
SubmodelFileEndpointLoader.setRelativeFileEndpoints(sm, hostName, port, rootPath);
SubmodelFileEndpointLoader.setRelativeFileEndpoints(sm, hostName, port, bundleFileRootPath);
}
}
}
Expand All @@ -769,10 +808,41 @@ private String getMqttAASClientId() {
if (aasBundles == null || aasBundles.isEmpty()) {
return "defaultNoShellId";
}
return aasBundles.stream().findFirst().get().getAAS().getIdShort();
Collection<AASBundle> firstBundleSet = aasBundles.get(0);
if (firstBundleSet == null || firstBundleSet.isEmpty()) {
return "defaultNoShellId";
}
return firstBundleSet.stream().findFirst().get().getAAS().getIdShort();
}

private String getMqttSubmodelClientId() {
return getMqttAASClientId() + "/submodelAggregator";
}

private void addAasxFilesResourceServlet(BaSyxContext context) {
HttpServlet httpServlet = createDefaultServlet();

String childContextPath = VABPathTools.append(contextConfig.getContextPath(), AASX_RES_FILE_CONTEXT_PATH);
Context childContext = createChildContextForAasxResourceFiles(childContextPath, AASX_RES_FILE_DOCBASE_PATH);

context.addChildContext(new BaSyxChildContext(childContext, httpServlet, AASX_RES_FILE_SERVLET_MAPPING_PATTERN));
}

private Context createChildContextForAasxResourceFiles(String childContextPath, String childDocbasePath) {
Context childContext = new StandardContext();
childContext.setPath(childContextPath);
childContext.setDocBase(childDocbasePath);
childContext.addLifecycleListener(new Tomcat.FixContextListener());
return childContext;
}

private void createBasyxResourceDirectoryIfNotExists() {
File directory = new File(AASX_RES_FILE_DOCBASE_PATH);

if (directory.exists())
return;

directory.mkdir();
}

}
Loading

0 comments on commit b1bd2b6

Please sign in to comment.