Commit a88d5f29 authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge branch 'feature/GONRG-2507_Send_Conflict_When_Workflow_Already_Exists'...

Merge branch 'feature/GONRG-2507_Send_Conflict_When_Workflow_Already_Exists' into 'integration-master'

GONRG-2507 Send Conflict When Workflow Already Exists

See merge request go3-nrg/platform/data-flow/ingestion/ingestion-workflow!83
parents 2f00d8b2 92639c22
Pipeline #45464 failed with stages
in 59 minutes and 39 seconds
package org.opengroup.osdu.workflow.provider.gcp.di;
/*
* Copyright 2020 Google LLC
* Copyright 2020 EPAM Systems, Inc
......@@ -17,6 +15,8 @@ package org.opengroup.osdu.workflow.provider.gcp.di;
* limitations under the License.
*/
package org.opengroup.osdu.workflow.provider.gcp.di;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.core.common.cache.VmCache;
import org.opengroup.osdu.core.gcp.multitenancy.credentials.DatastoreCredential;
......
......@@ -203,7 +203,7 @@ public class GcpWorkflowMetadataRepository implements IWorkflowMetadataRepositor
txn.commit();
workflowMetadata.setWorkflowId(entity.getKey().getName());
} else {
workflowMetadata.setWorkflowId(tasks.next().getKey().getName());
throw new AppException(HttpStatus.CONFLICT.value(), "Conflict", String.format("Workflow with name %s already exists.", workflowName));
}
} catch (DatastoreException ex) {
throw new PersistenceException(ex.getCode(), ex.getMessage(), ex.getReason());
......
......@@ -16,7 +16,6 @@
package org.opengroup.osdu.workflow.provider.gcp.security;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
......
......@@ -17,6 +17,19 @@
package org.opengroup.osdu.gcp.workflow.workflow;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_WORKFLOW_RUN_URL;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_WORKFLOW_URL;
import static org.opengroup.osdu.workflow.consts.TestConstants.GET_DETAILS_WORKFLOW_RUN_URL;
import static org.opengroup.osdu.workflow.util.PayloadBuilder.buildUpdateWorkflowPayload;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.sun.jersey.api.client.ClientResponse;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.HttpMethod;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.opengroup.osdu.gcp.workflow.util.HTTPClientGCP;
......@@ -24,6 +37,8 @@ import org.opengroup.osdu.workflow.workflow.v3.WorkflowRunV3IntegrationTests;
public class TestWorkflowRunV3Integration extends WorkflowRunV3IntegrationTests {
private final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
@BeforeEach
@Override
public void setup() {
......@@ -48,4 +63,53 @@ public class TestWorkflowRunV3Integration extends WorkflowRunV3IntegrationTests
}
});
}
@Override
protected void deleteTestWorkflows(String workflowName) throws Exception {
List<String> runIds = getWorkflowRuns(workflowName);
for (String runId : runIds) {
sendWorkflowRunFinishedUpdateRequest(workflowName, runId);
}
String url = CREATE_WORKFLOW_URL + "/" + workflowName;
sendDeleteRequest(url);
}
protected ClientResponse sendWorkflowRunFinishedUpdateRequest(String workflowName, String runId) throws Exception {
return client.send(
HttpMethod.PUT,
String.format(GET_DETAILS_WORKFLOW_RUN_URL, workflowName,
runId),
buildUpdateWorkflowPayload(),
headers,
client.getAccessToken()
);
}
private List<String> getWorkflowRuns(String workflowName) throws Exception {
ClientResponse response = client.send(
HttpMethod.GET,
String.format(CREATE_WORKFLOW_RUN_URL, workflowName),
null,
headers,
client.getAccessToken()
);
String respBody = response.getEntity(String.class);
JsonArray responseDataArr = gson.fromJson(respBody, JsonArray.class);
ArrayList<String> runIds = new ArrayList<String>();
for (JsonElement responseData: responseDataArr) {
runIds.add(responseData.getAsJsonObject().get("runId").getAsString());
}
return runIds;
}
}
......@@ -17,6 +17,19 @@
package org.opengroup.osdu.gcp.workflow.workflow;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_WORKFLOW_RUN_URL;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_WORKFLOW_URL;
import static org.opengroup.osdu.workflow.consts.TestConstants.GET_DETAILS_WORKFLOW_RUN_URL;
import static org.opengroup.osdu.workflow.util.PayloadBuilder.buildUpdateWorkflowPayload;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.sun.jersey.api.client.ClientResponse;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.HttpMethod;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.opengroup.osdu.gcp.workflow.util.HTTPClientGCP;
......@@ -24,6 +37,8 @@ import org.opengroup.osdu.workflow.workflow.v3.WorkflowV3IntegrationTests;
public class TestWorkflowV3Integration extends WorkflowV3IntegrationTests {
private final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
@BeforeEach
@Override
public void setup() {
......@@ -48,4 +63,53 @@ public class TestWorkflowV3Integration extends WorkflowV3IntegrationTests {
}
});
}
@Override
protected void deleteTestWorkflows(String workflowName) throws Exception {
List<String> runIds = getWorkflowRuns(workflowName);
for (String runId : runIds) {
sendWorkflowRunFinishedUpdateRequest(workflowName, runId);
}
String url = CREATE_WORKFLOW_URL + "/" + workflowName;
sendDeleteRequest(url);
}
protected ClientResponse sendWorkflowRunFinishedUpdateRequest(String workflowName, String runId) throws Exception {
return client.send(
HttpMethod.PUT,
String.format(GET_DETAILS_WORKFLOW_RUN_URL, workflowName,
runId),
buildUpdateWorkflowPayload(),
headers,
client.getAccessToken()
);
}
private List<String> getWorkflowRuns(String workflowName) throws Exception {
ClientResponse response = client.send(
HttpMethod.GET,
String.format(CREATE_WORKFLOW_RUN_URL, workflowName),
null,
headers,
client.getAccessToken()
);
String respBody = response.getEntity(String.class);
JsonArray responseDataArr = gson.fromJson(respBody, JsonArray.class);
ArrayList<String> runIds = new ArrayList<String>();
for (JsonElement responseData: responseDataArr) {
runIds.add(responseData.getAsJsonObject().get("runId").getAsString());
}
return runIds;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment