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;
}
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());
}
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);
}
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());
}
Aggregations