Search in sources :

Example 61 with IRepository

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

the class TenantFilter method filter.

@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
    MultivaluedMap<String, String> headers = containerRequestContext.getHeaders();
    MultivaluedMap<String, String> queryParameters = containerRequestContext.getUriInfo().getQueryParameters();
    String tenantName = null;
    if (headers.containsKey(WINERY_TENANT)) {
        tenantName = headers.getFirst(WINERY_TENANT);
    } else if (queryParameters.containsKey(WINERY_TENANT)) {
        tenantName = queryParameters.getFirst(WINERY_TENANT);
    }
    if (tenantName != null) {
        LOGGER.debug("Got new request for tenant: " + tenantName);
        IRepository repo = RepositoryFactory.getRepository();
        if (repo instanceof TenantRepository) {
            ((TenantRepository) repo).useTenant(tenantName);
        }
    }
}
Also used : TenantRepository(org.eclipse.winery.repository.filebased.TenantRepository) IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 62 with IRepository

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

the class APIResource method getAllArtifactTemplatesOfContainedDeploymentArtifacts.

@GET
@Path("getallartifacttemplatesofcontaineddeploymentartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedDeploymentArtifacts(@QueryParam("servicetemplate") String serviceTemplateQNameString, @QueryParam("nodetemplateid") String nodeTemplateId) {
    if (StringUtils.isEmpty(serviceTemplateQNameString)) {
        return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter").build();
    }
    QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);
    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
    final IRepository repository = RepositoryFactory.getRepository();
    if (!repository.exists(serviceTemplateId)) {
        return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
    }
    ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);
    Collection<QName> artifactTemplates = new ArrayList<>();
    List<TNodeTemplate> allNestedNodeTemplates = BackendUtils.getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
    for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
        if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
            Collection<QName> ats = BackendUtils.getArtifactTemplatesOfReferencedDeploymentArtifacts(nodeTemplate, repository);
            artifactTemplates.addAll(ats);
        }
    }
    // convert QName list to select2 data
    Select2DataWithOptGroups res = new Select2DataWithOptGroups();
    for (QName qName : artifactTemplates) {
        res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
    }
    return Response.ok().entity(res.asSortedSet()).build();
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) Select2DataWithOptGroups(org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 63 with IRepository

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

the class APIResource method getAllArtifactTemplatesOfContainedImplementationArtifacts.

/**
 * Implementation similar to
 * getAllArtifactTemplatesOfContainedDeploymentArtifacts. Only difference is
 * "getArtifactTemplatesOfReferencedImplementationArtifacts" instead of
 * "getArtifactTemplatesOfReferencedDeploymentArtifacts".
 */
@GET
@Path("getallartifacttemplatesofcontainedimplementationartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedImplementationArtifacts(@QueryParam("servicetemplate") String serviceTemplateQNameString, @QueryParam("nodetemplateid") String nodeTemplateId) {
    if (StringUtils.isEmpty(serviceTemplateQNameString)) {
        return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter").build();
    }
    QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);
    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
    final IRepository repository = RepositoryFactory.getRepository();
    if (!repository.exists(serviceTemplateId)) {
        return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
    }
    ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);
    Collection<QName> artifactTemplates = new ArrayList<>();
    List<TNodeTemplate> allNestedNodeTemplates = BackendUtils.getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
    for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
        if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
            Collection<QName> ats = BackendUtils.getArtifactTemplatesOfReferencedImplementationArtifacts(nodeTemplate, repository);
            artifactTemplates.addAll(ats);
        }
    }
    // convert QName list to select2 data
    Select2DataWithOptGroups res = new Select2DataWithOptGroups();
    for (QName qName : artifactTemplates) {
        res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
    }
    return Response.ok().entity(res.asSortedSet()).build();
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) Select2DataWithOptGroups(org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) IRepository(org.eclipse.winery.repository.backend.IRepository) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 64 with IRepository

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

the class AbstractComponentsResource method getListOfAllIds.

/**
 * Used by org.eclipse.winery.repository.repository.client and by the artifactcreationdialog.tag. Especially the
 * "name" field is used there at the UI
 *
 * @param grouped if given, the JSON output is grouped by namespace
 * @return A list of all ids of all instances of this component type. Format: <code>[({"namespace": "[namespace]",
 * "id": "[id]"},)* ]</code>.
 * <p>
 * If grouped is set, the list will be grouped by namespace.
 * <code>[{"id": "[namsepace encoded]", "test": "[namespace decoded]", "children":[{"id": "[qName]", "text":
 * "[id]"}]}]</code>
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Object getListOfAllIds(@QueryParam("grouped") String grouped, @QueryParam("includeVersions") String includeVersions, @QueryParam("full") @ApiParam("If set, the full information of the definition's child is returned. E.g., in the case of node types, the same result as a GET on {ns}/{id] is returned. Works only in the case of grouped.") String full) {
    Class<? extends DefinitionsChildId> idClass = RestUtils.getComponentIdClassForComponentContainer(this.getClass());
    final IRepository repository = RepositoryFactory.getRepository();
    SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds = repository.getAllDefinitionsChildIds(idClass);
    if (Objects.nonNull(grouped)) {
        return getGroupedListOfIds(allDefinitionsChildIds, full, includeVersions);
    } else {
        return RestUtils.getListOfIds(allDefinitionsChildIds, Objects.nonNull(full), Objects.nonNull(includeVersions));
    }
}
Also used : IRepository(org.eclipse.winery.repository.backend.IRepository) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 65 with IRepository

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

the class TenantRepositoryTest method testTenantRepository.

@Test
public void testTenantRepository() throws Exception {
    Path repositoryRoot = Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot());
    Environments.getInstance().getRepositoryConfig().setTenantRepository(true);
    RepositoryFactory.reconfigure();
    IRepository repository = RepositoryFactory.getRepository(repositoryRoot);
    assertTrue(repository instanceof TenantRepository);
    Files.createDirectory(repositoryRoot.resolve("tenant_1"));
    Files.createDirectory(repositoryRoot.resolve("tenant_2"));
    Files.createDirectory(repositoryRoot.resolve("tenant_3"));
    ((TenantRepository) repository).useTenant("tenant_1");
    repository.setElement(new ServiceTemplateId(QName.valueOf("{namespace}test1")), new TServiceTemplate.Builder("test1").build());
    ((TenantRepository) repository).useTenant("tenant_3");
    repository.setElement(new ServiceTemplateId(QName.valueOf("{namespace}test53")), new TServiceTemplate.Builder("test53").build());
    repository.setElement(new ServiceTemplateId(QName.valueOf("{namespace}test3")), new TServiceTemplate.Builder("test3").build());
    SortedSet<ServiceTemplateId>[] serviceTemplates = new SortedSet[3];
    Thread tenant1Thread = new Thread(() -> {
        ((TenantRepository) repository).useTenant("tenant_1");
        serviceTemplates[0] = repository.getAllDefinitionsChildIds(ServiceTemplateId.class);
    });
    Thread tenant2Thread = new Thread(() -> {
        ((TenantRepository) repository).useTenant("tenant_2");
        serviceTemplates[1] = repository.getAllDefinitionsChildIds(ServiceTemplateId.class);
    });
    Thread tenant3Thread = new Thread(() -> {
        ((TenantRepository) repository).useTenant("tenant_3");
        serviceTemplates[2] = repository.getAllDefinitionsChildIds(ServiceTemplateId.class);
    });
    tenant1Thread.start();
    tenant2Thread.start();
    tenant3Thread.start();
    tenant1Thread.join();
    tenant2Thread.join();
    tenant3Thread.join();
    assertEquals(1, serviceTemplates[0].size());
    assertEquals(QName.valueOf("{namespace}test1"), serviceTemplates[0].first().getQName());
    assertEquals(0, serviceTemplates[1].size());
    assertEquals(2, serviceTemplates[2].size());
    assertTrue(serviceTemplates[2].removeIf(serviceTemplateId -> serviceTemplateId.getQName().equals(QName.valueOf("{namespace}test53"))));
    assertTrue(serviceTemplates[2].removeIf(serviceTemplateId -> serviceTemplateId.getQName().equals(QName.valueOf("{namespace}test3"))));
    assertEquals(0, serviceTemplates[2].size());
}
Also used : Path(java.nio.file.Path) SortedSet(java.util.SortedSet) Files(java.nio.file.Files) Environments(org.eclipse.winery.common.configuration.Environments) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) Test(org.junit.jupiter.api.Test) Paths(java.nio.file.Paths) IRepository(org.eclipse.winery.repository.backend.IRepository) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) QName(javax.xml.namespace.QName) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Path(java.nio.file.Path) IRepository(org.eclipse.winery.repository.backend.IRepository) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) SortedSet(java.util.SortedSet) Test(org.junit.jupiter.api.Test)

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