Search in sources :

Example 1 with ProcessInstanceDuplicatedException

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

the class CassandraProcessInstances method importInstance.

@Override
public ProcessInstance importInstance(ExportedProcessInstance instance, Process process) {
    ProcessInstance imported = marshaller.importProcessInstance(instance, process);
    if (exists(imported.id())) {
        throw new ProcessInstanceDuplicatedException(imported.id());
    }
    create(imported.id(), imported);
    return imported;
}
Also used : ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance)

Example 2 with ProcessInstanceDuplicatedException

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

the class CassandraProcessInstances method create.

@Override
public void create(String id, ProcessInstance instance) {
    String resolvedId = resolveId(id, instance);
    if (isActive(instance)) {
        LOGGER.debug("create() called for instance {}", resolvedId);
        byte[] data = codec.encode(marshaller.marhsallProcessInstance(instance));
        if (data == null) {
            return;
        }
        Collection<String> tags = new LinkedHashSet<>(instance.tags().values());
        tags.add(resolvedId);
        if (instance.businessKey() != null) {
            tags.add(instance.businessKey());
        }
        Insert insert = insertInto(config.keyspace().orElse("automatiko"), tableName).value(INSTANCE_ID_FIELD, literal(resolvedId)).value(VERSION_FIELD, literal(((AbstractProcessInstance<?>) instance).getVersionTracker())).value(STATUS_FIELD, literal(((AbstractProcessInstance<?>) instance).status())).value(CONTENT_FIELD, bindMarker()).value(TAGS_FIELD, bindMarker()).ifNotExists();
        try {
            ResultSet rs = cqlSession.execute(cqlSession.prepare(insert.build()).bind(ByteBuffer.wrap(data), tags));
            if (!rs.wasApplied()) {
                throw new ProcessInstanceDuplicatedException(id);
            }
        } catch (QueryExecutionException e) {
            throw new ProcessInstanceDuplicatedException(id);
        } finally {
            cachedInstances.remove(resolvedId);
            cachedInstances.remove(id);
            disconnect(instance);
        }
    } else if (isPending(instance)) {
        if (cachedInstances.putIfAbsent(resolvedId, instance) != null) {
            throw new ProcessInstanceDuplicatedException(id);
        }
    } else {
        cachedInstances.remove(resolvedId);
        cachedInstances.remove(id);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) QueryExecutionException(com.datastax.oss.driver.api.core.servererrors.QueryExecutionException) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) Insert(com.datastax.oss.driver.api.querybuilder.insert.Insert)

Example 3 with ProcessInstanceDuplicatedException

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

the class DatabaseProcessInstances method importInstance.

@Override
public ProcessInstance importInstance(ExportedProcessInstance instance, Process process) {
    ProcessInstance imported = marshaller.importProcessInstance(instance, process);
    if (exists(imported.id())) {
        throw new ProcessInstanceDuplicatedException(imported.id());
    }
    create(imported.id(), imported);
    return imported;
}
Also used : ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance)

Example 4 with ProcessInstanceDuplicatedException

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

the class DynamoDBProcessInstances method create.

@Override
public void create(String id, ProcessInstance instance) {
    String resolvedId = resolveId(id, instance);
    if (isActive(instance)) {
        LOGGER.debug("create() called for instance {}", resolvedId);
        byte[] data = codec.encode(marshaller.marhsallProcessInstance(instance));
        if (data == null) {
            return;
        }
        Map<String, AttributeValue> itemValues = new HashMap<String, AttributeValue>();
        itemValues.put(INSTANCE_ID_FIELD, AttributeValue.builder().s(resolvedId).build());
        itemValues.put(VERSION_FIELD, AttributeValue.builder().n(String.valueOf(((AbstractProcessInstance<?>) instance).getVersionTracker())).build());
        itemValues.put(STATUS_FIELD, AttributeValue.builder().n(String.valueOf(((AbstractProcessInstance<?>) instance).status())).build());
        itemValues.put(CONTENT_FIELD, AttributeValue.builder().b(SdkBytes.fromByteArray(data)).build());
        Collection<String> tags = new ArrayList(instance.tags().values());
        tags.add(resolvedId);
        if (instance.businessKey() != null) {
            tags.add(instance.businessKey());
        }
        itemValues.put(TAGS_FIELD, AttributeValue.builder().ss(tags).build());
        PutItemRequest request = PutItemRequest.builder().tableName(tableName).conditionExpression("attribute_not_exists(" + INSTANCE_ID_FIELD + ")").item(itemValues).build();
        try {
            dynamodb.putItem(request);
        } catch (ConditionalCheckFailedException e) {
            throw new ProcessInstanceDuplicatedException(id);
        } finally {
            cachedInstances.remove(resolvedId);
            cachedInstances.remove(id);
            disconnect(instance);
        }
    } else if (isPending(instance)) {
        if (cachedInstances.putIfAbsent(resolvedId, instance) != null) {
            throw new ProcessInstanceDuplicatedException(id);
        }
    } else {
        cachedInstances.remove(resolvedId);
        cachedInstances.remove(id);
    }
}
Also used : AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PutItemRequest(software.amazon.awssdk.services.dynamodb.model.PutItemRequest) ConditionalCheckFailedException(software.amazon.awssdk.services.dynamodb.model.ConditionalCheckFailedException)

Example 5 with ProcessInstanceDuplicatedException

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

the class DynamoDBProcessInstances method importInstance.

@Override
public ProcessInstance importInstance(ExportedProcessInstance instance, Process process) {
    ProcessInstance imported = marshaller.importProcessInstance(instance, process);
    if (exists(imported.id())) {
        throw new ProcessInstanceDuplicatedException(imported.id());
    }
    create(imported.id(), imported);
    return imported;
}
Also used : ProcessInstanceDuplicatedException(io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance)

Aggregations

ProcessInstanceDuplicatedException (io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException)16 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)9 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)9 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)6 TrustedIdentityProvider (io.automatiko.engine.api.auth.TrustedIdentityProvider)3 LinkedHashSet (java.util.LinkedHashSet)3 Model (io.automatiko.engine.api.Model)2 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 Document (org.bson.Document)2 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)1 QueryExecutionException (com.datastax.oss.driver.api.core.servererrors.QueryExecutionException)1 Insert (com.datastax.oss.driver.api.querybuilder.insert.Insert)1 ConflictingVersionException (io.automatiko.engine.api.workflow.ConflictingVersionException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1