Skip to content

Commit fe1f377

Browse files
Merge pull request #314 from eclipse-basyx/development
BaSyx Java 1.4.0 release
2 parents 3ea8556 + 9a04e7f commit fe1f377

File tree

46 files changed

+1648
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1648
-146
lines changed

basyx.components/basyx.components.docker/basyx.components.AASServer/Dockerfile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ RUN apt install -y wget
66

77
# Copy built jar to image using the jar name specified in the pom.xml (JAR_FILE)
88
ARG JAR_FILE
9-
COPY wait-for-it.sh /
9+
COPY wait-for-it-env-and-start-jar.sh /
1010
# change EOL of .sh file to LF, so the unix container can find it
11-
RUN ["sed", "-i", "s/\r$//", "/wait-for-it.sh"]
12-
RUN ["chmod", "+x", "/wait-for-it.sh"]
13-
COPY wait-for-it-env.sh /
14-
# change EOL of .sh file to LF, so the unix container can find it
15-
RUN ["sed", "-i", "s/\r$//", "/wait-for-it-env.sh"]
16-
RUN ["chmod", "+x", "/wait-for-it-env.sh"]
11+
RUN ["sed", "-i", "s/\r$//", "/wait-for-it-env-and-start-jar.sh"]
12+
RUN ["chmod", "+x", "/wait-for-it-env-and-start-jar.sh"]
1713

1814
COPY target/${JAR_FILE} /usr/share/basyxExecutable.jar
1915
COPY target/lib /usr/share/lib
@@ -43,4 +39,4 @@ ARG MQTT_CONFIG_KEY
4339
ENV ${MQTT_CONFIG_KEY} "/usr/share/config/mqtt.properties"
4440

4541
# Start the jar
46-
CMD ./wait-for-it-env.sh && java -jar "/usr/share/basyxExecutable.jar"
42+
ENTRYPOINT ["./wait-for-it-env-and-start-jar.sh"]

basyx.components/basyx.components.docker/basyx.components.AASServer/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.eclipse.basyx</groupId>
99
<artifactId>basyx.components.docker</artifactId>
10-
<version>1.3.1</version>
10+
<version>1.4.0</version>
1111
</parent>
1212

1313
<artifactId>basyx.components.AASServer</artifactId>
@@ -80,14 +80,14 @@
8080
<dependency>
8181
<groupId>org.mongodb</groupId>
8282
<artifactId>mongodb-driver-sync</artifactId>
83-
<version>4.8.2</version>
83+
<version>4.9.0</version>
8484
</dependency>
8585

8686
<!-- Use Spring Data MongoDB for db data management -->
8787
<dependency>
8888
<groupId>org.springframework.data</groupId>
8989
<artifactId>spring-data-mongodb</artifactId>
90-
<version>3.4.7</version>
90+
<version>3.4.10</version>
9191
</dependency>
9292

9393
<!-- Adds additional classes of the BaSys SDK for tests -->
@@ -121,7 +121,7 @@
121121
<dependency>
122122
<groupId>org.eclipse.basyx</groupId>
123123
<artifactId>basyx.components.registry</artifactId>
124-
<version>1.3.1</version>
124+
<version>1.4.0</version>
125125
<scope>test</scope>
126126
</dependency>
127127
<dependency>

basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/AASServerComponent.java

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
4343
import org.eclipse.basyx.aas.aggregator.AASAggregatorAPIHelper;
4444
import org.eclipse.basyx.aas.aggregator.api.IAASAggregator;
45-
import org.eclipse.basyx.aas.aggregator.restapi.AASAggregatorProvider;
4645
import org.eclipse.basyx.aas.bundle.AASBundle;
4746
import org.eclipse.basyx.aas.bundle.AASBundleHelper;
4847
import org.eclipse.basyx.aas.factory.aasx.AASXToMetamodelConverter;
@@ -67,10 +66,12 @@
6766
import org.eclipse.basyx.components.aas.authorization.internal.AuthorizedAASServerFeatureFactory;
6867
import org.eclipse.basyx.components.aas.authorization.internal.AuthorizedDefaultServlet;
6968
import org.eclipse.basyx.components.aas.authorization.internal.AuthorizedDefaultServletParams;
69+
import org.eclipse.basyx.components.aas.autoregistration.AutoRegisterAASServerFeature;
7070
import org.eclipse.basyx.components.aas.configuration.AASEventBackend;
7171
import org.eclipse.basyx.components.aas.configuration.AASServerBackend;
7272
import org.eclipse.basyx.components.aas.configuration.BaSyxAASServerConfiguration;
7373
import org.eclipse.basyx.components.aas.delegation.DelegationAASServerFeature;
74+
import org.eclipse.basyx.components.aas.fileadaptation.FileValueAdaptingAASServerFeature;
7475
import org.eclipse.basyx.components.aas.mqtt.MqttAASServerFeature;
7576
import org.eclipse.basyx.components.aas.mqtt.MqttV2AASServerFeature;
7677
import org.eclipse.basyx.components.aas.servlet.AASAggregatorAASXUploadServlet;
@@ -256,8 +257,7 @@ public void startComponent() {
256257
// 2. Fix the file paths according to the servlet configuration
257258
modifyFilePaths(contextConfig.getHostname(), contextConfig.getPort(), contextConfig.getContextPath());
258259

259-
// 3. Register the initial AAS
260-
registerEnvironment();
260+
registerWhitelistedSubmodels();
261261
}
262262

263263
logger.info("Start the server");
@@ -353,17 +353,31 @@ private void loadAASServerFeaturesFromConfig() {
353353
addAASServerFeature(new DelegationAASServerFeature());
354354
}
355355

356+
if (isAutoRegisterEnabled()) {
357+
addAASServerFeature(new AutoRegisterAASServerFeature(registry, getURL()));
358+
}
359+
356360
if (isEventingEnabled()) {
357361
configureMqttFeature();
358362
}
359363

360364
configureSecurity();
361365

366+
addAASServerFeature(new FileValueAdaptingAASServerFeature(getURL()));
367+
362368
if (aasConfig.isAASXUploadEnabled()) {
363369
enableAASXUpload();
364370
}
365371
}
366372

373+
private boolean isAutoRegisterEnabled() {
374+
return isRegistryConfigured() && !isSubmodelRegistrationWhiteListConfigured();
375+
}
376+
377+
private boolean isSubmodelRegistrationWhiteListConfigured() {
378+
return !aasConfig.getSubmodels().isEmpty();
379+
}
380+
367381
private void configureSecurity() {
368382
if (!aasConfig.isAuthorizationEnabled()) {
369383
return;
@@ -377,6 +391,14 @@ private void configureSecurity() {
377391
addAASServerFeature(new AuthorizedAASServerFeatureFactory(securityConfig).create());
378392
}
379393

394+
private boolean isRegistryConfigured() {
395+
if (registry != null)
396+
return true;
397+
398+
String registryUrl = aasConfig.getRegistry();
399+
return !(registryUrl == null || registryUrl.isEmpty());
400+
}
401+
380402
private boolean isEventingEnabled() {
381403
return !aasConfig.getAASEvents().equals(AASEventBackend.NONE);
382404
}
@@ -399,6 +421,23 @@ private void configureMqttFeature() {
399421
* @return
400422
*/
401423
public String getURL() {
424+
if (isExternalPathConfigured()) {
425+
return getExternalURL();
426+
} else {
427+
return getInternalURL();
428+
}
429+
}
430+
431+
private boolean isExternalPathConfigured() {
432+
String hostPath = aasConfig.getHostpath();
433+
return hostPath != null && !hostPath.isEmpty();
434+
}
435+
436+
private String getExternalURL() {
437+
return aasConfig.getHostpath();
438+
}
439+
440+
private String getInternalURL() {
402441
String basePath = aasConfig.getHostpath();
403442
if (basePath.isEmpty()) {
404443
return contextConfig.getUrl();
@@ -413,6 +452,8 @@ public void stopComponent() {
413452
cleanUpAASServerFeatures();
414453

415454
server.shutdown();
455+
456+
logger.info("AAS Server stopped");
416457
}
417458

418459
private void deregisterAASAndSmAddedDuringRuntime() {
@@ -636,10 +677,8 @@ private boolean shouldUseSecuredRegistryConnection(BaSyxAASServerConfiguration a
636677
return aasConfig.isAuthorizationCredentialsForSecuredRegistryConfigured();
637678
}
638679

639-
private void registerEnvironment() {
640-
if (aasConfig.getSubmodels().isEmpty()) {
641-
registerFullAAS();
642-
} else {
680+
private void registerWhitelistedSubmodels() {
681+
if (!aasConfig.getSubmodels().isEmpty()) {
643682
registerSubmodelsFromWhitelist();
644683
}
645684
}
@@ -653,17 +692,6 @@ private void registerSubmodelsFromWhitelist() {
653692
}
654693
}
655694

656-
private void registerFullAAS() {
657-
if (registry == null) {
658-
logger.info("No registry specified, skipped registration");
659-
return;
660-
}
661-
662-
String baseUrl = getURL();
663-
String aggregatorPath = VABPathTools.concatenatePaths(baseUrl, AASAggregatorProvider.PREFIX);
664-
AASBundleHelper.register(registry, aasBundles, aggregatorPath);
665-
}
666-
667695
private void updateSMEndpoint(String smId, List<AASDescriptor> descriptors) {
668696
descriptors.forEach(desc -> {
669697
Collection<SubmodelDescriptor> smDescriptors = desc.getSubmodelDescriptors();

basyx.components/basyx.components.docker/basyx.components.AASServer/src/main/java/org/eclipse/basyx/components/aas/aasx/AASXPackageManager.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@
2424
******************************************************************************/
2525
package org.eclipse.basyx.components.aas.aasx;
2626

27-
import java.io.File;
2827
import java.io.IOException;
29-
import java.net.URI;
3028
import java.net.URISyntaxException;
3129
import java.nio.file.Path;
32-
import java.nio.file.Paths;
3330
import java.util.Set;
3431
import java.util.stream.Collectors;
3532

@@ -52,11 +49,13 @@ public AASXPackageManager(String path) {
5249
super(path);
5350
}
5451

52+
/**
53+
* @deprecated This method is deprecated. Please use the {@link AASXToMetamodelConverter#getTemporaryDirPath()}
54+
*/
5555
@Override
56-
protected Path getRootFolder() throws IOException, URISyntaxException {
57-
URI uri = AASXPackageManager.class.getProtectionDomain().getCodeSource().getLocation().toURI();
58-
URI parent = new File(uri).getParentFile().toURI();
59-
return Paths.get(parent);
56+
@Deprecated(since = "1.4.0", forRemoval = true)
57+
protected Path getRootFolder() throws URISyntaxException {
58+
return getTemporaryDirPath();
6059
}
6160

6261
@SuppressWarnings("unchecked")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2023 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
package org.eclipse.basyx.components.aas.autoregistration;
26+
27+
import java.util.Collection;
28+
29+
import org.eclipse.basyx.aas.aggregator.AASAggregatorAPIHelper;
30+
import org.eclipse.basyx.aas.aggregator.api.IAASAggregator;
31+
import org.eclipse.basyx.aas.metamodel.api.IAssetAdministrationShell;
32+
import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
33+
import org.eclipse.basyx.aas.metamodel.map.descriptor.AASDescriptor;
34+
import org.eclipse.basyx.aas.registration.api.IAASRegistry;
35+
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
36+
import org.eclipse.basyx.vab.exception.provider.ResourceNotFoundException;
37+
import org.eclipse.basyx.vab.modelprovider.VABPathTools;
38+
import org.eclipse.basyx.vab.modelprovider.api.IModelProvider;
39+
40+
/**
41+
* An {@link IAASAggregator} which automatically registers created Shells in the
42+
* registry
43+
*
44+
* @author fried
45+
*
46+
*/
47+
public class AutoRegisterAASAggregator implements IAASAggregator {
48+
49+
private IAASAggregator aggregator;
50+
private IAASRegistry registry;
51+
private String endpoint;
52+
53+
public AutoRegisterAASAggregator(IAASAggregator aggregator, IAASRegistry registry, String endpoint) {
54+
this.aggregator = aggregator;
55+
this.registry = registry;
56+
this.endpoint = endpoint;
57+
}
58+
59+
@Override
60+
public Collection<IAssetAdministrationShell> getAASList() {
61+
return aggregator.getAASList();
62+
}
63+
64+
@Override
65+
public IAssetAdministrationShell getAAS(IIdentifier aasId) throws ResourceNotFoundException {
66+
return aggregator.getAAS(aasId);
67+
}
68+
69+
@Override
70+
public IModelProvider getAASProvider(IIdentifier aasId) throws ResourceNotFoundException {
71+
return aggregator.getAASProvider(aasId);
72+
}
73+
74+
@Override
75+
public void createAAS(AssetAdministrationShell aas) {
76+
aggregator.createAAS(aas);
77+
registry.register(new AASDescriptor(aas, getEndpoint(aas)));
78+
79+
}
80+
81+
private String getEndpoint(AssetAdministrationShell aas) {
82+
String harmonized = AASAggregatorAPIHelper.harmonizeURL(endpoint);
83+
String aasAccessPath = AASAggregatorAPIHelper.getAASAccessPath(aas.getIdentification());
84+
return VABPathTools.concatenatePaths(harmonized, aasAccessPath);
85+
}
86+
87+
@Override
88+
public void updateAAS(AssetAdministrationShell aas) throws ResourceNotFoundException {
89+
aggregator.updateAAS(aas);
90+
}
91+
92+
@Override
93+
public void deleteAAS(IIdentifier aasId) {
94+
aggregator.deleteAAS(aasId);
95+
registry.delete(aasId);
96+
}
97+
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2023 the Eclipse BaSyx Authors
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining
5+
* a copy of this software and associated documentation files (the
6+
* "Software"), to deal in the Software without restriction, including
7+
* without limitation the rights to use, copy, modify, merge, publish,
8+
* distribute, sublicense, and/or sell copies of the Software, and to
9+
* permit persons to whom the Software is furnished to do so, subject to
10+
* the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* SPDX-License-Identifier: MIT
24+
******************************************************************************/
25+
package org.eclipse.basyx.components.aas.autoregistration;
26+
27+
import org.eclipse.basyx.aas.aggregator.api.IAASAggregator;
28+
import org.eclipse.basyx.aas.aggregator.api.IAASAggregatorFactory;
29+
import org.eclipse.basyx.aas.registration.api.IAASRegistry;
30+
31+
/**
32+
* Factory for creating a {@link AutoRegisterAASAggregator}
33+
*
34+
* @author fried
35+
*
36+
*/
37+
public class AutoRegisterAASAggregatorFactory implements IAASAggregatorFactory {
38+
39+
private IAASAggregatorFactory aggregatorFactory;
40+
private IAASRegistry registry;
41+
private String endpoint;
42+
43+
public AutoRegisterAASAggregatorFactory(IAASAggregatorFactory aggregatorFactory, IAASRegistry registry,
44+
String endpoint) {
45+
this.aggregatorFactory = aggregatorFactory;
46+
this.registry = registry;
47+
this.endpoint = endpoint;
48+
}
49+
50+
@Override
51+
public IAASAggregator create() {
52+
return new AutoRegisterAASAggregator(aggregatorFactory.create(), registry, endpoint);
53+
}
54+
55+
}

0 commit comments

Comments
 (0)