Search in sources :

Example 21 with ServiceTemplateId

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
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) TestWithGitRepoAndSshServer(org.eclipse.winery.repository.TestWithGitRepoAndSshServer) URISyntaxException(java.net.URISyntaxException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) OpenToscaBaseTypes(org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Logger(org.slf4j.Logger) Set(java.util.Set) IOException(java.io.IOException) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) Optional(java.util.Optional) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) InputStream(java.io.InputStream) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) HashMap(java.util.HashMap) Map(java.util.Map) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Test(org.junit.jupiter.api.Test)

Example 22 with ServiceTemplateId

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);
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 23 with ServiceTemplateId

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());
}
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 24 with ServiceTemplateId

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())));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) List(java.util.List) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) IRepository(org.eclipse.winery.repository.backend.IRepository) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) QName(javax.xml.namespace.QName) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test)

Example 25 with ServiceTemplateId

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());
}
Also used : ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)126 Test (org.junit.jupiter.api.Test)73 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)44 ArrayList (java.util.ArrayList)41 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)40 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)35 QName (javax.xml.namespace.QName)25 IOException (java.io.IOException)24 IRepository (org.eclipse.winery.repository.backend.IRepository)19 List (java.util.List)17 POST (javax.ws.rs.POST)17 Path (javax.ws.rs.Path)16 Produces (javax.ws.rs.Produces)16 HashMap (java.util.HashMap)15 TopologyWrapper (org.eclipse.winery.repository.targetallocation.util.TopologyWrapper)15 Map (java.util.Map)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)14 URI (java.net.URI)13 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)13 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13