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());
}
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.");
}
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>");
}
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());
}
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));
}
Aggregations