diff --git a/ChaosDataService/QueryDataConsumer.cpp b/ChaosDataService/QueryDataConsumer.cpp index 42b74b22c1d3a06484b42db235a0d2fc7c4c6cbf..b2381a13108e96121a5b0e59f07624f8672acb0c 100644 --- a/ChaosDataService/QueryDataConsumer.cpp +++ b/ChaosDataService/QueryDataConsumer.cpp @@ -112,7 +112,7 @@ void QueryDataConsumer::init(void *init_data) throw (chaos::CException) { db_impl_name, network_broker); if(!snapshot_data_worker) throw chaos::CException(-5, "Error allocating snapshot worker", __FUNCTION__); - chaos::utility::StartableService::initImplementation(query_engine, init_data, "QueryEngine", __PRETTY_FUNCTION__); + chaos::utility::StartableService::initImplementation(snapshot_data_worker, init_data, "SnapshotCreationWorker", __PRETTY_FUNCTION__); for(CacheServerListIterator iter = settings->startup_chache_servers.begin(); iter != settings->startup_chache_servers.end(); iter++) { diff --git a/ChaosSnapshotUtility/ChaosSnapshotUtility.xcodeproj/project.pbxproj b/ChaosSnapshotUtility/ChaosSnapshotUtility.xcodeproj/project.pbxproj index 92b128dca0b62f233b372bf194842ebd19b4f678..a3048933c4890695f11e34dec2a371db10ca00df 100644 --- a/ChaosSnapshotUtility/ChaosSnapshotUtility.xcodeproj/project.pbxproj +++ b/ChaosSnapshotUtility/ChaosSnapshotUtility.xcodeproj/project.pbxproj @@ -204,6 +204,32 @@ 323E66681A1E40CC009CDDB7 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; + CLANG_CXX_LIBRARY = "libstdc++"; + CONFIGURATION_BUILD_DIR = "$(SRCROOT)/../../usr/local/bin"; + HEADER_SEARCH_PATHS = ( + ../../, + /usr/local/include, + ../../usr/local/include, + ); + LIBRARY_SEARCH_PATHS = ( + /usr/local/lib, + "$(SRCROOT)/../../usr/local/lib", + ); + OTHER_LDFLAGS = ( + "-lboost_chrono", + "-lmemcached", + "-lboost_system", + "-lboost_thread", + "-lboost_program_options", + "-lboost_regex", + "-lboost_filesystem", + "-lboost_log", + "-lboost_log_setup", + "-lchaos_uitoolkit", + "-lchaos_common", + "-lboost_date_time", + ); PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -211,6 +237,32 @@ 323E66691A1E40CC009CDDB7 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; + CLANG_CXX_LIBRARY = "libstdc++"; + CONFIGURATION_BUILD_DIR = "$(SRCROOT)/../../usr/local/bin"; + HEADER_SEARCH_PATHS = ( + ../../, + /usr/local/include, + ../../usr/local/include, + ); + LIBRARY_SEARCH_PATHS = ( + /usr/local/lib, + "$(SRCROOT)/../../usr/local/lib", + ); + OTHER_LDFLAGS = ( + "-lboost_chrono", + "-lmemcached", + "-lboost_system", + "-lboost_thread", + "-lboost_program_options", + "-lboost_regex", + "-lboost_filesystem", + "-lboost_log", + "-lboost_log_setup", + "-lchaos_uitoolkit", + "-lchaos_common", + "-lboost_date_time", + ); PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/ChaosSnapshotUtility/main.cpp b/ChaosSnapshotUtility/main.cpp index 315eaa22c8819069741f9dd09df7a1fa6cd17a2d..01e10074538e479765fd33028ec9e9803e9f0e22 100644 --- a/ChaosSnapshotUtility/main.cpp +++ b/ChaosSnapshotUtility/main.cpp @@ -1,15 +1,82 @@ -// -// main.cpp -// ChaosSnapshotUtility -// -// Created by Claudio Bisegni on 20/11/14. -// Copyright (c) 2014 infn. All rights reserved. -// +/* + * main.cpp + * !CHOAS + * Created by Bisegni Claudio. + * + * Copyright 2014 INFN, National Institute of Nuclear Physics + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include <string> #include <iostream> -int main(int argc, const char * argv[]) { - // insert code here... - std::cout << "Hello, World!\n"; - return 0; +#include <chaos/ui_toolkit/ChaosUIToolkit.h> +#include <chaos/ui_toolkit/LowLevelApi/LLRpcApi.h> +#include <chaos/ui_toolkit/HighLevelApi/HLDataApi.h> + +#define OPT_CU_ID "device-id" +#define OPT_CDS_ADDRESS "cds-address" +#define OPT_SNAP_NAME "snapshot-name" +#define OPT_SNAPSHOT_OP "op" + +using namespace chaos; +using namespace chaos::ui; + +int main(int argc, char * argv[]) { + std::string device_id; + std::string snap_name; + std::string cds_addr; + unsigned int operation; + try{ + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<std::string>(OPT_CDS_ADDRESS, "CDS address", &cds_addr); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<std::string>(OPT_CU_ID, "The identification string of the device to snapshuot", &device_id); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<std::string>(OPT_SNAP_NAME, "The name of the snapshot", &snap_name); + ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->addOption<unsigned int>(OPT_SNAPSHOT_OP, "Operation on snapshot [create(0), delete(1)]", 0, &operation); + + ChaosUIToolkit::getInstance()->init(argc, argv); + //! [UIToolkit Init] + + if(!ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->hasOption(OPT_CDS_ADDRESS)){ + throw CException(-1, "The cds address is mandatory", "check param"); + } + + if(!ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->hasOption(OPT_CU_ID)){ + throw CException(-1, "No device identification set", "check param"); + } + + if(!ChaosUIToolkit::getInstance()->getGlobalConfigurationInstance()->hasOption(OPT_SNAP_NAME)){ + throw CException(-2, "Invalid snapshot name set", "check param"); + } + + if(!snap_name.size()) throw CException(-3, "Snapshot name can't zero-length", "check param"); + + SystemApiChannel *system_api_channel = LLRpcApi::getInstance()->getSystemApiClientChannel(cds_addr); + if(system_api_channel) { + LLRpcApi::getInstance()->releaseSystemApyChannel(system_api_channel); + } + } catch (CException& e) { + std::cerr << e.errorCode << " - "<< e.errorDomain << " - " << e.errorMessage << std::endl; + } catch (...) { + std::cerr << "General error " << std::endl; + } + + try { + //! [UIToolkit Deinit] + ChaosUIToolkit::getInstance()->deinit(); + //! [UIToolkit Deinit] + } catch (CException& e) { + std::cerr << e.errorCode << " - "<< e.errorDomain << " - " << e.errorMessage << std::endl; + } + return 0; } diff --git a/chaos/common/io/IODirectIODriver.h b/chaos/common/io/IODirectIODriver.h index 40e99103c6b1b67f7b20e7e46d13a88558426be4..f9374b582f3afb105b6bf6d5d230f2f05bc4b307 100644 --- a/chaos/common/io/IODirectIODriver.h +++ b/chaos/common/io/IODirectIODriver.h @@ -40,6 +40,11 @@ #include <boost/thread.hpp> #include <boost/atomic.hpp> +namespace chaos_data = chaos::common::data; +namespace chaos_utility = chaos::common::utility; +namespace chaos_direct_io = chaos::common::direct_io; +namespace chaos_dio_channel = chaos::common::direct_io::channel; + namespace chaos{ namespace common { //!forward declaration @@ -51,11 +56,6 @@ namespace chaos{ using namespace std; using namespace boost; - namespace chaos_data = chaos::common::data; - namespace chaos_utility = chaos::common::utility; - namespace chaos_direct_io = chaos::common::direct_io; - namespace chaos_dio_channel = chaos::common::direct_io::channel; - /*! Struct for initialization of the io driver */ diff --git a/chaos/ui_toolkit/LowLevelApi/LLRpcApi.cpp b/chaos/ui_toolkit/LowLevelApi/LLRpcApi.cpp index 43ca62a629b6906f55b99a4439f59815ef870279..a8c32c0678ff6b0bb5b44b58c2fa1eb6e04138a3 100644 --- a/chaos/ui_toolkit/LowLevelApi/LLRpcApi.cpp +++ b/chaos/ui_toolkit/LowLevelApi/LLRpcApi.cpp @@ -27,10 +27,10 @@ using namespace boost; using namespace chaos; using namespace chaos::common::io; using namespace chaos::ui; - +using namespace chaos::common::direct_io; #define LLRA_LAPP_ LAPP_ << "[LLRpcApi] - " -uint32_t DIOConn::garbage_counter; +uint32_t DIOConn::garbage_counter = 0; #define INIT_STEP 0 @@ -38,9 +38,9 @@ uint32_t DIOConn::garbage_counter; /* */ -LLRpcApi::LLRpcApi(): -direct_io_client(NULL){ +LLRpcApi::LLRpcApi() { network_broker = new NetworkBroker(); + direct_io_client = NULL; } /* @@ -162,8 +162,28 @@ SystemApiChannel *LLRpcApi::getSystemApiClientChannel(const std::string& direct_ } else { conn = new DIOConn(direct_io_client->getNewConnection(direct_io_address)); } + conn->garbage_counter++; + return new SystemApiChannel(conn, (channel::DirectIOSystemAPIClientChannel*)conn->connection->getNewChannelInstance("DirectIOSystemAPIClientChannel")); } -void releaseSystemApyChannel(SystemApiChannel *system_api_channel) { +void LLRpcApi::releaseSystemApyChannel(SystemApiChannel *system_api_channel) { + boost::unique_lock<boost::mutex> l(mutex_map_dio_addr_conn); + if(!system_api_channel) return; + + DIOConn *conn = system_api_channel->connection; + if(conn) { + conn->garbage_counter--; + if(system_api_channel->system_api_channel) { + conn->connection->releaseChannelInstance(system_api_channel->system_api_channel); + } + + if(!conn->garbage_counter) { + //need to be deleted the connection from the map + map_dio_addr_conn.erase(conn->connection->getURL()); + + //and form the root client + direct_io_client->releaseConnection(conn->connection); + } + } } diff --git a/chaos/ui_toolkit/LowLevelApi/LLRpcApi.h b/chaos/ui_toolkit/LowLevelApi/LLRpcApi.h index 2916b1b36850b67c10f4ba8c9a9e13be5fc1d1a0..04519e6a9201aecc7ed60326239f692c67bf93b0 100644 --- a/chaos/ui_toolkit/LowLevelApi/LLRpcApi.h +++ b/chaos/ui_toolkit/LowLevelApi/LLRpcApi.h @@ -63,7 +63,10 @@ namespace chaos { chaos_direct_io::channel::DirectIOSystemAPIClientChannel *system_api_channel; private: DIOConn *connection; - SystemApiChannel(DIOConn *_connection):connection(_connection){}; + SystemApiChannel(DIOConn *_connection, + chaos_direct_io::channel::DirectIOSystemAPIClientChannel *_system_api_channel): + connection(_connection), + system_api_channel(_system_api_channel){}; ~SystemApiChannel(){}; };