Search in sources :

Example 1 with KubernetesServerResolverFactory

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.KubernetesServerResolverFactory in project che-server by eclipse-che.

the class KubernetesInternalRuntimeTest method setup.

@BeforeMethod
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    runtimeStatesCache = new MapBasedRuntimeStateCache();
    machinesCache = new MapBasedMachinesCache();
    eventPublisher = new RuntimeEventsPublisher(eventService);
    serverResolverFactory = new KubernetesServerResolverFactory(pathTransformInverter, "che-host", MULTI_HOST_STRATEGY, WorkspaceExposureType.NATIVE.getConfigValue());
    startSynchronizer = spy(new StartSynchronizer(eventService, 5, IDENTITY));
    when(startSynchronizerFactory.create(any())).thenReturn(startSynchronizer);
    internalRuntime = new KubernetesInternalRuntime<>(13, 5, new URLRewriter.NoOpURLRewriter(), unrecoverablePodEventListenerFactory, serverCheckerFactory, volumesStrategy, probesScheduler, workspaceProbesFactory, eventPublisher, new KubernetesSharedPool(new NoopExecutorServiceWrapper()), runtimeStatesCache, machinesCache, startSynchronizerFactory, ImmutableSet.of(internalEnvironmentProvisioner), kubernetesEnvironmentProvisioner, toolingProvisioner, runtimeHangingDetector, previewUrlCommandProvisioner, secretAsContainerResourceProvisioner, serverResolverFactory, runtimeCleaner, cheNamespace, tracer, context, namespace);
    when(context.getEnvironment()).thenReturn(k8sEnv);
    when(context.getRuntime()).thenReturn(internalRuntime);
    when(serverCheckerFactory.create(any(), anyString(), any())).thenReturn(serversChecker);
    when(context.getIdentity()).thenReturn(IDENTITY);
    doNothing().when(namespace).cleanUp();
    when(namespace.services()).thenReturn(services);
    when(namespace.ingresses()).thenReturn(ingresses);
    when(namespace.deployments()).thenReturn(deployments);
    when(namespace.secrets()).thenReturn(secrets);
    when(namespace.configMaps()).thenReturn(configMaps);
    doReturn(ImmutableMap.of(M1_NAME, mock(InternalMachineConfig.class), M2_NAME, mock(InternalMachineConfig.class))).when(k8sEnv).getMachines();
    final Map<String, Service> allServices = ImmutableMap.of(SERVICE_NAME, mockService());
    final Ingress ingress = mockIngress();
    final Map<String, Ingress> allIngresses = ImmutableMap.of(INGRESS_NAME, ingress);
    when(services.create(any())).thenAnswer(a -> a.getArguments()[0]);
    when(ingresses.create(any())).thenAnswer(a -> a.getArguments()[0]);
    when(ingresses.wait(anyString(), anyLong(), any(), any())).thenReturn(ingress);
    when(deployments.deploy(any(Pod.class))).thenAnswer(inv -> inv.getArgument(0));
    when(deployments.deploy(any(Deployment.class))).thenAnswer(inv -> {
        Deployment d = inv.getArgument(0);
        Pod pod = new Pod();
        pod.setSpec(d.getSpec().getTemplate().getSpec());
        pod.setMetadata(d.getSpec().getTemplate().getMetadata());
        return pod;
    });
    when(k8sEnv.getServices()).thenReturn(allServices);
    when(k8sEnv.getIngresses()).thenReturn(allIngresses);
    when(k8sEnv.getPodsCopy()).thenReturn(podsMap);
    when(k8sEnv.getCommands()).thenReturn(new ArrayList<>(singletonList(envCommand)));
    when(deployments.waitRunningAsync(any())).thenReturn(CompletableFuture.completedFuture(null));
    when(serversChecker.startAsync(any())).thenReturn(CompletableFuture.completedFuture(null));
}
Also used : KubernetesServerResolverFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.KubernetesServerResolverFactory) Pod(io.fabric8.kubernetes.api.model.Pod) RuntimeEventsPublisher(org.eclipse.che.workspace.infrastructure.kubernetes.util.RuntimeEventsPublisher) EventService(org.eclipse.che.api.core.notification.EventService) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KubernetesSharedPool(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool) NoopExecutorServiceWrapper(org.eclipse.che.commons.observability.NoopExecutorServiceWrapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with KubernetesServerResolverFactory

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.KubernetesServerResolverFactory in project devspaces-images by redhat-developer.

the class KubernetesInternalRuntimeTest method setup.

@BeforeMethod
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    runtimeStatesCache = new MapBasedRuntimeStateCache();
    machinesCache = new MapBasedMachinesCache();
    eventPublisher = new RuntimeEventsPublisher(eventService);
    serverResolverFactory = new KubernetesServerResolverFactory(pathTransformInverter, "che-host", MULTI_HOST_STRATEGY, WorkspaceExposureType.NATIVE.getConfigValue());
    startSynchronizer = spy(new StartSynchronizer(eventService, 5, IDENTITY));
    when(startSynchronizerFactory.create(any())).thenReturn(startSynchronizer);
    internalRuntime = new KubernetesInternalRuntime<>(13, 5, new URLRewriter.NoOpURLRewriter(), unrecoverablePodEventListenerFactory, serverCheckerFactory, volumesStrategy, probesScheduler, workspaceProbesFactory, eventPublisher, new KubernetesSharedPool(new NoopExecutorServiceWrapper()), runtimeStatesCache, machinesCache, startSynchronizerFactory, ImmutableSet.of(internalEnvironmentProvisioner), kubernetesEnvironmentProvisioner, toolingProvisioner, runtimeHangingDetector, previewUrlCommandProvisioner, secretAsContainerResourceProvisioner, serverResolverFactory, runtimeCleaner, cheNamespace, tracer, context, namespace);
    when(context.getEnvironment()).thenReturn(k8sEnv);
    when(context.getRuntime()).thenReturn(internalRuntime);
    when(serverCheckerFactory.create(any(), anyString(), any())).thenReturn(serversChecker);
    when(context.getIdentity()).thenReturn(IDENTITY);
    doNothing().when(namespace).cleanUp();
    when(namespace.services()).thenReturn(services);
    when(namespace.ingresses()).thenReturn(ingresses);
    when(namespace.deployments()).thenReturn(deployments);
    when(namespace.secrets()).thenReturn(secrets);
    when(namespace.configMaps()).thenReturn(configMaps);
    doReturn(ImmutableMap.of(M1_NAME, mock(InternalMachineConfig.class), M2_NAME, mock(InternalMachineConfig.class))).when(k8sEnv).getMachines();
    final Map<String, Service> allServices = ImmutableMap.of(SERVICE_NAME, mockService());
    final Ingress ingress = mockIngress();
    final Map<String, Ingress> allIngresses = ImmutableMap.of(INGRESS_NAME, ingress);
    when(services.create(any())).thenAnswer(a -> a.getArguments()[0]);
    when(ingresses.create(any())).thenAnswer(a -> a.getArguments()[0]);
    when(ingresses.wait(anyString(), anyLong(), any(), any())).thenReturn(ingress);
    when(deployments.deploy(any(Pod.class))).thenAnswer(inv -> inv.getArgument(0));
    when(deployments.deploy(any(Deployment.class))).thenAnswer(inv -> {
        Deployment d = inv.getArgument(0);
        Pod pod = new Pod();
        pod.setSpec(d.getSpec().getTemplate().getSpec());
        pod.setMetadata(d.getSpec().getTemplate().getMetadata());
        return pod;
    });
    when(k8sEnv.getServices()).thenReturn(allServices);
    when(k8sEnv.getIngresses()).thenReturn(allIngresses);
    when(k8sEnv.getPodsCopy()).thenReturn(podsMap);
    when(k8sEnv.getCommands()).thenReturn(new ArrayList<>(singletonList(envCommand)));
    when(deployments.waitRunningAsync(any())).thenReturn(CompletableFuture.completedFuture(null));
    when(serversChecker.startAsync(any())).thenReturn(CompletableFuture.completedFuture(null));
}
Also used : KubernetesServerResolverFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.KubernetesServerResolverFactory) Pod(io.fabric8.kubernetes.api.model.Pod) RuntimeEventsPublisher(org.eclipse.che.workspace.infrastructure.kubernetes.util.RuntimeEventsPublisher) EventService(org.eclipse.che.api.core.notification.EventService) Service(io.fabric8.kubernetes.api.model.Service) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KubernetesSharedPool(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool) NoopExecutorServiceWrapper(org.eclipse.che.commons.observability.NoopExecutorServiceWrapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 Service (io.fabric8.kubernetes.api.model.Service)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)2 EventService (org.eclipse.che.api.core.notification.EventService)2 NoopExecutorServiceWrapper (org.eclipse.che.commons.observability.NoopExecutorServiceWrapper)2 KubernetesServerResolverFactory (org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.KubernetesServerResolverFactory)2 KubernetesSharedPool (org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool)2 RuntimeEventsPublisher (org.eclipse.che.workspace.infrastructure.kubernetes.util.RuntimeEventsPublisher)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 BeforeMethod (org.testng.annotations.BeforeMethod)2