com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest Java Examples
The following examples show how to use
com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PluginRequest.java From kubernetes-elastic-agents with Apache License 2.0 | 6 votes |
public void appendToConsoleLog(JobIdentifier jobIdentifier, String text) throws ServerRequestFailedException { Map<String, String> requestMap = new HashMap<>(); requestMap.put("pipelineName", jobIdentifier.getPipelineName()); requestMap.put("pipelineCounter", String.valueOf(jobIdentifier.getPipelineCounter())); requestMap.put("stageName", jobIdentifier.getStageName()); requestMap.put("stageCounter", jobIdentifier.getStageCounter()); requestMap.put("jobName", jobIdentifier.getJobName()); requestMap.put("text", text); DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_APPEND_TO_CONSOLE_LOG, CONSOLE_LOG_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(new GsonBuilder().create().toJson(requestMap)); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { LOG.error("Failed to append to console log for " + jobIdentifier.getRepresentation() + " with text: " + text); } }
Example #2
Source File: ConsoleLogRequestProcessorV2Test.java From gocd with Apache License 2.0 | 6 votes |
@Test void shouldRouteMessageToConsoleService() throws IOException, IllegalArtifactLocationException { Map<String, String> requestMap = new HashMap<>(); requestMap.put("pipeline_name", "p1"); requestMap.put("pipeline_counter", "1"); requestMap.put("stage_name", "s1"); requestMap.put("stage_counter", "2"); requestMap.put("job_name", "j1"); requestMap.put("text", "message1"); DefaultGoApiRequest goApiRequest = new DefaultGoApiRequest(APPEND_TO_CONSOLE_LOG, VERSION_2, null); goApiRequest.setRequestBody(new GsonBuilder().create().toJson(requestMap)); final ConsoleLogRequestProcessor processor = new ConsoleLogRequestProcessor(pluginRequestProcessorRegistry, consoleService); final GoApiResponse response = processor.process(pluginDescriptor, goApiRequest); assertThat(response.responseCode(), is(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE)); final JobIdentifier jobIdentifier = new JobIdentifier("p1", 1, null, "s1", "2", "j1"); verify(consoleService).appendToConsoleLog(jobIdentifier, "message1"); }
Example #3
Source File: ConsoleLogRequestProcessorV1Test.java From gocd with Apache License 2.0 | 6 votes |
@Test void shouldRouteMessageToConsoleService() throws IOException, IllegalArtifactLocationException { Map<String, String> requestMap = new HashMap<>(); requestMap.put("pipelineName", "p1"); requestMap.put("pipelineCounter", "1"); requestMap.put("stageName", "s1"); requestMap.put("stageCounter", "2"); requestMap.put("jobName", "j1"); requestMap.put("text", "message1"); DefaultGoApiRequest goApiRequest = new DefaultGoApiRequest(APPEND_TO_CONSOLE_LOG, VERSION_1, null); goApiRequest.setRequestBody(new GsonBuilder().create().toJson(requestMap)); final ConsoleLogRequestProcessor processor = new ConsoleLogRequestProcessor(pluginRequestProcessorRegistry, consoleService); final GoApiResponse response = processor.process(pluginDescriptor, goApiRequest); assertThat(response.responseCode(), is(DefaultGoApiResponse.SUCCESS_RESPONSE_CODE)); final JobIdentifier jobIdentifier = new JobIdentifier("p1", 1, null, "s1", "2", "j1"); verify(consoleService).appendToConsoleLog(jobIdentifier, "message1"); }
Example #4
Source File: PluginRequest.java From docker-elastic-agents-plugin with Apache License 2.0 | 6 votes |
public void appendToConsoleLog(JobIdentifier jobIdentifier, String text) throws ServerRequestFailedException { Map<String, String> requestMap = new HashMap<>(); requestMap.put("pipelineName", jobIdentifier.getPipelineName()); requestMap.put("pipelineCounter", String.valueOf(jobIdentifier.getPipelineCounter())); requestMap.put("stageName", jobIdentifier.getStageName()); requestMap.put("stageCounter", jobIdentifier.getStageCounter()); requestMap.put("jobName", jobIdentifier.getJobName()); requestMap.put("text", text); DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_APPEND_TO_CONSOLE_LOG, CONSOLE_LOG_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(new GsonBuilder().create().toJson(requestMap)); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { LOG.error("Failed to append to console log for " + jobIdentifier.represent() + " with text: " + text); } }
Example #5
Source File: PluginRequest.java From kubernetes-elastic-agents with Apache License 2.0 | 5 votes |
public ServerInfo getSeverInfo() throws ServerRequestFailedException { DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_INFO, SERVER_INFO_API_VERSION, PLUGIN_IDENTIFIER); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.serverInfo(response); } return ServerInfo.fromJSON(response.responseBody()); }
Example #6
Source File: AuthorizationRequestProcessorTest.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldProcessInvalidateCacheRequest() throws Exception { PluginRoleService pluginRoleService = mock(PluginRoleService.class); when(authorizationExtension.getMessageConverter(AuthorizationMessageConverterV1.VERSION)).thenReturn(new AuthorizationMessageConverterV1()); GoApiRequest request = new DefaultGoApiRequest(INVALIDATE_CACHE_REQUEST.requestName(), "1.0", null); AuthorizationRequestProcessor authorizationRequestProcessor = new AuthorizationRequestProcessor(registry, pluginRoleService); GoApiResponse response = authorizationRequestProcessor.process(pluginDescriptor, request); assertThat(response.responseCode(), is(200)); verify(pluginRoleService).invalidateRolesFor("cd.go.authorization.github"); }
Example #7
Source File: PluginSettingsRequestProcessorTest.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldRespondWith400InCaseOfErrors() { String PLUGIN_ID = "plugin-foo-id"; when(pluginDescriptor.id()).thenReturn(PLUGIN_ID); when(pluginSqlMapDao.findPlugin(PLUGIN_ID)).thenThrow(new RuntimeException()); DefaultGoApiRequest apiRequest = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension1", Collections.singletonList("1.0"))); apiRequest.setRequestBody("expected-request"); GoApiResponse response = processor.process(pluginDescriptor, apiRequest); assertThat(response.responseCode(), is(400)); }
Example #8
Source File: PluginSettingsRequestProcessorTest.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldNotGetPluginSettingsForPluginThatDoesNotExistInDB() { String PLUGIN_ID = "plugin-foo-id"; String requestBody = "expected-request"; when(pluginDescriptor.id()).thenReturn(PLUGIN_ID); when(pluginSqlMapDao.findPlugin(PLUGIN_ID)).thenReturn(new NullPlugin()); DefaultGoApiRequest apiRequest = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension1", Collections.singletonList("1.0"))); apiRequest.setRequestBody(requestBody); GoApiResponse response = processor.process(pluginDescriptor, apiRequest); assertThat(response.responseCode(), is(200)); assertThat(response.responseBody(), is(nullValue())); }
Example #9
Source File: PluginSettingsRequestProcessorTest.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldGetPluginSettingsForPluginThatExistsInDB() { String PLUGIN_ID = "plugin-foo-id"; when(pluginDescriptor.id()).thenReturn(PLUGIN_ID); when(pluginSqlMapDao.findPlugin(PLUGIN_ID)).thenReturn(new Plugin(PLUGIN_ID, "{\"k1\": \"v1\",\"k2\": \"v2\"}")); DefaultGoApiRequest apiRequest = new DefaultGoApiRequest(PluginSettingsRequestProcessor.GET_PLUGIN_SETTINGS, "1.0", new GoPluginIdentifier("extension1", Collections.singletonList("1.0"))); apiRequest.setRequestBody("expected-request"); GoApiResponse response = processor.process(pluginDescriptor, apiRequest); assertThat(response.responseCode(), is(200)); assertThat(response.responseBody(), is("{\"k1\":\"v1\",\"k2\":\"v2\"}")); }
Example #10
Source File: ConsoleLogRequestProcessorV2Test.java From gocd with Apache License 2.0 | 5 votes |
@Test void shouldRespondWithAMessageIfSomethingGoesWrong() { DefaultGoApiRequest goApiRequest = new DefaultGoApiRequest(APPEND_TO_CONSOLE_LOG, VERSION_2, null); goApiRequest.setRequestBody("this_is_invalid_JSON"); final ConsoleLogRequestProcessor processor = new ConsoleLogRequestProcessor(pluginRequestProcessorRegistry, consoleService); final GoApiResponse response = processor.process(pluginDescriptor, goApiRequest); assertThat(response.responseCode(), is(DefaultGoApiResponse.INTERNAL_ERROR)); final Map responseContents = new Gson().fromJson(response.responseBody(), Map.class); assertThat((String) responseContents.get("message"), containsString("Error:")); }
Example #11
Source File: ConsoleLogRequestProcessorV1Test.java From gocd with Apache License 2.0 | 5 votes |
@Test void shouldRespondWithAMessageIfSomethingGoesWrong() { DefaultGoApiRequest goApiRequest = new DefaultGoApiRequest(APPEND_TO_CONSOLE_LOG, VERSION_1, null); goApiRequest.setRequestBody("this_is_invalid_JSON"); final ConsoleLogRequestProcessor processor = new ConsoleLogRequestProcessor(pluginRequestProcessorRegistry, consoleService); final GoApiResponse response = processor.process(pluginDescriptor, goApiRequest); assertThat(response.responseCode(), is(DefaultGoApiResponse.INTERNAL_ERROR)); final Map responseContents = new Gson().fromJson(response.responseBody(), Map.class); assertThat((String) responseContents.get("message"), containsString("Error:")); }
Example #12
Source File: ServerInfoRequestProcessorTest.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldReturnAErrorResponseIfExtensionDoesNotSupportServerInfo() { DefaultGoApiRequest request = new DefaultGoApiRequest(GET_SERVER_INFO, "bad-version", new GoPluginIdentifier("foo", Arrays.asList("1.0"))); GoApiResponse response = processor.process(pluginDescriptor, request); assertThat(response.responseCode(), is(400)); }
Example #13
Source File: ServerInfoRequestProcessorTest.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldReturnSuccessForServerInfoV2() { DefaultGoApiRequest request = new DefaultGoApiRequest(GET_SERVER_INFO, "2.0", new GoPluginIdentifier("extension1", Arrays.asList("1.0"))); GoApiResponse response = processor.process(pluginDescriptor, request); assertThat(response.responseCode(), is(200)); }
Example #14
Source File: ServerInfoRequestProcessorTest.java From gocd with Apache License 2.0 | 5 votes |
@Test public void shouldReturnAServerIdInJSONForm() { DefaultGoApiRequest request = new DefaultGoApiRequest(GET_SERVER_INFO, "1.0", new GoPluginIdentifier("extension1", Arrays.asList("1.0"))); GoApiResponse response = processor.process(pluginDescriptor, request); assertThat(response.responseCode(), is(200)); assertThat(response.responseBody(), is(format("{\"server_id\":\"%s\",\"site_url\":\"%s\",\"secure_site_url\":\"%s\"}", serverConfig.getServerId(), serverConfig.getSiteUrl().getUrl(), serverConfig.getSecureSiteUrl().getUrl()))); }
Example #15
Source File: PluginRequest.java From docker-elastic-agents-plugin with Apache License 2.0 | 5 votes |
public void deleteAgents(Collection<Agent> toBeDeleted) throws ServerRequestFailedException { if (toBeDeleted.isEmpty()) { return; } DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_DELETE_AGENT, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(Agent.toJSONArray(toBeDeleted)); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.deleteAgents(response); } }
Example #16
Source File: PluginRequest.java From docker-elastic-agents-plugin with Apache License 2.0 | 5 votes |
public void disableAgents(Collection<Agent> toBeDisabled) throws ServerRequestFailedException { if (toBeDisabled.isEmpty()) { return; } DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_DISABLE_AGENT, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(Agent.toJSONArray(toBeDisabled)); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.disableAgents(response); } }
Example #17
Source File: PluginRequest.java From docker-elastic-agents-plugin with Apache License 2.0 | 5 votes |
public Agents listAgents() throws ServerRequestFailedException { DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_LIST_AGENTS, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.listAgents(response); } return new Agents(Agent.fromJSONArray(response.responseBody())); }
Example #18
Source File: PluginRequest.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 5 votes |
public void deleteAgents(Collection<Agent> toBeDeleted) throws ServerRequestFailedException { if (toBeDeleted.isEmpty()) { return; } DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_DELETE_AGENT, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(Agent.toJSONArray(toBeDeleted)); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.deleteAgents(response); } }
Example #19
Source File: PluginRequest.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 5 votes |
public void disableAgents(Collection<Agent> toBeDisabled) throws ServerRequestFailedException { if (toBeDisabled.isEmpty()) { return; } DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_DISABLE_AGENT, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(Agent.toJSONArray(toBeDisabled)); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.disableAgents(response); } }
Example #20
Source File: PluginRequest.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 5 votes |
public Agents listAgents() throws ServerRequestFailedException { DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_LIST_AGENTS, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.listAgents(response); } return new Agents(Agent.fromJSONArray(response.responseBody())); }
Example #21
Source File: PluginRequest.java From kubernetes-elastic-agents with Apache License 2.0 | 5 votes |
public void deleteAgents(Collection<Agent> toBeDeleted) throws ServerRequestFailedException { LOG.debug(format("[Server Ping] Deleting Agents: {0}", toBeDeleted.toString())); if (toBeDeleted.isEmpty()) { return; } DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_DELETE_AGENT, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(Agent.toJSONArray(toBeDeleted)); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.deleteAgents(response); } }
Example #22
Source File: PluginRequest.java From kubernetes-elastic-agents with Apache License 2.0 | 5 votes |
public void disableAgents(Collection<Agent> toBeDisabled) throws ServerRequestFailedException { LOG.debug(format("[Server Ping] Disabling Agents: {0}", toBeDisabled.toString())); if (toBeDisabled.isEmpty()) { return; } DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_DISABLE_AGENT, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(Agent.toJSONArray(toBeDisabled)); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.disableAgents(response); } }
Example #23
Source File: PluginRequest.java From kubernetes-elastic-agents with Apache License 2.0 | 5 votes |
public Agents listAgents() throws ServerRequestFailedException { DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_LIST_AGENTS, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { throw ServerRequestFailedException.listAgents(response); } return new Agents(Agent.fromJSONArray(response.responseBody())); }
Example #24
Source File: ConsoleLogger.java From docker-registry-artifact-plugin with Apache License 2.0 | 5 votes |
private void sendLog(ConsoleLogMessage consoleLogMessage) { DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.SEND_CONSOLE_LOG, CONSOLE_LOG_PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(consoleLogMessage.toJSON()); GoApiResponse response = accessor.submit(request); if (response.responseCode() != DefaultGoApiResponse.SUCCESS_RESPONSE_CODE) { LOG.error(String.format("Failed to submit console log: %s", response.responseBody())); } }
Example #25
Source File: ServerInfoRequestProcessorTest.java From gocd with Apache License 2.0 | 4 votes |
@Test public void shouldRegisterAPIRequestWithProcessor() { DefaultGoApiRequest request = new DefaultGoApiRequest(GET_SERVER_INFO, "1.0", new GoPluginIdentifier("extension1", Collections.singletonList("1.0"))); assertThat(processorRegistry.canProcess(request), is(true)); }
Example #26
Source File: PluginRequest.java From docker-swarm-elastic-agent-plugin with Apache License 2.0 | 4 votes |
public void addServerHealthMessage(List<Map<String, String>> messages) { Gson gson = new Gson(); DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_SERVER_HEALTH_ADD_MESSAGES, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(gson.toJson(messages)); // submit the request GoApiResponse response = accessor.submit(request); // check status if (response.responseCode() != 200) { LOG.error("The server sent an unexpected status code " + response.responseCode() + " with the response body " + response.responseBody()); } }
Example #27
Source File: ServerHealthRequestProcessorTest.java From gocd with Apache License 2.0 | 4 votes |
private DefaultGoApiRequest createRequest(String apiVersion, String requestBody) { DefaultGoApiRequest request = new DefaultGoApiRequest(ADD_SERVER_HEALTH_MESSAGES, apiVersion, null); request.setRequestBody(requestBody); return request; }
Example #28
Source File: RequestMother.java From gocd-filebased-authentication-plugin with Apache License 2.0 | 4 votes |
public static GoApiRequest requestWithCredentials(String username, String password) { final DefaultGoApiRequest defaultGoApiRequest = new DefaultGoApiRequest(null, null, null); defaultGoApiRequest.setRequestBody(requestJson(username, password)); return defaultGoApiRequest; }
Example #29
Source File: PluginRequest.java From docker-elastic-agents-plugin with Apache License 2.0 | 3 votes |
public void addServerHealthMessage(List<Map<String, String>> messages) { Gson gson = new Gson(); DefaultGoApiRequest request = new DefaultGoApiRequest(Constants.REQUEST_SERVER_SERVER_HEALTH_ADD_MESSAGES, PROCESSOR_API_VERSION, PLUGIN_IDENTIFIER); request.setRequestBody(gson.toJson(messages)); GoApiResponse response = accessor.submit(request); if (response.responseCode() != 200) { LOG.error("The server sent an unexpected status code " + response.responseCode() + " with the response body " + response.responseBody()); } }