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);
}
}
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()));
}
});
}
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;
}
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;
}
}
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());
}
Aggregations