Search in sources :

Example 31 with TDeploymentArtifact

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

the class SelfContainmentPackager method createSelfContainedNodeTypeImplementation.

private void createSelfContainedNodeTypeImplementation(TNodeTypeImplementation impl) {
    if (impl.getImplementationArtifacts() != null) {
        List<SelfContainmentPlugin.GeneratedArtifacts> generatedArtifacts = impl.getImplementationArtifacts().stream().filter(ia -> Objects.nonNull(ia.getArtifactRef())).filter(ia -> !new ArtifactTemplateId(ia.getArtifactRef()).isSelfContained()).map(ia -> this.downloadArtifacts(ia.getArtifactRef(), ia.getArtifactType())).filter(Objects::nonNull).filter(SelfContainmentPlugin.GeneratedArtifacts::containsNewElements).collect(Collectors.toList());
        if (!generatedArtifacts.isEmpty()) {
            NodeTypeImplementationId nodeTypeImplementationId = getSelfContainedNodeTypeImplId(impl);
            try {
                this.repository.duplicate(new NodeTypeImplementationId(impl.getQName()), nodeTypeImplementationId);
                TNodeTypeImplementation implementation = this.repository.getElement(nodeTypeImplementationId);
                generatedArtifacts.forEach(generatedArtifact -> {
                    if (implementation.getImplementationArtifacts() != null) {
                        implementation.getImplementationArtifacts().forEach(ia -> {
                            if (generatedArtifact.artifactToReplaceQName.equals(ia.getArtifactRef())) {
                                ia.setArtifactRef(generatedArtifact.selfContainedArtifactQName);
                                TArtifactTemplate artifactTemplate = generatedArtifact.selfContainedArtifactTemplate;
                                if (artifactTemplate == null) {
                                    artifactTemplate = repository.getElement(new ArtifactTemplateId(generatedArtifact.selfContainedArtifactQName));
                                }
                                if (artifactTemplate.getType() == null) {
                                    logger.error("Artifact Template does not have a type assigned! {}", generatedArtifact.selfContainedArtifactQName);
                                }
                                ia.setArtifactType(artifactTemplate.getType());
                            }
                        });
                        List<TDeploymentArtifact> deploymentArtifacts = implementation.getDeploymentArtifacts();
                        if (deploymentArtifacts == null) {
                            deploymentArtifacts = new ArrayList<>();
                            implementation.setDeploymentArtifacts(deploymentArtifacts);
                        } else {
                            deploymentArtifacts.removeIf(da -> da.getArtifactRef() != null && generatedArtifact.deploymentArtifactsToRemove.contains(da.getArtifactRef()));
                        }
                        for (QName artifactTemplate : generatedArtifact.deploymentArtifactsToAdd) {
                            TArtifactTemplate generatedAT = repository.getElement(new ArtifactTemplateId(artifactTemplate));
                            deploymentArtifacts.add(new TDeploymentArtifact.Builder(artifactTemplate.getLocalPart(), generatedAT.getType()).setArtifactRef(artifactTemplate).build());
                        }
                    }
                });
                repository.setElement(nodeTypeImplementationId, implementation);
            } catch (IOException e) {
                logger.error("Error while creating new self-contained NodeTypeImplementation of {}", impl, e);
            }
        }
    } else {
        logger.info("No processable IAs found in Node Type Implementation {}", impl.getQName());
    }
}
Also used : TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Collection(java.util.Collection) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Objects(java.util.Objects) List(java.util.List) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) VersionSupport(org.eclipse.winery.model.version.VersionSupport) IRepository(org.eclipse.winery.repository.backend.IRepository) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) QName(javax.xml.namespace.QName) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) QName(javax.xml.namespace.QName) IOException(java.io.IOException) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Objects(java.util.Objects) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact)

Example 32 with TDeploymentArtifact

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

the class UbuntuVMPlugin method downloadDependenciesBasedOnNodeType.

@Override
public void downloadDependenciesBasedOnNodeType(TNodeTypeImplementation nodeTypeImplementation, IRepository repository) {
    QName nodeType = nodeTypeImplementation.getNodeType();
    WineryVersion nodeTypeVersion = VersionUtils.getVersion(nodeType.getLocalPart());
    String componentVersion = nodeTypeVersion.getComponentVersion();
    if (componentVersion != null) {
        String codeName = getCodeName(componentVersion);
        if (codeName != null) {
            logger.info("Found code name '{}' for Ubuntu Node Type {}", codeName, nodeType);
            String nameWithoutVersion = VersionUtils.getNameWithoutVersion(nodeType.getLocalPart());
            WineryVersion artifactVersion = new WineryVersion(nodeTypeVersion.getComponentVersion() + "-CloudImage", 1, 1);
            ArtifactTemplateId artifactTemplateId = new ArtifactTemplateId(OpenToscaBaseTypes.artifactTemplateNamespace, nameWithoutVersion + "-DA" + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + artifactVersion, false);
            TArtifactTemplate element = repository.getElement(artifactTemplateId);
            element.setType(OpenToscaBaseTypes.cloudImageArtifactType);
            logger.info("Generated ArtifactTemplate {}", artifactTemplateId.getQName());
            if (!repository.exists(artifactTemplateId)) {
                logger.info("Trying to download image file...");
                String baseUrl = "https://cloud-images.ubuntu.com/" + codeName + "/current/" + codeName + "-server-cloudimg-amd64";
                try {
                    URL url = new URL(baseUrl + imageFileType);
                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                    connection.setRequestMethod("HEAD");
                    int responseCode = connection.getResponseCode();
                    if (responseCode != 200) {
                        connection.disconnect();
                        logger.info("Image not found, trying with '-disk' suffix...");
                        url = new URL(baseUrl + imageDiskType);
                        connection = (HttpURLConnection) url.openConnection();
                        connection.setRequestMethod("HEAD");
                        responseCode = connection.getResponseCode();
                    }
                    if (responseCode == 200) {
                        repository.setElement(artifactTemplateId, element);
                        ArtifactTemplateFilesDirectoryId filesId = new ArtifactTemplateFilesDirectoryId(artifactTemplateId);
                        String fileName = url.getFile().substring(url.getFile().lastIndexOf("/") + 1);
                        RepositoryFileReference repositoryFileReference = new RepositoryFileReference(filesId, fileName);
                        try (InputStream inputStream = url.openStream()) {
                            repository.putContentToFile(repositoryFileReference, inputStream, MediaType.parse("application/x-image"));
                        }
                        BackendUtils.synchronizeReferences(repository, artifactTemplateId);
                        TDeploymentArtifact imageDa = new TDeploymentArtifact.Builder("CloudImage", OpenToscaBaseTypes.cloudImageArtifactType).setArtifactRef(artifactTemplateId.getQName()).build();
                        List<TDeploymentArtifact> deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
                        if (deploymentArtifacts == null) {
                            deploymentArtifacts = new ArrayList<>();
                            nodeTypeImplementation.setDeploymentArtifacts(deploymentArtifacts);
                        }
                        deploymentArtifacts.add(imageDa);
                    } else {
                        logger.info("Could not download image -- the URLs do not exist: \n\t{}\n\t{}", baseUrl + imageFileType, baseUrl + imageDiskType);
                    }
                } catch (IOException e) {
                    logger.info("Error while downloading image file!", e);
                }
            }
        } else {
            logger.info("Could not identify code name of given Ubuntu Node Type! {}", nodeType);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) InputStream(java.io.InputStream) IOException(java.io.IOException) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) URL(java.net.URL) ArtifactTemplateFilesDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.ArtifactTemplateFilesDirectoryId) HttpURLConnection(java.net.HttpURLConnection) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) WineryVersion(org.eclipse.winery.common.version.WineryVersion)

Example 33 with TDeploymentArtifact

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

the class DASpecification method getSuitableConcreteDA.

public static TDeploymentArtifact getSuitableConcreteDA(TDeploymentArtifact abstractDeploymentArtifact, TNodeTemplate nodeTemplate) {
    TDeploymentArtifact concreteDA = null;
    if (nodeTemplate.getDeploymentArtifacts() != null) {
        List<TDeploymentArtifact> concreteDeploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
        concreteDA = getConcreteDA(abstractDeploymentArtifact, concreteDeploymentArtifacts);
    }
    if (concreteDA == null) {
        List<TNodeTypeImplementation> nodeTypeImplementations = getMatchingNodeTypeImplementations(nodeTemplate.getType());
        for (TNodeTypeImplementation nodeTypeImplementation : nodeTypeImplementations) {
            if (nodeTypeImplementation.getDeploymentArtifacts() != null) {
                List<TDeploymentArtifact> deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
                concreteDA = getConcreteDA(abstractDeploymentArtifact, deploymentArtifacts);
                if (concreteDA != null) {
                    return concreteDA;
                }
            }
        }
    } else {
        return concreteDA;
    }
    return null;
}
Also used : TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation)

Example 34 with TDeploymentArtifact

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

the class GenericArtifactsResource method generateArtifact.

/**
 * @return TImplementationArtifact | TDeploymentArtifact (XML) | URL of generated IA zip (in case of autoGenerateIA)
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates a new implementation/deployment artifact. If an implementation artifact with the same name already exists, it is <em>overridden</em>.")
@SuppressWarnings("unchecked")
public Response generateArtifact(GenerateArtifactApiData apiData, @Context UriInfo uriInfo) {
    // we assume that the parent ComponentInstance container exists
    final IRepository repository = RepositoryFactory.getRepository();
    if (StringUtils.isEmpty(apiData.artifactName)) {
        return Response.status(Status.BAD_REQUEST).entity("Empty artifactName").build();
    }
    if (StringUtils.isEmpty(apiData.artifactType)) {
        if (StringUtils.isEmpty(apiData.artifactTemplateName) || StringUtils.isEmpty(apiData.artifactTemplateNamespace)) {
            if (StringUtils.isEmpty(apiData.artifactTemplate)) {
                return Response.status(Status.BAD_REQUEST).entity("No artifact type given and no template given. Cannot guess artifact type").build();
            }
        }
    }
    if (!StringUtils.isEmpty(apiData.autoGenerateIA)) {
        if (StringUtils.isEmpty(apiData.javaPackage)) {
            return Response.status(Status.BAD_REQUEST).entity("no java package name supplied for IA auto generation.").build();
        }
        if (StringUtils.isEmpty(apiData.interfaceName)) {
            return Response.status(Status.BAD_REQUEST).entity("no interface name supplied for IA auto generation.").build();
        }
    }
    // convert second calling form to first calling form
    if (!StringUtils.isEmpty(apiData.artifactTemplate)) {
        QName qname = QName.valueOf(apiData.artifactTemplate);
        apiData.artifactTemplateName = qname.getLocalPart();
        apiData.artifactTemplateNamespace = qname.getNamespaceURI();
    }
    Document doc = null;
    // if invalid, abort and do not create anything
    if (!StringUtils.isEmpty(apiData.artifactSpecificContent)) {
        try {
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            InputSource is = new InputSource();
            StringReader sr = new StringReader(apiData.artifactSpecificContent);
            is.setCharacterStream(sr);
            doc = db.parse(is);
        } catch (Exception e) {
            // FIXME: currently we allow a single element only. However, the content should be internally wrapped by an (arbitrary) XML element as the content will be nested in the artifact element, too
            LOGGER.debug("Invalid content", e);
            return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
        }
    }
    // determine artifactTemplate and artifactType
    ArtifactTypeId artifactTypeId;
    ArtifactTemplateId artifactTemplateId = null;
    boolean doAutoCreateArtifactTemplate = !(StringUtils.isEmpty(apiData.autoCreateArtifactTemplate) || apiData.autoCreateArtifactTemplate.equalsIgnoreCase("no") || apiData.autoCreateArtifactTemplate.equalsIgnoreCase("false"));
    if (!doAutoCreateArtifactTemplate) {
        // no auto creation
        if (!StringUtils.isEmpty(apiData.artifactTemplateName) && !StringUtils.isEmpty(apiData.artifactTemplateNamespace)) {
            QName artifactTemplateQName = new QName(apiData.artifactTemplateNamespace, apiData.artifactTemplateName);
            artifactTemplateId = BackendUtils.getDefinitionsChildId(ArtifactTemplateId.class, artifactTemplateQName);
        }
        if (StringUtils.isEmpty(apiData.artifactType)) {
            // derive the type from the artifact template
            if (artifactTemplateId == null) {
                return Response.status(Status.NOT_ACCEPTABLE).entity("No artifactTemplate and no artifactType provided. Deriving the artifactType is not possible.").build();
            }
            @NonNull final QName type = repository.getElement(artifactTemplateId).getType();
            artifactTypeId = BackendUtils.getDefinitionsChildId(ArtifactTypeId.class, type);
        } else {
            // artifactTypeStr is directly given, use that
            artifactTypeId = BackendUtils.getDefinitionsChildId(ArtifactTypeId.class, apiData.artifactType);
        }
    } else {
        if (StringUtils.isEmpty(apiData.artifactType)) {
            return Response.status(Status.BAD_REQUEST).entity("Artifact template auto creation requested, but no artifact type supplied.").build();
        }
        artifactTypeId = BackendUtils.getDefinitionsChildId(ArtifactTypeId.class, apiData.artifactType);
        // ensure that given type exists
        if (!repository.exists(artifactTypeId)) {
            LOGGER.debug("Artifact type {} is created", apiData.artifactType);
            final TArtifactType element = repository.getElement(artifactTypeId);
            try {
                repository.setElement(artifactTypeId, element);
            } catch (IOException e) {
                throw new WebApplicationException(e);
            }
        }
        if (StringUtils.isEmpty(apiData.artifactTemplateName) || StringUtils.isEmpty(apiData.artifactTemplateNamespace)) {
            // no explicit name provided
            // we use the artifactNameStr as prefix for the
            // artifact template name
            // we create a new artifact template in the namespace of the parent
            // element
            Namespace namespace = this.resWithNamespace.getNamespace();
            artifactTemplateId = new ArtifactTemplateId(namespace, new XmlId(apiData.artifactName + "artifactTemplate", false));
        } else {
            QName artifactTemplateQName = new QName(apiData.artifactTemplateNamespace, apiData.artifactTemplateName);
            artifactTemplateId = new ArtifactTemplateId(artifactTemplateQName);
        }
        // even if artifactTemplate does not exist, it is loaded
        final TArtifactTemplate artifactTemplate = repository.getElement(artifactTemplateId);
        artifactTemplate.setType(artifactTypeId.getQName());
        try {
            repository.setElement(artifactTemplateId, artifactTemplate);
        } catch (IOException e) {
            throw new WebApplicationException(e);
        }
    }
    // variable artifactTypeId is set
    // variable artifactTemplateId is not null if artifactTemplate has been generated
    // we have to generate the DA/IA resource now
    // Doing it here instead of doing it at the subclasses is dirty on the
    // one hand, but quicker to implement on the other hand
    // Create the artifact itself
    ArtifactT resultingArtifact;
    if (this instanceof ImplementationArtifactsResource) {
        TImplementationArtifact.Builder builder = new TImplementationArtifact.Builder(artifactTypeId.getQName()).setName(apiData.artifactName).setInterfaceName(apiData.interfaceName).setOperationName(apiData.operationName);
        if (artifactTemplateId != null) {
            builder.setArtifactRef(artifactTemplateId.getQName());
        }
        if (doc != null) {
            // the content has been checked for validity at the beginning of the method.
            // If this point in the code is reached, the XML has been parsed into doc
            // just copy over the dom node. Hopefully, that works...
            builder.setAny(Collections.singletonList(doc.getDocumentElement()));
        }
        resultingArtifact = (ArtifactT) builder.build();
    } else {
        // for comments see other branch
        TDeploymentArtifact.Builder builder = new TDeploymentArtifact.Builder(apiData.artifactName, artifactTypeId.getQName());
        if (artifactTemplateId != null) {
            builder.setArtifactRef(artifactTemplateId.getQName());
        }
        if (doc != null) {
            builder.setAny(Collections.singletonList(doc.getDocumentElement()));
        }
        resultingArtifact = (ArtifactT) builder.build();
    }
    this.list.add(resultingArtifact);
    // TODO: Check for error, and in case one found return it
    RestUtils.persist(super.res);
    if (StringUtils.isEmpty(apiData.autoGenerateIA)) {
        // No IA generation
        return Response.created(URI.create(EncodingUtil.URLencode(apiData.artifactName))).entity(resultingArtifact).build();
    } else {
        // after everything was created, we fire up the artifact generation
        return this.generateImplementationArtifact(apiData.interfaceName, apiData.javaPackage, uriInfo, artifactTemplateId);
    }
}
Also used : InputSource(org.xml.sax.InputSource) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) WebApplicationException(javax.ws.rs.WebApplicationException) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) QName(javax.xml.namespace.QName) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) DocumentBuilder(javax.xml.parsers.DocumentBuilder) IOException(java.io.IOException) Document(org.w3c.dom.Document) WebApplicationException(javax.ws.rs.WebApplicationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) Namespace(org.eclipse.winery.model.ids.Namespace) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NonNull(org.eclipse.jdt.annotation.NonNull) StringReader(java.io.StringReader) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) XmlId(org.eclipse.winery.model.ids.XmlId) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) IRepository(org.eclipse.winery.repository.backend.IRepository) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation)

Example 35 with TDeploymentArtifact

use of org.eclipse.winery.model.tosca.TDeploymentArtifact 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)

Aggregations

TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)48 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 QName (javax.xml.namespace.QName)23 ArrayList (java.util.ArrayList)14 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)13 TNodeTypeImplementation (org.eclipse.winery.model.tosca.TNodeTypeImplementation)12 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)12 HashSet (java.util.HashSet)11 List (java.util.List)9 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)9 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)9 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)9 IOException (java.io.IOException)8 ArtifactTypeId (org.eclipse.winery.model.ids.definitions.ArtifactTypeId)8 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)7 Test (org.junit.jupiter.api.Test)7 TArtifactType (org.eclipse.winery.model.tosca.TArtifactType)6 TImplementationArtifact (org.eclipse.winery.model.tosca.TImplementationArtifact)6 Node (org.w3c.dom.Node)6 Map (java.util.Map)5