Search in sources :

Example 26 with NodeTypeId

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

the class RestUtilsWithGitBackendTest method renameAllVersionNamesOfOneComponent.

@Test
public void renameAllVersionNamesOfOneComponent() throws Exception {
    this.setRevisionTo("origin/plain");
    String version = "_0.3.4-w3";
    String oldName = "NodeTypeWith5Versions";
    String newName = "exampleName";
    String namespace = "http://opentosca.org/nodetypes";
    DefinitionsChildId oldId = new NodeTypeId(namespace, oldName + version, false);
    DefinitionsChildId newId = new NodeTypeId(namespace, newName + version, false);
    Response response = RestUtils.renameAllVersionsOfOneDefinition(oldId, newId);
    String expectedEntity = "http://localhost:8080/winery/nodetypes/" + EncodingUtil.URLencode(EncodingUtil.URLencode(namespace)) + "/" + newName + version + "/";
    assertEquals(201, response.getStatus());
    assertEquals(expectedEntity, response.getEntity());
    assertEquals(5, WineryVersionUtils.getAllVersionsOfOneDefinition(oldId, repository).size());
    assertEquals(5, WineryVersionUtils.getAllVersionsOfOneDefinition(newId, repository).size());
}
Also used : Response(javax.ws.rs.core.Response) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) Test(org.junit.jupiter.api.Test)

Example 27 with NodeTypeId

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

the class RestUtilsWithGitBackendTest method getFlagsOfAReleasableVersion.

@Test
public void getFlagsOfAReleasableVersion() throws Exception {
    this.setRevisionTo("d920a1a37e3e1c3be32bf282a4d240d83811fdb1");
    DefinitionsChildId id = new NodeTypeId("http://plain.winery.opentosca.org/nodetypes", "NodeTypeWithImplementation_1.0-w1-wip1", false);
    WineryVersion version = WineryVersionUtils.getCurrentVersionWithAllFlags(id, repository);
    assertTrue(version.isReleasable());
    assertTrue(version.isCurrentVersion());
    assertTrue(version.isLatestVersion());
    assertFalse(version.isEditable());
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Test(org.junit.jupiter.api.Test)

Example 28 with NodeTypeId

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

the class Splitting method getInputParamListofIncomingRelationshipTemplates.

public List<TParameter> getInputParamListofIncomingRelationshipTemplates(TTopologyTemplate topologyTemplate, List<TRelationshipTemplate> listOfIncomingRelationshipTemplates) {
    List<TParameter> listOfInputs = new ArrayList<>();
    IRepository repo = RepositoryFactory.getRepository();
    for (TRelationshipTemplate incomingRelationshipTemplate : listOfIncomingRelationshipTemplates) {
        TNodeTemplate incomingNodetemplate = ModelUtilities.getSourceNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
        NodeTypeId incomingNodeTypeId = new NodeTypeId(incomingNodetemplate.getType());
        TNodeType incomingNodeType = repo.getElement(incomingNodeTypeId);
        List<TInterface> incomingNodeTypeInterfaces = incomingNodeType.getInterfaces();
        RelationshipTypeId incomingRelationshipTypeId = new RelationshipTypeId(incomingRelationshipTemplate.getType());
        if (!incomingNodeTypeInterfaces.isEmpty()) {
            TInterface relevantInterface = null;
            List<TInterface> connectionInterfaces = incomingNodeTypeInterfaces.stream().filter(tInterface -> tInterface.getIdFromIdOrNameField().contains("connection")).collect(Collectors.toList());
            if (connectionInterfaces.size() > 1) {
                TNodeTemplate targetNodeTemplate = ModelUtilities.getTargetNodeTemplateOfRelationshipTemplate(topologyTemplate, incomingRelationshipTemplate);
                for (TInterface tInterface : connectionInterfaces) {
                    int separator = tInterface.getIdFromIdOrNameField().lastIndexOf("/");
                    String prefixRelation = tInterface.getIdFromIdOrNameField().substring(separator + 1);
                    if (targetNodeTemplate.getName() != null && targetNodeTemplate.getName().toLowerCase().contains(prefixRelation.toLowerCase())) {
                        relevantInterface = tInterface;
                    }
                }
            } else {
                relevantInterface = connectionInterfaces.get(0);
            }
            if (relevantInterface != null) {
                for (TOperation tOperation : relevantInterface.getOperations()) {
                    List<TParameter> inputParameters = tOperation.getInputParameters();
                    if (inputParameters != null) {
                        listOfInputs.addAll(inputParameters);
                    }
                }
            }
        }
    }
    return listOfInputs;
}
Also used : SortedSet(java.util.SortedSet) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) TParameter(org.eclipse.winery.model.tosca.TParameter) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) VersionSupport(org.eclipse.winery.model.version.VersionSupport) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Map(java.util.Map) TRequirement(org.eclipse.winery.model.tosca.TRequirement) Util(org.eclipse.winery.repository.common.Util) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ListUtils.listIsNotNullOrEmpty(org.eclipse.winery.common.ListUtils.listIsNotNullOrEmpty) Set(java.util.Set) IOException(java.io.IOException) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) TInterface(org.eclipse.winery.model.tosca.TInterface) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) Objects(java.util.Objects) List(java.util.List) DASpecification(org.eclipse.winery.repository.driverspecificationandinjection.DASpecification) TCapability(org.eclipse.winery.model.tosca.TCapability) IRepository(org.eclipse.winery.repository.backend.IRepository) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) Optional(java.util.Optional) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TOperation(org.eclipse.winery.model.tosca.TOperation) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) DriverInjection(org.eclipse.winery.repository.driverspecificationandinjection.DriverInjection) QName(javax.xml.namespace.QName) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) TInterface(org.eclipse.winery.model.tosca.TInterface) ArrayList(java.util.ArrayList) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TOperation(org.eclipse.winery.model.tosca.TOperation) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TParameter(org.eclipse.winery.model.tosca.TParameter) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate)

Example 29 with NodeTypeId

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

the class CsarImporter method processDefinitionsImport.

protected Optional<ServiceTemplateId> processDefinitionsImport(TDefinitions defs, TOSCAMetaFile tmf, Path definitionsPath, List<String> errors, CsarImportOptions options) throws IOException {
    List<TImport> imports = defs.getImport();
    this.importImports(definitionsPath.getParent(), tmf, imports, errors, options);
    // imports has been modified to contain necessary imports only
    // this method adds new imports to defs which may not be imported using "importImports".
    // Therefore, "importTypes" has to be called *after* importImports
    this.importTypes(defs, errors);
    Optional<ServiceTemplateId> entryServiceTemplate = Optional.empty();
    String defaultNamespace = defs.getTargetNamespace();
    List<TExtensibleElements> componentInstanceList = defs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation();
    for (final TExtensibleElements ci : componentInstanceList) {
        // Determine namespace
        String namespace = this.getNamespace(ci, defaultNamespace);
        // Ensure that element has the namespace
        this.setNamespace(ci, namespace);
        // Determine id
        String id = ModelUtilities.getId(ci);
        final DefinitionsChildId wid = determineWineryId(ci, namespace, id);
        if (targetRepository.exists(wid)) {
            if (options.isOverwrite()) {
                targetRepository.forceDelete(wid);
                String msg = String.format("Deleted %1$s %2$s to enable replacement", ci.getClass().getName(), wid.getQName().toString());
                CsarImporter.LOGGER.debug(msg);
            } else {
                String msg = String.format("Skipped %1$s %2$s, because it already exists", ci.getClass().getName(), wid.getQName().toString());
                CsarImporter.LOGGER.debug(msg);
                // this is not displayed in the UI as we currently do not distinguish between pre-existing types and types created during the import.
                continue;
            }
        }
        // Create a fresh definitions object without the other data.
        final TDefinitions newDefs = BackendUtils.createWrapperDefinitions(wid, targetRepository);
        // copy over the inputs determined by this.importImports
        newDefs.getImport().addAll(imports);
        // add the current TExtensibleElements as the only content to it
        newDefs.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().add(ci);
        if (ci instanceof TArtifactTemplate) {
            // convention: Definitions are stored in the "Definitions" directory, therefore going to levels up (Definitions dir -> root dir) resolves to the root dir
            // COS01, line 2663 states that the path has to be resolved from the *root* of the CSAR
            this.adjustArtifactTemplate(definitionsPath.getParent().getParent(), tmf, (ArtifactTemplateId) wid, (TArtifactTemplate) ci, errors);
        } else if (ci instanceof TNodeType) {
            this.adjustNodeType(definitionsPath.getParent().getParent(), (TNodeType) ci, (NodeTypeId) wid, tmf, errors);
        } else if (ci instanceof TRelationshipType) {
            this.adjustRelationshipType(definitionsPath.getParent().getParent(), (TRelationshipType) ci, (RelationshipTypeId) wid, tmf, errors);
        } else if (ci instanceof TServiceTemplate) {
            this.adjustServiceTemplate(definitionsPath.getParent().getParent(), tmf, (ServiceTemplateId) wid, (TServiceTemplate) ci, errors);
            entryServiceTemplate = Optional.of((ServiceTemplateId) wid);
        }
        // import license and readme files
        importLicenseAndReadme(definitionsPath.getParent().getParent(), wid, tmf, errors);
        // Therefore, we check the entity type separately here
        if (ci instanceof TEntityType) {
            if (options.isAsyncWPDParsing()) {
                // Adjusting takes a long time
                // Therefore, we first save the type as is and convert to Winery-Property-Definitions in the background
                CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
                CsarImporter.entityTypeAdjustmentService.submit(() -> {
                    adjustEntityType((TEntityType) ci, (EntityTypeId) wid, newDefs, errors);
                    CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
                });
            } else {
                adjustEntityType((TEntityType) ci, (EntityTypeId) wid, newDefs, errors);
                CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
            }
        } else {
            CsarImporter.storeDefinitions(targetRepository, wid, newDefs);
        }
    }
    return entryServiceTemplate;
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) TEntityType(org.eclipse.winery.model.tosca.TEntityType) TImport(org.eclipse.winery.model.tosca.TImport) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TNodeType(org.eclipse.winery.model.tosca.TNodeType) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 30 with NodeTypeId

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

the class WeaveGoHandler method handleNode.

@Override
public Set<String> handleNode(TNodeTemplate dockerContainer, TTopologyTemplate topologyTemplate, String imageId) {
    Set<String> discoveredNodeIds = new HashSet<>();
    IRepository repository = RepositoryFactory.getRepository();
    dockerContainer.setType(QNAME_ALPINE_CONTAINER);
    TNodeType goAppType = repository.getElement(new NodeTypeId(QNAME_GO_APP));
    TNodeTemplate goApp = ModelUtilities.instantiateNodeTemplate(goAppType);
    goApp.setName(dockerContainer.getName());
    topologyTemplate.addNodeTemplate(goApp);
    ModelUtilities.createRelationshipTemplateAndAddToTopology(goApp, dockerContainer, ToscaBaseTypes.hostedOnRelationshipType, topologyTemplate);
    discoveredNodeIds.add(dockerContainer.getId());
    discoveredNodeIds.add(goApp.getId());
    return discoveredNodeIds;
}
Also used : NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) HashSet(java.util.HashSet) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Aggregations

NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)67 TNodeType (org.eclipse.winery.model.tosca.TNodeType)36 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 Test (org.junit.jupiter.api.Test)27 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)23 QName (javax.xml.namespace.QName)21 IRepository (org.eclipse.winery.repository.backend.IRepository)20 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)15 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)15 WineryVersion (org.eclipse.winery.common.version.WineryVersion)14 Response (javax.ws.rs.core.Response)13 IOException (java.io.IOException)12 LinkedHashMap (java.util.LinkedHashMap)12 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)11 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)11 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)10 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)10 ArrayList (java.util.ArrayList)9 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)9 TEntityTemplate (org.eclipse.winery.model.tosca.TEntityTemplate)9