Search in sources :

Example 6 with Context

use of io.fabric8.mockwebserver.Context in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method setFileConfigurations.

private void setFileConfigurations(GitContext context, final String versionId, final String profileId, final Map<String, byte[]> fileConfigurations) throws IOException, GitAPIException {
    assertWriteLock();
    // Delete and remove stale file configurations
    File profileDir = GitHelpers.getProfileDirectory(getGit(), profileId);
    final HashSet<File> filesToDelete = new HashSet<File>();
    if (profileDir.exists()) {
        final List<File> filesList = new ArrayList<File>();
        java.nio.file.Files.walkFileTree(profileDir.toPath(), new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
                if (!Constants.AGENT_PROPERTIES.equals(path.getFileName().toString())) {
                    filesToDelete.add(path.toFile());
                }
                return super.visitFile(path, attrs);
            }
        });
    }
    for (Map.Entry<String, byte[]> entry : fileConfigurations.entrySet()) {
        String fileName = entry.getKey();
        byte[] newCfg = entry.getValue();
        setFileConfiguration(getGit(), profileId, fileName, newCfg);
        filesToDelete.remove(new File(profileDir, fileName));
    }
    for (File file : filesToDelete) {
        recursiveDeleteAndRemove(getGit(), file);
    }
    if (!fileConfigurations.isEmpty() || !filesToDelete.isEmpty()) {
        context.commitMessage("Update configurations for profile: " + profileId);
    }
}
Also used : Path(java.nio.file.Path) ZkPath(io.fabric8.zookeeper.ZkPath) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) File(java.io.File) LockFile(org.eclipse.jgit.internal.storage.file.LockFile) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 7 with Context

use of io.fabric8.mockwebserver.Context 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 8 with Context

use of io.fabric8.mockwebserver.Context 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 9 with Context

use of io.fabric8.mockwebserver.Context 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)

Example 10 with Context

use of io.fabric8.mockwebserver.Context in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method doPullInternal.

private PullPolicyResult doPullInternal(GitContext context, CredentialsProvider credentialsProvider, boolean allowVersionDelete, boolean allowPush, int forcedTimeoutInSeconds) {
    PullPolicyResult pullResult = pullPushPolicy.doPull(context, credentialsProvider, allowVersionDelete, allowPush, forcedTimeoutInSeconds);
    if (pullResult.getLastException() == null) {
        Map<String, PullPushPolicy.BranchChange> updatedVersions = pullResult.localUpdateVersions();
        if (!updatedVersions.isEmpty()) {
            if (updatedVersions.containsKey(GitHelpers.MASTER_BRANCH)) {
                versionCache.invalidateAll();
            } else {
                for (String version : updatedVersions.keySet()) {
                    versionCache.invalidate(version);
                }
            }
            notificationRequired = true;
        }
        Set<String> pullVersions = pullResult.getVersions();
        if (!pullVersions.isEmpty() && !pullVersions.equals(versions)) {
            versions.clear();
            for (String v : pullVersions) {
                if (!v.startsWith("patches-") && !v.startsWith("patch-") && !v.equals(HISTORY_BRANCH) && !v.equals(ADMIN_HISTORY_BRANCH)) {
                    versions.add(v);
                }
            }
        }
        if (pullResult.remoteUpdateRequired()) {
            doPushInternal(context, credentialsProvider);
        }
    }
    return pullResult;
}
Also used : PullPolicyResult(io.fabric8.git.PullPushPolicy.PullPolicyResult)

Aggregations

Test (org.junit.jupiter.api.Test)593 Checkpoint (io.vertx.junit5.Checkpoint)574 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)543 VertxTestContext (io.vertx.junit5.VertxTestContext)542 Vertx (io.vertx.core.Vertx)539 Reconciliation (io.strimzi.operator.common.Reconciliation)532 VertxExtension (io.vertx.junit5.VertxExtension)514 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)514 BeforeAll (org.junit.jupiter.api.BeforeAll)466 AfterAll (org.junit.jupiter.api.AfterAll)462 CoreMatchers.is (org.hamcrest.CoreMatchers.is)458 Future (io.vertx.core.Future)429 Mockito.when (org.mockito.Mockito.when)410 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)379 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)368 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)360 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)356 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)352 List (java.util.List)352 KubernetesVersion (io.strimzi.operator.KubernetesVersion)344