http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/pnodeconfig.cpp ---------------------------------------------------------------------- diff --git a/core/sqf/src/trafconf/pnodeconfig.cpp b/core/sqf/src/trafconf/pnodeconfig.cpp new file mode 100644 index 0000000..a47ce56 --- /dev/null +++ b/core/sqf/src/trafconf/pnodeconfig.cpp @@ -0,0 +1,629 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// @@@ START COPYRIGHT @@@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. +// +// @@@ END COPYRIGHT @@@ +// +/////////////////////////////////////////////////////////////////////////////// + +using namespace std; + +#include <errno.h> +#include <assert.h> +#include <sched.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <iostream> +#include "tclog.h" +#include "tctrace.h" +#include "pnodeconfig.h" + + +/////////////////////////////////////////////////////////////////////////////// +// Physical Node Configuration +/////////////////////////////////////////////////////////////////////////////// + +CPNodeConfig::CPNodeConfig( CPNodeConfigContainer *pnodesConfig + , pnodeConfigInfo_t &pnodeConfigInfo + ) + : pnodesConfig_(pnodesConfig) + , pnid_(pnodeConfigInfo.pnid) + , excludedFirstCore_(pnodeConfigInfo.excludedFirstCore) + , excludedLastCore_(pnodeConfigInfo.excludedLastCore) + , spareNode_(false) + , sparePNids_(NULL) + , sparePNidsCount_(0) + , next_(NULL) + , prev_(NULL) +{ + const char method_name[] = "CPNodeConfig::CPNodeConfig"; + TRACE_ENTRY; + + strcpy( name_, pnodeConfigInfo.nodename ); + CPU_ZERO( &excludedCoreMask_ ); + + TRACE_EXIT; +} + +CPNodeConfig::~CPNodeConfig( void ) +{ + const char method_name[] = "CPNodeConfig::~CPNodeConfig"; + TRACE_ENTRY; + + if (sparePNids_) + { + delete [] sparePNids_; + } + + TRACE_EXIT; +} + +int CPNodeConfig::GetSpareList( int sparePNids[] ) +{ + const char method_name[] = "CPNodeConfig::GetSpareList"; + TRACE_ENTRY; + + if ( ! sparePNids_ || ! sparePNids ) + { + return(0); + } + + if ( sparePNidsCount_ > 0 ) + { + for ( int i = 0; i < sparePNidsCount_ ; i++ ) + { + sparePNids[i] = sparePNids_[i]; + } + } + + TRACE_EXIT; + return(sparePNidsCount_); +} + +void CPNodeConfig::ResetSpare( void ) +{ + const char method_name[] = "CPNodeConfig::ResetSpare"; + TRACE_ENTRY; + + spareNode_ = false; + sparePNidsCount_ = 0; + if (sparePNids_) + { + delete [] sparePNids_; + } + + TRACE_EXIT; +} + +void CPNodeConfig::SetSpareList( int sparePNids[], int spareCount ) +{ + const char method_name[] = "CPNodeConfig::SetSpareList"; + TRACE_ENTRY; + + assert( ! sparePNids_ || spareCount ); + + sparePNidsCount_ = spareCount; + sparePNids_ = new int [sparePNidsCount_]; + + if ( ! sparePNids_ ) + { + int err = errno; + char la_buf[TC_LOG_BUF_SIZE]; + sprintf(la_buf, "[%s], Error: Can't allocate spare pnids array - errno=%d (%s)\n", method_name, err, strerror(errno)); + TcLogWrite(MON_PNODECONF_SET_SPARE_1, TC_LOG_CRIT, la_buf); + } + else + { + for ( int i = 0; i < sparePNidsCount_ ; i++ ) + { + sparePNids_[i] = sparePNids[i]; + if (TcTraceSettings & TC_TRACE_INIT) + { + trace_printf("%s@%d - Added spare pnid=%d to spare node array in (pnid=%d, nodename=%s)\n", method_name, __LINE__, sparePNids_[i], pnid_, name_); + } + } + spareNode_ = true; + } + + TRACE_EXIT; +} + +void CPNodeConfig::SetName( const char *newName ) +{ + if (newName) + { + strcpy(name_, newName); + } +} + +void CPNodeConfig::SetExcludedFirstCore( int excludedFirstCore ) +{ + excludedFirstCore_ = excludedFirstCore; +} + +void CPNodeConfig::SetExcludedLastCore( int excludedLastCore ) +{ + excludedLastCore_ = excludedLastCore; +} + +CPNodeConfigContainer::CPNodeConfigContainer( int pnodesConfigMax ) + : pnodesConfig_(NULL) + , pnodesCount_(0) + , snodesCount_(0) + , nextPNid_(0) + , pnodesConfigMax_(pnodesConfigMax) + , head_(NULL) + , tail_(NULL) +{ + const char method_name[] = "CPNodeConfigContainer::CPNodeConfigContainer"; + TRACE_ENTRY; + + pnodesConfig_ = new CPNodeConfig *[pnodesConfigMax_]; + + if ( ! pnodesConfig_ ) + { + int err = errno; + char la_buf[TC_LOG_BUF_SIZE]; + sprintf(la_buf, "[%s], Error: Can't allocate physical node configuration array - errno=%d (%s)\n", method_name, err, strerror(errno)); + TcLogWrite(MON_PNODECONF_CONSTR_1, TC_LOG_CRIT, la_buf); + } + else + { + // Initialize array + for ( int i = 0; i < pnodesConfigMax_; i++ ) + { + pnodesConfig_[i] = NULL; + } + } + + TRACE_EXIT; +} + +CPNodeConfigContainer::~CPNodeConfigContainer( void ) +{ + CPNodeConfig *pnodeConfig = head_; + + const char method_name[] = "CPNodeConfigContainer::~CPNodeConfigContainer"; + TRACE_ENTRY; + + // Delete entries + while ( head_ ) + { + DeletePNodeConfig( pnodeConfig ); + pnodeConfig = head_; + } + + // Delete array + if ( pnodesConfig_ ) + { + delete [] pnodesConfig_; + } + + TRACE_EXIT; +} + +void CPNodeConfigContainer::Clear( void ) +{ + const char method_name[] = "CPNodeConfigContainer::Clear"; + TRACE_ENTRY; + + CPNodeConfig *pnodeConfig = head_; + + // Delete entries + while ( head_ ) + { + DeletePNodeConfig( pnodeConfig ); + pnodeConfig = head_; + } + + if ( pnodesConfig_ ) + { + // Initialize array + for ( int i = 0; i < pnodesConfigMax_ ;i++ ) + { + pnodesConfig_[i] = NULL; + } + } + + pnodesCount_ = 0; + snodesCount_ = 0; + nextPNid_ = 0; + head_ = NULL; + tail_ = NULL; + + TRACE_EXIT; +} + +CPNodeConfig *CPNodeConfigContainer::AddPNodeConfig( pnodeConfigInfo_t &pnodeConfigInfo ) +{ + const char method_name[] = "CPNodeConfigContainer::AddPNodeConfig"; + TRACE_ENTRY; + + // pnid list is NOT sequential from zero + if ( ! (pnodeConfigInfo.pnid >= 0 && pnodeConfigInfo.pnid < pnodesConfigMax_) ) + { + char la_buf[TC_LOG_BUF_SIZE]; + sprintf( la_buf, "[%s], Error: Invalid pnid=%d - should be >= 0 and < %d)\n" + , method_name, pnodeConfigInfo.pnid, pnodesConfigMax_); + TcLogWrite(MON_PNODECONF_ADD_PNODE_1, TC_LOG_CRIT, la_buf); + return( NULL ); + } + + assert( pnodesConfig_[pnodeConfigInfo.pnid] == NULL ); + + CPNodeConfig *pnodeConfig = new CPNodeConfig( this, pnodeConfigInfo ); + if (pnodeConfig) + { + if ( pnodeConfigInfo.spareCount ) + { + snodesCount_++; + spareNodesConfigList_.push_back( pnodeConfig ); + } + + // Bump the physical node count + pnodesCount_++; + // Add it to the array + pnodesConfig_[pnodeConfigInfo.pnid] = pnodeConfig; + // Add it to the container list + if ( head_ == NULL ) + { + head_ = tail_ = pnodeConfig; + } + else + { + tail_->next_ = pnodeConfig; + pnodeConfig->prev_ = tail_; + tail_ = pnodeConfig; + } + + // Set the next available pnid + nextPNid_ = (pnodeConfigInfo.pnid == nextPNid_) ? (pnodeConfigInfo.pnid+1) : nextPNid_ ; + if ( nextPNid_ == pnodesConfigMax_ ) + { // We are at the limit, search for unused pnid from begining + nextPNid_ = -1; + for (int i = 0; i < pnodesConfigMax_; i++ ) + { + if ( pnodesConfig_[i] == NULL ) + { + nextPNid_ = i; + break; + } + } + } + else if ( pnodesConfig_[nextPNid_] != NULL ) + { // pnid is in use + int next = ((nextPNid_ + 1) < pnodesConfigMax_) ? nextPNid_ + 1 : 0 ; + nextPNid_ = -1; + for (int i = next; i < pnodesConfigMax_; i++ ) + { + if ( pnodesConfig_[i] == NULL ) + { + nextPNid_ = i; + break; + } + } + } + + if (TcTraceSettings & (TC_TRACE_INIT | TC_TRACE_REQUEST)) + { + trace_printf( "%s@%d - Added physical node configuration object\n" + " (pnid=%d, nextPNid_=%d)\n" + " (pnodesCount_=%d,pnodesConfigMax=%d)\n" + , method_name, __LINE__ + , pnodeConfigInfo.pnid, nextPNid_ + , pnodesCount_, pnodesConfigMax_); + } + } + else + { + int err = errno; + char la_buf[TC_LOG_BUF_SIZE]; + sprintf( la_buf, "[%s], Error: Can't allocate physical node configuration object - errno=%d (%s)\n" + , method_name, err, strerror(errno)); + TcLogWrite(MON_PNODECONF_ADD_PNODE_2, TC_LOG_ERR, la_buf); + } + + TRACE_EXIT; + return( pnodeConfig ); +} + +void CPNodeConfigContainer::DeletePNodeConfig( CPNodeConfig *pnodeConfig ) +{ + const char method_name[] = "CPNodeConfigContainer::DeletePNodeConfig"; + TRACE_ENTRY; + + if (TcTraceSettings & (TC_TRACE_INIT | TC_TRACE_REQUEST)) + { + trace_printf( "%s@%d Deleting node=%s, pnid=%d, nextPNid_=%d\n" + , method_name, __LINE__ + , pnodeConfig->GetName() + , pnodeConfig->GetPNid() + , nextPNid_ ); + } + + int pnid = pnodeConfig->GetPNid(); + pnodesConfig_[pnid] = NULL; + + if ( head_ == pnodeConfig ) + head_ = pnodeConfig->next_; + if ( tail_ == pnodeConfig ) + tail_ = pnodeConfig->prev_; + if ( pnodeConfig->prev_ ) + pnodeConfig->prev_->next_ = pnodeConfig->next_; + if ( pnodeConfig->next_ ) + pnodeConfig->next_->prev_ = pnodeConfig->prev_; + delete pnodeConfig; + + // Decrement the physical node configuration count + pnodesCount_--; + + if ( nextPNid_ == -1 ) + { // We are at the limit, use the deleted pnid as the next available + nextPNid_ = pnid; + } + else if ( nextPNid_ > pnid ) + { // Always use the lower pnid value + nextPNid_ = pnid; + } + + if (TcTraceSettings & (TC_TRACE_INIT | TC_TRACE_REQUEST)) + { + trace_printf( "%s@%d - Deleted physical node configuration object\n" + " (pnid=%d, nextPNid_=%d)\n" + " (pnodesCount_=%d,pnodesConfigMax=%d)\n" + , method_name, __LINE__ + , pnid, nextPNid_ + , pnodesCount_, pnodesConfigMax_); + } + TRACE_EXIT; +} + +int CPNodeConfigContainer::GetPNid( char *nodename ) +{ + const char method_name[] = "CPNodeConfigContainer::GetPNid"; + TRACE_ENTRY; + + int pnid = -1; + CPNodeConfig *config = head_; + while (config) + { + if ( hostnamecmp( config->GetName(), nodename ) == 0 ) + { + pnid = config->GetPNid(); + break; + } + config = config->GetNext(); + } + + TRACE_EXIT; + return( pnid ); +} + +CPNodeConfig *CPNodeConfigContainer::GetPNodeConfig( char *nodename ) +{ + const char method_name[] = "CPNodeConfigContainer::GetPNodeConfig"; + TRACE_ENTRY; + + CPNodeConfig *config = head_; + while (config) + { + if ( hostnamecmp( config->GetName(), nodename ) == 0 ) + { + break; + } + config = config->GetNext(); + } + + TRACE_EXIT; + return config; +} + +CPNodeConfig *CPNodeConfigContainer::GetPNodeConfig( int pnid ) +{ + const char method_name[] = "CPNodeConfigContainer::GetPNodeConfig"; + TRACE_ENTRY; + + CPNodeConfig *config = head_; + while (config) + { + if ( config->GetPNid() == pnid ) + { + break; + } + config = config->GetNext(); + } + + TRACE_EXIT; + return config; +} + +void CPNodeConfigContainer::GetSpareNodesConfigSet( const char *name + , PNodesConfigList_t &spareSet ) +{ + bool foundInSpareSet = false; + CPNodeConfig *spareNodeConfig; + CPNodeConfig *pNodeconfig; + PNodesConfigList_t tempSpareSet; + + const char method_name[] = "CPNodeConfigContainer::GetSpareNodesConfigSet"; + TRACE_ENTRY; + + PNodesConfigList_t::iterator itSn; + for ( itSn = spareNodesConfigList_.begin(); + itSn != spareNodesConfigList_.end(); + itSn++ ) + { + spareNodeConfig = *itSn; + if (TcTraceSettings & TC_TRACE_INIT) + { + trace_printf( "%s@%d - %s is a configured spare node\n" + , method_name, __LINE__ + , spareNodeConfig->GetName()); + } + + // Build the set of pnids that constitute the 'spare set' + int sparePNidsCount = spareNodeConfig->GetSparesCount()+1; + int *sparePNids = new int [sparePNidsCount]; + spareNodeConfig->GetSpareList( sparePNids ); + sparePNids[spareNodeConfig->GetSparesCount()] = spareNodeConfig->GetPNid(); + + // Build the list of configured physical nodes that + // constitute the 'spare set' + for ( int i = 0; i < sparePNidsCount ; i++ ) + { + pNodeconfig = GetPNodeConfig( sparePNids[i] ); + if ( pNodeconfig ) + { + tempSpareSet.push_back( pNodeconfig ); + if (TcTraceSettings & TC_TRACE_INIT) + { + trace_printf( "%s@%d - Added %s as member of spare set (%s, count=%ld)\n" + , method_name, __LINE__ + , pNodeconfig->GetName() + , spareNodeConfig->GetName() + , tempSpareSet.size() ); + } + } + } + + // Check each node in the 'spare set' + PNodesConfigList_t::iterator itSnSet; + for ( itSnSet = tempSpareSet.begin(); + itSnSet != tempSpareSet.end(); + itSnSet++ ) + { + pNodeconfig = *itSnSet; + if (TcTraceSettings & TC_TRACE_INIT) + { + trace_printf( "%s@%d - %s is in spare set (%s, count=%ld)\n" + , method_name, __LINE__ + , pNodeconfig->GetName() + , spareNodeConfig->GetName() + , tempSpareSet.size() ); + } + if ( CPNodeConfigContainer::hostnamecmp( pNodeconfig->GetName(), name ) == 0 ) + { + foundInSpareSet = true; + spareSet = tempSpareSet; + if (TcTraceSettings & TC_TRACE_INIT) + { + trace_printf( "%s@%d - Found %s in spare set (%s, count=%ld)\n" + , method_name, __LINE__ + , pNodeconfig->GetName() + , spareNodeConfig->GetName() + , tempSpareSet.size() ); + } + } + } + if (sparePNids) + { + tempSpareSet.clear(); + delete [] sparePNids; + } + if (foundInSpareSet) + { + break; + } + } + + TRACE_EXIT; +} + +int CPNodeConfigContainer::hostnamecmp( const char *p_str1, const char *p_str2 ) +{ + static bool sb_first_time = true; + static bool sb_strict_hostname_check = false; + if ( sb_first_time ) + { + sb_first_time = false; + char *lv_envvar=getenv( "MON_STRICT_HOSTNAME_CHECK" ); + + if ( lv_envvar && (atoi( lv_envvar ) == 1) ) + { + sb_strict_hostname_check = true; + } + } + + if ( !p_str1 ) return 1; + if ( !p_str2 ) return 1; + + // Compare the string passed in + int lv_ret = strcmp( p_str1, p_str2 ); + if ( lv_ret == 0 ) + { // Got a match! + return lv_ret; + } + if ( sb_strict_hostname_check ) + { + return lv_ret; + } + + char lv_str1_to_cmp[1024]; + char lv_str2_to_cmp[1024]; + memset( lv_str1_to_cmp, 0, 1024 ); + memset( lv_str2_to_cmp, 0, 1024 ); + + char *lp_str1_dot = strchr( (char *) p_str1, '.' ); + if ( lp_str1_dot ) + { // Found '.', copy up to one char before '.' + memcpy( lv_str1_to_cmp, p_str1, lp_str1_dot - p_str1 ); + } + else + { // Copy entire string + strcpy( lv_str1_to_cmp, p_str1 ); + } + + char *lp_str2_dot = strchr( (char *) p_str2, '.' ); + if ( lp_str2_dot ) + { // Found '.', copy up to one char before '.' + memcpy( lv_str2_to_cmp, p_str2, lp_str2_dot - p_str2 ); + } + else + { // Copy entire string + strcpy( lv_str2_to_cmp, p_str2 ); + } + + // Ignore case + NormalizeCase( lv_str1_to_cmp ); + NormalizeCase( lv_str2_to_cmp ); + return strcmp( lv_str1_to_cmp, lv_str2_to_cmp ); +} + +char *CPNodeConfigContainer::NormalizeCase( char *token ) +{ + char *ptr = token; + + const char method_name[] = "CPNodeConfigContainer::NormalizeCase"; + TRACE_ENTRY; + + while ( *ptr ) + { + *ptr = static_cast<char>(tolower( *ptr )); + if ( *ptr == '\n' ) *ptr = '\0'; + ptr++; + } + + TRACE_EXIT; + return token; +} +
http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/pnodeconfig.h ---------------------------------------------------------------------- diff --git a/core/sqf/src/trafconf/pnodeconfig.h b/core/sqf/src/trafconf/pnodeconfig.h new file mode 100644 index 0000000..f3b05f7 --- /dev/null +++ b/core/sqf/src/trafconf/pnodeconfig.h @@ -0,0 +1,131 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// @@@ START COPYRIGHT @@@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. +// +// @@@ END COPYRIGHT @@@ +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef PNODECONFIG_H_ +#define PNODECONFIG_H_ + +#include <list> + +#include "trafconf/trafconfig.h" +#include "lnodeconfig.h" + +class CLNodeConfig; +class CPNodeConfig; + +typedef list<CPNodeConfig *> PNodesConfigList_t; + +typedef struct pnodeConfigInfo_s +{ + int pnid; + char nodename[TC_PROCESSOR_NAME_MAX]; + int excludedFirstCore; + int excludedLastCore; + cpu_set_t excludedCoreMask; + int spareCount; + int sparePNid[TC_SPARE_NODES_MAX]; +} pnodeConfigInfo_t; + +class CPNodeConfigContainer +{ +public: + CPNodeConfigContainer( int pnodesConfigMax ); + ~CPNodeConfigContainer( void ); + + CPNodeConfig *AddPNodeConfig( pnodeConfigInfo_t &pnodeConfigInfo ); + void Clear( void ); + static int hostnamecmp(const char *p_str1, const char *p_str2); + void DeletePNodeConfig( CPNodeConfig *pnodeConfig ); + inline CPNodeConfig *GetFirstPNodeConfig( void ) { return ( head_ ); } + inline int GetNextPNid( void ) { return ( nextPNid_ ); } + int GetPNid( char *nodename ); + CPNodeConfig *GetPNodeConfig( char *nodename ); + CPNodeConfig *GetPNodeConfig( int pnid ); + inline int GetPNodesConfigMax( void ) { return ( pnodesConfigMax_ ); } + inline int GetPNodesCount( void ) { return ( pnodesCount_ ); } + inline int GetSNodesCount( void ) { return ( snodesCount_ ); } + inline PNodesConfigList_t *GetSpareNodesConfigList( void ) { return ( &spareNodesConfigList_ ); } + void GetSpareNodesConfigSet( const char *name, PNodesConfigList_t &spareSet ); + +protected: + CPNodeConfig **pnodesConfig_;// array of physical node configuration objects + int pnodesCount_; // # of physical nodes + int snodesCount_; // # of spare nodes + int nextPNid_; // next physical node id available + +private: + static char *NormalizeCase( char *token ); + + int pnodesConfigMax_; // maximum number of physical nodes + PNodesConfigList_t spareNodesConfigList_; // configured spare nodes list + CPNodeConfig *head_; // head of physical nodes linked list + CPNodeConfig *tail_; // tail of physical nodes linked list + +}; + +class CPNodeConfig : public CLNodeConfigContainer +{ + friend CPNodeConfig *CPNodeConfigContainer::AddPNodeConfig( pnodeConfigInfo_t &pnodeConfigInfo ); + friend void CPNodeConfigContainer::DeletePNodeConfig( CPNodeConfig *pnodeConfig ); +public: + + CPNodeConfig( CPNodeConfigContainer *pnodesConfig + , pnodeConfigInfo_t &pnodeConfigInfo + ); + ~CPNodeConfig( void ); + + inline cpu_set_t &GetExcludedCoreMask( void ) { return (excludedCoreMask_); } + inline int GetExcludedFirstCore( void ) { return ( excludedFirstCore_ ); } + inline int GetExcludedLastCore( void ) { return ( excludedLastCore_ ); } + inline const char *GetName( void ) { return ( name_ ); } + inline CPNodeConfig *GetNext( void ) { return ( next_ ); } + inline int GetPNid( void ) { return ( pnid_ ); } + void SetName( const char *newName ); + void SetExcludedFirstCore( int excludedFirstCore ); + void SetExcludedLastCore( int excludedLastCore ); + int GetSpareList( int sparePNid[] ); + inline int GetSparesCount( void ) { return ( sparePNidsCount_ ); } + + inline bool IsSpareNode( void ) { return ( spareNode_ ); } + inline void SetExcludedCoreMask( cpu_set_t &coreMask ) { excludedCoreMask_ = coreMask; } + void SetSpareList( int sparePNid[], int spareCount ); + void ResetSpare( void ); + +protected: +private: + CPNodeConfigContainer *pnodesConfig_; // physical nodes container + char name_[TC_PROCESSOR_NAME_MAX]; // hostname + int pnid_; // physical node identifier + cpu_set_t excludedCoreMask_; // mask of excluded SMP processor cores + int excludedFirstCore_;// First excluded SMP processor core used by logical node + int excludedLastCore_; // Last excluded SMP processor core used by logical node + bool spareNode_; // true when this is a spare physical node + int *sparePNids_; // array of pnids this physical node can spare + int sparePNidsCount_; // # of entries in spare sparePNids_ array + + CPNodeConfig *next_; // next PNodeConfig in CPNodeConfigContainer list + CPNodeConfig *prev_; // previous PNodeConfig in CPNodeConfigContainer list +}; + +#endif /* PNODECONFIG_H_ */ http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/tcdb.cpp ---------------------------------------------------------------------- diff --git a/core/sqf/src/trafconf/tcdb.cpp b/core/sqf/src/trafconf/tcdb.cpp new file mode 100644 index 0000000..7a41c3f --- /dev/null +++ b/core/sqf/src/trafconf/tcdb.cpp @@ -0,0 +1,474 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// @@@ START COPYRIGHT @@@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. +// +// @@@ END COPYRIGHT @@@ +// +/////////////////////////////////////////////////////////////////////////////// + +#include <stdlib.h> +#include <string.h> +#include <cctype> +#include <string> + +using namespace std; + +#include "tclog.h" +#include "tctrace.h" +//#include "tcdbmysql.h" +#include "tcdbsqlite.h" +#include "tcdb.h" + +/////////////////////////////////////////////////////////////////////////////// +// Cluster Configuration +/////////////////////////////////////////////////////////////////////////////// + +CTcdb::CTcdb( void ) + : dbStorageType_(TCDBSTOREUNDEFINED) + , tcdbStore_(NULL) +{ + const char method_name[] = "CTcdb::CTcdb"; + TRACE_ENTRY; + + memcpy(&eyecatcher_, "TCDB", 4); + + char *env; + string tcDbType; + size_t found; + + env = getenv("TRAF_CONFIG_DBSTORE"); + if ( env ) + { + char c; + int i = 0; + while ( env[i] ) + { + c=env[i]; + env[i] = (char) toupper( c ); + i++; + } + tcDbType = env; + if ( tcDbType.length() == 0 ) + { + char buf[TC_LOG_BUF_SIZE]; + snprintf( buf, sizeof(buf) + , "[%s], Environment variable TRAF_CONFIG_DBSTORE value is not set, " + "defaulting to SQLite storage method!\n" + , method_name ); + TcLogWrite( TCDB_TCDB_1, TC_LOG_WARNING, buf ); + dbStorageType_ = TCDBSQLITE; + } + else + { + found = tcDbType.find( TC_STORE_SQLITE ); + if (found != std::string::npos) + { + dbStorageType_ = TCDBSQLITE; + } + else + { + found = tcDbType.find( TC_STORE_MYSQL ); + if (found != std::string::npos) + { + dbStorageType_ = TCDBMYSQL; + } + else + { + found = tcDbType.find( TC_STORE_POSTGRESQL ); + if (found != std::string::npos) + { + dbStorageType_ = TCDBPOSTGRESQL; + } + else + { + if ( tcDbType.length() == 0 ) + { + char buf[TC_LOG_BUF_SIZE]; + snprintf( buf, sizeof(buf) + , "[%s], Environment variable TRAF_CONFIG_DBSTORE value (%s) invalid!\n" + , method_name, tcDbType.c_str() ); + TcLogWrite( TCDB_TCDB_2, TC_LOG_CRIT, buf ); + TRACE_EXIT; + } + } + } + } + } + } + else + { + // Environment variable TRAF_CONFIG_DBSTORE is undefined + // defaulting to SQLite storage method! + dbStorageType_ = TCDBSQLITE; + } + + TRACE_EXIT; +} + +CTcdb::~CTcdb ( void ) +{ + const char method_name[] = "CTcdb::~CTcdb"; + TRACE_ENTRY; + memcpy(&eyecatcher_, "tcdb", 4); + TRACE_EXIT; +} + +int CTcdb::AddLNodeData( int nid + , int pnid + , int firstCore + , int lastCore + , int processors + , int roles ) +{ + const char method_name[] = "CTcdb::AddLNodeData"; + TRACE_ENTRY; + + int rc = tcdbStore_->AddLNodeData( nid + , pnid + , firstCore + , lastCore + , processors + , roles ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::AddPNodeData( const char *name + , int pnid + , int excludedFirstCore + , int excludedLastCore ) +{ + const char method_name[] = "CTcdb::AddPNodeData"; + TRACE_ENTRY; + + + int rc = tcdbStore_->AddPNodeData( name + , pnid + , excludedFirstCore + , excludedLastCore ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::AddRegistryKey( const char *key ) +{ + const char method_name[] = "CTcdb::AddRegistryKey"; + TRACE_ENTRY; + + int rc = tcdbStore_->AddRegistryKey( key ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::AddRegistryProcess( const char *processName ) +{ + const char method_name[] = "CTcdb::AddRegistryProcess"; + TRACE_ENTRY; + + int rc = tcdbStore_->AddRegistryProcess( processName ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::AddRegistryClusterData( const char *key + , const char *dataValue ) +{ + const char method_name[] = "CTcdb::AddRegistryClusterData"; + TRACE_ENTRY; + + int rc = tcdbStore_->AddRegistryClusterData( key, dataValue ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::AddRegistryProcessData( const char *processName + , const char *key + , const char *dataValue ) +{ + const char method_name[] = "CTcdb::AddRegistryProcessData"; + TRACE_ENTRY; + + int rc = tcdbStore_->AddRegistryProcessData( processName, key, dataValue ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::AddUniqueString( int nid + , int id + , const char *uniqStr ) +{ + const char method_name[] = "CTcdb::AddUniqueString"; + TRACE_ENTRY; + + int rc = tcdbStore_->AddUniqueString( nid, id, uniqStr ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::Close( void ) +{ + const char method_name[] = "CTcdb::Close"; + TRACE_ENTRY; + + int rc = tcdbStore_->Close(); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::DeleteNodeData( int pnid ) +{ + const char method_name[] = "CTcdb::DeleteNodeData"; + TRACE_ENTRY; + + int rc = tcdbStore_->DeleteNodeData( pnid ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::DeleteUniqueString( int nid ) +{ + const char method_name[] = "CTcdb::DeleteUniqueString"; + TRACE_ENTRY; + + int rc = tcdbStore_->DeleteUniqueString( nid ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::Initialize( const char *rootNode + , const char *instanceNode ) +{ + const char method_name[] = "CTcdb::Initialize"; + TRACE_ENTRY; + + if ( IsInitialized() ) + { + return( TCALREADYINIT ); + } + + if (!tcdbStore_) + { + switch (dbStorageType_) + { + case TCDBMYSQL: + rootNode = rootNode; + instanceNode = instanceNode; +// tcdbStore_ = new CTcdbMySql( rootNode +// , instanceNode ); + return( TCNOTIMPLEMENTED ); + break; + case TCDBSQLITE: + tcdbStore_ = new CTcdbSqlite; + break; + default: + TRACE_EXIT; + return( TCNOTIMPLEMENTED ); + } + } + + int rc = tcdbStore_->Initialize(); + + TRACE_EXIT; + return( rc ); +} + +bool CTcdb::IsInitialized( void ) +{ + const char method_name[] = "CTcdb::IsInitialized"; + TRACE_ENTRY; + + bool rs = false; + if ( tcdbStore_ ) + { + rs = tcdbStore_->IsInitialized(); + } + + TRACE_EXIT; + return( rs ); +} + +int CTcdb::GetNode( int nid + , node_configuration_t &nodeConfig ) +{ + const char method_name[] = "CTcdb::GetNode"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetNode( nid, nodeConfig ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetNode( const char *name + , node_configuration_t &nodeConfig ) +{ + const char method_name[] = "CTcdb::GetNode"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetNode( name, nodeConfig ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetNodes( int &count + , int max + , node_configuration_t nodeConfig[] ) +{ + const char method_name[] = "CTcdb::GetNodes"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetNodes( count, max, nodeConfig ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetPNode( int pNid + , physical_node_configuration_t &pnodeConfig ) +{ + const char method_name[] = "CTcdb::GetPNode"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetPNode( pNid, pnodeConfig ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetPNode( const char *name + , physical_node_configuration_t &pnodeConfig ) +{ + const char method_name[] = "CTcdb::GetPNode"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetPNode( name, pnodeConfig ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetSNodes( int &count + , int max + , physical_node_configuration_t spareNodeConfig[] ) +{ + const char method_name[] = "CTcdb::GetSNodes"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetSNodes( count, max, spareNodeConfig ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetPersistProcess( const char *persistPrefix + , persist_configuration_t &persistConfig ) +{ + const char method_name[] = "CTcdb::GetPersistProcess"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetPersistProcess( persistPrefix, persistConfig ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetPersistProcessKeys( const char *persistProcessKeys ) +{ + const char method_name[] = "CTcdb::GetPersistProcessKeys"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetPersistProcessKeys( persistProcessKeys ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetRegistryClusterSet( int &count + , int max + , registry_configuration_t registryConfig[] ) +{ + const char method_name[] = "CTcdb::GetRegistryClusterSet"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetRegistryClusterSet( count, max, registryConfig ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetRegistryProcessSet( int &count + , int max + , registry_configuration_t registryConfig[] ) +{ + const char method_name[] = "CTcdb::GetRegistryProcessSet"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetRegistryProcessSet( count, max, registryConfig ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetUniqueString( int nid, int id, const char *uniqStr ) +{ + const char method_name[] = "CTcdb::GetUniqueString"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetUniqueString( nid, id, uniqStr ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetUniqueStringId( int nid + , const char *uniqStr + , int &id ) +{ + const char method_name[] = "CTcdb::GetUniqueStringId"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetUniqueStringId( nid, uniqStr, id ); + + TRACE_EXIT; + return( rc ); +} + +int CTcdb::GetUniqueStringIdMax( int nid, int &id ) +{ + const char method_name[] = "CTcdb::GetUniqueStringIdMax"; + TRACE_ENTRY; + + int rc = tcdbStore_->GetUniqueStringIdMax( nid, id ); + + TRACE_EXIT; + return( rc ); +} + http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/tcdb.h ---------------------------------------------------------------------- diff --git a/core/sqf/src/trafconf/tcdb.h b/core/sqf/src/trafconf/tcdb.h new file mode 100644 index 0000000..060f2f6 --- /dev/null +++ b/core/sqf/src/trafconf/tcdb.h @@ -0,0 +1,118 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// @@@ START COPYRIGHT @@@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. +// +// @@@ END COPYRIGHT @@@ +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef TCDB_H_ +#define TCDB_H_ + +#include <stdlib.h> +//#include "tcdbmysql.h" +#include "tcdbsqlite.h" +#include "trafconf/trafconfig.h" + +using namespace std; + + +// +// Trafodion Configuration Database Adaptor (CTrafConfigDb class) +// +// Implements common interface to storage classes used by the +// Trafodion Configuration API (trafconfig.cxx/.h). +// + +class CTcdb +{ +private: + int eyecatcher_; // Debuggging aid -- leave as first + // member variable of the class +public: + + CTcdb( void ); + ~CTcdb( void ); + + int AddLNodeData( int nid + , int pnid + , int firstCore + , int lastCore + , int processors + , int roles ); + int AddPNodeData( const char *name + , int pnid + , int excludedFirstCore + , int excludedLastCore ); + int AddRegistryKey( const char *key ); + int AddRegistryProcess( const char *name ); + int AddRegistryClusterData( const char *key, const char *dataValue ); + int AddRegistryProcessData( const char *procName + , const char *key + , const char *dataValue ); + int AddUniqueString( int nid, int id, const char *uniqStr ); + int Close( void ); + int DeleteNodeData( int pnid ); + int DeleteUniqueString( int nid ); + int GetNode( int nid + , node_configuration_t &nodeConfig ); + int GetNode( const char *name + , node_configuration_t &nodeConfig ); + int GetNodes( int &count + , int max + , node_configuration_t nodeConfig[] ); + int GetPNode( int pnid + , physical_node_configuration_t &pnodeConfig ); + int GetPNode( const char *name + , physical_node_configuration_t &pnodeConfig ); + int GetSNodes( int &count + , int max + , physical_node_configuration_t pNodeConfig[] ); + int GetPersistProcess( const char *persistPrefix + , persist_configuration_t &persistConfig ); + int GetPersistProcessKeys( const char *persistProcessKeys ); + int GetRegistryClusterSet( int &count + , int max + , registry_configuration_t registryConfig[] ); + int GetRegistryProcessSet( int &count + , int max + , registry_configuration_t registryConfig[] ); + inline TC_STORAGE_TYPE GetStorageType( void ) { return(dbStorageType_); } + int GetUniqueString( int nid, int id, const char *uniqStr ); + int GetUniqueStringId( int nid + , const char *uniqStr + , int &id ); + int GetUniqueStringIdMax( int nid, int &id ); + int Initialize( const char *rootNode = NULL + , const char *instanceNode = NULL ); + bool IsInitialized( void ); + int UpdatePNodeConfig( int pnid + , const char *name + , int excludedFirstCore + , int excludedLastCore ); + +protected: +private: + TC_STORAGE_TYPE dbStorageType_; + CTcdbStore *tcdbStore_; +}; + + +#endif /* TCDB_H_ */
