Search in sources :

Example 1 with GitNode

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);
    }
}
Also used : GitNode(io.fabric8.git.GitNode) InstanceNotFoundException(javax.management.InstanceNotFoundException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 2 with GitNode

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);
    }
}
Also used : GitService(io.fabric8.git.GitService) GitNode(io.fabric8.git.GitNode) IOException(java.io.IOException)

Example 3 with GitNode

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();
}
Also used : NamedThreadFactory(io.fabric8.utils.NamedThreadFactory) GitNode(io.fabric8.git.GitNode) RuntimeProperties(io.fabric8.api.RuntimeProperties) Activate(org.apache.felix.scr.annotations.Activate)

Example 4 with GitNode

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;
}
Also used : GitNode(io.fabric8.git.GitNode) RuntimeProperties(io.fabric8.api.RuntimeProperties)

Example 5 with GitNode

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);
    }
}
Also used : RuntimeProperties(io.fabric8.api.RuntimeProperties) KeeperException(org.apache.zookeeper.KeeperException) InstanceNotFoundException(javax.management.InstanceNotFoundException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Aggregations

GitNode (io.fabric8.git.GitNode)4 RuntimeProperties (io.fabric8.api.RuntimeProperties)3 IOException (java.io.IOException)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 KeeperException (org.apache.zookeeper.KeeperException)2 GitService (io.fabric8.git.GitService)1 NamedThreadFactory (io.fabric8.utils.NamedThreadFactory)1 Activate (org.apache.felix.scr.annotations.Activate)1