Search in sources :

Example 36 with IRepository

use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.

the class TenantRepository method initTenantRepository.

public IRepository initTenantRepository(String tenantName) throws GitAPIException, IOException {
    FileBasedRepositoryConfiguration fileBasedConfig = new FileBasedRepositoryConfiguration(repositoryRoot.resolve(tenantName));
    IRepository tenantRepo = this.createRepo(new GitBasedRepositoryConfiguration(false, fileBasedConfig));
    repositories.put(tenantName, tenantRepo);
    return tenantRepo;
}
Also used : GitBasedRepositoryConfiguration(org.eclipse.winery.common.configuration.GitBasedRepositoryConfiguration) FileBasedRepositoryConfiguration(org.eclipse.winery.common.configuration.FileBasedRepositoryConfiguration) IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 37 with IRepository

use of org.eclipse.winery.repository.backend.IRepository 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)

Example 38 with IRepository

use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.

the class PlacementUtils method completeModel.

/**
 * Completes the model based on the defined provider assignments and returns a completed ServiceTemplate if the
 * completion was successful. Otherwise, the ServiceTemplate with cleaned location and provider assignments is
 * returned. Additionally, the providers that led to the error are added to the black lists of the components.
 *
 * @param serviceTemplateId the ID of the ServiceTemplate to complete
 * @param topology          the incomplete TopologyTemplate to complete
 * @param blackList         the black list containing the NodeTemplates with the providers that are not usable for
 *                          them
 * @return the completed TopologyTemplate if completion is successful, the cleared and blacklisted TopologyTemplate
 * otherwise
 */
private static TTopologyTemplate completeModel(ServiceTemplateId serviceTemplateId, TTopologyTemplate topology, Map<String, List<String>> blackList) {
    Splitting splitting = new Splitting();
    IRepository repo = RepositoryFactory.getRepository();
    try {
        // create new temporary ServiceTemplate as working copy
        ServiceTemplateId placementId = new ServiceTemplateId(serviceTemplateId.getNamespace().getDecoded(), VersionSupport.getNewComponentVersionId(serviceTemplateId, "placement"), false);
        repo.forceDelete(placementId);
        TServiceTemplate placementServiceTemplate = new TServiceTemplate();
        placementServiceTemplate.setTargetNamespace(serviceTemplateId.getNamespace().getDecoded());
        placementServiceTemplate.setTopologyTemplate(topology);
        placementServiceTemplate.setName(placementId.getXmlId().getDecoded());
        placementServiceTemplate.setId(placementServiceTemplate.getName());
        // resolve open requirements until the topology is completed
        while (topology != null && !splitting.getOpenRequirements(topology).isEmpty()) {
            // add a target label to the topology based on the provider and location assignment
            assignNodesToTargetLabels(topology);
            placementServiceTemplate.setTopologyTemplate(topology);
            repo.setElement(placementId, placementServiceTemplate);
            // complete next level of requirements
            ServiceTemplateId newServiceTemplateId = splitting.matchTopologyOfServiceTemplate(placementId);
            topology = repo.getElement(newServiceTemplateId).getTopologyTemplate();
            // delete intermediate result to avoid cluttering
            repo.forceDelete(placementId);
            placementId = newServiceTemplateId;
        }
        repo.forceDelete(placementId);
        // returned completed topology
        return topology;
    } catch (Exception e) {
        LOGGER.debug("Exception while completing topology: {}", e.getMessage());
        return topology;
    }
}
Also used : Splitting(org.eclipse.winery.repository.splitting.Splitting) IRepository(org.eclipse.winery.repository.backend.IRepository) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) InvalidParameterException(java.security.InvalidParameterException) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate)

Example 39 with IRepository

use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.

the class EdmmResource method getOneToOneMap.

@GET
@Path("one-to-one-map")
@Produces(MediaType.APPLICATION_JSON)
public Response getOneToOneMap() {
    IRepository repository = RepositoryFactory.getRepository();
    EdmmManager edmmManager = EdmmManager.forRepository(repository);
    Map<QName, EdmmType> oneToOneMap = edmmManager.getOneToOneMap();
    Map<String, String> reverseOneToOneMap = new HashMap<>();
    for (Map.Entry<QName, EdmmType> entry : oneToOneMap.entrySet()) {
        EdmmType edmmType = entry.getValue();
        reverseOneToOneMap.put(edmmType.getValue(), entry.getKey().getLocalPart());
    }
    return Response.ok().type(MediaType.APPLICATION_JSON).entity(reverseOneToOneMap).build();
}
Also used : EdmmType(org.eclipse.winery.edmm.model.EdmmType) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) EdmmManager(org.eclipse.winery.edmm.EdmmManager) IRepository(org.eclipse.winery.repository.backend.IRepository) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with IRepository

use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.

the class GenericArtifactsResource method findInterface.

private Optional<TInterface> findInterface(EntityTypeId id, String interfaceName) {
    TInterface i;
    List<TInterface> interfaces = new ArrayList<>();
    IRepository repository = RepositoryFactory.getRepository();
    if (this.res instanceof NodeTypeImplementationResource || this.res instanceof NodeTypeImplementationsResource) {
        TNodeType nodeType = repository.getElement((NodeTypeId) id);
        if (nodeType.getInterfaces() != null) {
            interfaces.addAll(nodeType.getInterfaces());
        }
    } else if (this.res instanceof RelationshipTypeImplementationResource || this.res instanceof RelationshipTypeImplementationsResource) {
        TRelationshipType relationshipType = repository.getElement((RelationshipTypeId) id);
        if (relationshipType.getSourceInterfaces() != null) {
            interfaces.addAll(relationshipType.getSourceInterfaces());
        }
        if (relationshipType.getTargetInterfaces() != null) {
            interfaces.addAll(relationshipType.getTargetInterfaces());
        }
        if (relationshipType.getInterfaces() != null) {
            interfaces.addAll(relationshipType.getInterfaces());
        }
    }
    Iterator<TInterface> it = interfaces.iterator();
    do {
        i = it.next();
        if (i.getName().equals(interfaceName)) {
            return Optional.of(i);
        }
    } while (it.hasNext());
    return Optional.empty();
}
Also used : TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) RelationshipTypeImplementationsResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.relationshiptypeimplementations.RelationshipTypeImplementationsResource) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) TInterface(org.eclipse.winery.model.tosca.TInterface) INodeTemplateResourceOrNodeTypeImplementationResourceOrRelationshipTypeImplementationResource(org.eclipse.winery.repository.rest.resources._support.INodeTemplateResourceOrNodeTypeImplementationResourceOrRelationshipTypeImplementationResource) RelationshipTypeImplementationResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.relationshiptypeimplementations.RelationshipTypeImplementationResource) NodeTypeImplementationsResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationsResource) ArrayList(java.util.ArrayList) NodeTypeImplementationResource(org.eclipse.winery.repository.rest.resources.entitytypeimplementations.nodetypeimplementations.NodeTypeImplementationResource) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeType(org.eclipse.winery.model.tosca.TNodeType)

Aggregations

IRepository (org.eclipse.winery.repository.backend.IRepository)75 TNodeType (org.eclipse.winery.model.tosca.TNodeType)29 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)27 IOException (java.io.IOException)24 QName (javax.xml.namespace.QName)24 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)22 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)21 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 HashMap (java.util.HashMap)15 LoggerFactory (org.slf4j.LoggerFactory)15 LinkedHashMap (java.util.LinkedHashMap)14 List (java.util.List)14 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)14 RepositoryFactory (org.eclipse.winery.repository.backend.RepositoryFactory)14 Collectors (java.util.stream.Collectors)13 POST (javax.ws.rs.POST)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13