List of usage examples for org.apache.thrift.protocol TCompactProtocol TCompactProtocol
public TCompactProtocol(TTransport transport)
From source file:lizard.comms.thrift.ThriftLib.java
License:Apache License
/** Choose the wire-representation : compact is the normal choice */ public static TProtocol protocol(TTransport transport) { if (true)/* ww w . jav a 2s .c om*/ return new TCompactProtocol(transport); if (false) return new TBinaryProtocol(transport); if (false) return new TTupleProtocol(transport); if (false) return new TJSONProtocol(transport); throw new InternalErrorException("No protocol impl choosen"); }
From source file:org.apache.accumulo.core.trace.TraceFormatter.java
License:Apache License
public static RemoteSpan getRemoteSpan(Entry<Key, Value> entry) { TMemoryInputTransport transport = new TMemoryInputTransport(entry.getValue().get()); TCompactProtocol protocol = new TCompactProtocol(transport); RemoteSpan span = new RemoteSpan(); try {//from ww w.ja v a 2 s . c o m span.read(protocol); } catch (TException ex) { throw new RuntimeException(ex); } return span; }
From source file:org.apache.accumulo.core.util.ThriftMessageUtil.java
License:Apache License
public ThriftMessageUtil(int initialCapacity, double growthCoefficient) { // TODO does this make sense? better to push this down to the serialize method (accept the transport as an argument)? this.transport = new AutoExpandingBufferWriteTransport(initialCapacity, growthCoefficient); this.protocol = new TCompactProtocol(transport); }
From source file:org.apache.accumulo.core.util.ThriftMessageUtil.java
License:Apache License
/** * Deserializes a message into the provided {@code instance} from {@code serialized} * * @param serialized/*from ww w.j a v a 2 s .com*/ * The serialized representation of the object * @param instance * An instance of the object to reconstitute * @return The reconstituted instance provided * @throws IOException * When deserialization fails */ public <T extends TBase<?, ?>> T deserialize(byte[] serialized, int offset, int length, T instance) throws IOException { requireNonNull(instance); TCompactProtocol proto = new TCompactProtocol(new TMemoryInputTransport(serialized, offset, length)); try { instance.read(proto); } catch (TException e) { throw new IOException(e); } return instance; }
From source file:org.apache.accumulo.test.functional.KerberosProxyIT.java
License:Apache License
@Test public void testProxyClient() throws Exception { ClusterUser rootUser = kdc.getRootUser(); UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath()); UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); TSocket socket = new TSocket(hostname, proxyPort); log.info("Connecting to proxy with server primary '" + proxyPrimary + "' running on " + hostname); TSaslClientTransport transport = new TSaslClientTransport("GSSAPI", null, proxyPrimary, hostname, Collections.singletonMap("javax.security.sasl.qop", "auth"), null, socket); final UGIAssumingTransport ugiTransport = new UGIAssumingTransport(transport, ugi); // UGI transport will perform the doAs for us ugiTransport.open();//from ww w . jav a 2s . c o m AccumuloProxy.Client.Factory factory = new AccumuloProxy.Client.Factory(); Client client = factory.getClient(new TCompactProtocol(ugiTransport), new TCompactProtocol(ugiTransport)); // Will fail if the proxy can impersonate the client ByteBuffer login = client.login(rootUser.getPrincipal(), Collections.<String, String>emptyMap()); // For all of the below actions, the proxy user doesn't have permission to do any of them, but the client user does. // The fact that any of them actually run tells us that impersonation is working. // Create a table String table = "table"; if (!client.tableExists(login, table)) { client.createTable(login, table, true, TimeType.MILLIS); } // Write two records to the table String writer = client.createWriter(login, table, new WriterOptions()); Map<ByteBuffer, List<ColumnUpdate>> updates = new HashMap<>(); ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap("cf1".getBytes(UTF_8)), ByteBuffer.wrap("cq1".getBytes(UTF_8))); update.setValue(ByteBuffer.wrap("value1".getBytes(UTF_8))); updates.put(ByteBuffer.wrap("row1".getBytes(UTF_8)), Collections.<ColumnUpdate>singletonList(update)); update = new ColumnUpdate(ByteBuffer.wrap("cf2".getBytes(UTF_8)), ByteBuffer.wrap("cq2".getBytes(UTF_8))); update.setValue(ByteBuffer.wrap("value2".getBytes(UTF_8))); updates.put(ByteBuffer.wrap("row2".getBytes(UTF_8)), Collections.<ColumnUpdate>singletonList(update)); client.update(writer, updates); // Flush and close the writer client.flush(writer); client.closeWriter(writer); // Open a scanner to the table String scanner = client.createScanner(login, table, new ScanOptions()); ScanResult results = client.nextK(scanner, 10); assertEquals(2, results.getResults().size()); // Check the first key-value KeyValue kv = results.getResults().get(0); Key k = kv.key; ByteBuffer v = kv.value; assertEquals(ByteBuffer.wrap("row1".getBytes(UTF_8)), k.row); assertEquals(ByteBuffer.wrap("cf1".getBytes(UTF_8)), k.colFamily); assertEquals(ByteBuffer.wrap("cq1".getBytes(UTF_8)), k.colQualifier); assertEquals(ByteBuffer.wrap(new byte[0]), k.colVisibility); assertEquals(ByteBuffer.wrap("value1".getBytes(UTF_8)), v); // And then the second kv = results.getResults().get(1); k = kv.key; v = kv.value; assertEquals(ByteBuffer.wrap("row2".getBytes(UTF_8)), k.row); assertEquals(ByteBuffer.wrap("cf2".getBytes(UTF_8)), k.colFamily); assertEquals(ByteBuffer.wrap("cq2".getBytes(UTF_8)), k.colQualifier); assertEquals(ByteBuffer.wrap(new byte[0]), k.colVisibility); assertEquals(ByteBuffer.wrap("value2".getBytes(UTF_8)), v); // Close the scanner client.closeScanner(scanner); ugiTransport.close(); }
From source file:org.apache.accumulo.test.functional.KerberosProxyIT.java
License:Apache License
@Test public void testDisallowedClientForImpersonation() throws Exception { String user = testName.getMethodName(); File keytab = new File(kdc.getKeytabDir(), user + ".keytab"); kdc.createPrincipal(keytab, user);/*w w w . ja v a 2 s. c om*/ // Login as the new user UserGroupInformation.loginUserFromKeytab(user, keytab.getAbsolutePath()); UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); log.info("Logged in as " + ugi); // Expect an AccumuloSecurityException thrown.expect(AccumuloSecurityException.class); // Error msg would look like: // // org.apache.accumulo.core.client.AccumuloSecurityException: Error BAD_CREDENTIALS for user Principal in credentials object should match kerberos // principal. // Expected 'proxy/hw10447.local@EXAMPLE.COM' but was 'testDisallowedClientForImpersonation@EXAMPLE.COM' - Username or Password is Invalid) thrown.expect(new ThriftExceptionMatchesPattern(".*Error BAD_CREDENTIALS.*")); thrown.expect(new ThriftExceptionMatchesPattern( ".*Expected '" + proxyPrincipal + "' but was '" + kdc.qualifyUser(user) + "'.*")); TSocket socket = new TSocket(hostname, proxyPort); log.info("Connecting to proxy with server primary '" + proxyPrimary + "' running on " + hostname); // Should fail to open the tran TSaslClientTransport transport = new TSaslClientTransport("GSSAPI", null, proxyPrimary, hostname, Collections.singletonMap("javax.security.sasl.qop", "auth"), null, socket); final UGIAssumingTransport ugiTransport = new UGIAssumingTransport(transport, ugi); // UGI transport will perform the doAs for us ugiTransport.open(); AccumuloProxy.Client.Factory factory = new AccumuloProxy.Client.Factory(); Client client = factory.getClient(new TCompactProtocol(ugiTransport), new TCompactProtocol(ugiTransport)); // Will fail because the proxy can't impersonate this user (per the site configuration) try { client.login(kdc.qualifyUser(user), Collections.<String, String>emptyMap()); } finally { if (null != ugiTransport) { ugiTransport.close(); } } }
From source file:org.apache.accumulo.test.functional.KerberosProxyIT.java
License:Apache License
@Test public void testMismatchPrincipals() throws Exception { ClusterUser rootUser = kdc.getRootUser(); // Should get an AccumuloSecurityException and the given message thrown.expect(AccumuloSecurityException.class); thrown.expect(new ThriftExceptionMatchesPattern(ProxyServer.RPC_ACCUMULO_PRINCIPAL_MISMATCH_MSG)); // Make a new user String user = testName.getMethodName(); File keytab = new File(kdc.getKeytabDir(), user + ".keytab"); kdc.createPrincipal(keytab, user);// w ww .j a v a 2s . c om // Login as the new user UserGroupInformation.loginUserFromKeytab(user, keytab.getAbsolutePath()); UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); log.info("Logged in as " + ugi); TSocket socket = new TSocket(hostname, proxyPort); log.info("Connecting to proxy with server primary '" + proxyPrimary + "' running on " + hostname); // Should fail to open the tran TSaslClientTransport transport = new TSaslClientTransport("GSSAPI", null, proxyPrimary, hostname, Collections.singletonMap("javax.security.sasl.qop", "auth"), null, socket); final UGIAssumingTransport ugiTransport = new UGIAssumingTransport(transport, ugi); // UGI transport will perform the doAs for us ugiTransport.open(); AccumuloProxy.Client.Factory factory = new AccumuloProxy.Client.Factory(); Client client = factory.getClient(new TCompactProtocol(ugiTransport), new TCompactProtocol(ugiTransport)); // The proxy needs to recognize that the requested principal isn't the same as the SASL principal and fail // Accumulo should let this through -- we need to rely on the proxy to dump me before talking to accumulo try { client.login(rootUser.getPrincipal(), Collections.<String, String>emptyMap()); } finally { if (null != ugiTransport) { ugiTransport.close(); } } }
From source file:org.apache.carbondata.core.reader.ThriftReader.java
License:Apache License
/** * Opens the fileName for reading.//from w w w . j ava2s. co m */ public void open() throws IOException { FileFactory.FileType fileType = FileFactory.getFileType(fileName); dataInputStream = FileFactory.getDataInputStream(fileName, fileType, bufferSize); binaryIn = new TCompactProtocol(new TIOStreamTransport(dataInputStream)); }
From source file:org.apache.carbondata.core.util.CarbonUtil.java
License:Apache License
/** * Below method will be used to convert the thrift object to byte array. *//*from w w w . j a va 2 s .c o m*/ public static byte[] getByteArray(TBase t) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); byte[] thriftByteArray = null; TProtocol binaryOut = new TCompactProtocol(new TIOStreamTransport(stream)); try { t.write(binaryOut); stream.flush(); thriftByteArray = stream.toByteArray(); } catch (TException | IOException e) { closeStreams(stream); } finally { closeStreams(stream); } return thriftByteArray; }
From source file:org.apache.carbondata.core.util.CarbonUtil.java
License:Apache License
/** * Below method will be used to convert the byte array value to thrift object for * data chunk/* w w w .j a va 2s .c o m*/ * * @param data thrift byte array * @param creator type of thrift * @return thrift object * @throws IOException any problem while converting the object */ private static TBase read(byte[] data, TBaseCreator creator, int offset, int length) throws IOException { ByteArrayInputStream stream = new ByteArrayInputStream(data, offset, length); TProtocol binaryIn = new TCompactProtocol(new TIOStreamTransport(stream)); TBase t = creator.create(); try { t.read(binaryIn); } catch (TException e) { throw new IOException(e); } finally { CarbonUtil.closeStreams(stream); } return t; }