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);
}
}
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;
}
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);
}
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;
}
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);
}
}
}
}
}
}
Aggregations