Skip to content

Commit

Permalink
tech: fixing the cases when incorrect query parameters arrive in GET … (
Browse files Browse the repository at this point in the history
#34)

* tech: fixing the cases when incorrect query parameters arrive in GET TASKS flow
* tech: removing unused obsolete deprecated API
  • Loading branch information
gullerya authored and m-seldin committed Mar 12, 2018
1 parent 71945f8 commit 3725ea3
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 249 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.hp.octane.integrations.dto.DTOBase;
import com.hp.octane.integrations.dto.DTOFactory;
import com.hp.octane.integrations.dto.DTOInternalProviderBase;
import com.hp.octane.integrations.dto.pipelines.BuildHistory;
import com.hp.octane.integrations.dto.pipelines.PipelineNode;
import com.hp.octane.integrations.dto.pipelines.PipelinePhase;

Expand All @@ -32,7 +31,6 @@ public final class DTOPipelinesProvider extends DTOInternalProviderBase {
public DTOPipelinesProvider(DTOFactory.DTOConfiguration configuration) {
dtoPairs.put(PipelineNode.class, PipelineNodeImpl.class);
dtoPairs.put(PipelinePhase.class, PipelinePhaseImpl.class);
dtoPairs.put(BuildHistory.class, BuildHistoryImpl.class);
}

protected <T extends DTOBase> T instantiateDTO(Class<T> targetType) throws InstantiationException, IllegalAccessException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -115,20 +112,6 @@ public void run() {
}

private String getAbridgedTasks(String selfIdentity, String selfType, String selfUrl, Integer apiVersion, String sdkVersion, String pluginVersion, String octaneUser, String ciServerUser) {
// pre-process potentially non-URL-safe values
String selfUrlEscaped = selfUrl;
try {
selfUrlEscaped = URLEncoder.encode(selfUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException uee) {
logger.warn("failed to URL-encode server URL '" + selfUrl + "' (will be sent as is", uee);
}
String sdkVersionEscaped = sdkVersion;
try {
sdkVersionEscaped = URLEncoder.encode(sdkVersion, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException uee) {
logger.warn("failed to URL-encode SDK version '" + selfUrl + "' (will be sent as is", uee);
}

String responseBody = null;
RestClient restClient = restService.obtainClient();
OctaneConfiguration octaneConfiguration = pluginServices.getOctaneConfiguration();
Expand All @@ -139,9 +122,13 @@ private String getAbridgedTasks(String selfIdentity, String selfType, String sel
.setMethod(HttpMethod.GET)
.setUrl(octaneConfiguration.getUrl() +
SHARED_SPACE_INTERNAL_API_PATH_PART + octaneConfiguration.getSharedSpace() +
ANALYTICS_CI_PATH_PART + "servers/" + selfIdentity + "/tasks?self-type=" + selfType +
"&self-url=" + selfUrlEscaped + "&api-version=" + apiVersion + "&sdk-version=" + sdkVersionEscaped +
"&plugin-version=" + urlEncodeQueryParam(pluginVersion) + "&client-id=" + octaneUser + "&ci-server-user=" + ciServerUser)
ANALYTICS_CI_PATH_PART + "servers/" + selfIdentity + "/tasks?self-type=" + urlEncodeQueryParam(selfType) +
"&self-url=" + urlEncodeQueryParam(selfUrl) +
"&api-version=" + apiVersion +
"&sdk-version=" + urlEncodeQueryParam(sdkVersion) +
"&plugin-version=" + urlEncodeQueryParam(pluginVersion) +
"&client-id=" + urlEncodeQueryParam(octaneUser) +
"&ci-server-user=" + urlEncodeQueryParam(ciServerUser))
.setHeaders(headers);
try {
OctaneResponse octaneResponse = restClient.execute(octaneRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.hp.octane.integrations.dto.general.CIJobsList;
import com.hp.octane.integrations.dto.general.CIPluginSDKInfo;
import com.hp.octane.integrations.dto.general.CIProviderSummaryInfo;
import com.hp.octane.integrations.dto.pipelines.BuildHistory;
import com.hp.octane.integrations.dto.pipelines.PipelineNode;
import com.hp.octane.integrations.dto.snapshots.SnapshotNode;
import com.hp.octane.integrations.exceptions.ConfigurationException;
Expand Down Expand Up @@ -58,7 +57,6 @@ public final class TasksProcessorImpl extends OctaneSDK.SDKServiceBase implement
private static final String SUSPEND_STATUS = "suspend_status";
private static final String JOBS = "jobs";
private static final String RUN = "run";
private static final String HISTORY = "history";
private static final String BUILDS = "builds";
private static final String LATEST = "latest";
private static final String EXECUTOR = "executor";
Expand Down Expand Up @@ -108,8 +106,6 @@ public OctaneResultAbridged execute(OctaneTaskAbridged task) {
} else {
executeSnapshotByNumberRequest(result, path[1], path[3], subTree);
}
} else if (path.length == 3 && JOBS.equals(path[0]) && HISTORY.equals(path[2])) {
executeHistoryRequest(result, path[1], task.getBody());
} else {
result.setStatus(404);
}
Expand Down Expand Up @@ -167,7 +163,7 @@ private String[] pathTokenizer(String url) {
String[] path = Pattern.compile("^.*" + NGA_API + "/?").matcher(url).replaceFirst("").split("/");
params.put(0, path[0]);
for (int i = 1; i < path.length; i++) {
if ((path[i].equals(HISTORY) || path[i].equals(BUILDS) || path[i].equals(RUN)) && i == path.length - 1) { // last token
if ((path[i].equals(BUILDS) || path[i].equals(RUN)) && i == path.length - 1) { // last token
params.put(2, path[i]);
} else if (path[i].equals(BUILDS) && i == path.length - 2) { // one before last token
params.put(2, path[i]);
Expand Down Expand Up @@ -244,12 +240,6 @@ private void executeSnapshotByNumberRequest(OctaneResultAbridged result, String
result.getHeaders().put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
}

private void executeHistoryRequest(OctaneResultAbridged result, String jobId, String originalBody) {
BuildHistory content = pluginServices.getHistoryPipeline(jobId, originalBody);
result.setBody(dtoFactory.dtoToJson(content));
result.getHeaders().put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
}

private void executeUpsertCredentials(OctaneResultAbridged result, CredentialsInfo credentialsInfo) {
OctaneResponse response = pluginServices.upsertCredentials(credentialsInfo);
result.setBody(response.getBody());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.hp.octane.integrations.dto.general.CIJobsList;
import com.hp.octane.integrations.dto.general.CIPluginInfo;
import com.hp.octane.integrations.dto.general.CIServerInfo;
import com.hp.octane.integrations.dto.pipelines.BuildHistory;
import com.hp.octane.integrations.dto.pipelines.PipelineNode;
import com.hp.octane.integrations.dto.snapshots.SnapshotNode;
import com.hp.octane.integrations.dto.tests.TestsResult;
Expand Down Expand Up @@ -125,16 +124,6 @@ public interface CIPluginServices {
*/
SnapshotNode getSnapshotByNumber(String ciJobId, String buildCiId, boolean subTree);

/**
* Retrieves aggregated latest builds info
*
* @param ciJobId Job CI ID to get history data for
* @param originalBody request body
* @return history data for the specified pipeline
*/
@Deprecated
BuildHistory getHistoryPipeline(String ciJobId, String originalBody);

/**
* Retrieves tests result report for the specific build
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.hp.octane.integrations.dto.general.CIJobsList;
import com.hp.octane.integrations.dto.general.CIPluginInfo;
import com.hp.octane.integrations.dto.general.CIServerInfo;
import com.hp.octane.integrations.dto.pipelines.BuildHistory;
import com.hp.octane.integrations.dto.pipelines.PipelineNode;
import com.hp.octane.integrations.dto.snapshots.SnapshotNode;
import com.hp.octane.integrations.dto.tests.TestsResult;
Expand Down Expand Up @@ -92,11 +91,6 @@ public SnapshotNode getSnapshotByNumber(String ciJobId, String buildCiId, boolea
return null;
}

@Override
public BuildHistory getHistoryPipeline(String ciJobId, String originalBody) {
return null;
}

@Override
public TestsResult getTestsResult(String jobCiId, String buildCiId) {
return null;
Expand Down

0 comments on commit 3725ea3

Please sign in to comment.