use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method checkPendingPatches.
@Override
public void checkPendingPatches() {
File[] pendingPatches = patchesDir.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.exists() && pathname.getName().endsWith(".pending");
}
});
if (pendingPatches == null || pendingPatches.length == 0) {
return;
}
final String dataCache = systemContext.getProperty("org.osgi.framework.storage");
for (File pending : pendingPatches) {
try {
Pending what = Pending.valueOf(FileUtils.readFileToString(pending));
final String prefix = what == Pending.ROLLUP_INSTALLATION ? "install" : "rollback";
String name = pending.getName().replaceFirst("\\.pending$", "");
if (isStandaloneChild()) {
if (name.endsWith("." + System.getProperty("karaf.name") + ".patch")) {
name = name.replaceFirst("\\." + System.getProperty("karaf.name"), "");
} else {
continue;
}
}
File patchFile = new File(pending.getParentFile(), name);
if (!patchFile.isFile()) {
Activator.log(LogService.LOG_INFO, "Ignoring patch result file: " + patchFile.getName());
continue;
}
PatchData patchData = PatchData.load(new FileInputStream(patchFile));
Patch patch = loadPatch(new PatchDetailsRequest(patchData.getId()));
String dataFilesName = patchData.getId() + ".datafiles";
if (isStandaloneChild()) {
dataFilesName = patchData.getId() + "." + System.getProperty("karaf.name") + ".datafiles";
}
final File dataFilesBackupDir = new File(pending.getParentFile(), dataFilesName);
final Properties backupProperties = new Properties();
FileInputStream inStream = new FileInputStream(new File(dataFilesBackupDir, "backup-" + prefix + ".properties"));
backupProperties.load(inStream);
IOUtils.closeQuietly(inStream);
// maybe one of those bundles has data directory to restore?
for (Bundle b : systemContext.getBundles()) {
if (b.getSymbolicName() != null) {
String key = String.format("%s$$%s", stripSymbolicName(b.getSymbolicName()), b.getVersion().toString());
if (backupProperties.containsKey(key)) {
String backupDirName = backupProperties.getProperty(key);
File backupDir = new File(dataFilesBackupDir, prefix + "/" + backupDirName + "/data");
restoreDataDirectory(dataCache, b, backupDir);
// we no longer want to restore this dir
backupProperties.remove(key);
}
}
}
// 2. We can however have more bundle data backups - we'll restore them after each bundle
// is INSTALLED and we'll use listener for this
BundleListener bundleListener = new SynchronousBundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
Bundle b = event.getBundle();
if (event.getType() == BundleEvent.INSTALLED && b.getSymbolicName() != null) {
String key = String.format("%s$$%s", stripSymbolicName(b.getSymbolicName()), b.getVersion().toString());
if (backupProperties.containsKey(key)) {
String backupDirName = backupProperties.getProperty(key);
File backupDir = new File(dataFilesBackupDir, prefix + "/" + backupDirName + "/data");
restoreDataDirectory(dataCache, b, backupDir);
}
}
}
};
systemContext.addBundleListener(bundleListener);
pendingPatchesListeners.put(patchData.getId(), bundleListener);
} catch (Exception e) {
Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, true);
}
}
}
use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method loadPatch.
/**
* Retrieves patch information from existing file
* @param patchDescriptor existing file with patch descriptor (<code>*.patch</code> file)
* @param details whether the returned {@link Patch} should contain {@link ManagedPatch} information
* @return
* @throws IOException
*/
private Patch loadPatch(File patchDescriptor, boolean details) throws IOException {
Patch p = new Patch();
if (!patchDescriptor.exists() || !patchDescriptor.isFile()) {
return null;
}
PatchData data = PatchData.load(new FileInputStream(patchDescriptor));
p.setPatchData(data);
File patchDirectory = new File(patchesDir, FilenameUtils.getBaseName(patchDescriptor.getName()));
if (patchDirectory.exists() && patchDirectory.isDirectory()) {
// not every descriptor downloaded may be a ZIP file, not every patch has content
data.setPatchDirectory(patchDirectory);
}
data.setPatchLocation(patchesDir);
File resultFile = new File(patchesDir, FilenameUtils.getBaseName(patchDescriptor.getName()) + ".patch.result");
if (resultFile.exists() && resultFile.isFile()) {
PatchResult result = PatchResult.load(data, new FileInputStream(resultFile));
p.setResult(result);
}
if (details) {
ManagedPatch mp = gitPatchRepository.getManagedPatch(data.getId());
p.setManagedPatch(mp);
}
return p;
}
use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method mergeProfileChanges.
@Override
public void mergeProfileChanges(Patch patch, File gitRepository, String versionBranch, String patchBranch) {
Git git = null;
try {
git = Git.open(gitRepository);
// merge version branch with patch branch - no fast forward, so we have nice named commit
git.checkout().setCreateBranch(false).setName(versionBranch).call();
MergeResult result = git.merge().setFastForward(MergeCommand.FastForwardMode.NO_FF).include(git.getRepository().resolve(patchBranch)).setCommit(false).call();
boolean commit = true;
if (result.getMergeStatus() == MergeResult.MergeStatus.CONFLICTING) {
handleMergeConflict(git, result, versionBranch, patchBranch);
} else if (result.getMergeStatus() != MergeResult.MergeStatus.MERGED_NOT_COMMITTED) {
commit = false;
Activator.log2(LogService.LOG_ERROR, "Can't merge version branch \"" + versionBranch + "\" with" + " patch branch \"" + patchBranch + "\". Resetting the branch.");
git.reset().setMode(ResetCommand.ResetType.HARD).call();
}
// if (commit) {
// git.commit()
// .setMessage("Installing rollup patch \"" + patch.getPatchData().getId() + "\"")
// .call();
// }
} catch (Exception e) {
throw new PatchException(e.getMessage(), e);
} finally {
if (git != null) {
try {
git.branchDelete().setBranchNames(patchBranch).setForce(true).call();
} catch (GitAPIException e) {
Activator.log2(LogService.LOG_ERROR, e.getMessage());
}
gitPatchRepository.closeRepository(git, false);
}
}
}
use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class SupportServiceImpl method collect.
@Override
public File collect() {
String name = String.format("%s-%s", "SUPPORT", DATE_TIME_SUFFIX.format(new Date()));
File result = null;
ZipOutputStream file = null;
try {
result = File.createTempFile(name, ".zip");
LOGGER.info("Collecting information for support in file {}", result.getAbsolutePath());
file = new ZipOutputStream(new FileOutputStream(result));
for (Collector collector : collectors) {
for (Resource resource : collector.collect(resourceFactory)) {
collectFromResource(file, resource);
}
}
} catch (IOException e) {
LOGGER.error("Exception occured while collecting support information - resulting support file may not be usable", e);
} finally {
IOHelpers.close(file);
}
return result;
}
use of io.fabric8.insight.metrics.model.Result in project fabric8 by jboss-fuse.
the class FileBackupTest method backupSomeDataFiles.
@Test
public void backupSomeDataFiles() throws IOException {
PatchData patchData = new PatchData("my-patch");
patchData.setPatchLocation(new File(karafHome, "patches"));
PatchResult result = new PatchResult(patchData);
// updates installed bundle, has data dir
BundleUpdate b3 = new BundleUpdate("com.irrelevant.services", "1.2", "file:/dev/null", "1.1.0", "file:/dev/random");
// updates installed bundle, has data dir, but special case
BundleUpdate b4 = new BundleUpdate("org.apache.karaf.features.core", "1.3", "file:/dev/null", "1.2.1", "file:/dev/random");
// reinstalled bundle, has data dir
BundleUpdate b5 = new BundleUpdate("com.irrelevant.iot", null, null, "1.2.5", "file:/dev/random");
// reinstalled bundle, no data dir
BundleUpdate b6 = new BundleUpdate("com.irrelevant.space", null, null, "1.1.0", "file:/dev/random");
// update, but not for installed bundle
BundleUpdate b7 = new BundleUpdate("com.irrelevant.the.final.frontier", "1.5", "file:/dev/null", "1.1.3", "file:/dev/random");
result.getBundleUpdates().add(b3);
result.getBundleUpdates().add(b4);
result.getBundleUpdates().add(b5);
result.getBundleUpdates().add(b6);
result.getBundleUpdates().add(b7);
new FileBackupService(sys).backupDataFiles(result, Pending.ROLLUP_INSTALLATION);
Properties props = new Properties();
props.load(new FileInputStream(new File(karafHome, "patches/my-patch.datafiles/backup-install.properties")));
assertThat(props.getProperty("com.irrelevant.services$$1.1.0"), equalTo("com.irrelevant.services$$1.1.0"));
assertThat(props.getProperty("com.irrelevant.services$$1.2"), equalTo("com.irrelevant.services$$1.1.0"));
assertThat(props.getProperty("com.irrelevant.iot$$1.2.5"), equalTo("com.irrelevant.iot$$1.2.5"));
assertThat(props.stringPropertyNames().size(), equalTo(3));
assertTrue(new File(karafHome, "patches/my-patch.datafiles/install/com.irrelevant.services$$1.1.0/data/x").isDirectory());
assertTrue(new File(karafHome, "patches/my-patch.datafiles/install/com.irrelevant.iot$$1.2.5/data/z").isDirectory());
assertFalse(new File(karafHome, "patches/my-patch.datafiles/install/com.irrelevant.the.final.frontier$$1.5").isDirectory());
}
Aggregations