Search in sources :

Example 1 with LockHandle

use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method gitOperation.

@Override
public <T> T gitOperation(GitContext context, GitOperation<T> gitop, PersonIdent personIdent) {
    IllegalArgumentAssertion.assertNotNull(gitop, "gitop");
    IllegalArgumentAssertion.assertNotNull(context, "context");
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        LOGGER.debug("External call to execute a git operation: " + gitop);
        return executeInternal(context, personIdent, gitop);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle)

Example 2 with LockHandle

use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method getVersionFromCacheRW.

private Version getVersionFromCacheRW(String versionId, String profileId) {
    try {
        initialVersionsAvailable.await(15, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        LOGGER.warn("Waiting for initial versions failed");
    }
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        String branch = GitHelpers.getProfileBranch(versionId, profileId);
        if (GitHelpers.localBranchExists(getGit(), branch)) {
            return versionCache.get(versionId);
        } else {
            return null;
        }
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) FabricException(io.fabric8.api.FabricException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException)

Example 3 with LockHandle

use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method gitVersions.

@Override
public GitVersions gitVersions() {
    LockHandle readLock = aquireReadLock();
    try {
        assertValid();
        GitOperation<GitVersions> gitop = new GitOperation<GitVersions>() {

            public GitVersions call(Git git, GitContext context) throws Exception {
                List<GitVersion> localVersions = GitHelpers.gitVersions(git);
                return new GitVersions(localVersions);
            }
        };
        return executeInternal(newGitReadContext(), null, gitop);
    } finally {
        readLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitVersion(io.fabric8.api.commands.GitVersion) GitVersions(io.fabric8.api.commands.GitVersions) GitContext(io.fabric8.api.GitContext)

Example 4 with LockHandle

use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method createProfile.

@Override
public String createProfile(GitContext context, final Profile profile) {
    IllegalStateAssertion.assertNotNull(profile, "profile");
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        GitOperation<String> gitop = new GitOperation<String>() {

            public String call(Git git, GitContext context) throws Exception {
                String versionId = profile.getVersion();
                String profileId = profile.getId();
                Version version = getRequiredVersion(versionId);
                IllegalStateAssertion.assertFalse(version.hasProfile(profileId), "Profile already exists: " + profileId);
                checkoutRequiredProfileBranch(git, context, versionId, profileId);
                return createOrUpdateProfile(context, null, profile, new HashSet<String>());
            }
        };
        return executeInternal(context, null, gitop);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext) GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version)

Example 5 with LockHandle

use of io.fabric8.api.LockHandle in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method hasVersion.

@Override
public boolean hasVersion(GitContext context, final String versionId) {
    IllegalStateAssertion.assertNotNull(versionId, "versionId");
    LockHandle readLock = aquireReadLock();
    try {
        assertValid();
        GitOperation<Boolean> gitop = new GitOperation<Boolean>() {

            public Boolean call(Git git, GitContext context) throws Exception {
                return versions.contains(versionId);
            }
        };
        return executeInternal(context, null, gitop);
    } finally {
        readLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext)

Aggregations

LockHandle (io.fabric8.api.LockHandle)20 GitContext (io.fabric8.api.GitContext)13 Git (org.eclipse.jgit.api.Git)13 Profile (io.fabric8.api.Profile)4 FabricException (io.fabric8.api.FabricException)3 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 KeeperException (org.apache.zookeeper.KeeperException)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 Version (io.fabric8.api.Version)2 GitVersion (io.fabric8.api.commands.GitVersion)2 File (java.io.File)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 DataStoreTemplate (io.fabric8.api.DataStoreTemplate)1 ProfileBuilder (io.fabric8.api.ProfileBuilder)1 VersionBuilder (io.fabric8.api.VersionBuilder)1 GitVersions (io.fabric8.api.commands.GitVersions)1 GitProxyService (io.fabric8.git.GitProxyService)1 PushPolicyResult (io.fabric8.git.PullPushPolicy.PushPolicyResult)1 ProxySelector (java.net.ProxySelector)1