Search in sources :

Example 21 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraMetadataHandler method getKeySpace.

private Object getKeySpace(NoSQLConnection connection, String ksName) throws NoSQLServerException {
    ContextType contextType = null;
    if (StringUtils.isEmpty(ksName)) {
        return null;
    }
    if (connection.isContextMode()) {
        contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
    }
    if (contextType != null) {
        ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
    }
    // if ksName has quote,then case sensitive
    boolean hasQuote = (ksName.charAt(0) == '"') && (ksName.charAt(ksName.length() - 1) == '"');
    try {
        initCluster(connection);
        List<Object> keySpaces = getKeySpaces(connection);
        for (Object keySpace : keySpaces) {
            // $NON-NLS-1$
            String tmpKsName = (String) NoSQLReflection.invokeMethod(keySpace, "getName");
            if (hasQuote) {
                ksName = TalendQuoteUtils.removeQuotesIfExist(ksName);
                if (ksName.equals(tmpKsName)) {
                    return keySpace;
                }
            // case in-sensitive by default for kaName
            } else if (ksName.equalsIgnoreCase(tmpKsName)) {
                return keySpace;
            }
        }
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return null;
}
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 22 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraMetadataHandler method getColumnFamilyNames.

@Override
public Set<String> getColumnFamilyNames(NoSQLConnection connection, String ksName) throws NoSQLServerException {
    Set<String> cfNames = new HashSet<String>();
    try {
        Object keySpace = null;
        if (ksName == null) {
            keySpace = getKeySpace(connection);
        } else {
            keySpace = getKeySpace(connection, ksName);
            if (keySpace == null) {
                return cfNames;
            }
        }
        if (keySpace == null) {
            List<String> ksNames = getKeySpaceNames(connection);
            for (String name : ksNames) {
                cfNames.addAll(getColumnFamilyNames(connection, name));
            }
        } else {
            // $NON-NLS-1$
            Collection tables = (Collection) NoSQLReflection.invokeMethod(keySpace, "getTables");
            for (Object table : tables) {
                // $NON-NLS-1$
                String cfName = (String) NoSQLReflection.invokeMethod(table, "getName");
                cfNames.add(cfName);
            }
        }
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return cfNames;
}
Also used : NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) Collection(java.util.Collection) NoSQLServerException(org.talend.repository.nosql.exceptions.NoSQLServerException) NoSQLReflectionException(org.talend.repository.nosql.exceptions.NoSQLReflectionException) HashSet(java.util.HashSet)

Example 23 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException 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 24 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraOldVersionMetadataHandler method getKeySpace.

private Object getKeySpace(NoSQLConnection connection, String ksName) throws NoSQLServerException {
    ContextType contextType = null;
    if (StringUtils.isEmpty(ksName)) {
        return null;
    }
    if (connection.isContextMode()) {
        contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
    }
    if (contextType != null) {
        ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
    }
    Object ksDef = null;
    try {
        // $NON-NLS-1$
        ksDef = NoSQLReflection.invokeMethod(getOrCreateCluster(connection), "describeKeyspace", new Object[] { ksName });
    } catch (Exception e) {
        throw new NoSQLServerException(e);
    }
    return ksDef;
}
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 25 with NoSQLServerException

use of org.talend.repository.nosql.exceptions.NoSQLServerException in project tbd-studio-se by Talend.

the class CassandraOldVersionMetadataHandler method checkConnection.

@Override
public boolean checkConnection(NoSQLConnection connection) throws NoSQLServerException {
    cluster = null;
    try {
        ContextType contextType = null;
        String ksName = connection.getAttributes().get(ICassandraAttributies.DATABASE);
        if (connection.isContextMode()) {
            contextType = ConnectionContextHelper.getContextTypeForContextMode(connection);
        }
        if (contextType != null) {
            ksName = ContextParameterUtils.getOriginalValue(contextType, ksName);
        }
        Object cCluster = getOrCreateCluster(connection);
        // if cancel to interrupt check connection, throw exception
        if (Thread.currentThread().interrupted()) {
            // $NON-NLS-1$
            throw new InterruptedException();
        }
        if (StringUtils.isEmpty(ksName)) {
            // $NON-NLS-1$
            NoSQLReflection.invokeMethod(cCluster, "describeClusterName");
        } else {
            // $NON-NLS-1$
            Object ksDef = NoSQLReflection.invokeMethod(cCluster, "describeKeyspace", new Object[] { ksName });
            if (ksDef == null) {
                throw new NoSQLServerException("Keyspace '" + ksName + "' doesn't exist!");
            }
        }
        return true;
    } catch (Exception e) {
        if (e instanceof InterruptedException) {
            // $NON-NLS-1$
            throw new NoSQLServerException(Messages.getString("noSQLConnectionTest.cancelCheckConnection"), e);
        } else {
            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)

Aggregations

NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)36 NoSQLReflectionException (org.talend.repository.nosql.exceptions.NoSQLReflectionException)33 ArrayList (java.util.ArrayList)13 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)13 ASN1Object (org.bouncycastle.asn1.ASN1Object)9 JSONObject (org.talend.utils.json.JSONObject)9 List (java.util.List)7 JSONException (org.talend.utils.json.JSONException)6 HashSet (java.util.HashSet)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 SSLContext (javax.net.ssl.SSLContext)3 File (java.io.File)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 MappingTypeRetriever (org.talend.core.model.metadata.MappingTypeRetriever)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1