Search in sources :

Example 61 with Service

use of com.google.cloud.servicedirectory.v1.Service in project kubernetes by ballerinax.

the class KnativeServiceHandler method generate.

/**
 * Generate kubernetes deployment definition from annotation.
 *
 * @param serviceModel @{@link ServiceModel} definition
 * @throws KubernetesPluginException If an error occurs while generating artifact.
 */
private void generate(ServiceModel serviceModel) throws KubernetesPluginException {
    List<ContainerPort> containerPorts = null;
    if (serviceModel.getPorts() != null) {
        containerPorts = populatePorts(serviceModel.getPorts());
    }
    Container container = generateContainer(serviceModel, containerPorts);
    Service knativeSvc = new ServiceBuilder().withNewMetadata().withName(serviceModel.getName()).withNamespace(knativeDataHolder.getNamespace()).withAnnotations(serviceModel.getAnnotations()).withLabels(serviceModel.getLabels()).endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainerConcurrency((long) serviceModel.getContainerConcurrency()).withTimeoutSeconds((long) serviceModel.getTimeoutSeconds()).withContainers(container).withInitContainers(generateInitContainer(serviceModel)).withVolumes(populateVolume(serviceModel)).endSpec().endTemplate().endSpec().build();
    try {
        String knativeSvcContent = SerializationUtils.dumpWithoutRuntimeStateAsYaml(knativeSvc);
        KnativeUtils.writeToFile(knativeSvcContent, KNATIVE_SVC_FILE_POSTFIX + YAML);
    } catch (IOException e) {
        String errorMessage = "error while generating yaml file for deployment: " + serviceModel.getName();
        throw new KubernetesPluginException(errorMessage, e);
    }
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) Service(io.fabric8.knative.serving.v1.Service) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) ServiceBuilder(io.fabric8.knative.serving.v1.ServiceBuilder)

Example 62 with Service

use of com.google.cloud.servicedirectory.v1.Service in project kubernetes-client by fabric8io.

the class ServiceTest method testCreate.

@Test
@DisplayName("Should Create a Knative Service")
void testCreate() {
    Service service = new ServiceBuilder().withNewMetadata().withName("service").endMetadata().build();
    server.expect().post().withPath("/apis/serving.knative.dev/v1/namespaces/ns2/services").andReturn(HttpURLConnection.HTTP_OK, service).once();
    service = client.services().inNamespace("ns2").create(service);
    assertNotNull(service);
}
Also used : Service(io.fabric8.knative.serving.v1.Service) ServiceBuilder(io.fabric8.knative.serving.v1.ServiceBuilder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 63 with Service

use of com.google.cloud.servicedirectory.v1.Service in project kubernetes-client by fabric8io.

the class ServiceTest method testGet.

@Test
@DisplayName("Should get a Knative Service")
void testGet() {
    Service service2 = new ServiceBuilder().withNewMetadata().withName("service2").endMetadata().build();
    server.expect().get().withPath("/apis/serving.knative.dev/v1/namespaces/ns2/services/service2").andReturn(HttpURLConnection.HTTP_OK, service2).once();
    Service service = client.services().inNamespace("ns2").withName("service2").get();
    assertNotNull(service);
    assertEquals("service2", service.getMetadata().getName());
}
Also used : Service(io.fabric8.knative.serving.v1.Service) ServiceBuilder(io.fabric8.knative.serving.v1.ServiceBuilder) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 64 with Service

use of com.google.cloud.servicedirectory.v1.Service in project kubernetes-client by fabric8io.

the class ServiceCrudTest method shouldListAndGetService.

@Test
void shouldListAndGetService() {
    Service service2 = new ServiceBuilder().withNewMetadata().withName("service2").endMetadata().build();
    client.services().inNamespace("ns2").create(service2);
    ServiceList serviceList = client.services().inNamespace("ns2").list();
    assertNotNull(serviceList);
    assertEquals(1, serviceList.getItems().size());
    Service service = client.services().inNamespace("ns2").withName("service2").get();
    assertNotNull(service);
    assertEquals("service2", service.getMetadata().getName());
}
Also used : ServiceList(io.fabric8.knative.serving.v1.ServiceList) Service(io.fabric8.knative.serving.v1.Service) ServiceBuilder(io.fabric8.knative.serving.v1.ServiceBuilder) Test(org.junit.jupiter.api.Test)

Example 65 with Service

use of com.google.cloud.servicedirectory.v1.Service in project kubernetes-client by fabric8io.

the class ServiceCrudTest method shouldIncludeServiceStatus.

@Test
void shouldIncludeServiceStatus() {
    Service service = new ServiceBuilder().withNewMetadata().withName("service").endMetadata().build();
    Service created = client.services().inNamespace("ns2").create(service);
    ServiceList serviceList = client.services().inNamespace("ns2").list();
    assertNotNull(serviceList);
    assertEquals(1, serviceList.getItems().size());
    created.setStatus(new ServiceStatusBuilder().withNewAddress("http://my-service").build());
    assertNotNull(client.services().inNamespace("ns2").withName("service").updateStatus(created).getStatus());
}
Also used : ServiceStatusBuilder(io.fabric8.knative.serving.v1.ServiceStatusBuilder) ServiceList(io.fabric8.knative.serving.v1.ServiceList) Service(io.fabric8.knative.serving.v1.Service) ServiceBuilder(io.fabric8.knative.serving.v1.ServiceBuilder) 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