diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/Makefile | 2 | ||||
-rw-r--r-- | cpp/Makefile.mak | 2 | ||||
-rw-r--r-- | cpp/tools/Makefile | 30 | ||||
-rw-r--r-- | cpp/tools/Makefile.mak | 20 | ||||
-rw-r--r-- | cpp/tools/icegriddb/.depend.mak | 1 | ||||
-rw-r--r-- | cpp/tools/icegriddb/.gitignore | 13 | ||||
-rw-r--r-- | cpp/tools/icegriddb/DBTypes.ice | 30 | ||||
-rw-r--r-- | cpp/tools/icegriddb/IceGridDB.cpp | 383 | ||||
-rw-r--r-- | cpp/tools/icegriddb/IceGridDB.rc | 34 | ||||
-rw-r--r-- | cpp/tools/icegriddb/Makefile | 70 | ||||
-rw-r--r-- | cpp/tools/icegriddb/Makefile.mak | 86 | ||||
-rw-r--r-- | cpp/tools/icestormdb/.depend.mak | 3 | ||||
-rw-r--r-- | cpp/tools/icestormdb/.gitignore | 15 | ||||
-rw-r--r-- | cpp/tools/icestormdb/DBTypes.ice | 32 | ||||
-rw-r--r-- | cpp/tools/icestormdb/IceStormDB.cpp | 279 | ||||
-rw-r--r-- | cpp/tools/icestormdb/IceStormDB.rc | 34 | ||||
-rw-r--r-- | cpp/tools/icestormdb/Makefile | 65 | ||||
-rw-r--r-- | cpp/tools/icestormdb/Makefile.mak | 90 |
18 files changed, 1187 insertions, 2 deletions
diff --git a/cpp/Makefile b/cpp/Makefile index ec91a74ad69..eae673d0d7c 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -11,7 +11,7 @@ top_srcdir = . include $(top_srcdir)/config/Make.rules -SUBDIRS = config src include +SUBDIRS = config src tools include ifneq ($(MAKECMDGOALS),install) SUBDIRS := $(SUBDIRS) test diff --git a/cpp/Makefile.mak b/cpp/Makefile.mak index d67ea1d2c27..1f793702479 100644 --- a/cpp/Makefile.mak +++ b/cpp/Makefile.mak @@ -15,7 +15,7 @@ INSTALL_SUBDIRS = "$(install_bindir)" "$(install_libdir)" "$(install_includedir) !if "$(WINRT)" != "yes" -SUBDIRS = config src include test +SUBDIRS = config src tools include test install:: install-common @for %i in ( $(INSTALL_SUBDIRS) ) do \ diff --git a/cpp/tools/Makefile b/cpp/tools/Makefile new file mode 100644 index 00000000000..6644234afc8 --- /dev/null +++ b/cpp/tools/Makefile @@ -0,0 +1,30 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = .. + +include $(top_srcdir)/config/Make.rules + +SUBDIRS = icegriddb \ + icestormdb + +.PHONY: $(EVERYTHING) $(SUBDIRS) + +all:: $(SUBDIRS) + +$(SUBDIRS): + @echo "making all in $@" + @$(MAKE) all --directory=$@ + +$(EVERYTHING_EXCEPT_ALL):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done diff --git a/cpp/tools/Makefile.mak b/cpp/tools/Makefile.mak new file mode 100644 index 00000000000..5ad037717ad --- /dev/null +++ b/cpp/tools/Makefile.mak @@ -0,0 +1,20 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = .. + +!include $(top_srcdir)\config\Make.rules.mak + +SUBDIRS = icegriddb \ + icestormdb + +$(EVERYTHING):: + @for %i in ( $(SUBDIRS) ) do \ + @echo "making $@ in %i" && \ + cmd /c "cd %i && $(MAKE) -nologo -f Makefile.mak $@" || exit 1 diff --git a/cpp/tools/icegriddb/.depend.mak b/cpp/tools/icegriddb/.depend.mak new file mode 100644 index 00000000000..4b9f720b06c --- /dev/null +++ b/cpp/tools/icegriddb/.depend.mak @@ -0,0 +1 @@ +DBTypes.h DBTypes.cpp: DBTypes.ice "$(slicedir)/IceGrid/Admin.ice" "$(slicedir)/Ice/Identity.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(slicedir)/Ice/Properties.ice" "$(slicedir)/Ice/PropertiesAdmin.ice" "$(slicedir)/Ice/SliceChecksumDict.ice" "$(slicedir)/Glacier2/Session.ice" "$(slicedir)/Glacier2/SSLInfo.ice" "$(slicedir)/IceGrid/Exception.ice" "$(slicedir)/IceGrid/Descriptor.ice" "$(SLICE2CPP)" "$(SLICEPARSERLIB)" diff --git a/cpp/tools/icegriddb/.gitignore b/cpp/tools/icegriddb/.gitignore new file mode 100644 index 00000000000..d03b5a7c142 --- /dev/null +++ b/cpp/tools/icegriddb/.gitignore @@ -0,0 +1,13 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +DBTypes.cpp +DBTypes.h +IdentityObjectInfoDict.cpp +IdentityObjectInfoDict.h +SerialsDict.cpp +SerialsDict.h +StringAdapterInfoDict.cpp +StringAdapterInfoDict.h +StringApplicationInfoDict.cpp +StringApplicationInfoDict.h diff --git a/cpp/tools/icegriddb/DBTypes.ice b/cpp/tools/icegriddb/DBTypes.ice new file mode 100644 index 00000000000..96efb51157c --- /dev/null +++ b/cpp/tools/icegriddb/DBTypes.ice @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +#include <IceGrid/Admin.ice> + +[["cpp:header-ext:h"]] + +module IceGrid +{ + +dictionary<string, long> StringLongDict; + +struct AllData +{ + ApplicationInfoSeq applications; + AdapterInfoSeq adapters; + ObjectInfoSeq objects; + ObjectInfoSeq internalObjects; + StringLongDict serials; +}; + +}; diff --git a/cpp/tools/icegriddb/IceGridDB.cpp b/cpp/tools/icegriddb/IceGridDB.cpp new file mode 100644 index 00000000000..3e2853a27a1 --- /dev/null +++ b/cpp/tools/icegriddb/IceGridDB.cpp @@ -0,0 +1,383 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <IceUtil/DisableWarnings.h> +#include <IceUtil/Options.h> +#include <IceUtil/FileUtil.h> +#include <Ice/Application.h> +#include <Freeze/Freeze.h> +#include <Freeze/CatalogIndexList.h> +#include <IceGrid/Admin.h> +#include <IcePatch2Lib/Util.h> +#include <DBTypes.h> +#include <StringApplicationInfoDict.h> +#include <StringAdapterInfoDict.h> +#include <IdentityObjectInfoDict.h> +#include <SerialsDict.h> + +using namespace std; +using namespace Ice; +using namespace IceGrid; + +class Client : public Application +{ +public: + + void usage(); + virtual int run(int, char*[]); +}; + +#ifdef _WIN32 + +int +wmain(int argc, wchar_t* argv[]) + +#else + +int +main(int argc, char* argv[]) + +#endif +{ + Client app; + return app.main(argc, argv); +} + +void +Client::usage() +{ + cerr << "Usage: " << appName() << " <options>\n"; + cerr << + "Options:\n" + "-h, --help Show this message.\n" + "-v, --version Display version.\n" + "--import FILE Import database from FILE.\n" + "--export FILE Export database to FILE.\n" + "--dbhome DIR The database directory.\n" + "-d, --debug Print debug messages." + ; +} + +int +Client::run(int argc, char* argv[]) +{ + IceUtilInternal::Options opts; + opts.addOpt("h", "help"); + opts.addOpt("v", "version"); + opts.addOpt("d", "debug"); + opts.addOpt("", "import", IceUtilInternal::Options::NeedArg); + opts.addOpt("", "export", IceUtilInternal::Options::NeedArg); + opts.addOpt("", "dbhome", IceUtilInternal::Options::NeedArg); + + vector<string> args; + try + { + args = opts.parse(argc, const_cast<const char**>(argv)); + } + catch(const IceUtilInternal::BadOptException& e) + { + cerr << e.reason << endl; + usage(); + return EXIT_FAILURE; + } + if(!args.empty()) + { + cerr << argv[0] << ": too many arguments" << endl; + usage(); + return EXIT_FAILURE; + } + + if(opts.isSet("help")) + { + usage(); + return EXIT_SUCCESS; + } + + if(opts.isSet("version")) + { + cout << ICE_STRING_VERSION << endl; + return EXIT_SUCCESS; + } + + if((!opts.isSet("import") && !opts.isSet("export")) || (opts.isSet("import") && opts.isSet("export"))) + { + cerr << "Either --import or --export must be set" << endl; + usage(); + return EXIT_FAILURE; + } + + if(!opts.isSet("dbhome")) + { + cerr << "Database path must be specified" << endl; + usage(); + return EXIT_FAILURE; + } + + bool debug = opts.isSet("debug"); + bool import = opts.isSet("import"); + string dbFile = opts.optArg(import ? "import" : "export"); + string dbPath = opts.optArg("dbhome"); + + try + { + IceGrid::AllData data; + + EncodingVersion encoding = { 1, 1 }; + communicator()->getProperties()->setProperty("Freeze.DbEnv.Registry.DbHome", dbPath); + + if(import) + { + cout << "Importing database to directory `" << dbPath << "' from file `" << dbFile << "'" << endl; + + if(!IceUtilInternal::directoryExists(dbPath)) + { + cerr << "Output directory does not exist: " << dbPath << endl; + return EXIT_FAILURE; + } + + StringSeq files = IcePatch2Internal::readDirectory(dbPath); + if(!files.empty()) + { + cerr << "Output directory is not empty: " << dbPath << endl; + return EXIT_FAILURE; + } + + ifstream fs(dbFile, ios::binary); + if(fs.fail()) + { + cerr << "Could not open input file: " << strerror(errno) << endl; + return EXIT_FAILURE; + } + fs.unsetf(ios::skipws); + + fs.seekg(0, ios::end); + streampos fileSize = fs.tellg(); + fs.seekg(0, ios::beg); + + vector<Ice::Byte> buf; + buf.reserve(static_cast<size_t>(fileSize)); + buf.insert(buf.begin(), istream_iterator<Ice::Byte>(fs), istream_iterator<Ice::Byte>()); + + fs.close(); + + string type; + int version; + + Ice::InputStreamPtr stream = Ice::wrapInputStream(communicator(), buf, encoding); + stream->read(type); + if(type != "IceGrid") + { + cerr << "Incorrect input file type: " << type << endl; + return EXIT_FAILURE; + } + stream->read(version); + stream->read(data); + + { + Freeze::ConnectionPtr connection = Freeze::createConnection(communicator(), "Registry"); + Freeze::TransactionHolder txn(connection); + + if(debug) + { + cout << "Writing Applications Map:" << endl; + } + + StringApplicationInfoDict applications(connection, "applications"); + for(ApplicationInfoSeq::const_iterator p = data.applications.begin(); + p != data.applications.end(); + ++p) + { + if(debug) + { + cout << " NAME = " << p->descriptor.name << endl; + } + applications.put(StringApplicationInfoDict::value_type(p->descriptor.name, *p)); + } + + + if(debug) + { + cout << "Writing Adapters Map:" << endl; + } + + StringAdapterInfoDict adapters(connection, "adapters"); + for(AdapterInfoSeq::const_iterator p = data.adapters.begin(); p != data.adapters.end(); ++p) + { + if(debug) + { + cout << " NAME = " << p->id << endl; + } + adapters.put(StringAdapterInfoDict::value_type(p->id, *p)); + } + + if(debug) + { + cout << "Writing Objects Map:" << endl; + } + + IdentityObjectInfoDict objects(connection, "objects"); + for(ObjectInfoSeq::const_iterator p = data.objects.begin(); p != data.objects.end(); ++p) + { + if(debug) + { + cout << " NAME = " << communicator()->identityToString(p->proxy->ice_getIdentity()) << endl; + } + objects.put(IdentityObjectInfoDict::value_type(p->proxy->ice_getIdentity(), *p)); + } + + if(debug) + { + cout << "Writing Internal Objects Map:" << endl; + } + + IdentityObjectInfoDict internalObjects(connection, "internal-objects"); + for(ObjectInfoSeq::const_iterator p = data.internalObjects.begin(); + p != data.internalObjects.end(); + ++p) + { + if(debug) + { + cout << " NAME = " << communicator()->identityToString(p->proxy->ice_getIdentity()) << endl; + } + internalObjects.put(IdentityObjectInfoDict::value_type(p->proxy->ice_getIdentity(), *p)); + } + + if(debug) + { + cout << "Writing Serials Map:" << endl; + } + + SerialsDict serials(connection, "serials"); + for(StringLongDict::const_iterator p = data.serials.begin(); p != data.serials.end(); ++p) + { + if(debug) + { + cout << " NAME = " << p->first << endl; + } + serials.put(SerialsDict::value_type(p->first, p->second)); + } + + txn.commit(); + } + } + else + { + cout << "Exporting database from directory `" << dbPath << "' to file `" << dbFile << "'" << endl; + + { + Freeze::ConnectionPtr connection = Freeze::createConnection(communicator(), "Registry"); + Freeze::TransactionHolder txn(connection); + + if(debug) + { + cout << "Reading Application Map:" << endl; + } + + IceGrid::StringApplicationInfoDict applications(connection, "applications"); + for(IceGrid::StringApplicationInfoDict::const_iterator p = applications.begin(); + p != applications.end(); + ++p) + { + if(debug) + { + cout << " APPLICATION = " << p->first << endl; + } + data.applications.push_back(p->second); + } + + if(debug) + { + cout << "Reading Adapter Map:" << endl; + } + + StringAdapterInfoDict adapters(connection, "adapters"); + for(StringAdapterInfoDict::const_iterator p = adapters.begin(); p != adapters.end(); ++p) + { + if(debug) + { + cout << " ADAPTER = " << p->first << endl; + } + data.adapters.push_back(p->second); + } + + + if(debug) + { + cout << "Reading Object Map:" << endl; + } + + IdentityObjectInfoDict objects(connection, "objects"); + for(IdentityObjectInfoDict::const_iterator p = objects.begin(); p != objects.end(); ++p) + { + if(debug) + { + cout << " IDENTITY = " << communicator()->identityToString(p->first) << endl; + } + data.objects.push_back(p->second); + } + + if(debug) + { + cout << "Reading Internal Object Map:" << endl; + } + + IdentityObjectInfoDict internalObjects(connection, "internal-objects"); + for(IdentityObjectInfoDict::const_iterator p = internalObjects.begin(); + p != internalObjects.end(); + ++p) + { + if(debug) + { + cout << " IDENTITY = " << communicator()->identityToString(p->first) << endl; + } + data.internalObjects.push_back(p->second); + } + + if(debug) + { + cout << "Reading Serials Map:" << endl; + } + + SerialsDict serials(connection, "serials"); + for(SerialsDict::const_iterator p = serials.begin(); p != serials.end(); ++p) + { + if(debug) + { + cout << " NAME = " << p->first << endl; + } + data.serials.insert(std::make_pair(p->first, p->second)); + } + + txn.rollback(); + } + + Ice::OutputStreamPtr stream = Ice::createOutputStream(communicator(), encoding); + stream->write("IceGrid"); + stream->write(ICE_INT_VERSION); + stream->write(data); + pair<const Ice::Byte*, const Ice::Byte*> buf = stream->finished(); + + ofstream fs(dbFile, ios::binary); + if(fs.fail()) + { + cerr << "Could not open output file: " << strerror(errno) << endl; + return EXIT_FAILURE; + } + fs.write(reinterpret_cast<const char*>(buf.first), buf.second - buf.first); + fs.close(); + } + } + catch(const IceUtil::Exception& ex) + { + cerr << (import ? "Import" : "Export") << " failed:\n" << ex << endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/cpp/tools/icegriddb/IceGridDB.rc b/cpp/tools/icegriddb/IceGridDB.rc new file mode 100644 index 00000000000..7fee21a08bc --- /dev/null +++ b/cpp/tools/icegriddb/IceGridDB.rc @@ -0,0 +1,34 @@ +#include "winver.h" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 3,6,1,0 + PRODUCTVERSION 3,6,1,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "ZeroC, Inc.\0" + VALUE "FileDescription", "IceGridDB\0" + VALUE "FileVersion", "3.6.1\0" + VALUE "InternalName", "icegriddb\0" + VALUE "LegalCopyright", "Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.\0" + VALUE "OriginalFilename", "icegridadmin.exe\0" + VALUE "ProductName", "Ice\0" + VALUE "ProductVersion", "3.6.1\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END diff --git a/cpp/tools/icegriddb/Makefile b/cpp/tools/icegriddb/Makefile new file mode 100644 index 00000000000..e7ddbf72681 --- /dev/null +++ b/cpp/tools/icegriddb/Makefile @@ -0,0 +1,70 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../.. + +ICEGRIDDB = $(bindir)/icegriddb36 + +TARGETS = $(ICEGRIDDB) + +SLICE_OBJS = DBTypes.o + +OBJS = IceGridDB.o \ + StringApplicationInfoDict.o \ + IdentityObjectInfoDict.o \ + StringAdapterInfoDict.o \ + SerialsDict.o \ + $(SLICE_OBJS) + +SLICE2FREEZECMD = $(SLICE2FREEZE) --ice $(ICECPPFLAGS) + +SDIR = $(slicedir)/IceGrid + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../../include -I../../src $(CPPFLAGS) +SLICE2CPPFLAGS := --ice -I. $(SLICE2CPPFLAGS) +LIBS := -lIceGrid -lIcePatch2 -lGlacier2 -lFreeze $(LIBS) + +$(ICEGRIDDB): $(OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +StringApplicationInfoDict.h: StringApplicationInfoDict.cpp +StringApplicationInfoDict.cpp: $(SDIR)/Admin.ice $(SLICE2FREEZE) $(SLICEPARSERLIB) + rm -f StringApplicationInfoDict.h StringApplicationInfoDict.cpp + $(SLICE2FREEZECMD) --dict IceGrid::StringApplicationInfoDict,string,IceGrid::ApplicationInfo \ + StringApplicationInfoDict $(SDIR)/Admin.ice + +IdentityObjectInfoDict.h: IdentityObjectInfoDict.cpp +IdentityObjectInfoDict.cpp: $(slicedir)/Ice/Identity.ice $(SDIR)/Admin.ice $(SLICE2FREEZE) $(SLICEPARSERLIB) + rm -f IdentityObjectInfoDict.h IdentityObjectInfoDict.cpp + $(SLICE2FREEZECMD) --dict IceGrid::IdentityObjectInfoDict,Ice::Identity,IceGrid::ObjectInfo \ + --dict-index IceGrid::IdentityObjectInfoDict,type \ + IdentityObjectInfoDict $(slicedir)/Ice/Identity.ice $(SDIR)/Admin.ice + +StringAdapterInfoDict.h: StringAdapterInfoDict.cpp +StringAdapterInfoDict.cpp: $(SDIR)/Admin.ice $(SLICE2FREEZE) $(SLICEPARSERLIB) + rm -f StringAdapterInfoDict.h StringAdapterInfoDict.cpp + $(SLICE2FREEZECMD) --dict IceGrid::StringAdapterInfoDict,string,IceGrid::AdapterInfo \ + --dict-index IceGrid::StringAdapterInfoDict,replicaGroupId StringAdapterInfoDict $(SDIR)/Admin.ice + +SerialsDict.h: SerialsDict.cpp +SerialsDict.cpp: $(SLICE2FREEZE) $(SLICEPARSERLIB) + rm -f SerialsDict.h SerialsDict.cpp + $(SLICE2FREEZECMD) --dict IceGrid::SerialsDict,string,long SerialsDict + +clean:: + -rm -f StringApplicationInfoDict.h StringApplicationInfoDict.cpp + -rm -f IdentityObjectInfoDict.h IdentityObjectInfoDict.cpp + -rm -f StringAdapterInfoDict.h StringAdapterInfoDict.cpp + -rm -f SerialsDict.h SerialsDict.cpp + +install:: all + $(call installprogram,$(ICEGRIDDB),$(DESTDIR)$(install_bindir)) diff --git a/cpp/tools/icegriddb/Makefile.mak b/cpp/tools/icegriddb/Makefile.mak new file mode 100644 index 00000000000..de42ed32901 --- /dev/null +++ b/cpp/tools/icegriddb/Makefile.mak @@ -0,0 +1,86 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ..\.. + +ICEGRIDDB = $(top_srcdir)\bin\icegriddb35.exe + +TARGETS = $(ICEGRIDDB) + +SLICE_OBJS = DBTypes.obj + +OBJS = IceGridDB.obj \ + StringApplicationInfoDict.obj \ + IdentityObjectInfoDict.obj \ + StringAdapterInfoDict.obj \ + SerialsDict.obj \ + $(SLICE_OBJS) + +SRCS = $(OBJS:.obj=.cpp) + +SDIR = $(slicedir)\IceGrid + +SLICE2FREEZECMD = "$(SLICE2FREEZE)" --ice $(ICECPPFLAGS) + +!include $(top_srcdir)\config\Make.rules.mak + +CPPFLAGS = -I. -I..\..\src $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN +SLICE2CPPFLAGS = --ice $(SLICE2CPPFLAGS) +LINKWITH = $(LIBS) icegrid$(LIBSUFFIX).lib freeze$(LIBSUFFIX).lib glacier2$(LIBSUFFIX).lib icepatch2$(LIBSUFFIX).lib + +!if "$(GENERATE_PDB)" == "yes" +PDBFLAGS = /pdb:$(ICEGRIDDB:.exe=.pdb) +!endif + +RES_FILE = IceGridDB.res + +$(ICEGRIDDB): $(OBJS) IceGridDB.res + $(LINK) $(LD_EXEFLAGS) $(PDBFLAGS) $(OBJS) $(SETARGV) $(PREOUT)$@ $(PRELIBS)$(LINKWITH) $(RES_FILE) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) &&\ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + +StringApplicationInfoDict.h StringApplicationInfoDict.cpp: "$(SDIR)\Admin.ice" "$(SLICE2FREEZE)" "$(SLICEPARSERLIB)" + del /q StringApplicationInfoDict.h StringApplicationInfoDict.cpp + $(SLICE2FREEZECMD) --dict IceGrid::StringApplicationInfoDict,string,IceGrid::ApplicationInfo \ + StringApplicationInfoDict "$(SDIR)\Admin.ice" + +IdentityObjectInfoDict.h IdentityObjectInfoDict.cpp: "$(slicedir)\Ice\Identity.ice" "$(SDIR)\Admin.ice" "$(SLICE2FREEZE)" "$(SLICEPARSERLIB)" + del /q IdentityObjectInfoDict.h IdentityObjectInfoDict.cpp + $(SLICE2FREEZECMD) --dict IceGrid::IdentityObjectInfoDict,Ice::Identity,IceGrid::ObjectInfo \ + --dict-index IceGrid::IdentityObjectInfoDict,type \ + IdentityObjectInfoDict "$(slicedir)\Ice\Identity.ice" "$(SDIR)\Admin.ice" + +StringAdapterInfoDict.h StringAdapterInfoDict.cpp: "$(SDIR)\Admin.ice" "$(SLICE2FREEZE)" "$(SLICEPARSERLIB)" + del /q StringAdapterInfoDict.h StringAdapterInfoDict.cpp + $(SLICE2FREEZECMD) --dict IceGrid::StringAdapterInfoDict,string,IceGrid::AdapterInfo \ + --dict-index IceGrid::StringAdapterInfoDict,replicaGroupId StringAdapterInfoDict "$(SDIR)\Admin.ice" + +SerialsDict.h SerialsDict.cpp: "$(SLICE2FREEZE)" "$(SLICEPARSERLIB)" + del /q SerialsDict.h SerialsDict.cpp + $(SLICE2FREEZECMD) --dict IceGrid::SerialsDict,string,long SerialsDict + +clean:: + -del /q $(ICEGRIDDB:.exe=.*) + -del /q IceGridDB.res + -del /q DBTypes.h DBTypes.cpp + -del /q StringApplicationInfoDict.h StringApplicationInfoDict.cpp + -del /q StringAdapterInfoDict.h StringAdapterInfoDict.cpp + -del /q IdentityObjectInfoDict.h IdentityObjectInfoDict.cpp + -del /q SerialsDict.h SerialsDict.cpp + +install:: all + copy $(ICEGRIDDB) "$(install_bindir)" + + +!if "$(GENERATE_PDB)" == "yes" + +install:: all + copy $(ICEGRIDDB:.exe=.pdb) "$(install_bindir)" + +!endif diff --git a/cpp/tools/icestormdb/.depend.mak b/cpp/tools/icestormdb/.depend.mak new file mode 100644 index 00000000000..f3bdfe458a9 --- /dev/null +++ b/cpp/tools/icestormdb/.depend.mak @@ -0,0 +1,3 @@ +DBTypes.h DBTypes.cpp: DBTypes.ice ./SubscriberRecord.ice "$(slicedir)/Ice/Identity.ice" "$(slicedir)/IceStorm/IceStorm.ice" "$(slicedir)/Ice/SliceChecksumDict.ice" "$(slicedir)/IceStorm/Metrics.ice" "$(slicedir)/Ice/Metrics.ice" "$(slicedir)/Ice/BuiltinSequences.ice" ./LLURecord.ice "$(SLICE2CPP)" "$(SLICEPARSERLIB)" +LLURecord.h LLURecord.cpp: LLURecord.ice "$(SLICE2CPP)" "$(SLICEPARSERLIB)" +SubscriberRecord.h SubscriberRecord.cpp: SubscriberRecord.ice "$(slicedir)/Ice/Identity.ice" "$(slicedir)/IceStorm/IceStorm.ice" "$(slicedir)/Ice/SliceChecksumDict.ice" "$(slicedir)/IceStorm/Metrics.ice" "$(slicedir)/Ice/Metrics.ice" "$(slicedir)/Ice/BuiltinSequences.ice" "$(SLICE2CPP)" "$(SLICEPARSERLIB)" diff --git a/cpp/tools/icestormdb/.gitignore b/cpp/tools/icestormdb/.gitignore new file mode 100644 index 00000000000..392425e96f1 --- /dev/null +++ b/cpp/tools/icestormdb/.gitignore @@ -0,0 +1,15 @@ +// Generated by makegitignore.py + +// IMPORTANT: Do not edit this file -- any edits made here will be lost! +DBTypes.h +DBTypes.cpp +LLUMap.cpp +LLUMap.h +LLURecord.cpp +LLURecord.h +LLURecord.ice +SubscriberMap.cpp +SubscriberMap.h +SubscriberRecord.cpp +SubscriberRecord.h +SubscriberRecord.ice diff --git a/cpp/tools/icestormdb/DBTypes.ice b/cpp/tools/icestormdb/DBTypes.ice new file mode 100644 index 00000000000..ca4c9acf1bc --- /dev/null +++ b/cpp/tools/icestormdb/DBTypes.ice @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#pragma once + +[["cpp:header-ext:h"]] + +#include <SubscriberRecord.ice> +#include <LLURecord.ice> + +module IceStormElection +{ +dictionary<string, LogUpdate> StringLogUpdateDict; +}; + +module IceStorm +{ +dictionary<SubscriberRecordKey, SubscriberRecord> SubscriberRecordDict; + +struct AllData +{ + IceStormElection::StringLogUpdateDict llus; + IceStorm::SubscriberRecordDict subscribers; +}; + +}; diff --git a/cpp/tools/icestormdb/IceStormDB.cpp b/cpp/tools/icestormdb/IceStormDB.cpp new file mode 100644 index 00000000000..e60f0a6efb1 --- /dev/null +++ b/cpp/tools/icestormdb/IceStormDB.cpp @@ -0,0 +1,279 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <IceUtil/DisableWarnings.h> +#include <IceUtil/Options.h> +#include <IceUtil/FileUtil.h> +#include <Ice/Application.h> +#include <Freeze/Freeze.h> +#include <IcePatch2Lib/Util.h> +#include <DBTypes.h> +#include <LLUMap.h> +#include <SubscriberMap.h> + +using namespace std; +using namespace Ice; +using namespace IceStorm; +using namespace IceStormElection; + +class Client : public Application +{ +public: + + void usage(); + virtual int run(int, char*[]); +}; + +#ifdef _WIN32 + +int +wmain(int argc, wchar_t* argv[]) + +#else + +int +main(int argc, char* argv[]) + +#endif +{ + Client app; + return app.main(argc, argv); +} + +void +Client::usage() +{ + cerr << "Usage: " << appName() << " <options>\n"; + cerr << + "Options:\n" + "-h, --help Show this message.\n" + "-v, --version Display version.\n" + "--import FILE Import database from FILE.\n" + "--export FILE Export database to FILE.\n" + "--dbhome DIR The database directory.\n" + "-d, --debug Print debug messages." + ; +} + +int +Client::run(int argc, char* argv[]) +{ + IceUtilInternal::Options opts; + opts.addOpt("h", "help"); + opts.addOpt("v", "version"); + opts.addOpt("d", "debug"); + opts.addOpt("", "import", IceUtilInternal::Options::NeedArg); + opts.addOpt("", "export", IceUtilInternal::Options::NeedArg); + opts.addOpt("", "dbhome", IceUtilInternal::Options::NeedArg); + + vector<string> args; + try + { + args = opts.parse(argc, const_cast<const char**>(argv)); + } + catch(const IceUtilInternal::BadOptException& e) + { + cerr << e.reason << endl; + usage(); + return EXIT_FAILURE; + } + if(!args.empty()) + { + cerr << argv[0] << ": too many arguments" << endl; + usage(); + return EXIT_FAILURE; + } + + if(opts.isSet("help")) + { + usage(); + return EXIT_SUCCESS; + } + + if(opts.isSet("version")) + { + cout << ICE_STRING_VERSION << endl; + return EXIT_SUCCESS; + } + + if((!opts.isSet("import") && !opts.isSet("export")) || (opts.isSet("import") && opts.isSet("export"))) + { + cerr << "Either --import or --export must be set" << endl; + usage(); + return EXIT_FAILURE; + } + + if(!opts.isSet("dbhome")) + { + cerr << "Database path must be specified" << endl; + usage(); + return EXIT_FAILURE; + } + + bool debug = opts.isSet("debug"); + bool import = opts.isSet("import"); + string dbFile = opts.optArg(import ? "import" : "export"); + string dbPath = opts.optArg("dbhome"); + + try + { + IceStorm::AllData data; + + EncodingVersion encoding = { 1, 1 }; + communicator()->getProperties()->setProperty("Freeze.DbEnv.IceStorm.DbHome", dbPath); + + if(import) + { + cout << "Importing database to directory " << dbPath << " from file " << dbFile << endl; + + if(!IceUtilInternal::directoryExists(dbPath)) + { + cerr << "Output directory does not exist: " << dbPath << endl; + return EXIT_FAILURE; + } + + StringSeq files = IcePatch2Internal::readDirectory(dbPath); + if(!files.empty()) + { + cerr << "Output directory is not empty: " << dbPath << endl; + return EXIT_FAILURE; + } + + ifstream fs(dbFile, ios::binary); + if(fs.fail()) + { + cerr << "Could not open input file: " << strerror(errno) << endl; + return EXIT_FAILURE; + } + fs.unsetf(ios::skipws); + + fs.seekg(0, ios::end); + streampos fileSize = fs.tellg(); + fs.seekg(0, ios::beg); + + vector<Ice::Byte> buf; + buf.reserve(static_cast<size_t>(fileSize)); + buf.insert(buf.begin(), istream_iterator<Ice::Byte>(fs), istream_iterator<Ice::Byte>()); + + fs.close(); + + string type; + int version; + + Ice::InputStreamPtr stream = Ice::wrapInputStream(communicator(), buf, encoding); + stream->read(type); + if(type != "IceStorm") + { + cerr << "Incorrect input file type: " << type << endl; + return EXIT_FAILURE; + } + stream->read(version); + stream->read(data); + + { + Freeze::ConnectionPtr connection = Freeze::createConnection(communicator(), "IceStorm"); + Freeze::TransactionHolder txn(connection); + + if(debug) + { + cout << "Writing LLU Map:" << endl; + } + + IceStorm::LLUMap llumap(connection, "llu"); + for(StringLogUpdateDict::const_iterator p = data.llus.begin(); p != data.llus.end(); ++p) + { + if(debug) + { + cout << " KEY = " << p->first << endl; + } + llumap.put(*p); + } + + if(debug) + { + cout << "Writing Subscriber Map:" << endl; + } + + IceStorm::SubscriberMap subscribers(connection, "subscribers"); + for(SubscriberRecordDict::const_iterator q = data.subscribers.begin(); q != data.subscribers.end(); ++q) + { + if(debug) + { + cout << " KEY = TOPIC(" << communicator()->identityToString(q->first.topic) + << ") ID(" << communicator()->identityToString(q->first.id) << ")" <<endl; + } + subscribers.put(*q); + } + + txn.commit(); + } + } + else + { + cout << "Exporting database from directory " << dbPath << " to file " << dbFile << endl; + + { + Freeze::ConnectionPtr connection = Freeze::createConnection(communicator(), "IceStorm"); + + if(debug) + { + cout << "Reading LLU Map:" << endl; + } + + IceStorm::LLUMap llumap(connection, "llu"); + for(IceStorm::LLUMap::const_iterator p = llumap.begin(); p != llumap.end(); ++p) + { + if(debug) + { + cout << " KEY = " << p->first << endl; + } + data.llus.insert(*p); + } + + if(debug) + { + cout << "Reading Subscriber Map:" << endl; + } + + IceStorm::SubscriberMap subscribers(connection, "subscribers"); + for(IceStorm::SubscriberMap::const_iterator q = subscribers.begin(); q != subscribers.end(); ++q) + { + if(debug) + { + cout << " KEY = TOPIC(" << communicator()->identityToString(q->first.topic) + << ") ID(" << communicator()->identityToString(q->first.id) << ")" <<endl; + } + data.subscribers.insert(*q); + } + } + + Ice::OutputStreamPtr stream = Ice::createOutputStream(communicator(), encoding); + stream->write("IceStorm"); + stream->write(ICE_INT_VERSION); + stream->write(data); + pair<const Ice::Byte*, const Ice::Byte*> buf = stream->finished(); + + ofstream fs(dbFile, ios::binary); + if(fs.fail()) + { + cerr << "Could not open output file: " << strerror(errno) << endl; + return EXIT_FAILURE; + } + fs.write(reinterpret_cast<const char*>(buf.first), buf.second - buf.first); + fs.close(); + } + } + catch(const IceUtil::Exception& ex) + { + cerr << (import ? "Import" : "Export") << " failed:\n" << ex << endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/cpp/tools/icestormdb/IceStormDB.rc b/cpp/tools/icestormdb/IceStormDB.rc new file mode 100644 index 00000000000..786c8c95b32 --- /dev/null +++ b/cpp/tools/icestormdb/IceStormDB.rc @@ -0,0 +1,34 @@ +#include "winver.h" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 3,6,1,0 + PRODUCTVERSION 3,6,1,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "ZeroC, Inc.\0" + VALUE "FileDescription", "IceStormDB\0" + VALUE "FileVersion", "3.6.1\0" + VALUE "InternalName", "icestormdb\0" + VALUE "LegalCopyright", "Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.\0" + VALUE "OriginalFilename", "icegridadmin.exe\0" + VALUE "ProductName", "Ice\0" + VALUE "ProductVersion", "3.6.1\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END diff --git a/cpp/tools/icestormdb/Makefile b/cpp/tools/icestormdb/Makefile new file mode 100644 index 00000000000..0edaaba13c2 --- /dev/null +++ b/cpp/tools/icestormdb/Makefile @@ -0,0 +1,65 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ../.. + +ICESTORMDB = $(bindir)/icestormdb36 + +TARGETS = $(ICESTORMDB) + +SLICE_OBJS = DBTypes.o + +OBJS = IceStormDB.o \ + LLUMap.o \ + SubscriberMap.o \ + $(SLICE_OBJS) + +SRCS = $(OBJS:.o=.cpp) + +SLICE2FREEZECMD = $(SLICE2FREEZE) --ice $(ICECPPFLAGS) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. -I../../include -I../../src $(CPPFLAGS) +SLICE2CPPFLAGS := --ice -I. $(SLICE2CPPFLAGS) +LIBS := -lIceStorm -lIcePatch2 -lFreeze $(LIBS) + +$(ICESTORMDB): $(OBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +IceStormDB.o: LLURecord.h SubscriberRecord.h + +SubscriberRecord.ice: ../../src/IceStorm/SubscriberRecord.ice + cp ../../src/IceStorm/SubscriberRecord.ice . + +LLURecord.ice: ../../src/IceStorm/LLURecord.ice + cp ../../src/IceStorm/LLURecord.ice . + +LLUMap.h: LLUMap.cpp +LLUMap.cpp: LLURecord.ice $(SLICE2FREEZE) $(SLICEPARSERLIB) + rm -f LLUMap.h LLUMap.cpp + $(SLICE2FREEZECMD) --dict IceStorm::LLUMap,string,IceStormElection::LogUpdate \ + LLUMap LLURecord.ice + +SubscriberMap.h: SubscriberMap.cpp +SubscriberMap.cpp: SubscriberRecord.ice $(slicedir)/Ice/Identity.ice $(SLICE2FREEZE) $(SLICEPARSERLIB) + rm -f SubscriberMap.h SubscriberMap.cpp + $(SLICE2FREEZECMD) --dict IceStorm::SubscriberMap,IceStorm::SubscriberRecordKey,IceStorm::SubscriberRecord,sort \ + SubscriberMap SubscriberRecord.ice + +clean:: + -rm -f LLUMap.h LLUMap.cpp + -rm -f SubscriberMap.h SubscriberMap.cpp + -rm -f LLURecord.h LLURecord.cpp + -rm -f SubscriberRecord.h SubscriberRecord.cpp + -rm -f LLURecord.ice SubscriberRecord.ice + +install:: all + $(call installprogram,$(ICESTORMDB),$(DESTDIR)$(install_bindir)) diff --git a/cpp/tools/icestormdb/Makefile.mak b/cpp/tools/icestormdb/Makefile.mak new file mode 100644 index 00000000000..d31dbc54b9d --- /dev/null +++ b/cpp/tools/icestormdb/Makefile.mak @@ -0,0 +1,90 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +top_srcdir = ..\.. + +ICESTORMDB = $(top_srcdir)\bin\icestormdb35.exe + +TARGETS = $(ICESTORMDB) + +SLICE_OBJS = DBTypes.obj + +OBJS = IceStormDB.obj \ + LLUMap.obj \ + SubscriberMap.obj \ + $(SLICE_OBJS) + +SRCS = $(OBJS:.obj=.cpp) + +SDIR = $(slicedir)\IceStorm + +SLICE2FREEZECMD = "$(SLICE2FREEZE)" --ice $(ICECPPFLAGS) + +!include $(top_srcdir)\config\Make.rules.mak + +CPPFLAGS = -I. -I..\..\src $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN +SLICE2CPPFLAGS = --ice -I. $(SLICE2CPPFLAGS) +LINKWITH = $(LIBS) icestorm$(LIBSUFFIX).lib freeze$(LIBSUFFIX).lib icepatch2$(LIBSUFFIX).lib + +!if "$(GENERATE_PDB)" == "yes" +PDBFLAGS = /pdb:$(ICESTORMDB:.exe=.pdb) +!endif + +RES_FILE = IceStormDB.res + +$(ICESTORMDB): $(OBJS) IceStormDB.res + $(LINK) $(LD_EXEFLAGS) $(PDBFLAGS) $(OBJS) $(SETARGV) $(PREOUT)$@ $(PRELIBS)$(LINKWITH) $(RES_FILE) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) &&\ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + +IceStormDB.obj: SubscriberRecord.h LLURecord.h + +SubscriberRecord.ice: ..\..\src\IceStorm\SubscriberRecord.ice + copy ..\..\src\IceStorm\SubscriberRecord.ice . + +SubscriberRecord.h: SubscriberRecord.ice + "$(SLICE2CPP)" $(SLICE2CPPFLAGS) SubscriberRecord.ice + +LLURecord.ice: ..\..\src\IceStorm\LLURecord.ice + copy ..\..\src\IceStorm\LLURecord.ice . + +LLURecord.h: LLURecord.ice + "$(SLICE2CPP)" $(SLICE2CPPFLAGS) LLURecord.ice + +LLUMap.h LLUMap.cpp: LLURecord.ice "$(SLICE2FREEZE)" "$(SLICEPARSERLIB)" + del /q LLUMap.h LLUMap.cpp + $(SLICE2FREEZECMD) --dict IceStorm::LLUMap,string,IceStormElection::LogUpdate \ + LLUMap LLURecord.ice + +SubscriberMap.h SubscriberMap.cpp: SubscriberRecord.ice "$(SLICE2FREEZE)" "$(SLICEPARSERLIB)" + del /q SubscriberMap.h SubscriberMap.cpp + $(SLICE2FREEZECMD) \ + --dict IceStorm::SubscriberMap,IceStorm::SubscriberRecordKey,IceStorm::SubscriberRecord,sort \ + SubscriberMap SubscriberRecord.ice + +Clean:: + -del /q $(ICESTORMDB:.exe=.*) + -del /q IceStormDB.res + -del /q DBTypes.h DBTypes.cpp + -del /q LLUMap.h LLUMap.cpp + -del /q SubscriberMap.h SubscriberMap.cpp + -del /q LLURecord.h LLURecord.cpp + -del /q SubscriberRecord.h SubscriberRecord.cpp + -del /q LLURecord.ice SubscriberRecord.ice + +Install:: all + copy $(ICESTORMDB) "$(install_bindir)" + + +!if "$(GENERATE_PDB)" == "yes" + +Install:: all + copy $(ICESTORMDB:.exe=.pdb) "$(install_bindir)" + +!endif |