diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceGrid/.gitignore | 2 | ||||
-rw-r--r-- | cpp/src/IceGrid/DBTypes.ice | 30 | ||||
-rw-r--r-- | cpp/src/IceGrid/IceGridDB.cpp | 386 | ||||
-rw-r--r-- | cpp/src/IceGrid/IceGridDB.rc | 34 | ||||
-rw-r--r-- | cpp/src/IceGrid/Makefile | 31 | ||||
-rw-r--r-- | cpp/src/IceGrid/Makefile.mak | 36 | ||||
-rw-r--r-- | cpp/src/IceStorm/.gitignore | 2 | ||||
-rw-r--r-- | cpp/src/IceStorm/DBTypes.ice | 32 | ||||
-rw-r--r-- | cpp/src/IceStorm/IceStormDB.cpp | 282 | ||||
-rw-r--r-- | cpp/src/IceStorm/IceStormDB.rc | 34 | ||||
-rw-r--r-- | cpp/src/IceStorm/Makefile | 33 | ||||
-rw-r--r-- | cpp/src/IceStorm/Makefile.mak | 42 |
12 files changed, 913 insertions, 31 deletions
diff --git a/cpp/src/IceGrid/.gitignore b/cpp/src/IceGrid/.gitignore index 5a179db546b..baa4bbeaa15 100644 --- a/cpp/src/IceGrid/.gitignore +++ b/cpp/src/IceGrid/.gitignore @@ -1,6 +1,8 @@ // Generated by makegitignore.py // IMPORTANT: Do not edit this file -- any edits made here will be lost! +DBTypes.cpp +DBTypes.h IceLocatorDiscovery.cpp IceLocatorDiscovery.h Internal.cpp diff --git a/cpp/src/IceGrid/DBTypes.ice b/cpp/src/IceGrid/DBTypes.ice new file mode 100644 index 00000000000..6729a6bf434 --- /dev/null +++ b/cpp/src/IceGrid/DBTypes.ice @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 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/src/IceGrid/IceGridDB.cpp b/cpp/src/IceGrid/IceGridDB.cpp new file mode 100644 index 00000000000..12b968a18eb --- /dev/null +++ b/cpp/src/IceGrid/IceGridDB.cpp @@ -0,0 +1,386 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 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.\n" + ; +} + +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; + encoding.major = 1; + encoding.minor = 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.c_str(), 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", false); + 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", false); + 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", false); + 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", false); + 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", false); + 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.c_str(), 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/src/IceGrid/IceGridDB.rc b/cpp/src/IceGrid/IceGridDB.rc new file mode 100644 index 00000000000..228baecda41 --- /dev/null +++ b/cpp/src/IceGrid/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", "\251 2003-2016 ZeroC, Inc.\0" + VALUE "OriginalFilename", "icegriddb.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/src/IceGrid/Makefile b/cpp/src/IceGrid/Makefile index 6e059ab1e63..42f6672f692 100644 --- a/cpp/src/IceGrid/Makefile +++ b/cpp/src/IceGrid/Makefile @@ -10,12 +10,13 @@ top_srcdir = ../.. ADMIN = $(bindir)/icegridadmin +DB = $(bindir)/icegriddb NODE_SERVER = $(bindir)/icegridnode REGISTRY_SERVER = $(bindir)/icegridregistry -TARGETS = $(NODE_SERVER) $(REGISTRY_SERVER) $(ADMIN) +TARGETS = $(NODE_SERVER) $(REGISTRY_SERVER) $(ADMIN) $(DB) -SLICE_OBJS = Internal.o \ +CSLICE_OBJS = Internal.o \ IceLocatorDiscovery.o ADMIN_OBJS = Client.o \ @@ -27,7 +28,7 @@ ADMIN_OBJS = Client.o \ Parser.o \ Scanner.o \ Util.o \ - $(SLICE_OBJS) + $(CSLICE_OBJS) COMMON_OBJS = AdminRouter.o \ DescriptorBuilder.o \ @@ -36,7 +37,7 @@ COMMON_OBJS = AdminRouter.o \ PlatformInfo.o \ SessionManager.o \ TraceLevels.o \ - $(SLICE_OBJS) + $(CSLICE_OBJS) NODE_OBJS = Activator.o \ NodeAdminRouter.o \ @@ -89,11 +90,24 @@ REGISTRY_SVR_OBJS = \ $(REGISTRY_OBJS) \ IceGridRegistry.o +DSLICE_OBJS = DBTypes.o + +DB_OBJS = IceGridDB.o \ + StringApplicationInfoDict.o \ + IdentityObjectInfoDict.o \ + StringAdapterInfoDict.o \ + SerialsDict.o \ + $(DSLICE_OBJS) + OBJS = $(ADMIN_OBJS) \ $(COMMON_OBJS) \ $(NODE_OBJS) \ $(NODE_SVR_OBJS) \ - $(REGISTRY_SVR_OBJS) + $(REGISTRY_SVR_OBJS) \ + $(DB_OBJS) + +SLICE_OBJS = $(CSLICE_OBJS) \ + $(DSLICE_OBJS) SDIR = $(slicedir)/IceGrid @@ -101,7 +115,7 @@ RPATH_DIR = $(LOADER_PATH)/../$(libsubdir) include $(top_srcdir)/config/Make.rules -CPPFLAGS := $(CPPFLAGS) -I.. $(READLINE_FLAGS) +CPPFLAGS := $(CPPFLAGS) -I. -I.. $(READLINE_FLAGS) ICECPPFLAGS := $(ICECPPFLAGS) -I.. SLICE2CPPFLAGS := --checksum --ice --include-dir IceGrid $(SLICE2CPPFLAGS) SLICE2FREEZECMD := $(SLICE2FREEZE) --ice --include-dir IceGrid $(ICECPPFLAGS) @@ -111,6 +125,10 @@ $(ADMIN): $(ADMIN_OBJS) $(LIBTARGETS) $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(ADMIN_OBJS) -lGlacier2 $(EXPAT_RPATH_LINK) -lIceXML -lIceGrid -lIcePatch2 -lIceBox \ $(LIBS) $(READLINE_LIBS) $(OPENSSL_RPATH_LINK) +$(DB): $(DB_OBJS) $(LIBTARGETS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(DB_OBJS) -lIceGrid -lGlacier2 -lIcePatch2 -lFreeze $(LIBS) + $(REGISTRY_SERVER): $(REGISTRY_SVR_OBJS) $(LIBTARGETS) rm -f $@ $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(REGISTRY_SVR_OBJS) -lIceGrid -lIceStorm -lIceStormService -lGlacier2 -lIcePatch2 \ @@ -162,6 +180,7 @@ clean:: install:: all $(call installprogram,$(ADMIN),$(DESTDIR)$(install_bindir)) + $(call installprogram,$(DB),$(DESTDIR)$(install_bindir)) $(call installdata,$(top_srcdir)/../man/man1/icegridadmin.1,$(DESTDIR)$(install_mandir)) $(call installprogram,$(NODE_SERVER),$(DESTDIR)$(install_bindir)) $(call installdata,$(top_srcdir)/../man/man1/icegridnode.1,$(DESTDIR)$(install_mandir)) diff --git a/cpp/src/IceGrid/Makefile.mak b/cpp/src/IceGrid/Makefile.mak index 77fc02cd7ae..42317e5d807 100644 --- a/cpp/src/IceGrid/Makefile.mak +++ b/cpp/src/IceGrid/Makefile.mak @@ -11,22 +11,25 @@ top_srcdir = ..\.. ADMIN = $(top_srcdir)\bin\icegridadmin.exe +DB = $(top_srcdir)\bin\icegriddb.exe + NODE_SERVER_D = $(top_srcdir)\bin\icegridnoded.exe NODE_SERVER_R = $(top_srcdir)\bin\icegridnode.exe NODE_SERVER = $(top_srcdir)\bin\icegridnode$(LIBSUFFIX).exe - REGISTRY_SERVER_D = $(top_srcdir)\bin\icegridregistryd.exe REGISTRY_SERVER_R = $(top_srcdir)\bin\icegridregistry.exe REGISTRY_SERVER = $(top_srcdir)\bin\icegridregistry$(LIBSUFFIX).exe -TARGETS = $(ADMIN) $(NODE_SERVER) $(REGISTRY_SERVER) +TARGETS = $(ADMIN) $(NODE_SERVER) $(REGISTRY_SERVER) $(DB) -SLICE_OBJS = .\Internal.obj \ +CSLICE_OBJS = .\Internal.obj \ .\IceLocatorDiscovery.obj +DSLICE_OBJS = .\DBTypes.obj + all:: StringApplicationInfoDict.h StringApplicationInfoDict.cpp \ IdentityObjectInfoDict.h IdentityObjectInfoDict.cpp \ StringAdapterInfoDict.h StringAdapterInfoDict.cpp \ @@ -42,7 +45,7 @@ ADMIN_OBJS = .\Client.obj \ .\FileParserI.obj \ .\Parser.obj \ .\Util.obj \ - $(SLICE_OBJS) \ + $(CSLICE_OBJS) \ $(BISON_FLEX_OBJS) COMMON_OBJS = .\AdminRouter.obj \ @@ -52,7 +55,7 @@ COMMON_OBJS = .\AdminRouter.obj \ .\PlatformInfo.obj \ .\SessionManager.obj \ .\TraceLevels.obj \ - $(SLICE_OBJS) + $(CSLICE_OBJS) NODE_OBJS = .\Activator.obj \ .\NodeAdminRouter.obj \ @@ -105,9 +108,16 @@ REGISTRY_SVR_OBJS = \ $(REGISTRY_OBJS) \ .\IceGridRegistry.obj +DB_OBJS = .\IceGridDB.obj \ + .\IdentityObjectInfoDict.obj \ + .\SerialsDict.obj \ + .\StringAdapterInfoDict.obj \ + $(DSLICE_OBJS) + OBJS = $(ADMIN_OBJS) \ $(NODE_SVR_OBJS) \ - $(REGISTRY_SVR_OBJS) + $(REGISTRY_SVR_OBJS) \ + $(DB_OBJS) HDIR = $(headerdir)\IceGrid SDIR = $(slicedir)\IceGrid @@ -130,6 +140,7 @@ NPDBFLAGS = /pdb:$(NODE_SERVER:.exe=.pdb) !endif ARES_FILE = IceGridAdmin.res +DRES_FILE = IceGridDB.res RRES_FILE = IceGridRegistry.res NRES_FILE = IceGridNode.res @@ -140,6 +151,13 @@ $(ADMIN): $(ADMIN_OBJS) IceGridAdmin.res @if defined SIGN_CERTIFICATE echo ^ ^ ^ Signing $@ && \ signtool sign /f "$(SIGN_CERTIFICATE)" /p $(SIGN_PASSWORD) /t $(SIGN_TIMESTAMPSERVER) $@ +$(DB): $(DB_OBJS) IceGridDB.res + $(LINK) $(LD_EXEFLAGS) $(APDBFLAGS) $(DB_OBJS) $(SETARGV) $(PREOUT)$@ $(PRELIBS)$(LINKWITH) $(DRES_FILE) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) &&\ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + @if defined SIGN_CERTIFICATE echo ^ ^ ^ Signing $@ && \ + signtool sign /f "$(SIGN_CERTIFICATE)" /p $(SIGN_PASSWORD) /t $(SIGN_TIMESTAMPSERVER) $@ + $(REGISTRY_SERVER): $(REGISTRY_SVR_OBJS) IceGridRegistry.res $(LINK) $(LD_EXEFLAGS) $(RPDBFLAGS) $(REGISTRY_SVR_OBJS) $(SETARGV) $(PREOUT)$@ \ $(PRELIBS)$(NLINKWITH) $(RRES_FILE) @@ -163,7 +181,6 @@ IceLocatorDiscovery.h IceLocatorDiscovery.cpp: $(slicedir)\IceLocatorDiscovery\I @echo Generating dependencies for $< @"$(SLICE2CPP)" $(SLICE2CPPFLAGS) --depend $< | cscript /NoLogo $(top_srcdir)\..\config\makedepend-slice.vbs $(*F).ice - StringApplicationInfoDict.h StringApplicationInfoDict.cpp: $(SDIR)\Admin.ice $(SLICE2FREEZE) $(SLICEPARSERLIB) del /q StringApplicationInfoDict.h StringApplicationInfoDict.cpp $(SLICE2FREEZECMD) --dict IceGrid::StringApplicationInfoDict,string,IceGrid::ApplicationInfo \ @@ -185,26 +202,29 @@ SerialsDict.h SerialsDict.cpp: $(SLICE2FREEZE) $(SLICEPARSERLIB) $(SLICE2FREEZECMD) --dict IceGrid::SerialsDict,string,long SerialsDict clean:: + -del /q DBTypes.cpp DBTypes.h -del /q Internal.cpp Internal.h -del /q StringApplicationInfoDict.h StringApplicationInfoDict.cpp -del /q StringAdapterInfoDict.h StringAdapterInfoDict.cpp -del /q IdentityObjectInfoDict.h IdentityObjectInfoDict.cpp -del /q SerialsDict.h SerialsDict.cpp -del /q $(ADMIN:.exe=.*) + -del /q $(DB:.exe=.*) -del /q $(NODE_SERVER_D:.exe=.*) $(NODE_SERVER_R:.exe=.*) -del /q $(REGISTRY_SERVER_D:.exe=.*) $(REGISTRY_SERVER_R:.exe=.*) -del /q IceGridAdmin.res IceGridNode.res IceGridRegistry.res install:: all copy $(ADMIN) "$(install_bindir)" + copy $(DB) "$(install_bindir)" copy $(NODE_SERVER) "$(install_bindir)" copy $(REGISTRY_SERVER) "$(install_bindir)" - !if "$(GENERATE_PDB)" == "yes" install:: all copy $(ADMIN:.exe=.pdb) "$(install_bindir)" + copy $(DB:.exe=.pdb) "$(install_bindir)" copy $(NODE_SERVER:.exe=.pdb) "$(install_bindir)" copy $(REGISTRY_SERVER:.exe=.pdb) "$(install_bindir)" diff --git a/cpp/src/IceStorm/.gitignore b/cpp/src/IceStorm/.gitignore index 809f31e4118..afe04b10dd3 100644 --- a/cpp/src/IceStorm/.gitignore +++ b/cpp/src/IceStorm/.gitignore @@ -1,6 +1,8 @@ // Generated by makegitignore.py // IMPORTANT: Do not edit this file -- any edits made here will be lost! +DBTypes.h +DBTypes.cpp Instrumentation.cpp Election.cpp IceStormInternal.cpp diff --git a/cpp/src/IceStorm/DBTypes.ice b/cpp/src/IceStorm/DBTypes.ice new file mode 100644 index 00000000000..c75556f7100 --- /dev/null +++ b/cpp/src/IceStorm/DBTypes.ice @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 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/src/IceStorm/IceStormDB.cpp b/cpp/src/IceStorm/IceStormDB.cpp new file mode 100644 index 00000000000..76b1aa04244 --- /dev/null +++ b/cpp/src/IceStorm/IceStormDB.cpp @@ -0,0 +1,282 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 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.\n" + ; +} + +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 << argv[0] << ": " << 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 << argv[0] << ": either --import or --export must be set" << endl; + usage(); + return EXIT_FAILURE; + } + + if(!opts.isSet("dbhome")) + { + cerr << argv[0] << ": 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; + encoding.major = 1; + encoding.minor = 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 << argv[0] << ": output directory does not exist: " << dbPath << endl; + return EXIT_FAILURE; + } + + StringSeq files = IcePatch2Internal::readDirectory(dbPath); + if(!files.empty()) + { + cerr << argv[0] << ": output directory is not empty: " << dbPath << endl; + return EXIT_FAILURE; + } + + ifstream fs(dbFile.c_str(), ios::binary); + if(fs.fail()) + { + cerr << argv[0] << ": 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 << argv[0] << ": 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", false); + 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", false); + 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.c_str(), ios::binary); + if(fs.fail()) + { + cerr << argv[0] << ": 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 << argv[0] << ": " << (import ? "import" : "export") << " failed:\n" << ex << endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/cpp/src/IceStorm/IceStormDB.rc b/cpp/src/IceStorm/IceStormDB.rc new file mode 100644 index 00000000000..90b00213ff5 --- /dev/null +++ b/cpp/src/IceStorm/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", "\251 2003-2016 ZeroC, Inc.\0" + VALUE "OriginalFilename", "icestormdb.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/src/IceStorm/Makefile b/cpp/src/IceStorm/Makefile index f07bfbbca44..0b6aa5a5603 100644 --- a/cpp/src/IceStorm/Makefile +++ b/cpp/src/IceStorm/Makefile @@ -14,11 +14,12 @@ SONAME = $(call mksoname,IceStormService,$(SOVERSION)) LIBNAME = $(call mklibname,IceStormService) ADMIN = $(bindir)/icestormadmin +DB = $(bindir)/icestormdb MIGRATE = $(bindir)/icestormmigrate LIBTARGETS = $(call mklibtargets,$(libdir)/$(LIBFILENAME),$(libdir)/$(SONAME),$(libdir)$(cpp11libdirsuffix)/$(LIBNAME)) -TARGETS = $(LIBTARGETS) $(ADMIN) $(MIGRATE) +TARGETS = $(LIBTARGETS) $(ADMIN) $(MIGRATE) $(DB) -SLICE_OBJS = Election.o \ +CSLICE_OBJS = Election.o \ IceStormInternal.o \ Instrumentation.o \ LinkRecord.o \ @@ -43,24 +44,35 @@ LIB_OBJS = Instance.o \ Util.o \ V31FormatDB.o \ V32FormatDB.o \ - $(SLICE_OBJS) + $(CSLICE_OBJS) AOBJS = Admin.o \ Grammar.o \ Parser.o \ Scanner.o \ - $(SLICE_OBJS) + $(CSLICE_OBJS) MOBJS = LLUMap.o \ Migrate.o \ SubscriberMap.o \ V31FormatDB.o \ V32FormatDB.o \ - $(SLICE_OBJS) + $(CSLICE_OBJS) + +DSLICE_OBJS = DBTypes.o + +DOBJS = IceStormDB.o \ + LLUMap.o \ + SubscriberMap.o \ + $(DSLICE_OBJS) OBJS = $(LIB_OBJS) \ $(AOBJS) \ - $(MOBJS) + $(MOBJS) \ + $(DOBJS) + +SLICE_OBJS = $(CSLICE_OBJS) \ + $(DSLICE_OBJS) RPATH_DIR = $(LOADER_PATH)/../$(libsubdir) @@ -68,9 +80,9 @@ SLICE2FREEZECMD = $(SLICE2FREEZE) -I../.. --ice --include-dir IceStorm $(ICECPPF include $(top_srcdir)/config/Make.rules -CPPFLAGS := $(CPPFLAGS) -I.. $(READLINE_FLAGS) +CPPFLAGS := $(CPPFLAGS) -I. -I.. $(READLINE_FLAGS) ICECPPFLAGS := $(ICECPPFLAGS) -I.. -SLICE2CPPFLAGS := --ice --include-dir IceStorm $(SLICE2CPPFLAGS) +SLICE2CPPFLAGS := --ice --include-dir IceStorm -I. $(SLICE2CPPFLAGS) LINKWITH := $(BZIP2_RPATH_LINK) -lIceStorm -lIceGrid -lGlacier2 -lFreeze -lIceBox -lIce -lIceUtil $(libdir)/$(LIBFILENAME): $(LIB_OBJS) @@ -91,6 +103,10 @@ $(ADMIN): $(AOBJS) $(LIBTARGETS) rm -f $@ $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(AOBJS) -lIceStorm $(READLINE_LIBS) $(LIBS) +$(DB): $(DOBJS) $(LIBTARGETS) + rm -f $@ + $(CXX) $(LDFLAGS) $(LDEXEFLAGS) -o $@ $(DOBJS) -lIceStorm -lIcePatch2 -lFreeze $(LIBS) + $(MIGRATE): $(MOBJS) rm -f $@ $(CXX) $(LDFLAGS) $(DB_RPATH_LINK) $(LDEXEFLAGS) -o $@ $(MOBJS) -lIceStorm -lFreeze $(LIBS) @@ -136,6 +152,7 @@ clean:: install:: all $(call installlib,$(DESTDIR)$(install_libdir),$(libdir),$(LIBFILENAME),$(SONAME),$(LIBNAME)) $(call installprogram,$(ADMIN),$(DESTDIR)$(install_bindir)) + $(call installprogram,$(DB),$(DESTDIR)$(install_bindir)) $(call installdata,$(top_srcdir)/../man/man1/icestormadmin.1,$(DESTDIR)$(install_mandir)) $(call installprogram,$(MIGRATE),$(DESTDIR)$(install_bindir)) $(call installdata,$(top_srcdir)/../man/man1/icestormmigrate.1,$(DESTDIR)$(install_mandir)) diff --git a/cpp/src/IceStorm/Makefile.mak b/cpp/src/IceStorm/Makefile.mak index 84aefee6c63..6e5e8a46119 100644 --- a/cpp/src/IceStorm/Makefile.mak +++ b/cpp/src/IceStorm/Makefile.mak @@ -13,11 +13,12 @@ LIBNAME = $(top_srcdir)\lib\icestormservice$(LIBSUFFIX).lib DLLNAME = $(top_srcdir)\bin\icestormservice$(SOVERSION)$(LIBSUFFIX)$(COMPSUFFIX).dll ADMIN = $(top_srcdir)\bin\icestormadmin.exe +DB = $(top_srcdir)\bin\icestormdb.exe MIGRATE = $(top_srcdir)\bin\icestormmigrate.exe -TARGETS = $(LIBNAME) $(DLLNAME) $(ADMIN) $(MIGRATE) +TARGETS = $(LIBNAME) $(DLLNAME) $(ADMIN) $(MIGRATE) $(DB) -SLICE_OBJS = .\Election.obj \ +CSLICE_OBJS = .\Election.obj \ .\IceStormInternal.obj \ .\Instrumentation.obj \ .\LinkRecord.obj \ @@ -26,6 +27,8 @@ SLICE_OBJS = .\Election.obj \ .\V31Format.obj \ .\V32Format.obj +DSLICE_OBJS = .\DBTypes.obj + BISON_FLEX_OBJS = .\Grammar.obj \ .\Scanner.obj @@ -45,11 +48,11 @@ LIB_OBJS = .\Instance.obj \ .\Util.obj \ .\V31FormatDB.obj \ .\V32FormatDB.obj \ - $(SLICE_OBJS) + $(CSLICE_OBJS) AOBJS = .\Admin.obj \ .\Parser.obj \ - $(SLICE_OBJS) \ + $(CSLICE_OBJS) \ $(BISON_FLEX_OBJS) MOBJS = .\LLUMap.obj \ @@ -57,11 +60,20 @@ MOBJS = .\LLUMap.obj \ .\SubscriberMap.obj \ .\V31FormatDB.obj \ .\V32FormatDB.obj \ - $(SLICE_OBJS) + $(CSLICE_OBJS) + +DOBJS = .\IceStormDB.obj \ + .\LLUMap.obj \ + .\SubscriberMap.obj \ + $(DSLICE_OBJS) OBJS = $(LIB_OBJS) \ $(AOBJS) \ - $(MOBJS) + $(MOBJS) \ + $(DOBJS) + +SLICE_OBJS = $(CSLICE_OBJS) \ + $(DSLICE_OBJS) HDIR = $(headerdir)\IceStorm SDIR = $(slicedir)\IceStorm @@ -70,9 +82,9 @@ SLICE2FREEZECMD = $(SLICE2FREEZE) -I.. --ice --include-dir IceStorm $(ICECPPFLAG !include $(top_srcdir)\config\Make.rules.mak -CPPFLAGS = -I.. $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN +CPPFLAGS = -I. -I.. $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN ICECPPFLAGS = $(ICECPPFLAGS) -I.. -SLICE2CPPFLAGS = --ice --include-dir IceStorm $(SLICE2CPPFLAGS) +SLICE2CPPFLAGS = --ice --include-dir IceStorm -I. $(SLICE2CPPFLAGS) LINKWITH = $(LIBS) ALINKWITH = $(LIBS) MLINKWITH = $(LIBS) @@ -80,11 +92,13 @@ MLINKWITH = $(LIBS) !if "$(GENERATE_PDB)" == "yes" PDBFLAGS = /pdb:$(DLLNAME:.dll=.pdb) APDBFLAGS = /pdb:$(ADMIN:.exe=.pdb) +DPDBFLAGS = /pdb:$(DB:.exe=.pdb) MPDBFLAGS = /pdb:$(MIGRATE:.exe=.pdb) !endif RES_FILE = IceStormService.res ARES_FILE = IceStormAdmin.res +DRES_FILE = IceStormDB.res MRES_FILE = IceStormMigrate.res $(LIBNAME): $(DLLNAME) @@ -105,6 +119,13 @@ $(ADMIN): $(AOBJS) $(ARES_FILE) @if defined SIGN_CERTIFICATE echo ^ ^ ^ Signing $@ && \ signtool sign /f "$(SIGN_CERTIFICATE)" /p $(SIGN_PASSWORD) /t $(SIGN_TIMESTAMPSERVER) $@ +$(DB): $(DOBJS) $(DRES_FILE) + $(LINK) $(LD_EXEFLAGS) $(DPDBFLAGS) $(DOBJS) $(SETARGV) $(PREOUT)$@ $(PRELIBS)$(LINKWITH) $(DRES_FILE) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + @if defined SIGN_CERTIFICATE echo ^ ^ ^ Signing $@ && \ + signtool sign /f "$(SIGN_CERTIFICATE)" /p $(SIGN_PASSWORD) /t $(SIGN_TIMESTAMPSERVER) $@ + $(MIGRATE): $(MOBJS) $(MRES_FILE) $(LINK) $(LD_EXEFLAGS) $(MPDBFLAGS) $(MOBJS) $(SETARGV) $(PREOUT)$@ $(PRELIBS)$(MLINKWITH) $(MRES_FILE) @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ @@ -139,7 +160,8 @@ V31FormatDB.h V31FormatDB.cpp: V31Format.ice $(SLICE2FREEZE) $(SLICEPARSERLIB) V31FormatDB V31Format.ice clean:: - -del /q Election.cpp Election.h + -del /q DBTypes.cpp DBTypes.h + -del /q LLUMap.h LLUMap.cpp -del /q IceStormInternal.cpp IceStormInternal.h -del /q Instrumentation.cpp Instrumentation.h -del /q LinkRecord.cpp LinkRecord.h @@ -158,12 +180,14 @@ install:: all copy $(LIBNAME) "$(install_libdir)" copy $(DLLNAME) "$(install_bindir)" copy $(ADMIN) "$(install_bindir)" + copy $(DB) "$(install_bindir)" copy $(MIGRATE) "$(install_bindir)" !if "$(GENERATE_PDB)" == "yes" install:: all copy $(ADMIN:.exe=.pdb) "$(install_bindir)" + copy $(DB:.exe=.pdb) "$(install_bindir)" copy $(MIGRATE:.exe=.pdb) "$(install_bindir)" copy $(DLLNAME:.dll=.pdb) "$(install_bindir)" |