Search in sources :

Example 6 with LockHandle

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();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext)

Example 7 with LockHandle

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();
    }
}
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 8 with LockHandle

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();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext) Profile(io.fabric8.api.Profile)

Example 9 with LockHandle

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();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) RefSpec(org.eclipse.jgit.transport.RefSpec) GitContext(io.fabric8.api.GitContext)

Example 10 with LockHandle

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();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext) File(java.io.File) LockFile(org.eclipse.jgit.internal.storage.file.LockFile)

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