Java Code Examples for com.thoughtworks.go.plugin.api.response.GoApiResponse#responseCode()

The following examples show how to use com.thoughtworks.go.plugin.api.response.GoApiResponse#responseCode() . 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 vote down vote up
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: PluginRequest.java    From docker-elastic-agents-plugin with Apache License 2.0 6 votes vote down vote up
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 3
Source File: ConsoleLogger.java    From docker-registry-artifact-plugin with Apache License 2.0 5 votes vote down vote up
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 4
Source File: PluginRequest.java    From kubernetes-elastic-agents with Apache License 2.0 5 votes vote down vote up
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 5
Source File: PluginRequest.java    From kubernetes-elastic-agents with Apache License 2.0 5 votes vote down vote up
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 6
Source File: PluginRequest.java    From kubernetes-elastic-agents with Apache License 2.0 5 votes vote down vote up
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 7
Source File: PluginRequest.java    From kubernetes-elastic-agents with Apache License 2.0 5 votes vote down vote up
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 8
Source File: PluginRequest.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 5 votes vote down vote up
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 9
Source File: PluginRequest.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 5 votes vote down vote up
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 10
Source File: PluginRequest.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 5 votes vote down vote up
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 11
Source File: PluginRequest.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
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 12
Source File: PluginRequest.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
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 13
Source File: PluginRequest.java    From docker-elastic-agents-plugin with Apache License 2.0 5 votes vote down vote up
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 14
Source File: PluginRequest.java    From docker-swarm-elastic-agent-plugin with Apache License 2.0 4 votes vote down vote up
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 15
Source File: PluginRequest.java    From docker-elastic-agents-plugin with Apache License 2.0 3 votes vote down vote up
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());
    }
}