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