use of com.thinkbiganalytics.server.upgrade.UpgradeException in project kylo by Teradata.
the class FeedVersioningRemovalUpgradeAction method upgradeTo.
@Override
public void upgradeTo(KyloVersion startingVersion) {
log.info("Removing feed versioning: {}", startingVersion);
Session session = JcrMetadataAccess.getActiveSession();
try {
Node feedsNode = session.getRootNode().getNode("metadata/feeds");
NodeTypeManager typeMgr = (NodeTypeManager) session.getWorkspace().getNodeTypeManager();
NodeType currentFeedType = typeMgr.getNodeType("tba:feed");
List<String> currentSupertypes = Arrays.asList(currentFeedType.getDeclaredSupertypeNames());
if (currentSupertypes.contains("mix:versionable")) {
log.info("Removing versionable feed type {} ", currentFeedType);
// Remove feed version history
for (Node catNode : JcrUtil.getNodesOfType(feedsNode, "tba:category")) {
for (Node feedNode : JcrUtil.getNodesOfType(catNode, "tba:feed")) {
log.debug("Removing prior versions of feed: {}.{}", catNode.getName(), feedNode.getName());
if (JcrVersionUtil.isVersionable(feedNode)) {
VersionManager versionManager = session.getWorkspace().getVersionManager();
VersionHistory versionHistory = versionManager.getVersionHistory(feedNode.getPath());
VersionIterator vIt = versionHistory.getAllVersions();
int count = 0;
String last = "";
while (vIt.hasNext()) {
Version version = vIt.nextVersion();
String versionName = version.getName();
String baseVersion = "";
if (!"jcr:rootVersion".equals(versionName)) {
// baseVersion requires actual versionable node to get the base version name
baseVersion = JcrVersionUtil.getBaseVersion(feedNode).getName();
}
if (!"jcr:rootVersion".equals(versionName) && !versionName.equalsIgnoreCase(baseVersion)) {
last = version.getName();
// removeVersion writes directly to workspace, no session.save is necessary
versionHistory.removeVersion(version.getName());
count++;
}
}
if (count > 0) {
log.info("Removed {} versions through {} of feed {}", count, last, feedNode.getName());
} else {
log.debug("Feed {} had no versions", feedNode.getName());
}
}
}
}
// Redefine the NodeType of tba:feed to remove versionable but retain the versionable properties with weaker constraints
// Retaining the properties seems to override some residual properties on feed nodes that causes a failure later.
// In particular, jcr:predecessors was accessed later but redefining all mix:versionable properties to be safe.
NodeTypeTemplate template = typeMgr.createNodeTypeTemplate(currentFeedType);
List<String> newSupertypes = currentSupertypes.stream().filter(type -> !type.equals("mix:versionable")).collect(Collectors.toList());
template.setDeclaredSuperTypeNames(newSupertypes.toArray(new String[newSupertypes.size()]));
@SuppressWarnings("unchecked") List<PropertyDefinitionTemplate> propTemplates = template.getPropertyDefinitionTemplates();
PropertyDefinitionTemplate prop = typeMgr.createPropertyDefinitionTemplate();
prop.setName("jcr:versionHistory");
prop.setRequiredType(PropertyType.WEAKREFERENCE);
propTemplates.add(prop);
prop = typeMgr.createPropertyDefinitionTemplate();
prop.setName("jcr:baseVersion");
prop.setRequiredType(PropertyType.WEAKREFERENCE);
propTemplates.add(prop);
prop = typeMgr.createPropertyDefinitionTemplate();
prop.setName("jcr:predecessors");
prop.setRequiredType(PropertyType.WEAKREFERENCE);
prop.setMultiple(true);
propTemplates.add(prop);
prop = typeMgr.createPropertyDefinitionTemplate();
prop.setName("jcr:mergeFailed");
prop.setRequiredType(PropertyType.WEAKREFERENCE);
propTemplates.add(prop);
prop = typeMgr.createPropertyDefinitionTemplate();
prop.setName("jcr:activity");
prop.setRequiredType(PropertyType.WEAKREFERENCE);
propTemplates.add(prop);
prop = typeMgr.createPropertyDefinitionTemplate();
prop.setName("jcr:configuration");
prop.setRequiredType(PropertyType.WEAKREFERENCE);
propTemplates.add(prop);
log.info("Replacing the versionable feed type '{}' with a non-versionable type", currentFeedType);
NodeType newType = typeMgr.registerNodeType(template, true);
log.info("Replaced with new feed type '{}' with a non-versionable type", newType);
// This step may not be necessary.
for (Node catNode : JcrUtil.getNodesOfType(feedsNode, "tba:category")) {
for (Node feedNode : JcrUtil.getNodesOfType(catNode, "tba:feed")) {
feedNode.setPrimaryType(newType.getName());
if (feedNode.hasProperty("jcr:predecessors")) {
feedNode.getProperty("jcr:predecessors").setValue(new Value[0]);
;
feedNode.getProperty("jcr:predecessors").remove();
}
}
}
}
} catch (RepositoryException e) {
log.error("Failure while attempting to remove versioning from feeds", e);
throw new UpgradeException("Failure while attempting to remove versioning from feeds", e);
}
}
use of com.thinkbiganalytics.server.upgrade.UpgradeException in project kylo by Teradata.
the class UpgradeAction method moveProperty.
/**
* move a property from one node to another
*
* @param propName the name of the property to move
* @param fromNode the node to move from
* @param toNode the node to move to
* @param propertyType Optional. This is the new property type, or null if unchanged
*/
private void moveProperty(String propName, Node fromNode, Node toNode, Integer propertyType) {
try {
if ((fromNode != null) && (toNode != null)) {
if (fromNode.hasProperty(propName)) {
Property prop = fromNode.getProperty(propName);
if (propertyType == null) {
propertyType = prop.getType();
}
if (propertyType != prop.getType()) {
log.info("Property type for {} on Node {} is changing from {} to {} ", propName, fromNode.getName(), prop.getType(), propertyType);
}
if (prop.isMultiple()) {
toNode.setProperty(propName, prop.getValues(), propertyType);
} else {
toNode.setProperty(propName, prop.getValue(), propertyType);
}
prop.remove();
}
}
} catch (RepositoryException e) {
throw new UpgradeException("Failed to moved property " + propName + " from " + fromNode + " to " + toNode, e);
}
}
use of com.thinkbiganalytics.server.upgrade.UpgradeException in project kylo by Teradata.
the class ReindexUpgradeAction method upgradeTo.
@Override
public void upgradeTo(final KyloVersion startingVersion) {
log.info("Re-indexing metadata for version:: {}", startingVersion);
try {
Workspace workspace = (Workspace) JcrMetadataAccess.getActiveSession().getWorkspace();
workspace.reindex();
} catch (RepositoryException e) {
log.error("Failed to re-index metadata", e);
throw new UpgradeException("Failed to re-index metadata", e);
}
}
use of com.thinkbiganalytics.server.upgrade.UpgradeException in project kylo by Teradata.
the class CategoryAndFeedReindexingUpgradeAction method upgradeTo.
@Override
public void upgradeTo(KyloVersion startingVersion) {
log.info("****************** Start: Category and Feed Reindexing Support Upgrade Action ****************");
log.info("[REF.A] Upgrading feeds to support (1) allowing/stopping metadata indexing, AND (2) reindexing of history data for version: {}...", startingVersion);
log.info("Total feeds found for upgrading: {}", feedProvider.getFeeds().size());
if (feedProvider.getFeeds().isEmpty()) {
log.warn("No feeds have been found for upgrade!");
}
feedProvider.getFeeds().forEach(feed -> {
JcrFeed jcrFeed = (JcrFeed) feed;
if ((jcrFeed.getFeedSummary().isPresent()) && (jcrFeed.getFeedData().isPresent())) {
Node summaryNode = jcrFeed.getFeedSummary().get().getNode();
Node feedDataNode = jcrFeed.getFeedData().get().getNode();
try {
summaryNode.addMixin("tba:indexControlled");
summaryNode.setProperty("tba:allowIndexing", "Y");
if (!JcrUtil.hasNode(feedDataNode, "tba:historyReindexing")) {
log.info("Feed with id [{}] in category [{}] having name [{}] requires history reindexing support. Adding it.", jcrFeed.getId(), jcrFeed.getCategory().getDisplayName(), jcrFeed.getName());
feedDataNode.addNode("tba:historyReindexing", "tba:historyReindexing");
} else {
log.info("Feed with id [{}] in category [{}] having name [{}] already has history reindexing support. Skipping step to add again.", jcrFeed.getId(), jcrFeed.getCategory().getDisplayName(), jcrFeed.getName());
}
log.info("Upgraded feed with id [{}] in category [{}] having name [{}]", jcrFeed.getId(), jcrFeed.getCategory().getDisplayName(), jcrFeed.getName());
} catch (Exception e) {
log.error("Failed to configure feed {} to (1) support allowing/stopping metadata indexing, AND/OR (2) support reindexing of history data: {}", ((JcrFeed) feed).getName(), e);
throw new UpgradeException("Failed to configure feed to (1) support allowing/stopping metadata indexing, AND/OR (2) support reindexing of history data: " + summaryNode, e);
}
} else {
log.error("Failed to get summary and/or data node for feed: {}", ((JcrFeed) feed).getName());
throw new UpgradeException("Failed to get summary and/or data node for feed:" + ((JcrFeed) feed).getName());
}
});
log.info("Completed [REF.A]: Configured feeds to support (1) allowing/stopping metadata indexing, AND (2) reindexing of history data for version: {}", startingVersion);
log.info("[REF.B] Upgrading categories to support allowing/stopping metadata indexing for version: {}...", startingVersion);
log.info("Total categories found for upgrading: {}", categoryProvider.findAll().size());
if (categoryProvider.findAll().isEmpty()) {
log.warn("No categories have been found for for upgrade!");
}
categoryProvider.findAll().forEach(category -> {
JcrCategory jcrCategory = (JcrCategory) category;
Node categoryNode = jcrCategory.getNode();
try {
categoryNode.addMixin("tba:indexControlled");
categoryNode.setProperty("tba:allowIndexing", "Y");
log.info("Upgraded category with id [{}] having name [{}]", jcrCategory.getId(), jcrCategory.getDisplayName());
} catch (Exception e) {
log.error("Failed to configure category {} to support allowing/stopping metadata indexing: {}", ((JcrCategory) category).getDisplayName(), e);
throw new UpgradeException("Failed to configure category to support allowing/stopping metadata indexing: " + categoryNode, e);
}
});
log.info("Completed [REF.B]: Configured categories to support allowing/stopping metadata indexing for version: {}", startingVersion);
log.info("****************** End: Category and Feed Reindexing Support Upgrade Action ****************");
}
use of com.thinkbiganalytics.server.upgrade.UpgradeException in project kylo by Teradata.
the class CategoryAndFeedReindexingUpgradeAction method upgradeTo.
@Override
public void upgradeTo(KyloVersion startingVersion) {
log.info("****************** Start: Category and Feed Reindexing Support Upgrade Action ****************");
log.info("[REF.A] Upgrading feeds to support (1) allowing/stopping metadata indexing, AND (2) reindexing of history data for version: {}...", startingVersion);
log.info("Total feeds found for upgrading: {}", feedProvider.getFeeds().size());
if (feedProvider.getFeeds().isEmpty()) {
log.warn("No feeds have been found for upgrade!");
}
feedProvider.getFeeds().forEach(feed -> {
JcrFeed jcrFeed = (JcrFeed) feed;
if ((jcrFeed.getFeedSummary().isPresent()) && (jcrFeed.getFeedData().isPresent())) {
Node summaryNode = jcrFeed.getFeedSummary().get().getNode();
Node feedDataNode = jcrFeed.getFeedData().get().getNode();
try {
summaryNode.addMixin("tba:indexControlled");
summaryNode.setProperty("tba:allowIndexing", "Y");
if (!JcrUtil.hasNode(feedDataNode, "tba:historyReindexing")) {
log.info("Feed with id [{}] in category [{}] having name [{}] requires history reindexing support. Adding it.", jcrFeed.getId(), jcrFeed.getCategory().getDisplayName(), jcrFeed.getName());
feedDataNode.addNode("tba:historyReindexing", "tba:historyReindexing");
} else {
log.info("Feed with id [{}] in category [{}] having name [{}] already has history reindexing support. Skipping step to add again.", jcrFeed.getId(), jcrFeed.getCategory().getDisplayName(), jcrFeed.getName());
}
log.info("Upgraded feed with id [{}] in category [{}] having name [{}]", jcrFeed.getId(), jcrFeed.getCategory().getDisplayName(), jcrFeed.getName());
} catch (Exception e) {
log.error("Failed to configure feed {} to (1) support allowing/stopping metadata indexing, AND/OR (2) support reindexing of history data: {}", ((JcrFeed) feed).getName(), e);
throw new UpgradeException("Failed to configure feed to (1) support allowing/stopping metadata indexing, AND/OR (2) support reindexing of history data: " + summaryNode, e);
}
} else {
log.error("Failed to get summary and/or data node for feed: {}", ((JcrFeed) feed).getName());
throw new UpgradeException("Failed to get summary and/or data node for feed:" + ((JcrFeed) feed).getName());
}
});
log.info("Completed [REF.A]: Configured feeds to support (1) allowing/stopping metadata indexing, AND (2) reindexing of history data for version: {}", startingVersion);
log.info("[REF.B] Upgrading categories to support allowing/stopping metadata indexing for version: {}...", startingVersion);
log.info("Total categories found for upgrading: {}", categoryProvider.findAll().size());
if (categoryProvider.findAll().isEmpty()) {
log.warn("No categories have been found for for upgrade!");
}
categoryProvider.findAll().forEach(category -> {
JcrCategory jcrCategory = (JcrCategory) category;
Node categoryNode = jcrCategory.getNode();
try {
categoryNode.addMixin("tba:indexControlled");
categoryNode.setProperty("tba:allowIndexing", "Y");
log.info("Upgraded category with id [{}] having name [{}]", jcrCategory.getId(), jcrCategory.getDisplayName());
} catch (Exception e) {
log.error("Failed to configure category {} to support allowing/stopping metadata indexing: {}", ((JcrCategory) category).getDisplayName(), e);
throw new UpgradeException("Failed to configure category to support allowing/stopping metadata indexing: " + categoryNode, e);
}
});
log.info("Completed [REF.B]: Configured categories to support allowing/stopping metadata indexing for version: {}", startingVersion);
log.info("****************** End: Category and Feed Reindexing Support Upgrade Action ****************");
}
Aggregations