Skip to content

Commit

Permalink
Feature/model (winery#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
lharzenetter authored Aug 6, 2021
1 parent 2d5e36f commit d3030dd
Show file tree
Hide file tree
Showing 307 changed files with 6,150 additions and 10,463 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Winery CI
on: [ push, pull_request ]

jobs:

pre_job:
continue-on-error: true
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* 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.common;

import java.util.List;

public abstract class ListUtils {

public static boolean listIsNotNullOrEmpty(List<?> list) {
return list != null && !list.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public boolean isCompatible(ToscaNode left, ToscaNode right) {
public boolean isPoliciesCompatible(ToscaNode left, ToscaNode right) {
if (left.getTemplate().getPolicies() != null) {
if (right.getTemplate().getPolicies() != null) {
return mapToStringList(right.getTemplate().getPolicies().getPolicy()).containsAll(mapToStringList(left.getTemplate().getPolicies().getPolicy()));
return mapToStringList(right.getTemplate().getPolicies())
.containsAll(
mapToStringList(left.getTemplate().getPolicies())
);
} else {
return false;
}
Expand All @@ -58,7 +61,7 @@ public boolean isPoliciesCompatible(ToscaNode left, ToscaNode right) {
}

private List<String> mapToStringList(@NonNull List<TPolicy> policy) {
return policy.stream().map(p -> p.getPolicyType().toString() + p.getPolicyRef().toString()).collect(Collectors.toList());
return policy.stream().map(p -> p.getPolicyType() + p.getPolicyRef().toString()).collect(Collectors.toList());
}

public boolean isPropertiesCompatible(ToscaNode left, ToscaNode right) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult;
import org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker;
import org.eclipse.winery.compliance.checking.ToscaComplianceRuleMatcher;
import org.eclipse.winery.model.ids.extensions.ComplianceRuleId;
import org.eclipse.winery.model.ids.definitions.DefinitionsChildId;
import org.eclipse.winery.model.ids.definitions.NodeTypeId;
import org.eclipse.winery.model.ids.definitions.ServiceTemplateId;
import org.eclipse.winery.model.ids.extensions.ComplianceRuleId;
import org.eclipse.winery.model.tosca.TExtensibleElements;
import org.eclipse.winery.model.tosca.TNodeTemplate;
import org.eclipse.winery.model.tosca.TNodeType;
Expand Down Expand Up @@ -75,9 +75,10 @@ private void persist(HashMap<DefinitionsChildId, TExtensibleElements> allEntitie

@Test
public void testTComplianceRulePersistence() throws Exception {
OTComplianceRule rule = new OTComplianceRule(new OTComplianceRule.Builder());
rule.setName("test");
rule.setTargetNamespace(TEST_TARGET_NAMESPACE);
OTComplianceRule rule = new OTComplianceRule.Builder("test")
.setName("test")
.setTargetNamespace(TEST_TARGET_NAMESPACE)
.build();

ComplianceRuleId id = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test"));
BackendUtils.persist(repository, id, rule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import java.util.List;

import javax.xml.namespace.QName;

import org.eclipse.winery.common.version.WineryVersion;
import org.eclipse.winery.model.tosca.TNodeType;

Expand All @@ -39,11 +41,16 @@ public void createMyAppNode() {
nodeTypes = new CookbookConfigurationToscaConverter().convertCookbookConfigurationToToscaNode(cookbookConfiguration, 1);

assertEquals(2, nodeTypes.size());
assertEquals(true, nodeTypes.get(0).getCapabilityDefinitions().getCapabilityDefinition().get(0).getCapabilityType().toString().endsWith("myapp-1.1"));
assertEquals(true, nodeTypes.get(0).getCapabilityDefinitions().getCapabilityDefinition().get(1).getCapabilityType().toString().endsWith("myappaddon-1.2"));
assertEquals(true, nodeTypes.get(0).getRequirementDefinitions().getRequirementDefinition().get(1).getRequirementType().toString().endsWith("openjdk-8-jdk"));
assertEquals(true, nodeTypes.get(0).getRequirementDefinitions().getRequirementDefinition().get(2).getRequirementType().toString().endsWith("openjdk-8-jre-headless"));

assertEquals(true, nodeTypes.get(1).getCapabilityDefinitions().getCapabilityDefinition().get(0).getCapabilityType().toString().endsWith("ubuntu_16.04" + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1"));
QName capabilityType = nodeTypes.get(0).getCapabilityDefinitions().get(0).getCapabilityType();
assertNotNull(capabilityType);
assertTrue(capabilityType.toString().endsWith("myapp-1.1"));

QName capabilityType1 = nodeTypes.get(0).getCapabilityDefinitions().get(1).getCapabilityType();
assertNotNull(capabilityType1);
assertTrue(capabilityType1.toString().endsWith("myappaddon-1.2"));
assertTrue(nodeTypes.get(0).getRequirementDefinitions().get(1).getRequirementType().toString().endsWith("openjdk-8-jdk"));
assertTrue(nodeTypes.get(0).getRequirementDefinitions().get(2).getRequirementType().toString().endsWith("openjdk-8-jre-headless"));

assertTrue(nodeTypes.get(1).getCapabilityDefinitions().get(0).getCapabilityType().toString().endsWith("ubuntu_16.04" + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import org.eclipse.winery.model.tosca.TEntityTemplate;
import org.eclipse.winery.model.tosca.TEntityType;
import org.eclipse.winery.model.tosca.TEntityTypeImplementation;
import org.eclipse.winery.model.tosca.TImplementationArtifacts;
import org.eclipse.winery.model.tosca.TInterfaces;
import org.eclipse.winery.model.tosca.TImplementationArtifact;
import org.eclipse.winery.model.tosca.TInterface;
import org.eclipse.winery.model.tosca.TNodeTemplate;
import org.eclipse.winery.model.tosca.TNodeType;
import org.eclipse.winery.model.tosca.TNodeTypeImplementation;
Expand Down Expand Up @@ -213,16 +213,16 @@ private void createNode(TNodeTemplate nodeTemplate, EntityGraph entityGraph) {

private void createArtifact(TNodeTemplate nodeTemplate, EntityId componentNodeId, EntityGraph entityGraph) {
if (nodeTemplate.getDeploymentArtifacts() != null
&& nodeTemplate.getDeploymentArtifacts().getDeploymentArtifact().size() > 0) {
&& nodeTemplate.getDeploymentArtifacts().size() > 0) {
EntityId artifactsEntityId = componentNodeId.extend(DefaultKeys.ARTIFACTS);
entityGraph.addEntity(new SequenceEntity(artifactsEntityId, entityGraph));

for (TDeploymentArtifact artifact : nodeTemplate.getDeploymentArtifacts().getDeploymentArtifact()) {
for (TDeploymentArtifact artifact : nodeTemplate.getDeploymentArtifacts()) {
String path = null;

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

EntityId artifactEntityId = artifactsEntityId.extend(
Expand Down Expand Up @@ -354,9 +354,9 @@ private void createPropertiesDefinition(TEntityType toscaType, EntityId typeEnti

private void createOperations(TEntityType type, EntityId nodeTypeEntityId, EntityGraph entityGraph) {
if (type instanceof TNodeType && Objects.nonNull(((TNodeType) type).getInterfaces())) {
TInterfaces interfaces = ((TNodeType) type).getInterfaces();
interfaces.getInterface().forEach(anInterface -> {
anInterface.getOperation().forEach(operation -> {
List<TInterface> interfaces = ((TNodeType) type).getInterfaces();
interfaces.forEach(anInterface -> {
anInterface.getOperations().forEach(operation -> {
EntityId operationsEntityId = nodeTypeEntityId.extend(DefaultKeys.OPERATIONS);
entityGraph.addEntity(new MappingEntity(operationsEntityId, entityGraph));

Expand All @@ -376,26 +376,27 @@ private void createOperations(TEntityType type, EntityId nodeTypeEntityId, Entit
private String getImplementationForOperation(TEntityTypeImplementation implementation,
String interfaceName, String operationName) {
if (implementation != null && implementation.getImplementationArtifacts() != null) {
List<TImplementationArtifacts.ImplementationArtifact> artifacts = implementation.getImplementationArtifacts()
.getImplementationArtifact().stream()
List<TImplementationArtifact> artifacts = implementation.getImplementationArtifacts()
.stream()
.filter(artifact -> artifact.getInterfaceName() != null)
.filter(artifact -> artifact.getInterfaceName().equals(interfaceName))
.collect(Collectors.toList());

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

for (TImplementationArtifacts.ImplementationArtifact artifact : artifacts) {
if (artifact.getOperationName().equals(operationName)) {
for (TImplementationArtifact artifact : artifacts) {
if (artifact.getOperationName() != null && artifact.getOperationName().equals(operationName)) {
TArtifactTemplate artifactTemplate = artifactTemplates.get(artifact.getArtifactRef());
if (artifactTemplate != null &&
artifactTemplate.getArtifactReferences() != null &&
artifactTemplate.getArtifactReferences().getArtifactReference().size() > 0) {
return artifactTemplate.getArtifactReferences().getArtifactReference().get(0).getReference();
artifactTemplate.getArtifactReferences().size() > 0) {
return artifactTemplate.getArtifactReferences().get(0).getReference();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private void checkNodeType(QName type) {
// todo: some inheritance or mapping check?

if (nodeType.getInterfaces() != null) {
List<TInterface> interfaceList = nodeType.getInterfaces().getInterface();
List<TInterface> interfaceList = nodeType.getInterfaces();
if (interfaceList.size() > 0) {
interfaceList.stream()
.filter(ToscaLightUtils::isNotLifecycleInterface)
Expand All @@ -164,8 +164,10 @@ private void checkRelationType(QName type) {
}

// todo ?
relType.getSourceInterfaces();
relType.getTargetInterfaces();
if (relType != null) {
relType.getSourceInterfaces();
relType.getTargetInterfaces();
}
}

private boolean isElementVisited(QName qName) {
Expand Down
Loading

0 comments on commit d3030dd

Please sign in to comment.