Search in sources :

Example 46 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class MetadataResourceTest method testGetAllWorkflowDef.

@Test
public void testGetAllWorkflowDef() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test");
    workflowDef.setVersion(1);
    workflowDef.setDescription("test");
    List<WorkflowDef> listOfWorkflowDef = new ArrayList<>();
    listOfWorkflowDef.add(workflowDef);
    when(mockMetadataService.getWorkflowDefs()).thenReturn(listOfWorkflowDef);
    assertEquals(listOfWorkflowDef, metadataResource.getAll());
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 47 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class MetadataResourceTest method testCreateWorkflow.

@Test
public void testCreateWorkflow() {
    WorkflowDef workflowDef = new WorkflowDef();
    metadataResource.create(workflowDef);
    verify(mockMetadataService, times(1)).registerWorkflowDef(any(WorkflowDef.class));
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Test(org.junit.Test)

Example 48 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class MetadataResourceTest method testGetWorkflowDef.

@Test
public void testGetWorkflowDef() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test");
    workflowDef.setVersion(1);
    workflowDef.setDescription("test");
    when(mockMetadataService.getWorkflowDef(anyString(), any())).thenReturn(workflowDef);
    assertEquals(workflowDef, metadataResource.get("test", 1));
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Test(org.junit.Test)

Example 49 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class CassandraDAOTest method testWorkflowDefCRUD.

@Test
public void testWorkflowDefCRUD() throws Exception {
    String name = "workflow_def_1";
    int version = 1;
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName(name);
    workflowDef.setVersion(version);
    workflowDef.setOwnerEmail("test@junit.com");
    // create workflow definition explicitly in test
    // since, embedded Cassandra server does not support LWT required for this API.
    addWorkflowDefinition(workflowDef);
    // fetch the workflow definition
    Optional<WorkflowDef> defOptional = metadataDAO.getWorkflowDef(name, version);
    assertTrue(defOptional.isPresent());
    assertEquals(workflowDef, defOptional.get());
    // register a higher version
    int higherVersion = 2;
    workflowDef.setVersion(higherVersion);
    workflowDef.setDescription("higher version");
    // register the higher version definition
    addWorkflowDefinition(workflowDef);
    // fetch the higher version
    defOptional = metadataDAO.getWorkflowDef(name, higherVersion);
    assertTrue(defOptional.isPresent());
    assertEquals(workflowDef, defOptional.get());
    // fetch latest version
    defOptional = metadataDAO.getLatestWorkflowDef(name);
    assertTrue(defOptional.isPresent());
    assertEquals(workflowDef, defOptional.get());
    // modify the definition
    workflowDef.setOwnerEmail("junit@test.com");
    metadataDAO.updateWorkflowDef(workflowDef);
    // fetch the workflow definition
    defOptional = metadataDAO.getWorkflowDef(name, higherVersion);
    assertTrue(defOptional.isPresent());
    assertEquals(workflowDef, defOptional.get());
    // delete workflow def
    metadataDAO.removeWorkflowDef(name, higherVersion);
    defOptional = metadataDAO.getWorkflowDef(name, higherVersion);
    assertFalse(defOptional.isPresent());
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Test(org.junit.Test)

Example 50 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class CassandraMetadataDAO method getWorkflowDef.

@Override
public Optional<WorkflowDef> getWorkflowDef(String name, int version) {
    try {
        recordCassandraDaoRequests("getWorkflowDef");
        ResultSet resultSet = session.execute(selectWorkflowDefStatement.bind(name, version));
        WorkflowDef workflowDef = Optional.ofNullable(resultSet.one()).map(row -> readValue(row.getString(WORKFLOW_DEFINITION_KEY), WorkflowDef.class)).orElse(null);
        return Optional.ofNullable(workflowDef);
    } catch (Exception e) {
        Monitors.error(CLASS_NAME, "getTaskDef");
        String errorMsg = String.format("Error fetching workflow def: %s/%d", name, version);
        LOGGER.error(errorMsg, e);
        throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
    }
}
Also used : Row(com.datastax.driver.core.Row) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) PreparedStatement(com.datastax.driver.core.PreparedStatement) Inject(javax.inject.Inject) CassandraConfiguration(com.netflix.conductor.cassandra.CassandraConfiguration) ResultSet(com.datastax.driver.core.ResultSet) Session(com.datastax.driver.core.Session) Map(java.util.Map) Code(com.netflix.conductor.core.execution.ApplicationException.Code) TASK_DEFINITION_KEY(com.netflix.conductor.util.Constants.TASK_DEFINITION_KEY) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Logger(org.slf4j.Logger) Trace(com.netflix.conductor.annotations.Trace) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TASK_DEFS_KEY(com.netflix.conductor.util.Constants.TASK_DEFS_KEY) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Monitors(com.netflix.conductor.metrics.Monitors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) WORKFLOW_DEF_NAME_VERSION_KEY(com.netflix.conductor.util.Constants.WORKFLOW_DEF_NAME_VERSION_KEY) Statements(com.netflix.conductor.util.Statements) WORKFLOW_DEFINITION_KEY(com.netflix.conductor.util.Constants.WORKFLOW_DEFINITION_KEY) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) WORKFLOW_DEF_INDEX_KEY(com.netflix.conductor.util.Constants.WORKFLOW_DEF_INDEX_KEY) Collections(java.util.Collections) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ResultSet(com.datastax.driver.core.ResultSet) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Aggregations

WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)247 Test (org.junit.Test)185 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)173 Workflow (com.netflix.conductor.common.run.Workflow)128 HashMap (java.util.HashMap)123 Task (com.netflix.conductor.common.metadata.tasks.Task)100 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)71 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)49 ArrayList (java.util.ArrayList)43 LinkedList (java.util.LinkedList)37 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)35 List (java.util.List)33 UserTask (com.netflix.conductor.tests.utils.UserTask)28 Map (java.util.Map)25 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)20 ConstraintViolation (javax.validation.ConstraintViolation)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)13 ValidatorFactory (javax.validation.ValidatorFactory)13 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)12