Search in sources :

Example 1 with KyloVersion

use of com.thinkbiganalytics.KyloVersion 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 KyloVersion

use of com.thinkbiganalytics.KyloVersion in project kylo by Teradata.

the class HiveColumnsUpgradeAction method upgradeTo.

@Override
public void upgradeTo(final KyloVersion startingVersion) {
    log.info("Upgrading hive columns from version: {}", startingVersion);
    feedService.getFeeds().stream().filter(feed -> Optional.ofNullable(feed.getTable()).map(TableSetup::getTableSchema).map(TableSchema::getFields).isPresent()).forEach(feed -> {
        final TableSchema schema = feed.getTable().getTableSchema();
        final DerivedDatasource datasource = datasourceProvider.findDerivedDatasource("HiveDatasource", feed.getSystemCategoryName() + "." + feed.getSystemFeedName());
        if (datasource != null) {
            log.info("Upgrading schema: {}/{}", schema.getDatabaseName(), schema.getSchemaName());
            datasource.setGenericProperties(Collections.singletonMap("columns", (Serializable) schema.getFields()));
        }
    });
}
Also used : DerivedDatasource(com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource) Logger(org.slf4j.Logger) FeedManagerFeedService(com.thinkbiganalytics.feedmgr.service.feed.FeedManagerFeedService) LoggerFactory(org.slf4j.LoggerFactory) Profile(org.springframework.context.annotation.Profile) Serializable(java.io.Serializable) Inject(javax.inject.Inject) Component(org.springframework.stereotype.Component) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) Optional(java.util.Optional) TableSetup(com.thinkbiganalytics.feedmgr.rest.model.schema.TableSetup) KyloVersion(com.thinkbiganalytics.KyloVersion) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) Collections(java.util.Collections) KyloUpgrader(com.thinkbiganalytics.server.upgrade.KyloUpgrader) UpgradeState(com.thinkbiganalytics.server.upgrade.UpgradeState) Serializable(java.io.Serializable) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) TableSetup(com.thinkbiganalytics.feedmgr.rest.model.schema.TableSetup) DerivedDatasource(com.thinkbiganalytics.metadata.api.datasource.DerivedDatasource)

Example 3 with KyloVersion

use of com.thinkbiganalytics.KyloVersion in project kylo by Teradata.

the class KyloUpgradeService method upgradeNext.

/**
 * Upgrades to the next Kylo version relative to the current version.
 * @return true if after this call upgrades are complete and Kylo is up-to-date.
 */
public boolean upgradeNext() {
    boolean isComplete = false;
    if (this.upgradeActions.isPresent()) {
        // Determine the next version from the current version.  If this is
        // a fresh install then the build version will be returned.  If
        // there are no versions later than the current one (we are up-to-date)
        // then nextVerion will be null.
        KyloVersion nextVersion = metadataAccess.read(() -> {
            return getNextVersion();
        }, MetadataAccess.SERVICE);
        if (nextVersion != null) {
            // Invoke any upgrade actions targeted for this next version in its own transaction.
            this.upgradeActions.get().stream().filter(action -> action.isTargetVersion(nextVersion)).forEach(action -> {
                metadataAccess.commit(() -> {
                    action.upgradeTo(nextVersion);
                }, MetadataAccess.SERVICE);
            });
            // Update this version it to be the current version.
            metadataAccess.commit(() -> {
                versionProvider.setCurrentVersion(nextVersion);
            }, MetadataAccess.SERVICE);
            log.info("=================================");
            log.info("Finished upgrade through v{}", nextVersion);
            isComplete = nextVersion.equals(this.buildVersion);
            // fresh install actions.
            if (isComplete && this.freshInstall) {
                metadataAccess.commit(() -> {
                    this.upgradeActions.get().stream().filter(a -> a.isTargetFreshInstall()).forEach(a -> a.upgradeTo(this.buildVersion));
                    log.info("=================================");
                    log.info("Finished fresh install updates");
                }, MetadataAccess.SERVICE);
            }
            return isComplete;
        } else {
            log.info("Nothing left to upgrade - Kylo is up-to-date");
            return true;
        }
    } else {
        isComplete = metadataAccess.commit(() -> {
            versionProvider.setCurrentVersion(this.buildVersion);
            return true;
        }, MetadataAccess.SERVICE);
        log.info("=================================");
        log.info("Finished upgrade through v{}", this.buildVersion);
    }
    return isComplete;
}
Also used : IntStream(java.util.stream.IntStream) LoggerFactory(org.slf4j.LoggerFactory) ClassPathResource(org.springframework.core.io.ClassPathResource) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Charset(java.nio.charset.Charset) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) Resource(org.springframework.core.io.Resource) PrintWriter(java.io.PrintWriter) Logger(org.slf4j.Logger) KyloVersionProvider(com.thinkbiganalytics.metadata.api.app.KyloVersionProvider) Resources(com.google.common.io.Resources) FileSystemResource(org.springframework.core.io.FileSystemResource) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) KyloVersionUtil(com.thinkbiganalytics.KyloVersionUtil) List(java.util.List) Stream(java.util.stream.Stream) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) KyloVersion(com.thinkbiganalytics.KyloVersion) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KyloVersion(com.thinkbiganalytics.KyloVersion)

Example 4 with KyloVersion

use of com.thinkbiganalytics.KyloVersion in project kylo by Teradata.

the class KyloUpgradeService method init.

public void init() {
    if (!this.initialized) {
        ClassPathResource versionsResource = new ClassPathResource(UPGRADE_VERSIONS_FILE, KyloUpgradeService.class.getClassLoader());
        KyloVersion current = versionProvider.getCurrentVersion();
        this.freshInstall = current == null;
        this.buildVersion = KyloVersionUtil.getBuildVersion();
        this.upgradeSequence = readUpgradeVersions(versionsResource);
        this.initialized = true;
    }
}
Also used : KyloVersion(com.thinkbiganalytics.KyloVersion) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 5 with KyloVersion

use of com.thinkbiganalytics.KyloVersion in project kylo by Teradata.

the class KyloUpgrader method isUpgradeRequired.

public boolean isUpgradeRequired() {
    KyloVersion buildVer = KyloVersionUtil.getBuildVersion();
    KyloVersion currentVer = getCurrentVersion();
    return currentVer == null || !buildVer.matches(currentVer.getMajorVersion(), currentVer.getMinorVersion(), currentVer.getPointVersion());
}
Also used : KyloVersion(com.thinkbiganalytics.KyloVersion)

Aggregations

KyloVersion (com.thinkbiganalytics.KyloVersion)12 KyloUpgrader (com.thinkbiganalytics.server.upgrade.KyloUpgrader)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 KyloVersionUtil (com.thinkbiganalytics.KyloVersionUtil)2 UpgradeState (com.thinkbiganalytics.server.upgrade.UpgradeState)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Profile (org.springframework.context.annotation.Profile)2 Component (org.springframework.stereotype.Component)2 Resources (com.google.common.io.Resources)1 PoolingDataSourceService (com.thinkbiganalytics.db.PoolingDataSourceService)1 TableSchema (com.thinkbiganalytics.discovery.schema.TableSchema)1