Search in sources :

Example 56 with io.fabric8.kubernetes.api.model

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

the class FabricGitSynchronizeAction method performContainerAction.

@Override
protected void performContainerAction(String queuePath, String containerName) throws Exception {
    String command = map(new JMXRequest().withObjectName("io.fabric8:type=Fabric").withMethod("gitSynchronize").withDelay(randomDelay).withParam(Boolean.class, allowPush));
    curator.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL).forPath(queuePath, PublicStringSerializer.serialize(command));
}
Also used : JMXRequest(io.fabric8.api.commands.JMXRequest)

Example 57 with io.fabric8.kubernetes.api.model

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

the class PushPullPolicyIT method remoteUpdateWhenLocalBranchIsAheadButNoPushIsAllowed.

@Test
public void remoteUpdateWhenLocalBranchIsAheadButNoPushIsAllowed() throws GitAPIException, IOException {
    editVersion("1.1", 2, true, "fabric/profiles/default.profile/io.fabric8.other.properties");
    editVersion("1.1", 2, false);
    ObjectId branch1_1local = local.getRepository().getRef("refs/heads/1.1").getObjectId();
    ObjectId branch1_1remote = servlet.getRepository().getRef("refs/heads/1.1").getObjectId();
    assertThat(branch1_1local, not(equalTo(branch1_1remote)));
    local.checkout().setName("1.0").setCreateBranch(false).call();
    assertTrue(local.status().call().isClean());
    PullPushPolicy.PullPolicyResult result = policy.doPull(new GitContext(), CP, true, false);
    assertNull(result.getLastException());
    List<String> versions = new ArrayList<>(result.getVersions());
    // these are sorted (TreeSet)
    assertThat(versions.size(), equalTo(5));
    assertThat(versions.get(0), equalTo("1.0"));
    assertThat(versions.get(1), equalTo("1.0.1"));
    assertThat(versions.get(2), equalTo("1.1"));
    assertThat(versions.get(3), equalTo("1.2"));
    assertThat(versions.get(4), equalTo("master"));
    List<String> localUpdateVersions = new ArrayList<>(result.localUpdateVersions().keySet());
    assertThat(localUpdateVersions.size(), equalTo(1));
    assertThat(localUpdateVersions.get(0), equalTo("1.1"));
    assertFalse(result.remoteUpdateRequired());
    assertTrue(local.status().call().isClean());
    List<Ref> localBranches = local.branchList().call();
    assertThat(localBranches.size(), equalTo(5));
    assertNotNull(local.getRepository().getRef("1.1"));
    assertThat("Local branch should change (will be reset to remote)", local.getRepository().getRef("refs/heads/1.1").getObjectId(), equalTo(branch1_1remote));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) GitContext(io.fabric8.api.GitContext) ArrayList(java.util.ArrayList) DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) Test(org.junit.Test)

Example 58 with io.fabric8.kubernetes.api.model

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

the class PushPullPolicyIT method remoteUpdateWhenLocalBranchIsAhead.

@Test
public void remoteUpdateWhenLocalBranchIsAhead() throws GitAPIException, IOException {
    editVersion("1.1", 2, true, "fabric/profiles/default.profile/io.fabric8.other.properties");
    editVersion("1.1", 2, false);
    ObjectId branch1_1local = local.getRepository().getRef("refs/heads/1.1").getObjectId();
    ObjectId branch1_1remote = servlet.getRepository().getRef("refs/heads/1.1").getObjectId();
    assertThat(branch1_1local, not(equalTo(branch1_1remote)));
    local.checkout().setName("1.0").setCreateBranch(false).call();
    assertTrue(local.status().call().isClean());
    PullPushPolicy.PullPolicyResult result = policy.doPull(new GitContext(), CP, true);
    assertNull(result.getLastException());
    List<String> versions = new ArrayList<>(result.getVersions());
    // these are sorted (TreeSet)
    assertThat(versions.size(), equalTo(5));
    assertThat(versions.get(0), equalTo("1.0"));
    assertThat(versions.get(1), equalTo("1.0.1"));
    assertThat(versions.get(2), equalTo("1.1"));
    assertThat(versions.get(3), equalTo("1.2"));
    assertThat(versions.get(4), equalTo("master"));
    List<String> localUpdateVersions = new ArrayList<>(result.localUpdateVersions().keySet());
    assertThat(localUpdateVersions.size(), equalTo(1));
    assertThat(localUpdateVersions.get(0), equalTo("1.1"));
    assertTrue(result.remoteUpdateRequired());
    assertTrue(local.status().call().isClean());
    List<Ref> localBranches = local.branchList().call();
    assertThat(localBranches.size(), equalTo(5));
    assertNotNull(local.getRepository().getRef("1.1"));
    assertThat("Local branch should change by rebase on top of what's in remote", local.getRepository().getRef("refs/heads/1.1").getObjectId(), not(equalTo(branch1_1remote)));
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) GitContext(io.fabric8.api.GitContext) ArrayList(java.util.ArrayList) DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) Test(org.junit.Test)

Example 59 with io.fabric8.kubernetes.api.model

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

the class GitDataStoreImplProfilesIT method readVersionAndRefreshProfile.

@Test
public void readVersionAndRefreshProfile() {
    gdsi.importFromFileSystem("src/test/resources/distros/distro1/fabric/import");
    Version version = profileRegistry.getVersion("1.0");
    assertNotNull(version);
    Profile defaultProfile = version.getProfile("default");
    assertNotNull(defaultProfile);
    assertThat(defaultProfile.getBundles().size(), equalTo(1));
    assertThat(defaultProfile.getBundles().get(0), equalTo("mvn:io.fabric8/fabric-amazing/${version:fabric}"));
    assertThat(defaultProfile.getFeatures().size(), equalTo(1));
    assertThat(defaultProfile.getFeatures().get(0), equalTo("extraordinary"));
    assertThat(defaultProfile.getConfigurations().size(), equalTo(2));
    assertThat(defaultProfile.getConfigurations().get("my.special.pid").get("property2"), equalTo("value2"));
    assertThat(defaultProfile.getConfigurations().get("io.fabric8.agent").get("some.other.property"), equalTo("valueX"));
    assertThat(defaultProfile.getConfigurations().get("io.fabric8.agent").get("io.fabric8.number.of.sources"), equalTo("42,142,200"));
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(defaultProfile);
    Map<String, String> agentConfiguration = builder.getConfiguration(Constants.AGENT_PID);
    // refresh
    agentConfiguration.put("lastRefresh." + defaultProfile.getId(), String.valueOf(System.currentTimeMillis()));
    agentConfiguration.put("io.fabric8.number.of.sources", "100");
    builder.addConfiguration(Constants.AGENT_PID, agentConfiguration);
    profileRegistry.updateProfile(builder.getProfile());
}
Also used : Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 60 with io.fabric8.kubernetes.api.model

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

the class GitPatchManagementServiceImpl method determineVersion.

/**
 * Return version of product (Fuse, Fabric8) used, but probably based on different karafHome
 * @param home
 * @param product
 * @return
 */
private String determineVersion(File home, String product) {
    if (env != EnvType.FABRIC_CHILD && env != EnvType.STANDALONE_CHILD) {
        File versions = new File(home, "fabric/import/fabric/profiles/default.profile/io.fabric8.version.properties");
        if (versions.exists() && versions.isFile()) {
            Properties props = new Properties();
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(versions);
                props.load(fis);
                return props.getProperty(product);
            } catch (IOException e) {
                Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, true);
                return null;
            } finally {
                IOUtils.closeQuietly(fis);
            }
        } else {
            Activator.log2(LogService.LOG_ERROR, "Can't find io.fabric8.version.properties file in default profile");
        }
    } else {
        // for child container we have to be more careful and not examine root container's io.fabric8.version.properties!
        File startup = new File(home, "etc/startup.properties");
        if (startup.exists() && startup.isFile()) {
            Properties props = new Properties();
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(startup);
                props.load(fis);
                for (String key : props.stringPropertyNames()) {
                    if (key.startsWith("org/apache/karaf/features/org.apache.karaf.features.core")) {
                        String url = Utils.pathToMvnurl(key);
                        Artifact artifact = Utils.mvnurlToArtifact(url, true);
                        if (artifact != null) {
                            return artifact.getVersion();
                        }
                    }
                }
            } catch (IOException e) {
                Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, true);
                return null;
            } finally {
                IOUtils.closeQuietly(fis);
            }
        } else {
            Activator.log2(LogService.LOG_ERROR, "Can't find etc/startup.properties file in child container");
        }
    }
    return null;
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Artifact(io.fabric8.patch.management.Artifact)

Aggregations

Test (org.junit.Test)29 FabricService (io.fabric8.api.FabricService)26 File (java.io.File)22 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)18 InputStream (java.io.InputStream)16 Logger (org.slf4j.Logger)16 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)15 CommandSupport (io.fabric8.itests.support.CommandSupport)15 Deployment (org.jboss.arquillian.container.test.api.Deployment)15 StartLevelAware (org.jboss.arquillian.osgi.StartLevelAware)15 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)15 Asset (org.jboss.shrinkwrap.api.asset.Asset)15 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)15 ServiceTracker (org.osgi.util.tracker.ServiceTracker)15 IOException (java.io.IOException)14 Action (org.apache.felix.gogo.commands.Action)14 AbstractCommand (org.apache.felix.gogo.commands.basic.AbstractCommand)14 MavenResolver (io.fabric8.maven.MavenResolver)11 Container (io.fabric8.api.Container)10 BundleContext (org.osgi.framework.BundleContext)9