Search in sources :

Example 1 with SiteNotFoundException

use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.

the class ConfigurationServiceImpl method generateAuditLog.

private void generateAuditLog(String siteId, String path, String user) throws SiteNotFoundException {
    SiteFeed siteFeed = siteService.getSite(siteId);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_UPDATE);
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setActorId(user);
    auditLog.setPrimaryTargetId(siteId + ":" + path);
    auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
    auditLog.setPrimaryTargetValue(path);
    auditLog.setPrimaryTargetSubtype(CONTENT_TYPE_CONFIGURATION);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 2 with SiteNotFoundException

use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.

the class PublishServiceImpl method createAuditLogEntry.

private void createAuditLogEntry(String siteId, List<AuditLogParameter> auditLogParameters) throws SiteNotFoundException {
    SiteFeed siteFeed = siteService.getSite(siteId);
    AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
    auditLog.setOperation(OPERATION_CANCEL_PUBLISHING_PACKAGE);
    auditLog.setActorId(securityService.getCurrentUser());
    auditLog.setSiteId(siteFeed.getId());
    auditLog.setPrimaryTargetId(siteId);
    auditLog.setPrimaryTargetType(TARGET_TYPE_SITE);
    auditLog.setPrimaryTargetValue(siteId);
    auditLog.setParameters(auditLogParameters);
    auditServiceInternal.insertAuditLog(auditLog);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog)

Example 3 with SiteNotFoundException

use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.

the class ClusterManagementServiceImpl method removeMembers.

@Override
@HasPermission(type = DefaultPermission.class, action = "delete_cluster")
public boolean removeMembers(List<Long> memberIds) throws SiteNotFoundException {
    List<ClusterMember> members = getAllMemebers();
    boolean toRet = clusterManagementServiceInternal.removeMembers(memberIds);
    if (toRet) {
        SiteFeed siteFeed = siteService.getSite(studioConfiguration.getProperty(CONFIGURATION_GLOBAL_SYSTEM_SITE));
        AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
        auditLog.setSiteId(siteFeed.getId());
        auditLog.setOperation(OPERATION_REMOVE_CLUSTER_NODE);
        auditLog.setActorId(securityService.getCurrentUser());
        auditLog.setPrimaryTargetId(siteFeed.getSiteId());
        auditLog.setPrimaryTargetType(TARGET_TYPE_CLUSTER_NODE);
        auditLog.setPrimaryTargetValue(siteFeed.getName());
        List<AuditLogParameter> paramters = new ArrayList<AuditLogParameter>();
        for (ClusterMember m : members) {
            AuditLogParameter paramter = new AuditLogParameter();
            paramter.setTargetId(Long.toString(m.getId()));
            paramter.setTargetType(TARGET_TYPE_CLUSTER_NODE);
            paramter.setTargetValue(m.getLocalAddress());
            paramters.add(paramter);
        }
        auditLog.setParameters(paramters);
        auditServiceInternal.insertAuditLog(auditLog);
    }
    return toRet;
}
Also used : ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) ArrayList(java.util.ArrayList) AuditLogParameter(org.craftercms.studio.api.v2.dal.AuditLogParameter) AuditLog(org.craftercms.studio.api.v2.dal.AuditLog) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 4 with SiteNotFoundException

use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.

the class StudioPublisherTask method deploy.

private void deploy(String site, String environment, List<DeploymentItemTO> items, String author, String comment) throws DeploymentException, SiteNotFoundException {
    logger.debug("Deploying " + items.size() + " item(s)");
    SiteFeed siteFeed = siteService.getSite(site);
    if (servicesConfig.isStagingEnvironmentEnabled(site)) {
        String liveEnvironment = servicesConfig.getLiveEnvironment(site);
        if (StringUtils.equals(liveEnvironment, environment)) {
            String stagingEnvironment = servicesConfig.getStagingEnvironment(site);
            contentRepository.publish(site, siteFeed.getSandboxBranch(), items, stagingEnvironment, author, comment);
        }
    }
    contentRepository.publish(site, siteFeed.getSandboxBranch(), items, environment, author, comment);
}
Also used : SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed)

Example 5 with SiteNotFoundException

use of org.craftercms.studio.api.v1.exception.SiteNotFoundException in project studio by craftercms.

the class StudioClusterPublishedRepoSyncTask method executeInternal.

@Override
protected void executeInternal(String siteId) {
    // Log start time
    long startTime = System.currentTimeMillis();
    logger.debug("Worker starts syncing cluster node published 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);
            Optional<ClusterSiteRecord> localNodeRecord = clusterSiteRecords.stream().filter(x -> x.getClusterNodeId() == localNode.getId() && StringUtils.equals(x.getState(), STATE_CREATED)).findFirst();
            if (!localNodeRecord.isPresent()) {
                return;
            }
            long nodesCreated = clusterSiteRecords.stream().filter(x -> StringUtils.equals(x.getState(), STATE_CREATED)).count();
            if (nodesCreated < 1) {
                return;
            }
            // Check if site exists
            logger.debug("Check if site " + siteId + " exists in local repository");
            boolean success = true;
            int publishedReposCreated = clusterSiteRecords.stream().mapToInt(ClusterSiteRecord::getPublishedRepoCreated).sum();
            if (publishedReposCreated > 0 || siteFeed.getPublishedRepoCreated() > 0) {
                boolean siteCheck = checkIfSiteRepoExists(siteId);
                if (!siteCheck) {
                    // Site doesn't exist locally, create it
                    success = createSite(localNode.getId(), siteFeed.getId(), siteId, siteFeed.getSandboxBranch());
                } else {
                    clusterDao.setPublishedRepoCreated(localNode.getId(), siteFeed.getId());
                }
            } else {
                success = false;
            }
            if (success) {
                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 | CryptoException 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(siteFeed.getId(), siteId, clusterNodes, clusterSiteRecords);
                } catch (IOException | CryptoException | ServiceLayerException e) {
                    logger.error("Error while updating content for site " + siteId + " on cluster node.", e);
                }
            }
        }
    } catch (SiteNotFoundException e) {
        logger.error("Error while executing Cluster Node Sync Published 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);
}
Also used : RetryingRepositoryOperationFacade(org.craftercms.studio.api.v2.repository.RetryingRepositoryOperationFacade) PullCommand(org.eclipse.jgit.api.PullCommand) PUBLISHED_PATH(org.craftercms.studio.api.v2.utils.StudioConfiguration.PUBLISHED_PATH) UserServiceInternal(org.craftercms.studio.api.v2.service.security.internal.UserServiceInternal) TextEncryptor(org.craftercms.commons.crypto.TextEncryptor) URISyntaxException(java.net.URISyntaxException) StringUtils(org.apache.commons.lang3.StringUtils) InvalidRemoteUrlException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException) Config(org.eclipse.jgit.lib.Config) SITE_PUBLISHED_REPOSITORY_GIT_LOCK(org.craftercms.studio.api.v1.constant.StudioConstants.SITE_PUBLISHED_REPOSITORY_GIT_LOCK) ClusterSiteRecord(org.craftercms.studio.api.v2.dal.ClusterSiteRecord) Map(java.util.Map) URIish(org.eclipse.jgit.transport.URIish) ClusterDAO(org.craftercms.studio.api.v2.dal.ClusterDAO) RemoteAddCommand(org.eclipse.jgit.api.RemoteAddCommand) Path(java.nio.file.Path) STATE_CREATED(org.craftercms.studio.api.v1.dal.SiteFeed.STATE_CREATED) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) Set(java.util.Set) SiteService(org.craftercms.studio.api.v1.service.site.SiteService) Constants(org.eclipse.jgit.lib.Constants) UUID(java.util.UUID) CONFIG_PARAMETER_URL(org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryConstants.CONFIG_PARAMETER_URL) Objects(java.util.Objects) CONFIG_SECTION_REMOTE(org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryConstants.CONFIG_SECTION_REMOTE) List(java.util.List) ServicesConfig(org.craftercms.studio.api.v1.service.configuration.ServicesConfig) StudioConfiguration(org.craftercms.studio.api.v2.utils.StudioConfiguration) PATTERN_SITE(org.craftercms.studio.api.v1.constant.StudioConstants.PATTERN_SITE) Ref(org.eclipse.jgit.lib.Ref) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) Optional(java.util.Optional) CLUSTER_NODE_REMOTE_NAME_PREFIX(org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryConstants.CLUSTER_NODE_REMOTE_NAME_PREFIX) ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) Logger(org.craftercms.studio.api.v1.log.Logger) HashMap(java.util.HashMap) FetchCommand(org.eclipse.jgit.api.FetchCommand) RemoteSetUrlCommand(org.eclipse.jgit.api.RemoteSetUrlCommand) HashSet(java.util.HashSet) ImmutableNode(org.apache.commons.configuration2.tree.ImmutableNode) LoggerFactory(org.craftercms.studio.api.v1.log.LoggerFactory) Files(java.nio.file.Files) StudioClusterUtils(org.craftercms.studio.impl.v2.service.cluster.StudioClusterUtils) IOException(java.io.IOException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) ContentRepository(org.craftercms.studio.api.v1.repository.ContentRepository) CryptoException(org.craftercms.commons.crypto.CryptoException) CheckoutCommand(org.eclipse.jgit.api.CheckoutCommand) GIT_ROOT(org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryConstants.GIT_ROOT) SecurityService(org.craftercms.studio.api.v1.service.security.SecurityService) GitRepositoryHelper(org.craftercms.studio.api.v2.utils.GitRepositoryHelper) Paths(java.nio.file.Paths) GeneralLockService(org.craftercms.studio.api.v1.service.GeneralLockService) Git(org.eclipse.jgit.api.Git) Repository(org.eclipse.jgit.lib.Repository) PUBLISHED(org.craftercms.studio.api.v1.constant.GitRepositories.PUBLISHED) ImmutableNode(org.apache.commons.configuration2.tree.ImmutableNode) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) IOException(java.io.IOException) ClusterSiteRecord(org.craftercms.studio.api.v2.dal.ClusterSiteRecord) InvalidRemoteUrlException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException) ClusterMember(org.craftercms.studio.api.v2.dal.ClusterMember) SiteFeed(org.craftercms.studio.api.v1.dal.SiteFeed) CryptoException(org.craftercms.commons.crypto.CryptoException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException)

Aggregations

SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)41 SiteFeed (org.craftercms.studio.api.v1.dal.SiteFeed)34 AuditLog (org.craftercms.studio.api.v2.dal.AuditLog)23 ResponseBody (org.craftercms.studio.model.rest.ResponseBody)20 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)12 PostMapping (org.springframework.web.bind.annotation.PostMapping)11 ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)10 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)9 GetMapping (org.springframework.web.bind.annotation.GetMapping)9 ClusterMember (org.craftercms.studio.api.v2.dal.ClusterMember)8 Result (org.craftercms.studio.model.rest.Result)8 CryptoException (org.craftercms.commons.crypto.CryptoException)6 ResultOne (org.craftercms.studio.model.rest.ResultOne)6 IOException (java.io.IOException)5 Set (java.util.Set)5 ItemMetadata (org.craftercms.studio.api.v1.dal.ItemMetadata)5 AuditLogParameter (org.craftercms.studio.api.v2.dal.AuditLogParameter)5 HashSet (java.util.HashSet)4