Skip to content

Commit

Permalink
Modify elastic agent extension v5 capabilites (gocd#5937)
Browse files Browse the repository at this point in the history
* Modify 'supports_status_report' to 'supports_plugin_status_report'.
* Introduce 'supports_cluster_status_report' in v5 extension.
* 'supports_agent_status_report' remains unchanged.
  • Loading branch information
GaneshSPatil committed Mar 28, 2019
1 parent 2491750 commit 46882d8
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class CapabilitiesConverterV5 implements DataConverter<Capabilities, CapabilitiesDTO> {
@Override
public Capabilities fromDTO(CapabilitiesDTO capabilitiesDTO) {
return new Capabilities(capabilitiesDTO.supportsStatusReport(), capabilitiesDTO.supportsAgentStatusReport());
return new Capabilities(capabilitiesDTO.supportsPluginStatusReport(), capabilitiesDTO.supportsClusterStatusReport(), capabilitiesDTO.supportsAgentStatusReport());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,46 @@
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.Objects;

class CapabilitiesDTO {
private static final Gson GSON = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
@Expose
@SerializedName("supports_status_report")
@SerializedName("supports_plugin_status_report")
private boolean supportsStatusReport;

@Expose
@SerializedName("supports_cluster_status_report")
private boolean supportsClusterStatusReport;

@Expose
@SerializedName("supports_agent_status_report")
private boolean supportsAgentStatusReport;

public boolean supportsStatusReport() {
public boolean supportsPluginStatusReport() {
return supportsStatusReport;
}

public boolean supportsClusterStatusReport() {
return supportsClusterStatusReport;
}

public boolean supportsAgentStatusReport() {
return supportsAgentStatusReport;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CapabilitiesDTO)) return false;

if (o == null || getClass() != o.getClass()) return false;
CapabilitiesDTO that = (CapabilitiesDTO) o;

if (supportsStatusReport != that.supportsStatusReport) return false;
return supportsAgentStatusReport == that.supportsAgentStatusReport;
return supportsStatusReport == that.supportsStatusReport &&
supportsClusterStatusReport == that.supportsClusterStatusReport &&
supportsAgentStatusReport == that.supportsAgentStatusReport;
}

@Override
public int hashCode() {
int result = (supportsStatusReport ? 1 : 0);
result = 31 * result + (supportsAgentStatusReport ? 1 : 0);
return result;
return Objects.hash(supportsStatusReport, supportsClusterStatusReport, supportsAgentStatusReport);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
import static com.thoughtworks.go.plugin.domain.common.PluginConstants.ELASTIC_AGENT_EXTENSION;
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
Expand Down Expand Up @@ -97,7 +96,8 @@ public void shouldGetCapabilitiesOfAPlugin() {

final Capabilities capabilities = extensionV4.getCapabilities(PLUGIN_ID);

assertTrue(capabilities.supportsStatusReport());
assertTrue(capabilities.supportsPluginStatusReport());
assertFalse(capabilities.supportsClusterStatusReport());
assertTrue(capabilities.supportsAgentStatusReport());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@ public void shouldGetPluginIcon() {

@Test
public void shouldGetCapabilitiesOfAPlugin() {
final String responseBody = "{\"supports_status_report\":\"true\", \"supports_agent_status_report\":\"true\"}";
final String responseBody = "{" +
" \"supports_plugin_status_report\":\"true\", " +
" \"supports_cluster_status_report\":\"true\", " +
" \"supports_agent_status_report\":\"true\"" +
"}";
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));

final Capabilities capabilities = extensionV5.getCapabilities(PLUGIN_ID);

assertTrue(capabilities.supportsStatusReport());
assertTrue(capabilities.supportsPluginStatusReport());
assertTrue(capabilities.supportsClusterStatusReport());
assertTrue(capabilities.supportsAgentStatusReport());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ public void setUp() throws Exception {
public void fromDTO_shouldConvertToCapabilitiesFromCapabilitiesDTO() {
when(capabilitiesDTO.supportsStatusReport()).thenReturn(false);
when(capabilitiesDTO.supportsAgentStatusReport()).thenReturn(false);
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsStatusReport());
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsPluginStatusReport());
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsAgentStatusReport());

when(capabilitiesDTO.supportsStatusReport()).thenReturn(true);
when(capabilitiesDTO.supportsAgentStatusReport()).thenReturn(true);
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsStatusReport());
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsPluginStatusReport());
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsAgentStatusReport());

when(capabilitiesDTO.supportsStatusReport()).thenReturn(false);
when(capabilitiesDTO.supportsAgentStatusReport()).thenReturn(true);
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsStatusReport());
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsPluginStatusReport());
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsAgentStatusReport());

when(capabilitiesDTO.supportsStatusReport()).thenReturn(true);
when(capabilitiesDTO.supportsAgentStatusReport()).thenReturn(false);
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsStatusReport());
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsPluginStatusReport());
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsAgentStatusReport());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void shouldGetCapabilitiesFromResponseBody() {

Capabilities capabilities = new ElasticAgentExtensionConverterV4().getCapabilitiesFromResponseBody(responseBody);

assertTrue(capabilities.supportsStatusReport());
assertTrue(capabilities.supportsPluginStatusReport());
assertTrue(capabilities.supportsAgentStatusReport());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ public void setUp() throws Exception {

@Test
public void fromDTO_shouldConvertToCapabilitiesFromCapabilitiesDTO() {
when(capabilitiesDTO.supportsStatusReport()).thenReturn(false);
when(capabilitiesDTO.supportsPluginStatusReport()).thenReturn(false);
when(capabilitiesDTO.supportsAgentStatusReport()).thenReturn(false);
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsStatusReport());
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsPluginStatusReport());
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsAgentStatusReport());

when(capabilitiesDTO.supportsStatusReport()).thenReturn(true);
when(capabilitiesDTO.supportsPluginStatusReport()).thenReturn(true);
when(capabilitiesDTO.supportsAgentStatusReport()).thenReturn(true);
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsStatusReport());
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsPluginStatusReport());
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsAgentStatusReport());

when(capabilitiesDTO.supportsStatusReport()).thenReturn(false);
when(capabilitiesDTO.supportsPluginStatusReport()).thenReturn(false);
when(capabilitiesDTO.supportsAgentStatusReport()).thenReturn(true);
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsStatusReport());
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsPluginStatusReport());
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsAgentStatusReport());

when(capabilitiesDTO.supportsStatusReport()).thenReturn(true);
when(capabilitiesDTO.supportsPluginStatusReport()).thenReturn(true);
when(capabilitiesDTO.supportsAgentStatusReport()).thenReturn(false);
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsStatusReport());
assertTrue(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsPluginStatusReport());
assertFalse(capabilitiesConverter.fromDTO(capabilitiesDTO).supportsAgentStatusReport());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,16 @@ public void shouldGetStatusReportViewFromResponseBody() {

@Test
public void shouldGetCapabilitiesFromResponseBody() {
String responseBody = "{\"supports_status_report\":\"true\",\"supports_agent_status_report\":\"true\"}";
String responseBody = "{" +
" \"supports_plugin_status_report\":\"true\"," +
" \"supports_cluster_status_report\":\"true\"," +
" \"supports_agent_status_report\":\"true\"" +
"}";

Capabilities capabilities = new ElasticAgentExtensionConverterV5().getCapabilitiesFromResponseBody(responseBody);

assertTrue(capabilities.supportsStatusReport());
assertTrue(capabilities.supportsPluginStatusReport());
assertTrue(capabilities.supportsClusterStatusReport());
assertTrue(capabilities.supportsAgentStatusReport());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,31 @@
package com.thoughtworks.go.plugin.domain.elastic;

public class Capabilities {
private boolean supportsStatusReport;
private boolean supportsPluginStatusReport;
private boolean supportsClusterStatusReport;
private boolean supportsAgentStatusReport;

public Capabilities(boolean supportsStatusReport) {
this.supportsStatusReport = supportsStatusReport;
public Capabilities(boolean supportsPluginStatusReport) {
this.supportsPluginStatusReport = supportsPluginStatusReport;
}

public Capabilities(boolean supportsStatusReport, boolean supportsAgentStatusReport) {
this.supportsStatusReport = supportsStatusReport;
public Capabilities(boolean supportsPluginStatusReport, boolean supportsAgentStatusReport) {
this.supportsPluginStatusReport = supportsPluginStatusReport;
this.supportsAgentStatusReport = supportsAgentStatusReport;
}

public boolean supportsStatusReport() {
return supportsStatusReport;
public Capabilities(boolean supportsPluginStatusReport, boolean supportsClusterStatusReport, boolean supportsAgentStatusReport) {
this.supportsPluginStatusReport = supportsPluginStatusReport;
this.supportsClusterStatusReport = supportsClusterStatusReport;
this.supportsAgentStatusReport = supportsAgentStatusReport;
}

public boolean supportsPluginStatusReport() {
return supportsPluginStatusReport;
}

public boolean supportsClusterStatusReport() {
return supportsClusterStatusReport;
}

public boolean supportsAgentStatusReport() {
Expand All @@ -44,12 +55,12 @@ public boolean equals(Object o) {

Capabilities that = (Capabilities) o;

return supportsStatusReport == that.supportsStatusReport;
return supportsPluginStatusReport == that.supportsPluginStatusReport;

}

@Override
public int hashCode() {
return (supportsStatusReport ? 1 : 0);
return (supportsPluginStatusReport ? 1 : 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Capabilities getCapabilities() {
}

public boolean supportsStatusReport() {
return this.capabilities != null ? this.capabilities.supportsStatusReport() : false;
return this.capabilities != null ? this.capabilities.supportsPluginStatusReport() : false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public boolean shouldAssignWork(ElasticAgentMetadata metadata, String environmen

public String getPluginStatusReport(String pluginId) {
final ElasticAgentPluginInfo pluginInfo = elasticAgentMetadataStore.getPluginInfo(pluginId);
if (pluginInfo.getCapabilities().supportsStatusReport()) {
if (pluginInfo.getCapabilities().supportsPluginStatusReport()) {
return elasticAgentPluginRegistry.getPluginStatusReport(pluginId);
}

Expand Down

0 comments on commit 46882d8

Please sign in to comment.