Skip to content
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

Remove corresponding issues on branch delete #1224

Open
wants to merge 13 commits into
base: 9.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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 @@ -15,25 +15,44 @@
*/
package com.b2international.snowowl.core.branch;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.b2international.commons.exceptions.NotFoundException;
import com.b2international.index.revision.BaseRevisionBranching;
import com.b2international.snowowl.core.TerminologyResource;
import com.b2international.snowowl.core.authorization.AccessControl;
import com.b2international.snowowl.core.domain.RepositoryContext;
import com.b2international.snowowl.core.identity.Permission;
import com.b2international.snowowl.core.repository.PathTerminologyResourceResolver;

/**
* @since 4.1
*/
public final class BranchDeleteRequest extends BranchBaseRequest<Boolean> implements AccessControl {

private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LoggerFactory.getLogger(BranchDeleteRequest.class);

public BranchDeleteRequest(final String branchPath) {
super(branchPath);
}

@Override
public Boolean execute(RepositoryContext context) {
try {
//Remove branch
context.service(BaseRevisionBranching.class).delete(getBranchPath());

try {
//Schedule a job to remove issues corresponding to this branch
TerminologyResource resource = context.service(PathTerminologyResourceResolver.class).resolve(context, context.info().id(), getBranchPath());
String resourceURI = resource.getResourceURI(getBranchPath()).toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we have to treat the new tilde path variants (XZX~branch) as well here. Could you please add support for that?

context.service(ValidationCleanupService.class).scheduleStaleIssueRemoval(context, resourceURI);
} catch (Exception e) {
LOGGER.trace(String.format("Failed to remove validation issues associated with deleted branch %s", getBranchPath()), e);

Check warning on line 53 in core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/BranchDeleteRequest.java#L53

Added line #L53 was not covered by tests
}

} catch (NotFoundException e) {
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.b2international.snowowl.core.branch;
cmark marked this conversation as resolved.
Show resolved Hide resolved

import java.util.Collections;
import java.util.List;

import org.eclipse.core.runtime.jobs.ISchedulingRule;

import com.b2international.commons.CompareUtils;
import com.b2international.snowowl.core.ServiceProvider;
import com.b2international.snowowl.core.events.AsyncRequest;
import com.b2international.snowowl.core.identity.User;
import com.b2international.snowowl.core.jobs.JobRequests;
import com.b2international.snowowl.core.jobs.SerializableSchedulingRule;
import com.b2international.snowowl.core.validation.ValidationRequests;
import com.google.common.base.Joiner;

public class ValidationCleanupService {

public static final SerializableSchedulingRule VALIDATION_ISSUE_CLEANUP_RULE = new SerializableSchedulingRule() {

private static final long serialVersionUID = 1L;

@Override
public boolean isConflicting(ISchedulingRule rule) {
return rule == this;
}

@Override
public boolean contains(ISchedulingRule rule) {
return rule == this;
}
};

public ValidationCleanupService() {
}

public void scheduleStaleIssueRemoval(ServiceProvider context, String resourceURI) {
scheduleStaleIssueRemoval(context, List.of(resourceURI), Collections.emptyList());
}

public void scheduleStaleIssueRemoval(ServiceProvider context, List<String> resourceURIs) {
scheduleStaleIssueRemoval(context, resourceURIs, Collections.emptyList());
}

Check warning on line 43 in core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java#L42-L43

Added lines #L42 - L43 were not covered by tests

public void scheduleStaleIssueRemoval(ServiceProvider context, String resourceURI, List<String> resultIds) {
scheduleStaleIssueRemoval(context, List.of(resourceURI), resultIds);
}

Check warning on line 47 in core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java#L46-L47

Added lines #L46 - L47 were not covered by tests

public void scheduleStaleIssueRemoval(ServiceProvider context, List<String> resourceURIs, List<String> resultIds) {
AsyncRequest<Boolean> request;

if (!CompareUtils.isEmpty(resultIds)) {
request = ValidationRequests.issues()
.prepareDelete()
.setResultIds(resultIds)
.buildAsync();
} else {

Check warning on line 57 in core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java#L53-L57

Added lines #L53 - L57 were not covered by tests
if (CompareUtils.isEmpty(resourceURIs)) {
return;

Check warning on line 59 in core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/branch/ValidationCleanupService.java#L59

Added line #L59 was not covered by tests
}

request = ValidationRequests.issues()
.prepareDelete()
.setCodeSystemURIs(resourceURIs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the resourceURIs is null or empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing good, we shouldn't delete without resource uri filters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but that's a flaw in the API. If the caller should only use one input parameter, then we should split this method into two separate implementations instead of merging them into one with if else blocks.

.buildAsync();
}

final String description = String.format("Remove validation issues on stale/removed branch(es) of %s", Joiner.on(", ").join(resourceURIs));

JobRequests.prepareSchedule()
.setRequest(request)
.setDescription(description)
.setAutoClean(true)
.setSchedulingRule(VALIDATION_ISSUE_CLEANUP_RULE)
.build()
.execute(context);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.b2international.index.mapping.Mappings;
import com.b2international.index.query.Expressions;
import com.b2international.index.query.Query;
import com.b2international.snowowl.core.branch.ValidationCleanupService;
import com.b2international.snowowl.core.config.IndexSettings;
import com.b2international.snowowl.core.config.RepositoryConfiguration;
import com.b2international.snowowl.core.config.SnowOwlConfiguration;
Expand Down Expand Up @@ -106,6 +107,7 @@ public void preRun(SnowOwlConfiguration configuration, Environment env) throws E
env.services().registerService(ValidationConfiguration.class, validationConfig);
env.services().registerService(ValidationThreadPool.class, new ValidationThreadPool(numberOfValidationThreads, maxConcurrentExpensiveJobs, maxConcurrentNormalJobs));
env.services().registerService(ValidationIssueDetailExtensionProvider.class, new ValidationIssueDetailExtensionProvider(env.service(ClassPathScanner.class)));
env.services().registerService(ValidationCleanupService.class, new ValidationCleanupService());

final List<File> listOfFiles = validationDirectories.stream().flatMap(path -> Arrays.asList(path.toFile().listFiles()).stream()).toList();
final Set<File> validationRuleFiles = Sets.newHashSet();
Expand Down