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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations