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);
}
}
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);
}
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);
}
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());
}
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());
}
Aggregations