use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.
the class ContainerBuilder method synchronizeGitRepositories.
/**
* ENTESB-6368: Ensures that local git repository is synchronized with fabric-wide git repository.
*/
protected void synchronizeGitRepositories() {
GitService gitService = ServiceLocator.awaitService(GitService.class);
GitDataStore gitDataStore = ServiceLocator.awaitService(GitDataStore.class);
for (int i = 0; i < 10; i++) {
try {
LOG.info("Synchronizing Git repositories");
Iterable<PushResult> results = gitDataStore.doPush(gitService.getGit(), new GitContext().requirePush());
if (results.iterator().hasNext()) {
return;
}
throw new Exception("No reference was pushed");
} catch (Exception e) {
LOG.warn("Synchronization of Git repositories failed: " + e.getMessage());
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RuntimeException(ie);
}
}
}
}
use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.
the class ContainerBuilder method synchronizeGitRepositories.
/**
* ENTESB-6368: Ensures that local git repository is synchronized with fabric-wide git repository.
*/
protected void synchronizeGitRepositories() {
GitService gitService = io.fabric8.api.gravia.ServiceLocator.awaitService(GitService.class);
GitDataStore gitDataStore = io.fabric8.api.gravia.ServiceLocator.awaitService(GitDataStore.class);
for (int i = 0; i < 10; i++) {
try {
LOG.info("Synchronizing Git repositories");
Iterable<PushResult> results = gitDataStore.doPush(gitService.getGit(), new GitContext().requirePush());
if (results.iterator().hasNext()) {
return;
}
throw new Exception("No reference was pushed");
} catch (Exception e) {
LOG.warn("Synchronization of Git repositories failed: " + e.getMessage());
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
throw new RuntimeException(ie);
}
}
}
}
use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.
the class FabricMavenProxyTest method testUpload.
@Test
public void testUpload() throws Exception {
String featureLocation = System.getProperty("feature.location");
System.out.println("Testing with feature from:" + featureLocation);
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("maven").withProfiles("fabric").waitForProvisioning(10 * 60 * 1000L).assertProvisioningResult().build();
try {
List<String> uploadUrls = new ArrayList<String>();
ServiceProxy<CuratorFramework> curatorProxy = ServiceProxy.createServiceProxy(bundleContext, CuratorFramework.class);
try {
CuratorFramework curator = curatorProxy.getService();
List<String> children = ZooKeeperUtils.getChildren(curator, ZkPath.MAVEN_PROXY.getPath("upload"));
for (String child : children) {
String uploadeUrl = ZooKeeperUtils.getSubstitutedPath(curator, ZkPath.MAVEN_PROXY.getPath("upload") + "/" + child);
uploadUrls.add(uploadeUrl);
}
} finally {
curatorProxy.close();
}
// Pick a random maven proxy from the list.
Random random = new Random();
int index = random.nextInt(uploadUrls.size());
String targetUrl = uploadUrls.get(index);
String uploadUrl = targetUrl + "itest/itest/1.0/itest-1.0-features.xml";
System.out.println("Using URI: " + uploadUrl);
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "admin"));
CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
HttpPut put = new HttpPut(uploadUrl);
NFileEntity entity = new NFileEntity(new File(featureLocation), ContentType.TEXT_XML);
put.setEntity(entity);
HttpResponse response = client.execute(put);
System.out.println("Response:" + response.getStatusLine());
Assert.assertTrue(response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 202);
System.out.println(executeCommand("fabric:profile-edit --repository mvn:itest/itest/1.0/xml/features default"));
System.out.println(executeCommand("fabric:profile-edit --feature example-cbr default"));
Provision.containerStatus(containers, PROVISION_TIMEOUT);
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method trackPatch.
/**
* <p>This method turns static information about a patch into managed patch - i.e., patch added to git
* repository.</p>
*
* <p>Such patch has its own branch ready to be merged (when patch is installed). Before installation we can verify
* the patch,
* examine the content, check the differences, conflicts and perform simulation (merge to temporary branch created
* from main patch branch)</p>
*
* <p>The strategy is as follows:<ul>
* <li><em>main patch branch</em> in git repository tracks all changes (from baselines, patch-management
* system, patches and user changes)</li>
* <li>Initially there are 3 commits: baseline, patch-management bundle installation in etc/startup.properties,
* initial user changes</li>
* <li>We always <strong>tag the baseline commit</strong></li>
* <li>User changes may be applied each time Framework is restarted</li>
* <li>When we add a patch, we create <em>named branch</em> from the <strong>latest baseline</strong></li>
* <li>When we install a patch, we <strong>merge</strong> the patch branch with the <em>main patch branch</em>
* (that may contain additional user changes)</li>
* <li>When patch ZIP contains new baseline distribution, after merging patch branch, we tag the merge commit
* in <em>main patch branch</em> branch as new baseline</li>
* <li>Branches for new patches will then be created from new baseline commit</li>
* </ul></p>
* @param patchData
* @return
*/
@Override
public Patch trackPatch(PatchData patchData) throws PatchException {
try {
awaitInitialization();
} catch (InterruptedException e) {
throw new PatchException("Patch management system is not ready yet");
}
Git fork = null;
try {
Git mainRepository = gitPatchRepository.findOrCreateMainGitRepository();
// prepare single fork for all the below operations
fork = gitPatchRepository.cloneRepository(mainRepository, true);
// 1. find current baseline
RevTag latestBaseline = gitPatchRepository.findCurrentBaseline(fork);
if (latestBaseline == null) {
throw new PatchException("Can't find baseline distribution tracked in patch management. Is patch management initialized?");
}
// the commit from the patch should be available from main patch branch
RevCommit commit = new RevWalk(fork.getRepository()).parseCommit(latestBaseline.getObject());
// create dedicated branch for this patch. We'll immediately add patch content there so we can examine the
// changes from the latest baseline
gitPatchRepository.checkout(fork).setCreateBranch(true).setName("patch-" + patchData.getId()).setStartPoint(commit).call();
// copy patch resources (but not maven artifacts from system/ or repository/) to working copy
if (patchData.getPatchDirectory() != null) {
boolean removeTargetDir = patchData.isRollupPatch();
copyManagedDirectories(patchData.getPatchDirectory(), fork.getRepository().getWorkTree(), removeTargetDir, false, false);
}
// add the changes
fork.add().addFilepattern(".").call();
// remove the deletes (without touching specially-managed etc/overrides.properties)
for (String missing : fork.status().call().getMissing()) {
if (!"etc/overrides.properties".equals(missing)) {
fork.rm().addFilepattern(missing).call();
}
}
// record information about other "patches" included in added patch (e.g., Fuse patch
// may contain patches to admin:create based containers in standalone mode)
StringWriter sw = new StringWriter();
sw.append("# tags for patches included in \"").append(patchData.getId()).append("\"\n");
for (String bundle : patchData.getBundles()) {
// containers that want to patch:install patches added in root containers
if (bundle.contains("mvn:org.apache.karaf.admin/org.apache.karaf.admin.core/")) {
Artifact a = Utils.mvnurlToArtifact(bundle, true);
if (a != null) {
sw.append(String.format(EnvType.STANDALONE_CHILD.getBaselineTagFormat(), a.getVersion())).append("\n");
}
break;
}
}
FileUtils.write(new File(fork.getRepository().getWorkTree(), "patch-info.txt"), sw.toString());
fork.add().addFilepattern(".").call();
// commit the changes (patch vs. baseline) to patch branch
gitPatchRepository.prepareCommit(fork, String.format("[PATCH] Tracking patch %s", patchData.getId())).call();
// push the patch branch
gitPatchRepository.push(fork, "patch-" + patchData.getId());
// track other kinds of baselines found in the patch
if (env.isFabric()) {
trackBaselinesForRootContainer(fork);
trackBaselinesForChildContainers(fork);
trackBaselinesForSSHContainers(fork);
} else {
// for admin:create child containers
trackBaselinesForChildContainers(fork);
}
return new Patch(patchData, gitPatchRepository.getManagedPatch(patchData.getId()));
} catch (IOException | GitAPIException e) {
throw new PatchException(e.getMessage(), e);
} finally {
if (fork != null) {
gitPatchRepository.closeRepository(fork, true);
}
}
}
use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method rollbackNonRollupPatchInstallation.
@Test
public void rollbackNonRollupPatchInstallation() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement();
PatchManagement management = (PatchManagement) pm;
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
Patch patch = management.trackPatch(patches.get(0));
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
ObjectId master1 = fork.getRepository().resolve("master");
String tx = management.beginInstallation(PatchKind.NON_ROLLUP);
management.install(tx, patch, null);
management.rollbackInstallation(tx);
fork.pull().call();
ObjectId master2 = fork.getRepository().resolve("master");
assertThat(master1, equalTo(master2));
assertThat(fork.tagList().call().size(), equalTo(2));
assertTrue(repository.containsTag(fork, "patch-management"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
}
Aggregations