Skip to content

Commit

Permalink
Throw 'RecordNotFoundException' while generating cluster profile stat…
Browse files Browse the repository at this point in the history
…us report for non existent cluster profile
  • Loading branch information
imvirajp authored and GaneshSPatil committed Apr 22, 2019
1 parent 48a1b8b commit ccaba00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.Sets;
import com.thoughtworks.go.config.elastic.ClusterProfile;
import com.thoughtworks.go.config.elastic.ElasticProfile;
import com.thoughtworks.go.config.exceptions.RecordNotFoundException;
import com.thoughtworks.go.domain.AgentInstance;
import com.thoughtworks.go.domain.JobIdentifier;
import com.thoughtworks.go.domain.JobInstance;
Expand Down Expand Up @@ -231,6 +232,9 @@ public String getClusterStatusReport(String pluginId, String clusterProfileId) {
final ElasticAgentPluginInfo pluginInfo = elasticAgentMetadataStore.getPluginInfo(pluginId);
if (pluginInfo.getCapabilities().supportsClusterStatusReport()) {
ClusterProfile clusterProfile = clusterProfilesService.getPluginProfiles().findByPluginIdAndProfileId(pluginId, clusterProfileId);
if (clusterProfile == null) {
throw new RecordNotFoundException(String.format("Cluster profile with id: '%s' is not found.", clusterProfileId));
}
return elasticAgentPluginRegistry.getClusterStatusReport(pluginId, clusterProfile.getConfigurationAsMap(true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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.config.exceptions.RecordNotFoundException;
import com.thoughtworks.go.domain.*;
import com.thoughtworks.go.domain.config.ConfigurationKey;
import com.thoughtworks.go.domain.config.ConfigurationProperty;
Expand Down Expand Up @@ -422,6 +423,20 @@ void shouldErrorOutWhenPluginDoesNotClusterSupportStatusReport() {

}

@Test
void shouldErrorOutWhenClusterProfileNotFound() {
final Capabilities capabilities = new Capabilities(true, true, false);
final GoPluginDescriptor descriptor = new GoPluginDescriptor("cd.go.example.plugin", null, null, null, null, false);
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.");
}

@Nested
class JobCompleted {

Expand Down

0 comments on commit ccaba00

Please sign in to comment.