Commit 8b5f03ab authored by Axel Auweter's avatar Axel Auweter
Browse files

Initial import of CollectAgent (Makefile, Source, Eclipse settings).

Currently, this is only a proof of concept for using the Thrift API
provided by Cassandra a bit from C++. Let's hope to evolve this into
what we're aiming for, soon.
parent fc21ed3a
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?>
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.toolchain.gnu.macosx.base.182916731">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.macosx.base.182916731" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.macosx.base.182916731" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.macosx.base.182916731.802739244" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.macosx.base.470372249" name="cdt.managedbuild.toolchain.gnu.macosx.base" superClass="cdt.managedbuild.toolchain.gnu.macosx.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64" id="cdt.managedbuild.target.gnu.platform.macosx.base.731957909" name="Debug Platform" osList="macosx" superClass="cdt.managedbuild.target.gnu.platform.macosx.base"/>
<builder id="cdt.managedbuild.target.gnu.builder.macosx.base.369631675" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.macosx.base"/>
<tool id="cdt.managedbuild.tool.macosx.c.linker.macosx.base.152321851" name="MacOS X C Linker" superClass="cdt.managedbuild.tool.macosx.c.linker.macosx.base"/>
<tool id="cdt.managedbuild.tool.macosx.cpp.linker.macosx.base.1042804634" name="MacOS X C++ Linker" superClass="cdt.managedbuild.tool.macosx.cpp.linker.macosx.base">
<inputType id="cdt.managedbuild.tool.macosx.cpp.linker.input.172459185" superClass="cdt.managedbuild.tool.macosx.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
<tool id="cdt.managedbuild.tool.gnu.assembler.macosx.base.1899440248" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.macosx.base">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1546497501" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.archiver.macosx.base.516191539" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.macosx.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.345908920" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base">
<option id="gnu.cpp.compiler.option.include.paths.596958677" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="../../../thrift/lib/cpp/src"/>
<listOptionValue builtIn="false" value="/opt/local/include"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1562330115" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1988907322" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.base">
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.660553692" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="CollectAgent.null.1626518544" name="CollectAgent"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope"/>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.182916731;cdt.managedbuild.toolchain.gnu.macosx.base.182916731.802739244;cdt.managedbuild.tool.gnu.c.compiler.macosx.base.1988907322;cdt.managedbuild.tool.gnu.c.compiler.input.660553692">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.macosx.base.182916731;cdt.managedbuild.toolchain.gnu.macosx.base.182916731.802739244;cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.345908920;cdt.managedbuild.tool.gnu.cpp.compiler.input.1562330115">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
</cproject>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CollectAgent</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="cdt.managedbuild.toolchain.gnu.macosx.base.182916731" name="Default">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(gcc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
</extension>
</configuration>
</project>
//============================================================================
// Name : CollectAgent.cpp
// Author : Axel Auweter
// Version :
// Copyright : Leibniz Supercomputing Centre
// Description : As of now this is some rudimentary bad code to talk to the DB
//============================================================================
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <thrift/Thrift.h>
#include <thrift/transport/TTransport.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/TSocket.h>
#include <thrift/protocol/TProtocol.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include "cassandra/cassandra.h"
using namespace apache::thrift;
using namespace apache::thrift::transport;
using namespace apache::thrift::protocol;
using namespace org::apache::cassandra;
int main(void) {
boost::shared_ptr<TSocket> sock;
boost::shared_ptr<TTransport> tr;
boost::shared_ptr<TProtocol> prot;
std::string clusterName;
sock = boost::shared_ptr<TSocket>(new TSocket("localhost", 9160));
tr = boost::shared_ptr<TFramedTransport>(new TFramedTransport(sock));
prot = boost::shared_ptr<TBinaryProtocol>(new TBinaryProtocol(tr));
try {
CassandraClient myClient(prot);
tr->open();
myClient.describe_cluster_name(clusterName);
printf("Cluster name: %s\n", clusterName.c_str());
printf("Keyspaces:\n");
std::vector<KsDef> keySpaces;
myClient.describe_keyspaces(keySpaces);
for (int i=0; i<keySpaces.size(); i++) {
printf(" [%d]: %s\n", i, keySpaces[i].name.c_str());
}
CqlResult res;
std::string query = "USE " + keySpaces[0].name;
printf("Sending CQL statement: %s...", query.c_str());
myClient.execute_cql3_query(res, query, Compression::NONE, ConsistencyLevel::ONE);
printf(" Done.\n");
int resB = 0;
while (resB < keySpaces[0].cf_defs.size()) {
query = "SELECT * FROM " + keySpaces[0].cf_defs[resB].name + ";";
printf("Sending CQL statement: %s...", query.c_str());
myClient.execute_cql3_query(res, query, Compression::NONE, ConsistencyLevel::ONE);
printf(" Done.\nResult:\n");
int resC = 0;
while (resC < res.rows.size()) {
int resD = 0;
while (resD < res.rows[resC].columns.size()) {
printf("%s [%lu]:", res.rows[resC].columns[resD].name.c_str(),
res.rows[resC].columns[resD].value.length());
int resE = 0;
while (resE < res.rows[resC].columns[resD].value.length()) {
printf(" %02x", res.rows[resC].columns[resD].value.c_str()[resE] & 0xff);
resE++;
}
printf("\n");
resD++;
}
resC++;
}
resB++;
}
}
catch(TTransportException te){
printf("TP Exception: %s [%d]\n", te.what(), te.getType());
}catch(InvalidRequestException ire){
printf("IRE Exception: %s [%s]\n", ire.what(), ire.why.c_str());
}catch(NotFoundException nfe){
printf("NF Exception: %s\n", nfe.what());
}
return EXIT_SUCCESS;
}
CXXFLAGS = -O0 -g -Wall -fmessage-length=0 -I../../thrift/lib/cpp/src/ -I/opt/local/include/
OBJS = CollectAgent.o cassandra/Cassandra.o cassandra/cassandra_constants.o cassandra/cassandra_types.o
LIBS = -L../../thrift/lib/cpp/.libs/ -lthrift
TARGET = CollectAgent
SUBTARGETS = cassandra-lib
$(TARGET): $(SUBTARGETS) $(OBJS)
$(CXX) -o $(TARGET) $(OBJS) $(LIBS)
all: $(TARGET)
cassandra-lib: cassandra-headers
cassandra-headers:
@if [ ! -e cassandra ]; then \
printf "Building Thrift interface headers... "; \
../../thrift/compiler/cpp/thrift --gen cpp ../../cassandra/interface/cassandra.thrift; \
mv gen-cpp cassandra; \
echo "Done."; \
fi
clean: clean-cassandra-headers
rm -f $(OBJS) $(TARGET)
clean-cassandra-headers:
rm -rf cassandra
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment