use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method trackBaselinesForSSHContainers.
/**
* SSH containers are created from io.fabric8:fabric8-karaf distros. These however may be official, foundation
* or random (ZIPped from what currently was in FUSE_HOME of the container that created SSH container.
* Track all new baselines for SSH containers. These are looked up inside
* <code>io/fabric8/fabric8-karaf/**</code>
* @param fork
*/
public void trackBaselinesForSSHContainers(Git fork) throws IOException, GitAPIException {
// two separate branches for two kinds of baselines for SSH containers
if (fork.getRepository().getRef("refs/heads/" + gitPatchRepository.getFuseSSHContainerPatchBranchName()) == null) {
String startPoint = "patch-management^{commit}";
if (fork.getRepository().getRef("refs/remotes/origin/" + gitPatchRepository.getFuseSSHContainerPatchBranchName()) != null) {
startPoint = "refs/remotes/origin/" + gitPatchRepository.getFuseSSHContainerPatchBranchName();
}
gitPatchRepository.checkout(fork).setName(gitPatchRepository.getFuseSSHContainerPatchBranchName()).setStartPoint(startPoint).setCreateBranch(true).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).call();
}
if (fork.getRepository().getRef("refs/heads/" + gitPatchRepository.getFabric8SSHContainerPatchBranchName()) == null) {
String startPoint = "patch-management^{commit}";
if (fork.getRepository().getRef("refs/remotes/origin/" + gitPatchRepository.getFabric8SSHContainerPatchBranchName()) != null) {
startPoint = "refs/remotes/origin/" + gitPatchRepository.getFabric8SSHContainerPatchBranchName();
}
gitPatchRepository.checkout(fork).setName(gitPatchRepository.getFabric8SSHContainerPatchBranchName()).setStartPoint(startPoint).setCreateBranch(true).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).call();
}
File systemRepo = getSystemRepository(karafHome, systemContext);
File[] versionDirs = new File(systemRepo, "io/fabric8/fabric8-karaf").listFiles();
Set<Version> versions = new TreeSet<>();
if (versionDirs != null) {
for (File version : versionDirs) {
if (version.isDirectory()) {
versions.add(Utils.getOsgiVersion(version.getName()));
}
}
}
for (Version v : versions) {
String fabric8Version = v.toString();
// each version may have two (maybe more?) baseline distros.
// we may have "official" fabric8-karaf and the one created from FUSE_HOME (zipped on-fly).
String[] artifactPatterns = new String[] { "fabric8-karaf-%1$s.zip", "fabric8-karaf-%1$s-custom.zip" };
for (String artifactPattern : artifactPatterns) {
File baselineDistribution = null;
String location = String.format(systemRepo.getCanonicalPath() + "/io/fabric8/fabric8-karaf/%1$s/" + artifactPattern, fabric8Version);
if (new File(location).isFile()) {
baselineDistribution = new File(location);
Activator.log(LogService.LOG_INFO, "Found SSH baseline distribution: " + baselineDistribution.getCanonicalPath());
}
if (baselineDistribution != null) {
try {
// we don't know yet which branch we have to checkout, this method will do 2 pass unzipping
// and leave the fork checked out to correct branch - its name will be returned
String rootDir = String.format("fabric8-karaf-%s", fabric8Version);
String branchName = unzipFabric8Distro(rootDir, baselineDistribution, fabric8Version, fork);
if (branchName == null) {
continue;
}
// remove the deletes
for (String missing : fork.status().call().getMissing()) {
fork.rm().addFilepattern(missing).call();
}
// and we'll tag the child baseline
String tagName = branchName.replace("patches-", "");
fork.add().addFilepattern(".").call();
RevCommit commit = gitPatchRepository.prepareCommit(fork, String.format(MARKER_BASELINE_SSH_COMMIT_PATTERN, tagName, fabric8Version)).call();
fork.tag().setName(String.format("baseline-%s-%s", tagName, fabric8Version)).setObjectId(commit).call();
} catch (Exception e) {
Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, true);
}
}
}
}
gitPatchRepository.push(fork, gitPatchRepository.getFuseSSHContainerPatchBranchName());
gitPatchRepository.push(fork, gitPatchRepository.getFabric8SSHContainerPatchBranchName());
}
use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method loadPatchData.
/**
* Reads content of patch descriptor into non-(yet)-managed patch data structure
* @param patchDescriptor
* @return
*/
private PatchData loadPatchData(File patchDescriptor) throws IOException {
Properties properties = new Properties();
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(patchDescriptor);
properties.load(inputStream);
boolean ok = properties.containsKey("id") && properties.containsKey("bundle.count");
if (!ok) {
throw new PatchException("Patch descriptor is not valid");
}
return PatchData.load(properties);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method findLatestPatchRevision.
@Override
public String findLatestPatchRevision(File gitRepository, String versionId) {
Git git = null;
try {
git = Git.open(gitRepository);
Iterable<RevCommit> log = git.log().add(git.getRepository().resolve(versionId)).call();
List<RevCommit> oldestToNewest = new LinkedList<>();
RevCommit patchBaseRevision = null;
for (RevCommit rc : log) {
// in case we don't find previous R patch, we'll have to find it the hard way
oldestToNewest.add(0, rc);
if (rc.getShortMessage().startsWith("Installing rollup patch ")) {
if (rc.getParents() != null && rc.getParents().length == 2) {
// it's 2nd parent with "Installing profiles from patch ..." message
if (rc.getParents()[0].getShortMessage().startsWith("Installing profiles from patch ")) {
patchBaseRevision = rc.getParents()[0];
break;
} else if (rc.getParents()[1].getShortMessage().startsWith("Installing profiles from patch ")) {
patchBaseRevision = rc.getParents()[1];
break;
}
}
// if "Installing rollup patch ..." commit doesn't have 2 parents, it means it was created by
// some old patch mechanism from early 6.2.1 which just copied profiles over and didn't use
// merging
patchBaseRevision = rc;
break;
}
}
if (patchBaseRevision == null) {
// from this change
for (RevCommit rc : oldestToNewest) {
if (rc.getShortMessage().startsWith("Update configurations for profile: ")) {
patchBaseRevision = rc;
break;
}
}
}
if (patchBaseRevision == null) {
// we didn't find good place to start... we'll start from HEAD then
return versionId;
}
String patchBranchName = String.format("__%s-%d", versionId, new Date().getTime());
Ref branch = git.checkout().setCreateBranch(true).setName(patchBranchName).setStartPoint(patchBaseRevision).call();
return patchBranchName;
} catch (Exception e) {
throw new PatchException(e.getMessage(), e);
} finally {
if (git != null) {
gitPatchRepository.closeRepository(git, false);
}
}
}
use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method alignTo.
@Override
public boolean alignTo(Map<String, String> versions, List<String> urls, File localMavenRepository, Runnable callback) throws PatchException {
if (aligning.getAndSet(true)) {
return false;
}
try {
if (!env.isFabric()) {
try {
// we probably survived fabric:create without refreshing patch-management bundle
env = envService.determineEnvironmentType();
File patchRepositoryLocation = new File(patchesDir, GitPatchRepositoryImpl.MAIN_GIT_REPO_LOCATION);
getGitPatchRepository().close();
GitPatchRepositoryImpl repository = new GitPatchRepositoryImpl(env, patchRepositoryLocation, karafHome, karafBase, karafData, patchesDir);
setGitPatchRepository(repository);
start();
// let's tweak the configuration when entering fabric mode
// this way we will track other kinds of baselines
ensurePatchManagementInitialized();
if (master) {
// let the caller know that we've configured patch management in "master" container
// this is mainly to push the changes from local to cluster git repository
// so child/ssh containers created in fabric can fetch correct baselines
callback.run();
}
} catch (Exception e) {
throw new PatchException(e.getMessage(), e);
}
}
if (env.isFabric()) {
Git fork = null;
try {
ensuringLock.lock();
String version = versions.get(env.getProductId());
String tagName = String.format(env.getBaselineTagFormat(), version);
// we have to be at that tag
Git mainRepository = gitPatchRepository.findOrCreateMainGitRepository();
fetchFabricPatchData(mainRepository);
fork = gitPatchRepository.cloneRepository(mainRepository, true);
gitPatchRepository.checkout(fork).setName(gitPatchRepository.getMainBranchName()).call();
RevTag tag = gitPatchRepository.findCurrentBaseline(fork);
if (tag != null && tagName.equals(tag.getTagName())) {
if (master) {
// and then to data/git/servlet
try {
gitPatchRepository.pushPatchBranches();
callback.run();
} catch (Exception e) {
Activator.log(LogService.LOG_WARNING, null, e.getMessage(), e, false);
} catch (Error e) {
// in case newer patch management calls agent which is still wired to old patch management
Activator.log(LogService.LOG_WARNING, null, e.getMessage(), e, false);
}
}
return false;
}
boolean baselineSwitched = handleNonCurrentBaseline(fork, version, tagName, false, true);
if (localMavenRepository != null) {
try {
File systemRepo = getSystemRepository(karafHome, systemContext);
// let's copy artifacts referenced in etc/startup.properties from localMavenRepository to system
File etcStartupProperties = new File(karafBase, "etc/startup.properties");
try (FileInputStream fis = new FileInputStream(etcStartupProperties)) {
Properties props = new Properties();
props.load(fis);
for (String artifact : props.stringPropertyNames()) {
File target = new File(systemRepo, artifact);
File src = new File(localMavenRepository, artifact);
if (!target.exists() && src.isFile()) {
FileUtils.copyFile(src, target);
}
}
}
// now the URLs from the passed lis
for (String url : urls) {
String path = Utils.mvnurlToPath(url);
if (path != null) {
File target = new File(systemRepo, path);
File src = new File(localMavenRepository, path);
if (!target.exists() && src.isFile()) {
FileUtils.copyFile(src, target);
}
}
}
} catch (Exception e) {
Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, false);
}
}
return baselineSwitched;
} catch (Exception e) {
throw new PatchException(e.getMessage(), e);
} finally {
ensuringLock.unlock();
if (fork != null) {
gitPatchRepository.closeRepository(fork, true);
}
}
}
return false;
} finally {
aligning.set(false);
}
}
use of io.fabric8.patch.management.Patch in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method trackBaselinesForRootContainer.
/**
* These baselines are created from org.jboss.fuse:jboss-fuse-karaf or org.jboss.amq:jboss-a-mq baseline distros.
* @param fork
*/
private void trackBaselinesForRootContainer(Git fork) throws IOException, GitAPIException {
// two separate branches for two kinds of baselines for root containers
if (fork.getRepository().getRef("refs/heads/" + gitPatchRepository.getFuseRootContainerPatchBranchName()) == null) {
String startPoint = "patch-management^{commit}";
if (fork.getRepository().getRef("refs/remotes/origin/" + gitPatchRepository.getFuseRootContainerPatchBranchName()) != null) {
startPoint = "refs/remotes/origin/" + gitPatchRepository.getFuseRootContainerPatchBranchName();
}
gitPatchRepository.checkout(fork).setName(gitPatchRepository.getFuseRootContainerPatchBranchName()).setStartPoint(startPoint).setCreateBranch(true).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).call();
}
if (fork.getRepository().getRef("refs/heads/" + gitPatchRepository.getAmqRootContainerPatchBranchName()) == null) {
String startPoint = "patch-management^{commit}";
if (fork.getRepository().getRef("refs/remotes/origin/" + gitPatchRepository.getAmqRootContainerPatchBranchName()) != null) {
startPoint = "refs/remotes/origin/" + gitPatchRepository.getAmqRootContainerPatchBranchName();
}
gitPatchRepository.checkout(fork).setName(gitPatchRepository.getAmqRootContainerPatchBranchName()).setStartPoint(startPoint).setCreateBranch(true).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK).call();
}
File systemRepo = getSystemRepository(karafHome, systemContext);
String currentFuseVersion = determineVersion(karafHome, "fuse");
String currentFabricVersion = determineVersion(karafHome, "fabric");
// Fuse distros first
File[] versionDirs = new File(systemRepo, "org/jboss/fuse/jboss-fuse-karaf").listFiles();
Map<Version, File> versions = new TreeMap<>();
gitPatchRepository.checkout(fork).setName(gitPatchRepository.getFuseRootContainerPatchBranchName()).call();
// we'll look for Fuse/AMQ baseline in /patches dir too - it doesn't have to be present
versions.put(Utils.getOsgiVersion(currentFuseVersion), patchesDir);
if (versionDirs != null) {
for (File version : versionDirs) {
if (version.isDirectory()) {
versions.put(Utils.getOsgiVersion(version.getName()), version);
}
}
}
for (Map.Entry<Version, File> entry : versions.entrySet()) {
String version = entry.getKey().toString();
if (gitPatchRepository.containsTag(fork, String.format(EnvType.FABRIC_FUSE.getBaselineTagFormat(), version))) {
continue;
}
File baselineDistribution = null;
File location = new File(entry.getValue(), String.format("jboss-fuse-karaf-%1$s-baseline.zip", version));
if (location.isFile()) {
baselineDistribution = location;
Activator.log(LogService.LOG_INFO, "Found Fuse baseline distribution: " + baselineDistribution.getCanonicalPath());
}
if (baselineDistribution != null) {
RevCommit commit = trackBaselineRepository(fork, baselineDistribution, version);
fork.tag().setName(String.format(EnvType.FABRIC_FUSE.getBaselineTagFormat(), version)).setObjectId(commit).call();
}
}
// Now AMQ distros
versionDirs = new File(systemRepo, "org/jboss/amq/jboss-a-mq").listFiles();
versions.clear();
gitPatchRepository.checkout(fork).setName(gitPatchRepository.getAmqRootContainerPatchBranchName()).call();
// we'll look for Fuse/AMQ baseline in /patches dir too - it doesn't have to be present
versions.put(Utils.getOsgiVersion(currentFuseVersion), patchesDir);
if (versionDirs != null) {
for (File version : versionDirs) {
if (version.isDirectory()) {
versions.put(Utils.getOsgiVersion(version.getName()), version);
}
}
}
for (Map.Entry<Version, File> entry : versions.entrySet()) {
String version = entry.getKey().toString();
if (gitPatchRepository.containsTag(fork, String.format(EnvType.FABRIC_AMQ.getBaselineTagFormat(), version))) {
continue;
}
File baselineDistribution = null;
File location = new File(entry.getValue(), String.format("jboss-a-mq-%1$s-baseline.zip", version));
if (location.isFile()) {
baselineDistribution = location;
Activator.log(LogService.LOG_INFO, "Found AMQ baseline distribution: " + baselineDistribution.getCanonicalPath());
}
if (baselineDistribution != null) {
RevCommit commit = trackBaselineRepository(fork, baselineDistribution, version);
fork.tag().setName(String.format(EnvType.FABRIC_AMQ.getBaselineTagFormat(), version)).setObjectId(commit).call();
}
}
gitPatchRepository.push(fork, gitPatchRepository.getFuseRootContainerPatchBranchName());
gitPatchRepository.push(fork, gitPatchRepository.getAmqRootContainerPatchBranchName());
}
Aggregations