Search in sources :

Example 1 with PluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN in project che-server by eclipse-che.

the class BrokerEnvironmentFactoryTest method testMetadataBrokerSelfSignedCertificate.

@Test
public void testMetadataBrokerSelfSignedCertificate() throws Exception {
    when(certProvisioner.isConfigured()).thenReturn(true);
    when(certProvisioner.getCertPath()).thenReturn("/tmp/che/cacert");
    // given
    Collection<PluginFQN> pluginFQNs = singletonList(new PluginFQN(null, "id"));
    ArgumentCaptor<BrokersConfigs> captor = ArgumentCaptor.forClass(BrokersConfigs.class);
    // when
    factory.createForMetadataBroker(pluginFQNs, runtimeId, false);
    // then
    verify(factory).doCreate(captor.capture());
    BrokersConfigs brokersConfigs = captor.getValue();
    List<Container> containers = brokersConfigs.pods.values().stream().flatMap(p -> p.getSpec().getContainers().stream()).collect(Collectors.toList());
    assertEquals(containers.size(), 1);
    Container container = containers.get(0);
    assertEquals(container.getArgs().toArray(), new String[] { "--push-endpoint", PUSH_ENDPOINT, "--runtime-id", String.format("%s:%s:%s", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId()), "--cacert", "/tmp/che/cacert", "--registry-address", DEFAULT_REGISTRY, "--metas", "/broker-config/config.json" });
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Quantity(io.fabric8.kubernetes.api.model.Quantity) Listeners(org.testng.annotations.Listeners) Container(io.fabric8.kubernetes.api.model.Container) DataProvider(org.testng.annotations.DataProvider) Mock(org.mockito.Mock) Assert.assertEquals(org.testng.Assert.assertEquals) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test) MachineTokenEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.MachineTokenEnvVarProvider) Mockito.spy(org.mockito.Mockito.spy) Mockito.lenient(org.mockito.Mockito.lenient) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) URI(java.net.URI) Assert.assertFalse(org.testng.Assert.assertFalse) AgentAuthEnableEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.AgentAuthEnableEnvVarProvider) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) CertificateProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.CertificateProvisioner) Collection(java.util.Collection) BeforeMethod(org.testng.annotations.BeforeMethod) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Pair(org.eclipse.che.commons.lang.Pair) Mockito.verify(org.mockito.Mockito.verify) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) List(java.util.List) BrokersConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Assert.assertTrue(org.testng.Assert.assertTrue) TrustedCAProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.TrustedCAProvisioner) PluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN) Container(io.fabric8.kubernetes.api.model.Container) PluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN) BrokersConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs) Test(org.testng.annotations.Test)

Example 2 with PluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN in project che-server by eclipse-che.

the class BrokerEnvironmentFactoryTest method shouldNotIncludePluginsVolumeInMetadataBroker.

@Test
public void shouldNotIncludePluginsVolumeInMetadataBroker() throws Exception {
    // given
    Collection<PluginFQN> pluginFQNs = singletonList(new PluginFQN(null, "id"));
    ArgumentCaptor<BrokersConfigs> captor = ArgumentCaptor.forClass(BrokersConfigs.class);
    // when
    factory.createForMetadataBroker(pluginFQNs, runtimeId, false);
    // then
    verify(factory).doCreate(captor.capture());
    BrokersConfigs brokersConfigs = captor.getValue();
    InternalMachineConfig machine = brokersConfigs.machines.values().iterator().next();
    assertFalse(machine.getVolumes().containsKey(PLUGINS_VOLUME_NAME));
}
Also used : InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) PluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN) BrokersConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs) Test(org.testng.annotations.Test)

Example 3 with PluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN in project che-server by eclipse-che.

the class BrokerEnvironmentFactoryTest method testAddsMergeArgToMetadataBroker.

@Test
public void testAddsMergeArgToMetadataBroker() throws Exception {
    // given
    Collection<PluginFQN> pluginFQNs = singletonList(new PluginFQN(null, "id"));
    ArgumentCaptor<BrokersConfigs> captor = ArgumentCaptor.forClass(BrokersConfigs.class);
    // when
    factory.createForMetadataBroker(pluginFQNs, runtimeId, true);
    // then
    verify(factory).doCreate(captor.capture());
    BrokersConfigs brokersConfigs = captor.getValue();
    List<Container> containers = brokersConfigs.pods.values().stream().flatMap(p -> p.getSpec().getContainers().stream()).collect(Collectors.toList());
    assertEquals(containers.size(), 1);
    Container container = containers.get(0);
    assertTrue(container.getArgs().stream().anyMatch(e -> "--merge-plugins".equals(e)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Quantity(io.fabric8.kubernetes.api.model.Quantity) Listeners(org.testng.annotations.Listeners) Container(io.fabric8.kubernetes.api.model.Container) DataProvider(org.testng.annotations.DataProvider) Mock(org.mockito.Mock) Assert.assertEquals(org.testng.Assert.assertEquals) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test) MachineTokenEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.MachineTokenEnvVarProvider) Mockito.spy(org.mockito.Mockito.spy) Mockito.lenient(org.mockito.Mockito.lenient) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) URI(java.net.URI) Assert.assertFalse(org.testng.Assert.assertFalse) AgentAuthEnableEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.AgentAuthEnableEnvVarProvider) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) CertificateProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.CertificateProvisioner) Collection(java.util.Collection) BeforeMethod(org.testng.annotations.BeforeMethod) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Pair(org.eclipse.che.commons.lang.Pair) Mockito.verify(org.mockito.Mockito.verify) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) List(java.util.List) BrokersConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Assert.assertTrue(org.testng.Assert.assertTrue) TrustedCAProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.TrustedCAProvisioner) PluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN) Container(io.fabric8.kubernetes.api.model.Container) PluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN) BrokersConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs) Test(org.testng.annotations.Test)

Example 4 with PluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN in project che-server by eclipse-che.

the class BrokerEnvironmentFactoryTest method testArtifactsBrokerSelfSignedCertificate.

@Test
public void testArtifactsBrokerSelfSignedCertificate() throws Exception {
    when(certProvisioner.isConfigured()).thenReturn(true);
    when(certProvisioner.getCertPath()).thenReturn("/tmp/che/cacert");
    // given
    Collection<PluginFQN> pluginFQNs = singletonList(new PluginFQN(null, "id"));
    ArgumentCaptor<BrokersConfigs> captor = ArgumentCaptor.forClass(BrokersConfigs.class);
    // when
    factory.createForArtifactsBroker(pluginFQNs, runtimeId, false);
    // then
    verify(factory).doCreate(captor.capture());
    BrokersConfigs brokersConfigs = captor.getValue();
    List<Container> containers = brokersConfigs.pods.values().stream().flatMap(p -> p.getSpec().getContainers().stream()).collect(Collectors.toList());
    assertEquals(containers.size(), 1);
    Container container = containers.get(0);
    assertEquals(container.getArgs().toArray(), new String[] { "--push-endpoint", PUSH_ENDPOINT, "--runtime-id", String.format("%s:%s:%s", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId()), "--cacert", "/tmp/che/cacert", "--registry-address", DEFAULT_REGISTRY, "--metas", "/broker-config/config.json" });
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Quantity(io.fabric8.kubernetes.api.model.Quantity) Listeners(org.testng.annotations.Listeners) Container(io.fabric8.kubernetes.api.model.Container) DataProvider(org.testng.annotations.DataProvider) Mock(org.mockito.Mock) Assert.assertEquals(org.testng.Assert.assertEquals) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test) MachineTokenEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.MachineTokenEnvVarProvider) Mockito.spy(org.mockito.Mockito.spy) Mockito.lenient(org.mockito.Mockito.lenient) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) URI(java.net.URI) Assert.assertFalse(org.testng.Assert.assertFalse) AgentAuthEnableEnvVarProvider(org.eclipse.che.api.workspace.server.spi.provision.env.AgentAuthEnableEnvVarProvider) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) CertificateProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.CertificateProvisioner) Collection(java.util.Collection) BeforeMethod(org.testng.annotations.BeforeMethod) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Pair(org.eclipse.che.commons.lang.Pair) Mockito.verify(org.mockito.Mockito.verify) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) List(java.util.List) BrokersConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Assert.assertTrue(org.testng.Assert.assertTrue) TrustedCAProvisioner(org.eclipse.che.workspace.infrastructure.kubernetes.provision.TrustedCAProvisioner) PluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN) Container(io.fabric8.kubernetes.api.model.Container) PluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN) BrokersConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs) Test(org.testng.annotations.Test)

Example 5 with PluginFQN

use of org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN in project che-server by eclipse-che.

the class BrokerEnvironmentFactoryTest method shouldNameContainersAfterMetadataPluginBrokerImage.

@Test
public void shouldNameContainersAfterMetadataPluginBrokerImage() throws Exception {
    // given
    Collection<PluginFQN> pluginFQNs = singletonList(new PluginFQN(null, "id"));
    ArgumentCaptor<BrokersConfigs> captor = ArgumentCaptor.forClass(BrokersConfigs.class);
    // when
    factory.createForMetadataBroker(pluginFQNs, runtimeId, false);
    // then
    verify(factory).doCreate(captor.capture());
    BrokersConfigs brokersConfigs = captor.getValue();
    PodSpec brokerPodSpec = brokersConfigs.pods.values().iterator().next().getSpec();
    List<Container> containers = brokerPodSpec.getContainers();
    assertEquals(containers.size(), 1);
    assertEquals(containers.get(0).getName(), "metadata-image");
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) PluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN) BrokersConfigs(org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs) Test(org.testng.annotations.Test)

Aggregations

PluginFQN (org.eclipse.che.api.workspace.server.wsplugins.model.PluginFQN)28 BrokersConfigs (org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.brokerphases.BrokerEnvironmentFactory.BrokersConfigs)22 Test (org.testng.annotations.Test)22 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)14 Container (io.fabric8.kubernetes.api.model.Container)14 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)14 URI (java.net.URI)14 InternalMachineConfig (org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig)14 DataProvider (org.testng.annotations.DataProvider)12 ImmutableList (com.google.common.collect.ImmutableList)10 Quantity (io.fabric8.kubernetes.api.model.Quantity)10 Collection (java.util.Collection)10 Collections.singletonList (java.util.Collections.singletonList)10 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)10 AgentAuthEnableEnvVarProvider (org.eclipse.che.api.workspace.server.spi.provision.env.AgentAuthEnableEnvVarProvider)10 MachineTokenEnvVarProvider (org.eclipse.che.api.workspace.server.spi.provision.env.MachineTokenEnvVarProvider)10 Pair (org.eclipse.che.commons.lang.Pair)10 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)10