Repository: trafodion
Updated Branches:
  refs/heads/master 03fd16139 -> 02950e298


http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/tcdbsqlite.h
----------------------------------------------------------------------
diff --git a/core/sqf/src/trafconf/tcdbsqlite.h 
b/core/sqf/src/trafconf/tcdbsqlite.h
new file mode 100644
index 0000000..b03ebcb
--- /dev/null
+++ b/core/sqf/src/trafconf/tcdbsqlite.h
@@ -0,0 +1,130 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// @@@ 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 TCDBSQLITE_H_
+#define TCDBSQLITE_H_
+
+#include <stdlib.h>
+#include <sqlite3.h>
+#include "trafconf/trafconfig.h"
+#include "tcdbstore.h"
+
+class CTcdbSqlite : public CTcdbStore
+{
+public:
+
+    CTcdbSqlite( void );
+    ~CTcdbSqlite( 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[] );
+    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( void );
+    inline bool IsInitialized( void ) { return( (db_ != NULL) ); }
+    int         UpdatePNodeConfig( int pnid
+                                 , const char *name
+                                 , int excludedFirstCore
+                                 , int excludedLastCore );
+
+protected:
+private:
+    int  GetSNodeData( int pnid
+                     , const char *nodename
+                     , int excfirstcore
+                     , int exclastcore
+                     , physical_node_configuration_t &spareNodeConfig );
+    void SetLNodeData( int nid
+                     , int pnid
+                     , const char *nodename
+                     , int excfirstcore
+                     , int exclastcore
+                     , int firstcore
+                     , int lastcore
+                     , int processors
+                     , int roles 
+                     , node_configuration_t &nodeConfig );
+    void SetPNodeData( int pnid
+                     , const char *nodename
+                     , int excfirstcore
+                     , int exclastcore
+                     , physical_node_configuration_t &pnodeConfig );
+    int  SetPersistProcessData( const char *persistkey
+                              , const char *persistvalue
+                              , persist_configuration_t &persistConfig );
+    int  UpdatePNodeData( int pnid
+                        , const char *name
+                        , int excludedFirstCore
+                        , int excludedLastCore );
+
+    sqlite3   *db_;
+};
+
+
+#endif /* TCDBSQLITE_H_ */

http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/tcdbstore.cpp
----------------------------------------------------------------------
diff --git a/core/sqf/src/trafconf/tcdbstore.cpp 
b/core/sqf/src/trafconf/tcdbstore.cpp
new file mode 100644
index 0000000..2263a80
--- /dev/null
+++ b/core/sqf/src/trafconf/tcdbstore.cpp
@@ -0,0 +1,56 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// @@@ 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 "trafconf/trafconfig.h"
+#include "tcdbstore.h"
+
+///////////////////////////////////////////////////////////////////////////////
+//  Cluster Configuration
+///////////////////////////////////////////////////////////////////////////////
+
+CTcdbStore::CTcdbStore( TC_STORAGE_TYPE dbStorageType )
+          : dbStorageType_(dbStorageType)
+{
+    const char method_name[] = "CTcdbStore::CTcdbStore";
+    TRACE_ENTRY;
+    TRACE_EXIT;
+}
+
+CTcdbStore::~CTcdbStore ( void )
+{
+    const char method_name[] = "CTcdbStore::~CTcdbStore";
+    TRACE_ENTRY;
+    TRACE_EXIT;
+}
+

http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/tcdbstore.h
----------------------------------------------------------------------
diff --git a/core/sqf/src/trafconf/tcdbstore.h 
b/core/sqf/src/trafconf/tcdbstore.h
new file mode 100644
index 0000000..9c87a9c
--- /dev/null
+++ b/core/sqf/src/trafconf/tcdbstore.h
@@ -0,0 +1,112 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// @@@ 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 TCDBSTORE_H_
+#define TCDBSTORE_H_
+
+#include "trafconf/trafconfig.h"
+
+using namespace std;
+
+
+//
+// Trafodion Configuration Database Adaptor (CTcdbStore class)
+//
+//  Implements common interface to storage classes used by the
+//  Trafodion Configuration API (trafconfig.cxx/.h).
+//
+
+class CTcdbStore
+{
+protected:
+    int            eyecatcher_;      // Debuggging aid -- leave as first
+                                     // member variable of the class
+public:
+
+    CTcdbStore( TC_STORAGE_TYPE dbStorageType );
+    virtual ~CTcdbStore( void );
+
+    virtual int         AddLNodeData( int nid
+                                    , int pnid
+                                    , int firstCore
+                                    , int lastCore
+                                    , int processors
+                                    , int roles ) = 0;
+    virtual int         AddPNodeData( const char *name
+                                    , int pnid
+                                    , int excludedFirstCore
+                                    , int excludedLastCore ) = 0;
+    virtual int         AddRegistryKey( const char *key ) = 0;
+    virtual int         AddRegistryProcess( const char *name ) = 0;
+    virtual int         AddRegistryClusterData( const char *key
+                                              , const char *dataValue ) = 0;
+    virtual int         AddRegistryProcessData( const char *procName
+                                              , const char *key
+                                              , const char *dataValue ) = 0;
+    virtual int         AddUniqueString( int nid
+                                       , int id
+                                       , const char *uniqStr ) = 0;
+    virtual int         Close( void ) = 0;
+    virtual int         DeleteNodeData( int pnid ) = 0;
+    virtual int         DeleteUniqueString( int nid ) = 0;
+    virtual int         GetNode( int nid
+                               , node_configuration_t &nodeConfig ) = 0;
+    virtual int         GetNode( const char *name
+                               , node_configuration_t &nodeConfig ) = 0;
+    virtual int         GetNodes( int &count
+                                , int max
+                                , node_configuration_t nodeConfig[] ) = 0;
+    virtual int         GetPNode( int pnid
+                                , physical_node_configuration_t &pnodeConfig ) 
= 0;
+    virtual int         GetPNode( const char *name
+                                , physical_node_configuration_t &pnodeConfig ) 
= 0;
+    virtual int         GetSNodes( int &count
+                                 , int max
+                                 , physical_node_configuration_t pNodeConfig[] 
) = 0;
+    virtual int         GetPersistProcess( const char *persistPrefix
+                                         , persist_configuration_t 
&persistConfig ) = 0;
+    virtual int         GetPersistProcessKeys( const char *persistProcessKeys 
) = 0;
+    virtual int         GetRegistryClusterSet( int &count
+                                             , int max
+                                             , registry_configuration_t 
registryConfig[] ) = 0;
+    virtual int         GetRegistryProcessSet( int &count
+                                             , int max
+                                             , registry_configuration_t 
registryConfig[] ) = 0;
+    virtual int         GetUniqueString( int nid, int id, const char *uniqStr 
) = 0;
+    virtual int         GetUniqueStringId( int nid
+                                         , const char *uniqStr
+                                         , int &id ) = 0;
+    virtual int         GetUniqueStringIdMax( int nid, int &id ) = 0;
+    inline TC_STORAGE_TYPE GetStorageType( void ) { return( dbStorageType_ ); }
+    virtual int         Initialize( void ) = 0;
+    virtual bool        IsInitialized( void ) = 0;
+
+protected:
+    TC_STORAGE_TYPE     dbStorageType_;
+private:
+};
+
+
+#endif /* TCDBSTORE_H_ */

http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/tclog.cpp
----------------------------------------------------------------------
diff --git a/core/sqf/src/trafconf/tclog.cpp b/core/sqf/src/trafconf/tclog.cpp
new file mode 100644
index 0000000..0aa3feb
--- /dev/null
+++ b/core/sqf/src/trafconf/tclog.cpp
@@ -0,0 +1,121 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// @@@ 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 <iostream>
+
+using namespace std;
+
+#include <assert.h>
+#include <pthread.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <linux/unistd.h>
+#include "tctrace.h"
+#include "tclog.h"
+
+#define gettid() syscall(__NR_gettid)
+
+pthread_mutex_t       TcLogMutex = PTHREAD_MUTEX_INITIALIZER;
+
+const char *LogLevelStr( int severity )
+{
+    const char *str;
+
+    switch (severity)
+    {
+        case TC_LOG_EMERG:
+            str = "FATAL";
+            break;
+        case TC_LOG_ALERT:
+            str = "WARN";
+            break;
+        case TC_LOG_CRIT:
+            str = "FATAL";
+            break;
+        case TC_LOG_ERR:
+            str = "ERROR";
+            break;
+        case TC_LOG_WARNING:
+            str = "WARN";
+            break;
+        case TC_LOG_NOTICE:
+            str = "INFO";
+            break;
+        case TC_LOG_INFO:
+            str = "INFO";
+            break;
+        case TC_LOG_DEBUG:
+            str = "DEBUG";
+            break;
+        default:
+            str = "INFO";
+    }
+
+    return( str );
+}
+
+int TcLogWrite(int eventType, int severity, char *msg)
+{
+    int status;
+
+    char   eventTimeFmt[20];
+    struct timeval eventTime;
+
+    status = pthread_mutex_lock(&TcLogMutex);
+    assert(status == 0);
+
+    gettimeofday(&eventTime, NULL);
+    struct tm *ltime = localtime(&eventTime.tv_sec);
+    sprintf( eventTimeFmt
+           , "%04d-%02d-%02d %02d:%02d:%02d"
+           , ltime->tm_year+1900
+           , ltime->tm_mon+1
+           , ltime->tm_mday
+           , ltime->tm_hour
+           , ltime->tm_min
+           , ltime->tm_sec );
+
+    fprintf( stderr
+           , "%s,, %s, TRAFCONFIG,,, PIN: %u,,,, TID: %ld, Message ID: %d, 
%s\n"
+           , eventTimeFmt
+           , LogLevelStr(severity)
+           , getpid()
+           , gettid()
+           , eventType
+           , msg );
+
+    status = pthread_mutex_unlock(&TcLogMutex);
+    assert(status == 0);
+    
+    if (TcTraceSettings & TC_TRACE_LOG_MSG)
+    {
+        trace_printf("Log Event: %d, %s\n(%s)\n",
+                     eventType, LogLevelStr(severity), msg);
+    }
+
+    return(0);
+}

http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/tclog.h
----------------------------------------------------------------------
diff --git a/core/sqf/src/trafconf/tclog.h b/core/sqf/src/trafconf/tclog.h
new file mode 100644
index 0000000..e9ec644
--- /dev/null
+++ b/core/sqf/src/trafconf/tclog.h
@@ -0,0 +1,46 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// @@@ 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 TCLOG_H_
+#define TCLOG_H_
+
+#include "common/evl_sqlog_eventnum.h"
+
+using namespace std;
+
+#define TC_LOG_BUF_SIZE 256
+
+#define TC_LOG_EMERG   0   /* system is unusable */
+#define TC_LOG_ALERT   1   /* action must be taken immediately */
+#define TC_LOG_CRIT    2   /* critical conditions */
+#define TC_LOG_ERR     3   /* error conditions */
+#define TC_LOG_WARNING 4   /* warning conditions */
+#define TC_LOG_NOTICE  5   /* normal but significant condition */
+#define TC_LOG_INFO    6   /* informational */
+#define TC_LOG_DEBUG   7   /* debug-level messages */
+
+int TcLogWrite(int event_type, int severity, char *evl_buf);
+
+#endif  /* TCLOG_H_ */

http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/tctrace.cpp
----------------------------------------------------------------------
diff --git a/core/sqf/src/trafconf/tctrace.cpp 
b/core/sqf/src/trafconf/tctrace.cpp
new file mode 100644
index 0000000..b016f0a
--- /dev/null
+++ b/core/sqf/src/trafconf/tctrace.cpp
@@ -0,0 +1,367 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// @@@ 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 <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+using namespace std;
+
+#include "tctrace.h"
+
+#define TC_PROCESS_PATH_MAX    256
+
+const char *CTrafConfigTrace::strTraceEnable_ = "TC_TRACE_ENABLE";
+const char *CTrafConfigTrace::strTraceFile_   = "TC_TRACE_FILE";
+const char *CTrafConfigTrace::strTraceFileFb_ = "TC_TRACE_FILE_FB";
+
+const CTrafConfigTrace::TraceArea_t CTrafConfigTrace::traceAreaList_[] =
+{ 
+    {"TC_TRACE_REQUEST",         TC_TRACE_REQUEST},
+    {"TC_TRACE_NODE",            TC_TRACE_NODE},
+    {"TC_TRACE_PERSIST",         TC_TRACE_PERSIST},
+    {"TC_TRACE_PROCESS",         TC_TRACE_PROCESS},
+    {"TC_TRACE_REGISTRY",        TC_TRACE_REGISTRY},
+    {"TC_TRACE_INIT",            TC_TRACE_INIT},
+    {"TC_TRACE_LOG_MSG",         TC_TRACE_LOG_MSG},
+    {"TC_TRACE_ENTRY_EXIT",      TC_TRACE_ENTRY_EXIT}
+};
+
+// Global trace flags
+long TcTraceSettings = 0;
+
+CTrafConfigTrace::CTrafConfigTrace() 
+                : tracingEnabled_(false)
+                , traceSettingsSaved_(0)
+                , traceFileFb_(0)
+                , traceFileBase_(NULL)
+{
+    numTraceAreas_ = sizeof(traceAreaList_)/sizeof(TraceArea_t);
+}
+
+const char *CTrafConfigTrace::GetEnvStr(const char *key)
+{
+    const char *value;
+    value = getenv(key);
+    return value;
+}
+
+void CTrafConfigTrace::GetEnvInt(const char *key, int &val)
+{
+    const char *p = GetEnvStr(key);
+    if (p != NULL)
+    {
+        val = atoi(p);
+    }
+}
+
+bool CTrafConfigTrace::GetEnvBool(const char *key)
+{
+    const char *p = GetEnvStr(key);
+    bool val = false;
+    if (p != NULL)
+    {
+        val = atoi(p);
+    }
+    return val;
+}
+
+void CTrafConfigTrace::TraceClose( void )
+{
+    trace_close();
+}
+
+void CTrafConfigTrace::TraceInit( bool traceEnabled
+                                , const char *traceLevel
+                                , const char *pfname)
+{
+    bool pathnameUsed = false;
+    char trace_file_name[TC_PROCESS_PATH_MAX];
+    char hostname[TC_PROCESS_PATH_MAX];
+
+    tracingEnabled_ = traceEnabled;
+
+    if (gethostname(hostname,sizeof(hostname)) == -1)
+    {
+        sprintf( hostname,"TC");
+    }
+
+    if (pfname == NULL)
+    {   // Caller did not specify a trace file name, get name from
+        // environment variable if specified.
+        pfname = GetEnvStr(strTraceFile_);
+    }
+    
+    if (pfname == NULL)
+    {   // Use default prefix
+        pfname = "tctrace";
+    }
+
+    if (pfname != NULL)
+    {   // User specified trace file name
+
+        if ( pfname[0] == '/')
+        {
+            // Use filename passed in
+            strcpy(trace_file_name, pfname);
+            pathnameUsed = true;
+        }
+        else
+        {
+            // Format default trace file name and remove any existing trace 
file.
+            if( getenv("SQ_VIRTUAL_NODES") )
+            {
+                sprintf( trace_file_name,"%s/trafconfig.trace.%d.%s"
+                       , getenv("MPI_TMPDIR")
+                       , getpid()
+                       , hostname);
+            }
+            else
+            {
+                sprintf( trace_file_name,"%s/trafconfig.trace.%s"
+                       , getenv("MPI_TMPDIR")
+                       , hostname);
+            }
+            
+            if ((strcmp(pfname, "STDOUT") == 0)
+              || strcmp(pfname, "STDERR") == 0)
+            {
+                strcpy(trace_file_name, pfname);
+            }
+            else // Make user specified file name unique per node
+            {
+                sprintf(trace_file_name,"%s/%s.%d.%s"
+                        , getenv("MPI_TMPDIR")
+                        , pfname
+                        , getpid()
+                        , hostname);
+            }
+        }
+    }
+
+    if (!pathnameUsed)
+    {
+        remove(trace_file_name);
+    }
+
+    // Get any trace settings that were specified via environment variables
+    const char *value;
+
+    for (int i=0; i<numTraceAreas_; i++)
+    {
+        value = getenv(traceAreaList_[i].id);
+        if (value != NULL)
+        {
+            if (atoi(value) != 0)
+                // set the enabled flag for this trace area
+                TcTraceSettings |= traceAreaList_[i].bitFlag;
+        }
+    }
+
+    if (!tracingEnabled_)
+    {
+        // Get environment variable specifying whether tracing is enabled
+        tracingEnabled_ = GetEnvBool(strTraceEnable_);
+        // Get environment variable value for trace buffer size if specified
+        GetEnvInt(strTraceFileFb_, traceFileFb_);
+    }
+
+    // Convert the user specified trace level string to a number.  The
+    // number can be specified as a decimal, octal or hexadecimal
+    // constant.  Combine these flags with current TcTraceSettings that
+    // may have been set via environment variables.
+    long trace_flags;
+    trace_flags = strtol(traceLevel, NULL, 0);
+    if (errno != ERANGE)
+    {
+        TcTraceSettings |= trace_flags;
+    }
+
+    // If any trace settings were specified initialize the trace file
+    if (TcTraceSettings != 0 || tracingEnabled_)
+    {
+        traceSettingsSaved_ = TcTraceSettings;
+
+        if (pfname != NULL)
+        {
+            trace_init(trace_file_name,
+                       false,  // don't append pid to file name
+                       pathnameUsed?(char*)"":(char*)"trafconfig", // file 
prefix
+                       false);
+            if (traceFileFb_ > 0)
+            {
+                trace_set_mem(traceFileFb_);
+            }
+        }
+    }
+}
+
+
+void CTrafConfigTrace::TraceHelpBool( const char *key
+                                    , const char *value
+                                    , const char *key_cmp
+                                    , bool &value_ret )
+{
+    if ((key != NULL) && (strcasecmp(key, key_cmp) == 0))
+    {
+        value_ret = atoi(value);
+    }
+}
+
+void CTrafConfigTrace::TraceHelpInt( const char *key
+                                   , const char *value
+                                   , const char *key_cmp
+                                   , int &value_ret )
+{
+    if ((key != NULL) && (strcasecmp(key, key_cmp) == 0))
+    {
+        value_ret = atoi(value);
+    }
+}
+
+const char *CTrafConfigTrace::TraceHelpStr( const char *key
+                                          , const char *value
+                                          , const char *key_cmp )
+{
+    if ((key != NULL) && (strcasecmp(key, key_cmp) == 0))
+    {
+        return value;
+    }
+    return NULL;
+}
+
+
+void CTrafConfigTrace::TraceChange(const char *key, const char *value)
+{
+    bool trace_was_enabled = tracingEnabled_;
+    const char *pfname;
+    int  old_fb = traceFileFb_;
+
+    if (key == NULL)
+        return;
+
+    // Restore saved trace settings in case trace flags get modified
+    TcTraceSettings = traceSettingsSaved_;
+
+    // Compare the key with each of the trace flag strings.  When
+    // there is an equal compare, assign the value to the appropriate flag.
+    for (int i=0; i<numTraceAreas_; i++)
+    {
+        if (strcasecmp(key, traceAreaList_[i].id) == 0)
+        {
+            if (atoi(value) != 0)
+            {
+                // set the enabled flag for this trace area
+                TcTraceSettings |= traceAreaList_[i].bitFlag;
+            }
+            else // clear the enabled flag for this trace area
+            {
+                TcTraceSettings &= ~traceAreaList_[i].bitFlag;
+            }
+            break;
+        }
+    }
+    // Save current trace settings
+    traceSettingsSaved_ = TcTraceSettings;
+
+
+    // Check if tracing is being enabled/disabled
+    TraceHelpBool(key, value, strTraceEnable_, tracingEnabled_);
+    // Check if trace file buffer size is being specified
+    TraceHelpInt(key, value, strTraceFileFb_, traceFileFb_);
+
+    // Check if trace file base name is being specified
+    pfname = TraceHelpStr(key, value, strTraceFile_);
+    if (pfname != NULL)
+    {   // Save trace file base name
+        delete [] traceFileBase_;
+        traceFileBase_ = new char[strlen(pfname) + 1];
+        strcpy(traceFileBase_, pfname);
+    }
+
+    if (!trace_was_enabled && tracingEnabled_)
+    {
+        char fname[TC_PROCESS_PATH_MAX];
+        char hostname[TC_PROCESS_PATH_MAX];
+        if (gethostname(hostname,sizeof(hostname)) == -1)
+        {
+            sprintf( hostname,"TC");
+        }
+
+        // Formulate trace file name
+        if (traceFileBase_ != NULL)
+        {  // User specified trace file name
+            if ((strcmp(traceFileBase_, "STDOUT") == 0)
+                || strcmp(traceFileBase_, "STDERR") == 0)
+            {
+                strcpy(fname, traceFileBase_);
+            }
+            else 
+            {   // Make user specified file name unique per node
+                sprintf( fname,"%s/%s.%d.%s"
+                       , getenv("MPI_TMPDIR")
+                       , traceFileBase_
+                       , getpid()
+                       , hostname);
+            }
+        }
+        else
+        {   // No user specified trace file name, use default
+            if( getenv("SQ_VIRTUAL_NODES") )
+            {
+                sprintf( fname,"%s/trafconfig.trace.%d.%s"
+                       , getenv("MPI_TMPDIR")
+                       , getpid()
+                       , hostname);
+            }
+            else
+            {
+                sprintf( fname,"%s/trafconfig.trace.%s"
+                       , getenv("MPI_TMPDIR")
+                       , hostname);
+            }
+        }
+
+        // Tracing was disabled and is now enabled, initialize trace
+        trace_init(fname,
+                   false,  // don't append pid to file name
+                   hostname,  // prefix
+                   false);
+    }
+    if (trace_was_enabled && !tracingEnabled_)
+    {
+        // Tracing was enabled and now is disabled, flush trace.  Save
+        // current trace settings.
+        trace_flush();
+
+        TcTraceSettings = 0;
+    }
+
+    // If a new trace file buffer size was specified, set it
+    if ((traceFileFb_ > 0) && (old_fb != traceFileFb_))
+        trace_set_mem(traceFileFb_);
+}

http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/tctrace.h
----------------------------------------------------------------------
diff --git a/core/sqf/src/trafconf/tctrace.h b/core/sqf/src/trafconf/tctrace.h
new file mode 100644
index 0000000..3e72983
--- /dev/null
+++ b/core/sqf/src/trafconf/tctrace.h
@@ -0,0 +1,105 @@
+/**********************************************************************
+// @@@ 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 TCTRACE_H_
+#define TCTRACE_H_
+
+#include "seabed/trace.h"
+
+// All request processing
+#define TC_TRACE_REQUEST         0x00001
+// Node configuration processing
+#define TC_TRACE_NODE            0x00002
+// Persist configuration processing
+#define TC_TRACE_PERSIST         0x00004
+// Persist configuration processing
+#define TC_TRACE_PROCESS         0x00008
+// Registry configuration processing
+#define TC_TRACE_REGISTRY        0x00010
+// Initialization/shutdown information
+#define TC_TRACE_INIT            0x00020
+// Event messages logged (error,informational,critical,etc.)
+#define TC_TRACE_LOG_MSG         0x00040
+// Entry and exit from methods/functions
+#define TC_TRACE_ENTRY_EXIT      0x00080
+
+#define TRACE_ENTRY \
+   if (TcTraceSettings & TC_TRACE_ENTRY_EXIT) trace_printf("%s@%d\n", 
method_name, __LINE__)
+
+#define TRACE_EXIT \
+   if (TcTraceSettings & TC_TRACE_ENTRY_EXIT) trace_printf("%s@%d - Exit\n", 
method_name, __LINE__)
+
+extern long TcTraceSettings;
+
+class CTrafConfigTrace
+{
+public:
+    CTrafConfigTrace();
+    virtual ~CTrafConfigTrace() {}
+
+    void TraceChange( const char *key, const char *value );
+    void TraceClose( void );
+    void TraceInit( bool traceEnabled
+                  , const char *traceLevel
+                  , const char *pfname);
+
+private:
+
+    const char *GetEnvStr( const char *key );
+    void        GetEnvInt( const char *key, int &val );
+    bool        GetEnvBool( const char *key );
+    void        TraceHelpBool( const char *key
+                             , const char *value
+                             , const char *key_cmp
+                             , bool &value_ret );
+    void        TraceHelpInt( const char *key
+                            , const char *value
+                            , const char *key_cmp
+                            , int &value_ret );
+    const char *TraceHelpStr( const char *key
+                            , const char *value
+                            , const char *key_cmp );
+
+    // The number of trace areas held in "traceAreaList"
+    int   numTraceAreas_;
+    bool  tracingEnabled_;
+
+    // Save area for retaining prior trace settings if tracing is
+    // disabled.  These are used to restore the values when tracing
+    // is re-enabled.
+    long  traceSettingsSaved_;
+
+    // Optional size of trace file buffer.
+    int   traceFileFb_;
+    char *traceFileBase_;
+
+    // Array of strings defining various trace areas and the
+    // trace bit flag associated with that area
+    typedef struct {const char *id; long bitFlag;} TraceArea_t;
+    static const TraceArea_t traceAreaList_[];
+
+    static const char *strTraceEnable_;
+    static const char *strTraceFile_;
+    static const char *strTraceFileFb_;
+};
+
+#endif /* TCTRACE_H_ */

http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/trafconf.cpp
----------------------------------------------------------------------
diff --git a/core/sqf/src/trafconf/trafconf.cpp 
b/core/sqf/src/trafconf/trafconf.cpp
new file mode 100644
index 0000000..ad14b9b
--- /dev/null
+++ b/core/sqf/src/trafconf/trafconf.cpp
@@ -0,0 +1,630 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// @@@ 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 @@@
+//
+///////////////////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           
+// File:        trafconf.cxx
+//                                                                           
+// Description: Trafodion configuration display utility program
+//                                                                           
+///////////////////////////////////////////////////////////////////////////////
+using namespace std;
+
+#include <sched.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include "seabed/logalt.h"
+#include "tclog.h"
+#include "tctrace.h"
+#include "clusterconf.h"
+
+#define MAX_TOKEN   132
+
+typedef enum {
+    TrafConfType_Undefined=0,         // Invalid
+    TrafConfType_NodeName,            // Display node names
+    TrafConfType_NodeName_w,          // Display node names
+    TrafConfType_NodeId,              // Display node ids
+    TrafConfType_PhysicalNodeId,      // Display physical node ids
+    TrafConfType_ZoneId,              // Display zone ids
+    // the above displays values as: "<value-1>  <value-2> ..."
+    TrafConfType_NodeConfig,          // Display all nodes configuration 
attributes
+    // 
node-id=0;node-name=n7;cores=0-1;processors=2;roles=connection,aggregation,storage
+
+    TrafConfType_PersistConfig,       // Display all persist configuration 
keys and attributes
+
+    TrafConfType_PersistConfigKeys,   // Display persist configuration keys
+    // PERSIST_PROCESS_KEYS = DTM,TMID,SSCP,SSMP,PSD,WDG,QMN
+
+    TrafConfType_PersistConfigKey     // Display persist configuration 
attributes of a 'key'
+    // { <persist-prefix>_PROCESS_NAME    = {$<string><nid-format>} }
+    // [ <persist-prefix>_PROCESS_TYPE    = {DTM|PERSIST|PSD|SSMP|TMID|WDG} ]
+    // { <persist-prefix>_PROGRAM_NAME    = {<program-name>} }
+    // { <persist-prefix>_REQUIRES_DTM    = {Y|N} } 
+    // [ <persist-prefix>_STDOUT          = {<file-name-prefix><nid-format>} ]
+    // { <persist-prefix>_PERSIST_RETRIES = {<retries> , <time-window-secs>} }
+    // { <persist-prefix>_PERSIST_ZONES   = {<zid-format> [,<zid-format>] . . 
. }
+
+} TrafConfType_t;
+
+bool DisplayBeginEnd = false;   // Valid only with:
+                                //   TrafConfType_NodeConfig
+                                //   TrafConfType_PersistConfig
+bool DisplayShortHost = false;  // Valid only with:
+                                //   TrafConfType_NodeName
+                                //   TrafConfType_NodeName_w
+
+char NodeName[TC_PROCESSOR_NAME_MAX] = { 0 };
+char Key[MAX_TOKEN] = { 0 };
+TrafConfType_t TrafConfType = TrafConfType_Undefined;
+CClusterConfig  ClusterConfig;
+
+//char Node_name[MPI_MAX_PROCESSOR_NAME];
+//int MyPNID = -1;
+long TcTraceSettings = 0;
+
+const char *FormatNidString( FormatNid_t type );
+const char *FormatZidString( FormatZid_t type );
+
+extern const char *PersistProcessTypeString( TC_PROCESS_TYPE type );
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: TcLogWrite()
+//
+// Description:     Display event log message on terminal
+//
+// Usage:           Invoked to display error message
+//
+///////////////////////////////////////////////////////////////////////////////
+int TcLogWrite(int pv_event_type, posix_sqlog_severity_t pv_severity, char 
*pp_string)
+{
+    
+    pv_event_type = pv_event_type;
+    pv_severity = pv_severity;
+    int lv_err = 0;
+
+    printf("%s", pp_string );
+
+    return lv_err;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: DisplayUsage()
+//
+// Description:     Display usage help
+//
+// Usage:           Invoked by main() when no option, -? option, -h option,
+//                  or invalid options are used
+//
+///////////////////////////////////////////////////////////////////////////////
+void DisplayUsage( void )
+{
+    fprintf( stderr, 
+"\nUsage: trafconf { -? | -h | -name | -nameshort | -wname | -wnameshort | 
-node |  -persist }\n"
+"\n   Where:\n"
+"          -?           Displays usage.\n"
+"          -h           Displays usage.\n"
+"          -name        Displays all node names in configuration.\n"
+"                        - Name is as stored in configuration, which could be 
in short host name or FQDN form.\n"
+"          -short       Displays all node names in configuration in short host 
name form.\n"
+"          -wname       Displays all node names in configuration prefixed with 
'-w'\n"
+"                        - Name is as stored in configuration, which could be 
in short host name or FQDN form.\n"
+"          -wshort      Displays all node names in configuration short host 
name form prefixed with '-w'.\n"
+"          -node        Displays node configuration (without begin/end 
brackets).\n"
+"          -persist     Displays persist configuration (without begin/end 
brackets).\n\n"
+"          --node       Displays node configuration (with begin/end 
brackets).\n"
+"          --persist    Displays persist configuration (with begin/end 
brackets).\n\n"
+           );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: RoleTypeString()
+//
+///////////////////////////////////////////////////////////////////////////////
+const char *RoleTypeString( TC_ZONE_TYPE type )
+{
+    const char *str;
+
+    switch( type )
+    {
+        case ZoneType_Edge:
+            str = "connection";
+            break;
+        case ZoneType_Excluded:
+            str = "excluded";
+            break;
+        case ZoneType_Aggregation:
+            str = "aggregation";
+            break;
+        case ZoneType_Storage:
+            str = "storage";
+            break;
+        case ZoneType_Frontend:
+            str = "connection,aggregation";
+            break;
+        case ZoneType_Backend:
+            str = "aggregation,storage";
+            break;
+        case ZoneType_Any:
+            str = "connection,aggregation,storage";
+            break;
+        default:
+            str = "Undefined";
+            break;
+    }
+
+    return( str );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: DisplayNodeAttributes()
+//
+///////////////////////////////////////////////////////////////////////////////
+void DisplayNodeAttributes( CLNodeConfig *lnodeConfig )
+{
+
+    char coresString[MAX_TOKEN];
+
+    if ( lnodeConfig )
+    {
+        if (lnodeConfig->GetLastCore() == -1)
+        {
+            snprintf( coresString, sizeof(coresString)
+                    , "%d", lnodeConfig->GetFirstCore() );
+        }
+        else
+        {
+            snprintf( coresString, sizeof(coresString)
+                    , "%d-%d"
+                    , lnodeConfig->GetFirstCore()
+                    , lnodeConfig->GetLastCore() );
+        }
+        printf( "node-id=%d;node-name=%s;"
+                "cores=%s;processors=%d;roles=%s\n"
+              , lnodeConfig->GetNid()
+              , lnodeConfig->GetName()
+              , coresString
+              , lnodeConfig->GetProcessors()
+              , RoleTypeString( lnodeConfig->GetZoneType() )
+              );
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: NodeNameStr()
+//
+///////////////////////////////////////////////////////////////////////////////
+const char *NodeNameStr( const char *name )
+{
+    char *ptr = (char *)name;
+
+    while ( ptr && *ptr  && DisplayShortHost )
+    {
+        if ( *ptr == '.' && DisplayShortHost )
+        {
+            *ptr = '\0';
+            break;
+        }
+        ptr++;
+    }
+
+    return(name);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: DisplayNodeName()
+//
+///////////////////////////////////////////////////////////////////////////////
+void DisplayNodeName( CLNodeConfig *lnodeConfig, bool dashW )
+{
+    if ( lnodeConfig )
+    {
+        if ( dashW )
+        {
+            printf( "-w " );
+        }
+        printf( "%s ", NodeNameStr(lnodeConfig->GetName()) );
+    }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: DisplayNodesConfig()
+//
+///////////////////////////////////////////////////////////////////////////////
+int DisplayNodeConfig( char *nodeName )
+{
+    int rc   = -1;
+    CLNodeConfig *lnodeConfig;
+
+    lnodeConfig = ClusterConfig.GetFirstLNodeConfig();
+
+    if ( DisplayBeginEnd && TrafConfType == TrafConfType_NodeConfig )
+    {
+        printf( "BEGIN NODE\n\n" );
+    }
+    else if ( TrafConfType == TrafConfType_NodeConfig )
+    {
+        printf( "\n" );
+    }
+    
+    for ( ; lnodeConfig; lnodeConfig = lnodeConfig->GetNext() )
+    {
+        if ( lnodeConfig )
+        {
+            if ( *nodeName == '\0' 
+             || (strcmp( nodeName, lnodeConfig->GetName()) == 0))
+            {
+                switch (TrafConfType)
+                {
+                    case TrafConfType_NodeConfig:
+                        DisplayNodeAttributes( lnodeConfig );
+                        break;
+                    case TrafConfType_NodeName:
+                        DisplayNodeName( lnodeConfig, false );
+                        break;
+                    case TrafConfType_NodeName_w:
+                        DisplayNodeName( lnodeConfig, true );
+                        break;
+                    default:
+                        printf( "Invalid configuration type!\n" );
+                }
+                rc   = 0;
+            }
+            if (*nodeName != '\0' 
+             && strcmp( nodeName, lnodeConfig->GetName()) == 0)
+            {
+                break;
+            }
+        }
+    }
+
+    if ( DisplayBeginEnd && TrafConfType == TrafConfType_NodeConfig )
+    {
+        printf( "\nEND NODE\n" );
+    }
+    else if ( TrafConfType == TrafConfType_NodeConfig )
+    {
+        printf( "\n" );
+    }
+
+    return(rc);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: DisplayPersistKeys()
+//
+///////////////////////////////////////////////////////////////////////////////
+int DisplayPersistKeys( void )
+{
+    int rc   = -1;
+    char persist_config_str[MAX_TOKEN];
+    CPersistConfig *persistConfig;
+
+    persistConfig = ClusterConfig.GetFirstPersistConfig();
+    if (persistConfig)
+    {
+        snprintf( persist_config_str, sizeof(persist_config_str)
+                , "%s = ", PERSIST_PROCESS_KEYS );
+        for ( ; persistConfig; persistConfig = persistConfig->GetNext() )
+        {
+            strcat( persist_config_str, persistConfig->GetPersistPrefix() );
+            if ( persistConfig->GetNext() )
+            {
+                strcat( persist_config_str, "," );
+            }
+            rc   = 0;
+        }
+        printf ("%s\n\n", persist_config_str);
+    }
+    else
+    {
+        printf ("Configuration keys for persistent process do not exist\n");
+    }
+
+    return(rc);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: DisplayPersistConfig()
+//
+///////////////////////////////////////////////////////////////////////////////
+int DisplayPersistConfig( char *key )
+{
+    int rc   = -1;
+    bool foundConfig = false;
+    char persist_config_buf[TC_PERSIST_VALUE_MAX*2];
+    char process_name_str[TC_PERSIST_VALUE_MAX];
+    char process_type_str[TC_PERSIST_VALUE_MAX];
+    char program_name_str[TC_PERSIST_VALUE_MAX];
+    char program_args_str[TC_PERSIST_VALUE_MAX];
+    char requires_dtm_str[TC_PERSIST_VALUE_MAX];
+    char stdout_str[TC_PERSIST_VALUE_MAX];
+    char persist_retries_str[TC_PERSIST_VALUE_MAX];
+    char persist_zones_str[TC_PERSIST_VALUE_MAX];
+    CPersistConfig *persistConfig;
+
+    if ( DisplayBeginEnd )
+    {
+        printf( "BEGIN PERSIST\n\n" );
+    }
+    else
+    {
+        printf( "\n" );
+    }
+
+    if (*key == '\0')
+    {
+        DisplayPersistKeys();
+    }
+    
+    persistConfig = ClusterConfig.GetFirstPersistConfig();
+    if (persistConfig)
+    {
+        for ( ; persistConfig; persistConfig = persistConfig->GetNext() )
+        {
+            if (*key == '\0' ||
+                 strcasecmp( key, persistConfig->GetPersistPrefix()) == 0)
+            {
+                foundConfig = true;
+                snprintf( process_name_str, sizeof(process_name_str)
+                        , "%s_%s    = %s%s"
+                        , persistConfig->GetPersistPrefix()
+                        , PERSIST_PROCESS_NAME_KEY
+                        , persistConfig->GetProcessNamePrefix()
+                        , persistConfig->GetProcessNameFormat()
+                        );
+                snprintf( process_type_str, sizeof(process_type_str)
+                        , "%s_%s    = %s"
+                        , persistConfig->GetPersistPrefix()
+                        , PERSIST_PROCESS_TYPE_KEY
+                        , 
PersistProcessTypeString(persistConfig->GetProcessType())
+                        );
+                snprintf( program_name_str, sizeof(program_name_str)
+                        , "%s_%s    = %s"
+                        , persistConfig->GetPersistPrefix()
+                        , PERSIST_PROGRAM_NAME_KEY
+                        , persistConfig->GetProgramName()
+                        );
+                snprintf( program_args_str, sizeof(program_args_str)
+                        , "%s_%s    = %s"
+                        , persistConfig->GetPersistPrefix()
+                        , PERSIST_PROGRAM_ARGS_KEY
+                        , strlen(persistConfig->GetProgramArgs())
+                            ?persistConfig->GetProgramArgs():""
+                        );
+                snprintf( requires_dtm_str, sizeof(requires_dtm_str)
+                        , "%s_%s    = %s"
+                        , persistConfig->GetPersistPrefix()
+                        , PERSIST_REQUIRES_DTM
+                        , persistConfig->GetRequiresDTM()?"Y":"N"
+                        );
+                snprintf( stdout_str, sizeof(stdout_str)
+                        , "%s_%s          = %s%s"
+                        , persistConfig->GetPersistPrefix()
+                        , PERSIST_STDOUT_KEY
+                        , persistConfig->GetStdoutPrefix()
+                        , persistConfig->GetStdoutFormat()
+                        );
+                snprintf( persist_retries_str, sizeof(persist_retries_str)
+                        , "%s_%s = %d,%d"
+                        , persistConfig->GetPersistPrefix()
+                        , PERSIST_RETRIES_KEY
+                        , persistConfig->GetPersistRetries()
+                        , persistConfig->GetPersistWindow()
+                        );
+                snprintf( persist_zones_str, sizeof(persist_zones_str)
+                        , "%s_%s   = %s"
+                        , persistConfig->GetPersistPrefix()
+                        , PERSIST_ZONES_KEY
+                        , persistConfig->GetZoneFormat()
+                        );
+                snprintf( persist_config_buf, sizeof(persist_config_buf)
+                        , "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n"
+                        , process_name_str
+                        , process_type_str
+                        , program_name_str
+                        , program_args_str
+                        , requires_dtm_str
+                        , stdout_str
+                        , persist_retries_str
+                        , persist_zones_str
+                        );
+                if (strcasecmp( key, persistConfig->GetPersistPrefix()) == 0)
+                {
+                    printf ("%s", persist_config_buf);
+                    break;
+                }
+                if (persistConfig->GetNext())
+                {
+                    printf ("%s\n", persist_config_buf);
+                }
+                else
+                {
+                    printf ("%s", persist_config_buf);
+                }
+                rc   = 0;
+            }
+        }
+    }
+    if (!foundConfig)
+    {
+        printf ("Persistent process configuration does not exist\n");
+    }
+
+    if ( DisplayBeginEnd )
+    {
+        printf( "\nEND PERSIST\n" );
+    }
+    else
+    {
+        printf( "\n" );
+    }
+
+    return(rc);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: ProcessTrafConfig()
+//
+///////////////////////////////////////////////////////////////////////////////
+int ProcessTrafConfig( void )
+{
+    int rc   = -1;
+
+    switch (TrafConfType)
+    {
+        case TrafConfType_NodeConfig:
+        case TrafConfType_NodeName:
+        case TrafConfType_NodeName_w:
+            rc = DisplayNodeConfig( NodeName );
+            break;
+        case TrafConfType_PersistConfig:
+        case TrafConfType_PersistConfigKeys:
+        case TrafConfType_PersistConfigKey:
+            rc = DisplayPersistConfig( Key );
+            break;
+        case TrafConfType_NodeId:
+        case TrafConfType_PhysicalNodeId:
+        case TrafConfType_ZoneId:
+        default:
+            printf( "Not implemented, yet!\n" );
+    }
+
+    return( rc );
+}
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Function/Method: Program Main
+//
+///////////////////////////////////////////////////////////////////////////////
+int main( int argc, char *argv[] )
+{
+    int  error = 0;
+
+    if ( argc == 1 )
+    {
+        DisplayUsage();
+        return 0;
+    }
+
+    // Get required runtime options
+    for ( int argx = 1; argx < argc; argx++ )
+    {
+        if ( strcmp( argv [argx], "-?" ) == 0 )
+        {
+            DisplayUsage();
+            return 0;
+        }
+        else if ( strcasecmp( argv [argx], "-h" ) == 0 )
+        {
+            DisplayUsage();
+            return 0;
+        }
+        else if ( strcasecmp( argv [argx], "-name" ) == 0 )
+        {
+            TrafConfType = TrafConfType_NodeName;
+        }
+        else if ( strcasecmp( argv [argx], "-wname" ) == 0 )
+        {
+            TrafConfType = TrafConfType_NodeName_w;
+        }
+        else if ( strcasecmp( argv [argx], "-short" ) == 0 )
+        {
+            DisplayShortHost = true;
+            TrafConfType = TrafConfType_NodeName;
+        }
+        else if ( strcasecmp( argv [argx], "-wshort" ) == 0 )
+        {
+            DisplayShortHost = true;
+            TrafConfType = TrafConfType_NodeName_w;
+        }
+        else if ( strcasecmp( argv [argx], "-node" ) == 0 )
+        {
+            TrafConfType = TrafConfType_NodeConfig;
+        }
+        else if ( strcasecmp( argv [argx], "-persist" ) == 0 )
+        {
+            TrafConfType = TrafConfType_PersistConfig;
+        }
+        else if ( strcasecmp( argv [argx], "--node" ) == 0 )
+        {
+            DisplayBeginEnd = true;
+            TrafConfType = TrafConfType_NodeConfig;
+        }
+        else if ( strcasecmp( argv [argx], "--persist" ) == 0 )
+        {
+            DisplayBeginEnd = true;
+            TrafConfType = TrafConfType_PersistConfig;
+        }
+        else
+        {
+            DisplayUsage();
+            return 0;
+        }
+    }
+
+    char *env;
+    bool traceEnabled = false;
+    env = getenv("TC_TRACE_ENABLE");
+    if ( env && *env == '1' )
+    {
+        traceEnabled = true;
+    }
+
+    if ( !ClusterConfig.Initialize( traceEnabled, NULL ) )
+    {
+        printf( "Failed to initialize Trafodion Configuration!\n" );
+        exit( EXIT_FAILURE );
+    }
+    else
+    {
+        if ( !ClusterConfig.LoadConfig() )
+        {
+            printf( "Failed to load Trafodion Configuration!\n" );
+            exit( EXIT_FAILURE );
+        }
+    }
+
+    error = ProcessTrafConfig();
+    if ( error )
+    {
+        exit( EXIT_FAILURE );
+    }
+
+    exit( EXIT_SUCCESS );
+}

http://git-wip-us.apache.org/repos/asf/trafodion/blob/87849fcf/core/sqf/src/trafconf/trafconfig.cpp
----------------------------------------------------------------------
diff --git a/core/sqf/src/trafconf/trafconfig.cpp 
b/core/sqf/src/trafconf/trafconfig.cpp
new file mode 100644
index 0000000..e3c43ee
--- /dev/null
+++ b/core/sqf/src/trafconf/trafconfig.cpp
@@ -0,0 +1,599 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// @@@ 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 "tcdb.h"
+#include "tctrace.h"
+#include "trafconf/trafconfig.h"
+
+bool TcTraceEnabled = false;
+
+CTrafConfigTrace    TrafConfigTrace;
+CTcdb               TrafConfigDb;
+
+///////////////////////////////////////////////////////////////////////////////
+//  Trafodion Configuration
+///////////////////////////////////////////////////////////////////////////////
+
+TC_Export int tc_close( void )
+{
+    int rc = TrafConfigDb.Close();
+
+    if (TcTraceEnabled)
+    {
+        TrafConfigTrace.TraceClose();
+    }
+
+    return( rc );
+}
+
+TC_Export const char *tc_errmsg( int err )
+{
+    switch (err)
+    {
+        case TCSUCCESS:
+            return "Successful operation";
+        case TCNOTIMPLEMENTED:
+            return "Not implemented";
+        case TCNOTINIT:
+            return "Database not open";
+        case TCALREADYINIT:
+            return "Database already opened";
+        case TCDBOPERROR:
+            return "Database operation failed";
+        case TCDBNOEXIST:
+            return "Database operation yielded non-existent data";
+        case TCDBTRUNCATE:
+            return "Database operation returned less data than available";
+        case TCDBCORRUPT:
+            return "Internal processing error or database corruption";
+        default:
+            break;
+    }
+    return "Error undefined!";
+}
+
+TC_Export int tc_initialize( bool traceEnabled
+                           , const char *traceFileName
+                           , const char *instanceNode
+                           , const char *rootNode )
+{
+    int rc;
+
+    if ( TrafConfigDb.IsInitialized() )
+    {
+        return( TCALREADYINIT );
+    }
+
+    TcTraceEnabled = traceEnabled;
+    if (TcTraceEnabled)
+    {
+        TrafConfigTrace.TraceInit( TcTraceEnabled, "0", traceFileName );
+    }
+
+    switch (TrafConfigDb.GetStorageType())
+    {
+        case TCDBMYSQL:
+            if (!instanceNode)
+            {
+                instanceNode = TC_INSTANCE_NODE;
+            }
+            if (!rootNode)
+            {
+                rootNode = TC_ROOT_NODE;
+            }
+            rc = TrafConfigDb.Initialize( rootNode
+                                        , instanceNode );
+            break;
+        case TCDBSQLITE:
+            rc = TrafConfigDb.Initialize();
+            break;
+        default:
+            rc = TCNOTIMPLEMENTED;
+    }
+
+    return( rc );
+}
+
+TC_Export int tc_delete_node( int nid
+                            , const char *node_name )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+    node_configuration_t nodeConfig;
+
+    if (node_name)
+    {
+        rc = TrafConfigDb.GetNode( node_name, nodeConfig );
+        if ( rc != TCSUCCESS)
+        {
+            return( rc );
+        }
+    }
+    else
+    {
+        rc = TrafConfigDb.GetNode( nid, nodeConfig );
+        if ( rc != TCSUCCESS)
+        {
+            return( rc );
+        }
+    }
+
+    if ( nodeConfig.nid != -1)
+    {
+        rc = TrafConfigDb.DeleteNodeData( nodeConfig.pnid );
+    }
+
+    return( rc );
+}
+
+TC_Export int tc_get_node( const char *node_name
+                         , node_configuration_t *node_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.GetNode( node_name, *node_config );
+
+    return( rc );
+}
+
+TC_Export int tc_put_node( node_configuration_t *node_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.AddPNodeData( node_config->node_name
+                                  , node_config->pnid
+                                  , node_config->excluded_first_core
+                                  , node_config->excluded_last_core );
+    if (rc == TCSUCCESS)
+    {
+        rc = TrafConfigDb.AddLNodeData( node_config->nid
+                                      , node_config->pnid
+                                      , node_config->first_core
+                                      , node_config->last_core
+                                      , node_config->processors
+                                      , node_config->roles );
+    }
+
+    return( rc );
+}
+
+TC_Export int tc_get_pnode( const char *node_name
+                          , physical_node_configuration_t *pnode_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.GetPNode( node_name, *pnode_config );
+
+    return( rc );
+}
+
+TC_Export int tc_put_pnode( physical_node_configuration_t *pnode_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.AddPNodeData( pnode_config->node_name
+                                  , pnode_config->pnid
+                                  , pnode_config->excluded_first_core
+                                  , pnode_config->excluded_last_core );
+
+    return( rc );
+}
+
+TC_Export int tc_get_nodes( int *count
+                          , int  max
+                          , node_configuration_t *node_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    if ( node_config == NULL )
+    {
+        max = 0;
+    }
+
+    rc = TrafConfigDb.GetNodes( *count, max, node_config );
+
+    return( rc );
+}
+
+TC_Export int tc_get_snodes( int *scount
+                           , int  max
+                           , physical_node_configuration_t *pnode_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    if ( pnode_config == NULL )
+    {
+        max = 0;
+    }
+
+    rc = TrafConfigDb.GetSNodes( *scount, max, pnode_config );
+
+    return( rc );
+}
+
+TC_Export int tc_delete_persist_keys( void )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCNOTIMPLEMENTED;
+
+    //
+
+    return( rc );
+}
+
+TC_Export int tc_get_persist_keys( const char *persist_keys )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.GetPersistProcessKeys( persist_keys );
+
+    return( rc );
+}
+
+TC_Export int tc_put_persist_keys( const char *persist_keys )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCNOTIMPLEMENTED;
+
+    persist_keys = persist_keys;
+    //
+
+    return( rc );
+}
+
+TC_Export int tc_delete_persist_process( const char *persist_key_prefix )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCNOTIMPLEMENTED;
+
+    persist_key_prefix = persist_key_prefix;
+    //
+
+    return( rc );
+}
+
+TC_Export int tc_get_persist_process( const char *persist_key_prefix
+                                    , persist_configuration_t *persist_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.GetPersistProcess( persist_key_prefix, *persist_config );
+
+    return( rc );
+}
+
+TC_Export int tc_put_persist_process( const char *persist_key_prefix
+                                    , persist_configuration_t *persist_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCNOTIMPLEMENTED;
+
+    persist_key_prefix = persist_key_prefix;
+    persist_config = persist_config;
+    //
+
+    return( rc );
+}
+
+TC_Export int tc_get_registry_cluster_set( int *count
+                                         , int  max
+                                         , registry_configuration_t 
*registry_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.GetRegistryClusterSet( *count, max, registry_config );
+
+    return( rc );
+}
+
+TC_Export int tc_get_registry_process_set( int *count
+                                         , int  max
+                                         , registry_configuration_t 
*registry_config )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.GetRegistryProcessSet( *count, max, registry_config );
+
+    return( rc );
+}
+
+TC_Export int tc_get_registry_key( const char *key )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCNOTIMPLEMENTED;
+
+    key          = key;
+    //rc = TrafConfigDb.GetRegistryKey( key );
+
+    return( rc );
+}
+
+TC_Export int tc_put_registry_key( const char *key )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.AddRegistryKey( key );
+
+    return( rc );
+}
+
+TC_Export int tc_get_registry_process( const char *process_name )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCNOTIMPLEMENTED;
+
+    process_name = process_name;
+    //rc = TrafConfigDb.GetRegistryProcess( process_name );
+
+    return( rc );
+}
+
+TC_Export int tc_put_registry_process( const char *process_name )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.AddRegistryProcess( process_name );
+
+    return( rc );
+}
+
+TC_Export int tc_get_registry_cluster_data( const char *key
+                                          , const char *data )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCNOTIMPLEMENTED;
+
+    key          = key;
+    data         = data;
+    //rc = TrafConfigDb.GetRegistryClusterData( key, data );
+
+    return( rc );
+}
+
+TC_Export int tc_put_registry_cluster_data( const char *key
+                                          , const char *data )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.AddRegistryClusterData( key, data );
+
+    return( rc );
+}
+
+TC_Export int tc_get_registry_process_data( const char *process_name
+                                          , const char *key
+                                          , const char *data )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCNOTIMPLEMENTED;
+
+    process_name = process_name;
+    key          = key;
+    data         = data;
+    //rc = TrafConfigDb.GetRegistryProcessData( process_name, key, data );
+
+    return( rc );
+}
+
+TC_Export int tc_put_registry_process_data( const char *process_name
+                                          , const char *key
+                                          , const char *data )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.AddRegistryProcessData( process_name, key, data );
+
+    return( rc );
+}
+
+TC_Export TC_STORAGE_TYPE tc_get_storage_type( void )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCDBSTOREUNDEFINED );
+    }
+
+    return( TrafConfigDb.GetStorageType() );
+}
+
+TC_Export int tc_delete_unique_strings( int nid )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.DeleteUniqueString( nid );
+
+    return( rc );
+}
+
+
+TC_Export int tc_get_unique_string( int nid, int id, const char *unique_string 
)
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.GetUniqueString( nid, id, unique_string );
+
+    return( rc );
+}
+
+TC_Export int tc_put_unique_string( int nid, int id, const char *unique_string 
)
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.AddUniqueString( nid, id, unique_string );
+
+    return( rc );
+}
+
+TC_Export int tc_get_unique_string_id( int nid, const char *unique_string, int 
*id )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.GetUniqueStringId( nid, unique_string, *id );
+
+    return( rc );
+}
+
+TC_Export int tc_get_unique_string_id_max( int nid, int *id )
+{
+    if ( ! TrafConfigDb.IsInitialized() )
+    {
+        return( TCNOTINIT );
+    }
+
+    int rc = TCDBOPERROR;
+
+    rc = TrafConfigDb.GetUniqueStringIdMax( nid, *id );
+
+    return( rc );
+}
+

Reply via email to