org.apache.cassandra.thrift.InvalidRequestException Java Examples

The following examples show how to use org.apache.cassandra.thrift.InvalidRequestException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractSearch.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * This method intentionally swallows ordered execution issues.  For some reason, our Time UUID ordering does
 * not agree with the cassandra comparator as our micros get very close
 * @param query
 * @param <K>
 * @param <UUID>
 * @param <V>
 * @return
 */
protected static <K, UUID, V> List<HColumn<UUID, V>> swallowOrderedExecution( final SliceQuery<K, UUID, V> query ) {
    try {

        return query.execute().get().getColumns();
    }
    catch ( HInvalidRequestException e ) {
        //invalid request.  Occasionally we get order issues when there shouldn't be, disregard them.

        final Throwable invalidRequestException = e.getCause();

        if ( invalidRequestException instanceof InvalidRequestException
                //we had a range error
                && ( ( InvalidRequestException ) invalidRequestException ).getWhy().contains(
                "range finish must come after start in the order of traversal" )) {
            return Collections.emptyList();
        }

        throw e;
    }
}
 
Example #2
Source File: ThriftColumnFamilyTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testCassandraStorageCounterCF() throws IOException, ClassNotFoundException, TException, TimedOutException, NotFoundException, InvalidRequestException, NoSuchFieldException, UnavailableException, IllegalAccessException, InstantiationException, AuthenticationException, AuthorizationException
{
    pig.registerQuery("rows = LOAD 'cassandra://thriftKs/SomeApp?" + defaultParameters + "' USING CassandraStorage();");

    //Test counter column family support
    pig.registerQuery("CC = load 'cassandra://thriftKs/CC?" + defaultParameters + "' using CassandraStorage();");
    pig.registerQuery("total_hits = foreach CC generate key, SUM(columns.value);");
    //(chuck,4)
    Iterator<Tuple> it = pig.openIterator("total_hits");
    if (it.hasNext()) {
        Tuple t = it.next();
        Assert.assertEquals(t.get(0), "chuck");
        Assert.assertEquals(t.get(1), 4l);
    }
}
 
Example #3
Source File: CqlTableTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void SingleKeyTableTest(String initialQuery)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    pig.setBatchOn();
    pig.registerQuery(initialQuery);
    pig.registerQuery("insertformat= FOREACH moretestvalues GENERATE TOTUPLE(TOTUPLE('a',x)),TOTUPLE(y);");
    pig.registerQuery("STORE insertformat INTO 'cql://cql3ks/test?" + defaultParameters + nativeParameters + "&output_query=UPDATE+cql3ks.test+set+b+%3D+%3F' USING CqlNativeStorage();");
    pig.executeBatch();
    //(5,5)
    //(6,6)
    //(4,4)
    //(2,2)
    //(3,3)
    //(1,1)
    //input_cql=select * from test where token(a) > ? and token(a) <= ?
    pig.registerQuery("result= LOAD 'cql://cql3ks/test?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20test%20where%20token(a)%20%3E%20%3F%20and%20token(a)%20%3C%3D%20%3F' USING CqlNativeStorage();");
    Iterator<Tuple> it = pig.openIterator("result");
    while (it.hasNext()) {
        Tuple t = it.next();
        Assert.assertEquals(t.get(0), t.get(1));
    }
}
 
Example #4
Source File: CqlTableDataTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws TTransportException, IOException, InterruptedException, ConfigurationException,
                                  AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, CharacterCodingException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException
{
    startCassandra();
    setupDataByCql(statements);
    startHadoopCluster();
}
 
Example #5
Source File: CqlRecordReaderTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws TTransportException, IOException, InterruptedException, ConfigurationException,
AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, CharacterCodingException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException
{
    startCassandra();
    setupDataByCql(statements);
    startHadoopCluster();
}
 
Example #6
Source File: ThriftColumnFamilyTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private void executeCliStatements(String[] statements) throws CharacterCodingException, ClassNotFoundException, TException, TimedOutException, NotFoundException, InvalidRequestException, NoSuchFieldException, UnavailableException, IllegalAccessException, InstantiationException
{
    CliMain.connect("127.0.0.1", 9170);
    try
    {
        for (String stmt : statements)
            CliMain.processStatement(stmt);
    }
    catch (Exception e)
    {
    }
}
 
Example #7
Source File: ThriftColumnFamilyTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private String getColumnValue(String ks, String cf, String colName, String key, String validator)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, IOException
{
    Cassandra.Client client = getClient();
    client.set_keyspace(ks);

    ByteBuffer key_user_id = ByteBufferUtil.bytes(key);
    ColumnPath cp = new ColumnPath(cf);
    cp.column = ByteBufferUtil.bytes(colName);

    // read
    ColumnOrSuperColumn got = client.get(key_user_id, cp, ConsistencyLevel.ONE);
    return parseType(validator).getString(got.getColumn().value);
}
 
Example #8
Source File: ThriftColumnFamilyTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCassandraStorageFullCopy() throws IOException, ClassNotFoundException, TException, TimedOutException, NotFoundException, InvalidRequestException, NoSuchFieldException, UnavailableException, IllegalAccessException, InstantiationException, AuthenticationException, AuthorizationException
{
    pig.setBatchOn();
    pig.registerQuery("rows = LOAD 'cassandra://thriftKs/SomeApp?" + defaultParameters + "' USING CassandraStorage();");
    //full copy
    pig.registerQuery("STORE rows INTO 'cassandra://thriftKs/CopyOfSomeApp?" + defaultParameters + "' USING CassandraStorage();");
    pig.executeBatch();
    Assert.assertEquals("User Qux", getColumnValue("thriftKs", "CopyOfSomeApp", "name", "qux", "UTF8Type"));
    Assert.assertEquals("dislike", getColumnValue("thriftKs", "CopyOfSomeApp", "vote_type", "qux", "UTF8Type"));
    Assert.assertEquals("64.7", getColumnValue("thriftKs", "CopyOfSomeApp", "percent", "qux", "FloatType"));
}
 
Example #9
Source File: ThriftColumnFamilyTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCqlNativeStorage() throws IOException, ClassNotFoundException, TException, TimedOutException, NotFoundException, InvalidRequestException, NoSuchFieldException, UnavailableException, IllegalAccessException, InstantiationException, AuthenticationException, AuthorizationException
{
    //regular thrift column families
    //input_cql=select * from "SomeApp" where token(key) > ? and token(key) <= ?
    cqlStorageTest("data = load 'cql://thriftKs/SomeApp?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20%22SomeApp%22%20where%20token(key)%20%3E%20%3F%20and%20token(key)%20%3C%3D%20%3F' using CqlNativeStorage();");

    //Test counter colun family
    //input_cql=select * from "CC" where token(key) > ? and token(key) <= ?
    cqlStorageCounterTableTest("cc_data = load 'cql://thriftKs/CC?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20%22CC%22%20where%20token(key)%20%3E%20%3F%20and%20token(key)%20%3C%3D%20%3F' using CqlNativeStorage();");

    //Test composite column family
    //input_cql=select * from "Compo" where token(key) > ? and token(key) <= ?
    cqlStorageCompositeTableTest("compo_data = load 'cql://thriftKs/Compo?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20%22Compo%22%20where%20token(key)%20%3E%20%3F%20and%20token(key)%20%3C%3D%20%3F' using CqlNativeStorage();");
}
 
Example #10
Source File: ThriftColumnFamilyTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws TTransportException, IOException, InterruptedException, ConfigurationException,
                                  AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, CharacterCodingException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException
{
    startCassandra();
    setupDataByCli(statements);
    startHadoopCluster();
}
 
Example #11
Source File: ThriftColumnFamilyDataTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws TTransportException, IOException, InterruptedException, ConfigurationException,
                                  AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, CharacterCodingException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException
{
    startCassandra();
    setupDataByCli(statements);
    startHadoopCluster();
}
 
Example #12
Source File: CqlTableDataTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCqlNativeStorageMapType()
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    //input_cql=select * from maptable where token(key) > ? and token(key) <= ?
    maptableTest("map_rows = LOAD 'cql://cql3ks/maptable?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20maptable%20where%20token(key)%20%3E%20%3F%20and%20token(key)%20%3C%3D%20%3F' USING CqlNativeStorage();");
}
 
Example #13
Source File: CqlTableDataTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCqlNativeStorageListType()
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    //input_cql=select * from listtable where token(key) > ? and token(key) <= ?
    listtableTest("list_rows = LOAD 'cql://cql3ks/listtable?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20listtable%20where%20token(key)%20%3E%20%3F%20and%20token(key)%20%3C%3D%20%3F' USING CqlNativeStorage();");
}
 
Example #14
Source File: CqlTableDataTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCqlNativeStorageSetType()
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    //input_cql=select * from settable where token(key) > ? and token(key) <= ?
    settableTest("set_rows = LOAD 'cql://cql3ks/settable?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20settable%20where%20token(key)%20%3E%20%3F%20and%20token(key)%20%3C%3D%20%3F' USING CqlNativeStorage();");
}
 
Example #15
Source File: CqlTableDataTypeTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCqlNativeStorageRegularType()
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    //input_cql=select * from cqltable where token(key) > ? and token(key) <= ?
    cqlTableTest("rows = LOAD 'cql://cql3ks/cqltable?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20cqltable%20where%20token(key)%20%3E%20%3F%20and%20token(key)%20%3C%3D%20%3F' USING CqlNativeStorage();");

    //input_cql=select * from countertable where token(key) > ? and token(key) <= ?
    counterTableTest("cc_rows = LOAD 'cql://cql3ks/countertable?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20countertable%20where%20token(key)%20%3E%20%3F%20and%20token(key)%20%3C%3D%20%3F' USING CqlNativeStorage();");
}
 
Example #16
Source File: Schema.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
private void dropOldKeyspace() throws InvalidRequestException, SchemaDisagreementException, TException {
  TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
  TProtocol proto = new TBinaryProtocol(tr);
  Cassandra.Client client = new Cassandra.Client(proto);
  tr.open();

  client.system_drop_keyspace(JANUSGRAPH);
  LOGGER.info("DROPPED keyspace janusgraph");
  tr.close();
}
 
Example #17
Source File: CqlTableTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private void CollectionColumnTableTest(String initialQuery)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    pig.setBatchOn();
    pig.registerQuery(initialQuery);
    pig.registerQuery("recs= FOREACH collectiontable GENERATE TOTUPLE(TOTUPLE('m', m) ), TOTUPLE(TOTUPLE('map', TOTUPLE('m', 'mm'), TOTUPLE('n', 'nn')));");
    pig.registerQuery("STORE recs INTO 'cql://cql3ks/collectiontable?" + defaultParameters + nativeParameters + "&output_query=update+cql3ks.collectiontable+set+n+%3D+%3F' USING CqlNativeStorage();");
    pig.executeBatch();

    //(book2,((m,mm),(n,nn)))
    //(book3,((m,mm),(n,nn)))
    //(book4,((m,mm),(n,nn)))
    //(book1,((m,mm),(n,nn)))
    //input_cql=select * from collectiontable where token(m) > ? and token(m) <= ?
    pig.registerQuery("result= LOAD 'cql://cql3ks/collectiontable?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20collectiontable%20where%20token(m)%20%3E%20%3F%20and%20token(m)%20%3C%3D%20%3F' USING CqlNativeStorage();");
    Iterator<Tuple> it = pig.openIterator("result");
    if (it.hasNext()) {
        Tuple t = it.next();
        Tuple t1 = (Tuple) t.get(1);
        Assert.assertEquals(t1.size(), 2);
        Tuple element1 = (Tuple) t1.get(0);
        Tuple element2 = (Tuple) t1.get(1);
        Assert.assertEquals(element1.get(0), "m");
        Assert.assertEquals(element1.get(1), "mm");
        Assert.assertEquals(element2.get(0), "n");
        Assert.assertEquals(element2.get(1), "nn");
    }
    else
    {
        Assert.fail("Can't fetch any data");
    }
}
 
Example #18
Source File: CqlTableTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCqlNativeStorageCollectionColumnTable()
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    //input_cql=select * from collectiontable where token(m) > ? and token(m) <= ?
    CollectionColumnTableTest("collectiontable= LOAD 'cql://cql3ks/collectiontable?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20collectiontable%20where%20token(m)%20%3E%20%3F%20and%20token(m)%20%3C%3D%20%3F' USING CqlNativeStorage();");
}
 
Example #19
Source File: CqlTableTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private void CompositeKeyTableTest(String initialQuery)
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    pig.setBatchOn();
    pig.registerQuery(initialQuery);
    pig.registerQuery("insertformat = FOREACH moredata GENERATE TOTUPLE (TOTUPLE('a',x),TOTUPLE('b',y), TOTUPLE('c',z)),TOTUPLE(data);");
    pig.registerQuery("STORE insertformat INTO 'cql://cql3ks/compotable?" + defaultParameters + nativeParameters + "&output_query=UPDATE%20cql3ks.compotable%20SET%20d%20%3D%20%3F' USING CqlNativeStorage();");
    pig.executeBatch();

    //(5,6,Fix,nomatch)
    //(3,3,Three,match)
    //(1,1,One,match)
    //(2,2,Two,match)
    //(7,7,Seven,match)
    //(8,8,Eight,match)
    //(6,5,Sive,nomatch)
    //(4,4,Four,match)
    //(9,10,Ninen,nomatch)
    //input_cql=select * from compotable where token(a) > ? and token(a) <= ?
    pig.registerQuery("result= LOAD 'cql://cql3ks/compotable?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20compotable%20where%20token(a)%20%3E%20%3F%20and%20token(a)%20%3C%3D%20%3F' USING CqlNativeStorage();");
    Iterator<Tuple> it = pig.openIterator("result");
    int count = 0;
    while (it.hasNext()) {
        it.next();
        count ++;
    }
    Assert.assertEquals(count, 9);
}
 
Example #20
Source File: CqlTableTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCqlNativeStorageCompositeKeyTable()
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    //input_cql=select * from compmore where token(id) > ? and token(id) <= ?
    CompositeKeyTableTest("moredata= LOAD 'cql://cql3ks/compmore?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20compmore%20where%20token(id)%20%3E%20%3F%20and%20token(id)%20%3C%3D%20%3F' USING CqlNativeStorage();");
}
 
Example #21
Source File: CqlTableTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCqlNativeStorageSingleKeyTable()
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    //input_cql=select * from moredata where token(x) > ? and token(x) <= ?
    SingleKeyTableTest("moretestvalues= LOAD 'cql://cql3ks/moredata?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20moredata%20where%20token(x)%20%3E%20%3F%20and%20token(x)%20%3C%3D%20%3F' USING CqlNativeStorage();");
}
 
Example #22
Source File: CqlTableTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testCqlNativeStorageSchema()
throws AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, SchemaDisagreementException, IOException
{
    //input_cql=select * from cqltable where token(key1) > ? and token(key1) <= ?
    cqlTableSchemaTest("rows = LOAD 'cql://cql3ks/cqltable?" + defaultParameters + nativeParameters +  "&input_cql=select%20*%20from%20cqltable%20where%20token(key1)%20%3E%20%3F%20and%20token(key1)%20%3C%3D%20%3F' USING CqlNativeStorage();");

    //input_cql=select * from compactcqltable where token(key1) > ? and token(key1) <= ?
    compactCqlTableSchemaTest("rows = LOAD 'cql://cql3ks/compactcqltable?" + defaultParameters + nativeParameters + "&input_cql=select%20*%20from%20compactcqltable%20where%20token(key1)%20%3E%20%3F%20and%20token(key1)%20%3C%3D%20%3F' USING CqlNativeStorage();");
}
 
Example #23
Source File: CqlTableTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws TTransportException, IOException, InterruptedException, ConfigurationException,
                                  AuthenticationException, AuthorizationException, InvalidRequestException, UnavailableException, TimedOutException, TException, NotFoundException, CharacterCodingException, ClassNotFoundException, NoSuchFieldException, IllegalAccessException, InstantiationException
{
    startCassandra();
    setupDataByCql(statements);
    startHadoopCluster();
}
 
Example #24
Source File: PigTestBase.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
protected static void setupDataByCli(String[] statements) throws CharacterCodingException, ClassNotFoundException, TException, TimedOutException, NotFoundException, InvalidRequestException, NoSuchFieldException, UnavailableException, IllegalAccessException, InstantiationException
{
    // new error/output streams for CliSessionState
    ByteArrayOutputStream errStream = new ByteArrayOutputStream();
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();

    // checking if we can connect to the running cassandra node on localhost
    CliMain.connect("127.0.0.1", 9170);

    // setting new output stream
    CliMain.sessionState.setOut(new PrintStream(outStream));
    CliMain.sessionState.setErr(new PrintStream(errStream));

    // re-creating keyspace for tests
    try
    {
        // dropping in case it exists e.g. could be left from previous run
        CliMain.processStatement("drop keyspace thriftKs;");
    }
    catch (Exception e)
    {
    }

    for (String statement : statements)
    {
        errStream.reset();
        System.out.println("Executing statement: " + statement);
        CliMain.processStatement(statement);
        String result = outStream.toString();
        System.out.println("result: " + result);
        outStream.reset(); // reset stream so we have only output from next statement all the time
        errStream.reset(); // no errors to the end user.
    }
}
 
Example #25
Source File: AbstractCassandraInputAdapter.java    From OpenRate with Apache License 2.0 5 votes vote down vote up
private void insertColumnValue(String parentName, String id, String name, String value, long ts) throws TException, TimedOutException, UnavailableException, InvalidRequestException, UnsupportedEncodingException {
  ColumnParent parent = new ColumnParent(parentName);
  Column column = new Column(toByteBuffer(name));
  column.setValue(toByteBuffer(value));
  column.setTimestamp(ts);
  getClient().insert(toByteBuffer(id), parent, column, ConsistencyLevel.ONE);
}
 
Example #26
Source File: Operation.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
protected String getExceptionMessage(Exception e)
{
    String className = e.getClass().getSimpleName();
    String message = (e instanceof InvalidRequestException) ? ((InvalidRequestException) e).getWhy() : e.getMessage();
    return (message == null) ? "(" + className + ")" : String.format("(%s): %s", className, message);
}
 
Example #27
Source File: CassandraOutputDialog.java    From learning-hadoop with Apache License 2.0 4 votes vote down vote up
protected void popupSchemaInfo() {

    CassandraConnection conn = null;
    try {
      String hostS = transMeta.environmentSubstitute(m_hostText.getText());
      String portS = transMeta.environmentSubstitute(m_portText.getText());
      String userS = m_userText.getText();
      String passS = m_passText.getText();
      if (!Const.isEmpty(userS) && !Const.isEmpty(passS)) {
        userS = transMeta.environmentSubstitute(userS);
        passS = transMeta.environmentSubstitute(passS);
      }
      String keyspaceS = transMeta.environmentSubstitute(m_keyspaceText
          .getText());

      conn = CassandraOutputData.getCassandraConnection(hostS,
          Integer.parseInt(portS), userS, passS);
      try {
        conn.setKeyspace(keyspaceS);
      } catch (InvalidRequestException ire) {
        logError(
            BaseMessages.getString(PKG,
                "CassandraInputDialog.Error.ProblemGettingSchemaInfo.Message")
                + ":\n\n" + ire.why, ire);
        new ErrorDialog(shell, BaseMessages.getString(PKG,
            "CassandraInputDialog.Error.ProblemGettingSchemaInfo.Title"),
            BaseMessages.getString(PKG,
                "CassandraInputDialog.Error.ProblemGettingSchemaInfo.Message")
                + ":\n\n" + ire.why, ire);
        return;
      }

      String colFam = transMeta.environmentSubstitute(m_columnFamilyCombo
          .getText());
      if (Const.isEmpty(colFam)) {
        throw new Exception("No colummn family (table) name specified!");
      }

      if (!CassandraColumnMetaData.columnFamilyExists(conn, colFam)) {
        throw new Exception("The column family '" + colFam + "' does not "
            + "seem to exist in the keyspace '" + keyspaceS);
      }

      CassandraColumnMetaData cassMeta = new CassandraColumnMetaData(conn,
          colFam);
      String schemaDescription = cassMeta.getSchemaDescription();
      ShowMessageDialog smd = new ShowMessageDialog(shell, SWT.ICON_INFORMATION
          | SWT.OK, "Schema info", schemaDescription, true);
      smd.open();
    } catch (Exception e1) {
      logError(
          BaseMessages.getString(PKG,
              "CassandraOutputDialog.Error.ProblemGettingSchemaInfo.Message")
              + ":\n\n" + e1.getMessage(), e1);
      new ErrorDialog(shell, BaseMessages.getString(PKG,
          "CassandraOutputDialog.Error.ProblemGettingSchemaInfo.Title"),
          BaseMessages.getString(PKG,
              "CassandraOutputDialog.Error.ProblemGettingSchemaInfo.Message")
              + ":\n\n" + e1.getMessage(), e1);
    } finally {
      if (conn != null) {
        conn.close();
      }
    }
  }
 
Example #28
Source File: CassandraOutputDialog.java    From learning-hadoop with Apache License 2.0 4 votes vote down vote up
protected void setupColumnFamiliesCombo() {
  CassandraConnection conn = null;

  try {
    String hostS = transMeta.environmentSubstitute(m_hostText.getText());
    String portS = transMeta.environmentSubstitute(m_portText.getText());
    String userS = m_userText.getText();
    String passS = m_passText.getText();
    if (!Const.isEmpty(userS) && !Const.isEmpty(passS)) {
      userS = transMeta.environmentSubstitute(userS);
      passS = transMeta.environmentSubstitute(passS);
    }
    String keyspaceS = transMeta.environmentSubstitute(m_keyspaceText
        .getText());

    conn = CassandraOutputData.getCassandraConnection(hostS,
        Integer.parseInt(portS), userS, passS);

    try {
      conn.setKeyspace(keyspaceS);
    } catch (InvalidRequestException ire) {
      logError(
          BaseMessages.getString(PKG,
              "CassandraOutputDialog.Error.ProblemGettingSchemaInfo.Message")
              + ":\n\n" + ire.why, ire);
      new ErrorDialog(shell, BaseMessages.getString(PKG,
          "CassandraOutputDialog.Error.ProblemGettingSchemaInfo.Title"),
          BaseMessages.getString(PKG,
              "CassandraOutputDialog.Error.ProblemGettingSchemaInfo.Message")
              + ":\n\n" + ire.why, ire);
      return;
    }

    List<String> colFams = CassandraColumnMetaData.getColumnFamilyNames(conn);
    m_columnFamilyCombo.removeAll();
    for (String famName : colFams) {
      m_columnFamilyCombo.add(famName);
    }

  } catch (Exception ex) {
    logError(
        BaseMessages.getString(PKG,
            "CassandraOutputDialog.Error.ProblemGettingSchemaInfo.Message")
            + ":\n\n" + ex.getMessage(), ex);
    new ErrorDialog(shell, BaseMessages.getString(PKG,
        "CassandraOutputDialog.Error.ProblemGettingSchemaInfo.Title"),
        BaseMessages.getString(PKG,
            "CassandraOutputDialog.Error.ProblemGettingSchemaInfo.Message")
            + ":\n\n" + ex.getMessage(), ex);
  }
}
 
Example #29
Source File: CassandraProxyClient.java    From Hive-Cassandra with Apache License 2.0 1 votes vote down vote up
/**
 * Create a temporary keyspace. This will only be called when there is no keyspace except system
 * defined on (new cluster).
 * However we need a keyspace to call describe_ring to get all servers from the ring.
 *
 * @return the temporary keyspace
 * @throws InvalidRequestException
 *           error
 * @throws TException
 *           error
 * @throws SchemaDisagreementException
 * @throws InterruptedException
 *           error
 */
private KsDef createTmpKs() throws InvalidRequestException, TException, SchemaDisagreementException {

  Map<String, String> stratOpts = new HashMap<String, String>();
  stratOpts.put("replication_factor", "1");

  KsDef tmpKs = new KsDef("proxy_client_ks", "org.apache.cassandra.locator.SimpleStrategy",
      Arrays.asList(new CfDef[] {})).setStrategy_options(stratOpts);

  clientHolder.getClient().system_add_keyspace(tmpKs);

  return tmpKs;
}