Search in sources :

Example 11 with Process

use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.

the class ProcessInstanceMarshaller method unmarshallWorkflowProcessInstance.

public WorkflowProcessInstance unmarshallWorkflowProcessInstance(byte[] data, Process<?> process) {
    Map<String, io.automatiko.engine.api.definition.process.Process> processes = new HashMap<String, io.automatiko.engine.api.definition.process.Process>();
    io.automatiko.engine.api.definition.process.Process p = ((AbstractProcess<?>) process).process();
    // this can include version number in the id
    processes.put(process.id(), p);
    // this is raw process id as defined in bpmn or so
    processes.put(p.getId(), p);
    try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) {
        MarshallerReaderContext context = new MarshallerReaderContext(bais, null, processes, this.env);
        ObjectInputStream stream = context.stream;
        String processInstanceType = stream.readUTF();
        io.automatiko.engine.workflow.marshalling.impl.ProcessInstanceMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE.getMarshaller(processInstanceType);
        WorkflowProcessInstance pi = (WorkflowProcessInstance) marshaller.readProcessInstance(context);
        context.close();
        return pi;
    } catch (Exception e) {
        throw new RuntimeException("Error while unmarshalling process instance", e);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) Process(io.automatiko.engine.api.workflow.Process) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) MarshallerReaderContext(io.automatiko.engine.workflow.marshalling.impl.MarshallerReaderContext) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ObjectInputStream(java.io.ObjectInputStream)

Example 12 with Process

use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.

the class TestJobService method triggerProcessJob.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void triggerProcessJob(String jobId) {
    ProcessJobDescription job = (ProcessJobDescription) jobs.remove(jobId);
    if (job == null) {
        throw new IllegalArgumentException("Job with id " + jobId + " not found");
    }
    int limit = job.expirationTime().repeatLimit();
    try {
        LOGGER.debug("Job {} started", job.id());
        Process process = mappedProcesses.get(job.processId());
        if (process == null) {
            LOGGER.warn("No process found for process id {}", job.processId());
            return;
        }
        IdentityProvider.set(new TrustedIdentityProvider("System<timer>"));
        UnitOfWorkExecutor.executeInUnitOfWork(unitOfWorkManager, () -> {
            ProcessInstance<?> pi = process.createInstance(process.createModel());
            if (pi != null) {
                pi.start(TRIGGER, null, null);
            }
            return null;
        });
        limit--;
        if (limit == 0) {
            jobs.remove(jobId);
        }
        LOGGER.debug("Job {} completed", job.id());
    } finally {
        if (job.expirationTime().next() != null) {
            jobs.remove(jobId);
            scheduleProcessJob(job);
        } else {
            jobs.remove(jobId);
        }
    }
}
Also used : TrustedIdentityProvider(io.automatiko.engine.api.auth.TrustedIdentityProvider) Process(io.automatiko.engine.api.workflow.Process) ProcessJobDescription(io.automatiko.engine.api.jobs.ProcessJobDescription)

Example 13 with Process

use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.

the class DynamoDBProcessInstances method values.

@Override
public Collection values(ProcessInstanceReadMode mode, int status, int page, int size) {
    LOGGER.debug("values() called");
    Map<String, AttributeValue> attrValues = new HashMap<String, AttributeValue>();
    StringBuilder condition = new StringBuilder();
    attrValues.put(":status", AttributeValue.builder().n(String.valueOf(status)).build());
    condition.append(STATUS_FIELD + " = :status ");
    ScanRequest request = ScanRequest.builder().tableName(tableName).filterExpression(condition.toString()).expressionAttributeValues(attrValues).limit(page * size).build();
    return dynamodb.scanPaginator(request).items().stream().map(item -> {
        try {
            byte[] content = item.get(CONTENT_FIELD).b().asByteArray();
            return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, Long.parseLong(item.get(VERSION_FIELD).n())) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
        } catch (AccessDeniedException e) {
            return null;
        }
    }).filter(pi -> pi != null).skip(calculatePage(page, size)).limit(size).collect(Collectors.toList());
}
Also used : ConflictingVersionException(io.automatiko.engine.api.workflow.ConflictingVersionException) LoggerFactory(org.slf4j.LoggerFactory) DynamoDBPersistenceConfig(io.automatiko.engine.api.config.DynamoDBPersistenceConfig) SdkBytes(software.amazon.awssdk.core.SdkBytes) JacksonObjectMarshallingStrategy(io.automatiko.engine.addons.persistence.common.JacksonObjectMarshallingStrategy) Map(java.util.Map) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) Select(software.amazon.awssdk.services.dynamodb.model.Select) WaiterResponse(software.amazon.awssdk.core.waiters.WaiterResponse) ConditionalCheckFailedException(software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException) ScalarAttributeType(software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType) ResourceInUseException(software.amazon.awssdk.services.dynamodb.model.ResourceInUseException) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Model(io.automatiko.engine.api.Model) AttributeValueUpdate(software.amazon.awssdk.services.dynamodb.model.AttributeValueUpdate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StoredDataCodec(io.automatiko.engine.api.workflow.encrypt.StoredDataCodec) KeyType(software.amazon.awssdk.services.dynamodb.model.KeyType) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Collectors(java.util.stream.Collectors) PutItemRequest(software.amazon.awssdk.services.dynamodb.model.PutItemRequest) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) ProcessInstanceReadMode(io.automatiko.engine.api.workflow.ProcessInstanceReadMode) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) Optional(java.util.Optional) DeleteItemRequest(software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest) MutableProcessInstances(io.automatiko.engine.api.workflow.MutableProcessInstances) DescribeTableResponse(software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) GetItemRequest(software.amazon.awssdk.services.dynamodb.model.GetItemRequest) UpdateItemRequest(software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AttributeAction(software.amazon.awssdk.services.dynamodb.model.AttributeAction) ProvisionedThroughput(software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput) CreateTableRequest(software.amazon.awssdk.services.dynamodb.model.CreateTableRequest) ScanRequest(software.amazon.awssdk.services.dynamodb.model.ScanRequest) Process(io.automatiko.engine.api.workflow.Process) Logger(org.slf4j.Logger) AttributeDefinition(software.amazon.awssdk.services.dynamodb.model.AttributeDefinition) DynamoDbWaiter(software.amazon.awssdk.services.dynamodb.waiters.DynamoDbWaiter) MUTABLE(io.automatiko.engine.api.workflow.ProcessInstanceReadMode.MUTABLE) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) KeySchemaElement(software.amazon.awssdk.services.dynamodb.model.KeySchemaElement) ProcessInstanceMarshaller(io.automatiko.engine.workflow.marshalling.ProcessInstanceMarshaller) CreateTableResponse(software.amazon.awssdk.services.dynamodb.model.CreateTableResponse) DescribeTableRequest(software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest) ScanRequest(software.amazon.awssdk.services.dynamodb.model.ScanRequest) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 14 with Process

use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.

the class CassandraProcessInstances method values.

@Override
public Collection values(ProcessInstanceReadMode mode, int status, int page, int size) {
    LOGGER.debug("values() called");
    Select select = selectFrom(config.keyspace().orElse("automatiko"), tableName).column(CONTENT_FIELD).column(VERSION_FIELD).whereColumn(STATUS_FIELD).isEqualTo(literal(status));
    ResultSet rs = cqlSession.execute(select.build());
    return rs.all().stream().map(item -> {
        try {
            byte[] content = ByteUtils.getArray(item.getByteBuffer(CONTENT_FIELD));
            return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, item.getLong(VERSION_FIELD)) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
        } catch (AccessDeniedException e) {
            return null;
        }
    }).filter(pi -> pi != null).skip(calculatePage(page, size)).limit(size).collect(Collectors.toList());
}
Also used : QueryBuilder.insertInto(com.datastax.oss.driver.api.querybuilder.QueryBuilder.insertInto) QueryBuilder(com.datastax.oss.driver.api.querybuilder.QueryBuilder) ConflictingVersionException(io.automatiko.engine.api.workflow.ConflictingVersionException) LoggerFactory(org.slf4j.LoggerFactory) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert) CreateKeyspace(com.datastax.oss.driver.api.querybuilder.schema.CreateKeyspace) Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ByteBuffer(java.nio.ByteBuffer) CreateTable(com.datastax.oss.driver.api.querybuilder.schema.CreateTable) JacksonObjectMarshallingStrategy(io.automatiko.engine.addons.persistence.common.JacksonObjectMarshallingStrategy) Map(java.util.Map) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) ConsistencyLevel(com.datastax.oss.driver.api.core.ConsistencyLevel) Select(com.datastax.oss.driver.api.querybuilder.select.Select) Model(io.automatiko.engine.api.Model) ByteUtils(com.datastax.oss.driver.api.core.data.ByteUtils) QueryBuilder.bindMarker(com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker) Collection(java.util.Collection) QueryExecutionException(com.datastax.oss.driver.api.core.servererrors.QueryExecutionException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StoredDataCodec(io.automatiko.engine.api.workflow.encrypt.StoredDataCodec) Set(java.util.Set) QueryBuilder.selectFrom(com.datastax.oss.driver.api.querybuilder.QueryBuilder.selectFrom) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Collectors(java.util.stream.Collectors) SchemaBuilder(com.datastax.oss.driver.api.querybuilder.SchemaBuilder) List(java.util.List) DataTypes(com.datastax.oss.driver.api.core.type.DataTypes) Stream(java.util.stream.Stream) QueryBuilder.literal(com.datastax.oss.driver.api.querybuilder.QueryBuilder.literal) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) ProcessInstanceReadMode(io.automatiko.engine.api.workflow.ProcessInstanceReadMode) Optional(java.util.Optional) CassandraPersistenceConfig(io.automatiko.engine.api.config.CassandraPersistenceConfig) QueryBuilder.deleteFrom(com.datastax.oss.driver.api.querybuilder.QueryBuilder.deleteFrom) CreateIndex(com.datastax.oss.driver.api.querybuilder.schema.CreateIndex) MutableProcessInstances(io.automatiko.engine.api.workflow.MutableProcessInstances) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Process(io.automatiko.engine.api.workflow.Process) Row(com.datastax.oss.driver.api.core.cql.Row) LinkedHashSet(java.util.LinkedHashSet) Logger(org.slf4j.Logger) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) MUTABLE(io.automatiko.engine.api.workflow.ProcessInstanceReadMode.MUTABLE) ProcessInstanceMarshaller(io.automatiko.engine.workflow.marshalling.ProcessInstanceMarshaller) SchemaBuilder.createKeyspace(com.datastax.oss.driver.api.querybuilder.SchemaBuilder.createKeyspace) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) Select(com.datastax.oss.driver.api.querybuilder.select.Select) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet)

Example 15 with Process

use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.

the class DynamoDBProcessInstances method findByIdOrTag.

@Override
public Collection findByIdOrTag(ProcessInstanceReadMode mode, int status, String... values) {
    LOGGER.debug("findByIdOrTag() called for values {}", values);
    Map<String, AttributeValue> attrValues = new HashMap<String, AttributeValue>();
    int counter = 0;
    StringBuilder condition = new StringBuilder();
    attrValues.put(":status", AttributeValue.builder().n(String.valueOf(status)).build());
    condition.append(STATUS_FIELD + "= :status AND ");
    for (String value : values) {
        attrValues.put(":value" + counter, AttributeValue.builder().s(value).build());
        condition.append("contains(" + TAGS_FIELD + ", :value" + counter + ") OR ");
        counter++;
    }
    condition.delete(condition.length() - 4, condition.length());
    ScanRequest query = ScanRequest.builder().tableName(tableName).filterExpression(condition.toString()).expressionAttributeValues(attrValues).build();
    return dynamodb.scan(query).items().stream().map(item -> {
        try {
            byte[] content = item.get(CONTENT_FIELD).b().asByteArray();
            return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, Long.parseLong(item.get(VERSION_FIELD).n())) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
        } catch (AccessDeniedException e) {
            return null;
        }
    }).filter(pi -> pi != null).collect(Collectors.toList());
}
Also used : ConflictingVersionException(io.automatiko.engine.api.workflow.ConflictingVersionException) LoggerFactory(org.slf4j.LoggerFactory) DynamoDBPersistenceConfig(io.automatiko.engine.api.config.DynamoDBPersistenceConfig) SdkBytes(software.amazon.awssdk.core.SdkBytes) JacksonObjectMarshallingStrategy(io.automatiko.engine.addons.persistence.common.JacksonObjectMarshallingStrategy) Map(java.util.Map) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) Select(software.amazon.awssdk.services.dynamodb.model.Select) WaiterResponse(software.amazon.awssdk.core.waiters.WaiterResponse) ConditionalCheckFailedException(software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException) ScalarAttributeType(software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType) ResourceInUseException(software.amazon.awssdk.services.dynamodb.model.ResourceInUseException) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) Model(io.automatiko.engine.api.Model) AttributeValueUpdate(software.amazon.awssdk.services.dynamodb.model.AttributeValueUpdate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StoredDataCodec(io.automatiko.engine.api.workflow.encrypt.StoredDataCodec) KeyType(software.amazon.awssdk.services.dynamodb.model.KeyType) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Collectors(java.util.stream.Collectors) PutItemRequest(software.amazon.awssdk.services.dynamodb.model.PutItemRequest) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) ProcessInstanceReadMode(io.automatiko.engine.api.workflow.ProcessInstanceReadMode) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) Optional(java.util.Optional) DeleteItemRequest(software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest) MutableProcessInstances(io.automatiko.engine.api.workflow.MutableProcessInstances) DescribeTableResponse(software.amazon.awssdk.services.dynamodb.model.DescribeTableResponse) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) GetItemRequest(software.amazon.awssdk.services.dynamodb.model.GetItemRequest) UpdateItemRequest(software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AttributeAction(software.amazon.awssdk.services.dynamodb.model.AttributeAction) ProvisionedThroughput(software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput) CreateTableRequest(software.amazon.awssdk.services.dynamodb.model.CreateTableRequest) ScanRequest(software.amazon.awssdk.services.dynamodb.model.ScanRequest) Process(io.automatiko.engine.api.workflow.Process) Logger(org.slf4j.Logger) AttributeDefinition(software.amazon.awssdk.services.dynamodb.model.AttributeDefinition) DynamoDbWaiter(software.amazon.awssdk.services.dynamodb.waiters.DynamoDbWaiter) MUTABLE(io.automatiko.engine.api.workflow.ProcessInstanceReadMode.MUTABLE) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) KeySchemaElement(software.amazon.awssdk.services.dynamodb.model.KeySchemaElement) ProcessInstanceMarshaller(io.automatiko.engine.workflow.marshalling.ProcessInstanceMarshaller) CreateTableResponse(software.amazon.awssdk.services.dynamodb.model.CreateTableResponse) DescribeTableRequest(software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest) ScanRequest(software.amazon.awssdk.services.dynamodb.model.ScanRequest) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) AccessDeniedException(io.automatiko.engine.api.auth.AccessDeniedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

Process (io.automatiko.engine.api.workflow.Process)18 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)15 Model (io.automatiko.engine.api.Model)13 List (java.util.List)11 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)9 Collection (java.util.Collection)9 Application (io.automatiko.engine.api.Application)8 Optional (java.util.Optional)8 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)7 Collectors (java.util.stream.Collectors)7 ProcessInstanceReadMode (io.automatiko.engine.api.workflow.ProcessInstanceReadMode)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 WorkItem (io.automatiko.engine.api.workflow.WorkItem)5 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)5 AbstractProcess (io.automatiko.engine.workflow.AbstractProcess)5 IOException (java.io.IOException)5