Search in sources :

Example 6 with HDFSConnection

use of org.talend.repository.model.hdfs.HDFSConnection in project tbd-studio-se by Talend.

the class ExtractHDFSSchemaManager method extractColumns.

public List<MetadataColumn> extractColumns(HDFSConnection connection, ClassLoader classLoader, MetadataTable metadataTable) throws Exception {
    List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
    if (connection == null || metadataTable == null) {
        return columns;
    }
    EMap<String, String> additionalProperties = metadataTable.getAdditionalProperties();
    String hdfsPath = additionalProperties.get(HDFSConstants.HDFS_PATH);
    if (StringUtils.isEmpty(hdfsPath)) {
        return columns;
    }
    HDFSConnectionBean connectionBean = HDFSModelUtil.convert2HDFSConnectionBean(connection);
    Object filePath = getHDFSFilePath(connectionBean, classLoader, hdfsPath);
    IExtractSchemaService<HDFSConnection> service = ExtractHDFSMetaServiceFactory.getService(connectionBean, classLoader, filePath);
    return service.extractColumns(connection, metadataTable);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) HDFSConnectionBean(org.talend.designer.hdfsbrowse.model.HDFSConnectionBean) ArrayList(java.util.ArrayList) HDFSConnection(org.talend.repository.model.hdfs.HDFSConnection)

Example 7 with HDFSConnection

use of org.talend.repository.model.hdfs.HDFSConnection in project tbd-studio-se by Talend.

the class HdfsContextHandler method createContextParameters.

@Override
public List<IContextParameter> createContextParameters(String prefixName, Connection connection, Set<IConnParamName> paramSet) {
    List<IContextParameter> varList = new ArrayList<IContextParameter>();
    if (connection instanceof HDFSConnection) {
        HDFSConnection conn = (HDFSConnection) connection;
        String paramPrefix = prefixName + ConnectionContextHelper.LINE;
        String paramName = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof EHadoopParamName) {
                EHadoopParamName hdfsParam = (EHadoopParamName) param;
                paramName = paramPrefix + hdfsParam;
                switch(hdfsParam) {
                    case HdfsUser:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getUserName());
                        break;
                    case HdfsRowSeparator:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getRowSeparator());
                        break;
                    case HdfsFileSeparator:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getFieldSeparator());
                        break;
                    case HdfsRowHeader:
                        ConnectionContextHelper.createParameters(varList, paramName, conn.getHeaderValue(), JavaTypesManager.INTEGER);
                        break;
                    default:
                }
            }
        }
        createHadoopPropertiesContextVariable(prefixName, varList, conn.getHadoopProperties());
    }
    return varList;
}
Also used : ArrayList(java.util.ArrayList) EHadoopParamName(org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName) HDFSConnection(org.talend.repository.model.hdfs.HDFSConnection) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) IContextParameter(org.talend.core.model.process.IContextParameter)

Example 8 with HDFSConnection

use of org.talend.repository.model.hdfs.HDFSConnection in project tbd-studio-se by Talend.

the class HdfsContextHandler method setPropertiesForExistContextMode.

@Override
public void setPropertiesForExistContextMode(Connection connection, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> adaptMap) {
    if (connection == null) {
        return;
    }
    if (connection instanceof HDFSConnection) {
        HDFSConnection hcatalogConn = (HDFSConnection) connection;
        ContextItem currentContext = null;
        for (IConnParamName param : paramSet) {
            if (param instanceof EHadoopParamName) {
                String hdfsVariableName = null;
                EHadoopParamName hdfsConnectionParam = (EHadoopParamName) param;
                if (adaptMap != null && adaptMap.size() > 0) {
                    for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : adaptMap.entrySet()) {
                        currentContext = entry.getKey();
                        List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
                        for (ConectionAdaptContextVariableModel model : modelList) {
                            if (model.getValue().equals(hdfsConnectionParam.name())) {
                                hdfsVariableName = model.getName();
                                break;
                            }
                        }
                    }
                }
                if (hdfsVariableName != null) {
                    hdfsVariableName = getCorrectVariableName(currentContext, hdfsVariableName, hdfsConnectionParam);
                    matchContextForAttribues(hcatalogConn, hdfsConnectionParam, hdfsVariableName);
                }
            }
        }
        matchAdditionProperties(hcatalogConn, adaptMap);
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) EHadoopParamName(org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName) HDFSConnection(org.talend.repository.model.hdfs.HDFSConnection) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) ArrayList(java.util.ArrayList) List(java.util.List) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel) Map(java.util.Map)

Example 9 with HDFSConnection

use of org.talend.repository.model.hdfs.HDFSConnection in project tbd-studio-se by Talend.

the class HdfsContextHandler method revertPropertiesForContextMode.

@Override
public void revertPropertiesForContextMode(Connection connection, ContextType contextType) {
    if (connection instanceof HDFSConnection) {
        HDFSConnection conn = (HDFSConnection) connection;
        String hdfsUser = TalendQuoteUtils.removeQuotes(ContextParameterUtils.getOriginalValue(contextType, conn.getUserName()));
        String hdfsRowSeparator = TalendQuoteUtils.removeQuotes(ContextParameterUtils.getOriginalValue(contextType, conn.getRowSeparator()));
        String hdfsFiledSeparator = TalendQuoteUtils.removeQuotes(ContextParameterUtils.getOriginalValue(contextType, conn.getFieldSeparator()));
        String hdfsRowHeader = TalendQuoteUtils.removeQuotes(ContextParameterUtils.getOriginalValue(contextType, conn.getHeaderValue()));
        String hadoopProperties = conn.getHadoopProperties();
        List<Map<String, Object>> propertiesAfterRevert = transformContextModeToHadoopProperties(HadoopRepositoryUtil.getHadoopPropertiesList(hadoopProperties), contextType);
        conn.setHadoopProperties(HadoopRepositoryUtil.getHadoopPropertiesJsonStr(propertiesAfterRevert));
        conn.setUserName(hdfsUser);
        conn.setRowSeparator(hdfsRowSeparator);
        conn.setFieldSeparator(hdfsFiledSeparator);
        conn.setHeaderValue(hdfsRowHeader);
    }
}
Also used : HDFSConnection(org.talend.repository.model.hdfs.HDFSConnection) Map(java.util.Map)

Example 10 with HDFSConnection

use of org.talend.repository.model.hdfs.HDFSConnection in project tbd-studio-se by Talend.

the class HdfsContextHandler method matchAdditionProperties.

@Override
protected void matchAdditionProperties(Connection conn, Map<ContextItem, List<ConectionAdaptContextVariableModel>> adaptMap) {
    if (conn instanceof HDFSConnection) {
        HDFSConnection hadoopConn = (HDFSConnection) conn;
        if (adaptMap != null && !adaptMap.isEmpty()) {
            List<Map<String, Object>> hadoopListProperties = HadoopRepositoryUtil.getHadoopPropertiesList(hadoopConn.getHadoopProperties());
            Set<String> keys = getConAdditionPropertiesForContextMode(conn);
            for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : adaptMap.entrySet()) {
                List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
                for (ConectionAdaptContextVariableModel model : modelList) {
                    String propertyKey = model.getValue();
                    if (keys.contains(propertyKey)) {
                        List<Map<String, Object>> propertiesAfterContext = transformHadoopPropertiesForExistContextMode(hadoopListProperties, propertyKey, model.getName());
                        hadoopConn.setHadoopProperties(HadoopRepositoryUtil.getHadoopPropertiesJsonStr(propertiesAfterContext));
                    }
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) HDFSConnection(org.talend.repository.model.hdfs.HDFSConnection) ArrayList(java.util.ArrayList) List(java.util.List) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel) Map(java.util.Map)

Aggregations

HDFSConnection (org.talend.repository.model.hdfs.HDFSConnection)16 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 IConnParamName (org.talend.metadata.managment.ui.model.IConnParamName)4 EHadoopParamName (org.talend.metadata.managment.ui.utils.ExtendedNodeConnectionContextUtils.EHadoopParamName)4 HashSet (java.util.HashSet)2 List (java.util.List)2 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)2 IContextParameter (org.talend.core.model.process.IContextParameter)2 ContextItem (org.talend.core.model.properties.ContextItem)2 Property (org.talend.core.model.properties.Property)2 ConectionAdaptContextVariableModel (org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)2 HDFSConnectionBean (org.talend.designer.hdfsbrowse.model.HDFSConnectionBean)2 HDFSConnectionItem (org.talend.repository.model.hdfs.HDFSConnectionItem)2 Test (org.junit.Test)1 EHadoopVersion4Drivers (org.talend.core.hadoop.version.EHadoopVersion4Drivers)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)1 HDFSFile (org.talend.designer.hdfsbrowse.model.HDFSFile)1 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)1