Ice::PropertiesPtr IceBox::ServiceManagerI::createServiceProperties(const string& service) { PropertiesPtr properties; PropertiesPtr communicatorProperties = _communicator->getProperties(); if(communicatorProperties->getPropertyAsInt("IceBox.InheritProperties") > 0) { properties = communicatorProperties->clone(); properties->setProperty("Ice.Admin.Endpoints", ""); // Inherit all except Ice.Admin.Endpoints! } else { properties = createProperties(); } string programName = communicatorProperties->getProperty("Ice.ProgramName"); if(programName.empty()) { properties->setProperty("Ice.ProgramName", service); } else { properties->setProperty("Ice.ProgramName", programName + "-" + service); } return properties; }
Glacier2::FilterManagerPtr Glacier2::FilterManager::create(const InstancePtr& instance, const string& userId, const bool allowAddUser) { PropertiesPtr props = instance->properties(); string allow = props->getProperty("Glacier2.Filter.Category.Accept"); vector<string> allowSeq; stringToSeq(allow, allowSeq); if(allowAddUser) { int addUserMode = 0; if(!props->getProperty("Glacier2.Filter.Category.AcceptUser").empty()) { addUserMode = props->getPropertyAsInt("Glacier2.Filter.Category.AcceptUser"); } if(addUserMode > 0 && !userId.empty()) { if(addUserMode == 1) { allowSeq.push_back(userId); // Add user id to allowed categories. } else if(addUserMode == 2) { allowSeq.push_back('_' + userId); // Add user id with prepended underscore to allowed categories. } } } Glacier2::StringSetIPtr categoryFilter = new Glacier2::StringSetI(allowSeq); // // TODO: refactor initialization of filters. // allow = props->getProperty("Glacier2.Filter.AdapterId.Accept"); stringToSeq(allow, allowSeq); Glacier2::StringSetIPtr adapterIdFilter = new Glacier2::StringSetI(allowSeq); // // TODO: Object id's from configurations? // IdentitySeq allowIdSeq; allow = props->getProperty("Glacier2.Filter.Identity.Accept"); stringToSeq(instance->communicator(), allow, allowIdSeq); Glacier2::IdentitySetIPtr identityFilter = new Glacier2::IdentitySetI(allowIdSeq); return new Glacier2::FilterManager(instance, categoryFilter, adapterIdFilter, identityFilter); }
std::string ServiceManagerI::getDataDir() { PropertiesPtr props = mAdapter->getCommunicator()->getProperties(); getVLogger().setLocalVerbosityLevel(props->getProperty("CVAC.ServicesVerbosity")); // Load the CVAC property: 'CVAC.DataDir'. Used for the xml filename path, // and to provide a prefix to Runset paths std::string dataDir = props->getProperty("CVAC.DataDir"); if(dataDir.empty()) { localAndClientMsg(VLogger::WARN, NULL, "Unable to locate CVAC Data directory, specified: " "'CVAC.DataDir = path/to/dataDir' in config.service\n"); } localAndClientMsg(VLogger::DEBUG, NULL, "CVAC Data directory configured as: %s \n", dataDir.c_str()); return dataDir; }
IcePatch2::Patcher::Patcher(const CommunicatorPtr& communicator, const PatcherFeedbackPtr& feedback) : _feedback(feedback), _dataDir(getDataDir(communicator, ".")), _thorough(getThorough(communicator, 0) > 0), _chunkSize(getChunkSize(communicator, 100)), _remove(getRemove(communicator, 1)), _log(0) { const PropertiesPtr properties = communicator->getProperties(); const char* clientProxyProperty = "IcePatch2Client.Proxy"; std::string clientProxy = properties->getProperty(clientProxyProperty); if(clientProxy.empty()) { const char* endpointsProperty = "IcePatch2.Endpoints"; string endpoints = properties->getProperty(endpointsProperty); if(endpoints.empty()) { ostringstream os; os << "No proxy to IcePatch2 server. Please set `" << clientProxyProperty << "' or `" << endpointsProperty << "'."; throw os.str(); } ostringstream os; os << "The property " << endpointsProperty << " is deprecated, use " << clientProxyProperty << " instead."; communicator->getLogger()->warning(os.str()); Identity id; id.category = properties->getPropertyWithDefault("IcePatch2.InstanceName", "IcePatch2"); id.name = "server"; clientProxy = "\"" + communicator->identityToString(id) + "\" :" + endpoints; } ObjectPrx serverBase = communicator->stringToProxy(clientProxy); FileServerPrx server = FileServerPrx::checkedCast(serverBase); if(!server) { throw "proxy `" + clientProxy + "' is not a file server."; } init(server); }
IceBox::ServiceManagerI::ServiceManagerI(CommunicatorPtr communicator, int& argc, char* argv[]) : _communicator(communicator), _adminEnabled(false), _pendingStatusChanges(false), _traceServiceObserver(0) { #ifndef ICE_CPP11_MAPPING const_cast<CallbackPtr&>(_observerCompletedCB) = newCallback(this, &ServiceManagerI::observerCompleted); #endif _logger = _communicator->getLogger(); PropertiesPtr props = _communicator->getProperties(); _traceServiceObserver = props->getPropertyAsInt("IceBox.Trace.ServiceObserver"); if(props->getProperty("Ice.Admin.Enabled") == "") { _adminEnabled = props->getProperty("Ice.Admin.Endpoints") != ""; } else { _adminEnabled = props->getPropertyAsInt("Ice.Admin.Enabled") > 0; } if(_adminEnabled) { StringSeq facetSeq = props->getPropertyAsList("Ice.Admin.Facets"); if(!facetSeq.empty()) { _adminFacetFilter.insert(facetSeq.begin(), facetSeq.end()); } } for(int i = 1; i < argc; i++) { _argv.push_back(argv[i]); } }
// look for ServiceNamex.TrainedModel // Note that the x is significant string ServiceManagerI::getModelFileFromConfig() { CommunicatorPtr comm = mAdapter->getCommunicator(); if ( comm ) { PropertiesPtr props = comm->getProperties(); if (props==true) { string propname = mServiceName + "x.TrainedModel"; string propval = props->getProperty( propname ); return propval; } } return ""; }
int run(int, char* argv[], const CommunicatorPtr& communicator) { PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( communicator->stringToProxy(managerProxy)); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } TopicPrx topic; try { topic = manager->retrieve("single"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } assert(topic); // // Get a publisher object, create a twoway proxy and then cast to // a Single object. // SinglePrx single = SinglePrx::uncheckedCast(topic->getPublisher()->ice_twoway()); for(int i = 0; i < 1000; ++i) { single->event(i); } return EXIT_SUCCESS; }
void IceServiceInstaller::install(const PropertiesPtr& properties) { _debug = properties->getPropertyAsInt("Debug") != 0; initializeSid(properties->getPropertyWithDefault("ObjectName", "NT Authority\\LocalService")); const string defaultDisplayName[] = { "IceGrid registry (" + _icegridInstanceName + ")", "IceGrid node (" + _nodeName + " within " + _icegridInstanceName + ")", "Glacier2 router (" + _glacier2InstanceName + ")" }; const string defaultDescription[] = { "Location and deployment service for Ice applications", "Starts and monitors Ice servers", "Ice Firewall traversal service" }; string displayName = properties->getPropertyWithDefault("DisplayName", defaultDisplayName[_serviceType]); string description = properties->getPropertyWithDefault("Description", defaultDescription[_serviceType]); string imagePath = properties->getProperty("ImagePath"); if(imagePath == "") { char buffer[MAX_PATH]; DWORD size = GetModuleFileName(0, buffer, MAX_PATH); if(size == 0) { throw "Can't get full path to self: " + IceUtilInternal::errorToString(GetLastError()); } imagePath = string(buffer, size); imagePath.replace(imagePath.rfind('\\'), string::npos, "\\" + serviceTypeToLowerString(_serviceType) + ".exe"); } else { imagePath = fixDirSeparator(imagePath); } if(!fileExists(imagePath)) { throw imagePath + ": not found"; } string dependency; if(_serviceType == icegridregistry) { if(properties->getPropertyAsInt("DependOnRegistry") != 0) { throw "The IceGrid registry service can't depend on itself"; } string registryDataDir = fixDirSeparator(_serviceProperties->getProperty("IceGrid.Registry.Data")); if(registryDataDir == "") { throw "IceGrid.Registry.Data must be set in " + _configFile; } if(!IceUtilInternal::isAbsolutePath(registryDataDir)) { throw "'" + registryDataDir + "' is a relative path; IceGrid.Registry.Data must be an absolute path"; } if(!mkdir(registryDataDir)) { grantPermissions(registryDataDir, SE_FILE_OBJECT, true, true); } } else if(_serviceType == icegridnode) { string nodeDataDir = fixDirSeparator(_serviceProperties->getProperty("IceGrid.Node.Data")); if(nodeDataDir == "") { throw "IceGrid.Node.Data must be set in " + _configFile; } if(!IceUtilInternal::isAbsolutePath(nodeDataDir)) { throw "'" + nodeDataDir + "' is a relative path; IceGrid.Node.Data must be an absolute path"; } if(!mkdir(nodeDataDir)) { grantPermissions(nodeDataDir, SE_FILE_OBJECT, true, true); } grantPermissions("MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib", SE_REGISTRY_KEY, true); if(properties->getPropertyAsInt("DependOnRegistry") != 0) { dependency = "icegridregistry." + _icegridInstanceName; } } else if(_serviceType == glacier2router) { if(properties->getPropertyAsInt("DependOnRegistry") != 0) { if(_icegridInstanceName == "") { throw "Ice.Default.Locator must be set in " + _configFile + " when DependOnRegistry is not zero"; } dependency = "icegridregistry." + _icegridInstanceName; } } if(!_configFile.find("HKLM\\") == 0) { grantPermissions(_configFile); } string eventLog = properties->getProperty("EventLog"); if(eventLog == "") { eventLog = "Application"; } else { addLog(eventLog); } string eventLogSource = _serviceProperties->getPropertyWithDefault("Ice.EventLog.Source", _serviceName); addSource(eventLogSource, eventLog, getIceDLLPath(imagePath)); SC_HANDLE scm = OpenSCManager(0, 0, SC_MANAGER_ALL_ACCESS); if(scm == 0) { DWORD res = GetLastError(); throw "Cannot open SCM: " + IceUtilInternal::errorToString(res); } string deps = dependency; if(deps.empty()) { const string candidates[] = { "netprofm", "Nla" }; const int candidatesLen = 2; for(int i = 0; i < candidatesLen; ++i) { SC_HANDLE service = OpenService(scm, candidates[i].c_str(), GENERIC_READ); if(service != 0) { deps = candidates[i]; CloseServiceHandle(service); break; // for } } } deps += '\0'; // must be double-null terminated string command = "\"" + imagePath + "\" --service " + _serviceName + " --Ice.Config=\""; // // Get the full path of config file. // if(!_configFile.find("HKLM\\") == 0) { char fullPath[MAX_PATH]; if(GetFullPathName(_configFile.c_str(), MAX_PATH, fullPath, 0) > MAX_PATH) { throw "Could not compute the full path of " + _configFile; } command += string(fullPath) + "\""; } else { command += _configFile + "\""; } bool autoStart = properties->getPropertyAsIntWithDefault("AutoStart", 1) != 0; string password = properties->getProperty("Password"); SC_HANDLE service = CreateServiceW( scm, IceUtil::stringToWstring(_serviceName).c_str(), IceUtil::stringToWstring(displayName).c_str(), SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, autoStart ? SERVICE_AUTO_START : SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, IceUtil::stringToWstring(command).c_str(), 0, 0, IceUtil::stringToWstring(deps).c_str(), IceUtil::stringToWstring(_sidName).c_str(), IceUtil::stringToWstring(password).c_str()); if(service == 0) { DWORD res = GetLastError(); CloseServiceHandle(scm); throw "Cannot create service" + _serviceName + ": " + IceUtilInternal::errorToString(res); } // // Set description // wstring uDescription = IceUtil::stringToWstring(description); SERVICE_DESCRIPTIONW sd = { const_cast<wchar_t*>(uDescription.c_str()) }; if(!ChangeServiceConfig2W(service, SERVICE_CONFIG_DESCRIPTION, &sd)) { DWORD res = GetLastError(); CloseServiceHandle(scm); CloseServiceHandle(service); throw "Cannot set description for service" + _serviceName + ": " + IceUtilInternal::errorToString(res); } CloseServiceHandle(scm); CloseServiceHandle(service); }
instanceName = opts.optArg("instanceName"); } int port = communicator()->getProperties()->getPropertyAsInt("IceGridAdmin.Port"); if(!opts.optArg("port").empty()) { istringstream is(opts.optArg("port")); if(!(is >> port)) { cerr << _appName << ": given port number is not a numeric value" << endl; return EXIT_FAILURE; } } PropertiesPtr properties = communicator()->getProperties(); string replica = properties->getProperty("IceGridAdmin.Replica"); if(!opts.optArg("replica").empty()) { replica = opts.optArg("replica"); } Glacier2::RouterPrx router; AdminSessionPrx session; SessionKeepAliveThreadPtr keepAlive; int status = EXIT_SUCCESS; try { int sessionTimeout; int acmTimeout = 0; if(!communicator()->getDefaultLocator() && !communicator()->getDefaultRouter()) {
void CascadeTrainI::process(const Identity &client, const RunSet& runset, const TrainerProperties& trainProps, const Current& current) { mTrainProps->load(trainProps); // Obtain CVAC verbosity - TODO: this should happen earlier PropertiesPtr svcprops = current.adapter->getCommunicator()->getProperties(); string verbStr = svcprops->getProperty("CVAC.ServicesVerbosity"); if (!verbStr.empty()) { getVLogger().setLocalVerbosityLevel( verbStr ); } TrainerCallbackHandlerPrx callback = TrainerCallbackHandlerPrx::uncheckedCast(current.con->createProxy(client)->ice_oneway()); if (mTrainProps->hasInfoFile == false) { // check the validity of the runset. if (!checkPurposedLists( runset.purposedLists, callback )) return; } // Get the remote client name to use to save cascade file std::string connectName = cvac::getClientConnectionName(current); const std::string CVAC_DataDir = svcprops->getProperty("CVAC.DataDir"); if(runset.purposedLists.size() == 0 && mTrainProps->hasInfoFile == false) { string _resStr = "Error: no data (runset) for processing\n"; localAndClientMsg(VLogger::WARN, callback, _resStr.c_str()); return; } // Since createSamples fails if there is a space in a file name we will create a temporary runset // and provide symbolic links to files that name spaces in there names. //cvac::RunSet tempRunSet = runset; // Add the cvac data dir to the directories in the runset //addDataPath(tempRunSet, CVAC_DataDir); // The symbolic links are created in a tempdir so lets remember it so we can delete it at the end //std::string tempRSDir = fixupRunSet(tempRunSet, CVAC_DataDir); // Iterate over runset, inserting each POSITIVE Labelable into // the input file to "createsamples". Add each NEGATIVE into // the bgFile. Put both created files into a tempdir. std::string clientName = mServiceMan->getSandbox()->createClientName(mServiceMan->getServiceName(), connectName); std::string tempDir = mServiceMan->getSandbox()->createTrainingDir(clientName); //RunSetWrapper rsw( &tempRunSet, CVAC_DataDir, mServiceMan ); RunSetWrapper rsw( &runset, CVAC_DataDir, mServiceMan ); // We can't put the bgName and infoName in the tempdir without // changing cvSamples since it assumes that this files location is the root // directory for the data. //string bgName = tempDir + "/cascade_negatives.txt"; //string infoName = tempDir + "/cascade_positives.txt"; string bgName = "cascade_negatives.txt"; string infoName = "cascade_positives.txt"; if (mTrainProps->hasInfoFile) infoName = mTrainProps->infoFile; int numNeg = 0; writeBgFile( rsw, bgName, &numNeg, CVAC_DataDir, callback ); // set parameters to createsamples SamplesParams samplesParams; samplesParams.numSamples = 1000; if (mTrainProps->sampleSize.width != 0) samplesParams.width = mTrainProps->sampleSize.width; else samplesParams.width = mTrainProps->windowSize.width; if (mTrainProps->sampleSize.height != 0) samplesParams.height = mTrainProps->sampleSize.height; else samplesParams.height = mTrainProps->windowSize.height; // run createsamples std::string vecFname = tempDir + "/cascade_positives.vec"; int numPos = 0; createSamples( rsw, samplesParams, infoName, vecFname, &numPos, CVAC_DataDir, callback, bgName, numNeg); // Tell ServiceManager that we will listen for stop mServiceMan->setStoppable(); bool created = createClassifier( tempDir, vecFname, bgName, numPos, numNeg, mTrainProps ); // Tell ServiceManager that we are done listening for stop mServiceMan->clearStop(); if (created) { DetectorDataArchive dda; std::string clientDir = mServiceMan->getSandbox()->createClientDir(clientName); std::string archiveFilename = getDateFilename(clientDir, "cascade")+ ".zip"; dda.setArchiveFilename(archiveFilename); dda.addFile(XMLID, tempDir + "/cascade.xml"); dda.createArchive(tempDir); mServiceMan->getSandbox()->deleteTrainingDir(clientName); FilePath detectorData; detectorData.filename = getFileName(archiveFilename); std::string relDir; int idx = clientDir.find(CVAC_DataDir.c_str(), 0, CVAC_DataDir.length()); if (idx == 0) { relDir = clientDir.substr(CVAC_DataDir.length() + 1); }else { relDir = clientDir; } detectorData.directory.relativePath = relDir; callback->createdDetector(detectorData); localAndClientMsg(VLogger::INFO, callback, "Cascade training done.\n"); }else { localAndClientMsg(VLogger::INFO, callback, "Cascade training failed.\n"); } //deleteDirectory(tempRSDir); }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { IceUtilInternal::Options opts; opts.addOpt("", "count", IceUtilInternal::Options::NeedArg); try { opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } ObjectPrx base = communicator->stringToProxy(managerProxy); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } TopicPrx fed1; try { fed1 = manager->retrieve("fed1"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } EventPrx eventFed1 = EventPrx::uncheckedCast(fed1->getPublisher()->ice_oneway()); string arg = opts.optArg("count"); int count = 1; if(arg.empty()) { count = atoi(arg.c_str()); } while(true) { for(int i = 0; i < 10; ++i) { eventFed1->pub("fed1"); } // // Before we exit, we ping all proxies as twoway, to make sure // that all oneways are delivered. // EventPrx::uncheckedCast(eventFed1->ice_twoway())->ice_ping(); if(count == 0) { break; } --count; IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1)); } return EXIT_SUCCESS; }
IceInternal::DefaultsAndOverrides::DefaultsAndOverrides(const PropertiesPtr& properties) : overrideTimeout(false), overrideTimeoutValue(-1), overrideConnectTimeout(false), overrideConnectTimeoutValue(-1), overrideCloseTimeout(false), overrideCloseTimeoutValue(-1), overrideCompress(false), overrideCompressValue(false), overrideSecure(false), overrideSecureValue(false) { const_cast<string&>(defaultProtocol) = properties->getPropertyWithDefault("Ice.Default.Protocol", "tcp"); const_cast<string&>(defaultHost) = properties->getProperty("Ice.Default.Host"); string value; value = properties->getProperty("Ice.Override.Timeout"); if(!value.empty()) { const_cast<bool&>(overrideTimeout) = true; const_cast<Int&>(overrideTimeoutValue) = properties->getPropertyAsInt("Ice.Override.Timeout"); } value = properties->getProperty("Ice.Override.ConnectTimeout"); if(!value.empty()) { const_cast<bool&>(overrideConnectTimeout) = true; const_cast<Int&>(overrideConnectTimeoutValue) = properties->getPropertyAsInt("Ice.Override.ConnectTimeout"); } value = properties->getProperty("Ice.Override.CloseTimeout"); if(!value.empty()) { const_cast<bool&>(overrideCloseTimeout) = true; const_cast<Int&>(overrideCloseTimeoutValue) = properties->getPropertyAsInt("Ice.Override.CloseTimeout"); } value = properties->getProperty("Ice.Override.Compress"); if(!value.empty()) { const_cast<bool&>(overrideCompress) = true; const_cast<bool&>(overrideCompressValue) = properties->getPropertyAsInt("Ice.Override.Compress"); } value = properties->getProperty("Ice.Override.Secure"); if(!value.empty()) { const_cast<bool&>(overrideSecure) = true; const_cast<bool&>(overrideSecureValue) = properties->getPropertyAsInt("Ice.Override.Secure"); } const_cast<bool&>(defaultCollocationOptimization) = properties->getPropertyAsIntWithDefault("Ice.Default.CollocationOptimized", 1) > 0; value = properties->getPropertyWithDefault("Ice.Default.EndpointSelection", "Random"); if(value == "Random") { defaultEndpointSelection = Random; } else if(value == "Ordered") { defaultEndpointSelection = Ordered; } else { EndpointSelectionTypeParseException ex(__FILE__, __LINE__); ex.str = "illegal value `" + value + "'; expected `Random' or `Ordered'"; throw ex; } const_cast<int&>(defaultLocatorCacheTimeout) = properties->getPropertyAsIntWithDefault("Ice.Default.LocatorCacheTimeout", -1); const_cast<bool&>(defaultPreferSecure) = properties->getPropertyAsIntWithDefault("Ice.Default.PreferSecure", 0) > 0; value = properties->getPropertyWithDefault("Ice.Default.EncodingVersion", encodingVersionToString(currentEncoding)); defaultEncoding = stringToEncodingVersion(value); checkSupportedEncoding(defaultEncoding); bool slicedFormat = properties->getPropertyAsIntWithDefault("Ice.Default.SlicedFormat", 0) > 0; const_cast<FormatType&>(defaultFormat) = slicedFormat ? SlicedFormat : CompactFormat; }
bool IceBox::ServiceManagerI::start() { try { ServiceManagerPtr obj = this; PropertiesPtr properties = _communicator->getProperties(); // // Create an object adapter. Services probably should NOT share // this object adapter, as the endpoint(s) for this object adapter // will most likely need to be firewalled for security reasons. // ObjectAdapterPtr adapter; if(properties->getProperty("IceBox.ServiceManager.Endpoints") != "") { adapter = _communicator->createObjectAdapter("IceBox.ServiceManager"); Identity identity; identity.category = properties->getPropertyWithDefault("IceBox.InstanceName", "IceBox"); identity.name = "ServiceManager"; adapter->add(obj, identity); } // // Parse the property set with the prefix "IceBox.Service.". These // properties should have the following format: // // IceBox.Service.Foo=entry_point [args] // // We parse the service properties specified in IceBox.LoadOrder // first, then the ones from remaining services. // const string prefix = "IceBox.Service."; PropertyDict services = properties->getPropertiesForPrefix(prefix); PropertyDict::iterator p; StringSeq loadOrder = properties->getPropertyAsList("IceBox.LoadOrder"); vector<StartServiceInfo> servicesInfo; for(StringSeq::const_iterator q = loadOrder.begin(); q != loadOrder.end(); ++q) { p = services.find(prefix + *q); if(p == services.end()) { FailureException ex(__FILE__, __LINE__); ex.reason = "ServiceManager: no service definition for `" + *q + "'"; throw ex; } servicesInfo.push_back(StartServiceInfo(*q, p->second, _argv)); services.erase(p); } for(p = services.begin(); p != services.end(); ++p) { servicesInfo.push_back(StartServiceInfo(p->first.substr(prefix.size()), p->second, _argv)); } // // Check if some services are using the shared communicator in which // case we create the shared communicator now with a property set which // is the union of all the service properties (services which are using // the shared communicator). // PropertyDict sharedCommunicatorServices = properties->getPropertiesForPrefix("IceBox.UseSharedCommunicator."); if(!sharedCommunicatorServices.empty()) { InitializationData initData; initData.properties = createServiceProperties("SharedCommunicator"); for(vector<StartServiceInfo>::iterator q = servicesInfo.begin(); q != servicesInfo.end(); ++q) { if(properties->getPropertyAsInt("IceBox.UseSharedCommunicator." + q->name) <= 0) { continue; } // // Load the service properties using the shared communicator properties as // the default properties. // PropertiesPtr svcProperties = createProperties(q->args, initData.properties); // // Erase properties from the shared communicator which don't exist in the // service properties (which include the shared communicator properties // overriden by the service properties). // PropertyDict allProps = initData.properties->getPropertiesForPrefix(""); for(PropertyDict::iterator p = allProps.begin(); p != allProps.end(); ++p) { if(svcProperties->getProperty(p->first) == "") { initData.properties->setProperty(p->first, ""); } } // // Add the service properties to the shared communicator properties. // PropertyDict props = svcProperties->getPropertiesForPrefix(""); for(PropertyDict::const_iterator r = props.begin(); r != props.end(); ++r) { initData.properties->setProperty(r->first, r->second); } // // Parse <service>.* command line options (the Ice command line options // were parsed by the createProperties above) // q->args = initData.properties->parseCommandLineOptions(q->name, q->args); } _sharedCommunicator = initialize(initData); } // // Start the services. // for(vector<StartServiceInfo>::const_iterator r = servicesInfo.begin(); r != servicesInfo.end(); ++r) { start(r->name, r->entryPoint, r->args); } // // We may want to notify external scripts that the services // have started. This is done by defining the property: // // IceBox.PrintServicesReady=bundleName // // Where bundleName is whatever you choose to call this set of // services. It will be echoed back as "bundleName ready". // // This must be done after start() has been invoked on the // services. // string bundleName = properties->getProperty("IceBox.PrintServicesReady"); if(!bundleName.empty()) { cout << bundleName << " ready" << endl; } // // Register "this" as a facet to the Admin object, and then create // Admin object // try { _communicator->addAdminFacet(this, "IceBox.ServiceManager"); // // Add a Properties facet for each service // for(vector<ServiceInfo>::iterator r = _services.begin(); r != _services.end(); ++r) { const ServiceInfo& info = *r; CommunicatorPtr communicator = info.communicator != 0 ? info.communicator : _sharedCommunicator; _communicator->addAdminFacet(new PropertiesAdminI(communicator->getProperties()), "IceBox.Service." + info.name + ".Properties"); } _communicator->getAdmin(); } catch(const ObjectAdapterDeactivatedException&) { // // Expected if the communicator has been shutdown. // } if(adapter) { try { adapter->activate(); } catch(const ObjectAdapterDeactivatedException&) { // // Expected if the communicator has been shutdown. // } } } catch(const FailureException& ex) { Error out(_logger); out << ex.reason; stopAll(); return false; } catch(const Exception& ex) { Error out(_logger); out << "ServiceManager: " << ex; stopAll(); return false; } return true; }
bool RouterService::start(int argc, char* argv[], int& status) { bool nowarn; IceUtilInternal::Options opts; opts.addOpt("h", "help"); opts.addOpt("v", "version"); opts.addOpt("", "nowarn"); vector<string> args; try { args = opts.parse(argc, const_cast<const char**>(argv)); } catch(const IceUtilInternal::BadOptException& e) { error(e.reason); usage(argv[0]); return false; } if(opts.isSet("help")) { usage(argv[0]); status = EXIT_SUCCESS; return false; } if(opts.isSet("version")) { print(ICE_STRING_VERSION); status = EXIT_SUCCESS; return false; } nowarn = opts.isSet("nowarn"); if(!args.empty()) { consoleErr << argv[0] << ": too many arguments" << endl; usage(argv[0]); return false; } PropertiesPtr properties = communicator()->getProperties(); // // Initialize the client object adapter. // const string clientEndpointsProperty = "Glacier2.Client.Endpoints"; if(properties->getProperty(clientEndpointsProperty).empty()) { error("property `" + clientEndpointsProperty + "' is not set"); return false; } if(properties->getPropertyAsInt("Glacier2.SessionTimeout") > 0 && properties->getProperty("Glacier2.Client.ACM.Timeout").empty()) { ostringstream os; os << properties->getPropertyAsInt("Glacier2.SessionTimeout"); properties->setProperty("Glacier2.Client.ACM.Timeout", os.str()); } if(properties->getProperty("Glacier2.Client.ACM.Close").empty()) { properties->setProperty("Glacier2.Client.ACM.Close", "4"); // Forcefull close on invocation and idle. } ObjectAdapterPtr clientAdapter = communicator()->createObjectAdapter("Glacier2.Client"); // // Initialize the server object adapter only if server endpoints // are defined. // const string serverEndpointsProperty = "Glacier2.Server.Endpoints"; ObjectAdapterPtr serverAdapter; if(!properties->getProperty(serverEndpointsProperty).empty()) { serverAdapter = communicator()->createObjectAdapter("Glacier2.Server"); } string instanceName = communicator()->getProperties()->getPropertyWithDefault("Glacier2.InstanceName", "Glacier2"); vector<string> verifierProperties; verifierProperties.push_back("Glacier2.PermissionsVerifier"); verifierProperties.push_back("Glacier2.SSLPermissionsVerifier"); Glacier2Internal::setupNullPermissionsVerifier(communicator(), instanceName, verifierProperties); string verifierProperty = verifierProperties[0]; PermissionsVerifierPrx verifier; ObjectPrx obj; try { // // We use propertyToProxy instead of stringToProxy because the property // can provide proxy attributes // obj = communicator()->propertyToProxy(verifierProperty); } catch(const std::exception& ex) { ServiceError err(this); err << "permissions verifier `" << communicator()->getProperties()->getProperty(verifierProperty) << "' is invalid:\n" << ex; return false; } if(obj) { try { verifier = PermissionsVerifierPrx::checkedCast(obj); if(!verifier) { ServiceError err(this); err << "permissions verifier `" << communicator()->getProperties()->getProperty(verifierProperty) << "' is invalid"; return false; } } catch(const Ice::Exception& ex) { if(!nowarn) { ServiceWarning warn(this); warn << "unable to contact permissions verifier `" << communicator()->getProperties()->getProperty(verifierProperty) << "'\n" << ex; } verifier = PermissionsVerifierPrx::uncheckedCast(obj); } } // // Get the session manager if specified. // string sessionManagerProperty = "Glacier2.SessionManager"; string sessionManagerPropertyValue = properties->getProperty(sessionManagerProperty); SessionManagerPrx sessionManager; if(!sessionManagerPropertyValue.empty()) { try { obj = communicator()->propertyToProxy(sessionManagerProperty); } catch(const std::exception& ex) { ServiceError err(this); err << "session manager `" << sessionManagerPropertyValue << "' is invalid\n:" << ex; return false; } try { sessionManager = SessionManagerPrx::checkedCast(obj); if(!sessionManager) { error("session manager `" + sessionManagerPropertyValue + "' is invalid"); return false; } } catch(const std::exception& ex) { if(!nowarn) { ServiceWarning warn(this); warn << "unable to contact session manager `" << sessionManagerPropertyValue << "'\n" << ex; } sessionManager = SessionManagerPrx::uncheckedCast(obj); } sessionManager = SessionManagerPrx::uncheckedCast(sessionManager->ice_connectionCached(false)->ice_locatorCacheTimeout( properties->getPropertyAsIntWithDefault("Glacier2.SessionManager.LocatorCacheTimeout", 600))); } // // Check for an SSL permissions verifier. // string sslVerifierProperty = verifierProperties[1]; SSLPermissionsVerifierPrx sslVerifier; try { obj = communicator()->propertyToProxy(sslVerifierProperty); } catch(const std::exception& ex) { ServiceError err(this); err << "ssl permissions verifier `" << communicator()->getProperties()->getProperty(sslVerifierProperty) << "' is invalid:\n" << ex; return false; } if(obj) { try { sslVerifier = SSLPermissionsVerifierPrx::checkedCast(obj); if(!sslVerifier) { ServiceError err(this); err << "ssl permissions verifier `" << communicator()->getProperties()->getProperty(sslVerifierProperty) << "' is invalid"; } } catch(const Ice::Exception& ex) { if(!nowarn) { ServiceWarning warn(this); warn << "unable to contact ssl permissions verifier `" << communicator()->getProperties()->getProperty(sslVerifierProperty) << "'\n" << ex; } sslVerifier = SSLPermissionsVerifierPrx::uncheckedCast(obj); } } // // Get the SSL session manager if specified. // string sslSessionManagerProperty = "Glacier2.SSLSessionManager"; string sslSessionManagerPropertyValue = properties->getProperty(sslSessionManagerProperty); SSLSessionManagerPrx sslSessionManager; if(!sslSessionManagerPropertyValue.empty()) { try { obj = communicator()->propertyToProxy(sslSessionManagerProperty); } catch(const std::exception& ex) { ServiceError err(this); err << "ssl session manager `" << sslSessionManagerPropertyValue << "' is invalid:\n" << ex; return false; } try { sslSessionManager = SSLSessionManagerPrx::checkedCast(obj); if(!sslSessionManager) { error("ssl session manager `" + sslSessionManagerPropertyValue + "' is invalid"); return false; } } catch(const Ice::Exception& ex) { if(!nowarn) { ServiceWarning warn(this); warn << "unable to contact ssl session manager `" << sslSessionManagerPropertyValue << "'\n" << ex; } sslSessionManager = SSLSessionManagerPrx::uncheckedCast(obj); } sslSessionManager = SSLSessionManagerPrx::uncheckedCast(sslSessionManager->ice_connectionCached(false)->ice_locatorCacheTimeout( properties->getPropertyAsIntWithDefault("Glacier2.SSLSessionManager.LocatorCacheTimeout", 600))); } if(!verifier && !sslVerifier) { error("Glacier2 requires a permissions verifier or password file"); return false; } // // Create the instance object. // try { _instance = new Glacier2::Instance(communicator(), clientAdapter, serverAdapter); } catch(const Ice::InitializationException& ex) { error("Glacier2 initialization failed:\n" + ex.reason); return false; } // // Create the session router. The session router registers itself // and all required servant locators, so no registration has to be // done here. // _sessionRouter = new SessionRouterI(_instance, verifier, sessionManager, sslVerifier, sslSessionManager); // // Th session router is used directly as servant for the main // Glacier2 router Ice object. // Identity routerId; routerId.category = instanceName; routerId.name = "router"; Glacier2::RouterPrx routerPrx = Glacier2::RouterPrx::uncheckedCast(clientAdapter->add(_sessionRouter, routerId)); // // Add the Ice router finder object to allow retrieving the router // proxy with just the endpoint information of the router. // Identity finderId; finderId.category = "Ice"; finderId.name = "RouterFinder"; clientAdapter->add(new FinderI(routerPrx), finderId); if(_instance->getObserver()) { _instance->getObserver()->setObserverUpdater(_sessionRouter); } // // Everything ok, let's go. // try { clientAdapter->activate(); if(serverAdapter) { serverAdapter->activate(); } } catch(const std::exception& ex) { { ServiceError err(this); err << "caught exception activating object adapters\n" << ex; } stop(); return false; } return true; }
bowCV* BowICETrainI::initialize( TrainerCallbackHandlerPrx& _callback, const TrainerProperties &tprops, DetectorDataArchive& dda, const Current& current ) { // Set CVAC verbosity according to ICE properties PropertiesPtr iceprops = (current.adapter->getCommunicator()->getProperties()); string verbStr = iceprops->getProperty("CVAC.ServicesVerbosity"); if (!verbStr.empty()) { vLogger.setLocalVerbosityLevel( verbStr ); } // defaults //SURF, SIFT, FAST, STAR, MSER, GFTT, HARRIS string _nameFeature("SIFT"); //SURF, SIFT, OpponentSIFT, OpponentSURF string _nameDescriptor("SIFT"); //BruteForce-L1, BruteForce, FlannBased string _nameMatcher("BruteForce-L1"); int _countWords = 150; // read properties; need to cast const away cvac::Properties& trp = (cvac::Properties&) tprops.props; const string& nf = trp[bowCV::BOW_DETECTOR_NAME]; if (!nf.empty()) { _nameFeature = nf; localAndClientMsg(VLogger::DEBUG, _callback, "Set FeatureType to %s\n", nf.c_str() ); } const string& nd = trp[bowCV::BOW_EXTRACTOR_NAME]; if (!nd.empty()) { _nameDescriptor = nd; localAndClientMsg(VLogger::DEBUG, _callback, "Set DescriptorType to %s\n", nd.c_str() ); } const string& nm = trp[bowCV::BOW_MATCHER_NAME]; if (!nm.empty()) { _nameMatcher = nm; localAndClientMsg(VLogger::DEBUG, _callback, "Set MatcherType to %s\n", nm.c_str() ); } const string& nw = trp["NumWords"]; if (!nw.empty()) { errno=0; long int cw = (int) strtol( nw.c_str(), (char**) NULL, 10 ); if (cw>0 && cw<INT_MAX && errno==0) { // no error, successfully parsed int from NumWords property _countWords = cw; localAndClientMsg(VLogger::DEBUG, _callback, "Number of words set to %d\n", cw ); } } // figure out how to handle Negative purpose samples, if any const string& strategy = trp[bowCV::BOW_REJECT_CLASS_STRATEGY]; if (!strategy.empty()) { std::string strat = strategy; std::transform( strategy.begin(), strategy.end(), strat.begin(), ::tolower ); rejectClassStrategy = bowCV::BOW_REJECT_CLASS_AS_MULTICLASS; if (0==strat.compare(bowCV::BOW_REJECT_CLASS_IGNORE_SAMPLES)) { rejectClassStrategy = bowCV::BOW_REJECT_CLASS_IGNORE_SAMPLES; localAndClientMsg(VLogger::DEBUG, _callback, "BOW will ignore any samples with Negative purpose\n"); } else if (0==strat.compare(bowCV::BOW_REJECT_CLASS_AS_MULTICLASS)) { rejectClassStrategy = bowCV::BOW_REJECT_CLASS_AS_MULTICLASS; localAndClientMsg(VLogger::DEBUG, _callback, "BOW will treat samples with Negative purpose as a separate class\n"); } else if (0==strat.compare(bowCV::BOW_REJECT_CLASS_AS_FIRST_STAGE)) { rejectClassStrategy = bowCV::BOW_REJECT_CLASS_AS_FIRST_STAGE; localAndClientMsg(VLogger::DEBUG, _callback, "BOW will create a two-stage classifier: reject first, multiclass second\n"); localAndClientMsg(VLogger::ERROR, _callback, "BOW two-stage classifier is not implemented yet\n"); return false; } else { localAndClientMsg(VLogger::WARN, _callback, "Incorrect specifier for %s property, using default (%s).\n", bowCV::BOW_REJECT_CLASS_STRATEGY.c_str(), rejectClassStrategy.c_str() ); } } bowCV* pBowCV = new bowCV(this); bool fInitialized = pBowCV->train_initialize(_nameFeature,_nameDescriptor,_nameMatcher,_countWords, &dda); if (fInitialized) { return pBowCV; } else { return NULL; } }
bool NodeService::startImpl(int argc, char* argv[], int& status) { bool nowarn = false; bool readonly = false; string initFromReplica; string desc; vector<string> targets; for(int i = 1; i < argc; ++i) { if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { usage(argv[0]); status = EXIT_SUCCESS; return false; } else if(strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { print(ICE_STRING_VERSION); status = EXIT_SUCCESS; return false; } else if(strcmp(argv[i], "--nowarn") == 0) { nowarn = true; } else if(strcmp(argv[i], "--readonly") == 0) { readonly = true; } else if(strcmp(argv[i], "--initdb-from-replica") == 0) { if(i + 1 >= argc) { error("missing replica argument for option `" + string(argv[i]) + "'"); usage(argv[0]); return false; } initFromReplica = argv[++i]; } else if(strcmp(argv[i], "--deploy") == 0) { if(i + 1 >= argc) { error("missing descriptor argument for option `" + string(argv[i]) + "'"); usage(argv[0]); return false; } desc = argv[++i]; while(i + 1 < argc && argv[++i][0] != '-') { targets.push_back(argv[i]); } } else { error("invalid option: `" + string(argv[i]) + "'"); usage(argv[0]); return false; } } PropertiesPtr properties = communicator()->getProperties(); // // Disable server idle time. Otherwise, the adapter would be // shutdown prematurely and the deactivation would fail. // Deactivation of the node relies on the object adapter // to be active since it needs to terminate servers. // // TODO: implement Ice.ServerIdleTime in the activator // termination listener instead? // properties->setProperty("Ice.ServerIdleTime", "0"); // // Warn the user that setting Ice.ThreadPool.Server isn't useful. // if(!nowarn && properties->getPropertyAsIntWithDefault("Ice.ThreadPool.Server.Size", 0) > 0) { Warning out(communicator()->getLogger()); out << "setting `Ice.ThreadPool.Server.Size' is not useful, "; out << "you should set individual adapter thread pools instead."; } setupThreadPool(properties, "IceGrid.Node.ThreadPool", 1, 100); // // Create the activator. // TraceLevelsPtr traceLevels = new TraceLevels(communicator(), "IceGrid.Node"); _activator = new Activator(traceLevels); // // Collocate the IceGrid registry if we need to. // if(properties->getPropertyAsInt("IceGrid.Node.CollocateRegistry") > 0) { _registry = new CollocatedRegistry(communicator(), _activator, nowarn, readonly, initFromReplica); if(!_registry->start()) { return false; } // // Set the default locator property to point to the collocated // locator (this property is passed by the activator to each // activated server). The default locator is also needed by // the node session manager. // if(properties->getProperty("Ice.Default.Locator").empty()) { Identity locatorId; locatorId.category = properties->getPropertyWithDefault("IceGrid.InstanceName", "IceGrid"); locatorId.name = "Locator"; string endpoints = properties->getProperty("IceGrid.Registry.Client.Endpoints"); string locPrx = "\"" + communicator()->identityToString(locatorId) + "\" :" + endpoints; communicator()->setDefaultLocator(Ice::LocatorPrx::uncheckedCast(communicator()->stringToProxy(locPrx))); properties->setProperty("Ice.Default.Locator", locPrx); } } else if(properties->getProperty("Ice.Default.Locator").empty()) { error("property `Ice.Default.Locator' is not set"); return false; } // // Initialize the database environment (first setup the directory structure if needed). // string dataPath = properties->getProperty("IceGrid.Node.Data"); string dbPath; if(dataPath.empty()) { error("property `IceGrid.Node.Data' is not set"); return false; } else { if(!IceUtilInternal::directoryExists(dataPath)) { FileException ex(__FILE__, __LINE__); ex.path = dataPath; ex.error = IceInternal::getSystemErrno(); ServiceError err(this); err << "property `IceGrid.Node.Data' is set to an invalid path:\n" << ex; return false; } // // Creates subdirectories. // if(dataPath[dataPath.length() - 1] != '/') { dataPath += "/"; } IcePatch2::createDirectory(dataPath + "servers"); IcePatch2::createDirectory(dataPath + "tmp"); IcePatch2::createDirectory(dataPath + "distrib"); #ifdef _WIN32 // // Make sure these directories are not indexed by the Windows // indexing service (which can cause random "Access Denied" // errors if indexing runs at the same time as the node is // creating/deleting files). // try { setNoIndexingAttribute(dataPath + "servers"); setNoIndexingAttribute(dataPath + "tmp"); setNoIndexingAttribute(dataPath + "distrib"); } catch(const FileException& ex) { if(!nowarn) { Warning out(communicator()->getLogger()); out << "couldn't disable file indexing:\n" << ex; } } #endif } // // Check that required properties are set and valid. // if(properties->getProperty("IceGrid.Node.Endpoints").empty()) { error("property `IceGrid.Node.Endpoints' is not set"); return false; } string name = properties->getProperty("IceGrid.Node.Name"); if(name.empty()) { error("property `IceGrid.Node.Name' is not set"); return false; } // // Setup the Freeze database environment home directory. The name of the database // environment for the IceGrid node is the name of the node. // properties->setProperty("Freeze.DbEnv." + name + ".DbHome", dbPath); // // Create the node object adapter. // _adapter = communicator()->createObjectAdapter("IceGrid.Node"); // // Setup the user account mapper if configured. // string mapperProperty = "IceGrid.Node.UserAccountMapper"; string mapperPropertyValue = properties->getProperty(mapperProperty); UserAccountMapperPrx mapper; if(!mapperPropertyValue.empty()) { try { mapper = UserAccountMapperPrx::uncheckedCast(communicator()->propertyToProxy(mapperProperty)); } catch(const std::exception& ex) { ServiceError err(this); err << "user account mapper `" << mapperProperty << "' is invalid:\n" << ex; return false; } } else { string userAccountFileProperty = properties->getProperty("IceGrid.Node.UserAccounts"); if(!userAccountFileProperty.empty()) { try { Ice::ObjectPrx object = _adapter->addWithUUID(new FileUserAccountMapperI(userAccountFileProperty)); object = object->ice_collocationOptimized(true); mapper = UserAccountMapperPrx::uncheckedCast(object); } catch(const std::string& msg) { error(msg); return false; } } } // // Create a new timer to handle server activation/deactivation timeouts. // _timer = new IceUtil::Timer(); // // The IceGrid instance name. // const string instanceName = communicator()->getDefaultLocator()->ice_getIdentity().category; _sessions.reset(new NodeSessionManager(communicator())); // // Create the server factory. The server factory creates persistent objects // for the server and server adapter. It also takes care of installing the // evictors and object factories necessary to store these objects. // Identity id = communicator()->stringToIdentity(instanceName + "/Node-" + name); NodePrx nodeProxy = NodePrx::uncheckedCast(_adapter->createProxy(id)); _node = new NodeI(_adapter, *_sessions, _activator, _timer, traceLevels, nodeProxy, name, mapper); _adapter->add(_node, nodeProxy->ice_getIdentity()); _adapter->addServantLocator(new DefaultServantLocator(new NodeServerAdminRouter(_node)), _node->getServerAdminCategory()); // // Start the platform info thread if needed. // _node->getPlatformInfo().start(); // // Ensures that the locator is reachable. // if(!nowarn) { try { communicator()->getDefaultLocator()->ice_timeout(1000)->ice_ping(); } catch(const Ice::LocalException& ex) { Warning out(communicator()->getLogger()); out << "couldn't reach the IceGrid registry (this is expected "; out << "if it's down, otherwise please check the value of the "; out << "Ice.Default.Locator property):\n" << ex; } } // // Create the node sessions with the registries. // _sessions->create(_node); // // In some tests, we deploy icegridnodes using IceGrid: // if(properties->getProperty("Ice.Admin.Endpoints") != "") { // // Replace Process facet and create Admin object // try { ProcessPtr origProcess = ProcessPtr::dynamicCast(communicator()->removeAdminFacet("Process")); communicator()->addAdminFacet(new ProcessI(_activator, origProcess), "Process"); communicator()->getAdmin(); } catch(const Ice::NotRegisteredException&) { // // Some plug-in removed the Process facet, so we don't replace it. // (unlikely error though) // } } // // Start the activator. // _activator->start(); // // Activate the adapter. // _adapter->activate(); // // Notify the node session manager that the node can start // accepting incoming connections. // _sessions->activate(); string bundleName = properties->getProperty("IceGrid.Node.PrintServersReady"); if(!bundleName.empty() || !desc.empty()) { enableInterrupt(); if(!_sessions->waitForCreate()) { // // Create was interrupted, return true as if the service was // correctly initiliazed to make sure it's properly stopped. // return true; } disableInterrupt(); } // // Deploy application if a descriptor is passed as a command-line option. // if(!desc.empty()) { try { Ice::Identity regId; regId.category = instanceName; regId.name = "Registry"; RegistryPrx registry = RegistryPrx::checkedCast(communicator()->getDefaultLocator()->findObjectById(regId)); if(!registry) { throw "invalid registry"; } registry = registry->ice_preferSecure(true); // Use SSL if available. IceGrid::AdminSessionPrx session; if(communicator()->getProperties()->getPropertyAsInt("IceGridAdmin.AuthenticateUsingSSL")) { session = registry->createAdminSessionFromSecureConnection(); } else { string id = communicator()->getProperties()->getProperty("IceGridAdmin.Username"); string password = communicator()->getProperties()->getProperty("IceGridAdmin.Password"); while(id.empty()) { cout << "user id: " << flush; getline(cin, id); id = IceUtilInternal::trim(id); } if(password.empty()) { cout << "password: "******"failed to deploy application `" << desc << "':\n" << ex; } catch(const AccessDeniedException& ex) { ServiceWarning warn(this); warn << "failed to deploy application `" << desc << "':\n" << "registry database is locked by `" << ex.lockUserId << "'"; } catch(const std::exception& ex) { ServiceWarning warn(this); warn << "failed to deploy application `" << desc << "':\n" << ex; } catch(const string& reason) { ServiceWarning warn(this); warn << "failed to deploy application `" << desc << "':\n" << reason; } } if(!bundleName.empty()) { print(bundleName + " ready"); } return true; }
// // Setup the engine. // void IceSSL::SecureTransportEngine::initialize() { IceUtil::Mutex::Lock lock(_mutex); if(_initialized) { return; } SSLEngine::initialize(); const PropertiesPtr properties = communicator()->getProperties(); // // Check for a default directory. We look in this directory for // files mentioned in the configuration. // const string defaultDir = properties->getProperty("IceSSL.DefaultDir"); // // Load the CA certificates used to authenticate peers into // _certificateAuthorities array. // try { string caFile = properties->getProperty("IceSSL.CAs"); if(caFile.empty()) { caFile = properties->getProperty("IceSSL.CertAuthFile"); } if(!caFile.empty()) { string resolved; if(!checkPath(caFile, defaultDir, false, resolved)) { throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: CA certificate file not found:\n" + caFile); } _certificateAuthorities.reset(loadCACertificates(resolved)); } else if(properties->getPropertyAsInt("IceSSL.UsePlatformCAs") <= 0) { // Setup an empty list of Root CAs to not use the system root CAs. _certificateAuthorities.reset(CFArrayCreate(0, 0, 0, 0)); } } catch(const CertificateReadException& ce) { throw PluginInitializationException(__FILE__, __LINE__, ce.reason); } const string password = properties->getProperty("IceSSL.Password"); const int passwordRetryMax = properties->getPropertyAsIntWithDefault("IceSSL.PasswordRetryMax", 3); PasswordPromptPtr passwordPrompt = getPasswordPrompt(); string certFile = properties->getProperty("IceSSL.CertFile"); string keyFile = properties->getProperty("IceSSL.KeyFile"); string findCert = properties->getProperty("IceSSL.FindCert"); string keychain = properties->getProperty("IceSSL.Keychain"); string keychainPassword = properties->getProperty("IceSSL.KeychainPassword"); if(!certFile.empty()) { vector<string> files; if(!IceUtilInternal::splitString(certFile, IceUtilInternal::pathsep, files) || files.size() > 2) { throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: invalid value for IceSSL.CertFile:\n" + certFile); } vector<string> keyFiles; if(!keyFile.empty()) { if(!IceUtilInternal::splitString(keyFile, IceUtilInternal::pathsep, keyFiles) || keyFiles.size() > 2) { throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: invalid value for IceSSL.KeyFile:\n" + keyFile); } if(files.size() != keyFiles.size()) { throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: IceSSL.KeyFile does not agree with IceSSL.CertFile"); } } for(int i = 0; i < files.size(); ++i) { string file = files[i]; string keyFile = keyFiles.empty() ? "" : keyFiles[i]; string resolved; if(!checkPath(file, defaultDir, false, resolved)) { throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: certificate file not found:\n" + file); } file = resolved; if(!keyFile.empty()) { if(!checkPath(keyFile, defaultDir, false, resolved)) { throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: key file not found:\n" + keyFile); } keyFile = resolved; } try { _chain.reset(loadCertificateChain(file, keyFile, keychain, keychainPassword, password, passwordPrompt, passwordRetryMax)); break; } catch(const CertificateReadException& ce) { // // If this is the last certificate rethrow the exception as PluginInitializationException, // otherwise try the next certificate. // if(i == files.size() - 1) { throw PluginInitializationException(__FILE__, __LINE__, ce.reason); } } } } else if(!findCert.empty()) { _chain.reset(findCertificateChain(keychain, keychainPassword, findCert)); } // // DiffieHellmanParams in DER format. // #if defined(ICE_USE_SECURE_TRANSPORT_MACOS) string dhFile = properties->getProperty("IceSSL.DHParams"); if(!dhFile.empty()) { string resolved; if(!checkPath(dhFile, defaultDir, false, resolved)) { throw PluginInitializationException(__FILE__, __LINE__, "IceSSL: DH params file not found:\n" + dhFile); } readFile(resolved, _dhParams); } #endif // // Establish the cipher list. // const string ciphers = properties->getProperty("IceSSL.Ciphers"); CiphersHelper::initialize(); if(!ciphers.empty()) { parseCiphers(ciphers); } if(securityTraceLevel() >= 1) { ostringstream os; os << "enabling SSL ciphersuites:"; if(_ciphers.empty()) { map<string, SSLCipherSuite> enabled = CiphersHelper::ciphers(); for(map<string, SSLCipherSuite>::const_iterator i = enabled.begin(); i != enabled.end(); ++i) { os << "\n " << i->first; } } else { for(vector<SSLCipherSuite>::const_iterator i = _ciphers.begin(); i != _ciphers.end(); ++i) { os << "\n " << getCipherName(*i); } } getLogger()->trace(securityTraceCategory(), os.str()); } // // Parse protocols // const string protocolVersionMax = properties->getProperty("IceSSL.ProtocolVersionMax"); if(!protocolVersionMax.empty()) { _protocolVersionMax = parseProtocol(protocolVersionMax); } // // The default min protocol version is set to TLS1.0 to avoid security issues with SSLv3 // const string protocolVersionMin = properties->getPropertyWithDefault("IceSSL.ProtocolVersionMin", "tls1_0"); if(!protocolVersionMin.empty()) { _protocolVersionMin = parseProtocol(protocolVersionMin); } _initialized = true; }
RoutableReferencePtr IceInternal::ReferenceFactory::create(const Identity& ident, const string& facet, Reference::Mode mode, bool secure, const Ice::ProtocolVersion& protocol, const Ice::EncodingVersion& encoding, const vector<EndpointIPtr>& endpoints, const string& adapterId, const string& propertyPrefix) { DefaultsAndOverridesPtr defaultsAndOverrides = _instance->defaultsAndOverrides(); // // Default local proxy options. // LocatorInfoPtr locatorInfo; if(_defaultLocator) { if(_defaultLocator->ice_getEncodingVersion() != encoding) { locatorInfo = _instance->locatorManager()->get(_defaultLocator->ice_encodingVersion(encoding)); } else { locatorInfo = _instance->locatorManager()->get(_defaultLocator); } } RouterInfoPtr routerInfo = _instance->routerManager()->get(_defaultRouter); bool collocationOptimized = defaultsAndOverrides->defaultCollocationOptimization; bool cacheConnection = true; bool preferSecure = defaultsAndOverrides->defaultPreferSecure; Ice::EndpointSelectionType endpointSelection = defaultsAndOverrides->defaultEndpointSelection; int locatorCacheTimeout = defaultsAndOverrides->defaultLocatorCacheTimeout; int invocationTimeout = defaultsAndOverrides->defaultInvocationTimeout; Ice::Context ctx; // // Override the defaults with the proxy properties if a property prefix is defined. // if(!propertyPrefix.empty()) { PropertiesPtr properties = _instance->initializationData().properties; if(properties->getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { checkForUnknownProperties(propertyPrefix); } string property; property = propertyPrefix + ".Locator"; LocatorPrx locator = LocatorPrx::uncheckedCast(_communicator->propertyToProxy(property)); if(locator) { if(locator->ice_getEncodingVersion() != encoding) { locatorInfo = _instance->locatorManager()->get(locator->ice_encodingVersion(encoding)); } else { locatorInfo = _instance->locatorManager()->get(locator); } } property = propertyPrefix + ".Router"; RouterPrx router = RouterPrx::uncheckedCast(_communicator->propertyToProxy(property)); if(router) { if(propertyPrefix.size() > 7 && propertyPrefix.substr(propertyPrefix.size() - 7, 7) == ".Router") { Warning out(_instance->initializationData().logger); out << "`" << property << "=" << properties->getProperty(property) << "': cannot set a router on a router; setting ignored"; } else { routerInfo = _instance->routerManager()->get(router); } } property = propertyPrefix + ".CollocationOptimized"; collocationOptimized = properties->getPropertyAsIntWithDefault(property, collocationOptimized) > 0; property = propertyPrefix + ".ConnectionCached"; cacheConnection = properties->getPropertyAsIntWithDefault(property, cacheConnection) > 0; property = propertyPrefix + ".PreferSecure"; preferSecure = properties->getPropertyAsIntWithDefault(property, preferSecure) > 0; property = propertyPrefix + ".EndpointSelection"; if(!properties->getProperty(property).empty()) { string type = properties->getProperty(property); if(type == "Random") { endpointSelection = Random; } else if(type == "Ordered") { endpointSelection = Ordered; } else { EndpointSelectionTypeParseException ex(__FILE__, __LINE__); ex.str = "illegal value `" + type + "'; expected `Random' or `Ordered'"; throw ex; } } property = propertyPrefix + ".LocatorCacheTimeout"; string value = properties->getProperty(property); if(!value.empty()) { locatorCacheTimeout = properties->getPropertyAsIntWithDefault(property, locatorCacheTimeout); if(locatorCacheTimeout < -1) { locatorCacheTimeout = -1; Warning out(_instance->initializationData().logger); out << "invalid value for " << property << "`" << properties->getProperty(property) << "'" << ": defaulting to -1"; } } property = propertyPrefix + ".InvocationTimeout"; value = properties->getProperty(property); if(!value.empty()) { invocationTimeout = properties->getPropertyAsIntWithDefault(property, invocationTimeout); if(invocationTimeout < 1 && invocationTimeout != -1) { invocationTimeout = -1; Warning out(_instance->initializationData().logger); out << "invalid value for " << property << "`" << properties->getProperty(property) << "'" << ": defaulting to -1"; } } property = propertyPrefix + ".Context."; PropertyDict contexts = properties->getPropertiesForPrefix(property); for(PropertyDict::const_iterator p = contexts.begin(); p != contexts.end(); ++p) { ctx.insert(make_pair(p->first.substr(property.length()), p->second)); } } // // Create new reference // return new RoutableReference(_instance, _communicator, ident, facet, mode, secure, protocol, encoding, endpoints, adapterId, locatorInfo, routerInfo, collocationOptimized, cacheConnection, preferSecure, endpointSelection, locatorCacheTimeout, invocationTimeout, ctx); }
int Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initData, int version) { assert(_service); // // Create a pipe that is used to notify the parent when the child is ready. // SOCKET fds[2]; IceInternal::createPipe(fds); // // Fork the child. // pid_t pid = fork(); if(pid < 0) { if(argv[0]) { consoleErr << argv[0] << ": "; } consoleErr << strerror(errno) << endl; return EXIT_FAILURE; } if(pid != 0) { // // Parent process. // // // Close an unused end of the pipe. // close(fds[1]); // // Wait for the child to write a byte to the pipe to indicate that it // is ready to receive requests, or that an error occurred. // char c = 0; while(true) { if(read(fds[0], &c, 1) == -1) { if(IceInternal::interrupted()) { continue; } if(argv[0]) { consoleErr << argv[0] << ": "; } consoleErr << strerror(errno) << endl; _exit(EXIT_FAILURE); } break; } if(c != 0) { // // Read an error message. // char msg[1024]; size_t pos = 0; while(pos < sizeof(msg)) { ssize_t n = read(fds[0], &msg[pos], sizeof(msg) - pos); if(n == -1) { if(IceInternal::interrupted()) { continue; } if(argv[0]) { consoleErr << ": "; } consoleErr << "I/O error while reading error message from child:\n" << strerror(errno) << endl; _exit(EXIT_FAILURE); } pos += n; break; } if(argv[0]) { consoleErr << argv[0] << ": "; } consoleErr << "failure occurred in daemon"; if(strlen(msg) > 0) { consoleErr << ':' << endl << msg; } consoleErr << endl; _exit(EXIT_FAILURE); } _exit(EXIT_SUCCESS); } // // Child process. // string errMsg; int status = EXIT_FAILURE; try { // // Become a session and process group leader. // if(setsid() == -1) { throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno()); } // // Ignore SIGHUP so that the grandchild process is not sent SIGHUP when this // process exits. // signal(SIGHUP, SIG_IGN); // // Fork again to eliminate the possibility of acquiring a controlling terminal. // pid = fork(); if(pid < 0) { throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno()); } if(pid != 0) { exit(0); } if(_changeDirectory) { // // Change the working directory. // if(chdir("/") != 0) { throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno()); } } vector<int> fdsToClose; if(_closeFiles) { // // Take a snapshot of the open file descriptors. We don't actually close these // descriptors until after the communicator is initialized, so that plug-ins // have an opportunity to use stdin/stdout/stderr if necessary. This also // conveniently allows the Ice.PrintProcessId property to work as expected. // int fdMax = static_cast<int>(sysconf(_SC_OPEN_MAX)); if(fdMax <= 0) { throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno()); } for(int i = 0; i < fdMax; ++i) { if(fcntl(i, F_GETFL) != -1) { // // Don't close the write end of the pipe. // if(i != fds[1]) { fdsToClose.push_back(i); } } } } // // Create the CtrlCHandler after forking the child so that signals are initialized // properly. We do this before initializing the communicator because we need to // ensure that signals are initialized before additional threads are created. The // communicator thread pools currently use lazy initialization, but a thread can // be created to monitor connections. // _ctrlCHandler = new IceUtil::CtrlCHandler; // // Initialize the communicator. // _communicator = initializeCommunicator(argc, argv, initData, version); if(_closeFiles) { // // Close unnecessary file descriptors. // PropertiesPtr properties = _communicator->getProperties(); string stdOut = properties->getProperty("Ice.StdOut"); string stdErr = properties->getProperty("Ice.StdErr"); for(vector<int>::const_iterator p = fdsToClose.begin(); p != fdsToClose.end(); ++p) { // // NOTE: Do not close stdout if Ice.StdOut is defined. Likewise for Ice.StdErr. // if((*p == 1 && !stdOut.empty()) || (*p == 2 && !stdErr.empty())) { continue; } close(*p); } // // Associate stdin, stdout and stderr with /dev/null. // int fd = open("/dev/null", O_RDWR); assert(fd == 0); if(fd != 0) { throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno()); } if(stdOut.empty()) { fd = dup2(0, 1); assert(fd == 1); if(fd != 1) { throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno()); } } if(stdErr.empty()) { fd = dup2(1, 2); assert(fd == 2); if(fd != 2) { throw SyscallException(__FILE__, __LINE__, IceInternal::getSystemErrno()); } } } // // Write PID // if(_pidFile.size() > 0) { ofstream of(_pidFile.c_str()); of << getpid() << endl; if(!of) { warning("Could not write PID file " + _pidFile); } } // // Use the configured logger. // _logger = _communicator->getLogger(); // // Start the service. // if(start(argc, argv, status)) { // // Notify the parent that the child is ready. // char c = 0; while(true) { if(write(fds[1], &c, 1) == -1) { if(IceInternal::interrupted()) { continue; } } break; } close(fds[1]); fds[1] = -1; // // Wait for service shutdown. // waitForShutdown(); // // Stop the service. // if(stop()) { status = EXIT_SUCCESS; } } } catch(const Ice::Exception& ex) { ServiceError err(this); err << "service terminating after catching exception:\n" << ex; errMsg = err.str(); } catch(const std::exception& ex) { ServiceError err(this); err << "service terminating after catching exception:\n" << ex; errMsg = err.str(); } catch(...) { errMsg = "service terminating after catching unknown exception"; error(errMsg); } // // If the service failed and the pipe to the parent is still open, // then send an error notification to the parent. // if(status != EXIT_SUCCESS && fds[1] != -1) { char c = 1; while(true) { if(write(fds[1], &c, 1) == -1) { if(IceInternal::interrupted()) { continue; } } break; } const char* msg = errMsg.c_str(); size_t len = strlen(msg) + 1; // Include null byte size_t pos = 0; while(len > 0) { ssize_t n = write(fds[1], &msg[pos], len); if(n == -1) { if(IceInternal::interrupted()) { continue; } else { break; } } len -= n; pos += n; } close(fds[1]); } if(_communicator) { _communicator->destroy(); } return status; }
bool RegistryI::start(bool nowarn) { assert(_communicator); PropertiesPtr properties = _communicator->getProperties(); // // Initialize the database environment. // string dbPath = properties->getProperty("IceGrid.Registry.Data"); if(dbPath.empty()) { Error out(_communicator->getLogger()); out << "property `IceGrid.Registry.Data' is not set"; return false; } else { struct stat filestat; if(stat(dbPath.c_str(), &filestat) != 0 || !S_ISDIR(filestat.st_mode)) { Error out(_communicator->getLogger()); SyscallException ex(__FILE__, __LINE__); ex.error = getSystemErrno(); out << "property `IceGrid.Registry.Data' is set to an invalid path:\n" << ex; return false; } } // // Check that required properties are set and valid. // if(properties->getProperty("IceGrid.Registry.Client.Endpoints").empty()) { Error out(_communicator->getLogger()); out << "property `IceGrid.Registry.Client.Endpoints' is not set"; return false; } if(properties->getProperty("IceGrid.Registry.Server.Endpoints").empty()) { Error out(_communicator->getLogger()); out << "property `IceGrid.Registry.Server.Endpoints' is not set"; return false; } if(properties->getProperty("IceGrid.Registry.Internal.Endpoints").empty()) { Error out(_communicator->getLogger()); out << "property `IceGrid.Registry.Internal.Endpoints' is not set"; return false; } if(!properties->getProperty("IceGrid.Registry.SessionManager.Endpoints").empty()) { if(!nowarn) { Warning out(_communicator->getLogger()); out << "session manager endpoints `IceGrid.Registry.SessionManager.Endpoints' enabled"; } } properties->setProperty("Ice.PrintProcessId", "0"); properties->setProperty("Ice.ServerIdleTime", "0"); properties->setProperty("IceGrid.Registry.Client.AdapterId", ""); properties->setProperty("IceGrid.Registry.Server.AdapterId", ""); properties->setProperty("IceGrid.Registry.SessionManager.AdapterId", ""); properties->setProperty("IceGrid.Registry.Internal.AdapterId", ""); setupThreadPool(properties, "Ice.ThreadPool.Client", 1, 100); setupThreadPool(properties, "IceGrid.Registry.Client.ThreadPool", 1, 10); setupThreadPool(properties, "IceGrid.Registry.Server.ThreadPool", 1, 10); setupThreadPool(properties, "IceGrid.Registry.SessionManager.ThreadPool", 1, 10); setupThreadPool(properties, "IceGrid.Registry.Internal.ThreadPool", 1, 100); _replicaName = properties->getPropertyWithDefault("IceGrid.Registry.ReplicaName", "Master"); _master = _replicaName == "Master"; _sessionTimeout = properties->getPropertyAsIntWithDefault("IceGrid.Registry.SessionTimeout", 30); // // Get the instance name // if(_master) { _instanceName = properties->getProperty("IceGrid.InstanceName"); if(_instanceName.empty()) { if(_communicator->getDefaultLocator()) { _instanceName = _communicator->getDefaultLocator()->ice_getIdentity().category; } else { _instanceName = "IceGrid"; } } } else { if(properties->getProperty("Ice.Default.Locator").empty()) { Error out(_communicator->getLogger()); out << "property `Ice.Default.Locator' is not set"; return false; } _instanceName = _communicator->getDefaultLocator()->ice_getIdentity().category; } // // Ensure that nothing is running on this port. This is also // useful to ensure that we don't run twice the same instance of // the service too (which would cause the database environment of // the already running instance to be "corrupted".) // try { string endpoints = properties->getProperty("IceGrid.Registry.Client.Endpoints"); string strPrx = _instanceName + "/Locator:" + endpoints; _communicator->stringToProxy(strPrx)->ice_timeout(5000)->ice_ping(); Error out(_communicator->getLogger()); out << "an IceGrid registry is already running and listening on the client endpoints `" << endpoints << "'"; return false; } catch(const Ice::LocalException&) { } properties->setProperty("Freeze.DbEnv.Registry.DbHome", dbPath); properties->setProperty("Freeze.DbEnv.Registry.DbPrivate", "0"); // // Create the reaper thread. // _reaper = new ReapThread(); _reaper->start(); // // Create the internal registry object adapter. // ObjectAdapterPtr registryAdapter = _communicator->createObjectAdapter("IceGrid.Registry.Internal"); registryAdapter->activate(); // // Create the internal IceStorm service. // Identity registryTopicManagerId; registryTopicManagerId.category = _instanceName; registryTopicManagerId.name = "RegistryTopicManager"; _iceStorm = IceStorm::Service::create(_communicator, registryAdapter, registryAdapter, "IceGrid.Registry", registryTopicManagerId, "Registry"); const IceStorm::TopicManagerPrx topicManager = _iceStorm->getTopicManager(); // // Create the registry database. // _database = new Database(registryAdapter, topicManager, _instanceName, _traceLevels, getInfo()); _wellKnownObjects = new WellKnownObjectsManager(_database); // // Get the saved replica/node proxies and remove them from the // database. // Ice::ObjectProxySeq proxies; Ice::ObjectProxySeq::const_iterator p; NodePrxSeq nodes; proxies = _database->getInternalObjectsByType(Node::ice_staticId()); for(p = proxies.begin(); p != proxies.end(); ++p) { nodes.push_back(NodePrx::uncheckedCast(*p)); } InternalRegistryPrxSeq replicas; proxies = _database->getObjectsByType(InternalRegistry::ice_staticId()); for(p = proxies.begin(); p != proxies.end(); ++p) { replicas.push_back(InternalRegistryPrx::uncheckedCast(*p)); } // // NOTE: The internal registry object must be added only once the // node/replica proxies are retrieved and removed from the // database. Otherwise, if some replica/node register as soon as // the internal registry is setup we might clear valid proxies. // InternalRegistryPrx internalRegistry = setupInternalRegistry(registryAdapter); if(_master) { nodes = registerReplicas(internalRegistry, replicas, nodes); registerNodes(internalRegistry, nodes); } else { InternalReplicaInfoPtr info = _platform.getInternalReplicaInfo(); _session.create(_replicaName, info, _database, _wellKnownObjects, internalRegistry); registerNodes(internalRegistry, _session.getNodes(nodes)); } ObjectAdapterPtr serverAdapter = _communicator->createObjectAdapter("IceGrid.Registry.Server"); _clientAdapter = _communicator->createObjectAdapter("IceGrid.Registry.Client"); ObjectAdapterPtr sessionManagerAdapter; if(!properties->getProperty("IceGrid.Registry.SessionManager.Endpoints").empty()) { sessionManagerAdapter = _communicator->createObjectAdapter("IceGrid.Registry.SessionManager"); } Ice::Identity dummy; dummy.name = "dummy"; _wellKnownObjects->addEndpoint("Client", _clientAdapter->createDirectProxy(dummy)); _wellKnownObjects->addEndpoint("Server", serverAdapter->createDirectProxy(dummy)); if(sessionManagerAdapter) { _wellKnownObjects->addEndpoint("SessionManager", sessionManagerAdapter->createDirectProxy(dummy)); } _wellKnownObjects->addEndpoint("Internal", registryAdapter->createDirectProxy(dummy)); setupNullPermissionsVerifier(registryAdapter); if(!setupUserAccountMapper(registryAdapter)) { return false; } QueryPrx query = setupQuery(_clientAdapter); RegistryPrx registry = setupRegistry(_clientAdapter); Ice::LocatorRegistryPrx locatorRegistry = setupLocatorRegistry(serverAdapter); LocatorPrx internalLocator = setupLocator(_clientAdapter, registryAdapter, locatorRegistry, registry, query); // // Add a default servant locator to the client object adapter. The // default servant ensure that request on session objects are from // the same connection as the connection that created the session. // _sessionServantLocator = new SessionServantLocatorI(_clientAdapter, _instanceName); _clientAdapter->addServantLocator(_sessionServantLocator, ""); setupClientSessionFactory(registryAdapter, sessionManagerAdapter, internalLocator, nowarn); setupAdminSessionFactory(registryAdapter, sessionManagerAdapter, internalLocator, nowarn); _wellKnownObjects->finish(); if(_master) { _wellKnownObjects->registerAll(); } else { _session.registerAllWellKnownObjects(); } // // We are ready to go! // serverAdapter->activate(); _clientAdapter->activate(); if(sessionManagerAdapter) { sessionManagerAdapter->activate(); } return true; }
Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const CommunicatorPtr& communicator, const ObjectAdapterFactoryPtr& objectAdapterFactory, const string& name, const string& endpointInfo, const RouterPrx& router, bool noConfig) : _deactivated(false), _instance(instance), _communicator(communicator), _objectAdapterFactory(objectAdapterFactory), _servantManager(new ServantManager(instance, name)), _activateOneOffDone(false), _name(name), _directCount(0), _waitForActivate(false), _destroying(false), _destroyed(false), _noConfig(noConfig), _threadPerConnection(false), _threadPerConnectionStackSize(0) { if(_noConfig) { return; } PropertiesPtr properties = instance->initializationData().properties; StringSeq unknownProps; bool noProps = filterProperties(unknownProps); // // Warn about unknown object adapter properties. // if(unknownProps.size() != 0 && properties->getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { Warning out(_instance->initializationData().logger); out << "found unknown properties for object adapter '" << _name << "':"; for(unsigned int i = 0; i < unknownProps.size(); ++i) { out << "\n " << unknownProps[i]; } } // // Make sure named adapter has some configuration // if(endpointInfo.empty() && router == 0 && noProps) { InitializationException ex(__FILE__, __LINE__); ex.reason = "object adapter \"" + _name + "\" requires configuration."; throw ex; } const_cast<string&>(_id) = properties->getProperty(_name + ".AdapterId"); const_cast<string&>(_replicaGroupId) = properties->getProperty(_name + ".ReplicaGroupId"); __setNoDelete(true); try { _threadPerConnection = properties->getPropertyAsInt(_name + ".ThreadPerConnection") > 0; int threadPoolSize = properties->getPropertyAsInt(_name + ".ThreadPool.Size"); int threadPoolSizeMax = properties->getPropertyAsInt(_name + ".ThreadPool.SizeMax"); if(_threadPerConnection && (threadPoolSize > 0 || threadPoolSizeMax > 0)) { InitializationException ex(__FILE__, __LINE__); ex.reason = "object adapter \"" + _name + "\" cannot be configured for both\n" "thread pool and thread per connection"; throw ex; } if(!_threadPerConnection && threadPoolSize == 0 && threadPoolSizeMax == 0) { _threadPerConnection = _instance->threadPerConnection(); } if(_threadPerConnection) { int stackSize = properties->getPropertyAsIntWithDefault(_name + ".ThreadPerConnection.StackSize", static_cast<Int>(_instance->threadPerConnectionStackSize())); if(stackSize < 0) { stackSize = 0; } _threadPerConnectionStackSize = stackSize; } // // Create the per-adapter thread pool, if necessary. This is done before the creation of the incoming // connection factory as the thread pool is needed during creation for the call to incFdsInUse. // if(threadPoolSize > 0 || threadPoolSizeMax > 0) { _threadPool = new ThreadPool(_instance, _name + ".ThreadPool", 0); } if(!router) { const_cast<RouterPrx&>(router) = RouterPrx::uncheckedCast( _instance->proxyFactory()->propertyToProxy(_name + ".Router")); } if(router) { _routerInfo = _instance->routerManager()->get(router); if(_routerInfo) { // // Make sure this router is not already registered with another adapter. // if(_routerInfo->getAdapter()) { throw AlreadyRegisteredException(__FILE__, __LINE__, "object adapter with router", _instance->identityToString(router->ice_getIdentity())); } // // Add the router's server proxy endpoints to this object // adapter. // vector<EndpointIPtr> endpoints = _routerInfo->getServerEndpoints(); copy(endpoints.begin(), endpoints.end(), back_inserter(_routerEndpoints)); sort(_routerEndpoints.begin(), _routerEndpoints.end()); // Must be sorted. _routerEndpoints.erase(unique(_routerEndpoints.begin(), _routerEndpoints.end()), _routerEndpoints.end()); // // Associate this object adapter with the router. This way, // new outgoing connections to the router's client proxy will // use this object adapter for callbacks. // _routerInfo->setAdapter(this); // // Also modify all existing outgoing connections to the // router's client proxy to use this object adapter for // callbacks. // _instance->outgoingConnectionFactory()->setRouterInfo(_routerInfo); } } else { // // Parse the endpoints, but don't store them in the adapter. // The connection factory might change it, for example, to // fill in the real port number. // vector<EndpointIPtr> endpoints; if(endpointInfo.empty()) { endpoints = parseEndpoints(properties->getProperty(_name + ".Endpoints")); } else { endpoints = parseEndpoints(endpointInfo); } for(vector<EndpointIPtr>::iterator p = endpoints.begin(); p != endpoints.end(); ++p) { _incomingConnectionFactories.push_back(new IncomingConnectionFactory(instance, *p, this, _name)); } if(endpoints.empty()) { TraceLevelsPtr tl = _instance->traceLevels(); if(tl->network >= 2) { Trace out(_instance->initializationData().logger, tl->networkCat); out << "created adapter `" << name << "' without endpoints"; } } // // Parse published endpoints. If set, these are used in proxies // instead of the connection factory endpoints. // string endpts = properties->getProperty(_name + ".PublishedEndpoints"); _publishedEndpoints = parseEndpoints(endpts); if(_publishedEndpoints.empty()) { transform(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), back_inserter(_publishedEndpoints), Ice::constMemFun(&IncomingConnectionFactory::endpoint)); } // // Filter out any endpoints that are not meant to be published. // _publishedEndpoints.erase(remove_if(_publishedEndpoints.begin(), _publishedEndpoints.end(), not1(Ice::constMemFun(&EndpointI::publish))), _publishedEndpoints.end()); } if(!properties->getProperty(_name + ".Locator").empty()) { setLocator(LocatorPrx::uncheckedCast(_instance->proxyFactory()->propertyToProxy(_name + ".Locator"))); } else { setLocator(_instance->referenceFactory()->getDefaultLocator()); } } catch(...) { destroy(); __setNoDelete(false); throw; } __setNoDelete(false); }
bool RegistryI::startImpl() { assert(_communicator); PropertiesPtr properties = _communicator->getProperties(); // // Check that required properties are set and valid. // if(properties->getProperty("IceGrid.Registry.Client.Endpoints").empty()) { Error out(_communicator->getLogger()); out << "property `IceGrid.Registry.Client.Endpoints' is not set"; return false; } if(properties->getProperty("IceGrid.Registry.Server.Endpoints").empty()) { Error out(_communicator->getLogger()); out << "property `IceGrid.Registry.Server.Endpoints' is not set"; return false; } if(properties->getProperty("IceGrid.Registry.Internal.Endpoints").empty()) { Error out(_communicator->getLogger()); out << "property `IceGrid.Registry.Internal.Endpoints' is not set"; return false; } if(!properties->getProperty("IceGrid.Registry.SessionManager.Endpoints").empty()) { if(!_nowarn) { Warning out(_communicator->getLogger()); out << "session manager endpoints `IceGrid.Registry.SessionManager.Endpoints' enabled"; if(properties->getPropertyAsInt("IceGrid.Registry.SessionFilters") == 0) { out << " (with Glacier2 filters disabled)"; } } } if(!properties->getProperty("IceGrid.Registry.AdminSessionManager.Endpoints").empty()) { if(!_nowarn) { Warning out(_communicator->getLogger()); out << "administrative session manager endpoints `IceGrid.Registry.AdminSessionManager.Endpoints' enabled"; if(properties->getPropertyAsInt("IceGrid.Registry.AdminSessionFilters") == 0) { out << " (with Glacier2 filters disabled)"; } } } properties->setProperty("Ice.PrintProcessId", "0"); properties->setProperty("Ice.ServerIdleTime", "0"); properties->setProperty("IceGrid.Registry.Client.AdapterId", ""); properties->setProperty("IceGrid.Registry.Server.AdapterId", ""); properties->setProperty("IceGrid.Registry.SessionManager.AdapterId", ""); properties->setProperty("IceGrid.Registry.Internal.AdapterId", ""); setupThreadPool(properties, "IceGrid.Registry.Client.ThreadPool", 1, 10); setupThreadPool(properties, "IceGrid.Registry.Server.ThreadPool", 1, 10, true); // Serialize for admin callbacks setupThreadPool(properties, "IceGrid.Registry.SessionManager.ThreadPool", 1, 10); setupThreadPool(properties, "IceGrid.Registry.Internal.ThreadPool", 1, 100); _replicaName = properties->getPropertyWithDefault("IceGrid.Registry.ReplicaName", "Master"); _master = _replicaName == "Master"; _sessionTimeout = properties->getPropertyAsIntWithDefault("IceGrid.Registry.SessionTimeout", 30); if(!_master && properties->getProperty("Ice.Default.Locator").empty()) { if(properties->getProperty("Ice.Default.Locator").empty()) { Error out(_communicator->getLogger()); out << "property `Ice.Default.Locator' is not set"; return false; } } // // Get the instance name // if(_master) { _instanceName = properties->getProperty("IceGrid.InstanceName"); if(_instanceName.empty()) { if(_communicator->getDefaultLocator()) { _instanceName = _communicator->getDefaultLocator()->ice_getIdentity().category; } else { _instanceName = "IceGrid"; } } } else { _instanceName = _communicator->getDefaultLocator()->ice_getIdentity().category; } // // Ensure that nothing is running on this port. This is also // useful to ensure that we don't run twice the same instance of // the service too (which would cause the database environment of // the already running instance to be "corrupted".) // try { string endpoints = properties->getProperty("IceGrid.Registry.Client.Endpoints"); string strPrx = _instanceName + "/Locator:" + endpoints; _communicator->stringToProxy(strPrx)->ice_timeout(5000)->ice_ping(); Error out(_communicator->getLogger()); out << "an IceGrid registry is already running and listening on the client endpoints `" << endpoints << "'"; return false; } catch(const Ice::LocalException&) { } // // Create the reaper thread. // _reaper = new ReapThread(); _reaper->start(); // // Create the internal registry object adapter. // ObjectAdapterPtr registryAdapter = _communicator->createObjectAdapter("IceGrid.Registry.Internal"); registryAdapter->activate(); // // Create the internal IceStorm service. // Identity registryTopicManagerId; registryTopicManagerId.category = _instanceName; registryTopicManagerId.name = "RegistryTopicManager"; _iceStorm = IceStormInternal::Service::create(_communicator, registryAdapter, registryAdapter, "IceGrid.Registry", registryTopicManagerId, "Registry"); const IceStorm::TopicManagerPrx topicManager = _iceStorm->getTopicManager(); // // Create the registry database. // DatabasePluginPtr plugin; try { plugin = DatabasePluginPtr::dynamicCast(_communicator->getPluginManager()->getPlugin("DB")); } catch(const NotRegisteredException&) { } if(!plugin) { Error out(_communicator->getLogger()); out << "no database plugin configured with `Ice.Plugin.DB' or plugin is not a database plugin"; return false; } _database = new Database(registryAdapter, topicManager, _instanceName, _traceLevels, getInfo(), plugin, _readonly); _wellKnownObjects = new WellKnownObjectsManager(_database); // // Get the saved replica/node proxies. // ObjectProxySeq proxies; ObjectProxySeq::const_iterator p; NodePrxSeq nodes; proxies = _database->getInternalObjectsByType(Node::ice_staticId()); for(p = proxies.begin(); p != proxies.end(); ++p) { nodes.push_back(NodePrx::uncheckedCast(*p)); } InternalRegistryPrxSeq replicas; proxies = _database->getObjectsByType(InternalRegistry::ice_staticId()); for(p = proxies.begin(); p != proxies.end(); ++p) { replicas.push_back(InternalRegistryPrx::uncheckedCast(*p)); } // // NOTE: The internal registry object must be added only once the // node/replica proxies are retrieved. Otherwise, if some // replica/node register as soon as the internal registry is setup // we might clear valid proxies. // InternalRegistryPrx internalRegistry = setupInternalRegistry(registryAdapter); if(_master) { nodes = registerReplicas(internalRegistry, replicas, nodes); registerNodes(internalRegistry, nodes); } else { InternalReplicaInfoPtr info = _platform.getInternalReplicaInfo(); _session.create(_replicaName, info, _database, _wellKnownObjects, internalRegistry); registerNodes(internalRegistry, _session.getNodes(nodes)); } _serverAdapter = _communicator->createObjectAdapter("IceGrid.Registry.Server"); _clientAdapter = _communicator->createObjectAdapter("IceGrid.Registry.Client"); Ice::Identity dummy; dummy.name = "dummy"; _wellKnownObjects->addEndpoint("Client", _clientAdapter->createDirectProxy(dummy)); _wellKnownObjects->addEndpoint("Server", _serverAdapter->createDirectProxy(dummy)); _wellKnownObjects->addEndpoint("Internal", registryAdapter->createDirectProxy(dummy)); setupNullPermissionsVerifier(registryAdapter); if(!setupUserAccountMapper(registryAdapter)) { return false; } QueryPrx query = setupQuery(_clientAdapter); RegistryPrx registry = setupRegistry(_clientAdapter); Ice::LocatorRegistryPrx locatorRegistry = setupLocatorRegistry(_serverAdapter); LocatorPrx internalLocator = setupLocator(_clientAdapter, registryAdapter, locatorRegistry, registry, query); // // Create the session servant manager. The session servant manager is responsible // for managing sessions servants and to ensure that session servants are only // accessed by the connection that created the session. The session servant manager // also takes care of providing the router servant for server admin objects. // ObjectPtr serverAdminRouter = new RegistryServerAdminRouter(_database); AdminCallbackRouterPtr adminCallbackRouter = new AdminCallbackRouter; _servantManager = new SessionServantManager(_clientAdapter, _instanceName, true, getServerAdminCategory(), serverAdminRouter, adminCallbackRouter); _clientAdapter->addServantLocator(_servantManager, ""); _serverAdapter->addServantLocator(new DefaultServantLocator(adminCallbackRouter), ""); ObjectAdapterPtr sessionAdpt = setupClientSessionFactory(registryAdapter, internalLocator); ObjectAdapterPtr admSessionAdpt = setupAdminSessionFactory(registryAdapter, serverAdminRouter, internalLocator); _wellKnownObjects->finish(); if(_master) { _wellKnownObjects->registerAll(); } else { _session.registerAllWellKnownObjects(); } // // We are ready to go! // _serverAdapter->activate(); _clientAdapter->activate(); if(sessionAdpt) { sessionAdpt->activate(); } if(admSessionAdpt) { admSessionAdpt->activate(); } return true; }
void BowICETrainI::process(const Identity &client,const ::RunSet& runset, const TrainerProperties &tprops, const Current& current) { localAndClientMsg(VLogger::DEBUG, NULL, "starting BOW training process\n"); callbackPtr = TrainerCallbackHandlerPrx::uncheckedCast( current.con->createProxy(client)->ice_oneway()); localAndClientMsg( VLogger::DEBUG_2, callbackPtr, "starting BOW training process, got callback pointer\n"); PropertiesPtr props = (current.adapter->getCommunicator()->getProperties()); std::string CVAC_DataDir = props->getProperty("CVAC.DataDir"); // argument error checking: any data? consistent multiclass or pos/neg purpose? if (!checkPurposedLists( runset.purposedLists, callbackPtr )) return; DetectorDataArchive dda; bowCV* pBowCV = initialize(callbackPtr, tprops, dda, current); if ( NULL==pBowCV ) { localAndClientMsg(VLogger::ERROR, callbackPtr, "Trainer not initialized, aborting.\n"); return; } // Ingest the data for processing, one purposed list at a time. // Also, determine if the classIDs match nicely to the labels; // if so, add appropriate annotations into the trained model file. LabelMap labelmap; bool labelsMatch = true; for (size_t listidx = 0; listidx < runset.purposedLists.size(); listidx++) { processPurposedList( runset.purposedLists[listidx], pBowCV, callbackPtr, CVAC_DataDir, labelmap, &labelsMatch ); } if ( !labelsMatch ) labelmap.clear(); if ( !hasUniqueLabels(labelmap) ) labelmap.clear(); // create a sandbox for this client std::string connectName = cvac::getClientConnectionName(current); std::string clientName = mServiceMan->getSandbox()->createClientName( mServiceMan->getServiceName(), connectName); std::string tTempDir = mServiceMan->getSandbox()->createTrainingDir(clientName); // TODO: when should this tTempDir be deleted? localAndClientMsg(VLogger::INFO, callbackPtr, "Starting actual training procedure...\n"); // Tell ServiceManager that we will listen for stop mServiceMan->setStoppable(); // // run the actual training procedure on the previously ingested data; // this sets the pBowCV to point to files that it created, // and it adds some properties directly to the DDA // bool fTrain = pBowCV->train_run(tTempDir, mServiceMan); // Tell ServiceManager that we are done listening for stop mServiceMan->clearStop(); if(!fTrain) { deleteDirectory(tTempDir); localAndClientMsg(VLogger::ERROR, callbackPtr, "Error during the training of BoW.\n"); return; } // create the archive of the trained model FilePath trainedModel = createArchive( dda, pBowCV, labelmap, clientName, CVAC_DataDir, tTempDir ); callbackPtr->createdDetector(trainedModel); delete pBowCV; pBowCV = NULL; localAndClientMsg(VLogger::INFO, callbackPtr, "Training procedure completed.\n"); }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { IceUtilInternal::Options opts; opts.addOpt("", "cycle"); try { opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( communicator->stringToProxy(managerProxy)); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } TopicPrx topic; while(true) { try { topic = manager->retrieve("single"); break; } // This can happen if the replica group loses the majority // during retrieve. In this case we retry. catch(const Ice::UnknownException&) { continue; } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } } assert(topic); // // Get a publisher object, create a twoway proxy and then cast to // a Single object. // if(opts.isSet("cycle")) { Ice::ObjectPrx prx = topic->getPublisher()->ice_twoway(); vector<SinglePrx> single; Ice::EndpointSeq endpoints = prx->ice_getEndpoints(); for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { if((*p)->toString().substr(0, 3) != "udp") { Ice::EndpointSeq e; e.push_back(*p); single.push_back(SinglePrx::uncheckedCast(prx->ice_endpoints(e))); } } if(single.size() <= 1) { cerr << argv[0] << ": Not enough endpoints in publisher proxy" << endl; return EXIT_FAILURE; } int which = 0; for(int i = 0; i < 1000; ++i) { single[which]->event(i); which = (which + 1) % static_cast<int>(single.size()); } } else { SinglePrx single = SinglePrx::uncheckedCast(topic->getPublisher()->ice_twoway()); for(int i = 0; i < 1000; ++i) { single->event(i); } } return EXIT_SUCCESS; }
int run(int, char* argv[], const CommunicatorPtr& communicator) { PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } ObjectPrx base = communicator->stringToProxy(managerProxy); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } TopicPrx fed1; try { fed1 = manager->retrieve("fed1"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } TopicPrx fed2; try { fed2 = manager->retrieve("fed2"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } TopicPrx fed3; try { fed3 = manager->retrieve("fed3"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } EventPrx eventFed1 = EventPrx::uncheckedCast(fed1->getPublisher()->ice_oneway()); EventPrx eventFed2 = EventPrx::uncheckedCast(fed2->getPublisher()->ice_oneway()); EventPrx eventFed3 = EventPrx::uncheckedCast(fed3->getPublisher()->ice_oneway()); Ice::Context context; int i; context["cost"] = "0"; for(i = 0; i < 10; ++i) { eventFed1->pub("fed1:0", context); } context["cost"] = "10"; for(i = 0; i < 10; ++i) { eventFed1->pub("fed1:10", context); } context["cost"] = "15"; for(i = 0; i < 10; ++i) { eventFed1->pub("fed1:15", context); } context["cost"] = "0"; for(i = 0; i < 10; ++i) { eventFed2->pub("fed2:0", context); } context["cost"] = "5"; for(i = 0; i < 10; ++i) { eventFed2->pub("fed2:5", context); } context["cost"] = "0"; for(i = 0; i < 10; ++i) { eventFed3->pub("fed3:0", context); } // // Before we exit, we ping all proxies as twoway, to make sure // that all oneways are delivered. // EventPrx::uncheckedCast(eventFed1->ice_twoway())->ice_ping(); EventPrx::uncheckedCast(eventFed2->ice_twoway())->ice_ping(); EventPrx::uncheckedCast(eventFed3->ice_twoway())->ice_ping(); return EXIT_SUCCESS; }
IceInternal::ThreadPool::ThreadPool(const InstancePtr& instance, const string& prefix, int timeout) : _instance(instance), _dispatcher(_instance->initializationData().dispatcher), _destroyed(false), _prefix(prefix), _selector(instance), _nextThreadId(0), _size(0), _sizeIO(0), _sizeMax(0), _sizeWarn(0), _serialize(_instance->initializationData().properties->getPropertyAsInt(_prefix + ".Serialize") > 0), _hasPriority(false), _priority(0), _serverIdleTime(timeout), _threadIdleTime(0), _stackSize(0), _inUse(0), #if !defined(ICE_USE_IOCP) && !defined(ICE_OS_WINRT) _inUseIO(0), _nextHandler(_handlers.end()), #endif _promote(true) { PropertiesPtr properties = _instance->initializationData().properties; #ifndef ICE_OS_WINRT # ifdef _WIN32 SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); int nProcessors = sysInfo.dwNumberOfProcessors; # else int nProcessors = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN)); # endif #endif // // We use just one thread as the default. This is the fastest // possible setting, still allows one level of nesting, and // doesn't require to make the servants thread safe. // int size = properties->getPropertyAsIntWithDefault(_prefix + ".Size", 1); if(size < 1) { Warning out(_instance->initializationData().logger); out << _prefix << ".Size < 1; Size adjusted to 1"; size = 1; } int sizeMax = properties->getPropertyAsIntWithDefault(_prefix + ".SizeMax", size); #ifndef ICE_OS_WINRT if(sizeMax == -1) { sizeMax = nProcessors; } #endif if(sizeMax < size) { Warning out(_instance->initializationData().logger); out << _prefix << ".SizeMax < " << _prefix << ".Size; SizeMax adjusted to Size (" << size << ")"; sizeMax = size; } int sizeWarn = properties->getPropertyAsInt(_prefix + ".SizeWarn"); if(sizeWarn != 0 && sizeWarn < size) { Warning out(_instance->initializationData().logger); out << _prefix << ".SizeWarn < " << _prefix << ".Size; adjusted SizeWarn to Size (" << size << ")"; sizeWarn = size; } else if(sizeWarn > sizeMax) { Warning out(_instance->initializationData().logger); out << _prefix << ".SizeWarn > " << _prefix << ".SizeMax; adjusted SizeWarn to SizeMax (" << sizeMax << ")"; sizeWarn = sizeMax; } int threadIdleTime = properties->getPropertyAsIntWithDefault(_prefix + ".ThreadIdleTime", 60); if(threadIdleTime < 0) { Warning out(_instance->initializationData().logger); out << _prefix << ".ThreadIdleTime < 0; ThreadIdleTime adjusted to 0"; threadIdleTime = 0; } const_cast<int&>(_size) = size; const_cast<int&>(_sizeMax) = sizeMax; const_cast<int&>(_sizeWarn) = sizeWarn; #ifndef ICE_OS_WINRT const_cast<int&>(_sizeIO) = min(sizeMax, nProcessors); #else const_cast<int&>(_sizeIO) = sizeMax; #endif const_cast<int&>(_threadIdleTime) = threadIdleTime; #ifdef ICE_USE_IOCP _selector.setup(_sizeIO); #endif int stackSize = properties->getPropertyAsInt(_prefix + ".StackSize"); if(stackSize < 0) { Warning out(_instance->initializationData().logger); out << _prefix << ".StackSize < 0; Size adjusted to OS default"; stackSize = 0; } const_cast<size_t&>(_stackSize) = static_cast<size_t>(stackSize); const_cast<bool&>(_hasPriority) = properties->getProperty(_prefix + ".ThreadPriority") != ""; const_cast<int&>(_priority) = properties->getPropertyAsInt(_prefix + ".ThreadPriority"); if(!_hasPriority) { const_cast<bool&>(_hasPriority) = properties->getProperty("Ice.ThreadPriority") != ""; const_cast<int&>(_priority) = properties->getPropertyAsInt("Ice.ThreadPriority"); } _workQueue = new ThreadPoolWorkQueue(_instance, _selector); if(_instance->traceLevels()->threadPool >= 1) { Trace out(_instance->initializationData().logger, _instance->traceLevels()->threadPoolCat); out << "creating " << _prefix << ": Size = " << _size << ", SizeMax = " << _sizeMax << ", SizeWarn = " << _sizeWarn; } __setNoDelete(true); try { for(int i = 0 ; i < _size ; ++i) { EventHandlerThreadPtr thread = new EventHandlerThread(this, nextThreadId()); if(_hasPriority) { thread->start(_stackSize, _priority); } else { thread->start(_stackSize); } _threads.insert(thread); } } catch(const IceUtil::Exception& ex) { { Error out(_instance->initializationData().logger); out << "cannot create thread for `" << _prefix << "':\n" << ex; } destroy(); joinWithAllThreads(); __setNoDelete(false); throw; } catch(...) { __setNoDelete(false); throw; } __setNoDelete(false); }
void Ice::ObjectAdapterI::initialize(const RouterPrx& router) { if(_noConfig) { _reference = _instance->referenceFactory()->create("dummy -t", ""); return; } PropertiesPtr properties = _instance->initializationData().properties; StringSeq unknownProps; bool noProps = filterProperties(unknownProps); // // Warn about unknown object adapter properties. // if(unknownProps.size() != 0 && properties->getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0) { Warning out(_instance->initializationData().logger); out << "found unknown properties for object adapter `" << _name << "':"; for(unsigned int i = 0; i < unknownProps.size(); ++i) { out << "\n " << unknownProps[i]; } } try { // // Make sure named adapter has some configuration // if(router == 0 && noProps) { InitializationException ex(__FILE__, __LINE__); ex.reason = "object adapter `" + _name + "' requires configuration"; throw ex; } const_cast<string&>(_id) = properties->getProperty(_name + ".AdapterId"); const_cast<string&>(_replicaGroupId) = properties->getProperty(_name + ".ReplicaGroupId"); // // Setup a reference to be used to get the default proxy options // when creating new proxies. By default, create twoway proxies. // string proxyOptions = properties->getPropertyWithDefault(_name + ".ProxyOptions", "-t"); try { _reference = _instance->referenceFactory()->create("dummy " + proxyOptions, ""); } catch(const ProxyParseException&) { InitializationException ex(__FILE__, __LINE__); ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'"; throw ex; } int threadPoolSize = properties->getPropertyAsInt(_name + ".ThreadPool.Size"); int threadPoolSizeMax = properties->getPropertyAsInt(_name + ".ThreadPool.SizeMax"); bool hasPriority = properties->getProperty(_name + ".ThreadPool.ThreadPriority") != ""; // // Create the per-adapter thread pool, if necessary. This is done before the creation of the incoming // connection factory as the thread pool is needed during creation for the call to incFdsInUse. // if(threadPoolSize > 0 || threadPoolSizeMax > 0 || hasPriority) { _threadPool = new ThreadPool(_instance, _name + ".ThreadPool", 0); } _hasAcmTimeout = properties->getProperty(_name + ".ACM") != ""; if(_hasAcmTimeout) { _acmTimeout = properties->getPropertyAsInt(_name + ".ACM"); _instance->connectionMonitor()->checkIntervalForACM(_acmTimeout); } if(!router) { const_cast<RouterPrx&>(router) = RouterPrx::uncheckedCast( _instance->proxyFactory()->propertyToProxy(_name + ".Router")); } if(router) { _routerInfo = _instance->routerManager()->get(router); if(_routerInfo) { // // Make sure this router is not already registered with another adapter. // if(_routerInfo->getAdapter()) { throw AlreadyRegisteredException(__FILE__, __LINE__, "object adapter with router", _instance->identityToString(router->ice_getIdentity())); } // // Add the router's server proxy endpoints to this object // adapter. // vector<EndpointIPtr> endpoints = _routerInfo->getServerEndpoints(); copy(endpoints.begin(), endpoints.end(), back_inserter(_routerEndpoints)); sort(_routerEndpoints.begin(), _routerEndpoints.end()); // Must be sorted. _routerEndpoints.erase(unique(_routerEndpoints.begin(), _routerEndpoints.end()), _routerEndpoints.end()); // // Associate this object adapter with the router. This way, // new outgoing connections to the router's client proxy will // use this object adapter for callbacks. // _routerInfo->setAdapter(this); // // Also modify all existing outgoing connections to the // router's client proxy to use this object adapter for // callbacks. // _instance->outgoingConnectionFactory()->setRouterInfo(_routerInfo); } } else { // // Parse the endpoints, but don't store them in the adapter. // The connection factory might change it, for example, to // fill in the real port number. // vector<EndpointIPtr> endpoints = parseEndpoints(properties->getProperty(_name + ".Endpoints"), true); for(vector<EndpointIPtr>::iterator p = endpoints.begin(); p != endpoints.end(); ++p) { IncomingConnectionFactoryPtr factory = new IncomingConnectionFactory(_instance, *p, this); factory->initialize(_name); _incomingConnectionFactories.push_back(factory); } if(endpoints.empty()) { TraceLevelsPtr tl = _instance->traceLevels(); if(tl->network >= 2) { Trace out(_instance->initializationData().logger, tl->networkCat); out << "created adapter `" << _name << "' without endpoints"; } } // // Parse the published endpoints. // _publishedEndpoints = parsePublishedEndpoints(); } if(!properties->getProperty(_name + ".Locator").empty()) { setLocator(LocatorPrx::uncheckedCast(_instance->proxyFactory()->propertyToProxy(_name + ".Locator"))); } else { setLocator(_instance->referenceFactory()->getDefaultLocator()); } } catch(...) { destroy(); throw; } }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { bool batch = false; int idx = 1; while(idx < argc) { if(strcmp(argv[idx], "-b") == 0) { batch = true; for(int i = idx ; i + 1 < argc ; ++i) { argv[i] = argv[i + 1]; } --argc; } else if(strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) { usage(argv[0]); return EXIT_SUCCESS; } else if(argv[idx][0] == '-') { cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; usage(argv[0]); return EXIT_FAILURE; } } PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } ObjectPrx base = communicator->stringToProxy(managerProxy); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("SubscriberAdapter", "default"); EventIPtr eventFed1 = new EventI(communicator); // // Activate the servants. // ObjectPrx obj = adapter->addWithUUID(eventFed1); IceStorm::QoS qos; if(batch) { obj = obj->ice_batchOneway(); } else { obj = obj->ice_oneway(); } TopicPrx fed1; try { fed1 = manager->retrieve("fed1"); } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } fed1->subscribeAndGetPublisher(qos, obj); adapter->activate(); communicator->waitForShutdown(); fed1->unsubscribe(obj); return EXIT_SUCCESS; }
void ServiceI::start( const string& name, const CommunicatorPtr& communicator, const StringSeq& /*args*/) { PropertiesPtr properties = communicator->getProperties(); validateProperties(name, properties, communicator->getLogger()); int id = properties->getPropertyAsIntWithDefault(name + ".NodeId", -1); // If we are using a replicated deployment and if the topic // manager thread pool max size is not set then ensure it is set // to some suitably high number. This ensures no deadlocks in the // replicated case due to call forwarding from replicas to // coordinators. if(id != -1 && properties->getProperty(name + ".TopicManager.ThreadPool.SizeMax").empty()) { properties->setProperty(name + ".TopicManager.ThreadPool.SizeMax", "100"); } Ice::ObjectAdapterPtr topicAdapter = communicator->createObjectAdapter(name + ".TopicManager"); Ice::ObjectAdapterPtr publishAdapter = communicator->createObjectAdapter(name + ".Publish"); // // We use the name of the service for the name of the database environment. // string instanceName = properties->getPropertyWithDefault(name + ".InstanceName", "IceStorm"); Identity topicManagerId; topicManagerId.category = instanceName; topicManagerId.name = "TopicManager"; if(properties->getPropertyAsIntWithDefault(name+ ".Transient", 0) > 0) { _instance = new Instance(instanceName, name, communicator, publishAdapter, topicAdapter, 0); try { TransientTopicManagerImplPtr manager = new TransientTopicManagerImpl(_instance); _managerProxy = TopicManagerPrx::uncheckedCast(topicAdapter->add(manager, topicManagerId)); } catch(const Ice::Exception& ex) { _instance = 0; LoggerOutputBase s; s << "exception while starting IceStorm service " << name << ":\n"; s << ex; IceBox::FailureException e(__FILE__, __LINE__); e.reason = s.str(); throw e; } topicAdapter->activate(); publishAdapter->activate(); return; } if(id == -1) // No replication. { _instance = new Instance(instanceName, name, communicator, publishAdapter, topicAdapter); try { _manager = new TopicManagerImpl(_instance); _managerProxy = TopicManagerPrx::uncheckedCast(topicAdapter->add(_manager->getServant(), topicManagerId)); } catch(const Ice::Exception& ex) { _instance = 0; LoggerOutputBase s; s << "exception while starting IceStorm service " << name << ":\n"; s << ex; IceBox::FailureException e(__FILE__, __LINE__); e.reason = s.str(); throw e; } } else { // Here we want to create a map of id -> election node // proxies. map<int, NodePrx> nodes; string topicManagerAdapterId = properties->getProperty(name + ".TopicManager.AdapterId"); // We support two possible deployments. The first is a manual // deployment, the second is IceGrid. // // Here we check for the manual deployment const string prefix = name + ".Nodes."; Ice::PropertyDict props = properties->getPropertiesForPrefix(prefix); if(!props.empty()) { for(Ice::PropertyDict::const_iterator p = props.begin(); p != props.end(); ++p) { int nodeid = atoi(p->first.substr(prefix.size()).c_str()); nodes[nodeid] = NodePrx::uncheckedCast(communicator->propertyToProxy(p->first)); } } else { // If adapter id's are defined for the topic manager or // node adapters then we consider this an IceGrid based // deployment. string nodeAdapterId = properties->getProperty(name + ".Node.AdapterId"); // Validate first that the adapter ids match for the node // and the topic manager otherwise some other deployment // is being used. const string suffix = ".TopicManager"; if(topicManagerAdapterId.empty() || nodeAdapterId.empty() || topicManagerAdapterId.replace( topicManagerAdapterId.find(suffix), suffix.size(), ".Node") != nodeAdapterId) { Ice::Error error(communicator->getLogger()); error << "deployment error: `" << topicManagerAdapterId << "' prefix does not match `" << nodeAdapterId << "'"; throw IceBox::FailureException(__FILE__, __LINE__, "IceGrid deployment is incorrect"); } // Determine the set of node id and node proxies. // // This is determined by locating all topic manager // replicas, and then working out the node for that // replica. // // We work out the node id by removing the instance // name. The node id must follow. // IceGrid::LocatorPrx locator = IceGrid::LocatorPrx::checkedCast(communicator->getDefaultLocator()); assert(locator); IceGrid::QueryPrx query = locator->getLocalQuery(); Ice::ObjectProxySeq replicas = query->findAllReplicas( communicator->stringToProxy(instanceName + "/TopicManager")); for(Ice::ObjectProxySeq::const_iterator p = replicas.begin(); p != replicas.end(); ++p) { string adapterid = (*p)->ice_getAdapterId(); // Replace TopicManager with the node endpoint. adapterid = adapterid.replace(adapterid.find(suffix), suffix.size(), ".Node"); // The adapter id must start with the instance name. if(adapterid.find(instanceName) != 0) { Ice::Error error(communicator->getLogger()); error << "deployment error: `" << adapterid << "' does not start with `" << instanceName << "'"; throw IceBox::FailureException(__FILE__, __LINE__, "IceGrid deployment is incorrect"); } // The node id follows. We find the first digit (the // start of the node id, and then the end of the // digits). string::size_type start = instanceName.size(); while(start < adapterid.size() && !IceUtilInternal::isDigit(adapterid[start])) { ++start; } string::size_type end = start; while(end < adapterid.size() && IceUtilInternal::isDigit(adapterid[end])) { ++end; } if(start == end) { // We must have at least one digit, otherwise there is // some sort of deployment error. Ice::Error error(communicator->getLogger()); error << "deployment error: node id does not follow instance name. instance name:" << instanceName << " adapter id: " << adapterid; throw IceBox::FailureException(__FILE__, __LINE__, "IceGrid deployment is incorrect"); } int nodeid = atoi(adapterid.substr(start, end-start).c_str()); ostringstream os; os << "node" << nodeid; Ice::Identity id; id.category = instanceName; id.name = os.str(); nodes[nodeid] = NodePrx::uncheckedCast((*p)->ice_adapterId(adapterid)->ice_identity(id)); } } if(nodes.size() < 3) { Ice::Error error(communicator->getLogger()); error << "Replication requires at least 3 Nodes"; throw IceBox::FailureException(__FILE__, __LINE__, "Replication requires at least 3 Nodes"); } try { // If the node thread pool size is not set then initialize // to the number of nodes + 1 and disable thread pool size // warnings. if(properties->getProperty(name + ".Node.ThreadPool.Size").empty()) { ostringstream os; os << nodes.size() + 1; properties->setProperty(name + ".Node.ThreadPool.Size", os.str()); properties->setProperty(name + ".Node.ThreadPool.SizeWarn", "0"); } if(properties->getProperty(name + ".Node.MessageSizeMax").empty()) { properties->setProperty(name + ".Node.MessageSizeMax", "0"); // No limit on data exchanged internally } Ice::ObjectAdapterPtr nodeAdapter = communicator->createObjectAdapter(name + ".Node"); _instance = new Instance(instanceName, name, communicator, publishAdapter, topicAdapter, nodeAdapter, nodes[id]); _instance->observers()->setMajority(static_cast<unsigned int>(nodes.size())/2); // Trace replication information. TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->election > 0) { Ice::Trace out(traceLevels->logger, traceLevels->electionCat); out << "I am node " << id << "\n"; for(map<int, NodePrx>::const_iterator p = nodes.begin(); p != nodes.end(); ++p) { out << "\tnode: " << p->first << " proxy: " << p->second->ice_toString() << "\n"; } } if(topicManagerAdapterId.empty()) { // We're not using an IceGrid deployment. Here we need // a proxy which is used to create proxies to the // replicas later. _managerProxy = TopicManagerPrx::uncheckedCast(topicAdapter->createProxy(topicManagerId)); } else { // If we're using IceGrid deployment we need to create // indirect proxies. _managerProxy = TopicManagerPrx::uncheckedCast(topicAdapter->createIndirectProxy(topicManagerId)); } _manager = new TopicManagerImpl(_instance); topicAdapter->add(_manager->getServant(), topicManagerId); ostringstream os; // The node object identity. os << "node" << id; Ice::Identity nodeid; nodeid.category = instanceName; nodeid.name = os.str(); NodeIPtr node = new NodeI(_instance, _manager, _managerProxy, id, nodes); _instance->setNode(node); nodeAdapter->add(node, nodeid); nodeAdapter->activate(); node->start(); } catch(const Ice::Exception& ex) { _instance = 0; LoggerOutputBase s; s << "exception while starting IceStorm service " << name << ":\n"; s << ex; IceBox::FailureException e(__FILE__, __LINE__); e.reason = s.str(); throw e; } } topicAdapter->add(new FinderI(TopicManagerPrx::uncheckedCast(topicAdapter->createProxy(topicManagerId))), communicator->stringToIdentity("IceStorm/Finder")); topicAdapter->activate(); publishAdapter->activate(); }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { IceUtilInternal::Options opts; opts.addOpt("", "ordered"); opts.addOpt("", "twoway"); opts.addOpt("", "events", IceUtilInternal::Options::NeedArg); try { opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } ObjectPrx base = communicator->stringToProxy(managerProxy); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("SingleAdapter", "default"); TopicPrx topic; while(true) { try { topic = manager->retrieve("single"); break; } // This can happen if the replica group loses the majority // during retrieve. In this case we retry. catch(const Ice::UnknownException&) { continue; } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } } int events = 1000; if(opts.isSet("events")) { events = atoi(opts.optArg("events").c_str()); } // // Create subscribers with different QoS. // SingleIPtr sub; IceStorm::QoS qos; if(opts.isSet("ordered")) { sub = new SingleI(communicator, "twoway ordered", events); qos["reliability"] = "ordered"; } else { sub = new SingleI(communicator, "twoway", events); } Ice::ObjectPrx prx = adapter->addWithUUID(sub); while(true) { try { topic->subscribeAndGetPublisher(qos, prx); break; } // If we're already subscribed then we're done (previously we // got an UnknownException which succeeded). catch(const IceStorm::AlreadySubscribed&) { break; } // This can happen if the replica group loses the majority // during subscription. In this case we retry. catch(const Ice::UnknownException&) { } } adapter->activate(); sub->waitForEvents(); topic->unsubscribe(prx); return EXIT_SUCCESS; }