Search in sources :

Example 86 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.

the class CassandraMetadataHandler method initCluster.

private void initCluster(NoSQLConnection connection) throws NoSQLServerException {
    try {
        if (cluster != null) {
            // $NON-NLS-1$
            boolean isClosed = (Boolean) NoSQLReflection.invokeMethod(cluster, "isClosed");
            if (!isClosed) {
                return;
            }
        }
        ClassLoader classLoader = NoSQLClassLoaderFactory.getClassLoader(connection);
        ContextType contextType = null;
        String host = connection.getAttributes().get(ICassandraAttributies.HOST);
        String port = connection.getAttributes().get(ICassandraAttributies.PORT);
        if (connection.isContextMode()) {
            contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
        }
        if (contextType != null) {
            host = ContextParameterUtils.getOriginalValue(contextType, host);
            port = ContextParameterUtils.getOriginalValue(contextType, port);
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        cluster = NoSQLReflection.invokeStaticMethod("com.datastax.driver.core.Cluster", "builder", classLoader);
        // $NON-NLS-1$
        cluster = NoSQLReflection.invokeMethod(cluster, "addContactPoint", new Object[] { host });
        // //$NON-NLS-1$
        cluster = NoSQLReflection.invokeMethod(cluster, "withPort", new Object[] { Integer.valueOf(port) }, int.class);
        // Do authenticate
        String requireAuthAttr = connection.getAttributes().get(ICassandraAttributies.REQUIRED_AUTHENTICATION);
        boolean requireAuth = requireAuthAttr == null ? false : Boolean.valueOf(requireAuthAttr);
        if (requireAuth) {
            String username = connection.getAttributes().get(ICassandraAttributies.USERNAME);
            String password = connection.getValue(connection.getAttributes().get(ICassandraAttributies.PASSWORD), false);
            if (contextType != null) {
                username = ContextParameterUtils.getOriginalValue(contextType, username);
                password = ContextParameterUtils.getOriginalValue(contextType, password);
            }
            // $NON-NLS-1$
            cluster = NoSQLReflection.invokeMethod(cluster, "withCredentials", new Object[] { username, password });
        }
        // $NON-NLS-1$
        cluster = NoSQLReflection.invokeMethod(cluster, "build");
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException)

Example 87 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.

the class HDFSModelUtil method convert2HDFSConnectionBean.

/**
 * DOC ycbai Comment method "convert2HDFSConnectionBean".
 *
 * Convert HDFSConnection to HDFSConnectionBean
 *
 * @param connection
 * @return
 */
public static HDFSConnectionBean convert2HDFSConnectionBean(HDFSConnection connection) {
    ContextType contextType = null;
    if (connection.isContextMode()) {
        contextType = ConnectionContextHelper.getContextTypeForContextMode(connection, true);
    }
    HDFSConnectionBean bean = new HDFSConnectionBean();
    bean.setContextType(contextType);
    try {
        HadoopClusterConnection hcConnection = HCRepositoryUtil.getRelativeHadoopClusterConnection(connection);
        if (hcConnection != null) {
            ContextType parentContextType = null;
            if (hcConnection.isContextMode()) {
                parentContextType = ConnectionContextHelper.getContextTypeForContextMode(hcConnection, true);
            }
            bean.setParentContextType(parentContextType);
            BeanUtils.copyProperties(bean, hcConnection);
            Map<String, Object> properties = bean.getAdditionalProperties();
            Map<String, Set<String>> customVersionMap = HCVersionUtil.getCustomVersionMap(hcConnection);
            Iterator<Entry<String, Set<String>>> iter = customVersionMap.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry<String, Set<String>> entry = iter.next();
                String groupName = entry.getKey();
                Set<String> jars = entry.getValue();
                if (jars != null && jars.size() > 0) {
                    properties.put(groupName, jars);
                }
            }
        }
        bean.setUserName(connection.getUserName());
        bean.setFieldSeparator(connection.getFieldSeparator());
        bean.setRowSeparator(connection.getRowSeparator());
        bean.setRelativeHadoopClusterId(connection.getRelativeHadoopClusterId());
        Map<String, Object> configurations = bean.getConfigurations();
        List<Map<String, Object>> hadoopProperties = HadoopRepositoryUtil.getHadoopPropertiesFullList(connection, connection.getHadoopProperties(), false, true);
        for (Map<String, Object> propMap : hadoopProperties) {
            // $NON-NLS-1$
            String key = TalendQuoteUtils.removeQuotesIfExist(String.valueOf(propMap.get("PROPERTY")));
            // $NON-NLS-1$
            String value = TalendQuoteUtils.removeQuotesIfExist(String.valueOf(propMap.get("VALUE")));
            if (StringUtils.isNotEmpty(key) && value != null) {
                configurations.put(key, value);
            }
        }
    } catch (Exception e) {
        log.error("Convert failure from HDFSConnection to HDFSConnectionBean", e);
    }
    return bean;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) Set(java.util.Set) Entry(java.util.Map.Entry) HDFSConnectionBean(org.talend.designer.hdfsbrowse.model.HDFSConnectionBean) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) Map(java.util.Map)

Example 88 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.

the class MongoConnectionStringValidator method validate.

/* (non-Javadoc)
     * @see org.talend.repository.nosql.validator.IValidator#validate()
     */
@Override
public boolean validate() {
    if (value == null) {
        return false;
    }
    String connString = String.valueOf(value);
    if (connection.isContextMode()) {
        ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
        connString = ContextParameterUtils.getOriginalValue(contextType, connString);
    }
    return connString.startsWith(local_prefix) || connString.startsWith(atlas_prefix);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType)

Example 89 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.

the class HadoopConfsUtils method getConfsJarDefaultNames.

/**
 * Get all conf jars names. If the connection is in context mode each context group will has one conf jar, otherwise
 * there will be only one conf jar.
 *
 * @param connectionItem
 * @param createJarIfNotExist
 *
 * @return
 */
public static Set<String> getConfsJarDefaultNames(HadoopClusterConnectionItem connectionItem, boolean createJarIfNotExist) {
    Set<String> jarNames = new HashSet<>();
    HadoopClusterConnection connection = (HadoopClusterConnection) connectionItem.getConnection();
    if (connection.isContextMode()) {
        ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
        if (contextItem != null) {
            EList<ContextType> contexts = contextItem.getContext();
            for (ContextType contextType : contexts) {
                jarNames.add(HadoopConfsUtils.getConfsJarDefaultName(connectionItem, createJarIfNotExist, contextType.getName()));
            }
        }
    } else {
        jarNames.add(HadoopConfsUtils.getConfsJarDefaultName(connectionItem, createJarIfNotExist));
    }
    return jarNames;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) HashSet(java.util.HashSet)

Example 90 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tbd-studio-se by Talend.

the class HadoopConfsUtils method createAndDeployConfJar.

private static void createAndDeployConfJar(HadoopClusterConnectionItem connectionItem, String confJarId, String confJarName) throws IOException {
    // If the conf jar has been deployed before then no need to deploy again.
    if (containsInDeployedCache(connectionItem, confJarName)) {
        return;
    }
    byte[] confFileBA = null;
    HadoopClusterConnection connection = (HadoopClusterConnection) connectionItem.getConnection();
    if (connection.isContextMode()) {
        ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
        if (contextItem != null) {
            EMap<String, byte[]> confFiles = connection.getConfFiles();
            EList<ContextType> contexts = contextItem.getContext();
            for (ContextType contextType : contexts) {
                String contextName = contextType.getName();
                byte[] bs = confFiles.get(contextName);
                if (confJarId.endsWith(contextName) && bs != null) {
                    confFileBA = bs;
                    break;
                }
            }
        }
        if (confFileBA == null) {
            // either conf jar name is wrong or it is a old item.
            // then take the old hadoop conf file content.
            confFileBA = connection.getConfFile();
        }
    } else {
        confFileBA = connection.getConfFile();
    }
    if (confFileBA != null) {
        File confsTempFolder = new File(getConfsJarTempFolder());
        File confFile = new File(confsTempFolder, confJarName);
        FileUtils.writeByteArrayToFile(confFile, confFileBA);
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerService.class)) {
            ILibraryManagerService libService = GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
            if (libService != null && libService.isJarNeedToBeDeployed(confFile)) {
                if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
                    ILibrariesService service = GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
                    if (service != null) {
                        // Only deploy a new jar, no need to reset all
                        service.deployLibrary(confFile.toURI().toURL());
                        addToDeployedCache(connectionItem, confJarName);
                    }
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ILibraryManagerService(org.talend.core.ILibraryManagerService) ILibrariesService(org.talend.core.model.general.ILibrariesService) HadoopClusterConnection(org.talend.repository.model.hadoopcluster.HadoopClusterConnection) File(java.io.File)

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)108 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)27 ArrayList (java.util.ArrayList)26 ContextItem (org.talend.core.model.properties.ContextItem)21 PersistenceException (org.talend.commons.exception.PersistenceException)17 File (java.io.File)16 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)15 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)13 NoSQLReflectionException (org.talend.repository.nosql.exceptions.NoSQLReflectionException)13 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 List (java.util.List)10 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)8 Map (java.util.Map)8 EList (org.eclipse.emf.common.util.EList)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 Property (org.talend.core.model.properties.Property)6 HashSet (java.util.HashSet)5