use of org.talend.repository.model.hadoopcluster.HadoopSubConnection in project tbd-studio-se by Talend.
the class HadoopClusterService method copyHadoopCluster.
@Override
public void copyHadoopCluster(final Item sourceItem, final IPath path, String newName) throws PersistenceException, BusinessException {
if (isHadoopClusterItem(sourceItem)) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
HadoopClusterConnectionItem sourceClusterItem = (HadoopClusterConnectionItem) sourceItem;
HadoopClusterConnectionItem targetClusterItem = null;
if (StringUtils.isNotBlank(newName)) {
targetClusterItem = (HadoopClusterConnectionItem) factory.copy(sourceClusterItem, path, newName);
} else {
targetClusterItem = (HadoopClusterConnectionItem) factory.copy(sourceClusterItem, path, true);
}
HadoopClusterConnection targetClusterConnection = (HadoopClusterConnection) targetClusterItem.getConnection();
targetClusterConnection.getConnectionList().clear();
String targetClusterId = targetClusterItem.getProperty().getId();
Set<Item> sourceSubitems = HCRepositoryUtil.getSubitemsOfHadoopCluster(sourceClusterItem);
for (Item subitem : sourceSubitems) {
Item newSubitem = factory.copy(subitem, path, true);
if (newSubitem instanceof HadoopSubConnectionItem) {
((HadoopSubConnection) ((HadoopSubConnectionItem) newSubitem).getConnection()).setRelativeHadoopClusterId(targetClusterId);
targetClusterConnection.getConnectionList().add(newSubitem.getProperty().getId());
} else if (subitem instanceof DatabaseConnectionItem) {
((DatabaseConnection) ((DatabaseConnectionItem) newSubitem).getConnection()).getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HADOOP_CLUSTER_ID, targetClusterId);
}
factory.save(newSubitem);
}
factory.save(targetClusterItem);
}
}
Aggregations