Skip to content

Commit

Permalink
ServerInfo request processor does not delegate serialization to exten…
Browse files Browse the repository at this point in the history
…sions #5653
  • Loading branch information
maheshp committed Jan 7, 2019
1 parent e264530 commit 143054f
Show file tree
Hide file tree
Showing 30 changed files with 91 additions and 301 deletions.
Expand Up @@ -115,9 +115,4 @@ protected List<String> goSupportedVersions() {
private String getCurrentStaticAssetsPath(String pluginId) {
return AnalyticsMetadataStore.instance().getPluginInfo(pluginId).getStaticAssetsPath();
}

@Override
public String serverInfoJSON(String pluginId, String serverId, String siteUrl, String secureSiteUrl) {
throw new UnsupportedOperationException("Fetch Server Info is not supported by Analytics endpoint.");
}
}
Expand Up @@ -213,9 +213,4 @@ public List<FetchArtifactEnvironmentVariable> onSuccess(String responseBody, Str
public String pluginSettingsJSON(String pluginId, Map<String, String> pluginSettings) {
throw new UnsupportedOperationException("Fetch Plugin Settings is not supported by Artifact endpoint.");
}

@Override
public String serverInfoJSON(String pluginId, String serverId, String siteUrl, String secureSiteUrl) {
throw new UnsupportedOperationException("Fetch Server Info is not supported by Artifact endpoint.");
}
}
Expand Up @@ -23,8 +23,6 @@
import com.thoughtworks.go.plugin.access.authorization.models.AuthenticationResponse;
import com.thoughtworks.go.plugin.access.authorization.models.User;
import com.thoughtworks.go.plugin.access.common.AbstractExtension;
import com.thoughtworks.go.plugin.access.common.serverinfo.MessageHandlerForServerInfoRequestProcessor;
import com.thoughtworks.go.plugin.access.common.serverinfo.MessageHandlerForServerInfoRequestProcessor1_0;
import com.thoughtworks.go.plugin.access.common.settings.PluginSettingsJsonMessageHandler;
import com.thoughtworks.go.plugin.access.common.settings.PluginSettingsJsonMessageHandler1_0;
import com.thoughtworks.go.plugin.api.response.validation.ValidationResult;
Expand All @@ -49,15 +47,13 @@ public class AuthorizationExtension extends AbstractExtension {
@Autowired
public AuthorizationExtension(PluginManager pluginManager) {
super(pluginManager, new PluginRequestHelper(pluginManager, SUPPORTED_VERSIONS, AUTHORIZATION_EXTENSION), AUTHORIZATION_EXTENSION);
addHandler(AuthorizationMessageConverterV1.VERSION, new PluginSettingsJsonMessageHandler1_0(), new AuthorizationMessageConverterV1(),
new MessageHandlerForServerInfoRequestProcessor1_0());
addHandler(AuthorizationMessageConverterV1.VERSION, new PluginSettingsJsonMessageHandler1_0(), new AuthorizationMessageConverterV1()
);
}

private void addHandler(String version, PluginSettingsJsonMessageHandler messageHandler, AuthorizationMessageConverterV1 extensionHandler,
MessageHandlerForServerInfoRequestProcessor messageHandlerForServerInfoRequestProcessor) {
private void addHandler(String version, PluginSettingsJsonMessageHandler messageHandler, AuthorizationMessageConverterV1 extensionHandler) {
registerHandler(version, messageHandler);
messageHandlerMap.put(version, extensionHandler);
registerMessageHandlerForServerInfoRequestProcessor(version, messageHandlerForServerInfoRequestProcessor);
}

public com.thoughtworks.go.plugin.domain.authorization.Capabilities getCapabilities(String pluginId) {
Expand Down
Expand Up @@ -18,7 +18,6 @@

import com.thoughtworks.go.plugin.access.DefaultPluginInteractionCallback;
import com.thoughtworks.go.plugin.access.PluginRequestHelper;
import com.thoughtworks.go.plugin.access.common.serverinfo.MessageHandlerForServerInfoRequestProcessor;
import com.thoughtworks.go.plugin.access.common.settings.*;
import com.thoughtworks.go.plugin.api.response.validation.ValidationResult;
import com.thoughtworks.go.plugin.infra.PluginManager;
Expand All @@ -33,7 +32,6 @@ public abstract class AbstractExtension implements GoPluginExtension {
private final String extensionName;
protected Map<String, PluginSettingsJsonMessageHandler> pluginSettingsMessageHandlerMap = new HashMap<>();
private Map<String, MessageHandlerForPluginSettingsRequestProcessor> messageHandlersForPluginSettingsRequestProcessor = new HashMap<>();
private Map<String, MessageHandlerForServerInfoRequestProcessor> messageHandlersForServerInfoRequestProcessor = new HashMap<>();

protected AbstractExtension(PluginManager pluginManager, PluginRequestHelper pluginRequestHelper, String extensionName) {
this.pluginManager = pluginManager;
Expand Down Expand Up @@ -93,12 +91,6 @@ public String pluginSettingsJSON(String pluginId, Map<String, String> pluginSett
return messageHandlerForPluginSettingsRequestProcessor(resolvedExtensionVersion).pluginSettingsToJSON(pluginSettings);
}

@Override
public String serverInfoJSON(String pluginId, String serverId, String siteUrl, String secureSiteUrl) {
String resolvedExtensionVersion = pluginManager.resolveExtensionVersion(pluginId, extensionName, goSupportedVersions());
return messageHandlerForServerInfoRequestProcessor(resolvedExtensionVersion).serverInfoToJSON(serverId, siteUrl, secureSiteUrl);
}

@Override
public ValidationResult validatePluginSettings(String pluginId, final PluginSettingsConfiguration configuration) {
return pluginRequestHelper.submitRequest(pluginId, PluginSettingsConstants.REQUEST_VALIDATE_PLUGIN_SETTINGS, new DefaultPluginInteractionCallback<ValidationResult>() {
Expand All @@ -118,18 +110,10 @@ protected void registerMessageHandlerForPluginSettingsRequestProcessor(String ap
messageHandlersForPluginSettingsRequestProcessor.put(apiVersion, handler);
}

protected void registerMessageHandlerForServerInfoRequestProcessor(String apiVersion, MessageHandlerForServerInfoRequestProcessor handler) {
messageHandlersForServerInfoRequestProcessor.put(apiVersion, handler);
}

protected MessageHandlerForPluginSettingsRequestProcessor messageHandlerForPluginSettingsRequestProcessor(String pluginVersion) {
return messageHandlersForPluginSettingsRequestProcessor.get(pluginVersion);
}

protected MessageHandlerForServerInfoRequestProcessor messageHandlerForServerInfoRequestProcessor(String pluginVersion) {
return messageHandlersForServerInfoRequestProcessor.get(pluginVersion);
}

protected abstract List<String> goSupportedVersions();

public void registerHandler(String version, PluginSettingsJsonMessageHandler handler) {
Expand Down
Expand Up @@ -35,6 +35,4 @@ public interface GoPluginExtension {
void notifyPluginSettingsChange(String pluginId, Map<String, String> pluginSettings);

String pluginSettingsJSON(String pluginId, Map<String, String> pluginSettings);

String serverInfoJSON(String pluginId, String serverId, String siteUrl, String secureSiteUrl);
}
Expand Up @@ -150,9 +150,4 @@ public boolean isConfigRepoPlugin(String pluginId) {
protected List<String> goSupportedVersions() {
return goSupportedVersions;
}

@Override
public String serverInfoJSON(String pluginId, String serverId, String siteUrl, String secureSiteUrl) {
throw new UnsupportedOperationException("Fetch Server Info is not supported by ConfigRepo endpoint.");
}
}
Expand Up @@ -19,8 +19,6 @@
import com.thoughtworks.go.domain.JobIdentifier;
import com.thoughtworks.go.plugin.access.PluginRequestHelper;
import com.thoughtworks.go.plugin.access.common.AbstractExtension;
import com.thoughtworks.go.plugin.access.common.serverinfo.MessageHandlerForServerInfoRequestProcessor;
import com.thoughtworks.go.plugin.access.common.serverinfo.MessageHandlerForServerInfoRequestProcessor1_0;
import com.thoughtworks.go.plugin.access.common.settings.MessageHandlerForPluginSettingsRequestProcessor;
import com.thoughtworks.go.plugin.access.common.settings.MessageHandlerForPluginSettingsRequestProcessor1_0;
import com.thoughtworks.go.plugin.access.common.settings.PluginSettingsJsonMessageHandler1_0;
Expand Down Expand Up @@ -56,16 +54,13 @@ public ElasticAgentExtension(PluginManager pluginManager) {
registerHandler(ElasticAgentExtensionV4.VERSION, new PluginSettingsJsonMessageHandler1_0());

final MessageHandlerForPluginSettingsRequestProcessor1_0 pluginSettingsRequestProcessor = new MessageHandlerForPluginSettingsRequestProcessor1_0();
final MessageHandlerForServerInfoRequestProcessor1_0 serverInfoRequestProcessor = new MessageHandlerForServerInfoRequestProcessor1_0();

registerProcessor(ElasticAgentExtensionV3.VERSION, pluginSettingsRequestProcessor, serverInfoRequestProcessor);
registerProcessor(ElasticAgentExtensionV4.VERSION, pluginSettingsRequestProcessor, serverInfoRequestProcessor);
registerProcessor(ElasticAgentExtensionV3.VERSION, pluginSettingsRequestProcessor);
registerProcessor(ElasticAgentExtensionV4.VERSION, pluginSettingsRequestProcessor);
}

private void registerProcessor(String version, MessageHandlerForPluginSettingsRequestProcessor pluginSettingsRequestProcessor,
MessageHandlerForServerInfoRequestProcessor serverInfoRequestProcessor) {
private void registerProcessor(String version, MessageHandlerForPluginSettingsRequestProcessor pluginSettingsRequestProcessor) {
registerMessageHandlerForPluginSettingsRequestProcessor(version, pluginSettingsRequestProcessor);
registerMessageHandlerForServerInfoRequestProcessor(version, serverInfoRequestProcessor);
}

public void createAgent(String pluginId, final String autoRegisterKey, final String environment, final Map<String, String> configuration, JobIdentifier jobIdentifier) {
Expand Down
Expand Up @@ -19,8 +19,6 @@
import com.thoughtworks.go.plugin.access.DefaultPluginInteractionCallback;
import com.thoughtworks.go.plugin.access.PluginRequestHelper;
import com.thoughtworks.go.plugin.access.common.AbstractExtension;
import com.thoughtworks.go.plugin.access.common.serverinfo.MessageHandlerForServerInfoRequestProcessor;
import com.thoughtworks.go.plugin.access.common.serverinfo.MessageHandlerForServerInfoRequestProcessor1_0;
import com.thoughtworks.go.plugin.access.common.settings.*;
import com.thoughtworks.go.plugin.access.notification.v1.JsonMessageHandler1_0;
import com.thoughtworks.go.plugin.access.notification.v2.JsonMessageHandler2_0;
Expand Down Expand Up @@ -55,25 +53,23 @@ public NotificationExtension(PluginManager pluginManager) {
super(pluginManager, new PluginRequestHelper(pluginManager, goSupportedVersions, NOTIFICATION_EXTENSION), NOTIFICATION_EXTENSION);

registerHandlers("1.0", new PluginSettingsJsonMessageHandler1_0(), new JsonMessageHandler1_0(),
new MessageHandlerForPluginSettingsRequestProcessor1_0(), new MessageHandlerForServerInfoRequestProcessor1_0());
new MessageHandlerForPluginSettingsRequestProcessor1_0());

registerHandlers("2.0", new PluginSettingsJsonMessageHandler1_0(), new JsonMessageHandler2_0(),
new MessageHandlerForPluginSettingsRequestProcessor1_0(), new MessageHandlerForServerInfoRequestProcessor1_0());
new MessageHandlerForPluginSettingsRequestProcessor1_0());

registerHandlers("3.0", new PluginSettingsJsonMessageHandler2_0(), new JsonMessageHandler3_0(),
new MessageHandlerForPluginSettingsRequestProcessor1_0(), new MessageHandlerForServerInfoRequestProcessor1_0());
new MessageHandlerForPluginSettingsRequestProcessor1_0());

registerHandlers("4.0", new PluginSettingsJsonMessageHandler2_0(), new JsonMessageHandler4_0(),
new MessageHandlerForPluginSettingsRequestProcessor1_0(), new MessageHandlerForServerInfoRequestProcessor1_0());
new MessageHandlerForPluginSettingsRequestProcessor1_0());
}

private void registerHandlers(String version, PluginSettingsJsonMessageHandler pluginSettingsJsonMessageHandler, JsonMessageHandler jsonMessageHandler,
MessageHandlerForPluginSettingsRequestProcessor messageHandlerForPluginSettingsRequestProcessor,
MessageHandlerForServerInfoRequestProcessor messageHandlerForServerInfoRequestProcessor) {
MessageHandlerForPluginSettingsRequestProcessor messageHandlerForPluginSettingsRequestProcessor) {
registerHandler(version, pluginSettingsJsonMessageHandler);
messageHandlerMap.put(version, jsonMessageHandler);
registerMessageHandlerForPluginSettingsRequestProcessor(version, messageHandlerForPluginSettingsRequestProcessor);
registerMessageHandlerForServerInfoRequestProcessor(version, messageHandlerForServerInfoRequestProcessor);
}

public List<String> getNotificationsOfInterestFor(String pluginId) {
Expand Down
Expand Up @@ -173,9 +173,4 @@ JsonMessageHandler messageConverter(String resolvedExtensionVersion) {
protected List<String> goSupportedVersions() {
return goSupportedVersions;
}

@Override
public String serverInfoJSON(String pluginId, String serverId, String siteUrl, String secureSiteUrl) {
throw new UnsupportedOperationException("Fetch Server Info is not supported by PackageRepository endpoint.");
}
}
Expand Up @@ -78,9 +78,4 @@ public String pluginSettingsJSON(String pluginId, Map<String, String> pluginSett
protected List<String> goSupportedVersions() {
return supportedVersions;
}

@Override
public String serverInfoJSON(String pluginId, String serverId, String siteUrl, String secureSiteUrl) {
throw new UnsupportedOperationException("Fetch Server Info is not supported by Task endpoint.");
}
}
Expand Up @@ -161,9 +161,4 @@ Map<String, JsonMessageHandler> getMessageHandlerMap() {
protected List<String> goSupportedVersions() {
return goSupportedVersions;
}

@Override
public String serverInfoJSON(String pluginId, String serverId, String siteUrl, String secureSiteUrl) {
throw new UnsupportedOperationException("Fetch Server Info is not supported by SCM endpoint.");
}
}
Expand Up @@ -155,14 +155,6 @@ public void shouldSerializePluginSettingsToJSON() {
assertThat(pluginSettingsJSON, Is.is("{\"key1\":\"val1\",\"key2\":\"val2\"}"));
}

@Test
public void shouldNotExposeServerInfo() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("Fetch Server Info is not supported by Analytics endpoint.");

analyticsExtension.serverInfoJSON("plugin_id", "server_id", "site_url", "secure_site_url");
}

private void assertRequest(GoPluginApiRequest goPluginApiRequest, String extensionName, String version, String requestName, String requestBody) {
assertThat(goPluginApiRequest.extension(), Is.is(extensionName));
assertThat(goPluginApiRequest.extensionVersion(), Is.is(version));
Expand Down
Expand Up @@ -309,14 +309,6 @@ public void shouldNotExposePluginSettings() {
artifactExtension.pluginSettingsJSON("plugin_id", Collections.EMPTY_MAP);
}

@Test
public void shouldNotExposeServerInfo() {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("Fetch Server Info is not supported by Artifact endpoint.");

artifactExtension.serverInfoJSON("plugin_id", "server_id", "site_url", "secure_site_url");
}

@Test
public void shouldGetCapabilities() {
when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success("{}"));
Expand Down
Expand Up @@ -335,17 +335,6 @@ public void shouldNotSupportFetchingPluginSettings() throws Exception {
authorizationExtension.pluginSettingsJSON("plugin_id", Collections.emptyMap());
}

@Test
public void shouldSerializeServerInfoToJSON() throws Exception {
String pluginId = "plugin_id";

when(pluginManager.resolveExtensionVersion(pluginId, AUTHORIZATION_EXTENSION, authorizationExtension.goSupportedVersions())).thenReturn("1.0");

String serverInfoJSON = authorizationExtension.serverInfoJSON(pluginId, "x12adf", "http://my.build.com", "https://my.build.com");

Assert.assertThat(serverInfoJSON, Is.is("{\"server_id\":\"x12adf\",\"site_url\":\"http://my.build.com\",\"secure_site_url\":\"https://my.build.com\"}"));
}

private void assertRequest(GoPluginApiRequest goPluginApiRequest, String extensionName, String version, String requestName, String requestBody) {
Assert.assertThat(goPluginApiRequest.extension(), Is.is(extensionName));
Assert.assertThat(goPluginApiRequest.extensionVersion(), Is.is(version));
Expand Down
Expand Up @@ -143,14 +143,6 @@ public void shouldSerializePluginSettingsToJSON() throws Exception {
assertThat(pluginSettingsJSON, CoreMatchers.is("{\"key1\":\"val1\",\"key2\":\"val2\"}"));
}

@Test
public void shouldNotExposeServerInfo() throws Exception {
thrown.expect(UnsupportedOperationException.class);
thrown.expectMessage("Fetch Server Info is not supported by ConfigRepo endpoint.");

extension.serverInfoJSON("plugin_id", "server_id", "site_url", "secure_site_url");
}

private void assertRequest(GoPluginApiRequest goPluginApiRequest, String extensionName, String version, String requestName, String requestBody) {
assertThat(goPluginApiRequest.extension(), is(extensionName));
assertThat(goPluginApiRequest.extensionVersion(), is(version));
Expand Down
Expand Up @@ -18,8 +18,6 @@

import com.thoughtworks.go.domain.JobIdentifier;
import com.thoughtworks.go.plugin.access.common.AbstractExtension;
import com.thoughtworks.go.plugin.access.common.serverinfo.MessageHandlerForServerInfoRequestProcessor;
import com.thoughtworks.go.plugin.access.common.serverinfo.MessageHandlerForServerInfoRequestProcessor1_0;
import com.thoughtworks.go.plugin.access.common.settings.MessageHandlerForPluginSettingsRequestProcessor;
import com.thoughtworks.go.plugin.access.common.settings.MessageHandlerForPluginSettingsRequestProcessor1_0;
import com.thoughtworks.go.plugin.api.request.GoPluginApiRequest;
Expand Down Expand Up @@ -55,7 +53,6 @@ public class ElasticAgentExtensionTest {
protected GoPluginDescriptor descriptor;
protected ElasticAgentExtension extension;


@Before
public void setUp() throws Exception {
pluginManager = mock(PluginManager.class);
Expand Down Expand Up @@ -108,14 +105,6 @@ public void shouldHaveMessageHandlerForPluginSettingsRequestProcessorForAllExten
instanceOf(MessageHandlerForPluginSettingsRequestProcessor1_0.class));
}

@Test
public void shouldHaveMessageHandlerForServerInfoRequestProcessorForAllExtensionVersions() {
final ElasticAgentExtensionExposingHandlers extension = new ElasticAgentExtensionExposingHandlers(pluginManager);

assertThat(extension.messageHandlerForServerInfoRequestProcessor("3.0"),
instanceOf(MessageHandlerForServerInfoRequestProcessor1_0.class));
}

@Test
public void shouldMakeJobCompletionCall() {
when(pluginManager.resolveExtensionVersion(PLUGIN_ID, ELASTIC_AGENT_EXTENSION, SUPPORTED_VERSIONS)).thenReturn("4.0");
Expand All @@ -139,11 +128,6 @@ public MessageHandlerForPluginSettingsRequestProcessor messageHandlerForPluginSe
return super.messageHandlerForPluginSettingsRequestProcessor(pluginVersion);
}

@Override
public MessageHandlerForServerInfoRequestProcessor messageHandlerForServerInfoRequestProcessor(String pluginVersion) {
return super.messageHandlerForServerInfoRequestProcessor(pluginVersion);
}

@Override
public VersionedElasticAgentExtension getVersionedElasticAgentExtension(String pluginId) {
return super.getVersionedElasticAgentExtension(pluginId);
Expand Down

0 comments on commit 143054f

Please sign in to comment.