Search in sources :

Example 1 with Gateway

use of me.snowdrop.istio.api.networking.v1alpha3.Gateway in project kie-wb-common by kiegroup.

the class FlowElementConverterTest method convertSupported.

@Test
public void convertSupported() {
    StartEvent startEvent = mock(StartEvent.class);
    tested.convertNode(startEvent);
    verify(startEventConverter).convert(startEvent);
    EndEvent endEvent = mock(EndEvent.class);
    tested.convertNode(endEvent);
    verify(endEventConverter).convert(endEvent);
    BoundaryEvent boundaryEvent = mock(BoundaryEvent.class);
    tested.convertNode(boundaryEvent);
    verify(eventConverter).convertBoundaryEvent(boundaryEvent);
    IntermediateCatchEvent intermediateCatchEvent = mock(IntermediateCatchEvent.class);
    tested.convertNode(intermediateCatchEvent);
    verify(eventConverter).convert(intermediateCatchEvent);
    IntermediateThrowEvent intermediateThrowEvent = mock(IntermediateThrowEvent.class);
    tested.convertNode(intermediateThrowEvent);
    verify(throwEventConverter).convert(intermediateThrowEvent);
    Task task = mock(Task.class);
    tested.convertNode(task);
    verify(taskConverter).convert(task);
    Gateway gateway = mock(Gateway.class);
    tested.convertNode(gateway);
    verify(gatewayConverter).convert(gateway);
    SubProcess subProcess = mock(SubProcess.class);
    tested.convertNode(subProcess);
    verify(subProcessConverter).convertSubProcess(subProcess);
    CallActivity callActivity = mock(CallActivity.class);
    tested.convertNode(callActivity);
    verify(callActivityConverter).convert(callActivity);
    TextAnnotation textAnnotation = mock(TextAnnotation.class);
    tested.convertNode(textAnnotation);
    verify(artifactsConverter).convert(textAnnotation);
    DataObjectReference dataObjectReference = mock(DataObjectReference.class);
    tested.convertNode(dataObjectReference);
    verify(artifactsConverter).convert(dataObjectReference);
}
Also used : SubProcess(org.eclipse.bpmn2.SubProcess) Task(org.eclipse.bpmn2.Task) BoundaryEvent(org.eclipse.bpmn2.BoundaryEvent) Gateway(org.eclipse.bpmn2.Gateway) IntermediateCatchEvent(org.eclipse.bpmn2.IntermediateCatchEvent) StartEvent(org.eclipse.bpmn2.StartEvent) EndEvent(org.eclipse.bpmn2.EndEvent) CallActivity(org.eclipse.bpmn2.CallActivity) TextAnnotation(org.eclipse.bpmn2.TextAnnotation) IntermediateThrowEvent(org.eclipse.bpmn2.IntermediateThrowEvent) DataObjectReference(org.eclipse.bpmn2.DataObjectReference) Test(org.junit.Test)

Example 2 with Gateway

use of me.snowdrop.istio.api.networking.v1alpha3.Gateway in project kubernetes by ballerinax.

the class IstioGatewayHandler method generate.

/**
 * Generate the artifacts.
 * @param gatewayModel The gateway model.
 * @throws KubernetesPluginException Error if occurred when writing to file.
 */
private void generate(IstioGatewayModel gatewayModel) throws KubernetesPluginException {
    try {
        Gateway gateway = new GatewayBuilder().withNewMetadata().withName(gatewayModel.getName()).withNamespace(dataHolder.getNamespace()).withLabels(gatewayModel.getLabels()).withAnnotations(gatewayModel.getAnnotations()).endMetadata().withNewSpec().withSelector(gatewayModel.getSelector()).withServers(populateServers(gatewayModel.getServers())).endSpec().build();
        String gatewayContent = SerializationUtils.dumpWithoutRuntimeStateAsYaml(gateway);
        KubernetesUtils.writeToFile(gatewayContent, ISTIO_GATEWAY_FILE_POSTFIX + YAML);
    } catch (IOException e) {
        String errorMessage = "error while generating yaml file for istio gateway: " + gatewayModel.getName();
        throw new KubernetesPluginException(errorMessage, e);
    }
}
Also used : Gateway(me.snowdrop.istio.api.networking.v1alpha3.Gateway) GatewayBuilder(me.snowdrop.istio.api.networking.v1alpha3.GatewayBuilder) IOException(java.io.IOException) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException)

Example 3 with Gateway

use of me.snowdrop.istio.api.networking.v1alpha3.Gateway in project kubernetes by ballerinax.

the class IstioGatewayTest method noTLSHttpRedirect.

/**
 * Build bal file with istio gateway annotation having no tls httpsRedirect field.
 *
 * @throws IOException               Error when loading the generated yaml.
 * @throws InterruptedException      Error when compiling the ballerina file.
 * @throws KubernetesPluginException Error when deleting the generated artifacts folder.
 */
@Test(groups = { "istio" })
public void noTLSHttpRedirect() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "no_tls_https_redirect.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate gateway yaml
    File gatewayFile = KUBERNETES_TARGET_PATH.resolve("no_tls_https_redirect_istio_gateway.yaml").toFile();
    Assert.assertTrue(gatewayFile.exists());
    Gateway gateway = KubernetesTestUtils.loadYaml(gatewayFile);
    Assert.assertNotNull(gateway.getMetadata());
    Assert.assertEquals(gateway.getMetadata().getName(), "my-gateway", "Invalid gateway name");
    Assert.assertNotNull(gateway.getSpec());
    Assert.assertEquals(gateway.getSpec().getSelector().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "my-gateway-controller", "Invalid selector.");
    Assert.assertNotNull(gateway.getSpec().getServers());
    Assert.assertEquals(gateway.getSpec().getServers().size(), 1);
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getNumber().intValue(), 80, "Invalid port number.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getName(), "http", "Invalid port name.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getProtocol(), "HTTP", "Invalid port protocol.");
    Assert.assertNotNull(gateway.getSpec().getServers().get(0).getHosts());
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getHosts().size(), 2);
    Assert.assertTrue(gateway.getSpec().getServers().get(0).getHosts().contains("uk.bookinfo.com"), "uk.bookinfo.com host not included");
    Assert.assertTrue(gateway.getSpec().getServers().get(0).getHosts().contains("eu.bookinfo.com"), "eu.bookinfo.com host not included");
    Assert.assertNull(gateway.getSpec().getServers().get(0).getTls(), "tls options should not be available");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : Gateway(me.snowdrop.istio.api.networking.v1alpha3.Gateway) File(java.io.File) Test(org.testng.annotations.Test)

Example 4 with Gateway

use of me.snowdrop.istio.api.networking.v1alpha3.Gateway in project kubernetes by ballerinax.

the class IstioGatewayTest method tlsMutualTest.

/**
 * Build bal file with istio gateway annotation having mutual mode TLS.
 *
 * @throws IOException               Error when loading the generated yaml.
 * @throws InterruptedException      Error when compiling the ballerina file.
 * @throws KubernetesPluginException Error when deleting the generated artifacts folder.
 */
@Test(groups = { "istio" })
public void tlsMutualTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "tls_mutual.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate gateway yaml
    File gatewayFile = KUBERNETES_TARGET_PATH.resolve("tls_mutual_istio_gateway.yaml").toFile();
    Assert.assertTrue(gatewayFile.exists());
    Gateway gateway = KubernetesTestUtils.loadYaml(gatewayFile);
    Assert.assertNotNull(gateway.getMetadata());
    Assert.assertEquals(gateway.getMetadata().getName(), "my-gateway", "Invalid gateway name");
    Assert.assertNotNull(gateway.getSpec());
    Assert.assertEquals(gateway.getSpec().getSelector().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "my-gateway-controller", "Invalid selector.");
    Assert.assertNotNull(gateway.getSpec().getServers());
    Assert.assertEquals(gateway.getSpec().getServers().size(), 1);
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getNumber().intValue(), 443, "Invalid port number.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getName(), "https", "Invalid port name.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getProtocol(), "HTTPS", "Invalid port protocol.");
    Assert.assertNotNull(gateway.getSpec().getServers().get(0).getHosts());
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getHosts().size(), 1);
    Assert.assertTrue(gateway.getSpec().getServers().get(0).getHosts().contains("httpbin.example.com"), "httpbin.example.com host not included");
    Assert.assertNotNull(gateway.getSpec().getServers().get(0).getTls());
    Assert.assertFalse(gateway.getSpec().getServers().get(0).getTls().getHttpsRedirect(), "Invalid tls httpsRedirect value");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getTls().getMode().name(), "MUTUAL", "Invalid tls mode value");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getTls().getServerCertificate(), "/etc/istio/ingressgateway-certs/tls.crt", "Invalid tls serverCertificate value");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getTls().getPrivateKey(), "/etc/istio/ingressgateway-certs/tls.key", "Invalid tls privateKey value");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getTls().getCaCertificates(), "/etc/istio/ingressgateway-ca-certs/ca-chain.cert.pem", "Invalid tls caCertificates value");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : Gateway(me.snowdrop.istio.api.networking.v1alpha3.Gateway) File(java.io.File) Test(org.testng.annotations.Test)

Example 5 with Gateway

use of me.snowdrop.istio.api.networking.v1alpha3.Gateway in project kubernetes by ballerinax.

the class IstioGatewayTest method allFieldsTest.

/**
 * Build bal file with istio gateway annotations.
 *
 * @throws IOException               Error when loading the generated yaml.
 * @throws InterruptedException      Error when compiling the ballerina file.
 * @throws KubernetesPluginException Error when deleting the generated artifacts folder.
 */
@Test(groups = { "istio" })
public void allFieldsTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
    Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "all_fields.bal"), 0);
    // Check if docker image exists and correct
    validateDockerfile();
    validateDockerImage();
    // Validate gateway yaml
    File gatewayFile = KUBERNETES_TARGET_PATH.resolve("all_fields_istio_gateway.yaml").toFile();
    Assert.assertTrue(gatewayFile.exists());
    Gateway gateway = KubernetesTestUtils.loadYaml(gatewayFile);
    Assert.assertNotNull(gateway.getMetadata());
    Assert.assertEquals(gateway.getMetadata().getName(), "my-gateway", "Invalid gateway name");
    Assert.assertEquals(gateway.getMetadata().getNamespace(), "ballerina", "Invalid gateway namespace");
    Assert.assertEquals(gateway.getMetadata().getLabels().size(), 2);
    Assert.assertEquals(gateway.getMetadata().getLabels().get("label1"), "label1", "Invalid label");
    Assert.assertEquals(gateway.getMetadata().getLabels().get("label2"), "label2", "Invalid label");
    Assert.assertEquals(gateway.getMetadata().getAnnotations().size(), 2);
    Assert.assertEquals(gateway.getMetadata().getAnnotations().get("anno1"), "anno1Val", "Invalid annotation value");
    Assert.assertEquals(gateway.getMetadata().getAnnotations().get("anno2"), "anno2Val", "Invalid annotation value");
    Assert.assertNotNull(gateway.getSpec());
    Assert.assertEquals(gateway.getSpec().getSelector().get(KubernetesConstants.KUBERNETES_SELECTOR_KEY), "my-gateway-controller", "Invalid selector.");
    Assert.assertNotNull(gateway.getSpec().getServers());
    Assert.assertEquals(gateway.getSpec().getServers().size(), 1);
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getNumber().intValue(), 80, "Invalid port number.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getName(), "http", "Invalid port name.");
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getPort().getProtocol(), "HTTP", "Invalid port protocol.");
    Assert.assertNotNull(gateway.getSpec().getServers().get(0).getHosts());
    Assert.assertEquals(gateway.getSpec().getServers().get(0).getHosts().size(), 2);
    Assert.assertTrue(gateway.getSpec().getServers().get(0).getHosts().contains("uk.bookinfo.com"), "uk.bookinfo.com host not included");
    Assert.assertTrue(gateway.getSpec().getServers().get(0).getHosts().contains("eu.bookinfo.com"), "eu.bookinfo.com host not included");
    Assert.assertNotNull(gateway.getSpec().getServers().get(0).getTls());
    Assert.assertTrue(gateway.getSpec().getServers().get(0).getTls().getHttpsRedirect(), "Invalid tls httpsRedirect value");
    KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
    KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
    KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
Also used : Gateway(me.snowdrop.istio.api.networking.v1alpha3.Gateway) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

Gateway (me.snowdrop.istio.api.networking.v1alpha3.Gateway)10 Test (org.testng.annotations.Test)10 File (java.io.File)9 Gateway (org.eclipse.bpmn2.Gateway)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)2 BoundaryEvent (org.eclipse.bpmn2.BoundaryEvent)2 CallActivity (org.eclipse.bpmn2.CallActivity)2 EndEvent (org.eclipse.bpmn2.EndEvent)2 ExclusiveGateway (org.eclipse.bpmn2.ExclusiveGateway)2 FlowElement (org.eclipse.bpmn2.FlowElement)2 FlowElementsContainer (org.eclipse.bpmn2.FlowElementsContainer)2 InclusiveGateway (org.eclipse.bpmn2.InclusiveGateway)2 SequenceFlow (org.eclipse.bpmn2.SequenceFlow)2 Point (org.eclipse.dd.dc.Point)2 JsonToken (com.fasterxml.jackson.core.JsonToken)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1