Search in sources :

Example 21 with TTopologyTemplate

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

the class WineryRepositoryClient method getTopologyTemplate.

@Override
public TTopologyTemplate getTopologyTemplate(QName serviceTemplate, String parentPath, String elementPath) {
    // we try all repositories until the first hit
    for (WebResource wr : this.repositoryResources) {
        WebResource r = WineryRepositoryClient.getTopologyTemplateWebResource(wr, serviceTemplate, parentPath, elementPath);
        ClientResponse response = r.accept(MediaType.TEXT_XML).get(ClientResponse.class);
        if (response.getClientResponseStatus() == ClientResponse.Status.OK) {
            TTopologyTemplate topologyTemplate;
            Document doc = this.parseAndValidateTOSCAXML(response.getEntityInputStream());
            if (doc == null) {
                // no valid document
                return null;
            }
            try {
                topologyTemplate = WineryRepositoryClient.createUnmarshaller().unmarshal(doc.getDocumentElement(), TTopologyTemplate.class).getValue();
            } catch (JAXBException e) {
                LOGGER.debug("Could not parse topology, returning null", e);
                return null;
            }
            // first hit: immediately stop and return result
            return topologyTemplate;
        }
    }
    // nothing found
    return null;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) JAXBException(javax.xml.bind.JAXBException) WebResource(com.sun.jersey.api.client.WebResource) Document(org.w3c.dom.Document)

Aggregations

TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)21 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)10 Test (org.junit.Test)8 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)7 ArrayList (java.util.ArrayList)6 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)6 ServiceTemplateId (org.eclipse.winery.common.ids.definitions.ServiceTemplateId)5 TDeploymentArtifact (org.eclipse.winery.model.tosca.TDeploymentArtifact)4 IOException (java.io.IOException)3 List (java.util.List)3 QName (javax.xml.namespace.QName)3 TRequirement (org.eclipse.winery.model.tosca.TRequirement)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 URI (java.net.URI)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 JAXBException (javax.xml.bind.JAXBException)2 TDocumentation (org.eclipse.winery.model.tosca.TDocumentation)2 Splitting (org.eclipse.winery.repository.splitting.Splitting)2