Search in sources :

Example 1 with SolutionInputData

use of org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData in project winery by eclipse.

the class IpSecAlgorithm method applySolution.

@Override
public boolean applySolution(TTopologyTemplate topology, SolutionInputData inputData) {
    IRepository repository = RepositoryFactory.getRepository();
    NamespaceManager namespaceManager = repository.getNamespaceManager();
    Map<QName, TNodeType> nodeTypes = repository.getQNameToElementMapping(NodeTypeId.class);
    TNodeTemplate[] elements = new TNodeTemplate[2];
    for (int index = 0; index < 2; index++) {
        ComponentFinding componentFinding = inputData.getFindings().get(index);
        elements[index] = getVmHost(topology, componentFinding.getComponentId());
        if (Objects.isNull(elements[index])) {
            elements[index] = topology.getNodeTemplate(componentFinding.getComponentId());
        }
        Map<QName, TNodeType> children = ModelUtilities.getChildrenOf(elements[index].getType(), nodeTypes);
        // simply use the first element
        Optional<Map.Entry<QName, TNodeType>> firstSecure = children.entrySet().stream().filter(entry -> namespaceManager.isSecureCollection(entry.getKey().getNamespaceURI())).findFirst();
        if (firstSecure.isPresent()) {
            ModelUtilities.updateNodeTemplate(topology, elements[index].getId(), firstSecure.get().getKey(), firstSecure.get().getValue());
        } else {
            return false;
        }
    }
    // forward connection
    ModelUtilities.createRelationshipTemplateAndAddToTopology(elements[1], elements[0], ToscaBaseTypes.connectsToRelationshipType, "securely_connectsTo", topology);
    // backward connection
    ModelUtilities.createRelationshipTemplateAndAddToTopology(elements[0], elements[1], ToscaBaseTypes.connectsToRelationshipType, "securely_connectsTo", topology);
    return true;
}
Also used : SolutionInputData(org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData) TNodeType(org.eclipse.winery.model.tosca.TNodeType) OpenToscaBaseTypes(org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) ArrayList(java.util.ArrayList) Objects(java.util.Objects) SolutionStrategy(org.eclipse.winery.model.adaptation.problemsolving.SolutionStrategy) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) IRepository(org.eclipse.winery.repository.backend.IRepository) Map(java.util.Map) Optional(java.util.Optional) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) QName(javax.xml.namespace.QName) ComponentFinding(org.eclipse.winery.model.adaptation.problemsolving.ComponentFinding) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ToscaBaseTypes(org.eclipse.winery.model.tosca.constants.ToscaBaseTypes) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) QName(javax.xml.namespace.QName) ComponentFinding(org.eclipse.winery.model.adaptation.problemsolving.ComponentFinding) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Example 2 with SolutionInputData

use of org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData in project winery by eclipse.

the class IpSecAlgorithmTest method applySolutionTest.

@Test
public void applySolutionTest() throws Exception {
    this.setRevisionTo("a23f1c89c77fcde4de9fe7822532dc04e31731a0");
    IpSecAlgorithm ipSecAlgorithm = new IpSecAlgorithm();
    TTopologyTemplate topologyTemplate = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(QName.valueOf("{http://plain.winery.opentosca.org/servicetemplates}ServiceTemplateWithIpSecProblem_w1-wip1"))).getTopologyTemplate();
    ArrayList<ComponentFinding> componentFindings = new ArrayList<>();
    componentFindings.add(new ComponentFinding(null, "NodeTypeWithImplementation_1.0-w1-wip1"));
    componentFindings.add(new ComponentFinding(null, "NodeTypeWithXmlElementProperty"));
    SolutionInputData inputData = new SolutionInputData();
    inputData.setFindings(componentFindings);
    ipSecAlgorithm.applySolution(topologyTemplate, inputData);
    assertEquals(4, topologyTemplate.getNodeTemplates().size());
    assertEquals(QName.valueOf("{http://plain.winery.opentosca.org/secure/nodetypes}ubuntu_18-secure-w1-wip1"), topologyTemplate.getNodeTemplate("replaceableNode_1").getType());
    assertEquals(QName.valueOf("{http://plain.winery.opentosca.org/secure/nodetypes}ubuntu_18-secure-w1-wip1"), topologyTemplate.getNodeTemplate("replaceableNode_2").getType());
    assertEquals(5, topologyTemplate.getRelationshipTemplates().size());
    TRelationshipTemplate forward = topologyTemplate.getRelationshipTemplate("con-replaceableNode_2-securely_connectsTo-replaceableNode_1");
    assertNotNull(forward);
    assertEquals("replaceableNode_2", forward.getSourceElement().getRef().getId());
    assertEquals("replaceableNode_1", forward.getTargetElement().getRef().getId());
    TRelationshipTemplate backward = topologyTemplate.getRelationshipTemplate("con-replaceableNode_1-securely_connectsTo-replaceableNode_2");
    assertNotNull(backward);
    assertEquals("replaceableNode_1", backward.getSourceElement().getRef().getId());
    assertEquals("replaceableNode_2", backward.getTargetElement().getRef().getId());
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) SolutionInputData(org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) ComponentFinding(org.eclipse.winery.model.adaptation.problemsolving.ComponentFinding) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 3 with SolutionInputData

use of org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData in project winery by eclipse.

the class AbstractSecureProxyAlgorithm method applySolution.

@Override
public boolean applySolution(TTopologyTemplate topology, SolutionInputData inputData) {
    if (Objects.isNull(inputData.getFindings()) || inputData.getFindings().size() < 2) {
        return false;
    }
    String firstComponentId = inputData.getFindings().get(0).getComponentId();
    TNodeTemplate firstComponent = topology.getNodeTemplate(firstComponentId);
    String secondComponentId = inputData.getFindings().get(1).getComponentId();
    TNodeTemplate secondComponent = topology.getNodeTemplate(secondComponentId);
    Optional<TRelationshipTemplate> connectsToRelation = ModelUtilities.getOutgoingRelationshipTemplates(topology, firstComponent).stream().filter(relationship -> relationship.getType().equals(ToscaBaseTypes.connectsToRelationshipType)).filter(relationship -> relationship.getTargetElement().getRef().getId().equals(secondComponentId)).findFirst();
    if (!connectsToRelation.isPresent()) {
        connectsToRelation = ModelUtilities.getOutgoingRelationshipTemplates(topology, secondComponent).stream().filter(relationship -> relationship.getType().equals(ToscaBaseTypes.connectsToRelationshipType)).filter(relationship -> relationship.getTargetElement().getRef().getId().equals(firstComponentId)).findFirst();
        return connectsToRelation.isPresent() && insertProxy(secondComponent, firstComponent, connectsToRelation.get(), topology);
    }
    return insertProxy(firstComponent, secondComponent, connectsToRelation.get(), topology);
}
Also used : SolutionInputData(org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) ArrayList(java.util.ArrayList) Objects(java.util.Objects) SolutionStrategy(org.eclipse.winery.model.adaptation.problemsolving.SolutionStrategy) Map(java.util.Map) Optional(java.util.Optional) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ToscaBaseTypes(org.eclipse.winery.model.tosca.constants.ToscaBaseTypes) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 4 with SolutionInputData

use of org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData in project winery by eclipse.

the class SecureContainerProxyAlgorithmTest method insertContainerProxyTest.

@Test
public void insertContainerProxyTest() throws Exception {
    this.setRevisionTo("eb37f5cfec50c046985eac308e46482ce8bea8e3");
    TTopologyTemplate topologyTemplate = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(QName.valueOf("{http://plain.winery.opentosca.org/servicetemplates}StWithSecureProxyContainerProblem_w1-wip1"))).getTopologyTemplate();
    ArrayList<ComponentFinding> componentFindings = new ArrayList<>();
    componentFindings.add(new ComponentFinding(null, "sourceNode"));
    componentFindings.add(new ComponentFinding(null, "targetNode"));
    SolutionInputData inputData = new SolutionInputData();
    inputData.setFindings(componentFindings);
    new SecureContainerProxyAlgorithm().applySolution(topologyTemplate, inputData);
    assertEquals(6, topologyTemplate.getNodeTemplates().size());
    assertEquals(7, topologyTemplate.getRelationshipTemplates().size());
    assertNotNull(topologyTemplate.getNodeTemplate("sourceNode_proxy"));
    assertNotNull(topologyTemplate.getNodeTemplate("targetNode_proxy"));
    TRelationshipTemplate sourceToProxy = topologyTemplate.getRelationshipTemplate("con-sourceNode-connectsTo-sourceNode_proxy");
    assertNotNull(sourceToProxy);
    assertEquals("sourceNode", sourceToProxy.getSourceElement().getRef().getId());
    assertEquals("sourceNode_proxy", sourceToProxy.getTargetElement().getRef().getId());
    TRelationshipTemplate proxyToProxy = topologyTemplate.getRelationshipTemplate("con-sourceNode_proxy-securely-connectsTo-targetNode_proxy");
    assertNotNull(proxyToProxy);
    assertEquals("sourceNode_proxy", proxyToProxy.getSourceElement().getRef().getId());
    assertEquals("targetNode_proxy", proxyToProxy.getTargetElement().getRef().getId());
    TRelationshipTemplate targetProxyToTarget = topologyTemplate.getRelationshipTemplate("con-targetNode_proxy-connectsTo-targetNode");
    assertNotNull(targetProxyToTarget);
    assertEquals("targetNode_proxy", targetProxyToTarget.getSourceElement().getRef().getId());
    assertEquals("targetNode", targetProxyToTarget.getTargetElement().getRef().getId());
    TRelationshipTemplate sourceProxyOnDocker = topologyTemplate.getRelationshipTemplate("con-sourceNode_proxy-hostedOn-DockerEngine");
    assertNotNull(sourceProxyOnDocker);
    assertEquals("sourceNode_proxy", sourceProxyOnDocker.getSourceElement().getRef().getId());
    assertEquals("DockerEngine", sourceProxyOnDocker.getTargetElement().getRef().getId());
    TRelationshipTemplate targetProxyOnDocker2 = topologyTemplate.getRelationshipTemplate("con-targetNode_proxy-hostedOn-DockerEngine_2");
    assertNotNull(targetProxyOnDocker2);
    assertEquals("targetNode_proxy", targetProxyOnDocker2.getSourceElement().getRef().getId());
    assertEquals("DockerEngine_2", targetProxyOnDocker2.getTargetElement().getRef().getId());
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) SolutionInputData(org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) ArrayList(java.util.ArrayList) ComponentFinding(org.eclipse.winery.model.adaptation.problemsolving.ComponentFinding) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)4 SolutionInputData (org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData)4 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)4 ComponentFinding (org.eclipse.winery.model.adaptation.problemsolving.ComponentFinding)3 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)3 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 QName (javax.xml.namespace.QName)2 SolutionStrategy (org.eclipse.winery.model.adaptation.problemsolving.SolutionStrategy)2 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)2 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)2 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)2 TNodeType (org.eclipse.winery.model.tosca.TNodeType)2 ToscaBaseTypes (org.eclipse.winery.model.tosca.constants.ToscaBaseTypes)2 ModelUtilities (org.eclipse.winery.model.tosca.utils.ModelUtilities)2 RepositoryFactory (org.eclipse.winery.repository.backend.RepositoryFactory)2 Test (org.junit.jupiter.api.Test)2 OpenToscaBaseTypes (org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1