use of org.craftercms.studio.api.v2.exception.MissingPluginParameterException in project studio by craftercms.
the class SiteServiceImpl method createSiteFromBlueprint.
@Override
@ValidateParams
public void createSiteFromBlueprint(@ValidateStringParam(name = "blueprintId") String blueprintId, @ValidateNoTagsParam(name = "siteName") String siteName, @ValidateStringParam(name = "siteId", maxLength = 50, whitelistedPatterns = "[a-z0-9\\-]*") String siteId, @ValidateStringParam(name = "sandboxBranch") String sandboxBranch, @ValidateNoTagsParam(name = "desc") String desc, Map<String, String> params, boolean createAsOrphan) throws SiteAlreadyExistsException, SiteCreationException, DeployerTargetException, BlueprintNotFoundException, MissingPluginParameterException {
if (exists(siteId)) {
throw new SiteAlreadyExistsException();
}
logger.debug("Get blueprint descriptor for: " + blueprintId);
PluginDescriptor descriptor = sitesServiceInternal.getBlueprintDescriptor(blueprintId);
if (Objects.isNull(descriptor)) {
throw new BlueprintNotFoundException();
}
logger.debug("Validating blueprint parameters");
sitesServiceInternal.validateBlueprintParameters(descriptor, params);
String blueprintLocation = sitesServiceInternal.getBlueprintLocation(blueprintId);
String searchEngine = descriptor.getPlugin().getSearchEngine();
logger.debug("Validate site entitlements");
try {
entitlementValidator.validateEntitlement(EntitlementType.SITE, 1);
} catch (EntitlementException e) {
throw new SiteCreationException("Unable to complete request due to entitlement limits. Please contact " + "your system administrator.", e);
}
logger.info("Starting site creation process for site " + siteName + " from " + blueprintId + " blueprint.");
boolean success = true;
// We must fail site creation if any of the site creations steps fail and rollback
// For example: Create site => create Deployer Target (fail) = fail
// and rollback the whole thing.
// What we need to do for site creation and the order of execution:
// 1) deployer target, 2) git repo, 3) database, 4) kick deployer
String siteUuid = UUID.randomUUID().toString();
// Create the site in the preview deployer
logger.info("Creating deployer targets.");
try {
deployer.createTargets(siteId, searchEngine);
} catch (Exception e) {
success = false;
String msg = "Error while creating site: " + siteName + " ID: " + siteId + " from blueprint: " + blueprintId + ". The required Deployer targets couldn't be created";
logger.error(msg, e);
throw new DeployerTargetException(msg, e);
}
if (success) {
try {
logger.info("Copying site content from blueprint.");
success = createSiteFromBlueprintGit(blueprintLocation, siteName, siteId, sandboxBranch, desc, params);
ZonedDateTime now = ZonedDateTime.now();
logger.debug("Adding site UUID.");
addSiteUuidFile(siteId, siteUuid);
logger.info("Adding site record to database for site " + siteId);
// insert database records
SiteFeed siteFeed = new SiteFeed();
siteFeed.setName(siteName);
siteFeed.setSiteId(siteId);
siteFeed.setSiteUuid(siteUuid);
siteFeed.setDescription(desc);
siteFeed.setPublishingStatus(READY);
siteFeed.setPublishingStatusMessage(studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_DEFAULT));
siteFeed.setSandboxBranch(sandboxBranch);
siteFeed.setSearchEngine(searchEngine);
siteFeedMapper.createSite(siteFeed);
String localeAddress = studioClusterUtils.getClusterNodeLocalAddress();
ClusterMember cm = clusterDao.getMemberByLocalAddress(localeAddress);
if (Objects.nonNull(cm)) {
SiteFeed s = getSite(siteId);
clusterDao.insertClusterSiteSyncRepo(cm.getId(), s.getId(), null, null, null);
}
logger.info("Upgrading site.");
upgradeManager.upgradeSite(siteId);
// Add default groups
logger.info("Adding default groups");
addDefaultGroupsForNewSite(siteId);
String lastCommitId = contentRepositoryV2.getRepoLastCommitId(siteId);
String creator = securityService.getCurrentUser();
long startGetChangeSetCreatedFilesMark = logger.isDebugEnabled() ? System.currentTimeMillis() : 0;
Map<String, String> createdFiles = contentRepositoryV2.getChangeSetPathsFromDelta(siteId, null, lastCommitId);
if (logger.isDebugEnabled()) {
logger.debug("Get change set created files finished in " + (System.currentTimeMillis() - startGetChangeSetCreatedFilesMark) + " milliseconds");
}
logger.info("Adding audit log");
insertCreateSiteAuditLog(siteId, siteName, createdFiles);
processCreatedFiles(siteId, createdFiles, creator, now, lastCommitId);
contentRepositoryV2.insertGitLog(siteId, lastCommitId, 1, 1);
updateLastCommitId(siteId, lastCommitId);
updateLastVerifiedGitlogCommitId(siteId, lastCommitId);
updateLastSyncedGitlogCommitId(siteId, lastCommitId);
logger.info("Reload site configuration");
reloadSiteConfiguration(siteId);
} catch (Exception e) {
success = false;
logger.error("Error while creating site: " + siteName + " ID: " + siteId + " from blueprint: " + blueprintId + ". Rolling back.", e);
deleteSite(siteId);
throw new SiteCreationException("Error while creating site: " + siteName + " ID: " + siteId + " from blueprint: " + blueprintId + ". Rolling back.");
}
}
if (success) {
logger.info("Syncing all content to preview.");
// Now that everything is created, we can sync the preview deployer with the new content
try {
deploymentService.syncAllContentToPreview(siteId, true);
} catch (ServiceLayerException e) {
logger.error("Error while syncing site: " + siteName + " ID: " + siteId + " to preview. Site was " + "successfully created otherwise. Ignoring.", e);
throw new SiteCreationException("Error while syncing site: " + siteName + " ID: " + siteId + " to preview. Site was successfully created, but it won't be preview-able until the Preview " + "Deployer is reachable.");
}
setSiteState(siteId, STATE_CREATED);
} else {
throw new SiteCreationException("Error while creating site: " + siteName + " ID: " + siteId + ".");
}
logger.info("Finished creating site " + siteId);
}
use of org.craftercms.studio.api.v2.exception.MissingPluginParameterException in project studio by craftercms.
the class SitesServiceInternalImpl method validateBlueprintParameters.
@Override
public void validateBlueprintParameters(final PluginDescriptor descriptor, final Map<String, String> params) throws MissingPluginParameterException {
Plugin plugin = descriptor.getPlugin();
if (CollectionUtils.isEmpty(plugin.getParameters())) {
logger.debug("There are no parameters defined for blueprint: {0}", plugin.getId());
return;
}
for (Parameter param : plugin.getParameters()) {
logger.debug("Checking parameter {0} for blueprint {1}", param.getName(), plugin.getId());
if (param.isRequired()) {
if (!params.containsKey(param.getName()) || StringUtils.isEmpty(params.get(param.getName()))) {
throw new MissingPluginParameterException(descriptor, param);
}
} else {
params.putIfAbsent(param.getName(), param.getDefaultValue());
}
}
logger.debug("All required parameters are present for blueprint: {0}", plugin.getId());
}
Aggregations