-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: added interface changes to the server #38258
Changes from 3 commits
ebf4a08
7b40ee7
08196a8
bf58cb1
4744ff6
e510ca6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,17 +419,21 @@ protected Mono<? extends Artifact> checkoutReference( | |
}); | ||
} else { | ||
// TODO refactor method to account for RefName as well | ||
checkedOutArtifactMono = Mono.defer(() -> gitArtifactHelper | ||
.getArtifactByBaseIdAndBranchName( | ||
baseArtifactId, finalRefName, gitArtifactHelper.getArtifactReadPermission()) | ||
checkedOutArtifactMono = gitHandlingService | ||
.checkoutArtifact(jsonTransformationDTO) | ||
.flatMap(isCheckedOut -> gitArtifactHelper.getArtifactByBaseIdAndBranchName( | ||
baseArtifactId, finalRefName, gitArtifactHelper.getArtifactReadPermission())) | ||
.flatMap(artifact -> gitAnalyticsUtils.addAnalyticsForGitOperation( | ||
AnalyticsEvents.GIT_CHECKOUT_BRANCH, | ||
artifact, | ||
artifact.getGitArtifactMetadata().getIsRepoPrivate()))); | ||
artifact.getGitArtifactMetadata().getIsRepoPrivate())); | ||
} | ||
|
||
return checkedOutArtifactMono | ||
.doFinally(signalType -> gitRedisUtils.releaseFileLock(baseArtifactId, addFileLock)) | ||
return acquireFileLock | ||
.then(checkedOutArtifactMono) | ||
.flatMap(checkedOutArtifact -> gitRedisUtils | ||
.releaseFileLock(baseArtifactId, addFileLock) | ||
.thenReturn(checkedOutArtifact)) | ||
.tag(GitConstants.GitMetricConstants.CHECKOUT_REMOTE, FALSE.toString()) | ||
.name(GitSpan.OPS_CHECKOUT_BRANCH) | ||
.tap(Micrometer.observation(observationRegistry)) | ||
|
@@ -522,6 +526,9 @@ public Mono<? extends Artifact> createReference( | |
FieldName.BRANCH_NAME)); | ||
} | ||
|
||
Mono<Boolean> refCreationValidationMono = isValidationForRefCreationComplete( | ||
baseArtifact, parentArtifact, gitType, refType); | ||
|
||
Mono<? extends ArtifactExchangeJson> artifactExchangeJsonMono = | ||
exportService.exportByArtifactId( | ||
parentArtifact.getId(), VERSION_CONTROL, artifactType); | ||
|
@@ -531,15 +538,24 @@ public Mono<? extends Artifact> createReference( | |
gitArtifactHelper.createNewArtifactForCheckout( | ||
parentArtifact, refDTO.getRefName()); | ||
|
||
return Mono.zip(newArtifactFromSourceMono, artifactExchangeJsonMono); | ||
return refCreationValidationMono.flatMap(isOkayToProceed -> { | ||
if (!TRUE.equals(isOkayToProceed)) { | ||
return Mono.error(new AppsmithException( | ||
AppsmithError.GIT_ACTION_FAILED, | ||
"ref creation", | ||
"status unclean")); | ||
} | ||
|
||
return Mono.zip(newArtifactFromSourceMono, artifactExchangeJsonMono); | ||
}); | ||
})) | ||
.flatMap(tuple -> { | ||
ArtifactExchangeJson exportedJson = tuple.getT2(); | ||
Artifact newRefArtifact = tuple.getT1(); | ||
|
||
Mono<String> refCreationMono = gitHandlingService | ||
.createGitReference(jsonTransformationDTO) | ||
// TODO: ths error could be shipped to handling layer as well? | ||
.createGitReference(jsonTransformationDTO, refDTO) | ||
// TODO: this error could be shipped to handling layer as well? | ||
.onErrorResume(error -> Mono.error(new AppsmithException( | ||
AppsmithError.GIT_ACTION_FAILED, | ||
"ref creation preparation", | ||
|
@@ -553,25 +569,44 @@ public Mono<? extends Artifact> createReference( | |
exportedJson, | ||
refDTO.getRefName()); | ||
}) | ||
// after the branch is created, we need to reset the older branch to initial | ||
// commit | ||
.flatMap(importedArtifact -> { | ||
return gitArtifactHelper.publishArtifactPostRefCreation( | ||
importedArtifact, refType, TRUE); | ||
}) | ||
// after the branch is created, we need to reset the older branch to the | ||
// clean status, i.e. last commit | ||
.doOnSuccess(newImportedArtifact -> | ||
discardChanges(parentArtifact.getId(), artifactType, gitType)); | ||
}); | ||
}) | ||
.flatMap(newImportedArtifact -> gitAnalyticsUtils | ||
.addAnalyticsForGitOperation( | ||
.flatMap(newImportedArtifact -> gitRedisUtils | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will we release in case of errors? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No release in chain |
||
.releaseFileLock( | ||
newImportedArtifact.getGitArtifactMetadata().getDefaultArtifactId(), TRUE) | ||
.then(gitAnalyticsUtils.addAnalyticsForGitOperation( | ||
AnalyticsEvents.GIT_CREATE_BRANCH, | ||
newImportedArtifact, | ||
newImportedArtifact.getGitArtifactMetadata().getIsRepoPrivate()) | ||
.doFinally(signalType -> gitRedisUtils.releaseFileLock( | ||
newImportedArtifact.getGitArtifactMetadata().getDefaultArtifactId(), TRUE))) | ||
newImportedArtifact.getGitArtifactMetadata().getIsRepoPrivate()))) | ||
.name(GitSpan.OPS_CREATE_BRANCH) | ||
.tap(Micrometer.observation(observationRegistry)); | ||
|
||
return Mono.create(sink -> createBranchMono.subscribe(sink::success, sink::error, null, sink.currentContext())); | ||
} | ||
|
||
protected Mono<Boolean> isValidationForRefCreationComplete( | ||
Artifact baseArtifact, Artifact parentArtifact, GitType gitType, RefType refType) { | ||
if (RefType.BRANCH.equals(refType)) { | ||
return Mono.just(TRUE); | ||
} | ||
|
||
return getStatus(baseArtifact, parentArtifact, false, true, gitType).map(gitStatusDTO -> { | ||
if (!Boolean.TRUE.equals(gitStatusDTO.getIsClean())) { | ||
return FALSE; | ||
} | ||
|
||
return TRUE; | ||
}); | ||
} | ||
Comment on lines
+603
to
+616
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding validation for tag name format The reference creation validation method should also validate the tag name format when RefType is TAG. protected Mono<Boolean> isValidationForRefCreationComplete(
Artifact baseArtifact, Artifact parentArtifact, GitType gitType, RefType refType) {
if (RefType.BRANCH.equals(refType)) {
return Mono.just(TRUE);
}
+ if (RefType.TAG.equals(refType)) {
+ String tagName = parentArtifact.getGitArtifactMetadata().getRefName();
+ if (!isValidTagName(tagName)) {
+ return Mono.just(FALSE);
+ }
+ }
return getStatus(baseArtifact, parentArtifact, false, true, gitType).map(gitStatusDTO -> {
|
||
|
||
@Override | ||
public Mono<? extends Artifact> deleteGitReference( | ||
String baseArtifactId, GitRefDTO gitRefDTO, ArtifactType artifactType, GitType gitType) { | ||
|
@@ -650,7 +685,9 @@ protected Mono<? extends Artifact> deleteGitReference( | |
|
||
return gitHandlingService | ||
.deleteGitReference(jsonTransformationDTO) | ||
.doFinally(signalType -> gitRedisUtils.releaseFileLock(baseArtifactId, TRUE)) | ||
.flatMap(isReferenceDeleted -> gitRedisUtils | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same error handling question for all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No release in chain |
||
.releaseFileLock(baseArtifactId, TRUE) | ||
.thenReturn(isReferenceDeleted)) | ||
.flatMap(isReferenceDeleted -> { | ||
if (FALSE.equals(isReferenceDeleted)) { | ||
return Mono.error(new AppsmithException( | ||
|
@@ -1384,10 +1421,16 @@ protected Mono<GitStatusDTO> getStatus( | |
fetchRemoteMono = Mono.just("ignored"); | ||
} | ||
|
||
return Mono.zip(prepareForStatus, fetchRemoteMono) | ||
.then(gitHandlingService.getStatus(jsonTransformationDTO)); | ||
return Mono.zip(prepareForStatus, fetchRemoteMono).flatMap(tuple2 -> { | ||
return gitHandlingService | ||
.getStatus(jsonTransformationDTO) | ||
.flatMap(gitStatusDTO -> { | ||
return gitRedisUtils | ||
.releaseFileLock(baseArtifactId, isFileLock) | ||
.thenReturn(gitStatusDTO); | ||
}); | ||
}); | ||
}) | ||
.doFinally(signalType -> gitRedisUtils.releaseFileLock(baseArtifactId, isFileLock)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No release in chain |
||
.onErrorResume(throwable -> { | ||
/* | ||
in case of any error, the global exception handler will release the lock | ||
|
@@ -1640,11 +1683,12 @@ public Mono<? extends Artifact> discardChanges( | |
new AppsmithException(AppsmithError.INVALID_GIT_CONFIGURATION, GIT_CONFIG_ERROR)); | ||
} | ||
|
||
return Mono.just(branchedArtifact) | ||
.doFinally(signalType -> gitRedisUtils.acquireGitLock( | ||
return gitRedisUtils | ||
.acquireGitLock( | ||
branchedGitData.getDefaultArtifactId(), | ||
GitConstants.GitCommandConstants.DISCARD, | ||
TRUE)); | ||
TRUE) | ||
.thenReturn(branchedArtifact); | ||
}) | ||
.flatMap(branchedArtifact -> { | ||
GitArtifactMetadata branchedGitData = branchedArtifact.getGitArtifactMetadata(); | ||
|
@@ -1677,10 +1721,13 @@ public Mono<? extends Artifact> discardChanges( | |
// Update the last deployed status after the rebase | ||
.flatMap(importedArtifact -> gitArtifactHelper.publishArtifact(importedArtifact, true)); | ||
}) | ||
.flatMap(branchedArtifact -> gitAnalyticsUtils | ||
.addAnalyticsForGitOperation(AnalyticsEvents.GIT_DISCARD_CHANGES, branchedArtifact, null) | ||
.doFinally(signalType -> gitRedisUtils.releaseFileLock( | ||
branchedArtifact.getGitArtifactMetadata().getDefaultArtifactId(), TRUE))) | ||
.flatMap(branchedArtifact -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No release in chain |
||
return gitRedisUtils | ||
.releaseFileLock( | ||
branchedArtifact.getGitArtifactMetadata().getDefaultArtifactId(), TRUE) | ||
.then(gitAnalyticsUtils.addAnalyticsForGitOperation( | ||
AnalyticsEvents.GIT_DISCARD_CHANGES, branchedArtifact, null)); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding retry mechanism for lock release Lock release is critical for preventing deadlocks. Consider adding a retry mechanism with exponential backoff. .flatMap(branchedArtifact -> {
return gitRedisUtils
.releaseFileLock(
branchedArtifact.getGitArtifactMetadata().getDefaultArtifactId(), TRUE)
+ .retryWhen(Retry.backoff(3, Duration.ofMillis(100))
+ .filter(throwable -> throwable instanceof LockAcquisitionException))
.then(gitAnalyticsUtils.addAnalyticsForGitOperation(
AnalyticsEvents.GIT_DISCARD_CHANGES, branchedArtifact, null));
})
|
||
.name(GitSpan.OPS_DISCARD_CHANGES) | ||
.tap(Micrometer.observation(observationRegistry)); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sondermanish doesn't look like this one has a release in the chain