use of io.fabric8.api.RuntimeProperties 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.api.RuntimeProperties in project fabric8 by jboss-fuse.
the class GitHttpServerRegistrationHandler method createState.
private GitNode createState() {
RuntimeProperties sysprops = runtimeProperties.get();
String runtimeIdentity = sysprops.getRuntimeIdentity();
GitNode state = new GitNode("fabric-repo", runtimeIdentity);
if (group != null && group.isMaster()) {
String externalGitUrl = readExternalGitUrl();
if (externalGitUrl != null) {
state.setUrl(externalGitUrl);
} else {
String fabricRepoUrl = "${zk:" + runtimeIdentity + "/http}/git/fabric/";
state.setUrl(fabricRepoUrl);
}
}
return state;
}
use of io.fabric8.api.RuntimeProperties in project fabric8 by jboss-fuse.
the class GitHttpServerRegistrationHandler method zkCleanUp.
private void zkCleanUp(Group<GitNode> group) {
try {
RuntimeProperties sysprops = runtimeProperties.get();
String runtimeIdentity = sysprops.getRuntimeIdentity();
curator.get().newNamespaceAwareEnsurePath(ZkPath.GIT.getPath()).ensure(curator.get().getZookeeperClient());
List<String> allChildren = ZooKeeperUtils.getAllChildren(curator.get(), ZkPath.GIT.getPath());
for (String path : allChildren) {
String stringData = ZooKeeperUtils.getStringData(curator.get(), path);
if (stringData.contains("\"container\":\"" + runtimeIdentity + "\"")) {
LOGGER.info("Found older ZK \"/fabric/registry/clusters/git\" entry for node " + runtimeIdentity);
ZooKeeperUtils.delete(curator.get(), path);
LOGGER.info("Older ZK \"/fabric/registry/clusters/git\" entry for node " + runtimeIdentity + " has been removed");
}
}
} catch (KeeperException.NoNodeException ignored) {
} catch (Exception e) {
handleException(e);
}
}
use of io.fabric8.api.RuntimeProperties in project fabric8 by jboss-fuse.
the class FabricPatchServiceImpl method synchronize.
@Override
public String synchronize(final boolean verbose) throws Exception {
final String[] remoteUrl = new String[] { null };
patchManagement.pushPatchInfo(verbose);
GitOperation operation = new GitOperation() {
@Override
public Object call(Git git, GitContext context) throws Exception {
ProfileRegistry registry = fabricService.adapt(ProfileRegistry.class);
Map<String, String> properties = registry.getDataStoreProperties();
String username;
String password;
if (properties != null && properties.containsKey("gitRemoteUser") && properties.containsKey("gitRemotePassword")) {
username = properties.get("gitRemoteUser");
password = properties.get("gitRemotePassword");
} else {
username = ZooKeeperUtils.getContainerLogin(runtimeProperties);
password = ZooKeeperUtils.generateContainerToken(runtimeProperties, curator);
}
remoteUrl[0] = git.getRepository().getConfig().getString("remote", "origin", "url");
Iterable<PushResult> results = git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)).setPushTags().setPushAll().call();
logPushResult(results, git.getRepository(), verbose);
return null;
}
};
try {
gitDataStore.gitOperation(new GitContext(), operation, null);
} catch (FabricException e) {
if (e.getCause() != null && e.getCause() instanceof TransportException) {
LOG.warn("Problem when synchronizing patch information: " + e.getCause().getMessage());
} else {
throw e;
}
}
return remoteUrl[0];
}
use of io.fabric8.api.RuntimeProperties in project fabric8 by jboss-fuse.
the class ZooKeeperClusterBootstrapImpl method cleanInternal.
private BootstrapConfiguration cleanInternal(final BundleContext syscontext, final BootstrapConfiguration bootConfig, RuntimeProperties runtimeProps) throws TimeoutException {
LOGGER.debug("Begin clean fabric");
try {
Configuration zkClientCfg = null;
Configuration zkServerCfg = null;
Configuration[] configsSet = configAdmin.get().listConfigurations("(|(service.factoryPid=io.fabric8.zookeeper.server)(service.pid=io.fabric8.zookeeper))");
if (configsSet != null) {
for (Configuration cfg : configsSet) {
// let's explicitly delete client config first
if ("io.fabric8.zookeeper".equals(cfg.getPid())) {
zkClientCfg = cfg;
}
if ("io.fabric8.zookeeper.server".equals(cfg.getFactoryPid())) {
zkServerCfg = cfg;
}
}
}
File karafData = new File(data);
// Setup the listener for unregistration of {@link BootstrapConfiguration}
final CountDownLatch unregisterLatch = new CountDownLatch(1);
ServiceListener listener = new ServiceListener() {
@Override
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.UNREGISTERING) {
LOGGER.debug("Unregistering BootstrapConfiguration");
bootConfig.getComponentContext().getBundleContext().removeServiceListener(this);
unregisterLatch.countDown();
}
}
};
String filter = "(objectClass=" + BootstrapConfiguration.class.getName() + ")";
// FABRIC-1052: register listener using the same bundle context that is used for listeners related to SCR
bootConfig.getComponentContext().getBundleContext().addServiceListener(listener, filter);
CountDownLatch unregisterLatch2 = null;
if (syscontext.getServiceReference(CuratorComplete.class) != null) {
unregisterLatch2 = new CountDownLatch(1);
final CountDownLatch finalUnregisterLatch = unregisterLatch2;
listener = new ServiceListener() {
@Override
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.UNREGISTERING) {
LOGGER.debug("Unregistering CuratorComplete");
bootConfig.getComponentContext().getBundleContext().removeServiceListener(this);
finalUnregisterLatch.countDown();
}
}
};
bootConfig.getComponentContext().getBundleContext().addServiceListener(listener, "(objectClass=" + CuratorComplete.class.getName() + ")");
}
// Disable the BootstrapConfiguration component
// ENTESB-4827: disabling BootstrapConfiguration leads to deactivation of FabricService and ProfileUrlHandler
// and we have race condition if we're --cleaning after recently created fabric. previous fabric
// started FabricConfigAdminBridge which scheduled CM updates for tens of PIDs - among others,
// org.ops4j.pax.web, which leads to an attempt to reconfigure Jetty with "profile:jetty.xml"
// and if we disable ProfileUrlHandler we may loose Jetty instance
LOGGER.debug("Disable BootstrapConfiguration");
ComponentContext componentContext = bootConfig.getComponentContext();
componentContext.disableComponent(BootstrapConfiguration.COMPONENT_NAME);
if (!unregisterLatch.await(30, TimeUnit.SECONDS))
throw new TimeoutException("Timeout for unregistering BootstrapConfiguration service");
if (unregisterLatch2 != null && !unregisterLatch2.await(30, TimeUnit.SECONDS))
throw new TimeoutException("Timeout for unregistering CuratorComplete service");
// Do the cleanup
runtimeProps.clearRuntimeAttributes();
cleanConfigurations(syscontext, zkClientCfg, zkServerCfg);
cleanZookeeperDirectory(karafData);
cleanGitDirectory(karafData);
// Setup the registration listener for the new {@link BootstrapConfiguration}
final CountDownLatch registerLatch = new CountDownLatch(1);
final AtomicReference<ServiceReference<?>> sref = new AtomicReference<ServiceReference<?>>();
listener = new ServiceListener() {
@Override
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.REGISTERED) {
LOGGER.debug("Registered BootstrapConfiguration");
syscontext.removeServiceListener(this);
sref.set(event.getServiceReference());
registerLatch.countDown();
}
}
};
syscontext.addServiceListener(listener, "(objectClass=" + BootstrapConfiguration.class.getName() + ")");
// Enable the {@link BootstrapConfiguration} component and await the registration of the respective service
LOGGER.debug("Enable BootstrapConfiguration");
componentContext.enableComponent(BootstrapConfiguration.COMPONENT_NAME);
if (!registerLatch.await(30, TimeUnit.SECONDS))
throw new TimeoutException("Timeout for registering BootstrapConfiguration service");
return (BootstrapConfiguration) syscontext.getService(sref.get());
} catch (RuntimeException rte) {
throw rte;
} catch (TimeoutException toe) {
throw toe;
} catch (Exception ex) {
throw new FabricException("Unable to delete zookeeper configuration", ex);
} finally {
LOGGER.debug("End clean fabric");
}
}
Aggregations