Skip to content

Commit

Permalink
Enhance EDMM integration
Browse files Browse the repository at this point in the history
- Transformation check based on rule system
- Adaptation proposals
- Trigger transformation from TopoMod

Co-authored-by: Leonardo Frioli <[email protected]>
Signed-off-by: Michael Wurster <[email protected]>
  • Loading branch information
miwurster and wikilele committed Jan 25, 2021
1 parent b248dff commit 7bece2b
Show file tree
Hide file tree
Showing 37 changed files with 2,169 additions and 128 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Michael Wurster <[email protected]>
Latife Sen <[email protected]>
Ana Cristina Franco da Silva <[email protected]>
Pascal Hirmer <[email protected]> <[email protected]>
Leonardo Frioli <[email protected]>
Dominik Voigt <[email protected]>
Ghareeb Falazi <[email protected]>
Björn Müller <[email protected]>
Expand Down
3 changes: 2 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Copyright (c) 2017 Huixin Liu
Copyright (c) 2017-2020 Karoline Saatkamp
Copyright (c) 2017 Marvin Wohlfarth
Copyright (c) 2017 Michael Falkenthal
Copyright (c) 2017-2020 Michael Wurster
Copyright (c) 2017-2021 Michael Wurster
Copyright (c) 2017 Nick Fode
Copyright (c) 2017 Latife Sen
Copyright (c) 2017 Ruzica Jozin
Expand Down Expand Up @@ -80,6 +80,7 @@ Copyright (c) 2019 Sascha Zeller
Copyright (c) 2019-2020 Tobias Mathony
Copyright (c) 2019 Yannik Dietrich
Copyright (c) 2019 Yuye Tong
Copyright (c) 2020 Leonardo Frioli
Copyright (c) 2019-2020 Felix Burk
Copyright (c) 2019-2020 Johannes Hepp

Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.winery.common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.17</version>
<version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.winery.crawler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.21</version>
<version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
Expand Down
9 changes: 7 additions & 2 deletions org.eclipse.winery.edmm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependency>
<groupId>com.github.UST-EDMM.edmm</groupId>
<artifactId>edmm-core</artifactId>
<version>v1.0.8</version>
<version>v1.0.9</version>
</dependency>
<dependency>
<groupId>org.eclipse.winery</groupId>
Expand All @@ -58,6 +58,12 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.adr</groupId>
<artifactId>e-adr</artifactId>
Expand All @@ -70,5 +76,4 @@
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2020 Contributors to the Eclipse Foundation
* Copyright (c) 2019-2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -11,7 +11,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/

package org.eclipse.winery.edmm;

import java.util.HashMap;
Expand All @@ -33,7 +32,7 @@ static EdmmManager forRepository(IRepository repo) {
RepositoryFileReference ref = BackendUtils.getRefOfJsonConfiguration(new EdmmMappingsId());
return new JsonBasedEdmmManager(repo.ref2AbsolutePath(ref).toFile());
}

List<EdmmMappingItem> getOneToOneMappings();

void setOneToOneMappings(List<EdmmMappingItem> list);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/
package org.eclipse.winery.edmm;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;

import org.eclipse.winery.edmm.plugins.PluginManager;
import org.eclipse.winery.edmm.utils.ZipUtility;

import io.github.edmm.core.parser.EntityGraph;
import io.github.edmm.core.plugin.PluginService;
import io.github.edmm.core.transformation.TransformationContext;
import io.github.edmm.core.transformation.TransformationService;
import io.github.edmm.model.DeploymentModel;

public class TransformationManager {

public File transform(EntityGraph entityGraph, String target, String wineryRepository) throws Exception {
PluginService pluginService = PluginManager.getInstance()
.getPluginService();
TransformationService transformationService = new TransformationService(pluginService);

// getting the model from the graph
DeploymentModel deploymentModel = new DeploymentModel(UUID.randomUUID().toString(), entityGraph);

// the paths of the artifacts or operation files start from the root directory
File sourceDirectory = Paths.get(wineryRepository).toFile();
File targetDirectory = Files.createTempDirectory(target + "-").toFile();

TransformationContext transformationContext = transformationService.createContext(deploymentModel, target, sourceDirectory, targetDirectory);
transformationService.start(transformationContext);
// throws an exception if the transformation wasn't successful
transformationContext.throwExceptionIfErrorState();

Path zipPath = Paths.get(System.getProperty("java.io.tmpdir")).resolve(target + ".zip");
ZipUtility.pack(targetDirectory.toPath(), zipPath);

return zipPath.toFile();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2020 Contributors to the Eclipse Foundation
* Copyright (c) 2019-2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -100,7 +100,7 @@ public EntityGraph transform(TServiceTemplate serviceTemplate) {
}

private void createRelation(TRelationshipTemplate relationship, EntityGraph entityGraph) {
EntityId sourceComponentEntityId = EntityGraph.COMPONENTS.extend(relationship.getSourceElement().getRef().getName());
EntityId sourceComponentEntityId = EntityGraph.COMPONENTS.extend(relationship.getSourceElement().getRef().getId());
// the entity will always be in the graph since we first transform the NodeTemplates
entityGraph.getEntity(sourceComponentEntityId).ifPresent(entity -> {
EntityId relationTypeEntityId = createType(
Expand All @@ -120,15 +120,15 @@ private void createRelation(TRelationshipTemplate relationship, EntityGraph enti
entityGraph.addEntity(new MappingEntity(relationEntityId, entityGraph));
createProperties(relationship, relationEntityId, entityGraph);
} else {
String targetComponent = relationship.getTargetElement().getRef().getName();
String targetComponent = relationship.getTargetElement().getRef().getId();
entityGraph.addEntity(new ScalarEntity(targetComponent, relationEntityId, entityGraph));
}
});
}

private void createNode(TNodeTemplate nodeTemplate, EntityGraph entityGraph) {
// create the component inside the topology.
EntityId componentNodeId = EntityGraph.COMPONENTS.extend(nodeTemplate.getName());
EntityId componentNodeId = EntityGraph.COMPONENTS.extend(nodeTemplate.getId());
entityGraph.addEntity(new MappingEntity(componentNodeId, entityGraph));

// add the type to the model
Expand Down Expand Up @@ -161,14 +161,8 @@ private void createArtifact(TNodeTemplate nodeTemplate, EntityId componentNodeId
EntityId artifactEntityId = artifactsEntityId.extend(
artifact.getArtifactType().getLocalPart().toLowerCase()
);

createPathReferenceEntity(entityGraph, path, artifactEntityId);

entityGraph.addEntity(new ScalarEntity(
path != null && this.useAbsolutePaths ? Environments.getInstance().getRepositoryConfig().getRepositoryRoot() + "/" + path : path,
artifactEntityId,
entityGraph
));
}
}
}
Expand Down Expand Up @@ -313,15 +307,18 @@ private String getImplementationForOperation(TEntityTypeImplementation implement

if (artifacts.size() == 1 && artifacts.get(0).getArtifactRef() != null) {
TArtifactTemplate artifactTemplate = artifactTemplates.get(artifacts.get(0).getArtifactRef());
if (artifactTemplate.getArtifactReferences().getArtifactReference().size() > 0) {
if (artifactTemplate.getArtifactReferences() != null &&
artifactTemplate.getArtifactReferences().getArtifactReference().size() > 0) {
return artifactTemplate.getArtifactReferences().getArtifactReference().get(0).getReference();
}
}

for (TImplementationArtifacts.ImplementationArtifact artifact : artifacts) {
if (artifact.getOperationName().equals(operationName)) {
TArtifactTemplate artifactTemplate = artifactTemplates.get(artifact.getArtifactRef());
if (artifactTemplate != null && artifactTemplate.getArtifactReferences().getArtifactReference().size() > 0) {
if (artifactTemplate != null &&
artifactTemplate.getArtifactReferences() != null &&
artifactTemplate.getArtifactReferences().getArtifactReference().size() > 0) {
return artifactTemplate.getArtifactReferences().getArtifactReference().get(0).getReference();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*******************************************************************************
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/

package org.eclipse.winery.edmm.plugins;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import io.github.edmm.core.plugin.PluginService;
import io.github.edmm.core.plugin.TransformationPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class PluginManager {

private static final Logger LOGGER = LoggerFactory.getLogger(PluginManager.class);
private static PluginManager instance;

private final List<TransformationPlugin<?>> pluginsList = new ArrayList<>();

private PluginManager() {
initPlugins();
}

public static PluginManager getInstance() {
if (instance == null) {
instance = new PluginManager();
}
return instance;
}

public PluginService getPluginService() {
return new PluginService(pluginsList, new ArrayList<>());
}

/**
* Init the plugins lists with the plugins specified in the pluginContext.xml file in the transformation-framework
* package
*/
private void initPlugins() {
for (String classpath : getPluginsClassPaths()) {
TransformationPlugin<?> plugin;
// the plugin are initialized by reflection
try {
Class<?> pluginClass = Class.forName(classpath);
Constructor<?> constructor = pluginClass.getConstructor();
plugin = (TransformationPlugin<?>) constructor.newInstance();
pluginsList.add(plugin);
} catch (Exception e) {
// just the single plugin won't work
LOGGER.error("Plugin" + classpath + "initialization failed", e);
}
}
}

/**
* Read the pluginContext configuration file
*
* @return a list containing the plugins classpaths
*/
private List<String> getPluginsClassPaths() {
List<String> pluginsClassPaths = new ArrayList<>();
Document xmlPluginConfigDocument;

// opening the file in the edmm.core package
try {
InputStream pluginsInputStream = this.getClass()
.getClassLoader()
.getResourceAsStream("pluginContext.xml");

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
xmlPluginConfigDocument = documentBuilder.parse(pluginsInputStream);
} catch (Exception e) {
LOGGER.error("Plugin file reading failed", e);
// returns an empty list, no plugins will be initialized
return pluginsClassPaths;
}

// the plugins are listed with the tag name 'bean'
NodeList pluginsNodeList = xmlPluginConfigDocument.getElementsByTagName("bean");
for (int i = 0; i < pluginsNodeList.getLength(); i++) {
Node plugin = pluginsNodeList.item(i);
String classpath = plugin.getAttributes().getNamedItem("class").getNodeValue();
pluginsClassPaths.add(classpath);
}

return pluginsClassPaths;
}

public List<TransformationPlugin<?>> getPluginsList() {
return pluginsList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the Apache Software License 2.0
* which is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
*******************************************************************************/
package org.eclipse.winery.edmm.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import io.github.edmm.utils.Compress;

public class ZipUtility {

public static void pack(Path sourcePath, Path destPath) {
Compress.zip(sourcePath, destPath);
}

/**
* @param zipFilePath the Path of the zip file to unpack
* @param destDirPath the Path of the directory where we want the unzipped files, if the direcory exists it will be
* overwritten
* @return it return destDirPath
*/
public static Path unpack(Path zipFilePath, Path destDirPath) throws IOException {
if (Files.exists(destDirPath)) {
Files.delete(destDirPath);
}
Files.createDirectory(destDirPath);

ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(zipFilePath.toFile()));

ZipEntry zipEntry = zipInputStream.getNextEntry();
while (zipEntry != null) {

Path newFile = destDirPath.resolve(zipEntry.getName());
Files.createDirectories(newFile.getParent());
Files.copy(zipInputStream, newFile);
zipEntry = zipInputStream.getNextEntry();
}
zipInputStream.closeEntry();
zipInputStream.close();

return destDirPath;
}
}
Loading

0 comments on commit 7bece2b

Please sign in to comment.