use of com.thinkbiganalytics.metadata.modeshape.catalog.datasource.JcrDataSource in project kylo by Teradata.
the class MigrateLegacyDatasourcesUpgradeAction method upgradeTo.
@Override
public void upgradeTo(final KyloVersion targetVersion) {
log.info("Setting up catalog access control: {}", targetVersion);
try {
NodeTypeManager typeMgr = JcrMetadataAccess.getActiveSession().getWorkspace().getNodeTypeManager();
NodeType dataSourceType = typeMgr.getNodeType("tba:DataSource");
Connector conn = pluginManager.getPlugin("jdbc").flatMap(plugin -> connectorProvider.findByPlugin(plugin.getId())).orElseThrow(() -> new IllegalStateException("No JDBC connector found"));
legacyProvider.getDatasources().stream().map(JcrDatasource.class::cast).map(JcrDatasource::getNode).filter(node -> JcrUtil.isNodeType(node, "tba:userDatasource")).filter(node -> JcrUtil.isNodeType(JcrUtil.getNode(node, "tba:details"), "tba:jdbcDatasourceDetails")).forEach(jdbcNode -> {
try {
// Move the legacy datasource node to a temporary parent that doesn't have any constraints (the catalog folder).
Node tmpParent = JcrUtil.getNode(JcrUtil.getRootNode(jdbcNode), "metadata/catalog");
String dsSystemName = dataSourceProvider.generateSystemName(JcrUtil.getName(jdbcNode));
Path catDsPath = MetadataPaths.dataSourcePath(conn.getSystemName(), dsSystemName);
Node catDsNode = JcrUtil.moveNode(jdbcNode, JcrUtil.path(tmpParent.getPath()).resolve(dsSystemName));
// Wrap the node as a legacy UserDataSource and collect its properties.
JcrUserDatasource legacyDs = JcrUtil.getJcrObject(catDsNode, JcrUserDatasource.class);
Set<? extends JcrFeed> referencingFeeds = legacyDs.getFeedSources().stream().map(FeedSource::getFeed).map(JcrFeed.class::cast).collect(Collectors.toSet());
AtomicReference<String> controllerServiceId = new AtomicReference<>();
AtomicReference<String> password = new AtomicReference<>();
legacyDs.getDetails().filter(JcrJdbcDatasourceDetails.class::isInstance).map(JcrJdbcDatasourceDetails.class::cast).ifPresent(details -> {
controllerServiceId.set(details.getControllerServiceId().orElse(null));
password.set("{cipher}" + details.getPassword());
});
if (this.accessController.isEntityAccessControlled()) {
legacyDs.disableAccessControl(legacyDs.getOwner());
}
// Convert the legacy type into the catalog type.
JcrDataSource catDs = convertToDataSource(catDsNode, catDsPath, dataSourceType, controllerServiceId.get(), password.get());
linkDataSets(catDs, referencingFeeds);
if (this.accessController.isEntityAccessControlled()) {
List<SecurityRole> roles = roleProvider.getEntityRoles(SecurityRole.DATASOURCE);
actionsProvider.getAvailableActions(AllowedActions.DATASOURCE).ifPresent(actions -> catDs.enableAccessControl((JcrAllowedActions) actions, legacyDs.getOwner(), roles));
}
} catch (RepositoryException e) {
throw new UpgradeException("Failed to migrate legacy datasources", e);
}
});
} catch (IllegalStateException | RepositoryException e) {
throw new UpgradeException("Failed to migrate legacy datasources", e);
}
}
Aggregations