Search in sources :

Example 71 with Service

use of com.google.monitoring.v3.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 72 with Service

use of com.google.monitoring.v3.Service in project java-docs-samples by GoogleCloudPlatform.

the class BigQueryRunner method createMetricsIfNeeded.

private void createMetricsIfNeeded() {
    // If all required metrics already exist, no need to make service calls.
    if (REQUIRED_METRICS.stream().map(MetricDescriptor::getDisplayName).allMatch(existingMetrics::contains)) {
        return;
    }
    ListMetricDescriptorsRequest listMetricsRequest = ListMetricDescriptorsRequest.newBuilder().setName(projectName).setFilter(CUSTOM_METRIC_FILTER).build();
    ListMetricDescriptorsPagedResponse listMetricsResponse = client.listMetricDescriptors(listMetricsRequest);
    for (MetricDescriptor existingMetric : listMetricsResponse.iterateAll()) {
        existingMetrics.add(existingMetric.getDisplayName());
    }
    REQUIRED_METRICS.stream().filter(metric -> !existingMetrics.contains(metric.getDisplayName())).forEach(this::createMetric);
}
Also used : ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListMetricDescriptorsRequest(com.google.monitoring.v3.ListMetricDescriptorsRequest) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest) MetricDescriptor(com.google.api.MetricDescriptor) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) BigQuery(com.google.cloud.bigquery.BigQuery) ArrayList(java.util.ArrayList) BigQueryOptions(com.google.cloud.bigquery.BigQueryOptions) Lists(com.google.common.collect.Lists) ServiceOptions(com.google.cloud.ServiceOptions) TypedValue(com.google.monitoring.v3.TypedValue) Job(com.google.cloud.bigquery.Job) TableResult(com.google.cloud.bigquery.TableResult) Point(com.google.monitoring.v3.Point) PrintStream(java.io.PrintStream) ImmutableSet(com.google.common.collect.ImmutableSet) JobInfo(com.google.cloud.bigquery.JobInfo) ListMetricDescriptorsPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse) Metric(com.google.api.Metric) TimeSeries(com.google.monitoring.v3.TimeSeries) Set(java.util.Set) QueryJobConfiguration(com.google.cloud.bigquery.QueryJobConfiguration) Timestamps(com.google.protobuf.util.Timestamps) IOException(java.io.IOException) CreateTimeSeriesRequest(com.google.monitoring.v3.CreateTimeSeriesRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) JobId(com.google.cloud.bigquery.JobId) CreateMetricDescriptorRequest(com.google.monitoring.v3.CreateMetricDescriptorRequest) TimeInterval(com.google.monitoring.v3.TimeInterval) MetricDescriptor(com.google.api.MetricDescriptor) ListMetricDescriptorsRequest(com.google.monitoring.v3.ListMetricDescriptorsRequest) ListMetricDescriptorsPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListMetricDescriptorsPagedResponse)

Example 73 with Service

use of com.google.monitoring.v3.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 74 with Service

use of com.google.monitoring.v3.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 75 with Service

use of com.google.monitoring.v3.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)

Aggregations

Test (org.junit.jupiter.api.Test)33 Test (org.junit.Test)30 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 AbstractMessage (com.google.protobuf.AbstractMessage)19 CoreException (org.eclipse.core.runtime.CoreException)18 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)16 Service (com.google.monitoring.v3.Service)16 IOException (java.io.IOException)16 HashMap (java.util.HashMap)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 ArrayList (java.util.ArrayList)12 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)11 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)11 StatusRuntimeException (io.grpc.StatusRuntimeException)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