Search in sources :

Example 16 with ClusterMember

use of org.craftercms.studio.api.v2.dal.ClusterMember in project studio by craftercms.

the class SiteServiceImpl method updateLastCommitId.

@Override
@ValidateParams
public void updateLastCommitId(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "commitId") String commitId) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("siteId", site);
    params.put("lastCommitId", commitId);
    retryingOperationFacade.updateSiteLastCommitId(params);
    try {
        ClusterMember clusterMember = clusterDao.getMemberByLocalAddress(studioClusterUtils.getClusterNodeLocalAddress());
        if (Objects.nonNull(clusterMember)) {
            SiteFeed siteFeed = getSite(site);
            retryingOperationFacade.updateClusterNodeLastCommitId(clusterMember.getId(), siteFeed.getId(), commitId);
        }
    } catch (SiteNotFoundException e) {
        logger.error("Site not found " + site);
    }
}
Also used : ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 17 with ClusterMember

use of org.craftercms.studio.api.v2.dal.ClusterMember in project studio by craftercms.

the class SiteServiceImpl method updateLastSyncedGitlogCommitId.

@Override
public void updateLastSyncedGitlogCommitId(String site, String commitId) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("siteId", site);
    params.put("commitId", commitId);
    retryingOperationFacade.updateSiteLastSyncedGitlogCommitId(params);
    try {
        ClusterMember clusterMember = clusterDao.getMemberByLocalAddress(studioClusterUtils.getClusterNodeLocalAddress());
        if (Objects.nonNull(clusterMember)) {
            SiteFeed siteFeed = getSite(site);
            retryingOperationFacade.updateClusterNodeLastSyncedGitlogCommitId(clusterMember.getId(), siteFeed.getId(), commitId);
        }
    } catch (SiteNotFoundException e) {
        logger.error("Site not found " + site);
    }
}
Also used : ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException)

Example 18 with ClusterMember

use of org.craftercms.studio.api.v2.dal.ClusterMember in project studio by craftercms.

the class SiteServiceImpl method updateLastVerifiedGitlogCommitId.

@Override
public void updateLastVerifiedGitlogCommitId(String site, String commitId) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("siteId", site);
    params.put("commitId", commitId);
    retryingOperationFacade.updateSiteLastVerifiedGitlogCommitId(params);
    try {
        ClusterMember clusterMember = clusterDao.getMemberByLocalAddress(studioClusterUtils.getClusterNodeLocalAddress());
        if (Objects.nonNull(clusterMember)) {
            SiteFeed siteFeed = getSite(site);
            retryingOperationFacade.updateClusterNodeLastVerifiedGitlogCommitId(clusterMember.getId(), siteFeed.getId(), commitId);
        }
    } catch (SiteNotFoundException e) {
        logger.error("Site not found " + site);
    }
}
Also used : ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) HashMap(java.util.HashMap) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException)

Example 19 with ClusterMember

use of org.craftercms.studio.api.v2.dal.ClusterMember in project studio by craftercms.

the class StudioClusterSandboxRepoSyncTask method updateContent.

protected void updateContent(long localNodeId, long sId, String siteId, String sandboxBranchName, List<ClusterMember> clusterNodes) throws IOException, CryptoException, ServiceLayerException {
    logger.debug("Update sandbox for site " + siteId);
    Path siteSandboxPath = buildRepoPath(siteId).resolve(GIT_ROOT);
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    Repository repo = builder.setGitDir(siteSandboxPath.toFile()).readEnvironment().findGitDir().build();
    Map<String, String> remoteLastSyncCommits = remotesMap.get(siteId);
    if (remoteLastSyncCommits == null || remoteLastSyncCommits.isEmpty()) {
        remoteLastSyncCommits = new HashMap<String, String>();
        remotesMap.put(siteId, remoteLastSyncCommits);
    }
    try (Git git = new Git(repo)) {
        logger.debug("Update content from each active cluster memeber");
        for (ClusterMember remoteNode : clusterNodes) {
            ClusterSiteRecord csr = clusterDao.getClusterSiteRecord(remoteNode.getId(), sId);
            if (Objects.nonNull(csr) && StringUtils.equals(csr.getState(), STATE_CREATED)) {
                updateBranch(siteId, git, remoteNode, sandboxBranchName);
            }
        }
        String updatedCommitId = contentRepository.getRepoLastCommitId(siteId);
        clusterDao.updateNodeLastCommitId(localNodeId, sId, updatedCommitId);
        PreviewEventContext context = new PreviewEventContext();
        context.setSite(siteId);
        eventService.publish(EVENT_PREVIEW_SYNC, context);
    } catch (GitAPIException e) {
        logger.error("Error while syncing cluster node content for site " + siteId);
    }
}
Also used : Path(java.nio.file.Path) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RemoteRepository(org.craftercms.studio.api.v2.dal.RemoteRepository) ContentRepository(org.craftercms.studio.api.v1.repository.ContentRepository) Repository(org.eclipse.jgit.lib.Repository) ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) Git(org.eclipse.jgit.api.Git) ClusterSiteRecord(org.craftercms.studio.api.v2.dal.ClusterSiteRecord) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) PreviewEventContext(org.craftercms.studio.api.v1.ebus.PreviewEventContext)

Example 20 with ClusterMember

use of org.craftercms.studio.api.v2.dal.ClusterMember in project studio by craftercms.

the class StudioClusterSandboxRepoSyncTask method addRemotes.

protected void addRemotes(String siteId, List<ClusterMember> clusterNodes) throws InvalidRemoteUrlException, ServiceLayerException {
    Map<String, String> existingRemotes = remotesMap.get(siteId);
    logger.debug("Add cluster members as remotes to local sandbox repository");
    for (ClusterMember member : clusterNodes) {
        if (existingRemotes != null && existingRemotes.containsKey(member.getGitRemoteName())) {
            continue;
        }
        try {
            if (existingRemotes == null) {
                existingRemotes = new HashMap<String, String>();
                remotesMap.put(siteId, existingRemotes);
            }
            String remoteUrl = member.getGitUrl().replace("{siteId}", siteId) + "/" + studioConfiguration.getProperty(SANDBOX_PATH);
            addRemoteRepository(siteId, member, remoteUrl);
            existingRemotes.put(member.getGitRemoteName(), StringUtils.EMPTY);
        } catch (IOException e) {
            logger.error("Failed to open repository for site " + siteId, e);
        }
    }
}
Also used : ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) IOException(java.io.IOException)

Aggregations

ClusterMember (org.craftercms.studio.api.v2.dal.ClusterMember)26 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)10 IOException (java.io.IOException)9 Path (java.nio.file.Path)9 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)9 Git (org.eclipse.jgit.api.Git)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)9 ContentRepository (org.craftercms.studio.api.v1.repository.ContentRepository)8 Repository (org.eclipse.jgit.lib.Repository)8 ImmutableNode (org.apache.commons.configuration2.tree.ImmutableNode)7 RemoteRepository (org.craftercms.studio.api.v2.dal.RemoteRepository)7 FileRepositoryBuilder (org.eclipse.jgit.storage.file.FileRepositoryBuilder)7 HashMap (java.util.HashMap)6 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)6 InvalidRemoteUrlException (org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException)6 CryptoException (org.craftercms.commons.crypto.CryptoException)5 ClusterSiteRecord (org.craftercms.studio.api.v2.dal.ClusterSiteRecord)5 RemoteAddCommand (org.eclipse.jgit.api.RemoteAddCommand)5 URISyntaxException (java.net.URISyntaxException)4 File (java.io.File)3