use of io.fabric8.annotations.Configuration in project fabric8 by jboss-fuse.
the class GitHttpServerRegistrationHandler method activate.
@Activate
void activate(Map<String, ?> configuration) throws Exception {
RuntimeProperties sysprops = runtimeProperties.get();
realm = getConfiguredRealm(sysprops, configuration);
roles = getConfiguredRoles(sysprops, configuration);
dataPath = sysprops.getDataPath();
activateComponent();
group = new ZooKeeperGroup<GitNode>(curator.get(), ZkPath.GIT.getPath(), GitNode.class, new NamedThreadFactory("zkgroup-git-httpreg"));
// if anything went wrong in a previous deactivation we still have to clean up the registry
zkCleanUp(group);
group.add(this);
group.update(createState());
group.start();
}
use of io.fabric8.annotations.Configuration 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.annotations.Configuration 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.annotations.Configuration 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.annotations.Configuration in project fabric8 by jboss-fuse.
the class FabricServiceImpl method substituteConfigurations.
/**
* Performs substitution to configuration based on the registered {@link PlaceholderResolver} instances.
*/
public Map<String, Map<String, String>> substituteConfigurations(final Map<String, Map<String, String>> configurations) {
final Map<String, PlaceholderResolver> resolversSnapshot = new HashMap<String, PlaceholderResolver>(placeholderResolvers);
// Check that all resolvers are available
Set<String> requiredSchemes = getSchemesForProfileConfigurations(configurations);
Set<String> availableSchemes = resolversSnapshot.keySet();
if (!availableSchemes.containsAll(requiredSchemes)) {
StringBuilder sb = new StringBuilder();
sb.append("Missing Placeholder Resolvers:");
for (String scheme : requiredSchemes) {
if (!availableSchemes.contains(scheme)) {
sb.append(" ").append(scheme);
}
}
throw new FabricException(sb.toString());
}
final Map<String, Map<String, String>> mutableConfigurations = new HashMap<>();
for (Entry<String, Map<String, String>> entry : configurations.entrySet()) {
String key = entry.getKey();
Map<String, String> value = new HashMap<>(entry.getValue());
mutableConfigurations.put(key, value);
}
final FabricService fabricService = this;
for (Map.Entry<String, Map<String, String>> entry : mutableConfigurations.entrySet()) {
final String pid = entry.getKey();
Map<String, String> props = entry.getValue();
Map<String, String> original = new HashMap<>(props);
for (Map.Entry<String, String> e : original.entrySet()) {
final String key = e.getKey();
final String value = e.getValue();
try {
props.put(key, InterpolationHelper.substVars(value, key, null, props, new InterpolationHelper.SubstitutionCallback() {
public String getValue(String toSubstitute) {
if (toSubstitute != null && toSubstitute.contains(":")) {
String scheme = toSubstitute.substring(0, toSubstitute.indexOf(":"));
return resolversSnapshot.get(scheme).resolve(fabricService, mutableConfigurations, pid, key, toSubstitute);
}
return substituteBundleProperty(toSubstitute, bundleContext);
}
}));
} catch (EncryptionOperationNotPossibleException exception) {
LOGGER.warn("Error resolving " + key, exception);
}
}
}
return mutableConfigurations;
}
Aggregations