Search in sources :

Example 11 with TInterface

use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.

the class GenericArtifactsResource method generateImplementationArtifact.

/**
 * Generates the implementation artifact using the implementation artifact generator. Also sets the properties
 * according to the requirements of OpenTOSCA.
 */
private Response generateImplementationArtifact(String interfaceName, String javaPackage, UriInfo uriInfo, ArtifactTemplateId artifactTemplateId) {
    assert (this instanceof ImplementationArtifactsResource);
    IRepository repository = RepositoryFactory.getRepository();
    QName type = RestUtils.getType(this.res);
    EntityTypeId typeId = getTypeId(type).orElseThrow(IllegalStateException::new);
    TInterface i = findInterface(typeId, interfaceName).orElseThrow(IllegalStateException::new);
    Path workingDir;
    try {
        workingDir = Files.createTempDirectory("winery");
    } catch (IOException e2) {
        LOGGER.debug("Could not create temporary directory", e2);
        return Response.serverError().entity("Could not create temporary directory").build();
    }
    URI artifactTemplateFilesUri = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(artifactTemplateId)).resolve("files");
    URL artifactTemplateFilesUrl;
    try {
        artifactTemplateFilesUrl = artifactTemplateFilesUri.toURL();
    } catch (MalformedURLException e2) {
        LOGGER.debug("Could not convert URI to URL", e2);
        return Response.serverError().entity("Could not convert URI to URL").build();
    }
    String name = this.generateName(typeId, interfaceName);
    Generator gen = new Generator(i, javaPackage, artifactTemplateFilesUrl, name, workingDir.toFile());
    Path targetPath;
    try {
        targetPath = gen.generateProject();
    } catch (Exception e) {
        LOGGER.debug("IA generator failed", e);
        return Response.serverError().entity("IA generator failed").build();
    }
    DirectoryId fileDir = new ArtifactTemplateSourceDirectoryId(artifactTemplateId);
    try {
        BackendUtils.importDirectory(targetPath, repository, fileDir);
    } catch (IOException e) {
        throw new WebApplicationException(e);
    }
    // clean up
    FileUtils.forceDelete(workingDir);
    this.storeProperties(artifactTemplateId, typeId, name);
    URI url = uriInfo.getBaseUri().resolve(Util.getUrlPath(artifactTemplateId));
    return Response.created(url).build();
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) WebApplicationException(javax.ws.rs.WebApplicationException) TInterface(org.eclipse.winery.model.tosca.TInterface) QName(javax.xml.namespace.QName) IOException(java.io.IOException) URI(java.net.URI) URL(java.net.URL) WebApplicationException(javax.ws.rs.WebApplicationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) EntityTypeId(org.eclipse.winery.model.ids.definitions.EntityTypeId) ArtifactTemplateSourceDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateSourceDirectoryId) IRepository(org.eclipse.winery.repository.backend.IRepository) Generator(org.eclipse.winery.generators.ia.Generator)

Example 12 with TInterface

use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.

the class EdmmResource method buildInterfacesForNodeType.

private List<TInterface> buildInterfacesForNodeType(String interfaceName, String[] operations) {
    List<TOperation> tOperations = new ArrayList<>();
    for (String op : operations) {
        TOperation tOperation = new TOperation.Builder(op).build();
        tOperations.add(tOperation);
    }
    TInterface lifecycleInterface = new TInterface.Builder(interfaceName, tOperations).build();
    List<TInterface> interfaces = new ArrayList<>();
    interfaces.add(lifecycleInterface);
    return interfaces;
}
Also used : TOperation(org.eclipse.winery.model.tosca.TOperation) TInterface(org.eclipse.winery.model.tosca.TInterface) ArrayList(java.util.ArrayList)

Example 13 with TInterface

use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.

the class EdmmDependantTest method setup.

@BeforeEach
void setup() {
    // region *** NodeType setup ***
    QName nodeType1QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type");
    TNodeType nodeType1 = new TNodeType();
    nodeType1.setName(nodeType1QName.getLocalPart());
    nodeType1.setTargetNamespace(nodeType1QName.getNamespaceURI());
    nodeTypes.put(nodeType1QName, nodeType1);
    QName nodeType2QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type_2");
    TNodeType nodeType2 = new TNodeType();
    nodeType2.setName(nodeType2QName.getLocalPart());
    nodeType2.setTargetNamespace(nodeType2QName.getNamespaceURI());
    TEntityType.DerivedFrom derivedFrom = new TNodeType.DerivedFrom();
    derivedFrom.setTypeRef(nodeType1QName);
    nodeType2.setDerivedFrom(derivedFrom);
    nodeTypes.put(nodeType2QName, nodeType2);
    QName nodeType3QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type_3");
    TNodeType nodeType3 = new TNodeType();
    nodeType3.setName(nodeType3QName.getLocalPart());
    nodeType3.setTargetNamespace(nodeType3QName.getNamespaceURI());
    List<PropertyDefinitionKV> kvList = new ArrayList<>(Arrays.asList(new PropertyDefinitionKV("os_family", "xsd:string"), new PropertyDefinitionKV("public_key", "xsd:string"), new PropertyDefinitionKV("ssh_port", "number")));
    WinerysPropertiesDefinition wpd = new WinerysPropertiesDefinition();
    wpd.setPropertyDefinitions(kvList);
    ModelUtilities.replaceWinerysPropertiesDefinition(nodeType3, wpd);
    nodeType3.setProperties(wpd);
    nodeTypes.put(nodeType3QName, nodeType3);
    QName nodeType4QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type_4");
    TNodeType nodeType4 = new TNodeType();
    nodeType4.setName(nodeType4QName.getLocalPart());
    nodeType4.setTargetNamespace(nodeType4QName.getNamespaceURI());
    TOperation start = new TOperation();
    start.setName("start");
    TOperation stop = new TOperation();
    stop.setName("stop");
    TInterface lifecycle = new TInterface();
    lifecycle.setName("lifecycle_interface");
    lifecycle.getOperations().add(start);
    lifecycle.getOperations().add(stop);
    List<TInterface> tInterfaces = new ArrayList<>();
    tInterfaces.add(lifecycle);
    nodeType4.setInterfaces(tInterfaces);
    nodeTypes.put(nodeType4QName, nodeType4);
    // endregion
    // region *** ArtifactTemplates setup ***
    QName startIaQName = QName.valueOf("{" + NAMESPACE + "}" + "Start_IA");
    artifactTemplates.put(startIaQName, new TArtifactTemplate.Builder("Start_IA", startIaQName).addArtifactReference(new TArtifactReference.Builder("/artifacttemplates/" + NAMESPACE_DOUBLE_ENCODED + "/startTestNode4/files/script.sh").build()).build());
    QName stopIaQName = QName.valueOf("{" + NAMESPACE + "}" + "Stop_IA");
    TArtifactTemplate stopIa = new TArtifactTemplate.Builder("Stop_IA", stopIaQName).addArtifactReference(new TArtifactReference.Builder("/artifacttemplates/" + NAMESPACE_DOUBLE_ENCODED + "/startTestNode4/files/script.sh").build()).build();
    artifactTemplates.put(stopIaQName, stopIa);
    QName deploymentArtifactIAQName = QName.valueOf("{" + NAMESPACE + "}" + "TestNode1-DA");
    TArtifactTemplate deploymentArtifactTemplate = new TArtifactTemplate.Builder("TestNode1-DA", deploymentArtifactIAQName).addArtifactReference(new TArtifactReference.Builder("/artifacttemplates/" + NAMESPACE_DOUBLE_ENCODED + "/testNode1-DA/files/da.war").build()).build();
    artifactTemplates.put(deploymentArtifactIAQName, deploymentArtifactTemplate);
    // endregion
    // region *** NodeTypeImplementations setup ***
    QName nodeTypeImpl4QName = QName.valueOf("{" + NAMESPACE + "}" + "test_node_type_Impl_4");
    TImplementationArtifact startArtifact = new TImplementationArtifact.Builder(QName.valueOf("{ex.org}test")).setArtifactRef(startIaQName).setInterfaceName("lifecycle_interface").setOperationName("start").build();
    TImplementationArtifact stopArtifact = new TImplementationArtifact.Builder(QName.valueOf("{ex.org}test")).setArtifactRef(stopIaQName).setInterfaceName("lifecycle_interface").setOperationName("stop").build();
    nodeTypeImplementations.put(nodeTypeImpl4QName, new TNodeTypeImplementation.Builder(nodeTypeImpl4QName.getLocalPart(), nodeType4QName).addImplementationArtifact(startArtifact).addImplementationArtifact(stopArtifact).build());
    // endregion
    // region *** RelationType setup ***
    QName hostedOnQName = QName.valueOf("{" + NAMESPACE + "}" + "hostedOn");
    TRelationshipType hostedOnType = new TRelationshipType();
    hostedOnType.setName(hostedOnQName.getLocalPart());
    hostedOnType.setTargetNamespace(hostedOnQName.getNamespaceURI());
    relationshipTypes.put(hostedOnQName, hostedOnType);
    QName connectsToQName = QName.valueOf("{" + NAMESPACE + "}" + "connectsTo");
    TRelationshipType connectsToType = new TRelationshipType();
    connectsToType.setName(connectsToQName.getLocalPart());
    connectsToType.setTargetNamespace(connectsToQName.getNamespaceURI());
    relationshipTypes.put(connectsToQName, connectsToType);
    // endregion
    // region *** create NodeTemplates ***
    TDeploymentArtifact artifact = new TDeploymentArtifact.Builder("test_artifact", QName.valueOf("{" + NAMESPACE + "}" + "WAR")).setArtifactRef(deploymentArtifactIAQName).build();
    TNodeTemplate nt1 = new TNodeTemplate.Builder("test_node_1", nodeType1QName).setName("test_node_1").addDeploymentArtifact(artifact).build();
    nodeTemplates.put(nt1.getId(), nt1);
    TNodeTemplate nt2 = new TNodeTemplate();
    nt2.setType(nodeType2QName);
    nt2.setId("test_node_2");
    nt2.setName("test_node_2");
    nodeTemplates.put(nt2.getId(), nt2);
    TNodeTemplate nt3 = new TNodeTemplate();
    nt3.setType(nodeType3QName);
    nt3.setId("test_node_3");
    nt3.setName("test_node_3");
    TEntityTemplate.WineryKVProperties properties = new TEntityTemplate.WineryKVProperties();
    LinkedHashMap<String, String> nt3Properties = new LinkedHashMap<>();
    nt3Properties.put("os_family", "ubuntu");
    nt3Properties.put("public_key", "-----BEGIN PUBLIC KEY----- ... -----END PUBLIC KEY-----");
    nt3Properties.put("ssh_port", "22");
    properties.setKVProperties(nt3Properties);
    nt3.setProperties(properties);
    nodeTemplates.put(nt3.getId(), nt3);
    TNodeTemplate nt4 = new TNodeTemplate();
    nt4.setType(nodeType4QName);
    nt4.setId("test_node_4");
    nt4.setName("test_node_4");
    nodeTemplates.put(nt4.getId(), nt4);
    // endregion
    // region *** create RelationshipTemplate ***
    TRelationshipTemplate rt13 = new TRelationshipTemplate();
    rt13.setType(hostedOnQName);
    rt13.setId("1_hosted_on_3");
    rt13.setName("1_hosted_on_3");
    rt13.setSourceNodeTemplate(nt1);
    rt13.setTargetNodeTemplate(nt3);
    relationshipTemplates.put(rt13.getId(), rt13);
    TRelationshipTemplate rt23 = new TRelationshipTemplate();
    rt23.setType(hostedOnQName);
    rt23.setId("2_hosted_on_3");
    rt23.setName("2_hosted_on_3");
    rt23.setSourceNodeTemplate(nt2);
    rt23.setTargetNodeTemplate(nt3);
    relationshipTemplates.put(rt23.getId(), rt23);
    TRelationshipTemplate rt41 = new TRelationshipTemplate();
    rt41.setType(hostedOnQName);
    rt41.setId("4_hosted_on_1");
    rt41.setName("4_hosted_on_1");
    rt41.setSourceNodeTemplate(nt4);
    rt41.setTargetNodeTemplate(nt1);
    relationshipTemplates.put(rt41.getId(), rt41);
    TRelationshipTemplate rt12 = new TRelationshipTemplate();
    rt12.setType(connectsToQName);
    rt12.setId("1_connects_to_2");
    rt12.setName("1_connects_to_2");
    rt12.setSourceNodeTemplate(nt1);
    rt12.setTargetNodeTemplate(nt2);
    relationshipTemplates.put(rt12.getId(), rt12);
    // endregion
    // region *** create edmm type mapping ***
    edmm1to1Mapping.put(nodeType1QName, EdmmType.SOFTWARE_COMPONENT);
    // edmmTypeMapping.put(nodeType2QName, EdmmType.SOFTWARE_COMPONENT);
    edmmTypeExtendsMapping.put(nodeType3QName, EdmmType.COMPUTE);
    edmmTypeExtendsMapping.put(nodeType4QName, EdmmType.WEB_APPLICATION);
    edmm1to1Mapping.put(hostedOnQName, EdmmType.HOSTED_ON);
    edmm1to1Mapping.put(connectsToQName, EdmmType.CONNECTS_TO);
// endregion
}
Also used : PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) TInterface(org.eclipse.winery.model.tosca.TInterface) TEntityType(org.eclipse.winery.model.tosca.TEntityType) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TArtifactReference(org.eclipse.winery.model.tosca.TArtifactReference) ArrayList(java.util.ArrayList) WinerysPropertiesDefinition(org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition) LinkedHashMap(java.util.LinkedHashMap) TOperation(org.eclipse.winery.model.tosca.TOperation) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) QName(javax.xml.namespace.QName) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 14 with TInterface

use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.

the class InterfacesResource method onGet.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<?> onGet(@QueryParam("selectData") String selectData) {
    if (selectData == null) {
        return this.interfaces;
    }
    List<InterfacesSelectApiData> list = new ArrayList<>();
    for (TInterface item : this.interfaces) {
        List<String> ops = new ArrayList<>();
        for (TOperation op : item.getOperations()) {
            ops.add(op.getName());
        }
        list.add(new InterfacesSelectApiData(item.getName(), ops));
    }
    return list;
}
Also used : InterfacesSelectApiData(org.eclipse.winery.repository.rest.resources.apiData.InterfacesSelectApiData) TInterface(org.eclipse.winery.model.tosca.TInterface) TOperation(org.eclipse.winery.model.tosca.TOperation) ArrayList(java.util.ArrayList) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 15 with TInterface

use of org.eclipse.winery.model.tosca.TInterface in project winery by eclipse.

the class GeneratorTest method testMultipleOpsWithInOutParams.

@Test
public void testMultipleOpsWithInOutParams() throws Exception {
    TOperation install = new TOperation.Builder("install").addInputParameter(new TParameter.Builder("VMIP", "xs:string").build()).addInputParameter(new TParameter.Builder("DBMSUsername", "xs:string").build()).addOutputParameter(new TParameter.Builder("Output", "xs:string").build()).build();
    TOperation uninstall = new TOperation.Builder("uninstall").addInputParameter(new TParameter.Builder("SomeLongParameterName", "xs:string").build()).addInputParameter(new TParameter.Builder("Port", "xs:string").build()).addOutputParameter(new TParameter.Builder("Output", "xs:string").build()).build();
    TInterface iFace = new TInterface.Builder("http://www.example.org/interfaces/lifecycle", Arrays.asList(install, uninstall)).build();
    Generator gen = new Generator(iFace, "org.opentosca.ia.test", new URL("http://test.com"), "TestMultipleOpsWithInOutParams", wd.toFile());
    gen.generateProject();
}
Also used : TOperation(org.eclipse.winery.model.tosca.TOperation) TInterface(org.eclipse.winery.model.tosca.TInterface) TParameter(org.eclipse.winery.model.tosca.TParameter) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Aggregations

TInterface (org.eclipse.winery.model.tosca.TInterface)15 TNodeType (org.eclipse.winery.model.tosca.TNodeType)10 TOperation (org.eclipse.winery.model.tosca.TOperation)10 URL (java.net.URL)6 ArrayList (java.util.ArrayList)6 QName (javax.xml.namespace.QName)5 TParameter (org.eclipse.winery.model.tosca.TParameter)5 IRepository (org.eclipse.winery.repository.backend.IRepository)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 TRelationshipType (org.eclipse.winery.model.tosca.TRelationshipType)4 LinkedHashMap (java.util.LinkedHashMap)3 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)3 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)3 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)3 PropertyDefinitionKV (org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV)3 WinerysPropertiesDefinition (org.eclipse.winery.model.tosca.extensions.kvproperties.WinerysPropertiesDefinition)3 Test (org.junit.Test)3 Map (java.util.Map)2 Produces (javax.ws.rs.Produces)2