Skip to content

Commit

Permalink
Pass along all cluster-profiles belonging to that plugin as part of p…
Browse files Browse the repository at this point in the history
…lugin status report (gocd#5538)

* Do not send all available cluster profiles from different plugins.
  • Loading branch information
GaneshSPatil committed Apr 16, 2019
1 parent 0580a33 commit 1d2f3ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.common.collect.Sets;
import com.thoughtworks.go.config.elastic.ClusterProfile;
import com.thoughtworks.go.config.elastic.ClusterProfiles;
import com.thoughtworks.go.config.elastic.ElasticProfile;
import com.thoughtworks.go.domain.AgentInstance;
import com.thoughtworks.go.domain.JobIdentifier;
Expand Down Expand Up @@ -206,7 +205,7 @@ public boolean shouldAssignWork(ElasticAgentMetadata metadata, String environmen
public String getPluginStatusReport(String pluginId) {
final ElasticAgentPluginInfo pluginInfo = elasticAgentMetadataStore.getPluginInfo(pluginId);
if (pluginInfo.getCapabilities().supportsPluginStatusReport()) {
List<Map<String, String>> clusterProfiles = clusterProfilesService.getPluginProfiles().stream().map(profile -> profile.getConfigurationAsMap(true)).collect(Collectors.toList());
List<Map<String, String>> clusterProfiles = clusterProfilesService.getPluginProfiles().findByPluginId(pluginId).stream().map(profile -> profile.getConfigurationAsMap(true)).collect(Collectors.toList());
return elasticAgentPluginRegistry.getPluginStatusReport(pluginId, clusterProfiles);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.thoughtworks.go.config.elastic.ClusterProfiles;
import com.thoughtworks.go.config.elastic.ElasticProfile;
import com.thoughtworks.go.domain.*;
import com.thoughtworks.go.domain.config.ConfigurationKey;
import com.thoughtworks.go.domain.config.ConfigurationProperty;
import com.thoughtworks.go.domain.config.ConfigurationValue;
import com.thoughtworks.go.helper.AgentInstanceMother;
import com.thoughtworks.go.helper.GoConfigMother;
import com.thoughtworks.go.helper.JobInstanceMother;
Expand Down Expand Up @@ -309,6 +312,26 @@ void shouldGetAPluginStatusReportWhenPluginSupportsStatusReport() {
assertThat(pluginStatusReport).isEqualTo("<div>This is a plugin status report snippet.</div>");
}

@Test
void shouldPassAlongAllClusterProfilesBelongingToThePluginWhileGettingPluginStatusReport() {
final Capabilities capabilities = new Capabilities(true);
final GoPluginDescriptor descriptor = new GoPluginDescriptor("cd.go.example.plugin", null, null, null, null, false);
elasticAgentMetadataStore.setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, null, capabilities));

ClusterProfiles allClusterProfiles = new ClusterProfiles();
ClusterProfile cluster1 = new ClusterProfile("id1", "cd.go.example.plugin", new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1")));
ClusterProfile cluster2 = new ClusterProfile("id2", "cd.go.example.plugin2", new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2")));
allClusterProfiles.add(cluster1);
allClusterProfiles.add(cluster2);

when(clusterProfilesService.getPluginProfiles()).thenReturn(allClusterProfiles);
when(registry.getPluginStatusReport("cd.go.example.plugin", Arrays.asList(cluster1.getConfigurationAsMap(true)))).thenReturn("<div>This is a plugin status report snippet.</div>");

final String pluginStatusReport = service.getPluginStatusReport("cd.go.example.plugin");

assertThat(pluginStatusReport).isEqualTo("<div>This is a plugin status report snippet.</div>");
}

@Test
void shouldErrorOutWhenPluginDoesNotSupportStatusReport() {
final Capabilities capabilities = new Capabilities(false);
Expand Down

0 comments on commit 1d2f3ac

Please sign in to comment.