@Activate void activate() throws IOException { RuntimeProperties sysprops = runtimeProperties.get(); localRepo = new File(sysprops.getProperty(SystemProperties.KARAF_DATA) + DEFAULT_GIT_PATH); if (!localRepo.exists() && !localRepo.mkdirs()) { throw new IOException("Failed to create local repository"); } git = openOrInit(localRepo); activateComponent(); }
private void registerServlet() { try { HttpContext base = httpService.get().createDefaultHttpContext(); HttpContext secure = new SecureHttpContext(base, realm, role); String basePath = System.getProperty("karaf.data") + File.separator + "git" + File.separator + "servlet" + File.separator; String fabricGitPath = basePath + "fabric"; File fabricRoot = new File(fabricGitPath); // Only need to clone once. If repo already exists, just skip. if (!fabricRoot.exists()) { Git localGit = gitService.get().get(); Git.cloneRepository() .setBare(true) .setNoCheckout(true) .setCloneAllBranches(true) .setDirectory(fabricRoot) .setURI(localGit.getRepository().getDirectory().toURI().toString()) .call(); } Dictionary<String, Object> initParams = new Hashtable<String, Object>(); initParams.put("base-path", basePath); initParams.put("repository-root", basePath); initParams.put("export-all", "true"); httpService.get().registerServlet("/git", gitServlet, initParams, secure); activateComponent(); } catch (Exception e) { FabricException.launderThrowable(e); } }
private void updateMasterUrl(Group<GitNode> group) { if (group.isMaster()) { LOGGER.debug("Git repo is the master"); } else { LOGGER.debug("Git repo is not the master"); } try { GitNode state = createState(); group.update(state); String url = state.getUrl(); gitRemoteUrl = getSubstitutedData(curator.get(), url); if (group.isMaster()) { updateConfigAdmin(); } } catch (Exception e) { // Ignore } }
@Activate void activate(Map<String, ?> configuration) { realm = configuration != null && configuration.containsKey(REALM_PROPERTY_NAME) ? (String) configuration.get(REALM_PROPERTY_NAME) : DEFAULT_REALM; role = configuration != null && configuration.containsKey(ROLE_PROPERTY_NAME) ? (String) configuration.get(ROLE_PROPERTY_NAME) : DEFAULT_ROLE; registerServlet(); group = new ZooKeeperGroup<GitNode>(curator.get(), ZkPath.GIT.getPath(), GitNode.class); group.add(this); group.update(createState()); group.start(); activateComponent(); }
private void updateConfigAdmin() { // lets register the current URL to ConfigAdmin try { Configuration conf = configAdmin.get().getConfiguration(GIT_PID); if (conf == null) { LOGGER.warn("No configuration for pid " + GIT_PID); } else { Dictionary<String, Object> properties = conf.getProperties(); if (properties == null) { properties = new Hashtable<String, Object>(); } properties.put("fabric.git.url", gitRemoteUrl); conf.update(properties); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Setting pid " + GIT_PID + " config admin to: " + properties); } } } catch (Throwable e) { LOGGER.error("Could not load config admin for pid " + GIT_PID + ". Reason: " + e, e); } }
private void unregisterServlet() { httpService.get().unregister("/git"); }