Search in sources :

Example 6 with HadoopSubConnection

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);
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) HadoopClusterConnectionItem(org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) HadoopSubConnectionItem(org.talend.repository.model.hadoopcluster.HadoopSubConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) HadoopSubConnection(org.talend.repository.model.hadoopcluster.HadoopSubConnection) HadoopClusterConnectionItem(org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem) HadoopSubConnectionItem(org.talend.repository.model.hadoopcluster.HadoopSubConnectionItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Aggregations

HadoopSubConnection (org.talend.repository.model.hadoopcluster.HadoopSubConnection)6 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)4 HadoopSubConnectionItem (org.talend.repository.model.hadoopcluster.HadoopSubConnectionItem)4 Connection (org.talend.core.model.metadata.builder.connection.Connection)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 HadoopClusterConnectionItem (org.talend.repository.model.hadoopcluster.HadoopClusterConnectionItem)2 ArrayList (java.util.ArrayList)1 Path (org.eclipse.core.runtime.Path)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 ConnectionItem (org.talend.core.model.properties.ConnectionItem)1 ContextItem (org.talend.core.model.properties.ContextItem)1 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)1 Item (org.talend.core.model.properties.Item)1 Property (org.talend.core.model.properties.Property)1 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1 RepositoryNode (org.talend.repository.model.RepositoryNode)1