1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // CegoAdmNet.cc
4 // ----------
5 // Cego net client interface
6 //
7 // Design and Implementation by Bjoern Lemke
8 //
9 // (C)opyright 2010-2019 Bjoern Lemke
10 //
11 // IMPLEMENTATION MODULE
12 //
13 // Class: CegoAdmNet
14 //
15 // Description: Description: Database administration API
16 //
17 // Status: CLEAN
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20 
21 // cego includes
22 #include "CegoAdmNet.h"
23 #include "CegoDefs.h"
24 
25 #include <lfcbase/Net.h>
26 
CegoAdmNet()27 CegoAdmNet::CegoAdmNet()
28 {
29     _pN = 0;
30     _pAH = 0;
31     _pModule = 0;
32 }
33 
CegoAdmNet(const Chain & logFile,const Chain & progName,const Chain & logLevel)34 CegoAdmNet::CegoAdmNet(const Chain& logFile, const Chain& progName, const Chain& logLevel)
35 {
36     _logFile = logFile;
37     _progName = progName;
38     _logLevel = logLevel;
39     _pN = 0;
40     _pAH = 0;
41     _pModule = 0;
42 }
43 
~CegoAdmNet()44 CegoAdmNet::~CegoAdmNet()
45 {
46     if ( _pAH )
47 	delete _pAH;
48     if ( _pN )
49 	delete _pN;
50     if ( _pModule )
51 	delete _pModule;
52 }
53 
connect(const Chain & serverName,int port,const Chain & user,const Chain & pwd)54 void CegoAdmNet::connect(const Chain& serverName, int port, const Chain& user, const Chain& pwd)
55 {
56     Net n (  NETMNG_MSG_BUFLEN, NETMNG_SIZEBUFLEN, NETMNG_MAXSENDLEN );
57 
58     _pN = n.connect(serverName, port);
59 
60     if ( _logFile.length() > 1 )
61     {
62 	_pModule = new CegoModule(_logFile, _progName);
63 
64 	int modId = 100;
65 
66 	if ( _logLevel == Chain("notice"))
67 	    _pModule->logModule(modId, "dbdimp", Logger::NOTICE);
68 	else if ( _logLevel == Chain("error"))
69 	    _pModule->logModule(modId, "dbdimp", Logger::LOGERR);
70 	else if ( _logLevel == Chain("debug"))
71 	    _pModule->logModule(modId, "dbdimp", Logger::DEBUG);
72 	else
73 	    _pModule->logModule(modId, "dbdimp", Logger::NONE);
74 
75     }
76     else
77     {
78 	_pModule = new CegoModule;
79     }
80 
81 
82     _pAH = new CegoAdminHandler( _pModule, _pN);
83 
84     CegoAdminHandler::ResultType res = _pAH->requestSession(user, pwd);
85     if ( res != CegoAdminHandler::ADM_OK )
86     {
87 	Chain msg;
88 	_pAH->getMsg(msg);
89 	throw Exception(EXLOC, msg);
90     }
91 }
92 
getTableSetInfo(const Chain & tableSet,ListT<Chain> & tsInfoList,ListT<Chain> & fileInfoList,ListT<Chain> & logInfoList)93 void CegoAdmNet::getTableSetInfo(const Chain& tableSet,
94 				 ListT<Chain>& tsInfoList,
95 				 ListT<Chain>& fileInfoList,
96 				 ListT<Chain>& logInfoList)
97 {
98     CegoAdminHandler::ResultType res;
99     res = _pAH->medGetDetailedTableSetInfo(tableSet);
100     handleMedResult(res);
101 
102     CegoTableObject oe;
103     ListT<ListT<CegoFieldValue> > tsinfo;
104 
105     _pAH->getDetailedTableSetInfo(oe, tsinfo);
106 
107     ListT<CegoFieldValue> *pTSI = tsinfo.First();
108     while ( pTSI )
109     {
110 	Chain attr;
111 	Chain val;
112 
113 	CegoFieldValue *pF = pTSI->First();
114 	if ( pF )
115 	    attr = pF->valAsChain();
116 	pF = pTSI->Next();
117 	if ( pF )
118 	    val = pF->valAsChain();
119 
120 	Chain attrVal = attr + Chain(":") + val;
121 	tsInfoList.Insert( attrVal );
122 	pTSI = tsinfo.Next();
123     }
124 
125 
126     Chain format;
127     ListT<ListT<CegoFieldValue> > fileinfo;
128     _pAH->getDataFileInfo(oe, fileinfo, format);
129 
130     ListT<CegoFieldValue> *pFI = fileinfo.First();
131     while ( pFI )
132     {
133 
134 	Chain name;
135 	Chain type;
136 	Chain size;
137 	Chain used;
138 
139 	CegoFieldValue *pF = pFI->First();
140 	if ( pF )
141 	    name = pF->valAsChain();
142 	pF = pFI->Next();
143 	if ( pF )
144 	    type = pF->valAsChain();
145 
146 	pF = pFI->Next();
147 	if ( pF )
148 	    size = pF->valAsChain();
149 
150 	pF = pFI->Next();
151 	if ( pF )
152 	    used = pF->valAsChain();
153 
154 	Chain attrVal = name + Chain(":") + type + Chain(":") + size + Chain(":") + used;
155 	fileInfoList.Insert( attrVal );
156 
157 	pFI = fileinfo.Next();
158     }
159 
160 
161     ListT<ListT<CegoFieldValue> > loginfo;
162     _pAH->getLogInfo(oe, loginfo);
163 
164     ListT<CegoFieldValue> *pLI = loginfo.First();
165     while ( pLI )
166     {
167 
168 	Chain name;
169 	Chain status;
170 	Chain size;
171 	Chain offset;
172 	Chain usage;
173 
174 	CegoFieldValue *pF = pLI->First();
175 	if ( pF )
176 	    name = pF->valAsChain();
177 	pF = pLI->Next();
178 	if ( pF )
179 	    status = pF->valAsChain();
180 
181 	pF = pLI->Next();
182 	if ( pF )
183 	    size = pF->valAsChain();
184 
185 	pF = pLI->Next();
186 	if ( pF )
187 	    offset= pF->valAsChain();
188 
189 	pF = pLI->Next();
190 	if ( pF )
191 	    usage= pF->valAsChain();
192 
193 
194 	Chain attrVal = name + Chain(":") + status + Chain(":") + size + Chain(":") + offset + Chain(":") + usage;
195 	logInfoList.Insert( attrVal );
196 
197 	pLI = loginfo.Next();
198     }
199 }
200 
getTableSetList(ListT<Chain> & tslist)201 void CegoAdmNet::getTableSetList(ListT<Chain>& tslist)
202 {
203 
204     CegoAdminHandler::ResultType res;
205 
206     res = _pAH->medGetTableSetList();
207     handleMedResult(res);
208 
209     CegoTableObject oe;
210     ListT<ListT<CegoFieldValue> > info;
211 
212     _pAH->getTableSetList(oe, info);
213 
214     ListT<CegoFieldValue> *pFL = info.First();
215     while ( pFL )
216     {
217 	CegoFieldValue *pF = pFL->First();
218 	if ( pF )
219 	    tslist.Insert(pF->valAsChain());
220 	pFL = info.Next();
221     }
222 }
223 
startTableSet(const Chain & tableSet,bool doCleanup,bool forceload,bool cpDump,bool noInit)224 void CegoAdmNet::startTableSet(const Chain& tableSet, bool doCleanup, bool forceload, bool cpDump, bool noInit)
225 {
226 
227     CegoAdminHandler::ResultType res;
228     res = _pAH->medStartTableSet(tableSet, doCleanup, forceload, cpDump, noInit);
229 
230     handleMedResult(res);
231 }
232 
stopTableSet(const Chain & tableSet)233 void CegoAdmNet::stopTableSet(const Chain& tableSet)
234 {
235     CegoAdminHandler::ResultType res;
236     res = _pAH->medStopTableSet(tableSet);
237     handleMedResult(res);
238 }
239 
getThreadInfo(ListT<Chain> & threadInfoList)240 void CegoAdmNet::getThreadInfo(ListT<Chain>& threadInfoList)
241 {
242     CegoAdminHandler::ResultType res;
243 
244     res = _pAH->reqThreadInfo();
245     handleMedResult(res);
246 
247     CegoTableObject oe;
248     ListT<ListT<CegoFieldValue> > threadinfo;
249 
250     _pAH->getThreadInfo(oe, threadinfo);
251 
252     ListT<CegoFieldValue> *pTI = threadinfo.First();
253     while ( pTI )
254     {
255 
256 	Chain id;
257 	Chain status;
258 
259 	CegoFieldValue *pF = pTI->First();
260 	if ( pF )
261 	    id = pF->valAsChain();
262 	pF = pTI->Next();
263 	if ( pF )
264 	    status = pF->valAsChain();
265 
266 	Chain attrVal = id + Chain(":") + status;
267 	threadInfoList.Insert( attrVal );
268 
269 	pTI = threadinfo.Next();
270     }
271 }
272 
getDbThreadInfo(ListT<Chain> & dbThreadInfoList)273 void CegoAdmNet::getDbThreadInfo(ListT<Chain>& dbThreadInfoList)
274 {
275     CegoAdminHandler::ResultType res;
276 
277     res = _pAH->reqDbThreadInfo();
278     handleMedResult(res);
279 
280     CegoTableObject oe;
281     ListT<ListT<CegoFieldValue> > dbthreadinfo;
282 
283     Chain format;
284     _pAH->getDbThreadInfo(oe, dbthreadinfo, format);
285 
286     ListT<CegoFieldValue> *pDBTI = dbthreadinfo.First();
287     while ( pDBTI )
288     {
289 
290 	Chain id;
291 	Chain numReq;
292 	Chain status;
293 	Chain lastAction;
294 
295 	CegoFieldValue *pF = pDBTI->First();
296 	if ( pF )
297 	    id = pF->valAsChain();
298 	pF = pDBTI->Next();
299 	if ( pF )
300 	    numReq = pF->valAsChain();
301 	pF = pDBTI->Next();
302 	if ( pF )
303 	    status = pF->valAsChain();
304 
305 	CegoTableObject oe;
306 	ListT<ListT<CegoFieldValue> > lastactioninfo;
307 
308 	Chain format;
309 	_pAH->getDbThreadLastQuery(id.asInteger(), oe, lastactioninfo, format);
310 	ListT<CegoFieldValue> *pLAI = lastactioninfo.First();
311 	if ( pLAI )
312 	{
313 	    CegoFieldValue *pF = pLAI->First();
314 	    if ( pF )
315 		lastAction = pF->valAsChain();
316 	}
317 
318 	Chain attrVal = id + Chain(":") + numReq + Chain(":") + status + Chain(":") + lastAction;
319 
320 	dbThreadInfoList.Insert( attrVal );
321 
322 	pDBTI = dbthreadinfo.Next();
323     }
324 }
325 
getAdmThreadInfo(ListT<Chain> & admThreadInfoList)326 void CegoAdmNet::getAdmThreadInfo(ListT<Chain>& admThreadInfoList)
327 {
328     CegoAdminHandler::ResultType res;
329 
330     res = _pAH->reqAdmThreadInfo();
331     handleMedResult(res);
332 
333     CegoTableObject oe;
334     ListT<ListT<CegoFieldValue> > admthreadinfo;
335 
336     Chain format;
337     _pAH->getAdmThreadInfo(oe, admthreadinfo, format);
338 
339     ListT<CegoFieldValue> *pAdmTI = admthreadinfo.First();
340     while ( pAdmTI )
341     {
342 
343 	Chain id;
344 	Chain numReq;
345 	Chain status;
346 
347 	CegoFieldValue *pF = pAdmTI->First();
348 	if ( pF )
349 	    id = pF->valAsChain();
350 	pF = pAdmTI->Next();
351 	if ( pF )
352 	    numReq = pF->valAsChain();
353 	pF = pAdmTI->Next();
354 	if ( pF )
355 	    status = pF->valAsChain();
356 
357 	Chain attrVal = id + Chain(":") + numReq + Chain(":") + status;
358 
359 	admThreadInfoList.Insert( attrVal );
360 
361 	pAdmTI = admthreadinfo.Next();
362     }
363 }
364 
getLogThreadInfo(ListT<Chain> & logThreadInfoList)365 void CegoAdmNet::getLogThreadInfo(ListT<Chain>& logThreadInfoList)
366 {
367     CegoAdminHandler::ResultType res;
368 
369     res = _pAH->reqLogThreadInfo();
370     handleMedResult(res);
371 
372     CegoTableObject oe;
373     ListT<ListT<CegoFieldValue> > logthreadinfo;
374 
375     Chain format;
376     _pAH->getLogThreadInfo(oe, logthreadinfo, format);
377 
378     ListT<CegoFieldValue> *pLogTI = logthreadinfo.First();
379     while ( pLogTI )
380     {
381 
382 	Chain id;
383 	Chain numReq;
384 	Chain status;
385 
386 	CegoFieldValue *pF = pLogTI->First();
387 	if ( pF )
388 	    id = pF->valAsChain();
389 	pF = pLogTI->Next();
390 	if ( pF )
391 	    numReq = pF->valAsChain();
392 	pF = pLogTI->Next();
393 	if ( pF )
394 	    status = pF->valAsChain();
395 
396 	Chain attrVal = id + Chain(":") + numReq + Chain(":") + status;
397 
398 	logThreadInfoList.Insert( attrVal );
399 
400 	pLogTI = logthreadinfo.Next();
401     }
402 }
403 
importTableSet(const Chain & tableSet,const Chain & impMode,const Chain & impFile)404 void CegoAdmNet::importTableSet(const Chain& tableSet, const Chain& impMode, const Chain& impFile)
405 {
406     CegoAdminHandler::ResultType res;
407     bool isStructure=false;
408 
409     res = _pAH->reqImportTableSet(tableSet, isStructure, impFile, impMode);
410     handleMedResult(res);
411 }
412 
exportTableSet(const Chain & tableSet,const Chain & expMode,const Chain & expFile)413 void CegoAdmNet::exportTableSet(const Chain& tableSet, const Chain& expMode, const Chain& expFile)
414 {
415     CegoAdminHandler::ResultType res;
416     bool isStructure=false;
417     res = _pAH->reqExportTableSet(tableSet, isStructure, expFile, expMode);
418     handleMedResult(res);
419 }
420 
addDataFile(const Chain & tableSet,const Chain & fileType,const Chain & dataFile,int numPages)421 void CegoAdmNet::addDataFile(const Chain& tableSet, const Chain& fileType, const Chain& dataFile, int numPages)
422 {
423     CegoAdminHandler::ResultType res;
424     res = _pAH->medAddDataFile(tableSet, fileType, dataFile, numPages);
425     handleMedResult(res);
426 }
427 
defineTableSet(const Chain & tableSet,const Chain & tsRoot,const Chain & primary,const Chain & secondary,int sysSize,int tmpSize,int appSize,int logSize,int logNum,unsigned long long orderSize)428 void CegoAdmNet::defineTableSet(const Chain& tableSet,
429 				const Chain& tsRoot,
430 				const Chain& primary,
431 				const Chain& secondary,
432 				int sysSize,
433 				int tmpSize,
434 				int appSize,
435 				int logSize,
436 				int logNum,
437 				unsigned long long orderSize)
438 {
439 
440     CegoAdminHandler::ResultType res;
441     res = _pAH->medDefineTableSet(tableSet,
442 				  tsRoot,
443 				  primary,
444 				  secondary,
445 				  sysSize,
446 				  tmpSize,
447 				  appSize,
448 				  logSize,
449 				  logNum,
450 				  orderSize);
451     handleMedResult(res);
452 }
453 
createTableSet(const Chain & tableSet)454 void CegoAdmNet::createTableSet(const Chain& tableSet)
455 {
456     CegoAdminHandler::ResultType res;
457     res = _pAH->medCreateTableSet(tableSet);
458     handleMedResult(res);
459 }
460 
dropTableSet(const Chain & tableSet)461 void CegoAdmNet::dropTableSet(const Chain& tableSet)
462 {
463     CegoAdminHandler::ResultType res;
464     res = _pAH->medDropTableSet(tableSet);
465     handleMedResult(res);
466 }
467 
switchSecondary(const Chain & tableSet)468 void CegoAdmNet::switchSecondary(const Chain& tableSet)
469 {
470     CegoAdminHandler::ResultType res;
471     res = _pAH->medSecSwitch(tableSet);
472     handleMedResult(res);
473 }
474 
switchMediatorAction(const Chain & tableSet)475 void CegoAdmNet::switchMediatorAction(const Chain& tableSet)
476 {
477     CegoAdminHandler::ResultType res;
478     res = _pAH->secMedSwitch(tableSet);
479     handleMedResult(res);
480 }
481 
relocateSecondary(const Chain & tableSet,const Chain & secondary)482 void CegoAdmNet::relocateSecondary(const Chain& tableSet, const Chain& secondary)
483 {
484     CegoAdminHandler::ResultType res;
485     res = _pAH->medSecRelocate(tableSet, secondary);
486     handleMedResult(res);
487 }
488 
relocateMediator(const Chain & tableSet,const Chain & mediator)489 void CegoAdmNet::relocateMediator(const Chain& tableSet, const Chain& mediator)
490 {
491     CegoAdminHandler::ResultType res;
492     res = _pAH->secMedRelocate(tableSet, mediator);
493     handleMedResult(res);
494 }
495 
recoverTableSet(const Chain & tableSet,int pit)496 void CegoAdmNet::recoverTableSet(const Chain& tableSet, int pit)
497 {
498     CegoAdminHandler::ResultType res;
499     res = _pAH->medRecover(tableSet, pit);
500     handleMedResult(res);
501 }
502 
handleMedResult(CegoAdminHandler::ResultType res)503 void CegoAdmNet::handleMedResult(CegoAdminHandler::ResultType res)
504 {
505     Chain msg;
506     _pAH->getMsg(msg);
507 
508     bool doQuiet=true;
509 
510     if ( res == CegoAdminHandler::ADM_ERROR )
511     {
512 	throw Exception(EXLOC, msg);
513     }
514 
515     while ( res == CegoAdminHandler::ADM_INFO )
516     {
517 
518 	if ( doQuiet == false )
519 	{
520 	    Chain hostRole;
521 	    Chain hostName;
522 	    Chain msg;
523 
524 	    _pAH->getHostRole(hostRole);
525 	    _pAH->getHostName(hostName);
526 	    _pAH->getMsg(msg);
527 
528 	    ListT<CegoFieldValue> fvl;
529 	    fvl.Insert(CegoFieldValue(VARCHAR_TYPE, hostRole));
530 	    fvl.Insert(CegoFieldValue(VARCHAR_TYPE, hostName));
531 	    fvl.Insert(CegoFieldValue(VARCHAR_TYPE, msg));
532 
533 	}
534 
535 	res = _pAH->nextInfo();
536 
537     }
538 
539     _pAH->getMsg(msg);
540 
541     if ( res == CegoAdminHandler::ADM_OK )
542     {
543 	// ok
544     }
545     else if ( res == CegoAdminHandler::ADM_ERROR )
546     {
547 	throw Exception(EXLOC, msg);
548     }
549 }
550 
disconnect()551 void CegoAdmNet::disconnect()
552 {
553     _pAH->closeSession();
554 }
555