use of org.craftercms.commons.plugin.model.PluginDescriptor in project commons by craftercms.
the class PluginDescriptorReaderImplTest method testParameters.
@Test
public void testParameters() throws IOException, PluginException {
Parameter param = new Parameter();
param.setLabel("Optional Key");
param.setName("optionalKey");
param.setRequired(false);
param.setType(Parameter.Type.PASSWORD);
try (InputStream is = descriptorParams.getInputStream()) {
PluginDescriptor descriptor = reader.read(is);
assertNull(descriptor.getBlueprint());
assertNotNull(descriptor.getPlugin());
Plugin plugin = descriptor.getPlugin();
assertNotNull(plugin.getParameters());
assertEquals(3, plugin.getParameters().size());
assertEquals("AWS Access Key", plugin.getParameters().get(0).getLabel());
assertEquals("awsAccessKey", plugin.getParameters().get(0).getName());
assertEquals(param, plugin.getParameters().get(2));
}
}
use of org.craftercms.commons.plugin.model.PluginDescriptor in project commons by craftercms.
the class PluginDescriptorReaderImplTest method testV1.
@Test
public void testV1() throws IOException, PluginException {
try (InputStream is = descriptorV1.getInputStream()) {
PluginDescriptor descriptor = reader.read(is);
assertEquals("1", descriptor.getDescriptorVersion());
assertNotNull(descriptor.getBlueprint());
assertNull(descriptor.getPlugin());
BlueprintDescriptor.Blueprint blueprint = descriptor.getBlueprint();
assertEquals("Website Editorial Blueprint", blueprint.getName());
}
}
use of org.craftercms.commons.plugin.model.PluginDescriptor in project studio by craftercms.
the class SitesServiceInternalImpl method getBlueprintLocation.
@Override
public String getBlueprintLocation(String blueprintId) {
RepositoryItem[] blueprintsFolders = getBlueprintsFolders();
for (RepositoryItem folder : blueprintsFolders) {
if (folder.isFolder) {
Path descriptorPath = getBlueprintPath(folder);
PluginDescriptor descriptor = loadDescriptor(folder);
if (descriptor != null && descriptor.getPlugin().getId().equals(blueprintId)) {
return descriptorPath.getParent().toAbsolutePath().toString();
}
}
}
return StringUtils.EMPTY;
}
use of org.craftercms.commons.plugin.model.PluginDescriptor in project studio by craftercms.
the class AbstractPluginDescriptorUpgradeOperation method execute.
@Override
public void execute(final String site) throws UpgradeException {
Path descriptorFile = getRepositoryPath(site).getParent().resolve(descriptorPath);
if (Files.notExists(descriptorFile)) {
logger.info("Plugin descriptor file not found for site {0}", site);
return;
}
try (Reader reader = Files.newBufferedReader(descriptorFile)) {
PluginDescriptor descriptor = descriptorReader.read(reader);
if (descriptor.getDescriptorVersion().equals(descriptorVersion)) {
logger.info("Plugin descriptor already update for site " + site);
return;
}
logger.info("Updating plugin descriptor for site " + site);
doPluginDescriptorUpdates(descriptor);
descriptor.setDescriptorVersion(descriptorVersion);
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(true);
Yaml yaml = new Yaml(new DisableClassLoadingConstructor(), new Representer() {
@Override
protected NodeTuple representJavaBeanProperty(final Object javaBean, final Property property, final Object propertyValue, final Tag customTag) {
if (propertyValue != null) {
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
return null;
}
}, options);
String content = yaml.dumpAsMap(descriptor);
writeToRepo(site, descriptorPath, new ByteArrayInputStream(content.getBytes()));
commitAllChanges(site);
} catch (Exception e) {
throw new UpgradeException("Plugin descriptor can't be read for site " + site);
}
}
use of org.craftercms.commons.plugin.model.PluginDescriptor in project studio by craftercms.
the class SiteServiceImpl method createSiteCloneRemote.
@SuppressWarnings("deprecation")
private void createSiteCloneRemote(String siteId, String sandboxBranch, String description, String remoteName, String remoteUrl, String remoteBranch, boolean singleBranch, String authenticationType, String remoteUsername, String remotePassword, String remoteToken, String remotePrivateKey, Map<String, String> params, boolean createAsOrphan) throws ServiceLayerException, InvalidRemoteRepositoryException, InvalidRemoteRepositoryCredentialsException, RemoteRepositoryNotFoundException, InvalidRemoteUrlException {
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) git repo, 2) deployer target, 3) database, 4) kick deployer
String siteUuid = UUID.randomUUID().toString();
try {
// create site by cloning remote git repo
logger.info("Creating site " + siteId + " by cloning remote repository " + remoteName + " (" + remoteUrl + ")");
success = contentRepositoryV2.createSiteCloneRemote(siteId, sandboxBranch, remoteName, remoteUrl, remoteBranch, singleBranch, authenticationType, remoteUsername, remotePassword, remoteToken, remotePrivateKey, params, createAsOrphan);
} catch (InvalidRemoteRepositoryException | InvalidRemoteRepositoryCredentialsException | RemoteRepositoryNotFoundException | InvalidRemoteUrlException | ServiceLayerException e) {
contentRepository.deleteSite(siteId);
logger.error("Error while creating site: " + siteId + " ID: " + siteId + " as clone from " + "remote repository: " + remoteName + " (" + remoteUrl + "). Rolling back.", e);
throw e;
}
if (!success) {
contentRepository.removeRemoteRepositoriesForSite(siteId);
contentRepository.deleteSite(siteId);
throw new ServiceLayerException("Failed to create site: " + siteId + " ID: " + siteId + " as clone from " + "remote repository: " + remoteName + " (" + remoteUrl + ")");
}
// try to get the search engine from the blueprint descriptor file
String searchEngine = studioConfiguration.getProperty(StudioConfiguration.PREVIEW_SEARCH_ENGINE);
PluginDescriptor descriptor = sitesServiceInternal.getSiteBlueprintDescriptor(siteId);
if (Objects.nonNull(descriptor) && Objects.nonNull(descriptor.getPlugin())) {
searchEngine = descriptor.getPlugin().getSearchEngine();
logger.info("Using search engine {0} from plugin descriptor", searchEngine);
} else if (Objects.nonNull(descriptor) && Objects.nonNull(descriptor.getBlueprint())) {
searchEngine = descriptor.getBlueprint().getSearchEngine();
logger.info("Using search engine {0} from blueprint descriptor", searchEngine);
} else {
logger.info("Missing descriptor, using default search engine {0}", searchEngine);
}
if (success) {
// Create the site in the preview deployer
try {
logger.info("Creating Deployer targets for site " + siteId);
deployer.createTargets(siteId, searchEngine);
} catch (Exception e) {
logger.error("Error while creating site: " + siteId + " ID: " + siteId + " as clone from" + " remote repository: " + remoteName + " (" + remoteUrl + "). Rolling back...", e);
contentRepositoryV2.removeRemote(siteId, remoteName);
boolean deleted = contentRepository.deleteSite(siteId);
if (!deleted) {
logger.error("Error while rolling back site: " + siteId);
}
throw new DeployerTargetException("Error while creating site: " + siteId + " ID: " + siteId + " as clone from remote repository: " + remoteName + " (" + remoteUrl + "). The required Deployer targets couldn't " + "be created", e);
}
}
if (success) {
ZonedDateTime now = ZonedDateTime.now();
String creator = securityService.getCurrentUser();
try {
logger.debug("Adding site UUID.");
addSiteUuidFile(siteId, siteUuid);
// insert database records
logger.info("Adding site record to database for site " + siteId);
SiteFeed siteFeed = new SiteFeed();
siteFeed.setName(siteId);
siteFeed.setSiteId(siteId);
siteFeed.setSiteUuid(siteUuid);
siteFeed.setDescription(description);
siteFeed.setPublishingStatus(READY);
siteFeed.setPublishingStatusMessage(studioConfiguration.getProperty(JOB_DEPLOY_CONTENT_TO_ENVIRONMENT_STATUS_MESSAGE_DEFAULT));
siteFeed.setSandboxBranch(sandboxBranch);
siteFeed.setSearchEngine(searchEngine);
siteFeedMapper.createSite(siteFeed);
upgradeManager.upgradeSite(siteId);
// Add default groups
logger.info("Adding default groups for site " + siteId);
addDefaultGroupsForNewSite(siteId);
String lastCommitId = contentRepositoryV2.getRepoLastCommitId(siteId);
String firstCommitId = contentRepositoryV2.getRepoFirstCommitId(siteId);
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");
}
insertCreateSiteAuditLog(siteId, siteId, createdFiles);
contentRepositoryV2.insertGitLog(siteId, firstCommitId, 1, 1);
processCreatedFiles(siteId, createdFiles, creator, now, lastCommitId);
updateLastCommitId(siteId, lastCommitId);
updateLastVerifiedGitlogCommitId(siteId, lastCommitId);
updateLastSyncedGitlogCommitId(siteId, firstCommitId);
logger.info("Loading configuration for site " + siteId);
reloadSiteConfiguration(siteId);
} catch (Exception e) {
success = false;
logger.error("Error while creating site: " + siteId + " ID: " + siteId + " as clone from " + "remote repository: " + remoteName + " (" + remoteUrl + "). Rolling back.", e);
deleteSite(siteId);
throw new SiteCreationException("Error while creating site: " + siteId + " ID: " + siteId + " as clone from remote repository: " + remoteName + " (" + remoteUrl + "). Rolling back.");
}
}
if (success) {
// Now that everything is created, we can sync the preview deployer with the new content
logger.info("Sync all site content to preview for " + siteId);
try {
deploymentService.syncAllContentToPreview(siteId, true);
} catch (ServiceLayerException e) {
logger.error("Error while syncing site: " + siteId + " ID: " + siteId + " to preview. Site was " + "successfully created otherwise. Ignoring.", e);
throw new SiteCreationException("Error while syncing site: " + siteId + " 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: " + siteId + " ID: " + siteId + ".");
}
logger.info("Finished creating site " + siteId);
}
Aggregations