Search in sources :

Example 11 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class InstanceModelWebSocket method startInstanceModelRefinement.

private void startInstanceModelRefinement(QName serviceTemplate) {
    Thread thread = new Thread(() -> {
        this.instanceModelRefiner = new InstanceModelRefinement(this);
        DataToSend dataToSend = new DataToSend();
        dataToSend.topologyTemplate = this.instanceModelRefiner.refine(new ServiceTemplateId(serviceTemplate));
        try {
            this.sendAsync(dataToSend);
            this.onClose(this.session);
        } catch (JsonProcessingException e) {
            logger.error("Error while sending final topology template!", e);
        } catch (IOException e) {
            logger.error("Error while closing web socket!", e);
        }
    });
    thread.start();
}
Also used : InstanceModelRefinement(org.eclipse.winery.model.adaptation.instance.InstanceModelRefinement) IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 12 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class RefinementWebSocket method onMessage.

@Override
@OnMessage
public void onMessage(String message, Session session) throws IOException {
    RefinementWebSocketApiData data = JacksonProvider.mapper.readValue(message, RefinementWebSocketApiData.class);
    switch(data.task) {
        case START:
            if (!running) {
                Thread thread = new Thread(() -> {
                    RefinementElementApiData element = new RefinementElementApiData();
                    element.serviceTemplateContainingRefinements = refinement.refineServiceTemplate(new ServiceTemplateId(data.serviceTemplate));
                    try {
                        this.sendAsync(element);
                        this.session.close();
                        this.session = null;
                    } catch (JsonProcessingException e) {
                        LOGGER.error("Error while sending refinement result", e);
                    } catch (IOException e) {
                        LOGGER.error("Error while closing the session", e);
                    }
                    running = false;
                });
                this.running = true;
                thread.start();
            }
            break;
        case REFINE_WITH:
            this.future.complete(data.refineWith);
            break;
        case STOP:
            this.future.complete(-1);
            this.sendAsync(new RefinementElementApiData(null, this.refinementServiceTemplate, null));
            this.onClose(this.session);
            break;
    }
}
Also used : IOException(java.io.IOException) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) RefinementElementApiData(org.eclipse.winery.repository.rest.resources.apiData.RefinementElementApiData) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) OnMessage(javax.websocket.OnMessage)

Example 13 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class EnhancementUtilsTestWithGitBackedRepository method getAvailableFeaturesWhereASpecificRequirementIsSatisfied.

@Test
void getAvailableFeaturesWhereASpecificRequirementIsSatisfied() throws Exception {
    this.setRevisionTo("origin/plain");
    TServiceTemplate serviceTemplate = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(QName.valueOf("{http://opentosca.org/add/management/to/instances/servicetemplates}STWithBasicManagementOnly_w1-wip2")));
    Map<String, Map<QName, String>> availableFeaturesForTopology = // As we do not want to filter the features based on the deployment technology, the second parameter is null.
    EnhancementUtils.getAvailableFeaturesForTopology(serviceTemplate.getTopologyTemplate(), Collections.emptyList());
    assertEquals(2, availableFeaturesForTopology.size());
    assertEquals(2, availableFeaturesForTopology.get("MySQL-Database_w2").size());
    assertEquals(2, availableFeaturesForTopology.get("Ubuntu_16.04-w1").size());
}
Also used : ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) HashMap(java.util.HashMap) Map(java.util.Map) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test)

Example 14 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class EnhancementUtilsTestWithGitBackedRepository method applyFeaturesToTopology.

@Test
void applyFeaturesToTopology() throws Exception {
    this.setRevisionTo("origin/plain");
    TTopologyTemplate topology = RepositoryFactory.getRepository().getElement(new ServiceTemplateId(QName.valueOf("{http://opentosca.org/add/management/to/instances/servicetemplates}STWithBasicManagementOnly_w1-wip1"))).getTopologyTemplate();
    // As we do not want to filter the features based on the deployment technology, the second parameter is null.
    EnhancementUtils.applyFeaturesForTopology(topology, EnhancementUtils.getAvailableFeaturesForTopology(topology, Collections.emptyList()));
    String ubuntuNodeTemplateId = "Ubuntu_16.04-w1";
    String mySqlNodeTemplateId = "MySQL-Database_w1";
    assertEquals(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes" + EnhancementUtils.GENERATED_NS_SUFFIX + "}Ubuntu_16.04-w1-" + ubuntuNodeTemplateId + "-Testing-Freeze_and_Defrost" + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1"), topology.getNodeTemplate(ubuntuNodeTemplateId).getType());
    assertEquals(QName.valueOf("{http://opentosca.org/add/management/to/instances/nodetypes" + EnhancementUtils.GENERATED_NS_SUFFIX + "}MySQL-Database_w1-" + mySqlNodeTemplateId + "-Freeze_and_defrost" + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1"), topology.getNodeTemplate(mySqlNodeTemplateId).getType());
    assertNotNull(ModelUtilities.getPropertiesKV(topology.getNodeTemplate(ubuntuNodeTemplateId)));
    assertEquals(9, ModelUtilities.getPropertiesKV(topology.getNodeTemplate(ubuntuNodeTemplateId)).size());
    assertNotNull(ModelUtilities.getPropertiesKV(topology.getNodeTemplate(mySqlNodeTemplateId)));
    assertEquals(3, ModelUtilities.getPropertiesKV(topology.getNodeTemplate(mySqlNodeTemplateId)).size());
}
Also used : TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) Test(org.junit.jupiter.api.Test)

Example 15 with ServiceTemplateId

use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.

the class InstanceModelUtilsTest method executeErrorCommandTest.

@Test
void executeErrorCommandTest() throws Exception {
    this.setRevisionTo("origin/plain");
    TServiceTemplate serviceTemplate = this.repository.getElement(new ServiceTemplateId("http://opentosca.org/servicetemplates", "SshTest_w1-wip1", false));
    sshd.setCommandFactory((channel, command) -> new SupportErrorCommand(command) {

        @Override
        public String getReturnValue() {
            return "error";
        }
    });
    Session session = getSession(serviceTemplate);
    String pwd = InstanceModelUtils.executeCommand(session, "pwd");
    assertNotNull(pwd);
    assertTrue(pwd.isEmpty());
}
Also used : ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Session(com.jcraft.jsch.Session) 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