1 mike 1.1.2.1 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 mike 1.1.2.1 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include <Pegasus/Common/Config.h>
35 #include <cctype>
36 #include <cstdio>
37 #include <fstream>
38 #include <Pegasus/Common/Pair.h>
39 #include <Pegasus/Common/FileSystem.h>
40 #include <Pegasus/Common/InternalException.h>
41 #include <Pegasus/Common/DeclContext.h>
42 #include <Pegasus/Common/Resolver.h>
43 mike 1.1.2.1 #include <Pegasus/Common/System.h>
44 #include <Pegasus/Common/Tracer.h>
45 #include <Pegasus/Common/PegasusVersion.h>
46 #include <Pegasus/Common/MessageLoader.h>
47 #include <Pegasus/Common/CommonUTF.h>
48 #include <Pegasus/Common/ReadWriteSem.h>
49 #include <Pegasus/Common/Dir.h>
50 #include <Pegasus/Common/XmlStreamer.h>
51 #include <Pegasus/Common/BinaryStreamer.h>
52 #include <Pegasus/Common/AutoStreamer.h>
53 #include "DefaultRepository.h"
54 #include "RepositoryDeclContext.h"
55 #include "InstanceIndexFile.h"
56 #include "InstanceDataFile.h"
57 #include "AssocInstTable.h"
58 #include "AssocClassTable.h"
59 #include "ObjectCache.h"
60 #include "Filtering.h"
61
62 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
63 // #define win32
64 mike 1.1.2.1 # include <zlib.h>
65 # include <sstream>
66 #endif
67
68 #if 0
69 #undef PEG_METHOD_ENTER
70 #undef PEG_METHOD_EXIT
71 #define PEG_METHOD_ENTER(x,y) cout<<"--- Enter: "<<y<<endl;
72 #define PEG_METHOD_EXIT()
73 #endif
74
75 PEGASUS_USING_STD;
76
77 PEGASUS_NAMESPACE_BEGIN
78
79 static const Uint32 _MAX_FREE_COUNT = 16;
80
81 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
82 static int compressMode = 0; // PEP214
83 #endif
84
85 mike 1.1.2.1 // #define TEST_OUTPUT
86
87 //==============================================================================
88 //
89 // This is the class cache, which caches up PEGASUS_CLASS_CACHE_SIZE classes
90 // into memory. To override the default, define PEGASUS_CLASS_CACHE_SIZE in
91 // your environment. To supress the cache (and not compile it in at all)
92 // define PEGASUS_CLASS_CACHE_SIZE to 0.
93 //
94 //==============================================================================
95
96 #define PEGASUS_QUALIFIER_CACHE_SIZE 80
97
98 #if !defined(PEGASUS_CLASS_CACHE_SIZE)
99 # define PEGASUS_CLASS_CACHE_SIZE 8
100 #endif
101
102 #if (PEGASUS_CLASS_CACHE_SIZE != 0)
103 # define PEGASUS_USE_CLASS_CACHE
104 #endif
105
106 mike 1.1.2.1 #ifdef PEGASUS_USE_CLASS_CACHE
107 static ObjectCache<CIMClass> _classCache(PEGASUS_CLASS_CACHE_SIZE);
108 #endif /* PEGASUS_USE_CLASS_CACHE */
109
110 static ObjectCache<CIMQualifierDecl>
111 _qualifierCache(PEGASUS_QUALIFIER_CACHE_SIZE);
112
113 ////////////////////////////////////////////////////////////////////////////////
114 //
115 // _LoadFileToMemory() PEP214
116 //
117 // The gzxxxx functions read both compresed and non-compresed files.
118 //
119 // There is no conditional flag on reading of files since gzread()
120 // (from zlib) is capable of reading compressed and non-compressed
121 // files (so it contains the logic that examines the header
122 // and magic number). Everything will work properly if the repository
123 // has some compressed and some non-compressed files.
124 //
125 //
126 ////////////////////////////////////////////////////////////////////////////////
127 mike 1.1.2.1
128 void _LoadFileToMemory(Buffer& data, const String& path)
129 {
130
131 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
132
133 Uint32 fileSize;
134
135 if (!FileSystem::getFileSize(path, fileSize))
136 throw CannotOpenFile(path);
137
138 gzFile fp = gzopen(path.getCString(), "rb");
139
140 if (fp == NULL)
141 throw CannotOpenFile(path);
142
143 data.reserveCapacity(fileSize);
144 char buffer[4096];
145 int n;
146
147 while ((n = gzread(fp, buffer, sizeof(buffer))) > 0)
148 mike 1.1.2.1 data.append(buffer, n);
149
150 gzclose(fp);
151
152 #else
153
154 FileSystem::loadFileToMemory(data, path);
155
156 #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
157 }
158
159 ////////////////////////////////////////////////////////////////////////////////
160 //
161 // _LoadObject()
162 //
163 // Loads objects (classes and qualifiers) from disk to
164 // memory objects.
165 //
166 ////////////////////////////////////////////////////////////////////////////////
167
168 template<class Object>
169 mike 1.1.2.1 void _LoadObject(
170 const String& path,
171 Object& object,
172 ObjectStreamer* streamer)
173 {
174 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::_LoadObject");
175
176 // Get the real path of the file:
177
178 String realPath;
179
180 if (!FileSystem::existsNoCase(path, realPath))
181 {
182 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
183 path + " does not exist.");
184 PEG_METHOD_EXIT();
185 throw CannotOpenFile(path);
186 }
187
188 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "realpath = " + realPath);
189
190 mike 1.1.2.1 // Load file into memory:
191
192 Buffer data;
193 _LoadFileToMemory(data, realPath);
194 streamer->decode(data, 0, object);
195
196 PEG_METHOD_EXIT();
197 }
198
199 ////////////////////////////////////////////////////////////////////////////////
200 //
201 // _SaveObject()
202 //
203 // Saves objects (classes and qualifiers) from memory to
204 // disk files.
205 //
206 ////////////////////////////////////////////////////////////////////////////////
207
208 void _SaveObject(
209 const String& path,
210 Buffer& objectXml,
211 mike 1.1.2.1 ObjectStreamer* streamer)
212 {
213 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::_SaveObject");
214
215 // cout << "SAVE[" << path << "]" << endl;
216
217 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY
218 if (compressMode) // PEP214
219 {
220 PEGASUS_STD(ostringstream) os;
221 streamer->write(os, objectXml);
222 string str = os.str();
223
224 gzFile fp = gzopen(path.getCString(), "wb");
225
226 if (fp == NULL)
227 throw CannotOpenFile(path);
228
229 const char* ptr = str.data();
230 size_t rem = str.size();
231 int n;
232 mike 1.1.2.1
233 while (rem > 0 && (n = gzwrite(fp, (char*)ptr, rem)) > 0)
234 {
235 ptr += n;
236 rem -= n;
237 }
238
239 gzclose(fp);
240 }
241 else
242 #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
243 {
244 PEGASUS_STD(ofstream) os(path.getCString() PEGASUS_IOS_BINARY);
245
246 if (!os)
247 {
248 PEG_METHOD_EXIT();
249 throw CannotOpenFile(path);
250 }
251
252 streamer->write(os, objectXml);
253 mike 1.1.2.1 }
254 PEG_METHOD_EXIT();
255 }
256
257 ////////////////////////////////////////////////////////////////////////////////
258 //
259 // _beginInstanceTransaction()
260 //
261 // Creates rollback files to allow an incomplete transaction to be voided.
262 //
263 ////////////////////////////////////////////////////////////////////////////////
264
265 void _beginInstanceTransaction(
266 const String& indexFilePath,
267 const String& dataFilePath)
268 {
269 PEG_METHOD_ENTER(TRC_REPOSITORY, "_beginInstanceTransaction");
270
271 //
272 // Begin the transaction (an incomplete transaction will cause
273 // a rollback the next time an instance-oriented routine is invoked).
274 mike 1.1.2.1 //
275
276 if (!InstanceIndexFile::beginTransaction(indexFilePath))
277 {
278 PEG_METHOD_EXIT();
279 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
280 mike 1.1.2.2 MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
|
281 mike 1.1.2.1 "begin failed"));
282 }
283
284 if (!InstanceDataFile::beginTransaction(dataFilePath))
285 {
286 PEG_METHOD_EXIT();
287 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
288 mike 1.1.2.2 MessageLoaderParms("Repository.CIMRepository.BEGIN_FAILED",
|
289 mike 1.1.2.1 "begin failed"));
290 }
291
292 PEG_METHOD_EXIT();
293 }
294
295 ////////////////////////////////////////////////////////////////////////////////
296 //
297 // _commitInstanceTransaction()
298 //
299 // Removes the rollback files to complete the transaction.
300 //
301 ////////////////////////////////////////////////////////////////////////////////
302
303 void _commitInstanceTransaction(
304 const String& indexFilePath,
305 const String& dataFilePath)
306 {
307 PEG_METHOD_ENTER(TRC_REPOSITORY, "_commitInstanceTransaction");
308
309 //
310 mike 1.1.2.1 // Commit the transaction by removing the rollback files.
311 //
312
313 if (!InstanceIndexFile::commitTransaction(indexFilePath))
314 {
315 PEG_METHOD_EXIT();
316 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
317 mike 1.1.2.2 MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
|
318 mike 1.1.2.1 "commit failed"));
319 }
320
321 if (!InstanceDataFile::commitTransaction(dataFilePath))
322 {
323 PEG_METHOD_EXIT();
324 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
325 mike 1.1.2.2 MessageLoaderParms("Repository.CIMRepository.COMMIT_FAILED",
|
326 mike 1.1.2.1 "commit failed"));
327 }
328
329 PEG_METHOD_EXIT();
330 }
331
332 ////////////////////////////////////////////////////////////////////////////////
333 //
334 // _rollbackInstanceTransaction()
335 //
336 // Restores instance index and data files to void an incomplete operation.
337 // If there are no rollback files, this method has no effect.
338 //
339 ////////////////////////////////////////////////////////////////////////////////
340
341 static String _dirName(const String& path)
342 {
343 Uint32 n = path.size();
344
345 for (Uint32 i = n; i != 0; )
346 {
347 mike 1.1.2.1 if (path[--i] == '/')
348 return path.subString(0, i);
349 }
350
351 return String(".");
352 }
353
354 void _rollbackInstanceTransaction(
355 const String& indexFilePath,
356 const String& dataFilePath)
357 {
358 PEG_METHOD_ENTER(TRC_REPOSITORY, "_rollbackInstanceTransaction");
359
360 // Avoid rollback logic if directory has no .rollback files.
361
362 String path = _dirName(indexFilePath);
363 Array<String> rollbackFiles;
364
365 if (FileSystem::glob(path, "*.rollback", rollbackFiles))
366 {
367 if (rollbackFiles.size() == 0)
368 mike 1.1.2.1 return;
369 }
370
371 // Proceed to rollback logic.
372
373 if (!InstanceIndexFile::rollbackTransaction(indexFilePath))
374 {
375 PEG_METHOD_EXIT();
376 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
377 mike 1.1.2.2 MessageLoaderParms("Repository.CIMRepository.ROLLBACK_FAILED",
|
378 mike 1.1.2.1 "rollback failed"));
379 }
380
381 if (!InstanceDataFile::rollbackTransaction(dataFilePath))
382 {
383 PEG_METHOD_EXIT();
384 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
385 MessageLoaderParms(
|
386 mike 1.1.2.2 "Repository.CIMRepository.ROLLBACK_FAILED",
|
387 mike 1.1.2.1 "rollback failed"));
388 }
389
390 PEG_METHOD_EXIT();
391 }
392
393 ////////////////////////////////////////////////////////////////////////////////
394 //
395 // InstanceTransactionHandler
396 //
397 // This class is used to manage a repository instance transaction. The
398 // transaction is started when the class is instantiated, committed when
399 // the complete() method is called, and rolled back if the destructor is
400 // called without a prior call to complete().
401 //
402 // The appropriate repository write locks must be owned while an
403 // InstanceTransactionHandler instance exists.
404 //
405 ////////////////////////////////////////////////////////////////////////////////
406
407 class InstanceTransactionHandler
408 mike 1.1.2.1 {
409 public:
410 InstanceTransactionHandler(
411 const String& indexFilePath,
412 const String& dataFilePath)
413 : _indexFilePath(indexFilePath),
414 _dataFilePath(dataFilePath),
415 _isComplete(false)
416 {
417 _rollbackInstanceTransaction(_indexFilePath, _dataFilePath);
418 _beginInstanceTransaction(_indexFilePath, _dataFilePath);
419 }
420
421 ~InstanceTransactionHandler()
422 {
423 if (!_isComplete)
424 {
425 _rollbackInstanceTransaction(_indexFilePath, _dataFilePath);
426 }
427 }
428
429 mike 1.1.2.1 void complete()
430 {
431 _commitInstanceTransaction(_indexFilePath, _dataFilePath);
432 _isComplete = true;
433 }
434
435 private:
436 String _indexFilePath;
437 String _dataFilePath;
438 Boolean _isComplete;
439 };
440
441 ////////////////////////////////////////////////////////////////////////////////
442 //
443 // DefaultRepository::_rollbackIncompleteTransactions()
444 //
445 // Searches for incomplete instance transactions for all classes in all
446 // namespaces. Restores instance index and data files to void an
447 // incomplete operation. If no incomplete instance transactions are
448 // outstanding, this method has no effect.
449 //
450 mike 1.1.2.1 ////////////////////////////////////////////////////////////////////////////////
451
452 static Boolean _containsNoCase(const Array<String>& array, const String& str)
453 {
454 for (Uint32 i = 0; i < array.size(); i++)
455 {
456 if (String::equalNoCase(array[i], str))
457 return true;
458 }
459
460 return false;
461 }
462
463 void DefaultRepository::_rollbackIncompleteTransactions()
464 {
465 PEG_METHOD_ENTER(TRC_REPOSITORY,
466 "DefaultRepository::_rollbackIncompleteTransactions");
467
468 WriteLock wlock(_lock);
469 AutoFileLock fileLock(_lockFile);
470
471 mike 1.1.2.1 Array<CIMNamespaceName> namespaceNames;
472 _nameSpaceManager.getNameSpaceNames(namespaceNames);
473
474 for (Uint32 i = 0; i < namespaceNames.size(); i++)
475 {
476 // Form a list of .rollback files.
477
478 Array<String> rollbackFiles;
479 FileSystem::glob(
480 _nameSpaceManager.getInstanceDirRoot(namespaceNames[i]),
481 "*.rollback", rollbackFiles);
482
483 // Don't bother doing rollback if there are no rollback files.
484 // The algorithm below is expensive.
485
486 if (rollbackFiles.size() == 0)
487 continue;
488
489 Array<CIMName> classNames;
490 _nameSpaceManager.getSubClassNames(
491 namespaceNames[i], CIMName(), true, classNames);
492 mike 1.1.2.1
493 for (Uint32 j = 0; j < classNames.size(); j++)
494 {
495 //
496 // Get paths of index and data files:
497 //
498
499 String indexFilePath = _getInstanceIndexFilePath(
500 namespaceNames[i], classNames[j]);
501
502 String dataFilePath = _getInstanceDataFilePath(
503 namespaceNames[i], classNames[j]);
504
505 // Only perform rollback processing if there is a rollback file
506 // for either the data or index file.
507
508 if (_containsNoCase(rollbackFiles, dataFilePath + ".rollback") ||
509 _containsNoCase(rollbackFiles, indexFilePath + ".rollback"))
510 {
511 //
512 // Attempt rollback (if there are no rollback files, this will
513 mike 1.1.2.1 // have no effect). This code is here to rollback uncommitted
514 // changes left over from last time an instance-oriented
515 // function
516 // was called.
517 //
518
519 _rollbackInstanceTransaction(indexFilePath, dataFilePath);
520 }
521 }
522 }
523
524 PEG_METHOD_EXIT();
525 }
526
527 ////////////////////////////////////////////////////////////////////////////////
528 //
529 // DefaultRepository
530 //
531 // The following are not implemented:
532 //
533 // DefaultRepository::execQuery()
534 mike 1.1.2.1 // DefaultRepository::invokeMethod()
535 //
536 // Note that invokeMethod() will not never implemented since it is not
537 // meaningful for a repository.
538 //
539 ////////////////////////////////////////////////////////////////////////////////
540
541 DefaultRepository::DefaultRepository(
542 const String& repositoryRoot,
|
543 mike 1.1.2.2 Uint32 repositoryMode)
|
544 mike 1.1.2.1 :
|
545 mike 1.1.2.2 _repositoryRoot(repositoryRoot),
546 _repositoryMode(repositoryMode),
|
547 mike 1.1.2.1 _nameSpaceManager(repositoryRoot),
548 _lock(),
549 _resolveInstance(true)
550 {
551 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::DefaultRepository");
552
|
553 mike 1.1.2.2 Boolean binaryMode = repositoryMode & DefaultRepository::MODE_BIN;
|
554 mike 1.1.2.1
|
555 mike 1.1.2.2 if (repositoryMode == DefaultRepository::MODE_DEFAULT)
|
556 mike 1.1.2.1 {
557 binaryMode = ConfigManager::parseBooleanValue(
558 ConfigManager::getInstance()->getCurrentValue(
559 "enableBinaryRepository"));
560 }
561
562 #ifdef PEGASUS_ENABLE_COMPRESSED_REPOSITORY // PEP214
563 // FUTURE?? - compressMode = mode & DefaultRepository::MODE_COMPRESSED;
564 compressMode=1;
565
566 char* s = getenv("PEGASUS_ENABLE_COMPRESSED_REPOSITORY");
567 if (s && (strcmp(s, "build_non_compressed") == 0))
568 {
569 compressMode =0;
570 #ifdef TEST_OUTPUT
571 cout << "In Compress mode: build_non_compresed found" << endl;
572 #endif /* TEST_OUTPUT */
573 }
574 #endif /* PEGASUS_ENABLE_COMPRESSED_REPOSITORY */
575
576 #ifdef TEST_OUTPUT
577 mike 1.1.2.1 cout << "repositoryRoot = " << repositoryRoot << endl;
578 cout << "DefaultRepository: binaryMode=" << binaryMode <<
579 ", mode=" << mode << endl;
580 cout << "DefaultRepository: compressMode= " << compressMode << endl;
581 #endif /* TEST_OUTPUT */
582
583 if (binaryMode>0)
584 {
585 // BUILD BINARY
586 streamer = new AutoStreamer(new BinaryStreamer(), BINREP_MARKER);
587 ((AutoStreamer*)streamer)->addReader(new XmlStreamer(), 0);
588 }
589 else
590 {
591 // BUILD XML
592 streamer = new AutoStreamer(new XmlStreamer(),0xff);
593 ((AutoStreamer*)streamer)->addReader(
594 new BinaryStreamer(), BINREP_MARKER);
595 ((AutoStreamer*)streamer)->addReader(new XmlStreamer(), 0);
596 }
597
598 mike 1.1.2.1 _context = new RepositoryDeclContext(this);
599
600 _isDefaultInstanceProvider = ConfigManager::parseBooleanValue(
601 ConfigManager::getInstance()->getCurrentValue(
602 "repositoryIsDefaultInstanceProvider"));
603
604 _lockFile = ConfigManager::getInstance()->getHomedPath(
605 PEGASUS_REPOSITORY_LOCK_FILE).getCString();
606
607 _rollbackIncompleteTransactions();
608
609 PEG_METHOD_EXIT();
610 }
611
612 DefaultRepository::~DefaultRepository()
613 {
614 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::~DefaultRepository");
615
616 delete streamer;
617 delete _context;
618
619 mike 1.1.2.1 AssocClassTable::removeCaches();
620
621 PEG_METHOD_EXIT();
622 }
623
624 String _toString(Boolean x)
625 {
626 return(x ? "true" : "false");
627 }
628
629 CIMClass DefaultRepository::getClass(
630 bool lock,
631 const CIMNamespaceName& nameSpace,
632 const CIMName& className,
633 Boolean localOnly,
634 Boolean includeQualifiers,
635 Boolean includeClassOrigin,
636 const CIMPropertyList& propertyList)
637 {
638 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::getClass");
639
|
640 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
641 mike 1.1.2.1
642 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "nameSpace= " +
643 nameSpace.getString() + ", className= " +
644 className.getString() +
645 ", localOnly= " + _toString(localOnly) +
646 ", includeQualifiers= " + _toString(includeQualifiers) +
647 ", includeClassOrigin= " + _toString(includeClassOrigin));
648 String classFilePath;
649 classFilePath = _nameSpaceManager.getClassFilePath(
650 nameSpace, className, NameSpaceRead);
651
652 CIMClass cimClass;
653
654 try
655 {
656 #ifdef PEGASUS_USE_CLASS_CACHE
657
658 // Check the cache first:
659
660 if (!_classCache.get(classFilePath, cimClass))
661 {
662 mike 1.1.2.1 // Not in cache so load from disk:
663
664 _LoadObject(classFilePath, cimClass, streamer);
665
666 // Put in cache:
667
668 _classCache.put(classFilePath, cimClass);
669 }
670
671 #else /* PEGASUS_USE_CLASS_CACHE */
672
673 _LoadObject(classFilePath, cimClass, streamer);
674
675 #endif /* PEGASUS_USE_CLASS_CACHE */
676 }
677 catch (Exception&)
678 {
679 PEG_METHOD_EXIT();
680 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, className.getString());
681 }
682
683 mike 1.1.2.1 // Remove properties based on propertylist and localOnly flag (Bug 565)
684 Boolean propertyListNull = propertyList.isNull();
685
686 Filtering::filterClass(
687 cimClass,
688 localOnly,
689 includeQualifiers,
690 includeClassOrigin,
691 propertyList);
692
693 PEG_METHOD_EXIT();
694 return cimClass;
695 }
696
697 Boolean DefaultRepository::_checkInstanceAlreadyExists(
698 const CIMNamespaceName& nameSpace,
699 const CIMObjectPath& instanceName) const
700 {
701 PEG_METHOD_ENTER(TRC_REPOSITORY,
702 "DefaultRepository::_checkInstanceAlreadyExists");
703
704 mike 1.1.2.1 //
705 // Get the names of all superclasses and subclasses of this class
706 //
707
708 Array<CIMName> classNames;
709 CIMName className = instanceName.getClassName();
710 classNames.append(className);
711 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
712 _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);
713
714 //
715 // Search for an instance with the specified key values
716 //
717
718 for (Uint32 i = 0; i < classNames.size(); i++)
719 {
720 CIMObjectPath tmpInstanceName = instanceName;
721 tmpInstanceName.setClassName(classNames[i]);
722
723 String path = _getInstanceIndexFilePath(nameSpace, classNames[i]);
724
725 mike 1.1.2.1 Uint32 index;
726 Uint32 size;
727 if (InstanceIndexFile::lookupEntry(path, tmpInstanceName, index, size))
728 {
729 PEG_METHOD_EXIT();
730 return true;
731 }
732 }
733
734 PEG_METHOD_EXIT();
735 return false;
736 }
737
738 CIMInstance DefaultRepository::getInstance(
739 bool lock,
740 const CIMNamespaceName& nameSpace,
741 const CIMObjectPath& instanceName,
742 Boolean localOnly,
743 Boolean includeQualifiers,
744 Boolean includeClassOrigin,
745 const CIMPropertyList& propertyList)
746 mike 1.1.2.1 {
747 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::getInstance");
748
|
749 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
750 mike 1.1.2.1
751 //
752 // Validate namespace
753 //
754 if ((!instanceName.getNameSpace().isNull()) &&
755 (!instanceName.getNameSpace().equal(nameSpace)))
756 {
757 PEG_METHOD_EXIT();
758 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND,
759 instanceName.toString());
760 }
761
762 if (!_nameSpaceManager.classExists(nameSpace, instanceName.getClassName()))
763 {
764 throw PEGASUS_CIM_EXCEPTION(
765 CIM_ERR_INVALID_CLASS, instanceName.getClassName().getString());
766 }
767
768 //
769 // Get paths of index and data files:
770 //
771 mike 1.1.2.1
772 String indexFilePath = _getInstanceIndexFilePath(
773 nameSpace, instanceName.getClassName());
774
775 String dataFilePath = _getInstanceDataFilePath(
776 nameSpace, instanceName.getClassName());
777
778 //
779 // Get the index for this instance:
780 //
781
782 Uint32 index;
783 Uint32 size;
784
785 if (!InstanceIndexFile::lookupEntry(
786 indexFilePath, instanceName, index, size))
787 {
788 PEG_METHOD_EXIT();
789 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
790 }
791
792 mike 1.1.2.1 //
793 // Load the instance from file:
794 //
795
796 CIMInstance cimInstance;
797
798 if (!_loadInstance(dataFilePath, cimInstance, index, size))
799 {
800 PEG_METHOD_EXIT();
801 throw CannotOpenFile(dataFilePath);
802 }
803
804 //
805 // Resolve the instance (if requested):
806 //
807
808 if (_resolveInstance)
809 {
810 CIMConstClass cimClass;
811 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
812 true);
813 mike 1.1.2.1 }
814
815 Filtering::filterInstance(
816 cimInstance,
817 localOnly,
818 includeQualifiers,
819 includeClassOrigin,
820 propertyList);
821
822
823 PEG_METHOD_EXIT();
824 return cimInstance;
825 }
826
827 void DefaultRepository::deleteClass(
828 bool lock,
829 const CIMNamespaceName& nameSpace,
830 const CIMName& className)
831 {
832 PEG_METHOD_ENTER(TRC_REPOSITORY,"DefaultRepository::deleteClass");
833
|
834 mike 1.1.2.2 WriteLock wlock(_lock, lock);
835 AutoFileLock fileLock(_lockFile, lock);
|
836 mike 1.1.2.1
837 //
838 // Get the class and check to see if it is an association class:
839 //
840
841 CIMClass cimClass = getClass(
842 false, nameSpace, className, false, true, false, CIMPropertyList());
843 Boolean isAssociation = cimClass.isAssociation();
844
845 //
846 // Delete the class. The NameSpaceManager::deleteClass() method throws
847 // an exception if the class has subclasses.
848 //
849 #ifdef PEGASUS_USE_CLASS_CACHE
850
851 _classCache.evict(_nameSpaceManager.getClassFilePath(
852 nameSpace, className, NameSpaceRead));
853
854 #endif /* PEGASUS_USE_CLASS_CACHE */
855
856 _nameSpaceManager.deleteClass(nameSpace, className);
857 mike 1.1.2.1
858 //
859 // Remove associations:
860 //
861
862 if (isAssociation)
863 {
864 Array<String> assocFileName =
865 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceDelete);
866
867 if (FileSystem::exists(assocFileName[0]))
868 AssocClassTable::deleteAssociation(assocFileName[0], className);
869 }
870
871 PEG_METHOD_EXIT();
872 }
873
874 void _CompactInstanceRepository(
875 const String& indexFilePath,
876 const String& dataFilePath)
877 {
878 mike 1.1.2.1 PEG_METHOD_ENTER(TRC_REPOSITORY,
879 "DefaultRepository::_CompactInstanceRepository");
880
881 //
882 // Compact the data file first:
883 //
884
885 Array<Uint32> freeFlags;
886 Array<Uint32> indices;
887 Array<Uint32> sizes;
888 Array<CIMObjectPath> instanceNames;
889
890 if (!InstanceIndexFile::enumerateEntries(
891 indexFilePath, freeFlags, indices, sizes, instanceNames, true))
892 {
893 PEG_METHOD_EXIT();
894 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
895 MessageLoaderParms(
|
896 mike 1.1.2.2 "Repository.CIMRepository.INDEX_ENUM_ENTRIES_FAILED",
|
897 mike 1.1.2.1 "Failed to obtain the entries from the Repository Instance"
898 " Index file."));
899 }
900
901 if (!InstanceDataFile::compact(dataFilePath, freeFlags, indices, sizes))
902 {
903 PEG_METHOD_EXIT();
904 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
905 MessageLoaderParms(
|
906 mike 1.1.2.2 "Repository.CIMRepository.COMPACT_FAILED",
|
907 mike 1.1.2.1 "Failed to compact the Repository Instance Data file."));
908 }
909
910 //
911 // Now compact the index file:
912 //
913
914 if (!InstanceIndexFile::compact(indexFilePath))
915 {
916 PEG_METHOD_EXIT();
917 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
918 MessageLoaderParms(
|
919 mike 1.1.2.2 "Repository.CIMRepository.INDEX_COMPACT_FAILED",
|
920 mike 1.1.2.1 "Failed to compact the Repository Instance Index file."));
921 }
922
923 PEG_METHOD_EXIT();
924 }
925
926 void DefaultRepository::deleteInstance(
927 bool lock,
928 const CIMNamespaceName& nameSpace,
929 const CIMObjectPath& instanceName)
930 {
931 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::deleteInstance");
932
933 //
934 // Validate namespace
935 //
936 if ((!instanceName.getNameSpace().isNull()) &&
937 (!instanceName.getNameSpace().equal(nameSpace)))
938 {
939 PEG_METHOD_EXIT();
940 throw PEGASUS_CIM_EXCEPTION(
941 mike 1.1.2.1 CIM_ERR_NOT_FOUND, instanceName.toString());
942 }
943
|
944 mike 1.1.2.2 WriteLock wlock(_lock, lock);
945 AutoFileLock fileLock(_lockFile, lock);
|
946 mike 1.1.2.1
947 String errMessage;
948
949 //
950 // Get paths of index and data files:
951 //
952
953 String indexFilePath = _getInstanceIndexFilePath(
954 nameSpace, instanceName.getClassName());
955
956 String dataFilePath = _getInstanceDataFilePath(
957 nameSpace, instanceName.getClassName());
958
959 //
960 // Perform the operation in a transaction scope to enable rollback on
961 // failure.
962 //
963
964 InstanceTransactionHandler transaction(indexFilePath, dataFilePath);
965
966 //
967 mike 1.1.2.1 // Lookup instance from the index file (raise error if not found).
968 //
969
970 Uint32 index;
971 Uint32 size;
972
973 if (!InstanceIndexFile::lookupEntry(
974 indexFilePath, instanceName, index, size))
975 {
976 PEG_METHOD_EXIT();
977 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
978 }
979
980 //
981 // Remove entry from index file.
982 //
983
984 Uint32 freeCount;
985
986 if (!InstanceIndexFile::deleteEntry(indexFilePath, instanceName, freeCount))
987 {
988 mike 1.1.2.1 PEG_METHOD_EXIT();
989 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
990 MessageLoaderParms(
|
991 mike 1.1.2.2 "Repository.CIMRepository.FAILED_TO_DELETE_INSTANCE",
|
992 mike 1.1.2.1 "Failed to delete instance: $0",
993 instanceName.toString()));
994 }
995
996 transaction.complete();
997
998 //
999 // Compact the index and data files if the free count max was
1000 // reached.
1001 //
1002
1003 if (freeCount == _MAX_FREE_COUNT)
1004 _CompactInstanceRepository(indexFilePath, dataFilePath);
1005
1006 //
1007 // Delete from assocation table (if an assocation).
1008 //
1009
1010 String assocFileName = _nameSpaceManager.getAssocInstPath(nameSpace);
1011
1012 if (FileSystem::exists(assocFileName))
1013 mike 1.1.2.1 AssocInstTable::deleteAssociation(assocFileName, instanceName);
1014
1015 PEG_METHOD_EXIT();
1016 }
1017
1018 void DefaultRepository::_createAssocClassEntries(
1019 const CIMNamespaceName& nameSpace,
1020 const CIMConstClass& assocClass)
1021 {
1022 PEG_METHOD_ENTER(
1023 TRC_REPOSITORY, "DefaultRepository::_createAssocClassEntries");
1024
1025 // Open input file:
1026
1027
1028 Array<String> assocFileName =
1029 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceWrite);
1030 ofstream os;
1031
1032 if (!OpenAppend(os, assocFileName[0]))
1033 {
1034 mike 1.1.2.1 PEG_METHOD_EXIT();
1035 throw CannotOpenFile(assocFileName[0]);
1036 }
1037
1038 // Get the association's class name:
1039
1040 CIMName assocClassName = assocClass.getClassName();
1041
1042 // For each property:
1043
1044 Uint32 n = assocClass.getPropertyCount();
1045
1046 for (Uint32 i = 0; i < n; i++)
1047 {
1048 CIMConstProperty fromProp = assocClass.getProperty(i);
1049
1050 if (fromProp.getType() == CIMTYPE_REFERENCE)
1051 {
1052 for (Uint32 j = 0; j < n; j++)
1053 {
1054 CIMConstProperty toProp = assocClass.getProperty(j);
1055 mike 1.1.2.1
1056 if (toProp.getType() == CIMTYPE_REFERENCE &&
1057 (!fromProp.getName().equal (toProp.getName())))
1058 {
1059 CIMName fromClassName = fromProp.getReferenceClassName();
1060 CIMName fromPropertyName = fromProp.getName();
1061 CIMName toClassName = toProp.getReferenceClassName();
1062 CIMName toPropertyName = toProp.getName();
1063
1064 AssocClassTable::append(
1065 os,
1066 assocFileName[0],
1067 assocClassName,
1068 fromClassName,
1069 fromPropertyName,
1070 toClassName,
1071 toPropertyName);
1072 }
1073 }
1074 }
1075 }
1076 mike 1.1.2.1
1077 PEG_METHOD_EXIT();
1078 }
1079
1080 void DefaultRepository::createClass(
1081 bool lock,
1082 const CIMNamespaceName& nameSpace,
1083 const CIMClass& newClass,
1084 const ContentLanguageList& contentLangs)
1085 {
1086 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::createClass");
1087
|
1088 mike 1.1.2.2 WriteLock wlock(_lock, lock);
1089 AutoFileLock fileLock(_lockFile, lock);
|
1090 mike 1.1.2.1
1091 // -- Resolve the class:
1092 CIMClass cimClass(newClass);
1093
1094 Resolver::resolveClass (cimClass, _context, nameSpace);
1095
1096 // -- If an association, populate associations file:
1097
1098 if (cimClass.isAssociation())
1099 _createAssocClassEntries(nameSpace, cimClass);
1100
1101 // -- Create namespace manager entry:
1102
1103 String classFilePath;
1104
1105 _nameSpaceManager.createClass(nameSpace, cimClass.getClassName(),
1106 cimClass.getSuperClassName(), classFilePath);
1107
1108 // -- Create the class file:
1109
1110 Buffer classXml;
1111 mike 1.1.2.1 streamer->encode(classXml, cimClass);
1112 //XmlWriter::appendClassElement(classXml, cimClass);
1113 _SaveObject(classFilePath, classXml,streamer);
1114
1115
1116 PEG_METHOD_EXIT();
1117 }
1118
1119 /*------------------------------------------------------------------------------
1120
1121 This routine does the following:
1122
1123 1. Creates two entries in the association file for each relationship
1124 formed by this new assocation instance. A binary association
1125 (one with two references) ties two instances together. Suppose
1126 there are two instances: I1 and I2. Then two entries are created:
1127
1128 I2 -> I1
1129 I1 -> I2
1130
1131 For a ternary relationship, six entries will be created. Suppose
1132 mike 1.1.2.1 there are three instances: I1, I2, and I3:
1133
1134 I1 -> I2
1135 I1 -> I3
1136 I2 -> I1
1137 I2 -> I3
1138 I3 -> I1
1139 I3 -> I2
1140
1141 So for an N-ary relationship, there will be 2*N entries created.
1142
1143 2. Verifies that the association instance refers to real objects.
1144 (note that an association reference may refer to either an instance
1145 or a class). Throws an exception if one of the references does not
1146 refer to a valid object.
1147
1148 ------------------------------------------------------------------------------*/
1149
1150
1151 void DefaultRepository::_createAssocInstEntries(
1152 const CIMNamespaceName& nameSpace,
1153 mike 1.1.2.1 const CIMConstClass& cimClass,
1154 const CIMInstance& cimInstance,
1155 const CIMObjectPath& instanceName)
1156 {
1157 PEG_METHOD_ENTER(
1158 TRC_REPOSITORY, "DefaultRepository::_createAssocInstEntries");
1159
1160 // Open input file:
1161
1162 String assocFileName = _nameSpaceManager.getAssocInstPath(nameSpace);
1163 ofstream os;
1164
1165 if (!OpenAppend(os, assocFileName))
1166 {
1167 PEG_METHOD_EXIT();
1168 throw CannotOpenFile(assocFileName);
1169 }
1170
1171 // Get the association's instance name and class name:
1172
1173 String assocInstanceName = instanceName.toString();
1174 mike 1.1.2.1 CIMName assocClassName = instanceName.getClassName();
1175
1176 // For each property:
1177
1178 for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)
1179 {
1180 CIMConstProperty fromProp = cimInstance.getProperty(i);
1181
1182 // If a reference property:
1183
1184 if (fromProp.getType() == CIMTYPE_REFERENCE)
1185 {
1186 // For each property:
1187
1188 for (Uint32 j = 0, n = cimInstance.getPropertyCount(); j < n; j++)
1189 {
1190 CIMConstProperty toProp = cimInstance.getProperty(j);
1191
1192 // If a reference property and not the same property:
1193
1194 if (toProp.getType() == CIMTYPE_REFERENCE &&
1195 mike 1.1.2.1 (!fromProp.getName().equal (toProp.getName())))
1196 {
1197 CIMObjectPath fromRef;
1198 fromProp.getValue().get(fromRef);
1199
1200 CIMObjectPath toRef;
1201 toProp.getValue().get(toRef);
1202
1203
1204 // Fix for bugzilla 667:
1205 // Strip off the hostname if it is the same as the
1206 // local host
1207 if ((fromRef.getHost() != String::EMPTY) &&
1208 (System::isLocalHost(fromRef.getHost())))
1209 {
1210 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1211 "_createAssocInstEntries() - Stripping off local "
1212 "hostName from fromRef");
1213 fromRef.setHost(String::EMPTY);
1214 }
1215
1216 mike 1.1.2.1 // Strip off the namespace when it is the same as the
1217 // one this instance is created in.
1218 if ((fromRef.getHost() == String::EMPTY) &&
1219 (fromRef.getNameSpace() == nameSpace))
1220 {
1221 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1222 "_createAssocInstEntries() - Stripping off "
1223 "local nameSpace from fromRef");
1224 fromRef.setNameSpace(CIMNamespaceName());
1225 }
1226
1227 // Strip off the hostname if it is the same as the
1228 // local host
1229 if ((toRef.getHost() != String::EMPTY) &&
1230 (System::isLocalHost(toRef.getHost())))
1231 {
1232 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1233 "_createAssocInstEntries() - Stripping off "
1234 "local hostName from toRef");
1235 toRef.setHost(String::EMPTY);
1236 }
1237 mike 1.1.2.1
1238 // Strip off the namespace when it is the same as the
1239 // one this instance is created in.
1240 if ((toRef.getHost() == String::EMPTY) &&
1241 (toRef.getNameSpace() == nameSpace))
1242 {
1243 PEG_TRACE_CSTRING(TRC_REPOSITORY, Tracer::LEVEL4,
1244 "_createAssocInstEntries() - Stripping off "
1245 "local nameSpace from toRef");
1246 toRef.setNameSpace(CIMNamespaceName());
1247 }
1248
1249
1250 String fromObjectName = fromRef.toString();
1251 CIMName fromClassName = fromRef.getClassName();
1252 CIMName fromPropertyName = fromProp.getName();
1253 String toObjectName = toRef.toString();
1254 CIMName toClassName = toRef.getClassName();
1255 CIMName toPropertyName = toProp.getName();
1256
1257 AssocInstTable::append(
1258 mike 1.1.2.1 os,
1259 assocInstanceName,
1260 assocClassName,
1261 fromObjectName,
1262 fromClassName,
1263 fromPropertyName,
1264 toObjectName,
1265 toClassName,
1266 toPropertyName);
1267 }
1268 }
1269 }
1270 }
1271
1272 PEG_METHOD_EXIT();
1273 }
1274
1275 CIMObjectPath DefaultRepository::createInstance(
1276 bool lock,
1277 const CIMNamespaceName& nameSpace,
1278 const CIMInstance& newInstance,
1279 mike 1.1.2.1 const ContentLanguageList& contentLangs)
1280 {
1281 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::createInstance");
1282
|
1283 mike 1.1.2.2 WriteLock wlock(_lock, lock);
1284 AutoFileLock fileLock(_lockFile, lock);
|
1285 mike 1.1.2.1
1286 String errMessage;
1287
1288 //
1289 // Resolve the instance. Looks up class and fills out properties but
1290 // not the qualifiers.
1291 //
1292
1293 CIMInstance cimInstance(newInstance);
1294 CIMConstClass cimClass;
1295 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
1296 false);
1297 CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
1298
1299 //
1300 // Make sure the class has keys (otherwise it will be impossible to
1301 // create the instance).
1302 //
1303
1304 if (!cimClass.hasKeys())
1305 {
1306 mike 1.1.2.1 PEG_METHOD_EXIT();
1307 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
1308 mike 1.1.2.2 MessageLoaderParms("Repository.CIMRepository.CLASS_HAS_NO_KEYS",
|
1309 mike 1.1.2.1 "class has no keys: $0",
1310 cimClass.getClassName().getString()));
1311 }
1312
1313 //
1314 // Be sure instance does not already exist:
1315 //
1316
1317 if (_checkInstanceAlreadyExists(nameSpace, instanceName))
1318 {
1319 PEG_METHOD_EXIT();
1320 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS,
1321 instanceName.toString());
1322 }
1323
1324 //
1325 // Create association entries if an association instance.
1326 //
1327
1328 if (cimClass.isAssociation())
1329 _createAssocInstEntries(nameSpace, cimClass, cimInstance, instanceName);
1330 mike 1.1.2.1
1331 //
1332 // Get paths to data and index files:
1333 //
1334
1335 String indexFilePath = _getInstanceIndexFilePath(
1336 nameSpace, newInstance.getClassName());
1337
1338 String dataFilePath = _getInstanceDataFilePath(
1339 nameSpace, newInstance.getClassName());
1340
1341 //
1342 // Perform the operation in a transaction scope to enable rollback on
1343 // failure.
1344 //
1345
1346 InstanceTransactionHandler transaction(indexFilePath, dataFilePath);
1347
1348 //
1349 // Save instance to file:
1350 //
1351 mike 1.1.2.1
1352 Uint32 index;
1353 Uint32 size;
1354
1355 {
1356 Buffer data;
1357 streamer->encode(data, cimInstance);
1358 size = data.size();
1359
1360 if (!InstanceDataFile::appendInstance(dataFilePath, data, index))
1361 {
1362 PEG_METHOD_EXIT();
1363 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1364 MessageLoaderParms(
|
1365 mike 1.1.2.2 "Repository.CIMRepository.FAILED_TO_CREATE_INSTANCE",
|
1366 mike 1.1.2.1 "Failed to create instance: $0",
1367 instanceName.toString()));
1368 }
1369 }
1370
1371 //
1372 // Create entry in index file:
1373 //
1374
1375 if (!InstanceIndexFile::createEntry(
1376 indexFilePath, instanceName, index, size))
1377 {
1378 PEG_METHOD_EXIT();
1379 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1380 MessageLoaderParms(
|
1381 mike 1.1.2.2 "Repository.CIMRepository.FAILED_TO_CREATE_INSTANCE",
|
1382 mike 1.1.2.1 "Failed to create instance: $0",
1383 instanceName.toString()));
1384 }
1385
1386 transaction.complete();
1387
1388 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
1389 true);
1390
1391
1392 PEG_METHOD_EXIT();
1393 return instanceName;
1394 }
1395
1396 void DefaultRepository::modifyClass(
1397 bool lock,
1398 const CIMNamespaceName& nameSpace,
1399 const CIMClass& modifiedClass,
1400 const ContentLanguageList& contentLangs)
1401 {
1402 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::modifyClass");
1403 mike 1.1.2.1
|
1404 mike 1.1.2.2 WriteLock wlock(_lock, lock);
1405 AutoFileLock fileLock(_lockFile, lock);
|
1406 mike 1.1.2.1
1407 //
1408 // Resolve the class:
1409 //
1410
1411 CIMClass cimClass(modifiedClass);
1412 Resolver::resolveClass (cimClass, _context, nameSpace);
1413
1414 //
1415 // Check to see if it is okay to modify this class:
1416 //
1417
1418 String classFilePath;
1419
1420 _nameSpaceManager.checkModify(nameSpace, cimClass.getClassName(),
1421 cimClass.getSuperClassName(), classFilePath);
1422
1423 //
1424 // ATTN: KS
1425 // Disallow modification of classes which have instances (that are
1426 // in the repository). And we have no idea whether the class has
1427 mike 1.1.2.1 // instances in other repositories or in providers. We should do
1428 // an enumerate instance names at a higher level (above the repository).
1429 //
1430
1431 #ifdef PEGASUS_USE_CLASS_CACHE
1432
1433 _classCache.evict(classFilePath);
1434
1435 #endif /* PEGASUS_USE_CLASS_CACHE */
1436
1437 //
1438 // Delete the old file containing the class:
1439 //
1440
1441 if (!FileSystem::removeFileNoCase(classFilePath))
1442 {
1443 PEG_METHOD_EXIT();
1444 String str = "DefaultRepository::modifyClass()";
1445 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1446 MessageLoaderParms(
|
1447 mike 1.1.2.2 "Repository.CIMRepository.FAILED_TO_REMOVE_FILE",
|
1448 mike 1.1.2.1 "failed to remove file in $0", str));
1449 }
1450
1451 //
1452 // Create new class file:
1453 //
1454
1455 Buffer classXml;
1456 streamer->encode(classXml, cimClass);
1457 //XmlWriter::appendClassElement(classXml, cimClass);
1458 _SaveObject(classFilePath, classXml,streamer);
1459
1460 if (cimClass.isAssociation())
1461 {
1462 // Remove from Association
1463 Array<String> assocFileName =
1464 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceDelete);
1465 if (FileSystem::exists(assocFileName[0]))
1466 {
1467 AssocClassTable::deleteAssociation(
1468 assocFileName[0], cimClass.getClassName());
1469 mike 1.1.2.1 // Create the association again.
1470 _createAssocClassEntries(nameSpace, cimClass);
1471 }
1472 else
1473 {
1474 PEG_METHOD_EXIT();
1475 throw CannotOpenFile(assocFileName[0]);
1476 }
1477 }
1478
1479
1480 //
1481 // Cache this class:
1482 //
1483
1484 #ifdef PEGASUS_USE_CLASS_CACHE
1485
1486 _classCache.put(classFilePath, cimClass);
1487
1488 #endif /* PEGASUS_USE_CLASS_CACHE */
1489
1490 mike 1.1.2.1 PEG_METHOD_EXIT();
1491 }
1492
1493 void DefaultRepository::modifyInstance(
1494 bool lock,
1495 const CIMNamespaceName& nameSpace,
1496 const CIMInstance& modifiedInstance,
1497 Boolean includeQualifiers,
1498 const CIMPropertyList& propertyList,
1499 const ContentLanguageList& contentLangs)
1500 {
1501 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::modifyInstance");
1502
|
1503 mike 1.1.2.2 WriteLock wlock(_lock, lock);
1504 AutoFileLock fileLock(_lockFile, lock);
|
1505 mike 1.1.2.1
1506 //
1507 // Do this:
1508 //
1509
1510 String errMessage;
1511 CIMInstance cimInstance; // The instance that replaces the original
1512
1513 if (propertyList.isNull())
1514 {
1515 //
1516 // Replace all the properties in the instance
1517 //
1518 if (includeQualifiers)
1519 {
1520 //
1521 // Replace the entire instance with the given instance
1522 // (this is the default behavior)
1523 //
1524 cimInstance = modifiedInstance;
1525 }
1526 mike 1.1.2.1 else
1527 {
1528 //
1529 // Replace all the properties in the instance, but keep the
1530 // original qualifiers on the instance and on the properties
1531 //
1532
1533 _resolveInstance = false;
1534
1535 cimInstance = getInstance(
1536 false,
1537 nameSpace,
1538 modifiedInstance.getPath (),
1539 false,
1540 true,
1541 true,
1542 CIMPropertyList());
1543
1544 _resolveInstance = true;
1545
1546 CIMInstance newInstance(
1547 mike 1.1.2.1 modifiedInstance.getPath ().getClassName());
1548
1549 CIMInstance givenInstance = modifiedInstance;
1550
1551 //
1552 // Copy over the original instance qualifiers
1553 //
1554
1555 for (Uint32 i = 0; i < cimInstance.getQualifierCount(); i++)
1556 {
1557 newInstance.addQualifier(cimInstance.getQualifier(i));
1558 }
1559
1560 //
1561 // Loop through the properties replacing each property in the
1562 // original with a new value, but keeping the original qualifiers
1563 //
1564 for (Uint32 i=0; i<givenInstance.getPropertyCount(); i++)
1565 {
1566 // Copy the given property value (not qualifiers)
1567 CIMProperty givenProperty = givenInstance.getProperty(i);
1568 mike 1.1.2.1 CIMProperty newProperty(
1569 givenProperty.getName(),
1570 givenProperty.getValue(),
1571 givenProperty.getArraySize(),
1572 givenProperty.getReferenceClassName(),
1573 givenProperty.getClassOrigin(),
1574 givenProperty.getPropagated());
1575
1576 // Copy the original property qualifiers
1577 Uint32 origPos =
1578 cimInstance.findProperty(newProperty.getName());
1579 if (origPos != PEG_NOT_FOUND)
1580 {
1581 CIMProperty origProperty = cimInstance.getProperty(origPos);
1582 for (Uint32 j=0; j<origProperty.getQualifierCount(); j++)
1583 {
1584 newProperty.addQualifier(origProperty.getQualifier(j));
1585 }
1586 }
1587
1588 // Add the newly constructed property to the new instance
1589 mike 1.1.2.1 newInstance.addProperty(newProperty);
1590 }
1591
1592 // Use the newly merged instance to replace the original instance
1593 cimInstance = newInstance;
1594 }
1595 }
1596 else
1597 {
1598 //
1599 // Replace only the properties specified in the given instance
1600 //
1601
1602 _resolveInstance = false;
1603
1604 cimInstance = getInstance(false, nameSpace,
1605 modifiedInstance.getPath (), false, true, true, CIMPropertyList());
1606
1607 _resolveInstance = true;
1608
1609 CIMInstance givenInstance = modifiedInstance;
1610 mike 1.1.2.1
1611 // NOTE: Instance qualifiers are not changed when a property list
1612 // is specified. Property qualifiers are replaced with the
1613 // corresponding property values.
1614
1615 //
1616 // Loop through the propertyList replacing each property in the original
1617 //
1618
1619 for (Uint32 i=0; i<propertyList.size(); i++)
1620 {
1621 Uint32 origPropPos = cimInstance.findProperty(propertyList[i]);
1622 if (origPropPos != PEG_NOT_FOUND)
1623 {
1624 // Case: Property set in original
1625 CIMProperty origProperty =
1626 cimInstance.getProperty(origPropPos);
1627
1628 // Get the given property value
1629 Uint32 givenPropPos =
1630 givenInstance.findProperty(propertyList[i]);
1631 mike 1.1.2.1 if (givenPropPos != PEG_NOT_FOUND)
1632 {
1633 // Case: Property set in original and given
1634 CIMProperty givenProperty =
1635 givenInstance.getProperty(givenPropPos);
1636
1637 // Copy over the property from the given to the original
1638 if (includeQualifiers)
1639 {
1640 // Case: Total property replacement
1641 cimInstance.removeProperty(origPropPos);
1642 cimInstance.addProperty(givenProperty);
1643 }
1644 else
1645 {
1646 // Case: Replace only the property value (not quals)
1647 origProperty.setValue(givenProperty.getValue());
1648 cimInstance.removeProperty(origPropPos);
1649 cimInstance.addProperty(origProperty);
1650 }
1651 }
1652 mike 1.1.2.1 else
1653 {
1654 // Case: Property set in original and not in given
1655 // Just remove the property (set to null)
1656 cimInstance.removeProperty(origPropPos);
1657 }
1658 }
1659 else
1660 {
1661 // Case: Property not set in original
1662
1663 // Get the given property value
1664 Uint32 givenPropPos =
1665 givenInstance.findProperty(propertyList[i]);
1666 if (givenPropPos != PEG_NOT_FOUND)
1667 {
1668 // Case: Property set in given and not in original
1669 CIMProperty givenProperty =
1670 givenInstance.getProperty(givenPropPos);
1671
1672 // Copy over the property from the given to the original
1673 mike 1.1.2.1 if (includeQualifiers)
1674 {
1675 // Case: Total property copy
1676 cimInstance.addProperty(givenProperty);
1677 }
1678 else
1679 {
1680 // Case: Copy only the property value (not qualifiers)
1681 CIMProperty newProperty(
1682 givenProperty.getName(),
1683 givenProperty.getValue(),
1684 givenProperty.getArraySize(),
1685 givenProperty.getReferenceClassName(),
1686 givenProperty.getClassOrigin(),
1687 givenProperty.getPropagated());
1688 cimInstance.addProperty(newProperty);
1689 }
1690 }
1691 else
1692 {
1693 // Case: Property not set in original or in given
1694 mike 1.1.2.1
1695 // Nothing to do; just make sure the property name is valid
1696 // ATTN: This is not the most efficient solution
1697
1698 CIMClass cimClass = getClass(
1699 false,
1700 nameSpace,
1701 cimInstance.getClassName(),
1702 false,
1703 true,
1704 false,
1705 CIMPropertyList());
1706
1707 if (cimClass.findProperty(propertyList[i]) == PEG_NOT_FOUND)
1708 {
1709 // ATTN: This exception may be returned by setProperty
1710 PEG_METHOD_EXIT();
1711 throw PEGASUS_CIM_EXCEPTION(
1712 CIM_ERR_NO_SUCH_PROPERTY, "modifyInstance()");
1713 }
1714 }
1715 mike 1.1.2.1 }
1716 }
1717 }
1718
1719 //
1720 // Resolve the instance (do not propagate qualifiers from class since
1721 // this will bloat the instance).
1722 //
1723
1724 CIMConstClass cimClass;
1725 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
1726 false);
1727
1728 CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
1729
1730 //
1731 // Disallow operation if the instance name was changed:
1732 //
1733
1734 // For bugzilla 1508. Hostname and namespace are not included
1735 // in the comparison here.
1736 mike 1.1.2.1 CIMObjectPath modifiedInstancePath = modifiedInstance.getPath();
1737 modifiedInstancePath.setNameSpace(CIMNamespaceName());
1738 modifiedInstancePath.setHost(String::EMPTY);
1739 if (instanceName != modifiedInstancePath)
1740 {
1741 PEG_METHOD_EXIT();
1742 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1743 MessageLoaderParms(
|
1744 mike 1.1.2.2 "Repository.CIMRepository.ATTEMPT_TO_MODIFY_KEY_PROPERTY",
|
1745 mike 1.1.2.1 "Attempted to modify a key property"));
1746 }
1747
1748 //
1749 // Get paths of index and data files:
1750 //
1751
1752 String indexFilePath = _getInstanceIndexFilePath(
1753 nameSpace, modifiedInstance.getClassName());
1754
1755 String dataFilePath = _getInstanceDataFilePath(
1756 nameSpace, modifiedInstance.getClassName());
1757
1758 //
1759 // Look up the specified instance
1760 //
1761
1762 Uint32 oldSize;
1763 Uint32 oldIndex;
1764 Uint32 newSize;
1765 Uint32 newIndex;
1766 mike 1.1.2.1
1767 if (!InstanceIndexFile::lookupEntry(
1768 indexFilePath, instanceName, oldIndex, oldSize))
1769 {
1770 PEG_METHOD_EXIT();
1771 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
1772 }
1773
1774 //
1775 // Perform the operation in a transaction scope to enable rollback on
1776 // failure.
1777 //
1778
1779 InstanceTransactionHandler transaction(indexFilePath, dataFilePath);
1780
1781 //
1782 // Modify the data file:
1783 //
1784
1785 {
1786 Buffer out;
1787 mike 1.1.2.1 streamer->encode(out, cimInstance);
1788 //XmlWriter::appendInstanceElement(out, cimInstance);
1789
1790 newSize = out.size();
1791
1792 if (!InstanceDataFile::appendInstance(dataFilePath, out, newIndex))
1793 {
1794 PEG_METHOD_EXIT();
1795 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1796 MessageLoaderParms(
|
1797 mike 1.1.2.2 "Repository.CIMRepository.FAILED_TO_MODIFY_INSTANCE",
|
1798 mike 1.1.2.1 "Failed to modify instance $0",
1799 instanceName.toString()));
1800 }
1801 }
1802
1803 //
1804 // Modify the index file:
1805 //
1806
1807 Uint32 freeCount;
1808
1809 if (!InstanceIndexFile::modifyEntry(indexFilePath, instanceName, newIndex,
1810 newSize, freeCount))
1811 {
1812 PEG_METHOD_EXIT();
1813 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
1814 MessageLoaderParms(
|
1815 mike 1.1.2.2 "Repository.CIMRepository.FAILED_TO_MODIFY_INSTANCE",
|
1816 mike 1.1.2.1 "Failed to modify instance $0",
1817 instanceName.toString()));
1818 }
1819
1820 transaction.complete();
1821
1822 //
1823 // Compact the index and data files if the free count max was
1824 // reached.
1825 //
1826
1827 if (freeCount == _MAX_FREE_COUNT)
1828 _CompactInstanceRepository(indexFilePath, dataFilePath);
1829
1830 //
1831 // Resolve the instance:
1832 //
1833
1834 Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass,
1835 true);
1836
1837 mike 1.1.2.1 PEG_METHOD_EXIT();
1838 }
1839
1840 Array<CIMClass> DefaultRepository::enumerateClasses(
1841 bool lock,
1842 const CIMNamespaceName& nameSpace,
1843 const CIMName& className,
1844 Boolean deepInheritance,
1845 Boolean localOnly,
1846 Boolean includeQualifiers,
1847 Boolean includeClassOrigin)
1848 {
1849 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::enumerateClasses");
1850
|
1851 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
1852 mike 1.1.2.1
1853 Array<CIMName> classNames;
1854
1855 _nameSpaceManager.getSubClassNames(
1856 nameSpace, className, deepInheritance, classNames);
1857
1858 Array<CIMClass> result;
1859
1860 for (Uint32 i = 0; i < classNames.size(); i++)
1861 {
1862 result.append(getClass(false, nameSpace, classNames[i], localOnly,
1863 includeQualifiers, includeClassOrigin, CIMPropertyList()));
1864 }
1865
1866 PEG_METHOD_EXIT();
1867 return result;
1868 }
1869
1870 Array<CIMName> DefaultRepository::enumerateClassNames(
1871 bool lock,
1872 const CIMNamespaceName& nameSpace,
1873 mike 1.1.2.1 const CIMName& className,
1874 Boolean deepInheritance)
1875 {
1876 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::enumerateClassNames");
1877
|
1878 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
1879 mike 1.1.2.1
1880 Array<CIMName> classNames;
1881
1882 _nameSpaceManager.getSubClassNames(
1883 nameSpace, className, deepInheritance, classNames,true);
1884
1885 PEG_METHOD_EXIT();
1886 return classNames;
1887 }
1888
1889 Boolean DefaultRepository::_loadAllInstances(
1890 const CIMNamespaceName& nameSpace,
1891 const CIMName& className,
1892 Array<CIMInstance>& namedInstances)
1893 {
1894 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::_loadAllInstances");
1895
1896 Array<CIMObjectPath> instanceNames;
1897 Buffer data;
1898 Array<Uint32> indices;
1899 Array<Uint32> sizes;
1900 mike 1.1.2.1
1901 //
1902 // Form the names of the instance index and data files
1903 //
1904
1905 String indexFilePath = _getInstanceIndexFilePath(nameSpace, className);
1906 String dataFilePath = _getInstanceDataFilePath(nameSpace, className);
1907
1908 //
1909 // Enumerate the index file:
1910 //
1911
1912 Array<Uint32> freeFlags;
1913
1914 if (!InstanceIndexFile::enumerateEntries(
1915 indexFilePath, freeFlags, indices, sizes, instanceNames, true))
1916 {
1917 PEG_METHOD_EXIT();
1918 return false;
1919 }
1920
1921 mike 1.1.2.1 //
1922 // Form the array of instances result:
1923 //
1924
1925 if (instanceNames.size() > 0)
1926 {
1927 //
1928 // Load all instances from the data file:
1929 //
1930
1931 if (!InstanceDataFile::loadAllInstances(dataFilePath, data))
1932 {
1933 PEG_METHOD_EXIT();
1934 return false;
1935 }
1936
1937 //
1938 // for each instance loaded, call XML parser to parse the XML
1939 // data and create a CIMInstance object.
1940 //
1941
1942 mike 1.1.2.1 CIMInstance tmpInstance;
1943
1944 Uint32 bufferSize = data.size();
1945 char* buffer = (char*)data.getData();
1946
1947 for (Uint32 i = 0; i < instanceNames.size(); i++)
1948 {
1949 if (!freeFlags[i])
1950 {
1951 Uint32 pos= (Uint32)((&(buffer[indices[i]]))-buffer);
1952 streamer->decode(data, pos, tmpInstance);
1953
1954 Resolver::resolveInstance (tmpInstance, _context, nameSpace,
1955 true);
1956 tmpInstance.setPath (instanceNames[i]);
1957
1958 namedInstances.append (tmpInstance);
1959 }
1960 }
1961 }
1962
1963 mike 1.1.2.1 PEG_METHOD_EXIT();
1964 return true;
1965 }
1966
1967 Array<CIMInstance> DefaultRepository::enumerateInstancesForSubtree(
1968 bool lock,
1969 const CIMNamespaceName& nameSpace,
1970 const CIMName& className,
1971 Boolean deepInheritance,
1972 Boolean localOnly,
1973 Boolean includeQualifiers,
1974 Boolean includeClassOrigin,
1975 const CIMPropertyList& propertyList)
1976 {
1977 PEG_METHOD_ENTER(TRC_REPOSITORY,
1978 "DefaultRepository::enumerateInstancesForSubtree");
1979
1980 // It is not necessary to control access to the ReadWriteSem _lock here.
1981 // This method calls enumerateInstancesForClass, which does its own
1982 // access control.
1983
1984 mike 1.1.2.1 //
1985 // Get all descendent classes of this class:
1986 //
1987
1988 Array<CIMName> classNames;
1989 classNames.append(className);
1990 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
1991
1992 //
1993 // Get all instances for this class and all its descendent classes
1994 //
1995
1996 Array<CIMInstance> namedInstances;
1997
1998 for (Uint32 i = 0; i < classNames.size(); i++)
1999 {
2000 Array<CIMInstance> localNamedInstances =
2001 enumerateInstancesForClass(true, nameSpace, classNames[i],
2002 false, includeQualifiers, includeClassOrigin, propertyList);
2003
2004 // ATTN: Handles everything but deepInheritance.
2005 mike 1.1.2.1 for (Uint32 i = 0 ; i < localNamedInstances.size(); i++)
2006 {
2007 Filtering::filterInstance(localNamedInstances[i],
2008 localOnly,
2009 includeQualifiers,
2010 includeClassOrigin,
2011 propertyList);
2012 }
2013 namedInstances.appendArray(localNamedInstances);
2014 }
2015
2016 PEG_METHOD_EXIT();
2017 return namedInstances;
2018 }
2019
2020 Array<CIMInstance> DefaultRepository::enumerateInstancesForClass(
2021 bool lock,
2022 const CIMNamespaceName& nameSpace,
2023 const CIMName& className,
2024 Boolean localOnly,
2025 Boolean includeQualifiers,
2026 mike 1.1.2.1 Boolean includeClassOrigin,
2027 const CIMPropertyList& propertyList)
2028 {
2029 PEG_METHOD_ENTER(TRC_REPOSITORY,
2030 "DefaultRepository::enumerateInstancesForClass");
2031
|
2032 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2033 mike 1.1.2.1
2034 //
2035 // Get all instances for this class
2036 //
2037
2038 Array<CIMInstance> namedInstances;
2039
2040 if (!_loadAllInstances(nameSpace, className, namedInstances))
2041 {
2042 PEG_METHOD_EXIT();
2043 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2044 MessageLoaderParms(
|
2045 mike 1.1.2.2 "Repository.CIMRepository.FAILED_TO_LOAD_INSTANCES",
|
2046 mike 1.1.2.1 "Failed to load instances in class $0",
2047 className.getString()));
2048 }
2049
2050 // Do any required filtering of properties, qualifiers, classorigin
2051 // on the returned instances.
2052 for (Uint32 i = 0 ; i < namedInstances.size(); i++)
2053 {
2054 Filtering::filterInstance(namedInstances[i],
2055 localOnly,
2056 includeQualifiers,
2057 includeClassOrigin,
2058 propertyList);
2059 }
2060
2061 PEG_METHOD_EXIT();
2062 return namedInstances;
2063 }
2064
2065 Array<CIMObjectPath> DefaultRepository::enumerateInstanceNamesForSubtree(
2066 bool lock,
2067 mike 1.1.2.1 const CIMNamespaceName& nameSpace,
2068 const CIMName& className)
2069 {
2070 PEG_METHOD_ENTER(TRC_REPOSITORY,
2071 "DefaultRepository::enumerateInstanceNamesForSubtree");
2072
2073 // It is not necessary to control access to the ReadWriteSem _lock here.
2074 // This method calls enumerateInstanceNamesForClass, which does its own
2075 // access control.
2076
2077 //
2078 // Get names of descendent classes:
2079 //
2080
2081 Array<CIMName> classNames;
2082 classNames.append(className);
2083 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
2084
2085 //
2086 // Enumerate instance names for each of the subclasses
2087 //
2088 mike 1.1.2.1 Array<CIMObjectPath> instanceNames;
2089
2090 for (Uint32 i = 0; i < classNames.size(); i++)
2091 {
2092 instanceNames.appendArray(
2093 enumerateInstanceNamesForClass(true, nameSpace, classNames[i]));
2094 }
2095
2096 PEG_METHOD_EXIT();
2097 return instanceNames;
2098 }
2099
2100 Array<CIMObjectPath> DefaultRepository::enumerateInstanceNamesForClass(
2101 bool lock,
2102 const CIMNamespaceName& nameSpace,
2103 const CIMName& className)
2104 {
2105 PEG_METHOD_ENTER(TRC_REPOSITORY,
2106 "DefaultRepository::enumerateInstanceNamesForClass");
2107
|
2108 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2109 mike 1.1.2.1
2110 //
2111 // Get instance names from the instance index file for the class:
2112 //
2113 Array<CIMObjectPath> instanceNames;
2114 Array<Uint32> indices;
2115 Array<Uint32> sizes;
2116
2117 //
2118 // Form the names of the instance index and data files
2119 //
2120
2121 String indexFilePath = _getInstanceIndexFilePath(nameSpace, className);
2122 String dataFilePath = _getInstanceDataFilePath(nameSpace, className);
2123
2124 //
2125 // Get all instances for the class:
2126 //
2127
2128 Array<Uint32> freeFlags;
2129
2130 mike 1.1.2.1 if (!InstanceIndexFile::enumerateEntries(
2131 indexFilePath, freeFlags, indices, sizes, instanceNames, false))
2132 {
2133 PEG_METHOD_EXIT();
2134 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
2135 MessageLoaderParms(
|
2136 mike 1.1.2.2 "Repository.CIMRepository.FAILED_TO_LOAD_INSTANCE_NAMES",
|
2137 mike 1.1.2.1 "Failed to load instance names in class $0",
2138 className.getString()));
2139 }
2140
2141 PEG_METHOD_EXIT();
2142 return instanceNames;
2143 }
2144
2145
2146 Array<CIMInstance> DefaultRepository::execQuery(
2147 bool lock,
2148 const String& queryLanguage,
2149 const String& query)
2150 {
2151 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::execQuery");
2152
|
2153 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2154 mike 1.1.2.1
2155 PEG_METHOD_EXIT();
2156 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "execQuery()");
2157
2158 PEGASUS_UNREACHABLE(PEG_METHOD_EXIT();
2159 return Array<CIMInstance>();)
2160 }
2161
2162 Array<CIMObject> DefaultRepository::associators(
2163 bool lock,
2164 const CIMNamespaceName& nameSpace,
2165 const CIMObjectPath& objectName,
2166 const CIMName& assocClass,
2167 const CIMName& resultClass,
2168 const String& role,
2169 const String& resultRole,
2170 Boolean includeQualifiers,
2171 Boolean includeClassOrigin,
2172 const CIMPropertyList& propertyList)
2173 {
2174 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::associators");
2175 mike 1.1.2.1
|
2176 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2177 mike 1.1.2.1
2178 Array<CIMObjectPath> names = associatorNames(
2179 false,
2180 nameSpace,
2181 objectName,
2182 assocClass,
2183 resultClass,
2184 role,
2185 resultRole);
2186
2187 Array<CIMObject> result;
2188
2189 for (Uint32 i = 0, n = names.size(); i < n; i++)
2190 {
2191 CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
2192
2193 if (tmpNameSpace.isNull())
2194 tmpNameSpace = nameSpace;
2195
2196 //
2197 // ATTN-CAKG-P2-20020726: The following condition does not correctly
2198 mike 1.1.2.1 // distinguish instanceNames from classNames in every case
2199 // The instanceName of a singleton instance of a keyless class also
2200 // has no key bindings
2201 //
2202 if (names[i].getKeyBindings ().size () == 0)
2203 {
2204 CIMObjectPath tmpRef = names[i];
2205 tmpRef.setHost(String());
2206 tmpRef.setNameSpace(CIMNamespaceName());
2207
2208 CIMClass cimClass = getClass(
2209 false,
2210 tmpNameSpace,
2211 tmpRef.getClassName(),
2212 false,
2213 includeQualifiers,
2214 includeClassOrigin,
2215 propertyList);
2216
2217 CIMObject cimObject(cimClass);
2218 cimObject.setPath (names[i]);
2219 mike 1.1.2.1 result.append(cimObject);
2220 }
2221 else
2222 {
2223 CIMObjectPath tmpRef = names[i];
2224 tmpRef.setHost(String());
2225 tmpRef.setNameSpace(CIMNamespaceName());
2226
2227 CIMInstance cimInstance = getInstance(
2228 false,
2229 tmpNameSpace,
2230 tmpRef,
2231 false,
2232 includeQualifiers,
2233 includeClassOrigin,
2234 propertyList);
2235
2236 CIMObject cimObject(cimInstance);
2237 cimObject.setPath (names[i]);
2238 result.append(cimObject);
2239 }
2240 mike 1.1.2.1 }
2241
2242 PEG_METHOD_EXIT();
2243 return result;
2244 }
2245
2246 Array<CIMObjectPath> DefaultRepository::associatorNames(
2247 bool lock,
2248 const CIMNamespaceName& nameSpace,
2249 const CIMObjectPath& objectName,
2250 const CIMName& assocClass,
2251 const CIMName& resultClass,
2252 const String& role,
2253 const String& resultRole)
2254 {
2255 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::associatorNames");
2256
|
2257 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2258 mike 1.1.2.1
2259 Array<String> associatorNames;
2260
2261 // The assocClass parameter implies subclasses, so retrieve them
2262 Array<CIMName> assocClassList;
2263 if (!assocClass.isNull())
2264 {
2265 _nameSpaceManager.getSubClassNames(
2266 nameSpace, assocClass, true, assocClassList);
2267 assocClassList.append(assocClass);
2268 }
2269
2270 // The resultClass parameter implies subclasses, so retrieve them
2271 Array<CIMName> resultClassList;
2272 if (!resultClass.isNull())
2273 {
2274 _nameSpaceManager.getSubClassNames(
2275 nameSpace, resultClass, true, resultClassList);
2276 resultClassList.append(resultClass);
2277 }
2278
2279 mike 1.1.2.1 //
2280 // ATTN-CAKG-P2-20020726: The following condition does not correctly
2281 // distinguish instanceNames from classNames in every case
2282 // The instanceName of a singleton instance of a keyless class also
2283 // has no key bindings
2284 //
2285 if (objectName.getKeyBindings ().size () == 0)
2286 {
2287 CIMName className = objectName.getClassName();
2288
2289 Array<CIMName> classList;
2290 _nameSpaceManager.getSuperClassNames(nameSpace, className, classList);
2291 classList.append(className);
2292
2293 Array<String> assocFileName =
2294 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceRead);
2295
2296 for (int i=0,m=assocFileName.size(); i<m; i++)
2297 {
2298 AssocClassTable::getAssociatorNames(
2299 assocFileName[i],
2300 mike 1.1.2.1 classList,
2301 assocClassList,
2302 resultClassList,
2303 role,
2304 resultRole,
2305 associatorNames);
2306 }
2307 }
2308 else
2309 {
2310 String assocFileName = _nameSpaceManager.getAssocInstPath(nameSpace);
2311
2312 AssocInstTable::getAssociatorNames(
2313 assocFileName,
2314 objectName,
2315 assocClassList,
2316 resultClassList,
2317 role,
2318 resultRole,
2319 associatorNames);
2320 }
2321 mike 1.1.2.1
2322 Array<CIMObjectPath> result;
2323
2324 for (Uint32 i = 0, n = associatorNames.size(); i < n; i++)
2325 {
2326 CIMObjectPath r = associatorNames[i];
2327
2328 if (r.getHost().size() == 0)
2329 r.setHost(System::getHostName());
2330
2331 if (r.getNameSpace().isNull())
2332 r.setNameSpace(nameSpace);
2333
2334 result.append(r);
2335 }
2336
2337
2338 PEG_METHOD_EXIT();
2339 return result;
2340 }
2341
2342 mike 1.1.2.1 Array<CIMObject> DefaultRepository::references(
2343 bool lock,
2344 const CIMNamespaceName& nameSpace,
2345 const CIMObjectPath& objectName,
2346 const CIMName& resultClass,
2347 const String& role,
2348 Boolean includeQualifiers,
2349 Boolean includeClassOrigin,
2350 const CIMPropertyList& propertyList)
2351 {
2352 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::references");
2353
|
2354 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2355 mike 1.1.2.1
2356 Array<CIMObjectPath> names = referenceNames(
2357 false,
2358 nameSpace,
2359 objectName,
2360 resultClass,
2361 role);
2362
2363 Array<CIMObject> result;
2364
2365 for (Uint32 i = 0, n = names.size(); i < n; i++)
2366 {
2367 CIMNamespaceName tmpNameSpace = names[i].getNameSpace();
2368
2369 if (tmpNameSpace.isNull())
2370 tmpNameSpace = nameSpace;
2371
2372 // ATTN: getInstance() should this be able to handle instance names
2373 // with host names and namespaces?
2374
2375 CIMObjectPath tmpRef = names[i];
2376 mike 1.1.2.1 tmpRef.setHost(String());
2377 tmpRef.setNameSpace(CIMNamespaceName());
2378
2379 //
2380 // ATTN-CAKG-P2-20020726: The following condition does not correctly
2381 // distinguish instanceNames from classNames in every case
2382 // The instanceName of a singleton instance of a keyless class also
2383 // has no key bindings
2384 //
2385 if (objectName.getKeyBindings ().size () == 0)
2386 {
2387 CIMClass cimClass = getClass(
2388 false,
2389 tmpNameSpace,
2390 tmpRef.getClassName(),
2391 false,
2392 includeQualifiers,
2393 includeClassOrigin,
2394 propertyList);
2395
2396 CIMObject cimObject = CIMObject (cimClass);
2397 mike 1.1.2.1 cimObject.setPath (names[i]);
2398 result.append (cimObject);
2399 }
2400 else
2401 {
2402 CIMInstance instance = getInstance(
2403 false,
2404 tmpNameSpace,
2405 tmpRef,
2406 false,
2407 includeQualifiers,
2408 includeClassOrigin,
2409 propertyList);
2410
2411 CIMObject cimObject = CIMObject (instance);
2412 cimObject.setPath (names[i]);
2413 result.append (cimObject);
2414 }
2415 }
2416
2417 PEG_METHOD_EXIT();
2418 mike 1.1.2.1 return result;
2419 }
2420
2421 Array<CIMObjectPath> DefaultRepository::referenceNames(
2422 bool lock,
2423 const CIMNamespaceName& nameSpace,
2424 const CIMObjectPath& objectName,
2425 const CIMName& resultClass,
2426 const String& role)
2427 {
2428 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::referenceNames");
2429
|
2430 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2431 mike 1.1.2.1
2432 Array<String> tmpReferenceNames;
2433
2434 // The resultClass parameter implies subclasses, so retrieve them
2435 Array<CIMName> resultClassList;
2436
2437 try
2438 {
2439 if (!resultClass.isNull())
2440 {
2441 _nameSpaceManager.getSubClassNames(
2442 nameSpace, resultClass, true, resultClassList);
2443 resultClassList.append(resultClass);
2444 }
2445
2446 // ATTN-CAKG-P2-20020726: The following condition does not correctly
2447 // distinguish instanceNames from classNames in every case
2448 // The instanceName of a singleton instance of a keyless class also
2449 // has no key bindings
2450 //
2451 if (objectName.getKeyBindings ().size () == 0)
2452 mike 1.1.2.1 {
2453 CIMName className = objectName.getClassName();
2454
2455 Array<CIMName> classList;
2456 _nameSpaceManager.getSuperClassNames(
2457 nameSpace, className, classList);
2458 classList.append(className);
2459
2460 Array<String> assocFileName =
2461 _nameSpaceManager.getAssocClassPath(nameSpace,NameSpaceRead);
2462
2463 Boolean refs=false;
2464 for (int i = 0, m=assocFileName.size(); !refs && i < m; i++)
2465 {
2466 if (AssocClassTable::getReferenceNames(
2467 assocFileName[i],
2468 classList,
2469 resultClassList,
2470 role,
2471 tmpReferenceNames))
2472 {
2473 mike 1.1.2.1 refs |= true;
2474 }
2475 }
2476
2477 if (refs == false)
2478 {
2479 // Ignore error! It's okay not to have references.
2480 }
2481 }
2482 else
2483 {
2484 String assocFileName =
2485 _nameSpaceManager.getAssocInstPath(nameSpace);
2486
2487 if (!AssocInstTable::getReferenceNames(
2488 assocFileName,
2489 objectName,
2490 resultClassList,
2491 role,
2492 tmpReferenceNames))
2493 {
2494 mike 1.1.2.1 // Ignore error! It's okay not to have references.
2495 }
2496 }
2497 }
2498 catch (const CIMException& exception)
2499 {
2500 if (exception.getCode() == CIM_ERR_INVALID_CLASS)
2501 {
2502 throw PEGASUS_CIM_EXCEPTION(
2503 CIM_ERR_INVALID_PARAMETER, exception.getMessage());
2504 }
2505 else
2506 {
2507 throw;
2508 }
2509 }
2510
2511 Array<CIMObjectPath> result;
2512
2513 for (Uint32 i = 0, n = tmpReferenceNames.size(); i < n; i++)
2514 {
2515 mike 1.1.2.1 CIMObjectPath r = tmpReferenceNames[i];
2516
2517 if (r.getHost().size() == 0)
2518 r.setHost(System::getHostName());
2519
2520 if (r.getNameSpace().isNull())
2521 r.setNameSpace(nameSpace);
2522
2523 result.append(r);
2524 }
2525
2526 PEG_METHOD_EXIT();
2527 return result;
2528 }
2529
2530 CIMValue DefaultRepository::getProperty(
2531 bool lock,
2532 const CIMNamespaceName& nameSpace,
2533 const CIMObjectPath& instanceName,
2534 const CIMName& propertyName)
2535 {
2536 mike 1.1.2.1 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::getProperty");
2537
|
2538 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2539 mike 1.1.2.1
2540 //
2541 // Retrieve the specified instance
2542 //
2543
2544 CIMInstance cimInstance = getInstance(
2545 false, nameSpace, instanceName, false, true, true, CIMPropertyList());
2546
2547 //
2548 // Get the requested property from the instance
2549 //
2550
2551 Uint32 pos = cimInstance.findProperty(propertyName);
2552
2553 // ATTN: This breaks if the property is simply null
2554 if (pos == PEG_NOT_FOUND)
2555 {
2556 PEG_METHOD_EXIT();
2557 throw PEGASUS_CIM_EXCEPTION(
2558 CIM_ERR_NO_SUCH_PROPERTY,
2559 propertyName.getString());
2560 mike 1.1.2.1 }
2561
2562 CIMProperty prop = cimInstance.getProperty(pos);
2563
2564 //
2565 // Return the value:
2566 //
2567
2568 PEG_METHOD_EXIT();
2569 return prop.getValue();
2570 }
2571
2572 void DefaultRepository::setProperty(
2573 bool lock,
2574 const CIMNamespaceName& nameSpace,
2575 const CIMObjectPath& instanceName,
2576 const CIMName& propertyName,
2577 const CIMValue& newValue,
2578 const ContentLanguageList& contentLangs)
2579 {
2580 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::setProperty");
2581 mike 1.1.2.1
2582 // It is not necessary to control access to the ReadWriteSem _lock here.
2583 // This method calls modifyInstance, which does its own access control.
2584
2585 //
2586 // Create the instance to pass to modifyInstance()
2587 //
2588
2589 CIMInstance instance(instanceName.getClassName());
2590 instance.addProperty(CIMProperty(propertyName, newValue));
2591 instance.setPath (instanceName);
2592
2593 //
2594 // Create the propertyList to pass to modifyInstance()
2595 //
2596
2597 Array<CIMName> propertyListArray;
2598 propertyListArray.append(propertyName);
2599 CIMPropertyList propertyList(propertyListArray);
2600
2601 //
2602 mike 1.1.2.1 // Modify the instance to set the value of the given property
2603 //
2604 modifyInstance(
2605 true,
2606 nameSpace,
2607 instance,
2608 false,
2609 propertyList,
2610 ContentLanguageList());
2611
2612 PEG_METHOD_EXIT();
2613 }
2614
2615 CIMQualifierDecl DefaultRepository::getQualifier(
2616 bool lock,
2617 const CIMNamespaceName& nameSpace,
2618 const CIMName& qualifierName)
2619 {
2620 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::getQualifier");
2621
|
2622 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2623 mike 1.1.2.1
2624 //
2625 // Get path of qualifier file:
2626 //
2627
2628 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
2629 nameSpace, qualifierName,NameSpaceRead);
2630
2631 //
2632 // Load qualifier:
2633 //
2634
2635 CIMQualifierDecl qualifierDecl;
2636
2637 try
2638 {
2639 // Check the cache first:
2640
2641 if (!_qualifierCache.get(qualifierFilePath, qualifierDecl))
2642 {
2643 // Not in cache so load from disk:
2644 mike 1.1.2.1
2645 _LoadObject(qualifierFilePath, qualifierDecl, streamer);
2646
2647 // Put in cache:
2648
2649 _qualifierCache.put(qualifierFilePath, qualifierDecl);
2650 }
2651 }
2652 catch (const CannotOpenFile&)
2653 {
2654 PEG_METHOD_EXIT();
2655 throw PEGASUS_CIM_EXCEPTION
2656 (CIM_ERR_NOT_FOUND, qualifierName.getString());
2657 }
2658
2659 PEG_METHOD_EXIT();
2660 return qualifierDecl;
2661 }
2662
2663 void DefaultRepository::setQualifier(
2664 bool lock,
2665 mike 1.1.2.1 const CIMNamespaceName& nameSpace,
2666 const CIMQualifierDecl& qualifierDecl,
2667 const ContentLanguageList& contentLangs)
2668 {
2669 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::setQualifier");
2670
|
2671 mike 1.1.2.2 WriteLock wlock(_lock, lock);
2672 AutoFileLock fileLock(_lockFile, lock);
|
2673 mike 1.1.2.1
2674 // -- Get path of qualifier file:
2675
2676 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
2677 nameSpace, qualifierDecl.getName(),NameSpaceWrite);
2678
2679 // -- If qualifier already exists, throw exception:
2680
2681 if (FileSystem::existsNoCase(qualifierFilePath))
2682 {
2683 PEG_METHOD_EXIT();
2684 throw PEGASUS_CIM_EXCEPTION(
2685 CIM_ERR_NOT_SUPPORTED, qualifierDecl.getName().getString());
2686 }
2687
2688 // -- Save qualifier:
2689
2690 Buffer qualifierDeclXml;
2691 streamer->encode(qualifierDeclXml, qualifierDecl);
2692 //XmlWriter::appendQualifierDeclElement(qualifierDeclXml, qualifierDecl);
2693 _SaveObject(qualifierFilePath, qualifierDeclXml,streamer);
2694 mike 1.1.2.1
2695 _qualifierCache.put(qualifierFilePath, (CIMQualifierDecl&)qualifierDecl);
2696
2697 PEG_METHOD_EXIT();
2698 }
2699
2700 void DefaultRepository::deleteQualifier(
2701 bool lock,
2702 const CIMNamespaceName& nameSpace,
2703 const CIMName& qualifierName)
2704 {
2705 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::deleteQualifier");
2706
|
2707 mike 1.1.2.2 WriteLock wlock(_lock, lock);
2708 AutoFileLock fileLock(_lockFile, lock);
|
2709 mike 1.1.2.1
2710 // -- Get path of qualifier file:
2711
2712 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
2713 nameSpace, qualifierName,NameSpaceDelete);
2714
2715 // -- Delete qualifier:
2716
2717 if (!FileSystem::removeFileNoCase(qualifierFilePath))
2718 {
2719 PEG_METHOD_EXIT();
2720 throw PEGASUS_CIM_EXCEPTION
2721 (CIM_ERR_NOT_FOUND, qualifierName.getString());
2722 }
2723
2724 _qualifierCache.evict(qualifierFilePath);
2725
2726 PEG_METHOD_EXIT();
2727 }
2728
2729 Array<CIMQualifierDecl> DefaultRepository::enumerateQualifiers(
2730 mike 1.1.2.1 bool lock,
2731 const CIMNamespaceName& nameSpace)
2732 {
2733 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::enumerateQualifiers");
2734
|
2735 mike 1.1.2.2 ReadLock rlock(_lock, lock);
|
2736 mike 1.1.2.1
2737 String qualifiersRoot = _nameSpaceManager.getQualifiersRoot(nameSpace);
2738
2739 Array<String> qualifierNames;
2740
2741 if (!FileSystem::getDirectoryContents(qualifiersRoot, qualifierNames))
2742 {
2743 PEG_METHOD_EXIT();
2744 String str ="enumerateQualifiers()";
2745 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
2746 mike 1.1.2.2 MessageLoaderParms("Repository.CIMRepository.INTERNAL_ERROR",
|
2747 mike 1.1.2.1 "$0: internal error",
2748 str));
2749 }
2750
2751 Array<CIMQualifierDecl> qualifiers;
2752
2753 for (Uint32 i = 0; i < qualifierNames.size(); i++)
2754 {
2755 #ifdef PEGASUS_REPOSITORY_ESCAPE_UTF8
2756 // All chars above 0x7F will be escape.
2757 CIMQualifierDecl qualifier = getQualifier(false, nameSpace,
2758 escapeStringDecoder(qualifierNames[i]));
2759 #else
2760 CIMQualifierDecl qualifier = getQualifier( false, nameSpace,
2761 qualifierNames[i]);
2762 #endif
2763 qualifiers.append(qualifier);
2764 }
2765
2766 PEG_METHOD_EXIT();
2767 return qualifiers;
2768 mike 1.1.2.1 }
2769
2770 void DefaultRepository::createNameSpace(
2771 bool lock,
2772 const CIMNamespaceName& nameSpace,
2773 const NameSpaceAttributes& attributes)
2774 {
2775 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::createNameSpace");
2776
|
2777 mike 1.1.2.2 WriteLock wlock(_lock, lock);
2778 AutoFileLock fileLock(_lockFile, lock);
|
2779 mike 1.1.2.1 _nameSpaceManager.createNameSpace(nameSpace, attributes);
2780
2781 PEG_METHOD_EXIT();
2782 }
2783
2784 void DefaultRepository::modifyNameSpace(
2785 bool lock,
2786 const CIMNamespaceName& nameSpace,
2787 const NameSpaceAttributes& attributes)
2788 {
2789 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::modifyNameSpace");
2790
|
2791 mike 1.1.2.2 WriteLock wlock(_lock, lock);
2792 AutoFileLock fileLock(_lockFile, lock);
|
2793 mike 1.1.2.1 _nameSpaceManager.modifyNameSpace(nameSpace, attributes);
2794
2795 PEG_METHOD_EXIT();
2796 }
2797
2798 Array<CIMNamespaceName> DefaultRepository::enumerateNameSpaces(
2799 bool lock) const
2800 {
2801 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::enumerateNameSpaces");
2802
|
2803 mike 1.1.2.2 ReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
|
2804 mike 1.1.2.1
2805 Array<CIMNamespaceName> nameSpaceNames;
2806 _nameSpaceManager.getNameSpaceNames(nameSpaceNames);
2807
2808 PEG_METHOD_EXIT();
2809 return nameSpaceNames;
2810 }
2811
2812 void DefaultRepository::deleteNameSpace(
2813 bool lock,
2814 const CIMNamespaceName& nameSpace)
2815 {
2816 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::deleteNameSpace");
2817
|
2818 mike 1.1.2.2 WriteLock wlock(_lock, lock);
2819 AutoFileLock fileLock(_lockFile, lock);
|
2820 mike 1.1.2.1 _nameSpaceManager.deleteNameSpace(nameSpace);
2821
2822 PEG_METHOD_EXIT();
2823 }
2824
2825 Boolean DefaultRepository::getNameSpaceAttributes(
2826 bool lock,
2827 const CIMNamespaceName& nameSpace,
2828 NameSpaceAttributes& attributes)
2829 {
2830 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::deleteNameSpace");
2831
|
2832 mike 1.1.2.2 ReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
|
2833 mike 1.1.2.1 attributes.clear();
2834 PEG_METHOD_EXIT();
2835 return _nameSpaceManager.getNameSpaceAttributes(nameSpace, attributes);
2836 }
2837
2838 Boolean DefaultRepository::isRemoteNameSpace(
2839 bool lock,
2840 const CIMNamespaceName& nameSpaceName,
2841 String& remoteInfo)
2842 {
2843 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::isRemoteNamespace");
|
2844 mike 1.1.2.2 ReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
|
2845 mike 1.1.2.1 PEG_METHOD_EXIT();
2846 return _nameSpaceManager.isRemoteNameSpace(nameSpaceName, remoteInfo);
2847 }
2848
2849 //----------------------------------------------------------------------
2850 //
2851 // _getInstanceIndexFilePath()
2852 //
2853 // returns the file path of the instance index file.
2854 //
2855 //----------------------------------------------------------------------
2856
2857 String DefaultRepository::_getInstanceIndexFilePath(
2858 const CIMNamespaceName& nameSpace,
2859 const CIMName& className) const
2860 {
2861 PEG_METHOD_ENTER(TRC_REPOSITORY,
2862 "DefaultRepository::_getInstanceIndexFilePath");
2863
2864 String tmp = _nameSpaceManager.getInstanceDataFileBase(
2865 nameSpace, className);
2866 mike 1.1.2.1
2867 tmp.append(".idx");
2868
2869 PEG_METHOD_EXIT();
2870 return tmp;
2871 }
2872
2873 //----------------------------------------------------------------------
2874 //
2875 // _getInstanceDataFilePath()
2876 //
2877 // returns the file path of the instance file.
2878 //
2879 //----------------------------------------------------------------------
2880
2881 String DefaultRepository::_getInstanceDataFilePath(
2882 const CIMNamespaceName& nameSpace,
2883 const CIMName& className) const
2884 {
2885 PEG_METHOD_ENTER(
2886 TRC_REPOSITORY, "DefaultRepository::_getInstanceDataFilePath");
2887 mike 1.1.2.1
2888 String tmp = _nameSpaceManager.getInstanceDataFileBase(
2889 nameSpace, className);
2890 tmp.append(".instances");
2891
2892 PEG_METHOD_EXIT();
2893 return tmp;
2894 }
2895
2896 Boolean DefaultRepository::_loadInstance(
2897 const String& path,
2898 CIMInstance& object,
2899 Uint32 index,
2900 Uint32 size)
2901 {
2902 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::_loadInstance");
2903
2904 //
2905 // Load instance (in XML) from instance file into memory:
2906 //
2907
2908 mike 1.1.2.1 Buffer data;
2909
2910 if (!InstanceDataFile::loadInstance(path, index, size, data))
2911 {
2912 PEG_METHOD_EXIT();
2913 return false;
2914 }
2915
2916 //
2917 // Convert XML into an actual object:
2918 //
2919
2920 streamer->decode(data, 0, object);
2921 //XmlParser parser((char*)data.getData());
2922 //XmlReader::getObject(parser, object);
2923
2924 PEG_METHOD_EXIT();
2925 return true;
2926 }
2927
2928 void DefaultRepository::setDeclContext(
2929 mike 1.1.2.1 bool lock,
2930 RepositoryDeclContext* context)
2931 {
2932 PEG_METHOD_ENTER(TRC_REPOSITORY, "DefaultRepository::setDeclContext");
2933
|
2934 mike 1.1.2.2 WriteLock wlock(_lock, lock);
2935 AutoFileLock fileLock(_lockFile, lock);
|
2936 mike 1.1.2.1 _context = context;
2937
2938 PEG_METHOD_EXIT();
2939 }
2940
2941 #ifdef PEGASUS_DEBUG
2942 void DefaultRepository::DisplayCacheStatistics(
2943 bool lock)
2944 {
2945 #ifdef PEGASUS_USE_CLASS_CACHE
2946 cout << "Repository Class Cache Statistics:" << endl;
2947 _classCache.DisplayCacheStatistics();
2948 #endif
2949 cout << "Repository Qualifier Cache Statistics:" << endl;
2950 _qualifierCache.DisplayCacheStatistics();
2951 }
2952 #endif
2953
2954 void DefaultRepository::getSubClassNames(
2955 bool lock,
2956 const CIMNamespaceName& nameSpaceName,
2957 mike 1.1.2.1 const CIMName& className,
2958 Boolean deepInheritance,
2959 Array<CIMName>& subClassNames) const
2960 {
|
2961 mike 1.1.2.2 ReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
|
2962 mike 1.1.2.1 _nameSpaceManager.getSubClassNames(nameSpaceName,
2963 className,
2964 deepInheritance,
2965 subClassNames);
2966 }
2967
2968 /** Get the names of all superclasses (direct and indirect) of this
2969 class.
2970 */
2971 void DefaultRepository::getSuperClassNames(
2972 bool lock,
2973 const CIMNamespaceName& nameSpaceName,
2974 const CIMName& className,
2975 Array<CIMName>& superClassNames) const
2976 {
|
2977 mike 1.1.2.2 ReadLock rlock(const_cast<ReadWriteSem&>(_lock), lock);
|
2978 mike 1.1.2.1 _nameSpaceManager.getSuperClassNames(
2979 nameSpaceName, className, superClassNames);
2980 }
2981
2982 PEGASUS_NAMESPACE_END
|