Search in sources :

Example 1 with UpgradeException

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);
    }
}
Also used : Arrays(java.util.Arrays) VersionHistory(javax.jcr.version.VersionHistory) NodeTypeManager(org.modeshape.jcr.api.nodetype.NodeTypeManager) Version(javax.jcr.version.Version) VersionIterator(javax.jcr.version.VersionIterator) LoggerFactory(org.slf4j.LoggerFactory) RepositoryException(javax.jcr.RepositoryException) JcrVersionUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrVersionUtil) Node(javax.jcr.Node) UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) VersionManager(javax.jcr.version.VersionManager) UpgradeState(com.thinkbiganalytics.server.upgrade.UpgradeState) Logger(org.slf4j.Logger) Session(javax.jcr.Session) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) PropertyType(javax.jcr.PropertyType) Collectors(java.util.stream.Collectors) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Profile(org.springframework.context.annotation.Profile) List(java.util.List) Component(org.springframework.stereotype.Component) Value(javax.jcr.Value) NodeType(javax.jcr.nodetype.NodeType) JcrUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrUtil) KyloVersion(com.thinkbiganalytics.KyloVersion) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) KyloUpgrader(com.thinkbiganalytics.server.upgrade.KyloUpgrader) NodeTypeManager(org.modeshape.jcr.api.nodetype.NodeTypeManager) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) VersionManager(javax.jcr.version.VersionManager) VersionHistory(javax.jcr.version.VersionHistory) UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) Version(javax.jcr.version.Version) KyloVersion(com.thinkbiganalytics.KyloVersion) NodeType(javax.jcr.nodetype.NodeType) VersionIterator(javax.jcr.version.VersionIterator) Session(javax.jcr.Session)

Example 2 with UpgradeException

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);
    }
}
Also used : UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Example 3 with UpgradeException

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);
    }
}
Also used : UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) RepositoryException(javax.jcr.RepositoryException) Workspace(org.modeshape.jcr.api.Workspace)

Example 4 with UpgradeException

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 ****************");
}
Also used : UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) Node(javax.jcr.Node) UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) JcrCategory(com.thinkbiganalytics.metadata.modeshape.category.JcrCategory)

Example 5 with UpgradeException

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 ****************");
}
Also used : UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) JcrFeed(com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed) Node(javax.jcr.Node) UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) JcrCategory(com.thinkbiganalytics.metadata.modeshape.category.JcrCategory)

Aggregations

UpgradeException (com.thinkbiganalytics.server.upgrade.UpgradeException)15 RepositoryException (javax.jcr.RepositoryException)11 Node (javax.jcr.Node)7 JcrFeed (com.thinkbiganalytics.metadata.modeshape.feed.JcrFeed)5 Workspace (org.modeshape.jcr.api.Workspace)4 KyloVersion (com.thinkbiganalytics.KyloVersion)3 JcrMetadataAccess (com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess)3 JcrUtil (com.thinkbiganalytics.metadata.modeshape.support.JcrUtil)3 KyloUpgrader (com.thinkbiganalytics.server.upgrade.KyloUpgrader)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Session (javax.jcr.Session)3 NodeType (javax.jcr.nodetype.NodeType)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Profile (org.springframework.context.annotation.Profile)3 Component (org.springframework.stereotype.Component)3 JcrCategory (com.thinkbiganalytics.metadata.modeshape.category.JcrCategory)2 JcrVersionUtil (com.thinkbiganalytics.metadata.modeshape.support.JcrVersionUtil)2