use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class DmPublishServiceImpl method bulkGoLive.
@Override
@ValidateParams
public void bulkGoLive(@ValidateStringParam(name = "site") String site, @ValidateStringParam String environment, @ValidateSecurePathParam(name = "path") String path, String comment) throws ServiceLayerException {
logger.info("Starting Bulk Publish to '" + environment + "' for path " + path + " site " + site);
String queryPath = path;
if (queryPath.startsWith(FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
queryPath = queryPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, "");
}
logger.debug("Get change set for subtree for site: " + site + " root path: " + queryPath);
List<String> childrenPaths = new ArrayList<String>();
childrenPaths = objectStateService.getChangeSetForSubtree(site, queryPath);
logger.debug("Collected " + childrenPaths.size() + " content items for site " + site + " and root path " + queryPath);
Set<String> processedPaths = new HashSet<String>();
ZonedDateTime launchDate = ZonedDateTime.now(ZoneOffset.UTC);
for (String childPath : childrenPaths) {
String childHash = DigestUtils.md2Hex(childPath);
logger.debug("Processing dependencies for site " + site + " path " + childPath);
if (processedPaths.add(childHash)) {
List<String> pathsToPublish = new ArrayList<String>();
List<String> candidatesToPublish = new ArrayList<String>();
pathsToPublish.add(childPath);
candidatesToPublish.addAll(objectMetadataManager.getSameCommitItems(site, childPath));
candidatesToPublish.addAll(dependencyService.getPublishingDependencies(site, childPath));
for (String pathToAdd : candidatesToPublish) {
String hash = DigestUtils.md2Hex(pathToAdd);
if (processedPaths.add(hash)) {
pathsToPublish.add(pathToAdd);
}
}
String aprover = securityService.getCurrentUser();
if (StringUtils.isEmpty(comment)) {
comment = "Bulk Publish invoked by " + aprover;
}
logger.info("Deploying package of " + pathsToPublish.size() + " items to '" + environment + "' for site" + site + " path " + childPath);
try {
deploymentService.deploy(site, environment, pathsToPublish, launchDate, aprover, comment, true);
} catch (DeploymentException e) {
logger.error("Error while running Bulk Publish operation", e);
} finally {
logger.debug("Finished processing deployment package for path " + childPath + " site " + site);
}
}
}
logger.info("Finished Bulk Publish to '" + environment + "' for path " + path + " site " + site);
}
use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class PublishingManagerImpl method markItemsReady.
@RetryingOperation
@Override
@ValidateParams
public void markItemsReady(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<PublishRequest> copyToEnvironmentItems) throws DeploymentException {
for (PublishRequest item : copyToEnvironmentItems) {
item.setState(READY_FOR_LIVE);
publishRequestMapper.updateItemDeploymentState(item);
}
}
use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class PublishingManagerImpl method markItemsProcessing.
@RetryingOperation
@Override
@ValidateParams
public void markItemsProcessing(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<PublishRequest> itemsToDeploy) throws DeploymentException {
for (PublishRequest item : itemsToDeploy) {
item.setState(PublishRequest.State.PROCESSING);
publishRequestMapper.updateItemDeploymentState(item);
}
}
use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class PublishingManagerImpl method markItemsCompleted.
@Override
@ValidateParams
public void markItemsCompleted(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "environment") String environment, List<PublishRequest> processedItems) throws DeploymentException {
ZonedDateTime completed = ZonedDateTime.now();
for (PublishRequest item : processedItems) {
item.setState(PublishRequest.State.COMPLETED);
item.setCompletedDate(completed);
retryingOperationFacade.markPublishRequestCompleted(item);
}
}
use of org.craftercms.studio.api.v1.service.deployment.DeploymentException in project studio by craftercms.
the class PublishingManagerImpl method processItem.
@Override
public DeploymentItemTO processItem(PublishRequest item) throws DeploymentException, SiteNotFoundException {
if (item == null) {
throw new DeploymentException("Cannot process item, item is null.");
}
DeploymentItemTO deploymentItem = new DeploymentItemTO();
deploymentItem.setSite(item.getSite());
deploymentItem.setPath(item.getPath());
deploymentItem.setCommitId(item.getCommitId());
deploymentItem.setPackageId(item.getPackageId());
String site = item.getSite();
String path = item.getPath();
String oldPath = item.getOldPath();
String environment = item.getEnvironment();
String action = item.getAction();
String user = item.getUser();
String liveEnvironment = LIVE_ENVIRONMENT;
if (servicesConfig.isStagingEnvironmentEnabled(site)) {
liveEnvironment = servicesConfig.getLiveEnvironment(site);
}
boolean isLive = false;
if (StringUtils.isNotEmpty(liveEnvironment)) {
if (liveEnvironment.equals(environment)) {
isLive = true;
}
} else if (StringUtils.equalsIgnoreCase(LIVE_ENVIRONMENT, item.getEnvironment()) || StringUtils.equalsIgnoreCase(PRODUCTION_ENVIRONMENT, environment)) {
isLive = true;
}
if (StringUtils.equals(action, PublishRequest.Action.DELETE)) {
if (oldPath != null && oldPath.length() > 0) {
contentService.deleteContent(site, oldPath, user);
boolean hasRenamedChildren = false;
if (oldPath.endsWith(FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
if (contentService.contentExists(site, oldPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""))) {
// TODO: SJ: This bypasses the Content Service, fix
RepositoryItem[] children = contentRepository.getContentChildren(site, oldPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""));
if (children.length > 1) {
hasRenamedChildren = true;
}
}
if (!hasRenamedChildren) {
deleteFolder(site, oldPath.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""), user);
}
}
deploymentItem.setMove(true);
deploymentItem.setOldPath(oldPath);
objectMetadataManager.clearRenamed(site, path);
}
boolean haschildren = false;
if (item.getPath().endsWith(FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
if (contentService.contentExists(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""))) {
// TODO: SJ: This bypasses the Content Service, fix
RepositoryItem[] children = contentRepository.getContentChildren(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""));
if (children.length > 1) {
haschildren = true;
}
}
}
if (contentService.contentExists(site, path)) {
contentService.deleteContent(site, path, user);
if (!haschildren) {
deleteFolder(site, path.replace(FILE_SEPARATOR + DmConstants.INDEX_FILE, ""), user);
}
}
deploymentItem.setDelete(true);
} else {
if (StringUtils.equals(action, PublishRequest.Action.MOVE)) {
deploymentItem.setMove(true);
deploymentItem.setOldPath(oldPath);
if (oldPath != null && oldPath.length() > 0) {
if (isLive) {
objectMetadataManager.clearRenamed(site, path);
}
}
}
ItemMetadata itemMetadata = objectMetadataManager.getProperties(site, path);
if (itemMetadata == null) {
if (contentService.contentExists(site, path)) {
LOGGER.warn("Content item: '" + site + "':'" + path + "' doesn't exists in " + "the database, but does exist in git. This may cause problems " + "in the environment: '" + environment + "'");
} else {
LOGGER.warn("Content item: '" + site + "':'" + path + "' cannot be published. " + "Content does not exist in git nor in the database. Skipping...");
return null;
}
} else {
ContentItemTO contentItem = contentService.getContentItem(site, path);
if (isLive) {
// should consider what should be done if this does not work.
// Currently the method will bail and the item is stuck in processing.
LOGGER.debug("Environment is live, transition item to LIVE state {0}:{1}", site, path);
// check if commit id from workflow and from object state match
if (Objects.isNull(itemMetadata.getCommitId()) || itemMetadata.getCommitId().equals(item.getCommitId())) {
objectStateService.transition(site, contentItem, TransitionEvent.DEPLOYMENT);
}
} else {
objectStateService.transition(site, contentItem, TransitionEvent.SAVE);
}
itemMetadata.setSubmittedBy(StringUtils.EMPTY);
itemMetadata.setSendEmail(0);
itemMetadata.setSubmittedForDeletion(0);
itemMetadata.setSubmissionComment(StringUtils.EMPTY);
itemMetadata.setSubmittedToEnvironment(StringUtils.EMPTY);
itemMetadata.setLaunchDate(null);
objectMetadataManager.updateObjectMetadata(itemMetadata);
}
String blacklistConfig = studioConfiguration.getProperty(CONFIGURATION_PUBLISHING_BLACKLIST_REGEX);
if (StringUtils.isNotEmpty(blacklistConfig) && ContentUtils.matchesPatterns(item.getPath(), Arrays.asList(StringUtils.split(blacklistConfig, ",")))) {
LOGGER.debug("File " + item.getPath() + " of the site " + site + " will not be published because it " + "matches the configured publishing blacklist regex patterns.");
markItemsCompleted(site, item.getEnvironment(), Arrays.asList(item));
deploymentItem = null;
}
}
return deploymentItem;
}
Aggregations