Search in sources :

Example 81 with Service

use of com.google.cloud.servicedirectory.v1.Service in project quarkus by quarkusio.

the class KnativeScaleBoundsTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")).isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml")).satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("knative.yml"));
    assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).singleElement().satisfies(i -> {
        Service service = (Service) i;
        Map<String, String> annotations = service.getSpec().getTemplate().getMetadata().getAnnotations();
        assertThat(annotations).contains(entry("autoscaling.knative.dev/minScale", "3"));
        assertThat(annotations).contains(entry("autoscaling.knative.dev/maxScale", "5"));
    });
}
Also used : Path(java.nio.file.Path) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Service(io.fabric8.knative.serving.v1.Service) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Assertions.entry(org.assertj.core.api.Assertions.entry) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) List(java.util.List) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Map(java.util.Map) ProdBuildResults(io.quarkus.test.ProdBuildResults) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Path(java.nio.file.Path) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Service(io.fabric8.knative.serving.v1.Service) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) Test(org.junit.jupiter.api.Test)

Example 82 with Service

use of com.google.cloud.servicedirectory.v1.Service in project quarkus by quarkusio.

the class KnativeWithApplicationPropertiesTest method assertGeneratedResources.

@Test
public void assertGeneratedResources() throws IOException {
    Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
    assertThat(kubernetesDir).isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")).isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml")).satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2));
    List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("knative.yml"));
    assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).singleElement().satisfies(i -> {
        assertThat(i).isInstanceOfSatisfying(Service.class, s -> {
            assertThat(s.getSpec()).satisfies(spec -> {
                assertThat(s.getMetadata()).satisfies(m -> {
                    assertThat(m.getName()).isEqualTo("test-it");
                    assertThat(m.getLabels()).contains(entry("foo", "bar"));
                    assertThat(m.getAnnotations()).contains(entry("bar", "baz"));
                    assertThat(m.getNamespace()).isEqualTo("applications");
                });
                assertThat(spec.getTemplate()).satisfies(template -> {
                    assertThat(template.getSpec()).satisfies(templateSpec -> {
                        assertThat(templateSpec.getContainers()).hasSize(1).singleElement().satisfies(c -> {
                            assertThat(c.getPorts()).hasSize(1).singleElement().satisfies(p -> {
                                assertThat(p.getName()).isEqualTo("http1");
                            });
                        });
                    });
                });
            });
        });
    });
}
Also used : Path(java.nio.file.Path) Test(org.junit.jupiter.api.Test) List(java.util.List) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) Service(io.fabric8.knative.serving.v1.Service) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProdBuildResults(io.quarkus.test.ProdBuildResults) IOException(java.io.IOException) ProdModeTestResults(io.quarkus.test.ProdModeTestResults) Assertions.entry(org.assertj.core.api.Assertions.entry) Path(java.nio.file.Path) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Test(org.junit.jupiter.api.Test) QuarkusProdModeTest(io.quarkus.test.QuarkusProdModeTest)

Example 83 with Service

use of com.google.cloud.servicedirectory.v1.Service in project kramerius by ceskaexpedice.

the class IiifAPI method manifest.

@GET
@Path("{pid}/manifest")
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response manifest(@PathParam("pid") String pid) {
    checkPid(pid);
    try {
        DocumentDto document = getIiifDocument(pid);
        PropertyValue titleLabel = new PropertyValueSimpleImpl(document.getTitle());
        Manifest manifest = new ManifestImpl(UriBuilder.fromUri(iiifUri).path(getClass(), "manifest").build(pid), titleLabel);
        List<String> fieldList = new ArrayList<String>();
        List<Canvas> canvases = new ArrayList<Canvas>();
        List<String> children = ItemResourceUtils.solrChildrenPids(pid, fieldList, solrAccess, solrMemoization);
        Map<String, Pair<Integer, Integer>> resolutions = getResolutions(children);
        for (String p : children) {
            String repPid = p.replace("/", "");
            if (repPid.equals(pid)) {
                continue;
            }
            DocumentDto page = getIiifDocument(repPid);
            if (!"page".equals(page.getModel()))
                continue;
            String id = ApplicationURL.applicationURL(this.requestProvider.get()) + "/canvas/" + repPid;
            Pair<Integer, Integer> resolution = resolutions.get(p);
            if (resolution != null) {
                Canvas canvas = new CanvasImpl(id, new PropertyValueSimpleImpl(page.getTitle()), resolution.getLeft(), resolution.getRight());
                ImageResource resource = new ImageResourceImpl();
                String resourceId = ApplicationURL.applicationURL(this.requestProvider.get()).toString() + "/iiif/" + repPid + "/full/full/0/default.jpg";
                resource.setType("dctypes:Image");
                resource.setId(resourceId);
                resource.setHeight(resolution.getLeft());
                resource.setWidth(resolution.getRight());
                resource.setFormat("image/jpeg");
                Service service = new ServiceImpl();
                service.setContext("http://iiif.io/api/image/2/context.json");
                service.setId(ApplicationURL.applicationURL(this.requestProvider.get()).toString() + "/iiif/" + repPid);
                service.setProfile("http://iiif.io/api/image/2/level1.json");
                resource.setService(service);
                Image image = new ImageImpl();
                image.setOn(new URI(id));
                image.setResource(resource);
                canvas.setImages(Collections.singletonList(image));
                canvases.add(canvas);
            }
        }
        // no pages - 500 ?
        if (canvases.isEmpty()) {
            throw new GenericApplicationException("cannot create manifest for pid '" + pid + "'");
        }
        Sequence sequence = new SequenceImpl();
        sequence.setCanvases(canvases);
        manifest.setSequences(Collections.singletonList(sequence));
        return Response.ok().entity(toJSON(manifest)).build();
    } catch (IOException e) {
        throw new GenericApplicationException(e.getMessage());
    } catch (URISyntaxException e) {
        throw new GenericApplicationException(e.getMessage());
    } catch (InterruptedException e) {
        throw new GenericApplicationException(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) ManifestImpl(de.digitalcollections.iiif.presentation.model.impl.v2.ManifestImpl) SequenceImpl(de.digitalcollections.iiif.presentation.model.impl.v2.SequenceImpl) URISyntaxException(java.net.URISyntaxException) Image(de.digitalcollections.iiif.presentation.model.api.v2.Image) GenericApplicationException(cz.incad.kramerius.rest.api.exceptions.GenericApplicationException) URI(java.net.URI) ImageResourceImpl(de.digitalcollections.iiif.presentation.model.impl.v2.ImageResourceImpl) ImageResource(de.digitalcollections.iiif.presentation.model.api.v2.ImageResource) Pair(org.apache.commons.lang3.tuple.Pair) ServiceImpl(de.digitalcollections.iiif.presentation.model.impl.v2.ServiceImpl) Canvas(de.digitalcollections.iiif.presentation.model.api.v2.Canvas) PropertyValue(de.digitalcollections.iiif.presentation.model.api.v2.PropertyValue) Service(de.digitalcollections.iiif.presentation.model.api.v2.Service) Sequence(de.digitalcollections.iiif.presentation.model.api.v2.Sequence) IOException(java.io.IOException) Manifest(de.digitalcollections.iiif.presentation.model.api.v2.Manifest) ImageImpl(de.digitalcollections.iiif.presentation.model.impl.v2.ImageImpl) CanvasImpl(de.digitalcollections.iiif.presentation.model.impl.v2.CanvasImpl) PropertyValueSimpleImpl(de.digitalcollections.iiif.presentation.model.impl.v2.PropertyValueSimpleImpl) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 84 with Service

use of com.google.cloud.servicedirectory.v1.Service in project dekorate by dekorateio.

the class KnativeExampleTest method shouldContainServiceWithPortNamedHttp1.

@Test
public void shouldContainServiceWithPortNamedHttp1() {
    KubernetesList list = Serialization.unmarshalAsList(KnativeExampleTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/knative.yml"));
    assertNotNull(list);
    assertEquals(1, list.getItems().size());
    Service s = findFirst(list, Service.class).orElseThrow(() -> new IllegalStateException("No knative service found!"));
    assertNotNull(s);
    Container c = s.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertEquals("http1", c.getPorts().get(0).getName());
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Service(io.fabric8.knative.serving.v1.Service) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Test(org.junit.jupiter.api.Test)

Example 85 with Service

use of com.google.cloud.servicedirectory.v1.Service in project dekorate by dekorateio.

the class Issue409Test method shouldHaveCustomImageInKnativeYaml.

@Test
public void shouldHaveCustomImageInKnativeYaml() {
    Service s = Serialization.unmarshal(Service.class.getClassLoader().getResourceAsStream("META-INF/dekorate/knative.yml"));
    assertNotNull(s);
    Container c = s.getSpec().getTemplate().getSpec().getContainers().get(0);
    assertNotNull(c);
    String image = c.getImage();
    assertEquals("my-group/my-name:my-version", image);
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Service(io.fabric8.knative.serving.v1.Service) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)33 Service (io.fabric8.knative.serving.v1.Service)28 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)22 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)22 Test (org.junit.Test)19 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)18 CoreException (org.eclipse.core.runtime.CoreException)18 Service (com.google.monitoring.v3.Service)16 IOException (java.io.IOException)15 AbstractMessage (com.google.protobuf.AbstractMessage)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)11 ProdBuildResults (io.quarkus.test.ProdBuildResults)11 ProdModeTestResults (io.quarkus.test.ProdModeTestResults)11 QuarkusProdModeTest (io.quarkus.test.QuarkusProdModeTest)11 Path (java.nio.file.Path)11 ArrayList (java.util.ArrayList)11 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)11 List (java.util.List)10 DisplayName (org.junit.jupiter.api.DisplayName)10