从C#连接到Accumulo [英] Connecting from C# to Accumulo

查看:283
本文介绍了从C#连接到Accumulo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来与Accumulo工作。我需要通过C#读取远程Accumulo /写数据。
对C#的唯一代码示例/文档,我发现是 -
Accumulo createBatchScanner范围内未正常工作



我试图编译Xamarin Studio中的代码,在Mac上。结果
口我遇到的问题是这一行:

  AccumuloProxy.Client客户端=新AccumuloProxy.Client(协议); 




错误CS0246:类型或命名空间名称 AccumuloProxy'不能被发现。是否缺少 org.apache.accumulo.proxy.thrift使用指令? (CS0246)(AccumuloIntegratorPrototype)




我在哪里可以找到要添加到我的相关AccumuloProxy客户CSHARP项目的DLL?
是有办法,我可以产生相同的



下面是一个代码片段:

 命名空间AccumuloIntegratorPrototype 
{
类MainClass
{
静态的byte [] GetBytes会(字符串str)
{
返回Encoding.ASCII.GetBytes(STR);
}

静态字符串的GetString(字节[]字节)
{
返回Encoding.ASCII.GetString(字节);
}

公共静态无效的主要(字串[] args)
{

{
/ ** **连接/
TTransport运输=新TSocket(xxx.xx.x.xx,42424);
运输=新TFramedTransport(运输);
TCompactProtocol协议=新TCompactProtocol(运输);
transport.Open();

AccumuloProxy.Client客户端=新AccumuloProxy.Client(协议);


解决方案

感谢所有的指针。

为能够完成我的项目。

这些都是我的笔记。



一个。版本:

Accumulo 1.5

节俭0.90

单3.2.5



乙。策略/选项用于从C#连接到Accumulo:

Accumulo代理API



℃。 Accumulo代理用C#绑定:

用运行Accumulo

1.安装单3.2.5

2.安装一个节点上执行以下操作节俭0.90

3.配置的Accumulo代理服务

修改文件$ ACCUMULO_HOME /代理/ proxy.properties;

具体更新了实例名,动物园管理员< BR>
4.启动代理daemon-

  $ {} ACCUMULO_HOME /斌/ accumulo代理 - p $ {} ACCUMULO_HOME /proxy/proxy.properties 

5.Generated C#绑定,使用代理.thrift IDL文件

 节俭--gen CSHARP $ ACCUMULO_HOME /代理/节俭/ proxy.thrift 

这导致在$ {} ACCUMULO_HOME /代理/节俭/
创建一个名为发电机CSHARP目录
6.需要根据发电机的CSHARP文件在C#项目,在D节,下文。

7. Thrift.dll,也是必要的。



ð。 C#项目 - Accumulo客户:

1.在步骤C5创建的类型库的项目

2.添加的文件下发电机CSHARP,上述图书馆。

3.添加引用thrift.dll

4.内置库



电子。 thrift.dll

2 - 从C#


在C#项目,读取/写入Accumulo,

1.添加引用连接到Accumulo 。新增参考建在D节图书馆,上述

3.在Accumulo服务器,开始代理(参见步骤C4,以上)



下面是一些示例代码,读取数据,来尝试这个功能了..

 使用系统; 
使用System.Text;
使用System.Collections.Generic;

使用Thrift.Protocol;
使用Thrift.Transport;


命名空间AccumuloIntegratorPrototype
{
类MainClass
{
静态的byte [] GetBytes会(字符串str)
{
返回Encoding.ASCII.GetBytes(STR);
}


静态字符串的GetString(字节[]字节)
{
返回Encoding.ASCII.GetString(字节);
}

公共静态无效的主要(字串[] args)
{


{
字符串accumuloProxyServerIP = xxx.xxx.x.xx; // IP
INT accumuloProxyServerPort = 42424; //端口号

TTransport运输=新TSocket(accumuloProxyServerIP,accumuloProxyServerPort);
运输=新TFramedTransport(运输);
TCompactProtocol协议=新TCompactProtocol(运输);
transport.Open();

字符串本金=根; //应用程序ID
&字典LT;字符串,字符串> passwd文件=新词典<字符串,字符串>();
passwd.Add(密码,XXXXX); //密码

AccumuloProxy.Client客户端=新AccumuloProxy.Client(协议);
字节[] = loginToken client.login(本金,passwd文件); //登录令牌


// {{
//读取行的范围从Accumulo
变种bScanner =新BatchScanOptions();
范围的范围=新范围();

range.Start =新的密钥();
range.Start.Row = GetBytes会(D001);

//极品\0只有当你需要获得一个单行回
//否则,它并不需要
range.Stop =新的密钥();
range.Stop.Row = GetBytes会(d001\0);

bScanner.Ranges =新的List<范围和GT;();
bScanner.Ranges.Add(范围);

字符串scanId = client.createBatchScanner(loginToken,部门,bScanner);


VAR更多= TRUE;
,而(更多)
{
变种扫描= client.nextK(scanId,10);
更= scan.More;

的foreach(在scan.Results VAR的条目)
{
Console.WriteLine(行=+的GetString(entry.Key.Row));
Console.WriteLine({0} {1} {2} [{3}] {4} {5}的GetString(entry.Key.Row)的GetString(entry.Key.ColFamily) GetString的(entry.Key.ColQualifier)的GetString(entry.Key.ColVisibility)的GetString(entry.Value),(长)entry.Key.Timestamp);
}
}

client.closeScanner(scanId);

client.Dispose();
transport.Close();

}赶上(例外五)
{
Console.WriteLine(E);
}
//}}



}
}
}


I am new to working with Accumulo. I need to read/write data from a remote Accumulo through C#. The only code sample/documentation for C#, I have found is - Accumulo createBatchScanner range not working as expected

I attempted to compile the code in Xamarin Studio, on a Mac.
The issue I am encountering is with this line:

AccumuloProxy.Client client = new AccumuloProxy.Client(protocol);

Error CS0246: The type or namespace name AccumuloProxy' could not be found. Are you missingorg.apache.accumulo.proxy.thrift' using directive? (CS0246) (AccumuloIntegratorPrototype)

Where can I find the DLLs to add to my CSharp project related to AccumuloProxy client? Is there a way I can generate the same?

Here is a code fragment:

namespace AccumuloIntegratorPrototype
{
    class MainClass
    {
        static byte[] GetBytes(string str)
        {
            return Encoding.ASCII.GetBytes(str);
        }

        static string GetString(byte[] bytes)
        {
            return Encoding.ASCII.GetString(bytes);
        }

        public static void Main (string[] args)
        {
            try
            {
                /** connect **/
                TTransport transport = new TSocket("xxx.xx.x.xx", 42424);
                transport = new TFramedTransport(transport);
                TCompactProtocol protocol = new TCompactProtocol(transport);
                transport.Open();

                AccumuloProxy.Client client = new AccumuloProxy.Client(protocol);

解决方案

Thanks to all for the pointers.
Was able to complete my project.
These are my notes.

A. Versions:
Accumulo 1.5
Thrift 0.90
Mono 3.2.5

B. Strategy/option used to connect to Accumulo from C#:
Accumulo Proxy API

C. Accumulo Proxy with C# bindings:
Performed the following actions on a node running Accumulo
1. Installed Mono 3.2.5
2. Installed Thrift 0.90
3. Configured Accumulo proxy service
Modified the file $ACCUMULO_HOME/proxy/proxy.properties;
Specifically updated the instance name, and zookeeper
4. Started the proxy daemon-

${ACCUMULO_HOME}/bin/accumulo proxy -p ${ACCUMULO_HOME}/proxy/proxy.properties

5.Generated the c# bindings, using the proxy.thrift IDL file

thrift --gen csharp $ACCUMULO_HOME/proxy/thrift/proxy.thrift

This resulted in the creation of a directory called gen-csharp under ${ACCUMULO_HOME}/proxy/thrift/
6. The files under gen-csharp are needed in the C# project, in section D, below.
7. Thrift.dll, is also needed.

D. C# project - Accumulo Client:
1. Created a project of type library.
2. Added the files under gen-csharp in step C5, above to the library
3. Added reference to thrift.dll
4. Built the library

E. Connecting to Accumulo from C#
In the C# project that reads/writes to Accumulo,
1. Added reference - thrift.dll
2. Added reference to the library built in section D, above
3. On the Accumulo server, started the proxy (refer step C4, above)

Here is some sample code, to read data, to try this functionality out..

using System;
using System.Text;
using System.Collections.Generic;

using Thrift.Protocol;
using Thrift.Transport;


namespace AccumuloIntegratorPrototype
{
class MainClass
{
    static byte[] GetBytes(string str)
    {
        return Encoding.ASCII.GetBytes(str);
    }


    static string GetString(byte[] bytes)
    {
        return Encoding.ASCII.GetString(bytes);
    }

    public static void Main (string[] args)
    {

        try
        {
            String accumuloProxyServerIP = "xxx.xxx.x.xx";//IP
            int accumuloProxyServerPort = 42424;//Port Number

            TTransport transport = new TSocket(accumuloProxyServerIP, accumuloProxyServerPort);
            transport = new TFramedTransport(transport);
            TCompactProtocol protocol = new TCompactProtocol(transport);
            transport.Open();

            String principal = "root";//Application ID
            Dictionary<string, string> passwd = new Dictionary<string,string>();
            passwd.Add("password", "xxxxx");//Password

            AccumuloProxy.Client client = new AccumuloProxy.Client(protocol);
            byte[] loginToken = client.login(principal, passwd);//Login token


            //{{
            //Read a range of rows from Accumulo
            var bScanner = new BatchScanOptions();
            Range range = new Range();

            range.Start = new Key();
            range.Start.Row = GetBytes("d001");

            //Need the \0 only if you need to get a single row back
            //Otherwise, its not needed
            range.Stop = new Key();
            range.Stop.Row = GetBytes("d001\0");

            bScanner.Ranges = new List<Range>();
            bScanner.Ranges.Add(range);

            String scanId = client.createBatchScanner(loginToken, "departments", bScanner);


            var more = true;
            while (more)
            {
                var scan = client.nextK(scanId, 10);
                more = scan.More;

                foreach (var entry in scan.Results)
                {
                    Console.WriteLine("Row = " + GetString(entry.Key.Row));
                    Console.WriteLine("{0} {1}:{2} [{3}]  {4}    {5}", GetString(entry.Key.Row), GetString(entry.Key.ColFamily), GetString(entry.Key.ColQualifier), GetString(entry.Key.ColVisibility), GetString(entry.Value),(long)entry.Key.Timestamp);
                }
            }

            client.closeScanner(scanId);

            client.Dispose();
            transport.Close();

            }catch (Exception e)
            {
                Console.WriteLine(e);
            }
        //}}



    }
}
}

这篇关于从C#连接到Accumulo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆