Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static List<AuditEntry> createSampleAuditEntries() {
"developer1",
LocalDateTime.now().minusHours(1),
AuditEntry.Status.APPLIED,
AuditEntry.ExecutionType.EXECUTION,
AuditEntry.ChangeType.STANDARD_CODE,
"com.example.Change001",
"migrate",
"sourceFile",
Expand All @@ -112,7 +112,7 @@ public static List<AuditEntry> createSampleAuditEntries() {
"developer2",
LocalDateTime.now().minusMinutes(30),
AuditEntry.Status.FAILED,
AuditEntry.ExecutionType.EXECUTION,
AuditEntry.ChangeType.STANDARD_CODE,
"com.example.Change002",
"rollback",
"sourceFile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void testCompleteAuditEntryPersistenceInDynamoDB() {
auditEntry()
.withTaskId(changeId)
.withState(AuditEntry.Status.STARTED)
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClassName("io.flamingock.store.dynamodb.changes.audit._001__NonTxTransactionalFalseChange")
.withMethodName("apply")
.withTxType(AuditTxType.NON_TX)
Expand All @@ -122,7 +122,7 @@ void testCompleteAuditEntryPersistenceInDynamoDB() {
auditEntry()
.withTaskId(changeId)
.withState(AuditEntry.Status.APPLIED)
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClassName("io.flamingock.store.dynamodb.changes.audit._001__NonTxTransactionalFalseChange")
.withMethodName("apply")
.withTxType(AuditTxType.NON_TX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ void testCompleteAuditEntryPersistenceInMongoDB() {
})
.THEN_VerifyAuditSequenceStrict(
STARTED(changeId)
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_001__NonTxTransactionalFalseChange.class)
.withTxType(AuditTxType.NON_TX)
.withTargetSystemId("mongodb")
.withSystemChange(false)
.withTimestampBetween(testStart, testEnd),
APPLIED(changeId)
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_001__NonTxTransactionalFalseChange.class)
.withTxType(AuditTxType.NON_TX)
.withTargetSystemId("mongodb")
Expand Down Expand Up @@ -144,24 +144,24 @@ void testNonTxScenarios() {
.THEN_VerifyAuditSequenceStrict(
// First change (NonTxTransactionalFalseChange) - STARTED & EXECUTED
STARTED("non-tx-transactional-false")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_001__NonTxTransactionalFalseChange.class)
.withTxType(AuditTxType.NON_TX)
.withTargetSystemId("mongodb"),
APPLIED("non-tx-transactional-false")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_001__NonTxTransactionalFalseChange.class)
.withTxType(AuditTxType.NON_TX)
.withTargetSystemId("mongodb"),

// Second change (NonTxTargetSystemChange) - STARTED & EXECUTED
STARTED("non-tx-target-system")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_003__NonTxTargetSystemChange.class)
.withTxType(AuditTxType.NON_TX)
.withTargetSystemId("non-tx-system"),
APPLIED("non-tx-target-system")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_003__NonTxTargetSystemChange.class)
.withTxType(AuditTxType.NON_TX)
.withTargetSystemId("non-tx-system")
Expand Down Expand Up @@ -193,12 +193,12 @@ void testTxSharedScenarios() {
})
.THEN_VerifyAuditSequenceStrict(
STARTED("tx-shared-default")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_002__TxSharedDefaultChange.class)
.withTxType(AuditTxType.TX_SEPARATE_NO_MARKER)
.withTargetSystemId("mongodb"),
APPLIED("tx-shared-default")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_002__TxSharedDefaultChange.class)
.withTxType(AuditTxType.TX_SEPARATE_NO_MARKER)
.withTargetSystemId("mongodb")
Expand Down Expand Up @@ -229,12 +229,12 @@ void testTxNoMarkerWhenSameMongoClientButDifferentTargetSystem() {
})
.THEN_VerifyAuditSequenceStrict(
STARTED("tx-separate-no-marker")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_004__TxSeparateAndSameMongoClientChange.class)
.withTxType(AuditTxType.TX_SEPARATE_NO_MARKER)
.withTargetSystemId("mongo-system"),
APPLIED("tx-separate-no-marker")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_004__TxSeparateAndSameMongoClientChange.class)
.withTxType(AuditTxType.TX_SEPARATE_NO_MARKER)
.withTargetSystemId("mongo-system")
Expand Down Expand Up @@ -266,12 +266,12 @@ void testTxSeparateNoMarkerScenario() {
})
.THEN_VerifyAuditSequenceStrict(
STARTED("tx-separate-no-marker")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_005__TxSeparateChange.class)
.withTxType(AuditTxType.TX_SEPARATE_NO_MARKER)
.withTargetSystemId("tx-separate-system"),
APPLIED("tx-separate-no-marker")
.withType(AuditEntry.ExecutionType.EXECUTION)
.withType(AuditEntry.ChangeType.STANDARD_CODE)
.withClass(_005__TxSeparateChange.class)
.withTxType(AuditTxType.TX_SEPARATE_NO_MARKER)
.withTargetSystemId("tx-separate-system")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public List<AuditEntry> getAuditHistory() {
rs.getString("author"),
rs.getTimestamp("created_at").toLocalDateTime(),
rs.getString("state") != null ? AuditEntry.Status.valueOf(rs.getString("state")) : null,
rs.getString("type") != null ? AuditEntry.ExecutionType.valueOf(rs.getString("type")) : null,
rs.getString("type") != null ? AuditEntry.ChangeType.valueOf(rs.getString("type")) : null,
rs.getString("invoked_class"),
rs.getString("invoked_method"),
rs.getString("source_file"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,31 @@

public class AuditEntryRequest {

public enum ExecutionType {EXECUTION}

public enum Status {
STARTED,
APPLIED,
FAILED,
ROLLED_BACK,
ROLLBACK_FAILED,
MANUAL_MARKED_AS_APPLIED,
MANUAL_MARKED_AS_ROLLED_BACK
}

private final String stageId;

private final String taskId;

private final String author;

private final long appliedAtEpochMillis;

private final Status state;

private final String className;

private final String methodName;

private final Object metadata;

private final long executionMillis;

private final String executionHostname;

private final String errorTrace;

private final ExecutionType type;

private final ChangeType type;
private final AuditTxType txStrategy;

private final String targetSystemId;

private final String order;

private final RecoveryStrategy recoveryStrategy;

protected Boolean systemChange;//TODO not in server

private final Boolean transactionFlag;
protected Boolean systemChange;//TODO not in server

public AuditEntryRequest(String stageId,
String taskId,
String author,
long appliedAtEpochMillis,
Status state,
ExecutionType type,
ChangeType type,
String className,
String methodName,
long executionMillis,
Expand Down Expand Up @@ -155,7 +126,7 @@ public Boolean getSystemChange() {
return systemChange;
}

public ExecutionType getType() {
public ChangeType getType() {
return type;
}

Expand All @@ -179,6 +150,18 @@ public Boolean getTransactionFlag() {
return transactionFlag;
}

public enum ChangeType {STANDARD_CODE, STANDARD_TEMPLATE, MONGOCK_EXECUTION, MONGOCK_BEFORE}

public enum Status {
STARTED,
APPLIED,
FAILED,
ROLLED_BACK,
ROLLBACK_FAILED,
MANUAL_MARKED_AS_APPLIED,
MANUAL_MARKED_AS_ROLLED_BACK
}


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AuditEntry implements Comparable<AuditEntry> {
private final long executionMillis;
private final String executionHostname;
private final String errorTrace;
private final ExecutionType type;
private final ChangeType type;
private final AuditTxType txStrategy;
private final String targetSystemId;
private final String order;
Expand All @@ -51,7 +51,7 @@ public AuditEntry(String executionId,
String author,
LocalDateTime timestamp,
Status state,
ExecutionType type,
ChangeType type,
String className,
String methodName,
String sourceFile,
Expand Down Expand Up @@ -100,7 +100,7 @@ public AuditEntry(String executionId,
String author,
LocalDateTime timestamp,
Status state,
ExecutionType type,
ChangeType type,
String className,
String methodName,
String sourceFile,
Expand All @@ -125,7 +125,7 @@ public AuditEntry(String executionId,
String author,
LocalDateTime timestamp,
Status state,
ExecutionType type,
ChangeType type,
String className,
String methodName,
String sourceFile,
Expand Down Expand Up @@ -207,7 +207,7 @@ public boolean isLegacy() {
return legacy;
}

public ExecutionType getType() {
public ChangeType getType() {
return type;
}

Expand Down Expand Up @@ -318,24 +318,18 @@ public boolean hasHigherPriorityThan(Status other) {
return this.priority > other.priority;
}



public static boolean isRequiredExecution(Status entryStatus) {
return entryStatus == null || entryStatus == FAILED || entryStatus == ROLLED_BACK || entryStatus == ROLLBACK_FAILED;
}

public AuditEntryRequest.Status toRequestStatus() {
return AuditEntryRequest.Status.valueOf(name());
}

}

//TODO remove this
public enum ExecutionType {
EXECUTION;
public enum ChangeType {
STANDARD_CODE, STANDARD_TEMPLATE, MONGOCK_EXECUTION, MONGOCK_BEFORE;

public AuditEntryRequest.ExecutionType toRequestExecutionType() {
return AuditEntryRequest.ExecutionType.valueOf(name());
public AuditEntryRequest.ChangeType toRequestExecutionType() {
return AuditEntryRequest.ChangeType.valueOf(name());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import io.flamingock.internal.core.pipeline.execution.ExecutionContext;
import io.flamingock.internal.common.core.task.TaskDescriptor;

import static io.flamingock.internal.common.core.audit.AuditEntry.ChangeType.MONGOCK_BEFORE;
import static io.flamingock.internal.common.core.audit.AuditEntry.ChangeType.MONGOCK_EXECUTION;
import static io.flamingock.internal.common.core.audit.AuditEntry.ChangeType.STANDARD_CODE;

public abstract class AuditContextBundle {


Expand All @@ -40,20 +44,20 @@ public static AuditContextBundle.Operation fromOngoingStatusOperation(TargetSyst
}

private final Operation operation;
private final TaskDescriptor loadedTask;
private final TaskDescriptor changeDescriptor;
private final ExecutionContext executionContext;
private final RuntimeContext runtimeContext;
private final AuditTxType operationType;
private final String targetSystemId;

public AuditContextBundle(Operation operation,
TaskDescriptor loadedTask,
TaskDescriptor changeDescriptor,
ExecutionContext executionContext,
RuntimeContext runtimeContext,
AuditTxType auditTxType,
String targetSystemId) {
this.operation = operation;
this.loadedTask = loadedTask;
this.changeDescriptor = changeDescriptor;
this.executionContext = executionContext;
this.runtimeContext = runtimeContext;
this.operationType = auditTxType;
Expand All @@ -64,8 +68,8 @@ public Operation getOperation() {
return operation;
}

public TaskDescriptor getLoadedTask() {
return loadedTask;
public TaskDescriptor getChangeDescriptor() {
return changeDescriptor;
}

public ExecutionContext getExecutionContext() {
Expand All @@ -86,7 +90,7 @@ public String getTargetSystemId() {


public AuditEntry toAuditEntry() {
TaskDescriptor loadedChange = getLoadedTask();
TaskDescriptor loadedChange = getChangeDescriptor();
ExecutionContext stageExecutionContext = getExecutionContext();
RuntimeContext runtimeContext = getRuntimeContext();

Expand All @@ -97,7 +101,7 @@ public AuditEntry toAuditEntry() {
loadedChange.getAuthor(),
runtimeContext.getAppliedAt(),
getAuditStatus(),
getExecutionType(),
getChangeType(),
loadedChange.getSource(),
runtimeContext.getMethodExecutor(),
null, //TODO: set sourceFile
Expand Down Expand Up @@ -127,8 +131,16 @@ private AuditEntry.Status getAuditStatus() {
}
}

private AuditEntry.ExecutionType getExecutionType() {
return AuditEntry.ExecutionType.EXECUTION;
private AuditEntry.ChangeType getChangeType() {
if(changeDescriptor.isLegacy()) {
//TODO improve the way we retrieve mongock before
return changeDescriptor.getId().endsWith("_before")
? MONGOCK_BEFORE
: MONGOCK_EXECUTION;
} else {
//TODO update this when template is released
return STANDARD_CODE;
}
}


Expand Down
Loading
Loading