use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.
the class ActiveMQConsumerFactory method updateInternal.
private void updateInternal(Map<String, ?> configuration) throws Exception {
try {
LOG.info("Starting consumer");
consumerService = new ActiveMQService(connectionFactory);
consumerService.setMaxAttempts(10);
consumerService.start();
String destination = (String) configuration.get("destination");
if (destination == null) {
destination = DEFAULT_DESTINATION;
}
consumer = new ConsumerThread(consumerService, destination);
consumer.start();
LOG.info("Consumer started");
} catch (JMSException e) {
throw new Exception("Cannot start consumer", e);
}
}
use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.
the class ActiveMQProducerFactory method updateInternal.
private void updateInternal(Map<String, ?> configuration) throws Exception {
try {
LOG.info("Starting producer");
producerService = new ActiveMQService(connectionFactory);
producerService.setMaxAttempts(10);
producerService.start();
String destination = (String) configuration.get("destination");
if (destination == null) {
destination = DEFAULT_DESTINATION;
}
producer = new ProducerThread(producerService, destination);
producer.setSleep(500);
producer.start();
LOG.info("Producer started");
} catch (JMSException e) {
throw new Exception("Cannot start producer", e);
}
}
use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.
the class FileBackupService method backupDataFiles.
/**
* Invoked just before Framework is restarted and data/cache directory is removed. We copy existing data
* directories for current bundles and record for which bundle$$version it is used.
* @param result used to create backup directories.
* @param pending
* @throws IOException
*/
@Override
public void backupDataFiles(PatchResult result, Pending pending) throws IOException {
Map<String, Bundle> bundlesWithData = new HashMap<>();
// bundle.getDataFile("xxx") creates data dir if it didn't exist - it's not what we want
String storageLocation = systemContext.getProperty("org.osgi.framework.storage");
if (storageLocation == null) {
Activator.log(LogService.LOG_INFO, "Can't determine \"org.osgi.framework.storage\" property value");
return;
}
File cacheDir = new File(storageLocation);
if (!cacheDir.isDirectory()) {
return;
}
for (Bundle b : systemContext.getBundles()) {
if (b.getSymbolicName() != null) {
String sn = Utils.stripSymbolicName(b.getSymbolicName());
if ("org.apache.karaf.features.core".equals(sn)) {
// we start with fresh features service state
continue;
}
// a bit of knowledge of how Felix works below...
File dataDir = new File(cacheDir, "bundle" + b.getBundleId() + "/data");
if (dataDir.isDirectory()) {
String key = String.format("%s$$%s", sn, b.getVersion().toString());
bundlesWithData.put(key, b);
}
}
}
// this property file will be used to map full symbolicName$$version to a location where bundle data
// is stored - the data must be restored both during R patch installation and rollback
Properties properties = new Properties();
String dirName = result.getPatchData().getId() + ".datafiles";
if (result.getParent() != null) {
dirName = result.getPatchData().getId() + "." + System.getProperty("karaf.name") + ".datafiles";
}
File dataBackupDir = new File(result.getPatchData().getPatchLocation(), dirName);
String prefix = pending == Pending.ROLLUP_INSTALLATION ? "install" : "rollback";
for (BundleUpdate update : result.getBundleUpdates()) {
// same update for both updated and reinstalled bundle
String key = String.format("%s$$%s", update.getSymbolicName(), pending == Pending.ROLLUP_INSTALLATION ? update.getPreviousVersion() : (update.getNewVersion() == null ? update.getPreviousVersion() : update.getNewVersion()));
if (bundlesWithData.containsKey(key)) {
File dataFileBackupDir = new File(dataBackupDir, prefix + "/" + key + "/data");
dataFileBackupDir.mkdirs();
final Bundle b = bundlesWithData.get(key);
FileUtils.copyDirectory(b.getDataFile(""), dataFileBackupDir, new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory() || !b.getSymbolicName().equals("org.apache.felix.configadmin") || pathname.getName().endsWith(".config");
}
});
properties.setProperty(key, key);
properties.setProperty(String.format("%s$$%s", update.getSymbolicName(), update.getPreviousVersion()), key);
if (update.getNewVersion() != null) {
properties.setProperty(String.format("%s$$%s", update.getSymbolicName(), update.getNewVersion()), key);
}
}
}
FileOutputStream propsFile = new FileOutputStream(new File(dataBackupDir, "backup-" + prefix + ".properties"));
properties.store(propsFile, "Data files to restore after \"" + result.getPatchData().getId() + "\" " + (pending == Pending.ROLLUP_INSTALLATION ? "installation" : "rollback"));
propsFile.close();
}
use of io.fabric8.arquillian.kubernetes.event.Start in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method applyChanges.
/**
* <p>This method updates ${karaf.base} simply by copying all files from currently checked out working copy
* (usually HEAD of main patch branch) to <code>${karaf.base}</code></p>
* @param git
* @param restartFileInstall whether to start fileinstall bundle at the end
* @throws IOException
* @throws GitAPIException
*/
private void applyChanges(Git git, boolean restartFileInstall) throws IOException, GitAPIException {
Bundle fileInstall = null;
for (Bundle b : systemContext.getBundles()) {
if (b.getSymbolicName() != null && Utils.stripSymbolicName(b.getSymbolicName()).equals("org.apache.felix.fileinstall")) {
fileInstall = b;
break;
}
}
if (fileInstall != null) {
try {
fileInstall.stop(Bundle.STOP_TRANSIENT);
} catch (Exception e) {
Activator.log(LogService.LOG_WARNING, e.getMessage());
}
}
File wcDir = git.getRepository().getWorkTree();
copyManagedDirectories(wcDir, karafBase, true, true, true);
File lib = new File(wcDir, "lib");
if (lib.exists()) {
FileUtils.copyDirectory(lib, new File(karafBase, "lib.next"));
}
// we do exception for etc/overrides.properties
File overrides = new File(karafBase, "etc/overrides.properties");
if (overrides.exists() && overrides.length() == 0) {
FileUtils.deleteQuietly(overrides);
}
if (restartFileInstall && fileInstall != null) {
try {
fileInstall.start(Bundle.START_TRANSIENT);
} catch (Exception e) {
Activator.log(LogService.LOG_WARNING, e.getMessage());
}
}
}
use of io.fabric8.arquillian.kubernetes.event.Start 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);
}
}
}
Aggregations