use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.
the class StudioClusterSandboxRepoSyncTask method executeInternal.
@Override
protected void executeInternal(String siteId) {
// Log start time
long startTime = System.currentTimeMillis();
logger.debug("Worker starts syncing cluster node sandbox for site " + siteId);
try {
HierarchicalConfiguration<ImmutableNode> registrationData = studioClusterUtils.getClusterConfiguration();
if (registrationData != null && !registrationData.isEmpty()) {
String localAddress = studioClusterUtils.getClusterNodeLocalAddress();
ClusterMember localNode = clusterDao.getMemberByLocalAddress(localAddress);
List<ClusterMember> clusterNodes = studioClusterUtils.getClusterNodes(localAddress);
SiteFeed siteFeed = siteService.getSite(siteId);
List<ClusterSiteRecord> clusterSiteRecords = clusterDao.getSiteStateAcrossCluster(siteId);
long nodesCreated = clusterSiteRecords.stream().filter(x -> StringUtils.equals(x.getState(), STATE_CREATED)).count();
if (nodesCreated < 1 && !StringUtils.equals(siteFeed.getState(), STATE_CREATED)) {
return;
}
// Check if site exists
logger.debug("Check if site " + siteId + " exists in local repository");
boolean success = true;
boolean siteCheck = checkIfSiteRepoExists(siteId);
if (!siteCheck) {
// Site doesn't exist locally, create it
success = createSite(localNode.getId(), siteFeed.getId(), siteId, siteFeed.getSiteUuid(), siteFeed.getSearchEngine(), clusterNodes, clusterSiteRecords);
}
if (success && clusterDao.existsClusterSiteSyncRepo(localNode.getId(), siteFeed.getId()) < 1) {
String commitId = contentRepository.getRepoLastCommitId(siteId);
clusterDao.insertClusterSiteSyncRepo(localNode.getId(), siteFeed.getId(), commitId, commitId, siteFeed.getLastSyncedGitlogCommitId());
clusterDao.setSiteState(localNode.getId(), siteFeed.getId(), STATE_CREATED);
addSiteUuidFile(siteId, siteFeed.getSiteUuid());
}
if (success) {
syncRemoteRepositories(siteId, localAddress);
// Check if the site needs to be synced
boolean syncRequired = isSyncRequired(siteId, siteFeed.getLastCommitId());
if (syncRequired) {
try {
// Add the remote repositories to the local repository to sync from if not added already
logger.debug("Add remotes for site " + siteId);
addRemotes(siteId, clusterNodes);
} catch (InvalidRemoteUrlException | ServiceLayerException e) {
logger.error("Error while adding remotes on cluster node for site " + siteId);
}
try {
// Sync with remote and update the local cache with the last commit ID to speed things up
logger.debug("Update content for site " + siteId);
updateContent(localNode.getId(), siteFeed.getId(), siteId, siteFeed.getSandboxBranch(), clusterNodes);
} catch (IOException | CryptoException | ServiceLayerException e) {
logger.error("Error while updating content for site " + siteId + " on cluster node.", e);
}
}
}
}
} catch (SiteNotFoundException | IOException e) {
logger.error("Error while executing Cluster Node Sync Sandbox for site " + siteId, e);
}
// Compute execution duration and log it
long duration = System.currentTimeMillis() - startTime;
logger.debug("Worker finished syncing cluster node for site " + siteId);
logger.debug("Worker performed cluster node sync for site " + siteId + " in " + duration + "ms");
logger.debug("Finished Cluster Node Sync task for site " + siteId);
}
use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.
the class StudioAuditLogProcessingTask method processAuditLog.
private void processAuditLog(String site) throws SiteNotFoundException {
logger.debug("Getting last verified commit for site: " + site);
SiteFeed siteFeed = siteService.getSite(site);
if (checkSiteUuid(site, siteFeed.getSiteUuid())) {
String lastSyncedCommit = siteService.getLastSyncedGitlogCommitId(site);
if (StringUtils.isNotEmpty(lastSyncedCommit)) {
logger.debug("Update gitlog for site " + site + " from last synced commit " + lastSyncedCommit);
contentRepository.updateGitlog(site, lastSyncedCommit, batchSizeGitLog);
processAuditLogFromRepo(site, batchSizeAudited);
}
}
}
use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.
the class StudioAuditLogProcessingTask method processAuditLogFromRepo.
private void processAuditLogFromRepo(String siteId, int batchSize) throws SiteNotFoundException {
List<GitLog> unauditedGitlogs = contentRepository.getUnauditedCommits(siteId, batchSize);
if (unauditedGitlogs != null) {
SiteFeed siteFeed = siteService.getSite(siteId);
for (GitLog gl : unauditedGitlogs) {
if (contentRepository.commitIdExists(siteId, gl.getCommitId())) {
String prevCommitId = gl.getCommitId() + PREVIOUS_COMMIT_SUFFIX;
List<RepoOperation> operations = contentRepository.getOperationsFromDelta(siteId, prevCommitId, gl.getCommitId());
for (RepoOperation repoOperation : operations) {
Map<String, String> activityInfo = new HashMap<String, String>();
String contentClass;
AuditLog auditLog;
switch(repoOperation.getAction()) {
case CREATE:
case COPY:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_CREATE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
auditLog.setOrigin(ORIGIN_GIT);
auditServiceInternal.insertAuditLog(auditLog);
break;
case UPDATE:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_UPDATE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setOrigin(ORIGIN_GIT);
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
auditServiceInternal.insertAuditLog(auditLog);
break;
case DELETE:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_DELETE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setOrigin(ORIGIN_GIT);
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
auditServiceInternal.insertAuditLog(auditLog);
break;
case MOVE:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getMoveToPath());
if (repoOperation.getMoveToPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getMoveToPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_MOVE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setOrigin(ORIGIN_GIT);
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getMoveToPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getMoveToPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getMoveToPath()));
auditServiceInternal.insertAuditLog(auditLog);
break;
default:
logger.error("Error: Unknown repo operation for site " + siteId + " operation: " + repoOperation.getAction());
break;
}
}
}
contentRepository.markGitLogAudited(siteId, gl.getCommitId());
}
}
}
use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.
the class ContentServiceImpl method createFolder.
@Override
@ValidateParams
public boolean createFolder(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "name") String name) throws SiteNotFoundException {
boolean toRet = false;
String commitId = _contentRepository.createFolder(site, path, name);
if (commitId != null) {
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_CREATE);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(securityService.getCurrentUser());
auditLog.setPrimaryTargetId(site + ":" + path + FILE_SEPARATOR + name);
auditLog.setPrimaryTargetType(TARGET_TYPE_FOLDER);
auditLog.setPrimaryTargetValue(path + FILE_SEPARATOR + name);
auditServiceInternal.insertAuditLog(auditLog);
contentRepository.insertGitLog(site, commitId, 1, 1);
siteService.updateLastCommitId(site, commitId);
toRet = true;
}
return toRet;
}
use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.
the class ContentServiceImpl method updateDatabaseOnMove.
protected void updateDatabaseOnMove(String site, String fromPath, String movePath) throws SiteNotFoundException {
logger.debug("updateDatabaseOnMove FROM {0} TO {1} ", fromPath, movePath);
String user = securityService.getCurrentUser();
Map<String, String> params = new HashMap<>();
params.put(DmConstants.KEY_SOURCE_PATH, fromPath);
params.put(DmConstants.KEY_TARGET_PATH, movePath);
// These do not exist in 3.0, note some extensions may be using it
// params.put(DmConstants.KEY_SOURCE_FULL_PATH, expandRelativeSitePath(site, fromPath));
// params.put(DmConstants.KEY_TARGET_FULL_PATH, expandRelativeSitePath(site, movePath));
ContentItemTO renamedItem = getContentItem(site, movePath, 0);
String contentType = renamedItem.getContentType();
if (!renamedItem.isFolder()) {
dmContentLifeCycleService.process(site, user, movePath, contentType, DmContentLifeCycleService.ContentLifeCycleOperation.RENAME, params);
// change the path of this object in the object state database
objectStateService.updateObjectPath(site, fromPath, movePath);
objectStateService.transition(site, renamedItem, SAVE);
renamedItem = getContentItem(site, movePath, 0);
}
// update metadata
if (!objectMetadataManager.isRenamed(site, fromPath)) {
// if an item was previously moved, we do not track intermediate moves because it will
// ultimately orphan deployed content. Old Path is always the OLDEST DEPLOYED PATH
ItemMetadata metadata = objectMetadataManager.getProperties(site, fromPath);
if (metadata == null && !renamedItem.isFolder()) {
if (!objectMetadataManager.metadataExist(site, fromPath)) {
objectMetadataManager.insertNewObjectMetadata(site, fromPath);
}
metadata = objectMetadataManager.getProperties(site, fromPath);
}
if (!renamedItem.isNew() && !renamedItem.isFolder()) {
// if the item is not new, we need to track the old URL for deployment
logger.debug("item is not new, and has not previously been moved. Track the old URL {0}", fromPath);
Map<String, Object> objMetadataProps = new HashMap<String, Object>();
objMetadataProps.put(ItemMetadata.PROP_RENAMED, 1);
objMetadataProps.put(ItemMetadata.PROP_OLD_URL, fromPath);
objectMetadataManager.setObjectMetadata(site, fromPath, objMetadataProps);
}
}
if (!renamedItem.isFolder()) {
if (objectMetadataManager.metadataExist(site, movePath)) {
if (!StringUtils.equalsIgnoreCase(fromPath, movePath)) {
objectMetadataManager.deleteObjectMetadata(site, movePath);
}
}
objectMetadataManager.updateObjectPath(site, fromPath, movePath);
}
// write activity stream
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_MOVE);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(user);
auditLog.setPrimaryTargetId(site + ":" + movePath);
if (renamedItem.isFolder()) {
auditLog.setPrimaryTargetType(TARGET_TYPE_FOLDER);
} else {
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
}
auditLog.setPrimaryTargetValue(movePath);
auditLog.setPrimaryTargetSubtype(getContentTypeClass(site, movePath));
auditServiceInternal.insertAuditLog(auditLog);
updateDependenciesOnMove(site, fromPath, movePath);
}
Aggregations