Commit 7fdc68ca authored by Yunhua Koglin's avatar Yunhua Koglin
Browse files

move validating workflow name in core code

parent e49dbbae
Pipeline #50737 failed with stages
in 31 minutes and 6 seconds
......@@ -70,13 +70,6 @@ public class AwsWorkflowMetadataRepository implements IWorkflowMetadataRepositor
@Override
public WorkflowMetadata createWorkflow(WorkflowMetadata workflowMetadata) {
//should be removed once the validation occurs in common code
if (!workflowMetadata.getWorkflowName().matches("^[a-zA-Z0-9._-]{1,64}$")) {
throw new AppException(HttpStatus.BAD_REQUEST.value(), "Invalid workflow name",
String.format("Invalid workflowName. Must match pattern '%s'", "^[a-zA-Z0-9._-]{1,64}$"));
}
String dataPartitionId = headers.getPartitionIdWithFallbackToAccountId();
workflowMetadata.setWorkflowId(generateWorkflowId(workflowMetadata.getWorkflowName(), dataPartitionId)); //name should be unique. Enforce it via using name/id as same field
......
......@@ -59,9 +59,8 @@ public class WorkflowMetadataDoc {
@DynamoDBAttribute(attributeName = "isDeployedThroughWorkflowService")
private Boolean isDeployedThroughWorkflowService;
// @DynamoDBAttribute(attributeName = "registrationInstructions")
// @DynamoDBTyped
// private Map<String,Object> registrationInstructions;
@DynamoDBAttribute(attributeName = "registrationInstructions")
private Map<String,Object> registrationInstructions;
public static WorkflowMetadataDoc create(WorkflowMetadata workflowMetadata, String dataPartitionId) {
......@@ -74,7 +73,7 @@ public class WorkflowMetadataDoc {
.creationTimestamp(workflowMetadata.getCreationTimestamp())
.version(workflowMetadata.getCreationTimestamp())
.isDeployedThroughWorkflowService(false) //we dont support deployment right now
// .registrationInstructions(workflowMetadata.getRegistrationInstructions())
.registrationInstructions(workflowMetadata.getRegistrationInstructions())
.build();
return doc;
......@@ -90,7 +89,7 @@ public class WorkflowMetadataDoc {
.creationTimestamp(creationTimestamp)
.version(version)
.isDeployedThroughWorkflowService(isDeployedThroughWorkflowService)
// .registrationInstructions(registrationInstructions)
.registrationInstructions(registrationInstructions)
.build();
return metadata;
......
......@@ -90,10 +90,7 @@ public class GcpWorkflowMetadataRepository implements IWorkflowMetadataRepositor
@Override
public WorkflowMetadata createWorkflow(WorkflowMetadata workflowMetadata) {
log.info("Saving workflow : {}", workflowMetadata);
if (!workflowMetadata.getWorkflowName().matches("^[a-zA-Z0-9._-]{1,64}$")) {
throw new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unknown error",
"Unknown error happened when validating workflow name");
}
String dagName = null;
Map<String, Object> instructions = workflowMetadata.getRegistrationInstructions();
if (Objects.nonNull(instructions)) {
......
......@@ -70,21 +70,13 @@ public class TestWorkflowV3Integration extends WorkflowV3IntegrationTests {
}
@Override
@Test
@Disabled
public void shouldReturnBadRequestWhenInvalidDagNameWorkflowCreate() throws Exception {
// Validation logic is missing in core. issue raised to opengroup
//super.shouldReturnBadRequestWhenInvalidDagNameWorkflowCreate();
}
@Override
@Test
@Disabled
public void shouldReturnInternalServerErrorWhenIncorrectWorkflowNameWorkflowCreate() throws Exception {
// Validation logic is missing in core. issue raised to opengroup
//super.shouldReturnInternalServerErrorWhenIncorrectWorkflowNameWorkflowCreate();
}
@Test
@Disabled
public void shouldReturnBadRequestWhenInvalidDagNameWorkflowCreate() throws Exception {
// Validation logic is missing in core. issue raised to opengroup
//super.shouldReturnBadRequestWhenInvalidDagNameWorkflowCreate();
}
private void deleteAllTestWorkflowRecords() {
createdWorkflows.stream().forEach(c -> {
try {
......
......@@ -64,7 +64,7 @@ public abstract class WorkflowV3IntegrationTests extends TestBase {
}
@Test
public void shouldReturnInternalServerErrorWhenIncorrectWorkflowNameWorkflowCreate()
public void shouldReturnBadRequestErrorWhenIncorrectWorkflowNameWorkflowCreate()
throws Exception {
ClientResponse response = client.send(
HttpMethod.POST,
......@@ -73,7 +73,7 @@ public abstract class WorkflowV3IntegrationTests extends TestBase {
headers,
client.getAccessToken()
);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR.value(), response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST.value(), response.getStatus());
}
@Test
......
......@@ -3,6 +3,7 @@ package org.opengroup.osdu.ibm.workflow.workflow.v3;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opengroup.osdu.workflow.consts.TestConstants.GET_DETAILS_WORKFLOW_RUN_URL;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_WORKFLOW_WORKFLOW_NAME;
import java.util.UUID;
......@@ -23,9 +24,14 @@ public class TestWorkflowRunV3Integration extends WorkflowRunV3IntegrationTests
@BeforeEach
@Override
public void setup() {
public void setup() throws Exception {
this.client = new HTTPClientIBM();
this.headers = client.getCommonHeader();
try {
deleteTestWorkflows(CREATE_WORKFLOW_WORKFLOW_NAME);
} catch (Exception e) {
throw e;
}
}
@AfterEach
......
package org.opengroup.osdu.ibm.workflow.workflow.v3;
import static org.opengroup.osdu.workflow.consts.TestConstants.CREATE_WORKFLOW_WORKFLOW_NAME;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
......@@ -12,9 +13,14 @@ public class TestWorkflowV3Integration extends WorkflowV3IntegrationTests {
@BeforeEach
@Override
public void setup() {
public void setup() throws Exception {
this.client = new HTTPClientIBM();
this.headers = client.getCommonHeader();
try {
deleteTestWorkflows(CREATE_WORKFLOW_WORKFLOW_NAME);
} catch (Exception e) {
throw e;
}
}
@AfterEach
......@@ -25,24 +31,14 @@ public class TestWorkflowV3Integration extends WorkflowV3IntegrationTests {
this.headers = null;
}
@Override
@Test
@Disabled
public void shouldReturnBadRequestWhenInvalidDagNameWorkflowCreate() throws Exception {
public void shouldReturnBadRequestWhenInvalidDagNameWorkflowCreate() throws Exception {
// Validation logic is missing in core. issue raised to opengroup
//super.shouldReturnBadRequestWhenInvalidDagNameWorkflowCreate();
}
@Override
@Test
@Disabled
public void shouldReturnInternalServerErrorWhenIncorrectWorkflowNameWorkflowCreate() throws Exception {
// Validation logic is missing in core. issue raised to opengroup
//super.shouldReturnInternalServerErrorWhenIncorrectWorkflowNameWorkflowCreate();
}
private void deleteAllTestWorkflowRecords() {
createdWorkflows.stream().forEach(c -> {
try {
......
......@@ -3,7 +3,6 @@ package org.opengroup.osdu.workflow.service;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.opengroup.osdu.core.common.exception.BadRequestException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.workflow.logging.AuditLogger;
......@@ -39,9 +38,10 @@ public class WorkflowManagerServiceImpl implements IWorkflowManagerService {
@Override
public WorkflowMetadata createWorkflow(final CreateWorkflowRequest request) {
if (StringUtils.isEmpty(request.getWorkflowName())) {
throw new BadRequestException("Invalid workflow name provided");
if (!request.getWorkflowName().matches("^[a-zA-Z0-9._-]{1,64}$")) {
throw new BadRequestException("Invalid workflow name provided. Must match pattern ^[a-zA-Z0-9._-]{1,64}$");
}
final WorkflowMetadata workflowMetadata = getWorkflowMetadata(request, dpsHeaders.getUserEmail());
final WorkflowMetadata savedMetadata = workflowMetadataRepository.createWorkflow(workflowMetadata);
final WorkflowEngineRequest rq = new WorkflowEngineRequest(workflowMetadata.getWorkflowName());
......
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