| | |
| | | import com.gitblit.Constants.FederationPullStatus;
|
| | | import com.gitblit.Constants.FederationStrategy;
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.manager.IGitblitManager;
|
| | | import com.gitblit.manager.INotificationManager;
|
| | | import com.gitblit.manager.IRepositoryManager;
|
| | | import com.gitblit.manager.IRuntimeManager;
|
| | | import com.gitblit.manager.IUserManager;
|
| | | import com.gitblit.models.FederationModel;
|
| | | import com.gitblit.models.RefModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | |
| | | /**
|
| | | * Constructor for specifying a single federation registration. This
|
| | | * constructor is used to schedule the next pull execution.
|
| | | * |
| | | *
|
| | | * @param registration
|
| | | */
|
| | | private FederationPullExecutor(FederationModel registration) {
|
| | |
| | | * Constructor to specify a group of federation registrations. This is
|
| | | * normally used at startup to pull and then schedule the next update based
|
| | | * on each registrations frequency setting.
|
| | | * |
| | | *
|
| | | * @param registrations
|
| | | * @param isDaemon
|
| | | * if true, registrations are rescheduled in perpetuity. if
|
| | |
| | | if (registration.notifyOnError) {
|
| | | String message = "Federation pull of " + registration.name + " @ "
|
| | | + registration.url + " is now at " + is.name();
|
| | | GitBlit.self()
|
| | | INotificationManager mailManager = GitBlit.getManager(INotificationManager.class);
|
| | | mailManager
|
| | | .sendMailToAdministrators(
|
| | | "Pull Status of " + registration.name + " is " + is.name(),
|
| | | message);
|
| | |
| | | /**
|
| | | * Mirrors a repository and, optionally, the server's users, and/or
|
| | | * configuration settings from a origin Gitblit instance.
|
| | | * |
| | | *
|
| | | * @param registration
|
| | | * @throws Exception
|
| | | */
|
| | |
| | | c, registrationFolder, registration.name));
|
| | | return;
|
| | | }
|
| | | File repositoriesFolder = new File(GitBlit.getString(Keys.git.repositoriesFolder, "git"));
|
| | | IRepositoryManager repositoryManager = GitBlit.getManager(IRepositoryManager.class);
|
| | | File repositoriesFolder = repositoryManager.getRepositoriesFolder();
|
| | | File registrationFolderFile = new File(repositoriesFolder, registrationFolder);
|
| | | registrationFolderFile.mkdirs();
|
| | |
|
| | |
| | | repositoryName.indexOf(DOT_GIT_EXT));
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | // confirm that the origin of any pre-existing repository matches
|
| | | // the clone url
|
| | | String fetchHead = null;
|
| | | Repository existingRepository = GitBlit.self().getRepository(repositoryName);
|
| | | |
| | | if (existingRepository == null && GitBlit.self().isCollectingGarbage(repositoryName)) {
|
| | | Repository existingRepository = repositoryManager.getRepository(repositoryName);
|
| | |
|
| | | if (existingRepository == null && repositoryManager.isCollectingGarbage(repositoryName)) {
|
| | | logger.warn(MessageFormat.format("Skipping local repository {0}, busy collecting garbage", repositoryName));
|
| | | continue;
|
| | | }
|
| | |
| | |
|
| | | CloneResult result = JGitUtils.cloneRepository(registrationFolderFile, repository.name,
|
| | | cloneUrl, registration.bare, credentials);
|
| | | Repository r = GitBlit.self().getRepository(repositoryName);
|
| | | RepositoryModel rm = GitBlit.self().getRepositoryModel(repositoryName);
|
| | | Repository r = repositoryManager.getRepository(repositoryName);
|
| | | RepositoryModel rm = repositoryManager.getRepositoryModel(repositoryName);
|
| | | repository.isFrozen = registration.mirror;
|
| | | if (result.createdRepository) {
|
| | | // default local settings
|
| | |
| | | String branch = org.eclipse.jgit.lib.Constants.R_HEADS
|
| | | + ref.displayName.substring(ref.displayName.indexOf('/') + 1);
|
| | | String hash = ref.getReferencedObjectId().getName();
|
| | | |
| | |
|
| | | JGitUtils.setBranchRef(r, branch, hash);
|
| | | logger.info(MessageFormat.format(" resetting {0} of {1} to {2}", branch,
|
| | | repository.name, hash));
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | String newHead;
|
| | | if (StringUtils.isEmpty(repository.HEAD)) {
|
| | | newHead = newFetchHead;
|
| | |
| | | federationSets.addAll(repository.federationSets);
|
| | | }
|
| | | repository.federationSets = new ArrayList<String>(federationSets);
|
| | | |
| | |
|
| | | // merge indexed branches
|
| | | Set<String> indexedBranches = new HashSet<String>();
|
| | | if (rm.indexedBranches != null) {
|
| | |
| | | // "federated" repositories.
|
| | | repository.isFederated = cloneUrl.startsWith(registration.url);
|
| | |
|
| | | GitBlit.self().updateConfiguration(r, repository);
|
| | | repositoryManager.updateConfiguration(r, repository);
|
| | | r.close();
|
| | | }
|
| | |
|
| | | IUserManager userManager = GitBlit.getManager(IUserManager.class);
|
| | | IGitblitManager gitblitManager = GitBlit.getManager(IGitblitManager.class);
|
| | | IUserService userService = null;
|
| | |
|
| | | try {
|
| | |
| | | }
|
| | |
|
| | | // insert new user or update local user
|
| | | UserModel localUser = GitBlit.self().getUserModel(user.username);
|
| | | UserModel localUser = userManager.getUserModel(user.username);
|
| | | if (localUser == null) {
|
| | | // create new local user
|
| | | GitBlit.self().updateUserModel(user.username, user, true);
|
| | | gitblitManager.updateUserModel(user.username, user, true);
|
| | | } else {
|
| | | // update repository permissions of local user
|
| | | if (user.permissions != null) {
|
| | |
| | | }
|
| | | localUser.password = user.password;
|
| | | localUser.canAdmin = user.canAdmin;
|
| | | GitBlit.self().updateUserModel(localUser.username, localUser, false);
|
| | | gitblitManager.updateUserModel(localUser.username, localUser, false);
|
| | | }
|
| | |
|
| | | for (String teamname : GitBlit.self().getAllTeamnames()) {
|
| | | TeamModel team = GitBlit.self().getTeamModel(teamname);
|
| | | for (String teamname : userManager.getAllTeamNames()) {
|
| | | TeamModel team = userManager.getTeamModel(teamname);
|
| | | if (user.isTeamMember(teamname) && !team.hasUser(user.username)) {
|
| | | // new team member
|
| | | team.addUser(user.username);
|
| | | GitBlit.self().updateTeamModel(teamname, team, false);
|
| | | userManager.updateTeamModel(teamname, team);
|
| | | } else if (!user.isTeamMember(teamname) && team.hasUser(user.username)) {
|
| | | // remove team member
|
| | | team.removeUser(user.username);
|
| | | GitBlit.self().updateTeamModel(teamname, team, false);
|
| | | userManager.updateTeamModel(teamname, team);
|
| | | }
|
| | |
|
| | | // update team repositories
|
| | |
| | | for (Map.Entry<String, AccessPermission> entry : remoteTeam.permissions.entrySet()){
|
| | | team.setRepositoryPermission(entry.getKey(), entry.getValue());
|
| | | }
|
| | | GitBlit.self().updateTeamModel(teamname, team, false);
|
| | | userManager.updateTeamModel(teamname, team);
|
| | | } else if(!ArrayUtils.isEmpty(remoteTeam.repositories)) {
|
| | | // pulling from <= 1.1
|
| | | team.addRepositoryPermissions(remoteTeam.repositories);
|
| | | GitBlit.self().updateTeamModel(teamname, team, false);
|
| | | userManager.updateTeamModel(teamname, team);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | /**
|
| | | * Sends a status acknowledgment to the origin Gitblit instance. This
|
| | | * includes the results of the federated pull.
|
| | | * |
| | | *
|
| | | * @param registration
|
| | | * @throws Exception
|
| | | */
|
| | |
| | | return;
|
| | | }
|
| | | InetAddress addr = InetAddress.getLocalHost();
|
| | | String federationName = GitBlit.getString(Keys.federation.name, null);
|
| | | IStoredSettings settings = GitBlit.getManager(IRuntimeManager.class).getSettings();
|
| | | String federationName = settings.getString(Keys.federation.name, null);
|
| | | if (StringUtils.isEmpty(federationName)) {
|
| | | federationName = addr.getHostName();
|
| | | }
|
| | |
| | |
|
| | | /**
|
| | | * Schedules the next check of the federated Gitblit instance.
|
| | | * |
| | | *
|
| | | * @param registration
|
| | | */
|
| | | private void schedule(FederationModel registration) {
|