Search in sources :

Example 1 with MachineStatusEvent

use of org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent in project che-server by eclipse-che.

the class KubernetesInternalRuntimeTest method stopsWaitingAllMachineStartWhenOneMachineStartFailed.

@Test(expectedExceptions = InfrastructureException.class)
public void stopsWaitingAllMachineStartWhenOneMachineStartFailed() throws Exception {
    final Container container1 = mockContainer(CONTAINER_NAME_1, EXPOSED_PORT_1);
    final Container container2 = mockContainer(CONTAINER_NAME_2, EXPOSED_PORT_2, INTERNAL_PORT);
    final ImmutableMap<String, Pod> allPods = ImmutableMap.of(WORKSPACE_POD_NAME, mockPod(ImmutableList.of(container1, container2)));
    when(k8sEnv.getPodsCopy()).thenReturn(allPods);
    internalRuntime = spy(internalRuntime);
    doThrow(IllegalStateException.class).when(internalRuntime).waitRunningAsync(any(), argThat(m -> m.getName().equals(M1_NAME)));
    try {
        internalRuntime.start(emptyMap());
    } catch (Exception rethrow) {
        verify(deployments).deploy(any(Pod.class));
        verify(ingresses).create(any());
        verify(services).create(any());
        verify(eventService, atLeastOnce()).publish(any());
        final List<MachineStatusEvent> events = captureEvents();
        assertTrue(events.contains(newEvent(M1_NAME, STARTING)));
        throw rethrow;
    }
}
Also used : Arrays(java.util.Arrays) ServerStatus(org.eclipse.che.api.core.model.workspace.runtime.ServerStatus) KubernetesServerImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesServerImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CREATE_IN_CHE_INSTALLATION_NAMESPACE(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations.CREATE_IN_CHE_INSTALLATION_NAMESPACE) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) KubernetesObjectUtil.putLabels(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putLabels) Mockito.doThrow(org.mockito.Mockito.doThrow) MockitoAnnotations(org.mockito.MockitoAnnotations) KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) Arrays.asList(java.util.Arrays.asList) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) WorkspaceExposureType(org.eclipse.che.workspace.infrastructure.kubernetes.server.WorkspaceExposureType) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) ServiceExposureStrategyProvider(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ServiceExposureStrategyProvider) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) KubernetesConfigsMaps(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesConfigsMaps) KubernetesDeployments(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesDeployments) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) KubernetesMachineCache(org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesMachineCache) IngressPathTransformInverter(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.IngressPathTransformInverter) SidecarToolingProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.SidecarToolingProvisioner) Mockito.doNothing(org.mockito.Mockito.doNothing) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Executors(java.util.concurrent.Executors) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) UnrecoverablePodEventListenerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListenerFactory) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) LogWatcher(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.LogWatcher) Mockito.mock(org.mockito.Mockito.mock) MachineStatus(org.eclipse.che.api.core.model.workspace.runtime.MachineStatus) InternalEnvironmentProvisioner(org.eclipse.che.api.workspace.server.spi.provision.InternalEnvironmentProvisioner) Mock(org.mockito.Mock) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) Mockito.spy(org.mockito.Mockito.spy) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) ArrayList(java.util.ArrayList) CheNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.CheNamespace) ServersChecker(org.eclipse.che.api.workspace.server.hc.ServersChecker) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace) Answer(org.mockito.stubbing.Answer) Stream.concat(java.util.stream.Stream.concat) ProbeScheduler(org.eclipse.che.api.workspace.server.hc.probe.ProbeScheduler) LogWatchTimeouts(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.LogWatchTimeouts) KubernetesSecrets(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesSecrets) Pod(io.fabric8.kubernetes.api.model.Pod) MachineStatusEvent(org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent) KubernetesIngresses(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesIngresses) Mockito.times(org.mockito.Mockito.times) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) Mockito.never(org.mockito.Mockito.never) KubernetesRuntimeStateCache(org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesRuntimeStateCache) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) DEBUG_WORKSPACE_START_LOG_LIMIT_BYTES(org.eclipse.che.api.workspace.shared.Constants.DEBUG_WORKSPACE_START_LOG_LIMIT_BYTES) PodEvent(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent) ServersCheckerFactory(org.eclipse.che.api.workspace.server.hc.ServersCheckerFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Date(java.util.Date) DtoConverter(org.eclipse.che.api.workspace.server.DtoConverter) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) KubernetesPreviewUrlCommandProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesPreviewUrlCommandProvisioner) Collectors.toMap(java.util.stream.Collectors.toMap) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KubernetesServices(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesServices) PodEvents(org.eclipse.che.workspace.infrastructure.kubernetes.util.PodEvents) ParseException(java.text.ParseException) StateException(org.eclipse.che.api.workspace.server.spi.StateException) KubernetesObjectUtil.putAnnotations(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putAnnotations) EventService(org.eclipse.che.api.core.notification.EventService) Command(org.eclipse.che.api.core.model.workspace.config.Command) PodLogHandler(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.PodLogHandler) WorkspaceProbes(org.eclipse.che.api.workspace.server.hc.probe.WorkspaceProbes) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KubernetesServerResolverFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.KubernetesServerResolverFactory) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) MULTI_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultiHostExternalServiceExposureStrategy.MULTI_HOST_STRATEGY) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) URLRewriter(org.eclipse.che.api.workspace.server.URLRewriter) BeforeMethod(org.testng.annotations.BeforeMethod) STARTING(org.eclipse.che.api.core.model.workspace.runtime.MachineStatus.STARTING) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) KubernetesSharedPool(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) WorkspaceVolumesStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumesStrategy) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Entry(java.util.Map.Entry) KubernetesRuntimeCommandImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeCommandImpl) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) WorkspaceProbesFactory(org.eclipse.che.api.workspace.server.hc.probe.WorkspaceProbesFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) NoopExecutorServiceWrapper(org.eclipse.che.commons.observability.NoopExecutorServiceWrapper) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Container(io.fabric8.kubernetes.api.model.Container) DataProvider(org.testng.annotations.DataProvider) DEBUG_WORKSPACE_START(org.eclipse.che.api.workspace.shared.Constants.DEBUG_WORKSPACE_START) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver) Captor(org.mockito.Captor) HashSet(java.util.HashSet) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) Collections.singletonMap(java.util.Collections.singletonMap) Service(io.fabric8.kubernetes.api.model.Service) RUNNING(org.eclipse.che.api.core.model.workspace.runtime.MachineStatus.RUNNING) LinkedList(java.util.LinkedList) RuntimeEventsPublisher(org.eclipse.che.workspace.infrastructure.kubernetes.util.RuntimeEventsPublisher) Collections.emptyMap(java.util.Collections.emptyMap) MachineId(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl.MachineId) Answers(org.mockito.Answers) InOrder(org.mockito.InOrder) Tracer(io.opentracing.Tracer) RuntimeLogEvent(org.eclipse.che.api.workspace.shared.dto.event.RuntimeLogEvent) IntOrStringBuilder(io.fabric8.kubernetes.api.model.IntOrStringBuilder) Assert.fail(org.testng.Assert.fail) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) SecretAsContainerResourceProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.secret.SecretAsContainerResourceProvisioner) Mockito.when(org.mockito.Mockito.when) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) CHE_ORIGINAL_NAME_LABEL(org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_ORIGINAL_NAME_LABEL) Assert.assertTrue(org.testng.Assert.assertTrue) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) Collectors.toList(java.util.stream.Collectors.toList) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) ParseException(java.text.ParseException) StateException(org.eclipse.che.api.workspace.server.spi.StateException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Test(org.testng.annotations.Test)

Example 2 with MachineStatusEvent

use of org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent in project devspaces-images by redhat-developer.

the class OpenShiftInternalRuntimeTest method verifyEventsOrder.

private void verifyEventsOrder(MachineStatusEvent... expectedEvents) {
    final Iterator<MachineStatusEvent> actualEvents = captureEvents().iterator();
    for (MachineStatusEvent expected : expectedEvents) {
        if (!actualEvents.hasNext()) {
            fail("It is expected to receive machine status events");
        }
        final MachineStatusEvent actual = actualEvents.next();
        assertEquals(actual, expected);
    }
    if (actualEvents.hasNext()) {
        fail("No more events expected");
    }
}
Also used : MachineStatusEvent(org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent)

Example 3 with MachineStatusEvent

use of org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent in project devspaces-images by redhat-developer.

the class KubernetesInternalRuntimeTest method stopsWaitingAllMachineStartWhenOneMachineStartFailed.

@Test(expectedExceptions = InfrastructureException.class)
public void stopsWaitingAllMachineStartWhenOneMachineStartFailed() throws Exception {
    final Container container1 = mockContainer(CONTAINER_NAME_1, EXPOSED_PORT_1);
    final Container container2 = mockContainer(CONTAINER_NAME_2, EXPOSED_PORT_2, INTERNAL_PORT);
    final ImmutableMap<String, Pod> allPods = ImmutableMap.of(WORKSPACE_POD_NAME, mockPod(ImmutableList.of(container1, container2)));
    when(k8sEnv.getPodsCopy()).thenReturn(allPods);
    internalRuntime = spy(internalRuntime);
    doThrow(IllegalStateException.class).when(internalRuntime).waitRunningAsync(any(), argThat(m -> m.getName().equals(M1_NAME)));
    try {
        internalRuntime.start(emptyMap());
    } catch (Exception rethrow) {
        verify(deployments).deploy(any(Pod.class));
        verify(ingresses).create(any());
        verify(services).create(any());
        verify(eventService, atLeastOnce()).publish(any());
        final List<MachineStatusEvent> events = captureEvents();
        assertTrue(events.contains(newEvent(M1_NAME, STARTING)));
        throw rethrow;
    }
}
Also used : Arrays(java.util.Arrays) ServerStatus(org.eclipse.che.api.core.model.workspace.runtime.ServerStatus) KubernetesServerImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesServerImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CREATE_IN_CHE_INSTALLATION_NAMESPACE(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations.CREATE_IN_CHE_INSTALLATION_NAMESPACE) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) KubernetesObjectUtil.putLabels(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putLabels) Mockito.doThrow(org.mockito.Mockito.doThrow) MockitoAnnotations(org.mockito.MockitoAnnotations) KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) Arrays.asList(java.util.Arrays.asList) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) WorkspaceExposureType(org.eclipse.che.workspace.infrastructure.kubernetes.server.WorkspaceExposureType) IngressBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressBackend) ServiceExposureStrategyProvider(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.ServiceExposureStrategyProvider) Mockito.doReturn(org.mockito.Mockito.doReturn) Assert.assertFalse(org.testng.Assert.assertFalse) KubernetesConfigsMaps(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesConfigsMaps) KubernetesDeployments(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesDeployments) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) Set(java.util.Set) KubernetesMachineCache(org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesMachineCache) IngressPathTransformInverter(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.IngressPathTransformInverter) SidecarToolingProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.SidecarToolingProvisioner) Mockito.doNothing(org.mockito.Mockito.doNothing) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Executors(java.util.concurrent.Executors) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) UnrecoverablePodEventListenerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.util.UnrecoverablePodEventListenerFactory) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) LogWatcher(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.LogWatcher) Mockito.mock(org.mockito.Mockito.mock) MachineStatus(org.eclipse.che.api.core.model.workspace.runtime.MachineStatus) InternalEnvironmentProvisioner(org.eclipse.che.api.workspace.server.spi.provision.InternalEnvironmentProvisioner) Mock(org.mockito.Mock) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) Mockito.spy(org.mockito.Mockito.spy) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) ArrayList(java.util.ArrayList) CheNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.CheNamespace) ServersChecker(org.eclipse.che.api.workspace.server.hc.ServersChecker) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace) Answer(org.mockito.stubbing.Answer) Stream.concat(java.util.stream.Stream.concat) ProbeScheduler(org.eclipse.che.api.workspace.server.hc.probe.ProbeScheduler) LogWatchTimeouts(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.LogWatchTimeouts) KubernetesSecrets(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesSecrets) Pod(io.fabric8.kubernetes.api.model.Pod) MachineStatusEvent(org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent) KubernetesIngresses(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesIngresses) Mockito.times(org.mockito.Mockito.times) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) Mockito.never(org.mockito.Mockito.never) KubernetesRuntimeStateCache(org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesRuntimeStateCache) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) DEBUG_WORKSPACE_START_LOG_LIMIT_BYTES(org.eclipse.che.api.workspace.shared.Constants.DEBUG_WORKSPACE_START_LOG_LIMIT_BYTES) PodEvent(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.event.PodEvent) ServersCheckerFactory(org.eclipse.che.api.workspace.server.hc.ServersCheckerFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Date(java.util.Date) DtoConverter(org.eclipse.che.api.workspace.server.DtoConverter) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServiceBackendPort(io.fabric8.kubernetes.api.model.networking.v1.ServiceBackendPort) KubernetesPreviewUrlCommandProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.KubernetesPreviewUrlCommandProvisioner) Collectors.toMap(java.util.stream.Collectors.toMap) IngressRule(io.fabric8.kubernetes.api.model.networking.v1.IngressRule) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) KubernetesServices(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesServices) PodEvents(org.eclipse.che.workspace.infrastructure.kubernetes.util.PodEvents) ParseException(java.text.ParseException) StateException(org.eclipse.che.api.workspace.server.spi.StateException) KubernetesObjectUtil.putAnnotations(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil.putAnnotations) EventService(org.eclipse.che.api.core.notification.EventService) Command(org.eclipse.che.api.core.model.workspace.config.Command) PodLogHandler(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.log.PodLogHandler) WorkspaceProbes(org.eclipse.che.api.workspace.server.hc.probe.WorkspaceProbes) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) KubernetesServerResolverFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.KubernetesServerResolverFactory) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) MULTI_HOST_STRATEGY(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.MultiHostExternalServiceExposureStrategy.MULTI_HOST_STRATEGY) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) URLRewriter(org.eclipse.che.api.workspace.server.URLRewriter) BeforeMethod(org.testng.annotations.BeforeMethod) STARTING(org.eclipse.che.api.core.model.workspace.runtime.MachineStatus.STARTING) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) KubernetesSharedPool(org.eclipse.che.workspace.infrastructure.kubernetes.util.KubernetesSharedPool) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) List(java.util.List) WorkspaceVolumesStrategy(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.WorkspaceVolumesStrategy) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) IngressServiceBackend(io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend) Ingress(io.fabric8.kubernetes.api.model.networking.v1.Ingress) Entry(java.util.Map.Entry) KubernetesRuntimeCommandImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeCommandImpl) Secret(io.fabric8.kubernetes.api.model.Secret) Optional(java.util.Optional) WorkspaceProbesFactory(org.eclipse.che.api.workspace.server.hc.probe.WorkspaceProbesFactory) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) NoopExecutorServiceWrapper(org.eclipse.che.commons.observability.NoopExecutorServiceWrapper) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) Container(io.fabric8.kubernetes.api.model.Container) DataProvider(org.testng.annotations.DataProvider) DEBUG_WORKSPACE_START(org.eclipse.che.api.workspace.shared.Constants.DEBUG_WORKSPACE_START) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ServerResolver(org.eclipse.che.workspace.infrastructure.kubernetes.server.resolver.ServerResolver) Captor(org.mockito.Captor) HashSet(java.util.HashSet) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) IngressSpec(io.fabric8.kubernetes.api.model.networking.v1.IngressSpec) Collections.singletonMap(java.util.Collections.singletonMap) Service(io.fabric8.kubernetes.api.model.Service) RUNNING(org.eclipse.che.api.core.model.workspace.runtime.MachineStatus.RUNNING) LinkedList(java.util.LinkedList) RuntimeEventsPublisher(org.eclipse.che.workspace.infrastructure.kubernetes.util.RuntimeEventsPublisher) Collections.emptyMap(java.util.Collections.emptyMap) MachineId(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl.MachineId) Answers(org.mockito.Answers) InOrder(org.mockito.InOrder) Tracer(io.opentracing.Tracer) RuntimeLogEvent(org.eclipse.che.api.workspace.shared.dto.event.RuntimeLogEvent) IntOrStringBuilder(io.fabric8.kubernetes.api.model.IntOrStringBuilder) Assert.fail(org.testng.Assert.fail) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) SecretAsContainerResourceProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.secret.SecretAsContainerResourceProvisioner) Mockito.when(org.mockito.Mockito.when) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) CHE_ORIGINAL_NAME_LABEL(org.eclipse.che.workspace.infrastructure.kubernetes.Constants.CHE_ORIGINAL_NAME_LABEL) Assert.assertTrue(org.testng.Assert.assertTrue) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) Collectors.toList(java.util.stream.Collectors.toList) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) ParseException(java.text.ParseException) StateException(org.eclipse.che.api.workspace.server.spi.StateException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Test(org.testng.annotations.Test)

Example 4 with MachineStatusEvent

use of org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent in project che-server by eclipse-che.

the class KubernetesInternalRuntimeTest method verifyOrderedEventsChains.

private void verifyOrderedEventsChains(MachineStatusEvent[]... eventsArrays) {
    Map<String, LinkedList<MachineStatusEvent>> machine2Events = new HashMap<>();
    List<MachineStatusEvent> machineStatusEvents = captureEvents();
    for (MachineStatusEvent event : machineStatusEvents) {
        final String machineName = event.getMachineName();
        machine2Events.computeIfPresent(machineName, (mName, events) -> {
            events.add(event);
            return events;
        });
        machine2Events.computeIfAbsent(machineName, mName -> {
            final LinkedList<MachineStatusEvent> events = new LinkedList<>();
            events.add(event);
            return events;
        });
    }
    for (MachineStatusEvent[] expected : eventsArrays) {
        final MachineStatusEvent machineStatusEvent = expected[0];
        final MachineStatusEvent[] actual = machine2Events.remove(machineStatusEvent.getMachineName()).toArray(new MachineStatusEvent[expected.length]);
        assertEquals(actual, expected);
    }
    assertTrue(machine2Events.isEmpty(), "No more events expected");
}
Also used : MachineStatusEvent(org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedList(java.util.LinkedList)

Example 5 with MachineStatusEvent

use of org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent in project che-server by eclipse-che.

the class OpenShiftInternalRuntimeTest method verifyEventsOrder.

private void verifyEventsOrder(MachineStatusEvent... expectedEvents) {
    final Iterator<MachineStatusEvent> actualEvents = captureEvents().iterator();
    for (MachineStatusEvent expected : expectedEvents) {
        if (!actualEvents.hasNext()) {
            fail("It is expected to receive machine status events");
        }
        final MachineStatusEvent actual = actualEvents.next();
        assertEquals(actual, expected);
    }
    if (actualEvents.hasNext()) {
        fail("No more events expected");
    }
}
Also used : MachineStatusEvent(org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent)

Aggregations

MachineStatusEvent (org.eclipse.che.api.workspace.shared.dto.event.MachineStatusEvent)6 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)4 HashMap (java.util.HashMap)4 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 Container (io.fabric8.kubernetes.api.model.Container)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 IntOrStringBuilder (io.fabric8.kubernetes.api.model.IntOrStringBuilder)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 Service (io.fabric8.kubernetes.api.model.Service)2 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)2 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)2