use of io.fabric8.git.GitNode in project fabric8 by jboss-fuse.
the class GitHttpServerRegistrationHandler method updateMasterUrl.
private void updateMasterUrl(Group<GitNode> group) {
try {
if (group.isMaster()) {
LOGGER.debug("Git repo is the master");
if (!isMaster.getAndSet(true)) {
registerServlet(dataPath, realm, roles);
}
} else {
LOGGER.debug("Git repo is not the master");
if (isMaster.getAndSet(false)) {
unregisterServlet();
}
}
GitNode state = createState();
group.update(state);
String url = state.getUrl();
gitRemoteUrl.set(ZooKeeperUtils.getSubstitutedData(curator.get(), url));
} catch (Exception e) {
LOGGER.debug("Failed to update master git server url.", e);
}
}
use of io.fabric8.git.GitNode in project fabric8 by jboss-fuse.
the class GitMasterListener method updateMasterUrl.
/**
* Updates the git master url, if needed.
*/
private void updateMasterUrl(Group<GitNode> group) {
GitNode master = group.master();
String masterUrl = master != null ? master.getUrl() : null;
try {
if (masterUrl != null) {
GitService gitservice = gitService.get();
String substitutedUrl = getSubstitutedData(curator.get(), masterUrl);
if (!Strings.isNotBlank(substitutedUrl)) {
LOGGER.warn("Could not render git master URL {}.", masterUrl);
}
// Catch any possible issue indicating that the URL is invalid.
if (!FabricValidations.isURIValid(substitutedUrl)) {
LOGGER.warn("Not changing master Git URL to \"" + substitutedUrl + "\". There may be pending ZK connection shutdown.");
} else {
gitservice.notifyRemoteChanged(substitutedUrl);
}
}
} catch (Exception e) {
LOGGER.error("Failed to point origin to the new master.", e);
}
}
use of io.fabric8.git.GitNode 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.git.GitNode 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.git.GitNode 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);
}
}
Aggregations