use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class InstanceModelRefinementTest method completeRoundTripTest.
@Test
void completeRoundTripTest() throws Exception {
this.setRevisionTo("origin/plain");
// region ***** setup *****
InstanceModelRefinement modelRefinement = new InstanceModelRefinement(// simply iterate over all plugins and execute it once
new InstanceModelPluginChooser() {
private final String[] pluginOrder = { "Tomcat", "SpringWebApplication", "MySQL-DB", "MySQL-DBMS", "PetClinic" };
private int nextPlugin = 0;
@Override
public InstanceModelRefinementPlugin selectPlugin(TTopologyTemplate template, List<InstanceModelRefinementPlugin> plugins) {
if (nextPlugin < pluginOrder.length) {
String pluginId = pluginOrder[nextPlugin++];
Optional<InstanceModelRefinementPlugin> first = plugins.stream().filter(plugin -> plugin.getId().equals(pluginId)).findFirst();
if (first.isPresent()) {
InstanceModelRefinementPlugin plugin = first.get();
plugin.setSelectedMatchId(0);
if (plugin.getSubGraphs() != null && plugin.getSubGraphs().size() > 0 && plugin.getSubGraphs().get(0).additionalInputs != null) {
Map<String, String> inputs = new HashMap<>();
plugin.getSubGraphs().get(0).additionalInputs.forEach(input -> {
if (input.equals(InstanceModelUtils.vmIP)) {
inputs.put(InstanceModelUtils.vmIP, "localhost");
} else if (input.equals(InstanceModelUtils.vmPrivateKey)) {
InputStream resourceAsStream = Objects.requireNonNull(ClassLoader.getSystemClassLoader().getResourceAsStream("winery.test"));
try {
inputs.put(InstanceModelUtils.vmPrivateKey, IOUtils.toString(resourceAsStream));
} catch (IOException e) {
logger.error("Error while retrieving private key", e);
}
} else if (input.equals(InstanceModelUtils.vmUser)) {
inputs.put(InstanceModelUtils.vmUser, "test");
} else if (input.equals(InstanceModelUtils.vmSshPort)) {
inputs.put(InstanceModelUtils.vmSshPort, Integer.toString(sshPort));
}
});
inputs.put(InstanceModelUtils.vmSshPort, Integer.toString(sshPort));
plugin.setUserInputs(inputs, template, 0);
}
return plugin;
}
}
return null;
}
});
String expectedMySqlPort = "3306";
String expectedTomcatPort = "8080";
String expectedDatabaseUser = "dbTestUser";
String expectedDatabaseName = "testDatabase";
String expectedPetClinicContext = "petClinicTest";
sshd.setCommandFactory((channel, command) -> new SupportSuccessCommand(command) {
@Override
public String getReturnValue() {
if (this.getCommand().startsWith("sudo /usr/bin/mysql --help | grep Distrib")) {
return "5.7";
}
if (this.getCommand().startsWith("sudo netstat -tulpen | grep mysqld")) {
return expectedMySqlPort;
}
if (this.getCommand().startsWith("sudo -i mysql -sN -e \"SELECT schema_name from INFORMATION_SCHEMA.SCHEMATA") || (this.getCommand().startsWith("sudo cat /opt/tomcat/latest/webapps/") && this.getCommand().endsWith("| sed -r 's/USE (.*);$/\\1/'"))) {
return expectedDatabaseName;
}
if (this.getCommand().startsWith("sudo find /opt/tomcat/latest/webapps/") && this.getCommand().endsWith("| sed -r 's/database=(.*)$/\\1/'")) {
return "mysql";
}
if (this.getCommand().startsWith("sudo cat /opt/tomcat/latest/webapps/") && this.getCommand().endsWith("IDENTIFIED BY (.*);$/\\2/'")) {
return expectedDatabaseUser;
}
if (this.getCommand().startsWith("sudo find /opt/tomcat/latest/webapps -name *.war")) {
return expectedPetClinicContext;
}
if (this.getCommand().startsWith("sudo cat /opt/tomcat/latest/RELEASE-NOTES | grep 'Apache Tomcat")) {
return "9";
}
if (this.getCommand().startsWith("sudo cat /opt/tomcat/latest/conf/server.xml | grep '<Connector port=\".*\"")) {
return expectedTomcatPort;
}
return null;
}
});
// endregion
TTopologyTemplate topologyTemplate = modelRefinement.refine(new ServiceTemplateId("http://opentosca.org/servicetemplates", "InstancePluginsTest_w1-wip1", false));
// region ***** assertions *****
assertNotNull(topologyTemplate);
assertEquals(5, topologyTemplate.getNodeTemplates().size());
TNodeTemplate petClinic = topologyTemplate.getNodeTemplate("Pet_Clinic_w1_0");
assertNotNull(petClinic);
TEntityTemplate.Properties petClinicProperties = petClinic.getProperties();
assertNotNull(petClinicProperties);
assertTrue(petClinicProperties instanceof TEntityTemplate.WineryKVProperties);
assertEquals(expectedPetClinicContext, ((TEntityTemplate.WineryKVProperties) petClinicProperties).getKVProperties().get("context"));
TNodeTemplate mySqlDb = topologyTemplate.getNodeTemplate("MySQL-DB_0");
assertNotNull(mySqlDb);
TEntityTemplate.Properties mySqlDbProperties = mySqlDb.getProperties();
assertNotNull(mySqlDbProperties);
assertTrue(mySqlDbProperties instanceof TEntityTemplate.WineryKVProperties);
assertEquals(expectedDatabaseName, ((TEntityTemplate.WineryKVProperties) mySqlDbProperties).getKVProperties().get("DBName"));
assertEquals(expectedDatabaseUser, ((TEntityTemplate.WineryKVProperties) mySqlDbProperties).getKVProperties().get("DBUser"));
TNodeTemplate tomcat = topologyTemplate.getNodeTemplate("Tomcat_0");
assertNotNull(tomcat);
TEntityTemplate.Properties tomcatProperties = tomcat.getProperties();
assertNotNull(tomcatProperties);
assertEquals(QName.valueOf("{http://opentosca.org/nodetypes}Tomcat_9-w1"), tomcat.getType());
assertTrue(tomcatProperties instanceof TEntityTemplate.WineryKVProperties);
assertEquals(expectedTomcatPort, ((TEntityTemplate.WineryKVProperties) tomcatProperties).getKVProperties().get("Port"));
TNodeTemplate dbms = topologyTemplate.getNodeTemplate("MySQL-DBMS_0");
assertNotNull(dbms);
TEntityTemplate.Properties dbmsProperties = dbms.getProperties();
assertNotNull(dbmsProperties);
assertEquals(QName.valueOf("{http://opentosca.org/nodetypes}MySQL-DBMS_5.7-w1"), dbms.getType());
assertTrue(dbmsProperties instanceof TEntityTemplate.WineryKVProperties);
assertEquals(expectedMySqlPort, ((TEntityTemplate.WineryKVProperties) dbmsProperties).getKVProperties().get("DBMSPort"));
// endregion
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class InstanceModelRefinementTest method refineEmpty.
@Test
void refineEmpty() {
InstanceModelRefinement modelRefinement = new InstanceModelRefinement((template, plugins) -> null);
TTopologyTemplate topologyTemplate = modelRefinement.refine(new ServiceTemplateId("http://opentosca.org/servicetemplates", "myCoolNotExistingServiceTemplate", false));
assertNull(topologyTemplate);
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId 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.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class SubstitutionTestWithGitBackedRepository method substituteNodeTemplateTypes.
@Test
public void substituteNodeTemplateTypes() throws Exception {
this.setRevisionTo("16a4ec8a55c4a87d8a46088d283640adadd2f07c");
Substitution substitution = new Substitution();
ServiceTemplateId serviceTemplateId = new ServiceTemplateId("http://plain.winery.org/pattern-based/servicetemplates", "ServiceTemplateContainingAbstractNodeTemplates_w1-wip1", false);
ServiceTemplateId newId = substitution.substituteTopologyOfServiceTemplate(serviceTemplateId);
TServiceTemplate element = repo.getElement(newId);
assertNotNull(element.getTopologyTemplate());
List<TNodeTemplate> nodeTemplates = element.getTopologyTemplate().getNodeTemplates();
assertEquals(5, nodeTemplates.size());
// ensure these types do not exist anymore
assertFalse(nodeTemplates.removeIf(tNodeTemplate -> new QName("http://plain.winery.opentosca.org/patterns", "Infrastructure-As-A-Service_w1").equals(tNodeTemplate.getType()) || new QName("http://plain.winery.opentosca.org/pattern-based/nodetypes", "AbstractNodeTypeWithProperties_1-w1-wip1").equals(tNodeTemplate.getType())));
assertTrue(nodeTemplates.removeIf(tNodeTemplate -> new QName("http://plain.winery.org/pattern-based/nodetypes", "Infrastructure-As-A-Service-Implementation_1-w1-wip1").equals(tNodeTemplate.getType())));
assertTrue(nodeTemplates.removeIf(tNodeTemplate -> new QName("http://plain.winery.org/pattern-based/nodetypes", "NodeTypeInheritingFromAbstractType_1-w1-wip1").equals(tNodeTemplate.getType())));
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class SubstitutionTestWithGitBackedRepository method substituteNodeTemplateWithServiceTemplateAndOutgoingRelationship.
@Test
public void substituteNodeTemplateWithServiceTemplateAndOutgoingRelationship() throws Exception {
this.setRevisionTo("origin/plain");
Substitution substitution = new Substitution();
ServiceTemplateId serviceTemplateId = new ServiceTemplateId("http://plain.winery.org/pattern-based/servicetemplates", "ServiceTemplateContainingAbstractNodeTemplates_w3-wip1", false);
ServiceTemplateId substitutedServiceTemplate = substitution.substituteTopologyOfServiceTemplate(serviceTemplateId);
TServiceTemplate element = repo.getElement(substitutedServiceTemplate);
assertNotNull(element.getTopologyTemplate());
assertNotNull(element.getTopologyTemplate().getNodeTemplates());
assertEquals(5, element.getTopologyTemplate().getNodeTemplates().size());
assertNotNull(element.getTopologyTemplate().getRelationshipTemplates());
assertEquals(4, element.getTopologyTemplate().getRelationshipTemplates().size());
assertEquals("NodeTypeWithThreeReqCapPairsCoveringAllReqCapVariants_w1-wip1", element.getTopologyTemplate().getRelationshipTemplate("con_2").getSourceElement().getRef().getId());
}
Aggregations