Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions ml-app-deployer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ dependencies {
implementation "org.apache.commons:commons-lang3:3.20.0"

// For PreviewInterceptor; can be excluded if that feature is not used
implementation("com.flipkart.zjsonpatch:zjsonpatch:0.4.16") {
// Prefer the api version declared above
exclude module: "jackson-databind"
}
// See https://github.com/flipkart-incubator/zjsonpatch for details. Note that starting in 0.6.x, Jackson is not
// included, which suits us fine as we already depend on Jackson for other reasons.
implementation "io.github.vishwakarma:zjsonpatch:0.6.2"

// Required for the pdc-java-client code that has been temporarily added to this subproject
// for at least the 6.2.0 release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public class PreviewInterceptor extends DefaultResponseErrorHandler implements C

private final Logger logger = LoggerFactory.getLogger(getClass());

private ManageClient manageClient;

private ArrayNode results;
private final ManageClient manageClient;
private final ArrayNode results;

public PreviewInterceptor(ManageClient manageClient) {
this.manageClient = manageClient;
Expand All @@ -54,9 +53,6 @@ public PreviewInterceptor(ManageClient manageClient) {
* A 404 can happen during a preview when deploying database-specific resources like CPF pipelines or domains.
* If the associated triggers database hasn't been created yet, a 404 will occur. But that shouldn't interrupt a
* deployment process. So a 404 is logged but not treated as an error.
*
* @param httpResponse
* @return
*/
@Override
public boolean hasError(ClientHttpResponse httpResponse) throws IOException {
Expand All @@ -83,11 +79,6 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] bytes, ClientHtt
* For a PUT request, need to get the existing resource as JSON; merge the incoming payload, represented by the byte
* array, into that JSON; and then compare the results to the existing JSON to produce a diff as a JSON patch. The
* results of this are then added to the report.
*
* @param request
* @param bytes
* @return
* @throws IOException
*/
protected ClientHttpResponse previewPut(HttpRequest request, byte[] bytes) throws IOException {
logger.info("Previewing PUT to: " + request.getURI());
Expand All @@ -113,11 +104,6 @@ protected ClientHttpResponse previewPut(HttpRequest request, byte[] bytes) throw

/**
* Uses zjsonpatch to capture the difference between the incoming request and the existing resource as a JSON patch.
*
* @param existingResource
* @param payload
* @return
* @throws IOException
*/
protected JsonNode buildJsonPatch(ObjectNode existingResource, String payload) throws IOException {
ObjectNode payloadResource = (ObjectNode) ObjectMapperFactory.getObjectMapper().readTree(payload);
Expand All @@ -130,7 +116,7 @@ protected JsonNode buildJsonPatch(ObjectNode existingResource, String payload) t

protected void includeJsonPatchInReport(HttpRequest request, ObjectNode existingResource, JsonNode jsonPatch) {
ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
if (jsonPatch instanceof ArrayNode && jsonPatch.size() > 0) {
if (jsonPatch instanceof ArrayNode && !jsonPatch.isEmpty()) {
ObjectNode result = mapper.createObjectNode();
result.set("message", new TextNode("Will update resource at: " + request.getURI()));
result.set("existingResource", existingResource);
Expand All @@ -146,10 +132,6 @@ protected void includeJsonPatchInReport(HttpRequest request, ObjectNode existing
/**
* A PUT request is made to a "properties" endpoint for a resource that can also be used for getting the JSON for
* the existing resource.
*
* @param request
* @return
* @throws IOException
*/
protected ObjectNode getExistingResource(HttpRequest request) throws IOException {
String existingJson = manageClient.getJson(request.getURI());
Expand All @@ -160,8 +142,6 @@ protected ObjectNode getExistingResource(HttpRequest request) throws IOException
* Some resources need to be modified to account for difference that will always exist with an incoming request,
* as that request may have properties that won't ever exist in the resource JSON retrieved from the Manage API,
* such as a user's password.
*
* @param payload
*/
protected void modifyPayloadBeforePreview(ObjectNode payload) {
// Passwords will never be present in the source, so remove from the target
Expand All @@ -178,10 +158,6 @@ protected void modifyPayloadBeforePreview(ObjectNode payload) {
/**
* For a POST operation, a new resource is being created, so just need to include the resource in the report - no
* diff is needed.
*
* @param request
* @param bytes
* @return
*/
protected ClientHttpResponse previewPost(HttpRequest request, byte[] bytes) throws IOException {
ObjectMapper mapper = ObjectMapperFactory.getObjectMapper();
Expand Down Expand Up @@ -218,21 +194,15 @@ protected ClientHttpResponse previewPost(HttpRequest request, byte[] bytes) thro
/**
* For a DELETE operation, a resource is being deleted, so just need to include the resource URI in the report - no
* diff is needed.
*
* @param request
* @param bytes
* @return
*/
protected ClientHttpResponse previewDelete(HttpRequest request, byte[] bytes) throws IOException {
protected ClientHttpResponse previewDelete(HttpRequest request, byte[] bytes) {
logger.info("Previewing, so not sending DELETE to: " + request.getURI());
return newFakeResponse();
}

/**
* Creates a "fake" response for PUT and POST requests. Testing so far shows that simply returning a 200/OK
* suffices during a preview.
*
* @return
*/
protected ClientHttpResponse newFakeResponse() {
return new ClientHttpResponse() {
Expand Down
Loading