Search in sources :

Example 16 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method createService.

/**
 * Create Service resource
 *
 * @param openShiftClient       Openshift client
 * @param nonNamespaceOperation NonNamespaceOperation instance
 */
private Service createService(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation) {
    BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
    String serviceName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
    Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withName(serviceName)).thenReturn(baseOperation);
    Mockito.when(baseOperation.get()).thenReturn(null);
    Service service = Mockito.mock(Service.class, Mockito.RETURNS_DEEP_STUBS);
    return service;
}
Also used : Service(io.fabric8.kubernetes.api.model.Service) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation)

Example 17 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method createIngress.

/**
 * Create Ingress resource
 *
 * @param openShiftClient       Openshift client
 * @param nonNamespaceOperation NonNamespaceOperation instance
 * @param scalableResource      ScalableResource instance
 */
private Ingress createIngress(OpenShiftClient openShiftClient, NonNamespaceOperation nonNamespaceOperation, ScalableResource scalableResource) {
    String ingressName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_INGRESS_SUFFIX;
    Mockito.when(openShiftClient.extensions().ingresses().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withName(ingressName)).thenReturn(scalableResource);
    Ingress ingress = Mockito.mock(Ingress.class, Mockito.RETURNS_DEEP_STUBS);
    return ingress;
}
Also used : Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress)

Example 18 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testCreateServiceResourceForKubernetesClientException.

@Test
public void testCreateServiceResourceForKubernetesClientException() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources());
    NonNamespaceOperation nonNamespaceOperationService = Mockito.mock(NonNamespaceOperation.class);
    BaseOperation baseOperationService = Mockito.mock(BaseOperation.class);
    String serviceName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX + ContainerBasedGatewayConstants.CMS_SERVICE_SUFFIX;
    Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperationService);
    Mockito.when(nonNamespaceOperationService.withName(serviceName)).thenReturn(baseOperationService);
    Mockito.when(baseOperationService.get()).thenThrow(KubernetesClientException.class);
    API api = SampleTestObjectCreator.createDefaultAPI().context("").build();
    try {
        kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
    } catch (ContainerBasedGatewayException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) API(org.wso2.carbon.apimgt.core.models.API) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 19 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.

the class KubernetesBuildConfigsProducer method doListBuildConfigsByLabels.

protected void doListBuildConfigsByLabels(Exchange exchange, String operation) throws Exception {
    BuildConfigList buildConfigsList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_CONFIGS_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> buildConfigs;
        buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            buildConfigs.withLabel(entry.getKey(), entry.getValue());
        }
        buildConfigsList = buildConfigs.list();
    } else {
        MixedOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> buildConfigs;
        buildConfigs = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).buildConfigs();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            buildConfigs.withLabel(entry.getKey(), entry.getValue());
        }
        buildConfigsList = buildConfigs.list();
    }
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(buildConfigsList.getItems());
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) DoneableBuildConfig(io.fabric8.openshift.api.model.DoneableBuildConfig) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DoneableBuildConfig(io.fabric8.openshift.api.model.DoneableBuildConfig) BuildConfigResource(io.fabric8.openshift.client.dsl.BuildConfigResource) Map(java.util.Map) BuildConfigList(io.fabric8.openshift.api.model.BuildConfigList)

Example 20 with NonNamespaceOperation

use of io.fabric8.kubernetes.client.dsl.NonNamespaceOperation in project camel by apache.

the class KubernetesBuildsProducer method doListBuildByLabels.

protected void doListBuildByLabels(Exchange exchange, String operation) throws Exception {
    BuildList buildList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILDS_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<Build, BuildList, DoneableBuild, BuildResource<Build, DoneableBuild, String, LogWatch>> builds = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            builds.withLabel(entry.getKey(), entry.getValue());
        }
        buildList = builds.list();
    } else {
        MixedOperation<Build, BuildList, DoneableBuild, BuildResource<Build, DoneableBuild, String, LogWatch>> builds = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            builds.withLabel(entry.getKey(), entry.getValue());
        }
        buildList = builds.list();
    }
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(buildList.getItems());
}
Also used : BuildList(io.fabric8.openshift.api.model.BuildList) DoneableBuild(io.fabric8.openshift.api.model.DoneableBuild) DoneableBuild(io.fabric8.openshift.api.model.DoneableBuild) Build(io.fabric8.openshift.api.model.Build) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Map(java.util.Map) BuildResource(io.fabric8.openshift.client.dsl.BuildResource)

Aggregations

OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)17 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)15 Map (java.util.Map)12 Resource (io.fabric8.kubernetes.client.dsl.Resource)9 Service (io.fabric8.kubernetes.api.model.Service)8 Test (org.junit.Test)8 API (org.wso2.carbon.apimgt.core.models.API)8 BeforeTest (org.testng.annotations.BeforeTest)7 Test (org.testng.annotations.Test)7 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)7 ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)6 BaseOperation (io.fabric8.kubernetes.client.dsl.base.BaseOperation)6 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)5 URL (java.net.URL)5 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)5 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ArrayList (java.util.ArrayList)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 ConfigMapList (io.fabric8.kubernetes.api.model.ConfigMapList)1