Skip to content

Commit

Permalink
Merge pull request #314 from eclipse-basyx/development
Browse files Browse the repository at this point in the history
BaSyx Java 1.4.0 release
  • Loading branch information
FrankSchnicke authored Apr 3, 2023
2 parents 3ea8556 + 9a04e7f commit fe1f377
Show file tree
Hide file tree
Showing 46 changed files with 1,648 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ RUN apt install -y wget

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

COPY target/${JAR_FILE} /usr/share/basyxExecutable.jar
COPY target/lib /usr/share/lib
Expand Down Expand Up @@ -43,4 +39,4 @@ ARG MQTT_CONFIG_KEY
ENV ${MQTT_CONFIG_KEY} "/usr/share/config/mqtt.properties"

# Start the jar
CMD ./wait-for-it-env.sh && java -jar "/usr/share/basyxExecutable.jar"
ENTRYPOINT ["./wait-for-it-env-and-start-jar.sh"]
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.3.1</version>
<version>1.4.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.8.2</version>
<version>4.9.0</version>
</dependency>

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

<!-- Adds additional classes of the BaSys SDK for tests -->
Expand Down Expand Up @@ -121,7 +121,7 @@
<dependency>
<groupId>org.eclipse.basyx</groupId>
<artifactId>basyx.components.registry</artifactId>
<version>1.3.1</version>
<version>1.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.eclipse.basyx.aas.aggregator.AASAggregatorAPIHelper;
import org.eclipse.basyx.aas.aggregator.api.IAASAggregator;
import org.eclipse.basyx.aas.aggregator.restapi.AASAggregatorProvider;
import org.eclipse.basyx.aas.bundle.AASBundle;
import org.eclipse.basyx.aas.bundle.AASBundleHelper;
import org.eclipse.basyx.aas.factory.aasx.AASXToMetamodelConverter;
Expand All @@ -67,10 +66,12 @@
import org.eclipse.basyx.components.aas.authorization.internal.AuthorizedAASServerFeatureFactory;
import org.eclipse.basyx.components.aas.authorization.internal.AuthorizedDefaultServlet;
import org.eclipse.basyx.components.aas.authorization.internal.AuthorizedDefaultServletParams;
import org.eclipse.basyx.components.aas.autoregistration.AutoRegisterAASServerFeature;
import org.eclipse.basyx.components.aas.configuration.AASEventBackend;
import org.eclipse.basyx.components.aas.configuration.AASServerBackend;
import org.eclipse.basyx.components.aas.configuration.BaSyxAASServerConfiguration;
import org.eclipse.basyx.components.aas.delegation.DelegationAASServerFeature;
import org.eclipse.basyx.components.aas.fileadaptation.FileValueAdaptingAASServerFeature;
import org.eclipse.basyx.components.aas.mqtt.MqttAASServerFeature;
import org.eclipse.basyx.components.aas.mqtt.MqttV2AASServerFeature;
import org.eclipse.basyx.components.aas.servlet.AASAggregatorAASXUploadServlet;
Expand Down Expand Up @@ -256,8 +257,7 @@ public void startComponent() {
// 2. Fix the file paths according to the servlet configuration
modifyFilePaths(contextConfig.getHostname(), contextConfig.getPort(), contextConfig.getContextPath());

// 3. Register the initial AAS
registerEnvironment();
registerWhitelistedSubmodels();
}

logger.info("Start the server");
Expand Down Expand Up @@ -353,17 +353,31 @@ private void loadAASServerFeaturesFromConfig() {
addAASServerFeature(new DelegationAASServerFeature());
}

if (isAutoRegisterEnabled()) {
addAASServerFeature(new AutoRegisterAASServerFeature(registry, getURL()));
}

if (isEventingEnabled()) {
configureMqttFeature();
}

configureSecurity();

addAASServerFeature(new FileValueAdaptingAASServerFeature(getURL()));

if (aasConfig.isAASXUploadEnabled()) {
enableAASXUpload();
}
}

private boolean isAutoRegisterEnabled() {
return isRegistryConfigured() && !isSubmodelRegistrationWhiteListConfigured();
}

private boolean isSubmodelRegistrationWhiteListConfigured() {
return !aasConfig.getSubmodels().isEmpty();
}

private void configureSecurity() {
if (!aasConfig.isAuthorizationEnabled()) {
return;
Expand All @@ -377,6 +391,14 @@ private void configureSecurity() {
addAASServerFeature(new AuthorizedAASServerFeatureFactory(securityConfig).create());
}

private boolean isRegistryConfigured() {
if (registry != null)
return true;

String registryUrl = aasConfig.getRegistry();
return !(registryUrl == null || registryUrl.isEmpty());
}

private boolean isEventingEnabled() {
return !aasConfig.getAASEvents().equals(AASEventBackend.NONE);
}
Expand All @@ -399,6 +421,23 @@ private void configureMqttFeature() {
* @return
*/
public String getURL() {
if (isExternalPathConfigured()) {
return getExternalURL();
} else {
return getInternalURL();
}
}

private boolean isExternalPathConfigured() {
String hostPath = aasConfig.getHostpath();
return hostPath != null && !hostPath.isEmpty();
}

private String getExternalURL() {
return aasConfig.getHostpath();
}

private String getInternalURL() {
String basePath = aasConfig.getHostpath();
if (basePath.isEmpty()) {
return contextConfig.getUrl();
Expand All @@ -413,6 +452,8 @@ public void stopComponent() {
cleanUpAASServerFeatures();

server.shutdown();

logger.info("AAS Server stopped");
}

private void deregisterAASAndSmAddedDuringRuntime() {
Expand Down Expand Up @@ -636,10 +677,8 @@ private boolean shouldUseSecuredRegistryConnection(BaSyxAASServerConfiguration a
return aasConfig.isAuthorizationCredentialsForSecuredRegistryConfigured();
}

private void registerEnvironment() {
if (aasConfig.getSubmodels().isEmpty()) {
registerFullAAS();
} else {
private void registerWhitelistedSubmodels() {
if (!aasConfig.getSubmodels().isEmpty()) {
registerSubmodelsFromWhitelist();
}
}
Expand All @@ -653,17 +692,6 @@ private void registerSubmodelsFromWhitelist() {
}
}

private void registerFullAAS() {
if (registry == null) {
logger.info("No registry specified, skipped registration");
return;
}

String baseUrl = getURL();
String aggregatorPath = VABPathTools.concatenatePaths(baseUrl, AASAggregatorProvider.PREFIX);
AASBundleHelper.register(registry, aasBundles, aggregatorPath);
}

private void updateSMEndpoint(String smId, List<AASDescriptor> descriptors) {
descriptors.forEach(desc -> {
Collection<SubmodelDescriptor> smDescriptors = desc.getSubmodelDescriptors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
******************************************************************************/
package org.eclipse.basyx.components.aas.aasx;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -52,11 +49,13 @@ public AASXPackageManager(String path) {
super(path);
}

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

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*******************************************************************************
* Copyright (C) 2023 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.basyx.components.aas.autoregistration;

import java.util.Collection;

import org.eclipse.basyx.aas.aggregator.AASAggregatorAPIHelper;
import org.eclipse.basyx.aas.aggregator.api.IAASAggregator;
import org.eclipse.basyx.aas.metamodel.api.IAssetAdministrationShell;
import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
import org.eclipse.basyx.aas.metamodel.map.descriptor.AASDescriptor;
import org.eclipse.basyx.aas.registration.api.IAASRegistry;
import org.eclipse.basyx.submodel.metamodel.api.identifier.IIdentifier;
import org.eclipse.basyx.vab.exception.provider.ResourceNotFoundException;
import org.eclipse.basyx.vab.modelprovider.VABPathTools;
import org.eclipse.basyx.vab.modelprovider.api.IModelProvider;

/**
* An {@link IAASAggregator} which automatically registers created Shells in the
* registry
*
* @author fried
*
*/
public class AutoRegisterAASAggregator implements IAASAggregator {

private IAASAggregator aggregator;
private IAASRegistry registry;
private String endpoint;

public AutoRegisterAASAggregator(IAASAggregator aggregator, IAASRegistry registry, String endpoint) {
this.aggregator = aggregator;
this.registry = registry;
this.endpoint = endpoint;
}

@Override
public Collection<IAssetAdministrationShell> getAASList() {
return aggregator.getAASList();
}

@Override
public IAssetAdministrationShell getAAS(IIdentifier aasId) throws ResourceNotFoundException {
return aggregator.getAAS(aasId);
}

@Override
public IModelProvider getAASProvider(IIdentifier aasId) throws ResourceNotFoundException {
return aggregator.getAASProvider(aasId);
}

@Override
public void createAAS(AssetAdministrationShell aas) {
aggregator.createAAS(aas);
registry.register(new AASDescriptor(aas, getEndpoint(aas)));

}

private String getEndpoint(AssetAdministrationShell aas) {
String harmonized = AASAggregatorAPIHelper.harmonizeURL(endpoint);
String aasAccessPath = AASAggregatorAPIHelper.getAASAccessPath(aas.getIdentification());
return VABPathTools.concatenatePaths(harmonized, aasAccessPath);
}

@Override
public void updateAAS(AssetAdministrationShell aas) throws ResourceNotFoundException {
aggregator.updateAAS(aas);
}

@Override
public void deleteAAS(IIdentifier aasId) {
aggregator.deleteAAS(aasId);
registry.delete(aasId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (C) 2023 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.basyx.components.aas.autoregistration;

import org.eclipse.basyx.aas.aggregator.api.IAASAggregator;
import org.eclipse.basyx.aas.aggregator.api.IAASAggregatorFactory;
import org.eclipse.basyx.aas.registration.api.IAASRegistry;

/**
* Factory for creating a {@link AutoRegisterAASAggregator}
*
* @author fried
*
*/
public class AutoRegisterAASAggregatorFactory implements IAASAggregatorFactory {

private IAASAggregatorFactory aggregatorFactory;
private IAASRegistry registry;
private String endpoint;

public AutoRegisterAASAggregatorFactory(IAASAggregatorFactory aggregatorFactory, IAASRegistry registry,
String endpoint) {
this.aggregatorFactory = aggregatorFactory;
this.registry = registry;
this.endpoint = endpoint;
}

@Override
public IAASAggregator create() {
return new AutoRegisterAASAggregator(aggregatorFactory.create(), registry, endpoint);
}

}
Loading

0 comments on commit fe1f377

Please sign in to comment.