Search in sources :

Example 6 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.

the class ClusterProfilesServiceTest method shouldFetchClustersDefinedAsPartOfElasticTag.

@Test
void shouldFetchClustersDefinedAsPartOfElasticTag() {
    ElasticConfig elasticConfig = new ElasticConfig();
    elasticConfig.setClusterProfiles(new ClusterProfiles(clusterProfile));
    when(goConfigService.getElasticConfig()).thenReturn(elasticConfig);
    PluginProfiles<ClusterProfile> actualClusterProfiles = clusterProfilesService.getPluginProfiles();
    assertThat(actualClusterProfiles).isEqualTo(elasticConfig.getClusterProfiles());
}
Also used : ElasticConfig(com.thoughtworks.go.config.elastic.ElasticConfig) ClusterProfiles(com.thoughtworks.go.config.elastic.ClusterProfiles) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 7 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.

the class ElasticAgentPluginServiceTest method shouldErrorOutWhenClusterProfileNotFound.

@Test
void shouldErrorOutWhenClusterProfileNotFound() {
    final Capabilities capabilities = new Capabilities(true, true, false);
    final GoPluginDescriptor descriptor = GoPluginDescriptor.builder().id("cd.go.example.plugin").build();
    elasticAgentMetadataStore.setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, null, capabilities));
    ClusterProfile clusterProfile = new ClusterProfile("cluster-profile-id", "cd.go.example.plugin");
    clusterProfile.addNewConfigurationWithValue("go-server-url", "server-url", false);
    PluginProfiles<ClusterProfile> clusterProfiles = new ClusterProfiles(clusterProfile);
    when(clusterProfilesService.getPluginProfiles()).thenReturn(clusterProfiles);
    final RecordNotFoundException exception = assertThrows(RecordNotFoundException.class, () -> service.getClusterStatusReport("cd.go.example.plugin", "test"));
    assertThat(exception.getMessage()).isEqualTo("Cluster profile with id: 'test' is not found.");
}
Also used : ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) Capabilities(com.thoughtworks.go.plugin.domain.elastic.Capabilities) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ClusterProfiles(com.thoughtworks.go.config.elastic.ClusterProfiles) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 8 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.

the class ElasticAgentPluginServiceTest method shouldGetAPluginAgentReportWhenPluginSupportsStatusReport.

@Test
void shouldGetAPluginAgentReportWhenPluginSupportsStatusReport() throws Exception {
    final Capabilities capabilities = new Capabilities(false, true);
    final GoPluginDescriptor descriptor = GoPluginDescriptor.builder().id("cd.go.example.plugin").build();
    elasticAgentMetadataStore.setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, null, capabilities));
    JobIdentifier jobIdentifier = mock(JobIdentifier.class);
    ClusterProfile clusterProfile = mock(ClusterProfile.class);
    JobPlan jobPlan = mock(JobPlan.class);
    when(jobIdentifier.getId()).thenReturn(2L);
    when(jobInstanceSqlMapDao.loadPlan(jobIdentifier.getId())).thenReturn(jobPlan);
    when(jobPlan.getClusterProfile()).thenReturn(clusterProfile);
    when(registry.getAgentStatusReport("cd.go.example.plugin", jobIdentifier, "some-id", clusterProfile.getConfigurationAsMap(true))).thenReturn("<div>This is a agent status report snippet.</div>");
    final String agentStatusReport = service.getAgentStatusReport("cd.go.example.plugin", jobIdentifier, "some-id");
    assertThat(agentStatusReport).isEqualTo("<div>This is a agent status report snippet.</div>");
}
Also used : ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) Capabilities(com.thoughtworks.go.plugin.domain.elastic.Capabilities) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 9 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.

the class ElasticAgentPluginServiceTest method shouldCreateAgentForNewlyAddedJobPlansOnly.

@Test
void shouldCreateAgentForNewlyAddedJobPlansOnly() {
    JobPlan plan1 = plan(1, "docker");
    JobPlan plan2 = plan(2, "docker");
    String ephemeralKey = randomUUID().toString();
    when(ephemeralAutoRegisterKeyService.autoRegisterKey()).thenReturn(ephemeralKey);
    when(goConfigService.elasticJobStarvationThreshold()).thenReturn(10000L);
    ClusterProfile clusterProfile = new ClusterProfile(plan1.getElasticProfile().getClusterProfileId(), plan1.getClusterProfile().getPluginId());
    ArgumentCaptor<CreateAgentMessage> createAgentMessageArgumentCaptor = ArgumentCaptor.forClass(CreateAgentMessage.class);
    ArgumentCaptor<Long> ttl = ArgumentCaptor.forClass(Long.class);
    when(environmentConfigService.envForPipeline("pipeline-2")).thenReturn("env-2");
    service.createAgentsFor(asList(plan1), asList(plan1, plan2));
    verify(createAgentQueue).post(createAgentMessageArgumentCaptor.capture(), ttl.capture());
    CreateAgentMessage createAgentMessage = createAgentMessageArgumentCaptor.getValue();
    assertThat(createAgentMessage.autoregisterKey()).isEqualTo(ephemeralKey);
    assertThat(createAgentMessage.pluginId()).isEqualTo(plan2.getClusterProfile().getPluginId());
    assertThat(createAgentMessage.configuration()).isEqualTo(plan2.getElasticProfile().getConfigurationAsMap(true));
    assertThat(createAgentMessage.environment()).isEqualTo("env-2");
    assertThat(createAgentMessage.jobIdentifier()).isEqualTo(plan2.getIdentifier());
}
Also used : CreateAgentMessage(com.thoughtworks.go.server.messaging.elasticagents.CreateAgentMessage) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 10 with ClusterProfile

use of com.thoughtworks.go.config.elastic.ClusterProfile in project gocd by gocd.

the class ClusterProfilesServiceIntegrationTest method shouldUpdateExistingClusterProfile.

@Test
public void shouldUpdateExistingClusterProfile() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    String clusterId = "cluster1";
    String pluginid = "pluginid";
    ClusterProfile clusterProfile = new ClusterProfile(clusterId, pluginid);
    ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("username"), new ConfigurationValue("view"));
    ClusterProfile newClusterProfile = new ClusterProfile(clusterId, pluginid, property);
    clusterProfilesService.create(clusterProfile, new Username("Bob"), new HttpLocalizedOperationResult());
    assertThat(clusterProfilesService.getPluginProfiles().size(), is(1));
    assertThat(clusterProfilesService.getPluginProfiles().find(clusterId), is(clusterProfile));
    clusterProfilesService.update(newClusterProfile, new Username("Bob"), result);
    assertThat(result.isSuccessful(), is(true));
    assertThat(clusterProfilesService.getPluginProfiles().size(), is(1));
    assertThat(clusterProfilesService.getPluginProfiles().find(clusterId), is(newClusterProfile));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Username(com.thoughtworks.go.server.domain.Username) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)69 Test (org.junit.jupiter.api.Test)39 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)32 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)14 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)12 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)10 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)10 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)10 ClusterProfiles (com.thoughtworks.go.config.elastic.ClusterProfiles)8 Username (com.thoughtworks.go.server.domain.Username)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ElasticConfig (com.thoughtworks.go.config.elastic.ElasticConfig)6 Capabilities (com.thoughtworks.go.plugin.domain.elastic.Capabilities)6 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)5 RecordNotFoundException (com.thoughtworks.go.config.exceptions.RecordNotFoundException)5 JobAgentMetadata (com.thoughtworks.go.domain.JobAgentMetadata)4 ElasticAgentInformation (com.thoughtworks.go.plugin.access.elastic.models.ElasticAgentInformation)4 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)4 GoCipher (com.thoughtworks.go.security.GoCipher)4