use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.
the class DummyBatchingProgressMonitor method getVersionIds.
@Override
public List<String> getVersionIds(GitContext context) {
LockHandle readLock = aquireReadLock();
try {
assertValid();
GitOperation<List<String>> gitop = new GitOperation<List<String>>() {
public List<String> call(Git git, GitContext context) throws Exception {
List<String> result = new ArrayList<>(versions);
// we do not want to expose master branch as a version
if (result.contains(GitHelpers.MASTER_BRANCH)) {
result.remove(GitHelpers.MASTER_BRANCH);
}
Collections.sort(result, VersionSequence.getComparator());
return Collections.unmodifiableList(result);
}
};
return executeInternal(context, null, gitop);
} finally {
readLock.unlock();
}
}
use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.
the class DummyBatchingProgressMonitor method getVersionFromCacheRO.
private Version getVersionFromCacheRO(String versionId, String profileId) {
LockHandle readLock = aquireReadLock();
try {
assertValid();
String branch = GitHelpers.getProfileBranch(versionId, profileId);
if (GitHelpers.localBranchExists(getGit(), branch)) {
if (versionCache.asMap().containsKey(versionId)) {
return versionCache.asMap().get(versionId);
} else {
return null;
}
} else {
return null;
}
} catch (Exception e) {
throw FabricException.launderThrowable(e);
} finally {
readLock.unlock();
}
}
use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.
the class DummyBatchingProgressMonitor method updateProfile.
@Override
public String updateProfile(GitContext context, final Profile profile, boolean force) {
IllegalStateAssertion.assertNotNull(profile, "profile");
LockHandle writeLock = aquireWriteLock();
try {
assertValid();
// Get the existing profile
final String versionId = profile.getVersion();
final String profileId = profile.getId();
final Profile lastProfile = getRequiredProfile(versionId, profileId);
if (force || !lastProfile.equals(profile)) {
GitOperation<String> gitop = new GitOperation<String>() {
public String call(Git git, GitContext context) throws Exception {
checkoutRequiredProfileBranch(git, context, versionId, profileId);
return createOrUpdateProfile(context, lastProfile, profile, new HashSet<String>());
}
};
return executeInternal(context, null, gitop);
} else {
LOGGER.debug("Skip unchanged profile update for: {}", profile);
return lastProfile.getId();
}
} finally {
writeLock.unlock();
}
}
use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.
the class DummyBatchingProgressMonitor method deleteVersion.
@Override
public void deleteVersion(GitContext context, final String versionId) {
IllegalStateAssertion.assertNotNull(versionId, "versionId");
LockHandle writeLock = aquireWriteLock();
try {
assertValid();
LOGGER.debug("Delete version: " + versionId);
GitOperation<Void> gitop = new GitOperation<Void>() {
public Void call(Git git, GitContext context) throws Exception {
removeVersionFromCaches(versionId);
GitHelpers.removeBranch(git, versionId);
git.push().setTimeout(gitTimeout).setCredentialsProvider(getCredentialsProvider()).setRefSpecs(new RefSpec().setSource(null).setDestination("refs/heads/" + versionId)).call();
return null;
}
};
executeInternal(context, null, gitop);
} finally {
writeLock.unlock();
}
}
use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.
the class DummyBatchingProgressMonitor method deleteProfile.
@Override
public void deleteProfile(GitContext context, final String versionId, final String profileId) {
IllegalStateAssertion.assertNotNull(versionId, "versionId");
IllegalStateAssertion.assertNotNull(profileId, "profileId");
LockHandle writeLock = aquireWriteLock();
try {
assertValid();
LOGGER.debug("Delete " + ProfileBuilder.Factory.create(versionId, profileId).getProfile());
GitOperation<Void> gitop = new GitOperation<Void>() {
public Void call(Git git, GitContext context) throws Exception {
checkoutRequiredProfileBranch(git, context, versionId, profileId);
File profileDirectory = GitHelpers.getProfileDirectory(git, profileId);
recursiveDeleteAndRemove(git, profileDirectory);
context.commitMessage("Removed profile " + profileId);
return null;
}
};
executeInternal(context, null, gitop);
} finally {
writeLock.unlock();
}
}
Aggregations