1 mike 1.48 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.48 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
|
25 mike 1.51 // Modified By: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
26 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
27 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
28 mike 1.48 //
29 //%/////////////////////////////////////////////////////////////////////////////
30
|
31 mike 1.51 #include <Pegasus/Common/Config.h>
|
32 mike 1.48 #include <cctype>
33 #include <cstdio>
34 #include <fstream>
35 #include <Pegasus/Common/Pair.h>
36 #include <Pegasus/Common/Destroyer.h>
37 #include <Pegasus/Common/FileSystem.h>
38 #include <Pegasus/Common/Exception.h>
39 #include <Pegasus/Common/XmlReader.h>
40 #include <Pegasus/Common/XmlWriter.h>
41 #include <Pegasus/Common/DeclContext.h>
42 #include <Pegasus/Common/DeclContext.h>
43 #include <Pegasus/Common/System.h>
|
44 kumpf 1.52 #include <Pegasus/Common/Tracer.h>
|
45 kumpf 1.63 #include <Pegasus/Common/PegasusVersion.h>
46
|
47 mike 1.48 #include "CIMRepository.h"
48 #include "RepositoryDeclContext.h"
49 #include "InstanceIndexFile.h"
|
50 mike 1.53 #include "InstanceDataFile.h"
|
51 mike 1.48 #include "AssocInstTable.h"
52 #include "AssocClassTable.h"
53
54 #define INDENT_XML_FILES
55
56 PEGASUS_USING_STD;
57
58 PEGASUS_NAMESPACE_BEGIN
59
|
60 mike 1.53 static const Uint32 _MAX_FREE_COUNT = 16;
61
|
62 mike 1.48 ////////////////////////////////////////////////////////////////////////////////
63 //
64 // _LoadObject()
65 //
|
66 mike 1.51 // Loads objects (classes and qualifiers) from disk to
67 // memory objects.
|
68 mike 1.48 //
69 ////////////////////////////////////////////////////////////////////////////////
70
71 template<class Object>
72 void _LoadObject(
73 const String& path,
74 Object& object)
75 {
|
76 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_LoadObject");
77
|
78 mike 1.48 // Get the real path of the file:
79
80 String realPath;
81
82 if (!FileSystem::existsNoCase(path, realPath))
|
83 kumpf 1.61 {
84 String traceString = path + " does not exists.";
85 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, traceString);
|
86 kumpf 1.58 PEG_METHOD_EXIT();
|
87 mike 1.51 throw CannotOpenFile(path);
|
88 kumpf 1.58 }
|
89 mike 1.48
|
90 kumpf 1.61 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "realpath = " + realPath);
91
|
92 mike 1.48 // Load file into memory:
93
94 Array<Sint8> data;
95 FileSystem::loadFileToMemory(data, realPath);
96 data.append('\0');
97
98 XmlParser parser((char*)data.getData());
99
100 XmlReader::getObject(parser, object);
|
101 kumpf 1.58
102 PEG_METHOD_EXIT();
|
103 mike 1.48 }
104
105 ////////////////////////////////////////////////////////////////////////////////
106 //
107 // _SaveObject()
108 //
|
109 mike 1.51 // Saves objects (classes and qualifiers) from memory to
110 // disk files.
|
111 mike 1.48 //
112 ////////////////////////////////////////////////////////////////////////////////
113
114 template<class Object>
115 void _SaveObject(const String& path, const Object& object)
116 {
|
117 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_SaveObject");
118
|
119 mike 1.48 Array<Sint8> out;
120 object.toXml(out);
121
122 ArrayDestroyer<char> destroyer(path.allocateCString());
123 PEGASUS_STD(ofstream) os(destroyer.getPointer() PEGASUS_IOS_BINARY);
124
125 if (!os)
|
126 kumpf 1.58 {
127 PEG_METHOD_EXIT();
|
128 mike 1.51 throw CannotOpenFile(path);
|
129 kumpf 1.58 }
|
130 mike 1.48
131 #ifdef INDENT_XML_FILES
132 out.append('\0');
133 XmlWriter::indentedPrint(os, out.getData(), 2);
134 #else
135 os.write((char*)out.getData(), out.size());
136 #endif
|
137 kumpf 1.58
138 PEG_METHOD_EXIT();
|
139 mike 1.48 }
140
141 static String _MakeAssocInstPath(
142 const String& nameSpace,
143 const String& repositoryRoot)
144 {
|
145 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_MakeAssocInstPath");
146
|
147 mike 1.48 String tmp = nameSpace;
148 tmp.translate('/', '#');
|
149 kumpf 1.58
|
150 kumpf 1.64 String returnString(repositoryRoot);
151 returnString.append('/');
152 returnString.append(tmp);
153 returnString.append("/instances/associations");
154
|
155 kumpf 1.58 PEG_METHOD_EXIT();
|
156 kumpf 1.64 return returnString;
|
157 mike 1.48 }
158
159 static String _MakeAssocClassPath(
160 const String& nameSpace,
161 const String& repositoryRoot)
162 {
|
163 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_MakeAssocClassPath");
164
|
165 mike 1.48 String tmp = nameSpace;
166 tmp.translate('/', '#');
|
167 kumpf 1.58
|
168 kumpf 1.64 String returnString(repositoryRoot);
169 returnString.append('/');
170 returnString.append(tmp);
171 returnString.append("/classes/associations");
172
|
173 kumpf 1.58 PEG_METHOD_EXIT();
|
174 kumpf 1.64 return returnString;
|
175 mike 1.48 }
176
177 ////////////////////////////////////////////////////////////////////////////////
178 //
179 // CIMRepository
180 //
181 // The following are not implemented:
182 //
183 // CIMRepository::execQuery()
184 // CIMRepository::referencesNames()
185 // CIMRepository::invokeMethod()
186 //
187 // Note that invokeMethod() will not never implemented since it is not
188 // meaningful for a repository.
189 //
190 // ATTN: make operations on files non-case-sensitive.
191 //
192 ////////////////////////////////////////////////////////////////////////////////
193
194 CIMRepository::CIMRepository(const String& repositoryRoot)
|
195 mike 1.51 : _repositoryRoot(repositoryRoot), _nameSpaceManager(repositoryRoot),
|
196 kumpf 1.56 _lock(), _resolveInstance(true)
|
197 mike 1.48 {
|
198 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::CIMRepository");
199
|
200 mike 1.48 _context = new RepositoryDeclContext(this);
|
201 mike 1.51 _isDefaultInstanceProvider = (ConfigManager::getInstance()->getCurrentValue(
202 "repositoryIsDefaultInstanceProvider") == "true");
|
203 kumpf 1.58
204 PEG_METHOD_EXIT();
|
205 mike 1.48 }
206
207 CIMRepository::~CIMRepository()
208 {
|
209 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::~CIMRepository");
210
|
211 mike 1.48 delete _context;
|
212 kumpf 1.58
213 PEG_METHOD_EXIT();
|
214 mike 1.48 }
215
|
216 mike 1.51
217 void CIMRepository::read_lock(void) throw(IPCException)
218 {
|
219 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::read_lock");
220
|
221 mike 1.51 _lock.wait_read(pegasus_thread_self());
|
222 kumpf 1.58
223 PEG_METHOD_EXIT();
|
224 mike 1.51 }
225
226 void CIMRepository::read_unlock(void)
227 {
|
228 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::read_unlock");
229
|
230 mike 1.51 _lock.unlock_read(pegasus_thread_self());
|
231 kumpf 1.58
232 PEG_METHOD_EXIT();
|
233 mike 1.51 }
234
235 void CIMRepository::write_lock(void) throw(IPCException)
236 {
|
237 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::write_lock");
238
|
239 mike 1.51 _lock.wait_write(pegasus_thread_self());
|
240 kumpf 1.58
241 PEG_METHOD_EXIT();
|
242 mike 1.51 }
243
244 void CIMRepository::write_unlock(void)
245 {
|
246 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::write_unlock");
247
|
248 mike 1.51 _lock.unlock_write(pegasus_thread_self());
|
249 kumpf 1.58
250 PEG_METHOD_EXIT();
|
251 mike 1.51 }
252
|
253 mike 1.48 CIMClass CIMRepository::getClass(
254 const String& nameSpace,
255 const String& className,
256 Boolean localOnly,
257 Boolean includeQualifiers,
258 Boolean includeClassOrigin,
|
259 mike 1.51 const CIMPropertyList& propertyList)
|
260 mike 1.48 {
|
261 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getClass");
262
|
263 kumpf 1.61 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4, "nameSpace = " +
264 nameSpace + ", className = " + className);
265
|
266 mike 1.48 // ATTN: localOnly, includeQualifiers, and includeClassOrigin are ignored
267 // for now.
268
|
269 mike 1.51
270
|
271 mike 1.48 String classFilePath;
272 classFilePath = _nameSpaceManager.getClassFilePath(nameSpace, className);
273
274 CIMClass cimClass;
|
275 mike 1.51
276 try
277 {
278 _LoadObject(classFilePath, cimClass);
279 }
|
280 mike 1.53 catch (Exception&)
|
281 mike 1.51 {
|
282 kumpf 1.58 PEG_METHOD_EXIT();
|
283 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, className);
284 }
|
285 mike 1.48
|
286 kumpf 1.58 PEG_METHOD_EXIT();
|
287 mike 1.48 return cimClass;
288 }
289
290 Boolean CIMRepository::_getInstanceIndex(
291 const String& nameSpace,
292 const CIMReference& instanceName,
293 String& className,
|
294 mike 1.53 Uint32& index,
|
295 mike 1.51 Uint32& size,
|
296 mike 1.48 Boolean searchSuperClasses) const
297 {
|
298 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstanceIndex");
299
|
300 mike 1.53 //
301 // Get all descendent classes of this class:
302 //
|
303 mike 1.51
|
304 mike 1.48 className = instanceName.getClassName();
305
306 Array<String> classNames;
307 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
308 classNames.prepend(className);
309
|
310 mike 1.53 //
311 // Get all superclasses of this one:
312 //
|
313 mike 1.48
314 if (searchSuperClasses)
|
315 mike 1.51 _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);
|
316 mike 1.48
|
317 mike 1.53 //
318 // Get instance names from each qualifying instance file for the class:
319 //
|
320 mike 1.48
321 for (Uint32 i = 0; i < classNames.size(); i++)
322 {
|
323 mike 1.51 CIMReference tmpInstanceName = instanceName;
324 tmpInstanceName.setClassName(classNames[i]);
|
325 mike 1.48
|
326 mike 1.53 //
327 // Lookup index of instance:
328 //
|
329 mike 1.48
|
330 mike 1.53 String path = _getInstanceIndexFilePath(nameSpace, classNames[i]);
|
331 mike 1.48
|
332 mike 1.53 if (InstanceIndexFile::lookupEntry(path, tmpInstanceName, index, size))
|
333 mike 1.51 {
334 className = classNames[i];
|
335 kumpf 1.58 PEG_METHOD_EXIT();
|
336 mike 1.51 return true;
337 }
|
338 mike 1.48 }
339
|
340 kumpf 1.58 PEG_METHOD_EXIT();
|
341 mike 1.48 return false;
342 }
343
344 CIMInstance CIMRepository::getInstance(
345 const String& nameSpace,
346 const CIMReference& instanceName,
347 Boolean localOnly,
348 Boolean includeQualifiers,
349 Boolean includeClassOrigin,
|
350 mike 1.55 const CIMPropertyList& propertyList)
|
351 mike 1.48 {
|
352 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getInstance");
353
|
354 mike 1.53 //
355 // Get the index for this instance:
356 //
|
357 mike 1.48
358 String className;
359 Uint32 index;
|
360 mike 1.51 Uint32 size;
361
|
362 mike 1.53 if (!_getInstanceIndex(nameSpace, instanceName, className, index, size))
|
363 mike 1.48 {
|
364 kumpf 1.52 PEG_METHOD_EXIT();
|
365 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
|
366 mike 1.48 }
367
|
368 mike 1.53 //
369 // Load the instance from file:
370 //
|
371 mike 1.48
|
372 mike 1.53 String path = _getInstanceDataFilePath(nameSpace, className);
|
373 mike 1.48 CIMInstance cimInstance;
|
374 mike 1.53
|
375 mike 1.51 if (!_loadInstance(path, cimInstance, index, size))
376 {
|
377 kumpf 1.52 PEG_METHOD_EXIT();
|
378 mike 1.51 throw CannotOpenFile(path);
379 }
380
|
381 mike 1.54 //
382 // Resolve the instance (if requested):
383 //
384
385 if (_resolveInstance)
386 {
387 CIMConstClass cimClass;
388 cimInstance.resolve(_context, nameSpace, cimClass, true);
389 }
390
|
391 kumpf 1.52 PEG_METHOD_EXIT();
|
392 mike 1.48 return cimInstance;
393 }
394
395 void CIMRepository::deleteClass(
396 const String& nameSpace,
397 const String& className)
398 {
|
399 kumpf 1.61 PEG_METHOD_ENTER(TRC_REPOSITORY,"CIMRepository::deleteClass");
|
400 kumpf 1.58
|
401 mike 1.53 //
402 // Get the class and check to see if it is an association class:
403 //
|
404 mike 1.51
|
405 mike 1.48 CIMClass cimClass = getClass(nameSpace, className, false);
406 Boolean isAssociation = cimClass.isAssociation();
407
|
408 mike 1.53 //
409 // Disallow deletion if class has instances:
410 //
|
411 mike 1.48
|
412 mike 1.53 String indexFilePath = _getInstanceIndexFilePath(nameSpace, className);
|
413 kumpf 1.61 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
414 "instance indexFilePath = " + indexFilePath);
|
415 mike 1.53
416 String dataFilePath = _getInstanceDataFilePath(nameSpace, className);
|
417 kumpf 1.61 PEG_TRACE_STRING(TRC_REPOSITORY, Tracer::LEVEL4,
418 "instance dataFilePath = " + dataFilePath);
|
419 mike 1.48
|
420 mike 1.53 if (InstanceIndexFile::hasNonFreeEntries(indexFilePath))
|
421 kumpf 1.58 {
422 PEG_METHOD_EXIT();
|
423 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_CLASS_HAS_INSTANCES, className);
|
424 kumpf 1.58 }
|
425 mike 1.48
|
426 mike 1.53 //
427 // Delete the class. The NameSpaceManager::deleteClass() method throws
428 // and exception if the class has sublclasses.
429 //
|
430 kumpf 1.58 try
431 {
432 _nameSpaceManager.deleteClass(nameSpace, className);
433 }
434 catch (CIMException& e)
435 {
436 PEG_METHOD_EXIT();
437 throw e;
438 }
|
439 mike 1.48
|
440 mike 1.53 FileSystem::removeFileNoCase(indexFilePath);
|
441 kumpf 1.61
|
442 mike 1.53 FileSystem::removeFileNoCase(dataFilePath);
443
444 //
445 // Kill off empty instance files:
446 //
447
448 //
449 // Remove association:
450 //
|
451 mike 1.48
452 if (isAssociation)
453 {
|
454 mike 1.51 String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
|
455 mike 1.48
|
456 mike 1.51 if (FileSystem::exists(assocFileName))
457 AssocClassTable::deleteAssociation(assocFileName, className);
|
458 mike 1.48 }
|
459 kumpf 1.61
|
460 kumpf 1.58 PEG_METHOD_EXIT();
|
461 mike 1.48 }
462
|
463 mike 1.53 void _CompactInstanceRepository(
464 const String& indexFilePath,
465 const String& dataFilePath)
466 {
|
467 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_CompactInstanceRepository");
468
|
469 mike 1.53 //
470 // Compact the data file first:
471 //
472
473 Array<Uint32> freeFlags;
474 Array<Uint32> indices;
475 Array<Uint32> sizes;
476 Array<CIMReference> instanceNames;
477
478 if (!InstanceIndexFile::enumerateEntries(
479 indexFilePath, freeFlags, indices, sizes, instanceNames, true))
480 {
|
481 kumpf 1.58 PEG_METHOD_EXIT();
|
482 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "compact failed");
483 }
484
485 if (!InstanceDataFile::compact(dataFilePath, freeFlags, indices, sizes))
|
486 kumpf 1.58 {
487 PEG_METHOD_EXIT();
|
488 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "compact failed");
|
489 kumpf 1.58 }
|
490 mike 1.53
491 //
492 // Now compact the index file:
493 //
494
495 if (!InstanceIndexFile::compact(indexFilePath))
|
496 kumpf 1.58 {
497 PEG_METHOD_EXIT();
|
498 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "compact failed");
|
499 kumpf 1.58 }
500
501 PEG_METHOD_EXIT();
|
502 mike 1.53 }
503
|
504 mike 1.48 void CIMRepository::deleteInstance(
505 const String& nameSpace,
506 const CIMReference& instanceName)
507 {
|
508 mike 1.53 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteInstance");
|
509 mike 1.51
510 String errMessage;
511
|
512 mike 1.53 //
513 // Get paths of index and data files:
514 //
515
516 String indexFilePath = _getInstanceIndexFilePath(
517 nameSpace, instanceName.getClassName());
|
518 mike 1.48
|
519 mike 1.53 String dataFilePath = _getInstanceDataFilePath(
|
520 mike 1.51 nameSpace, instanceName.getClassName());
|
521 mike 1.48
|
522 mike 1.53 //
523 // Attempt rollback (if there are no rollback files, this will have no
524 // effect). This code is here to rollback uncommitted changes left over
525 // from last time an instance-oriented function was called.
526 //
527
528 if (!InstanceIndexFile::rollbackTransaction(indexFilePath))
529 {
530 PEG_METHOD_EXIT();
531 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
532 }
533
534 if (!InstanceDataFile::rollbackTransaction(dataFilePath))
535 {
536 PEG_METHOD_EXIT();
537 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
538 }
539
540 //
541 // Lookup instance from the index file (raise error if not found).
542 //
543 mike 1.53
|
544 mike 1.48 Uint32 index;
|
545 mike 1.51 Uint32 size;
|
546 mike 1.48
|
547 mike 1.53 if (!InstanceIndexFile::lookupEntry(
548 indexFilePath, instanceName, index, size))
|
549 kumpf 1.52 {
550 PEG_METHOD_EXIT();
|
551 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
|
552 kumpf 1.52 }
|
553 mike 1.48
|
554 mike 1.53 //
555 // Begin the transaction (any return prior to commit will cause
556 // a rollback next time an instance-oriented routine is invoked).
557 //
558
559 if (!InstanceIndexFile::beginTransaction(indexFilePath))
560 {
561 PEG_METHOD_EXIT();
562 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
563 }
|
564 mike 1.48
|
565 mike 1.53 if (!InstanceDataFile::beginTransaction(dataFilePath))
|
566 mike 1.48 {
|
567 kumpf 1.52 PEG_METHOD_EXIT();
|
568 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
|
569 mike 1.48 }
570
|
571 mike 1.53 //
572 // Remove entry from index file.
573 //
|
574 mike 1.48
|
575 mike 1.53 Uint32 freeCount;
|
576 mike 1.48
|
577 mike 1.53 if (!InstanceIndexFile::deleteEntry(indexFilePath, instanceName, freeCount))
|
578 mike 1.48 {
|
579 mike 1.53 errMessage.append("Failed to delete instance: ");
|
580 mike 1.51 errMessage.append(instanceName.toString());
|
581 kumpf 1.52 PEG_METHOD_EXIT();
|
582 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
|
583 mike 1.48 }
584
|
585 mike 1.53 //
586 // Commit the transaction:
587 //
|
588 mike 1.51
|
589 mike 1.53 if (!InstanceIndexFile::commitTransaction(indexFilePath))
590 {
591 PEG_METHOD_EXIT();
592 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
593 }
594
595 if (!InstanceDataFile::commitTransaction(dataFilePath))
|
596 mike 1.48 {
|
597 kumpf 1.52 PEG_METHOD_EXIT();
|
598 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
|
599 mike 1.48 }
600
|
601 mike 1.53 //
602 // Compact the index and data files if the free count max was
603 // reached.
604 //
605
606 if (freeCount == _MAX_FREE_COUNT)
607 _CompactInstanceRepository(indexFilePath, dataFilePath);
608
609 //
610 // Delete from assocation table (if an assocation).
611 //
|
612 mike 1.48
613 String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
614
615 if (FileSystem::exists(assocFileName))
|
616 mike 1.51 AssocInstTable::deleteAssociation(assocFileName, instanceName);
|
617 kumpf 1.52
618 PEG_METHOD_EXIT();
|
619 mike 1.48 }
620
621 void CIMRepository::_createAssocClassEntries(
622 const String& nameSpace,
623 const CIMConstClass& assocClass)
624 {
|
625 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createAssocClassEntries");
626
|
627 mike 1.48 // Open input file:
628
|
629 mike 1.51
|
630 mike 1.48 String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
631 ofstream os;
632
633 if (!OpenAppend(os, assocFileName))
|
634 kumpf 1.58 {
635 PEG_METHOD_EXIT();
|
636 mike 1.51 throw CannotOpenFile(assocFileName);
|
637 kumpf 1.58 }
|
638 mike 1.48
639 // Get the association's class name:
640
641 String assocClassName = assocClass.getClassName();
642
643 // For each property:
644
645 Uint32 n = assocClass.getPropertyCount();
646
647 for (Uint32 i = 0; i < n; i++)
648 {
|
649 mike 1.51 CIMConstProperty fromProp = assocClass.getProperty(i);
|
650 mike 1.48
|
651 mike 1.51 if (fromProp.getType() == CIMType::REFERENCE)
652 {
653 for (Uint32 j = 0; j < n; j++)
654 {
655 CIMConstProperty toProp = assocClass.getProperty(j);
656
657 if (toProp.getType() == CIMType::REFERENCE &&
658 fromProp.getName() != toProp.getName())
659 {
660 String fromClassName = fromProp.getReferenceClassName();
661 String fromPropertyName = fromProp.getName();
662 String toClassName = toProp.getReferenceClassName();
663 String toPropertyName = toProp.getName();
664
665 AssocClassTable::append(
666 os,
667 assocClassName,
668 fromClassName,
669 fromPropertyName,
670 toClassName,
671 toPropertyName);
672 mike 1.51 }
673 }
674 }
|
675 mike 1.48 }
|
676 kumpf 1.58
677 PEG_METHOD_EXIT();
|
678 mike 1.48 }
679
680 void CIMRepository::createClass(
681 const String& nameSpace,
682 const CIMClass& newClass)
683 {
|
684 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createClass");
685
|
686 mike 1.48 // -- Resolve the class:
|
687 mike 1.51 CIMClass cimClass(newClass);
688
|
689 mike 1.48 cimClass.resolve(_context, nameSpace);
690
691 // -- If an association, populate associations file:
692
693 if (cimClass.isAssociation())
|
694 mike 1.51 _createAssocClassEntries(nameSpace, cimClass);
|
695 mike 1.48
696 // -- Create namespace manager entry:
697
698 String classFilePath;
699
700 _nameSpaceManager.createClass(nameSpace, cimClass.getClassName(),
|
701 mike 1.51 cimClass.getSuperClassName(), classFilePath);
|
702 mike 1.48
703 // -- Create the class file:
704
705 _SaveObject(classFilePath, cimClass);
|
706 kumpf 1.58
707 PEG_METHOD_EXIT();
|
708 mike 1.48 }
709
710 /*------------------------------------------------------------------------------
711
712 This routine does the following:
713
|
714 mike 1.51 1. Creates two entries in the association file for each relationship
715 formed by this new assocation instance. A binary association
716 (one with two references) ties two instances together. Suppose
717 there are two instances: I1 and I2. Then two entries are created:
718
719 I2 -> I1
720 I1 -> I2
721
722 For a ternary relationship, six entries will be created. Suppose
723 there are three instances: I1, I2, and I3:
724
725 I1 -> I2
726 I1 -> I3
727 I2 -> I1
728 I2 -> I3
729 I3 -> I1
730 I3 -> I2
731
732 So for an N-ary relationship, there will be 2*N entries created.
733
734 2. Verifies that the association instance refers to real objects.
735 mike 1.51 (note that an association reference may refer to either an instance
736 or a class). Throws an exception if one of the references does not
737 refer to a valid object.
|
738 mike 1.48
739 ------------------------------------------------------------------------------*/
740
741 void CIMRepository::_createAssocInstEntries(
742 const String& nameSpace,
743 const CIMConstClass& cimClass,
744 const CIMInstance& cimInstance,
745 const CIMReference& instanceName)
746 {
|
747 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_createAssocInstEntries");
748
|
749 mike 1.48 // Open input file:
750
751 String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
752 ofstream os;
753
754 if (!OpenAppend(os, assocFileName))
|
755 kumpf 1.58 {
756 PEG_METHOD_EXIT();
|
757 mike 1.51 throw CannotOpenFile(assocFileName);
|
758 kumpf 1.58 }
|
759 mike 1.48
760 // Get the association's instance name and class name:
761
762 String assocInstanceName = instanceName.toString();
763 String assocClassName = instanceName.getClassName();
764
765 // For each property:
766
767 for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)
768 {
|
769 mike 1.51 CIMConstProperty fromProp = cimInstance.getProperty(i);
|
770 mike 1.48
|
771 mike 1.51 // If a reference property:
|
772 mike 1.48
|
773 mike 1.51 if (fromProp.getType() == CIMType::REFERENCE)
774 {
775 // For each property:
776
777 for (Uint32 j = 0, n = cimInstance.getPropertyCount(); j < n; j++)
778 {
779 CIMConstProperty toProp = cimInstance.getProperty(j);
780
781 // If a reference property and not the same property:
782
783 if (toProp.getType() == CIMType::REFERENCE &&
784 fromProp.getName() != toProp.getName())
785 {
786 CIMReference fromRef;
787 fromProp.getValue().get(fromRef);
788
789 CIMReference toRef;
790 toProp.getValue().get(toRef);
791
792 String fromObjectName = fromRef.toString();
793 String fromClassName = fromRef.getClassName();
794 mike 1.51 String fromPropertyName = fromProp.getName();
795 String toObjectName = toRef.toString();
796 String toClassName = toRef.getClassName();
797 String toPropertyName = toProp.getName();
798
799 AssocInstTable::append(
800 os,
801 assocInstanceName,
802 assocClassName,
803 fromObjectName,
804 fromClassName,
805 fromPropertyName,
806 toObjectName,
807 toClassName,
808 toPropertyName);
809 }
810 }
811 }
|
812 mike 1.48 }
|
813 kumpf 1.58
814 PEG_METHOD_EXIT();
|
815 mike 1.48 }
816
|
817 mike 1.51 CIMReference CIMRepository::createInstance(
|
818 mike 1.48 const String& nameSpace,
819 const CIMInstance& newInstance)
820 {
|
821 kumpf 1.61 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createInstance");
|
822 mike 1.51
823 String errMessage;
824
|
825 mike 1.53 //
826 // Get paths to data and index files:
827 //
828
829 String dataFilePath = _getInstanceDataFilePath(
830 nameSpace, newInstance.getClassName());
831
832 String indexFilePath = _getInstanceIndexFilePath(
833 nameSpace, newInstance.getClassName());
834
835 //
836 // Attempt rollback (if there are no rollback files, this will have no
837 // effect). This code is here to rollback uncommitted changes left over
838 // from last time an instance-oriented function was called.
839 //
840
841 if (!InstanceIndexFile::rollbackTransaction(indexFilePath))
842 {
843 PEG_METHOD_EXIT();
844 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
845 }
846 mike 1.53
847 if (!InstanceDataFile::rollbackTransaction(dataFilePath))
848 {
849 PEG_METHOD_EXIT();
850 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
851 }
852
853 //
|
854 mike 1.54 // Resolve the instance. Looks up class and fills out properties but
855 // not the qualifiers.
|
856 mike 1.53 //
857
|
858 mike 1.51 CIMInstance cimInstance(newInstance);
|
859 mike 1.48 CIMConstClass cimClass;
|
860 mike 1.54 cimInstance.resolve(_context, nameSpace, cimClass, false);
|
861 mike 1.48 CIMReference instanceName = cimInstance.getInstanceName(cimClass);
862
|
863 mike 1.53 //
864 // Make sure the class has keys (otherwise it will be impossible to
865 // create the instance).
866 //
|
867 mike 1.48
868 if (!cimClass.hasKeys())
869 {
|
870 mike 1.51 errMessage = "class has no keys: ";
871 errMessage += cimClass.getClassName();
|
872 kumpf 1.52 PEG_METHOD_EXIT();
|
873 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
|
874 mike 1.48 }
875
|
876 mike 1.53 //
877 // Be sure instance does not already exist:
878 //
|
879 mike 1.48
880 String className;
881 Uint32 dummyIndex;
|
882 mike 1.51 Uint32 dummySize;
|
883 mike 1.48
|
884 mike 1.53 if (_getInstanceIndex(nameSpace, instanceName, className, dummyIndex,
885 dummySize, true))
|
886 mike 1.48 {
|
887 kumpf 1.52 PEG_METHOD_EXIT();
|
888 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS,
889 instanceName.toString());
|
890 mike 1.48 }
891
|
892 mike 1.53 //
893 // Create association entries if an association instance.
894 //
|
895 mike 1.48
896 if (cimClass.isAssociation())
|
897 mike 1.53 _createAssocInstEntries(nameSpace, cimClass, cimInstance, instanceName);
898
899 //
900 // Begin the transaction (any return prior to commit will cause
901 // a rollback next time an instance-oriented routine is invoked).
902 //
903
904 if (!InstanceIndexFile::beginTransaction(indexFilePath))
|
905 mike 1.48 {
|
906 mike 1.53 PEG_METHOD_EXIT();
907 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
|
908 mike 1.48 }
909
|
910 mike 1.53 if (!InstanceDataFile::beginTransaction(dataFilePath))
911 {
912 PEG_METHOD_EXIT();
913 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
914 }
|
915 mike 1.48
|
916 mike 1.53 //
917 // Save instance to file:
918 //
|
919 mike 1.51
920 Uint32 index;
921 Uint32 size;
|
922 mike 1.53
|
923 mike 1.51 {
|
924 mike 1.53 Array<Sint8> data;
925 cimInstance.toXml(data);
926 size = data.size();
927
928 if (!InstanceDataFile::appendInstance(dataFilePath, data, index))
929 {
930 errMessage.append("Failed to create instance: ");
931 errMessage.append(instanceName.toString());
932 PEG_METHOD_EXIT();
933 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
934 }
935 }
936
937 //
938 // Create entry in index file:
939 //
940
941 if (!InstanceIndexFile::createEntry(
942 indexFilePath, instanceName, index, size))
943 {
944 errMessage.append("Failed to create instance: ");
|
945 mike 1.51 errMessage.append(instanceName.toString());
|
946 kumpf 1.52 PEG_METHOD_EXIT();
|
947 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
948 }
|
949 mike 1.48
|
950 mike 1.53 //
951 // Commit the changes:
952 //
|
953 mike 1.48
|
954 mike 1.53 if (!InstanceIndexFile::commitTransaction(indexFilePath))
|
955 mike 1.51 {
|
956 kumpf 1.52 PEG_METHOD_EXIT();
|
957 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
|
958 mike 1.51 }
|
959 mike 1.48
|
960 mike 1.53 if (!InstanceDataFile::commitTransaction(dataFilePath))
|
961 mike 1.51 {
|
962 kumpf 1.52 PEG_METHOD_EXIT();
|
963 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
|
964 mike 1.51 }
|
965 mike 1.53
|
966 mike 1.54 cimInstance.resolve(_context, nameSpace, cimClass, true);
967
|
968 kumpf 1.52 PEG_METHOD_EXIT();
|
969 mike 1.53 return instanceName;
|
970 mike 1.48 }
971
972 void CIMRepository::modifyClass(
973 const String& nameSpace,
974 const CIMClass& modifiedClass)
975 {
|
976 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyClass");
977
|
978 mike 1.53 //
979 // Resolve the class:
980 //
|
981 mike 1.51
|
982 mike 1.53 CIMClass cimClass(modifiedClass);
|
983 mike 1.48 cimClass.resolve(_context, nameSpace);
984
|
985 mike 1.53 //
986 // Check to see if it is okay to modify this class:
987 //
|
988 mike 1.48
989 String classFilePath;
990
991 _nameSpaceManager.checkModify(nameSpace, cimClass.getClassName(),
|
992 mike 1.51 cimClass.getSuperClassName(), classFilePath);
|
993 mike 1.48
|
994 mike 1.53 //
995 // ATTN: KS
996 // Disallow modification of classes which have instances (that are
997 // in the repository). And we have no idea whether the class has
998 // instances in other repositories or in providers. We should do
999 // an enumerate instance names at a higher level (above the repository).
1000 //
1001
1002 //
1003 // Delete the old file containing the class:
1004 //
|
1005 mike 1.48
1006 if (!FileSystem::removeFileNoCase(classFilePath))
1007 {
|
1008 kumpf 1.58 PEG_METHOD_EXIT();
|
1009 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
1010 "failed to remove file in CIMRepository::modifyClass()");
|
1011 mike 1.48 }
1012
|
1013 mike 1.53 //
1014 // Create new class file:
1015 //
|
1016 mike 1.48
1017 _SaveObject(classFilePath, cimClass);
|
1018 kumpf 1.58
1019 PEG_METHOD_EXIT();
|
1020 mike 1.48 }
1021
1022 void CIMRepository::modifyInstance(
1023 const String& nameSpace,
|
1024 mike 1.51 const CIMNamedInstance& modifiedInstance,
1025 Boolean includeQualifiers,
1026 const CIMPropertyList& propertyList)
|
1027 mike 1.48 {
|
1028 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::modifyInstance");
1029
|
1030 mike 1.53 //
1031 // Get paths of index and data files:
1032 //
|
1033 mike 1.51
|
1034 mike 1.53 const CIMInstance& instance = modifiedInstance.getInstance();
1035
1036 String indexFilePath = _getInstanceIndexFilePath(
1037 nameSpace, instance.getClassName());
1038
1039 String dataFilePath = _getInstanceDataFilePath(
1040 nameSpace, instance.getClassName());
1041
1042 //
1043 // First attempt rollback:
1044 //
1045
1046 if (!InstanceIndexFile::rollbackTransaction(indexFilePath))
|
1047 kumpf 1.58 {
1048 PEG_METHOD_EXIT();
|
1049 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
|
1050 kumpf 1.58 }
|
1051 mike 1.53
1052 if (!InstanceDataFile::rollbackTransaction(dataFilePath))
|
1053 kumpf 1.58 {
1054 PEG_METHOD_EXIT();
|
1055 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "rollback failed");
|
1056 kumpf 1.58 }
|
1057 mike 1.53
1058 //
1059 // Begin the transaction:
1060 //
1061
1062 if (!InstanceIndexFile::beginTransaction(indexFilePath))
|
1063 kumpf 1.58 {
1064 PEG_METHOD_EXIT();
|
1065 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
|
1066 kumpf 1.58 }
|
1067 mike 1.53
1068 if (!InstanceDataFile::beginTransaction(dataFilePath))
|
1069 kumpf 1.61 {
|
1070 kumpf 1.58 PEG_METHOD_EXIT();
|
1071 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "begin failed");
|
1072 kumpf 1.58 }
|
1073 mike 1.53
1074 //
1075 // Do this:
1076 //
|
1077 mike 1.51
1078 String errMessage;
|
1079 mike 1.53 CIMInstance cimInstance; // The instance that replaces the original
|
1080 mike 1.51
1081 if (propertyList.isNull())
1082 {
1083 //
1084 // Replace all the properties in the instance
1085 //
1086 if (includeQualifiers)
1087 {
1088 //
1089 // Replace the entire instance with the given instance
1090 // (this is the default behavior)
1091 //
1092 cimInstance = modifiedInstance.getInstance();
1093 }
1094 else
1095 {
1096 //
1097 // Replace all the properties in the instance, but keep the
1098 // original qualifiers on the instance and on the properties
1099 //
1100
|
1101 mike 1.55 _resolveInstance = false;
1102
1103 cimInstance = getInstance(
1104 nameSpace,
1105 modifiedInstance.getInstanceName(),
1106 false,
1107 true,
1108 true);
1109
1110 _resolveInstance = true;
|
1111 mike 1.54
|
1112 mike 1.51 CIMInstance newInstance(
1113 modifiedInstance.getInstanceName().getClassName());
|
1114 mike 1.54
|
1115 mike 1.51 CIMInstance givenInstance = modifiedInstance.getInstance();
1116
1117 //
1118 // Copy over the original instance qualifiers
1119 //
|
1120 mike 1.54
1121 for (Uint32 i = 0; i < cimInstance.getQualifierCount(); i++)
|
1122 mike 1.51 {
1123 newInstance.addQualifier(cimInstance.getQualifier(i));
1124 }
1125
1126 //
1127 // Loop through the properties replacing each property in the
1128 // original with a new value, but keeping the original qualifiers
1129 //
1130 for (Uint32 i=0; i<givenInstance.getPropertyCount(); i++)
1131 {
1132 // Copy the given property value (not qualifiers)
1133 CIMProperty givenProperty = givenInstance.getProperty(i);
1134 CIMProperty newProperty(
1135 givenProperty.getName(),
1136 givenProperty.getValue(),
1137 givenProperty.getArraySize(),
1138 givenProperty.getReferenceClassName(),
1139 givenProperty.getClassOrigin(),
1140 givenProperty.getPropagated());
1141
1142 // Copy the original property qualifiers
1143 mike 1.51 Uint32 origPos =
1144 cimInstance.findProperty(newProperty.getName());
1145 if (origPos != PEG_NOT_FOUND)
1146 {
1147 CIMProperty origProperty = cimInstance.getProperty(origPos);
1148 for (Uint32 j=0; j<origProperty.getQualifierCount(); j++)
1149 {
1150 newProperty.addQualifier(origProperty.getQualifier(i));
1151 }
1152 }
1153
1154 // Add the newly constructed property to the new instance
1155 newInstance.addProperty(newProperty);
1156 }
1157
1158 // Use the newly merged instance to replace the original instance
1159 cimInstance = newInstance;
1160 }
1161 }
1162 else
1163 {
1164 mike 1.51 //
1165 // Replace only the properties specified in the given instance
1166 //
1167
|
1168 mike 1.55 _resolveInstance = false;
1169
|
1170 mike 1.51 cimInstance = getInstance(nameSpace,
|
1171 mike 1.55 modifiedInstance.getInstanceName(), false, true, true);
1172
1173 _resolveInstance = true;
1174
|
1175 mike 1.51 CIMInstance givenInstance = modifiedInstance.getInstance();
1176
1177 // NOTE: Instance qualifiers are not changed when a property list
1178 // is specified. Property qualifiers are replaced with the
1179 // corresponding property values.
1180
1181 //
1182 // Loop through the propertyList replacing each property in the original
1183 //
|
1184 mike 1.53
|
1185 mike 1.51 for (Uint32 i=0; i<propertyList.getNumProperties(); i++)
1186 {
1187 Uint32 origPropPos =
1188 cimInstance.findProperty(propertyList.getPropertyName(i));
1189 if (origPropPos != PEG_NOT_FOUND)
1190 {
1191 // Case: Property set in original
1192 CIMProperty origProperty =
1193 cimInstance.getProperty(origPropPos);
1194
1195 // Get the given property value
1196 Uint32 givenPropPos =
1197 givenInstance.findProperty(propertyList.getPropertyName(i));
1198 if (givenPropPos != PEG_NOT_FOUND)
1199 {
1200 // Case: Property set in original and given
1201 CIMProperty givenProperty =
1202 givenInstance.getProperty(givenPropPos);
1203
1204 // Copy over the property from the given to the original
1205 if (includeQualifiers)
1206 mike 1.51 {
1207 // Case: Total property replacement
1208 cimInstance.removeProperty(origPropPos);
1209 cimInstance.addProperty(givenProperty);
1210 }
1211 else
1212 {
1213 // Case: Replace only the property value (not quals)
1214 origProperty.setValue(givenProperty.getValue());
1215 cimInstance.removeProperty(origPropPos);
1216 cimInstance.addProperty(origProperty);
1217 }
1218 }
1219 else
1220 {
1221 // Case: Property set in original and not in given
1222 // Just remove the property (set to null)
1223 cimInstance.removeProperty(origPropPos);
1224 }
1225 }
1226 else
1227 mike 1.51 {
1228 // Case: Property not set in original
1229
1230 // Get the given property value
1231 Uint32 givenPropPos =
1232 givenInstance.findProperty(propertyList.getPropertyName(i));
1233 if (givenPropPos != PEG_NOT_FOUND)
1234 {
1235 // Case: Property set in given and not in original
1236 CIMProperty givenProperty =
1237 givenInstance.getProperty(givenPropPos);
1238
1239 // Copy over the property from the given to the original
1240 if (includeQualifiers)
1241 {
1242 // Case: Total property copy
1243 cimInstance.addProperty(givenProperty);
1244 }
1245 else
1246 {
1247 // Case: Copy only the property value (not qualifiers)
1248 mike 1.51 CIMProperty newProperty(
1249 givenProperty.getName(),
1250 givenProperty.getValue(),
1251 givenProperty.getArraySize(),
1252 givenProperty.getReferenceClassName(),
1253 givenProperty.getClassOrigin(),
1254 givenProperty.getPropagated());
1255 cimInstance.addProperty(newProperty);
1256 }
1257 }
1258 else
1259 {
1260 // Case: Property not set in original or in given
1261
1262 // Nothing to do; just make sure the property name is valid
1263 // ATTN: This is not the most efficient solution
1264 CIMClass cimClass = getClass(
1265 nameSpace, cimInstance.getClassName(), false);
1266 if (!cimClass.existsProperty(
1267 propertyList.getPropertyName(i)))
1268 {
1269 mike 1.51 // ATTN: This exception may be returned by setProperty
|
1270 kumpf 1.58 PEG_METHOD_EXIT();
|
1271 mike 1.51 throw PEGASUS_CIM_EXCEPTION(
1272 CIM_ERR_NO_SUCH_PROPERTY, "modifyInstance()");
1273 }
1274 }
1275 }
1276 }
1277 }
1278
|
1279 mike 1.53 //
|
1280 mike 1.54 // Resolve the instance (do not propagate qualifiers from class since
1281 // this will bloat the instance).
|
1282 mike 1.53 //
|
1283 mike 1.48
1284 CIMConstClass cimClass;
|
1285 mike 1.54 cimInstance.resolve(_context, nameSpace, cimClass, false);
|
1286 mike 1.48
|
1287 mike 1.51 CIMReference instanceName = cimInstance.getInstanceName(cimClass);
1288
|
1289 mike 1.53 //
1290 // Disallow operation if the instance name was changed:
1291 //
|
1292 mike 1.51
1293 if (instanceName != modifiedInstance.getInstanceName())
1294 {
|
1295 kumpf 1.58 PEG_METHOD_EXIT();
|
1296 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
1297 "Attempted to modify a key property");
1298 }
1299
1300 Uint32 oldSize;
1301 Uint32 oldIndex;
1302 Uint32 newSize;
1303 Uint32 newIndex;
|
1304 mike 1.48
|
1305 mike 1.53 if (!InstanceIndexFile::lookupEntry(
1306 indexFilePath, instanceName, oldIndex, oldSize))
|
1307 mike 1.51 {
|
1308 kumpf 1.58 PEG_METHOD_EXIT();
|
1309 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
1310 }
|
1311 mike 1.48
|
1312 mike 1.53 //
1313 // Modify the data file:
1314 //
1315
1316 {
1317 Array<Sint8> out;
1318 cimInstance.toXml(out);
|
1319 mike 1.48
|
1320 mike 1.53 newSize = out.size();
|
1321 mike 1.48
|
1322 mike 1.53 if (!InstanceDataFile::appendInstance(dataFilePath, out, newIndex))
1323 {
1324 errMessage.append("Failed to modify instance ");
1325 errMessage.append(instanceName.toString());
|
1326 kumpf 1.58 PEG_METHOD_EXIT();
|
1327 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1328 }
|
1329 mike 1.48 }
1330
|
1331 mike 1.53 //
1332 // Modify the index file:
1333 //
1334
1335 Uint32 freeCount;
|
1336 mike 1.51
|
1337 mike 1.53 if (!InstanceIndexFile::modifyEntry(indexFilePath, instanceName, newIndex,
1338 newSize, freeCount))
|
1339 mike 1.51 {
1340 errMessage.append("Failed to modify instance ");
1341 errMessage.append(instanceName.toString());
|
1342 kumpf 1.58 PEG_METHOD_EXIT();
|
1343 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1344 }
1345
|
1346 mike 1.53 //
1347 // Commit the transaction:
1348 //
1349
1350 if (!InstanceIndexFile::commitTransaction(indexFilePath))
|
1351 kumpf 1.58 {
1352 PEG_METHOD_EXIT();
|
1353 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
|
1354 kumpf 1.58 }
|
1355 mike 1.53
1356 if (!InstanceDataFile::commitTransaction(dataFilePath))
|
1357 kumpf 1.58 {
1358 PEG_METHOD_EXIT();
|
1359 mike 1.53 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "commit failed");
|
1360 kumpf 1.58 }
|
1361 mike 1.48
|
1362 mike 1.53 //
1363 // Compact the index and data files if the free count max was
1364 // reached.
1365 //
1366
1367 if (freeCount == _MAX_FREE_COUNT)
1368 _CompactInstanceRepository(indexFilePath, dataFilePath);
|
1369 mike 1.54
1370 //
1371 // Resolve the instance:
1372 //
1373
1374 cimInstance.resolve(_context, nameSpace, cimClass, true);
|
1375 kumpf 1.58
1376 PEG_METHOD_EXIT();
|
1377 mike 1.48 }
1378
1379 Array<CIMClass> CIMRepository::enumerateClasses(
1380 const String& nameSpace,
1381 const String& className,
1382 Boolean deepInheritance,
1383 Boolean localOnly,
1384 Boolean includeQualifiers,
1385 Boolean includeClassOrigin)
1386 {
|
1387 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateClasses");
|
1388 mike 1.51
|
1389 mike 1.48 Array<String> classNames;
1390
1391 _nameSpaceManager.getSubClassNames(
|
1392 mike 1.51 nameSpace, className, deepInheritance, classNames);
|
1393 mike 1.48
1394 Array<CIMClass> result;
1395
1396 for (Uint32 i = 0; i < classNames.size(); i++)
1397 {
|
1398 mike 1.51 result.append(getClass(nameSpace, classNames[i], localOnly,
1399 includeQualifiers, includeClassOrigin));
|
1400 mike 1.48 }
1401
|
1402 kumpf 1.58 PEG_METHOD_EXIT();
|
1403 mike 1.48 return result;
1404 }
1405
1406 Array<String> CIMRepository::enumerateClassNames(
1407 const String& nameSpace,
1408 const String& className,
1409 Boolean deepInheritance)
1410 {
|
1411 kumpf 1.59 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateClassNames");
|
1412 kumpf 1.58
|
1413 mike 1.48 Array<String> classNames;
1414
1415 _nameSpaceManager.getSubClassNames(
|
1416 mike 1.51 nameSpace, className, deepInheritance, classNames);
|
1417 mike 1.48
|
1418 kumpf 1.58 PEG_METHOD_EXIT();
|
1419 mike 1.48 return classNames;
1420 }
1421
|
1422 mike 1.53 Boolean CIMRepository::_loadAllInstances(
1423 const String& nameSpace,
1424 const String& className,
1425 Array<CIMNamedInstance>& namedInstances)
1426 {
|
1427 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_loadAllInstances");
1428
|
1429 mike 1.53 Array<CIMReference> instanceNames;
1430 Array<Sint8> data;
1431 Array<Uint32> indices;
1432 Array<Uint32> sizes;
1433
1434 //
1435 // Form the name of the instance index file
1436 //
1437
1438 String indexFilePath = _getInstanceIndexFilePath(nameSpace, className);
1439
1440 //
1441 // Form the name of the instance file
1442 //
1443
1444 String dataFilePath = _getInstanceDataFilePath(nameSpace, className);
1445
1446 //
1447 // Enumerate the index file:
1448 //
1449
1450 mike 1.53 Array<Uint32> freeFlags;
1451
1452 if (!InstanceIndexFile::enumerateEntries(
1453 indexFilePath, freeFlags, indices, sizes, instanceNames, true))
1454 {
|
1455 kumpf 1.58 PEG_METHOD_EXIT();
|
1456 mike 1.53 return false;
1457 }
1458
1459 //
1460 // Form the array of instances result:
1461 //
1462
1463 if (instanceNames.size() > 0)
1464 {
1465 //
1466 // Load all instances from the data file:
1467 //
1468
1469 if (!InstanceDataFile::loadAllInstances(dataFilePath, data))
|
1470 kumpf 1.58 {
1471 PEG_METHOD_EXIT();
|
1472 mike 1.53 return false;
|
1473 kumpf 1.58 }
|
1474 mike 1.53
1475 //
1476 // for each instance loaded, call XML parser to parse the XML
1477 // data and create a CIMInstance object.
1478 //
1479
1480 CIMInstance tmpInstance;
1481
1482 Uint32 bufferSize = data.size();
1483 char* buffer = (char*)data.getData();
1484
1485 for (Uint32 i = 0; i < instanceNames.size(); i++)
1486 {
1487 if (!freeFlags[i])
1488 {
1489 XmlParser parser(&(buffer[indices[i]]));
1490
1491 XmlReader::getObject(parser, tmpInstance);
1492
|
1493 mike 1.54 tmpInstance.resolve(_context, nameSpace, true);
1494
|
1495 mike 1.53 namedInstances.append(
1496 CIMNamedInstance(instanceNames[i], tmpInstance));
1497 }
1498 }
1499 }
1500
|
1501 kumpf 1.58 PEG_METHOD_EXIT();
|
1502 mike 1.53 return true;
1503 }
1504
|
1505 mike 1.51 Array<CIMNamedInstance> CIMRepository::enumerateInstances(
|
1506 mike 1.48 const String& nameSpace,
1507 const String& className,
1508 Boolean deepInheritance,
1509 Boolean localOnly,
1510 Boolean includeQualifiers,
1511 Boolean includeClassOrigin,
|
1512 mike 1.51 const CIMPropertyList& propertyList)
|
1513 mike 1.48 {
|
1514 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateInstances");
1515
|
1516 mike 1.53 //
1517 // Get all descendent classes of this class:
1518 //
|
1519 mike 1.48
1520 Array<String> classNames;
|
1521 mike 1.51 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
|
1522 mike 1.48 classNames.prepend(className);
1523
|
1524 mike 1.53 //
1525 // Get all instances for this class and all its descendent classes
1526 //
|
1527 mike 1.48
|
1528 mike 1.51 Array<CIMNamedInstance> namedInstances;
|
1529 mike 1.48
1530 for (Uint32 i = 0; i < classNames.size(); i++)
1531 {
|
1532 mike 1.51 if (!_loadAllInstances(nameSpace, classNames[i], namedInstances))
1533 {
1534 String errMessage = "Failed to load instances in class ";
1535 errMessage.append(classNames[i]);
|
1536 kumpf 1.58 PEG_METHOD_EXIT();
|
1537 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1538 }
|
1539 mike 1.48 }
1540
|
1541 kumpf 1.58 PEG_METHOD_EXIT();
|
1542 mike 1.51 return namedInstances;
|
1543 mike 1.48 }
1544
1545 Array<CIMReference> CIMRepository::enumerateInstanceNames(
1546 const String& nameSpace,
1547 const String& className)
1548 {
|
1549 kumpf 1.61 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateInstanceNames");
|
1550 mike 1.51
|
1551 mike 1.53 //
1552 // Get names of descendent classes:
1553 //
|
1554 mike 1.48
1555 Array<String> classNames;
|
1556 kumpf 1.61 try
|
1557 mday 1.57 {
|
1558 kumpf 1.59 _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
|
1559 mday 1.57 }
|
1560 kumpf 1.60 catch(CIMException& e)
|
1561 mday 1.57 {
|
1562 kumpf 1.60 PEG_METHOD_EXIT();
1563 throw e;
|
1564 mday 1.57 }
|
1565 kumpf 1.61
|
1566 mike 1.48 classNames.prepend(className);
1567
|
1568 mike 1.53 //
1569 // Get instance names from each qualifying instance file for the class:
1570 //
|
1571 mike 1.48
1572 Array<CIMReference> instanceNames;
1573 Array<Uint32> indices;
|
1574 mike 1.51 Array<Uint32> sizes;
|
1575 mike 1.48
1576 for (Uint32 i = 0; i < classNames.size(); i++)
1577 {
|
1578 mike 1.53 //
1579 // Form the name of the class index file:
1580 //
|
1581 mike 1.48
|
1582 mike 1.53 String indexFilePath = _getInstanceIndexFilePath(
1583 nameSpace, classNames[i]);
|
1584 mike 1.48
|
1585 mike 1.53 //
|
1586 mike 1.51 // Get all instances for that class:
|
1587 mike 1.53 //
1588
1589 Array<Uint32> freeFlags;
|
1590 mike 1.48
|
1591 mike 1.53 if (!InstanceIndexFile::enumerateEntries(
1592 indexFilePath, freeFlags, indices, sizes, instanceNames, false))
|
1593 mike 1.51 {
1594 String errMessage = "Failed to load instance names in class ";
|
1595 mike 1.53 errMessage.append(classNames[i]);
|
1596 kumpf 1.52 PEG_METHOD_EXIT();
|
1597 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
1598 }
|
1599 mike 1.48 }
|
1600 mike 1.53
|
1601 kumpf 1.52 PEG_METHOD_EXIT();
|
1602 mike 1.48 return instanceNames;
1603 }
1604
1605 Array<CIMInstance> CIMRepository::execQuery(
1606 const String& queryLanguage,
1607 const String& query)
1608 {
|
1609 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::execQuery");
1610
1611 PEG_METHOD_EXIT();
|
1612 mike 1.48 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "execQuery()");
1613
|
1614 kumpf 1.58 PEG_METHOD_EXIT();
|
1615 mike 1.48 return Array<CIMInstance>();
1616 }
1617
1618 Array<CIMObjectWithPath> CIMRepository::associators(
1619 const String& nameSpace,
1620 const CIMReference& objectName,
1621 const String& assocClass,
1622 const String& resultClass,
1623 const String& role,
1624 const String& resultRole,
1625 Boolean includeQualifiers,
1626 Boolean includeClassOrigin,
|
1627 mike 1.51 const CIMPropertyList& propertyList)
|
1628 mike 1.48 {
|
1629 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::associators");
1630
|
1631 mike 1.48 Array<CIMReference> names = associatorNames(
|
1632 mike 1.51 nameSpace,
1633 objectName,
1634 assocClass,
1635 resultClass,
1636 role,
1637 resultRole);
|
1638 mike 1.48
1639 Array<CIMObjectWithPath> result;
1640
1641 for (Uint32 i = 0, n = names.size(); i < n; i++)
1642 {
|
1643 mike 1.51 String tmpNameSpace = names[i].getNameSpace();
|
1644 mike 1.48
|
1645 mike 1.51 if (tmpNameSpace.size() == 0)
1646 tmpNameSpace = nameSpace;
|
1647 mike 1.48
|
1648 mike 1.51 if (names[i].isClassName())
1649 {
1650 CIMReference tmpRef = names[i];
1651 tmpRef.setHost(String());
1652 tmpRef.setNameSpace(String());
1653
1654 CIMClass cimClass = getClass(
1655 tmpNameSpace,
1656 tmpRef.getClassName(),
1657 false,
1658 includeQualifiers,
1659 includeClassOrigin,
1660 propertyList);
1661
1662 CIMObject cimObject(cimClass);
1663 result.append(CIMObjectWithPath(names[i], cimObject));
1664 }
1665 else
1666 {
1667 CIMReference tmpRef = names[i];
1668 tmpRef.setHost(String());
1669 mike 1.51 tmpRef.setNameSpace(String());
1670
1671 CIMInstance cimInstance = getInstance(
1672 tmpNameSpace,
1673 tmpRef,
1674 false,
1675 includeQualifiers,
1676 includeClassOrigin,
1677 propertyList);
1678
1679 CIMObject cimObject(cimInstance);
1680 result.append(CIMObjectWithPath(names[i], cimObject));
1681 }
|
1682 mike 1.48 }
1683
|
1684 kumpf 1.58 PEG_METHOD_EXIT();
|
1685 mike 1.48 return result;
1686 }
1687
1688 Array<CIMReference> CIMRepository::associatorNames(
1689 const String& nameSpace,
1690 const CIMReference& objectName,
1691 const String& assocClass,
1692 const String& resultClass,
1693 const String& role,
1694 const String& resultRole)
1695 {
|
1696 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::associatorNames");
|
1697 mike 1.51
|
1698 mike 1.48 Array<String> associatorNames;
1699
1700 if (objectName.isClassName())
1701 {
|
1702 mike 1.51 String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
|
1703 mike 1.48
|
1704 mike 1.51 AssocClassTable::getAssociatorNames(
1705 assocFileName,
1706 objectName.toString(),
1707 assocClass,
1708 resultClass,
1709 role,
1710 resultRole,
1711 associatorNames);
|
1712 mike 1.48 }
1713 else
1714 {
|
1715 mike 1.51 String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
|
1716 mike 1.48
|
1717 mike 1.51 AssocInstTable::getAssociatorNames(
1718 assocFileName,
1719 objectName,
1720 assocClass,
1721 resultClass,
1722 role,
1723 resultRole,
1724 associatorNames);
|
1725 mike 1.48 }
1726
1727 Array<CIMReference> result;
1728
1729 for (Uint32 i = 0, n = associatorNames.size(); i < n; i++)
1730 {
|
1731 mike 1.51 CIMReference r = associatorNames[i];
|
1732 mike 1.48
1733 if (r.getHost().size() == 0)
1734 r.setHost(System::getHostName());
1735
1736 if (r.getNameSpace().size() == 0)
1737 r.setNameSpace(nameSpace);
1738
|
1739 mike 1.51 result.append(r);
|
1740 mike 1.48 }
1741
|
1742 kumpf 1.58 PEG_METHOD_EXIT();
|
1743 mike 1.48 return result;
1744 }
1745
1746 Array<CIMObjectWithPath> CIMRepository::references(
1747 const String& nameSpace,
1748 const CIMReference& objectName,
1749 const String& resultClass,
1750 const String& role,
1751 Boolean includeQualifiers,
1752 Boolean includeClassOrigin,
|
1753 mike 1.51 const CIMPropertyList& propertyList)
|
1754 mike 1.48 {
|
1755 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::references");
1756
|
1757 mike 1.48 Array<CIMReference> names = referenceNames(
|
1758 mike 1.51 nameSpace,
1759 objectName,
1760 resultClass,
1761 role);
|
1762 mike 1.48
1763 Array<CIMObjectWithPath> result;
1764
1765 for (Uint32 i = 0, n = names.size(); i < n; i++)
1766 {
|
1767 mike 1.51 String tmpNameSpace = names[i].getNameSpace();
|
1768 mike 1.48
|
1769 mike 1.51 if (tmpNameSpace.size() == 0)
1770 tmpNameSpace = nameSpace;
|
1771 mike 1.48
|
1772 mike 1.51 // ATTN: getInstance() should this be able to handle instance names
1773 // with host names and namespaces?
|
1774 mike 1.48
|
1775 mike 1.51 CIMReference tmpRef = names[i];
1776 tmpRef.setHost(String());
1777 tmpRef.setNameSpace(String());
1778
1779 if (objectName.isClassName())
1780 {
1781 CIMClass cimClass = getClass(
1782 tmpNameSpace,
1783 tmpRef.getClassName(),
1784 false,
1785 includeQualifiers,
1786 includeClassOrigin,
1787 propertyList);
1788
1789 result.append(CIMObjectWithPath(names[i], cimClass));
1790 }
1791 else
1792 {
1793 CIMInstance instance = getInstance(
1794 tmpNameSpace,
1795 tmpRef,
1796 mike 1.51 false,
1797 includeQualifiers,
1798 includeClassOrigin,
1799 propertyList);
|
1800 mike 1.48
|
1801 mike 1.51 result.append(CIMObjectWithPath(names[i], instance));
1802 }
|
1803 mike 1.48 }
1804
|
1805 kumpf 1.58 PEG_METHOD_EXIT();
|
1806 mike 1.48 return result;
1807 }
1808
1809 Array<CIMReference> CIMRepository::referenceNames(
1810 const String& nameSpace,
1811 const CIMReference& objectName,
1812 const String& resultClass,
1813 const String& role)
1814 {
|
1815 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::referenceNames");
1816
|
1817 mike 1.48 Array<String> tmpReferenceNames;
1818
1819 if (objectName.isClassName())
1820 {
|
1821 mike 1.51 String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
|
1822 mike 1.48
|
1823 mike 1.51 if (!AssocClassTable::getReferenceNames(
1824 assocFileName,
1825 objectName.getClassName(),
1826 resultClass,
1827 role,
1828 tmpReferenceNames))
1829 {
1830 // Ignore error! It's okay not to have references.
1831 }
|
1832 mike 1.48 }
1833 else
1834 {
|
1835 mike 1.51 String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
|
1836 mike 1.48
|
1837 mike 1.51 if (!AssocInstTable::getReferenceNames(
1838 assocFileName,
1839 objectName,
1840 resultClass,
1841 role,
1842 tmpReferenceNames))
1843 {
1844 // Ignore error! It's okay not to have references.
1845 }
|
1846 mike 1.48 }
1847
1848 Array<CIMReference> result;
1849
1850 for (Uint32 i = 0, n = tmpReferenceNames.size(); i < n; i++)
1851 {
|
1852 mike 1.51 CIMReference r = tmpReferenceNames[i];
|
1853 mike 1.48
1854 if (r.getHost().size() == 0)
1855 r.setHost(System::getHostName());
1856
1857 if (r.getNameSpace().size() == 0)
1858 r.setNameSpace(nameSpace);
1859
|
1860 mike 1.51 result.append(r);
|
1861 mike 1.48 }
1862
|
1863 kumpf 1.58 PEG_METHOD_EXIT();
|
1864 mike 1.48 return result;
1865 }
1866
1867 CIMValue CIMRepository::getProperty(
1868 const String& nameSpace,
1869 const CIMReference& instanceName,
1870 const String& propertyName)
1871 {
|
1872 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getProperty");
1873
|
1874 mike 1.53 //
1875 // Get the index for this instance:
1876 //
|
1877 mike 1.48
1878 String className;
1879 Uint32 index;
|
1880 mike 1.51 Uint32 size;
|
1881 mike 1.48
|
1882 mike 1.53 if (!_getInstanceIndex(nameSpace, instanceName, className, index, size))
|
1883 kumpf 1.58 {
1884 PEG_METHOD_EXIT();
|
1885 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
|
1886 kumpf 1.58 }
|
1887 mike 1.48
|
1888 mike 1.53 //
1889 // Load the instance into memory:
1890 //
|
1891 mike 1.48
|
1892 mike 1.53 String path = _getInstanceDataFilePath(nameSpace, className);
|
1893 mike 1.48 CIMInstance cimInstance;
|
1894 mike 1.53
|
1895 mike 1.51 if (!_loadInstance(path, cimInstance, index, size))
1896 {
|
1897 kumpf 1.58 PEG_METHOD_EXIT();
|
1898 mike 1.51 throw CannotOpenFile(path);
1899 }
|
1900 mike 1.48
|
1901 mike 1.53 //
1902 // Grab the property from the instance:
1903 //
|
1904 mike 1.48
1905 Uint32 pos = cimInstance.findProperty(propertyName);
1906
|
1907 mike 1.51 // ATTN: This breaks if the property is simply null
|
1908 mike 1.48 if (pos == PEGASUS_NOT_FOUND)
|
1909 kumpf 1.58 {
1910 PEG_METHOD_EXIT();
|
1911 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NO_SUCH_PROPERTY, "getProperty()");
|
1912 kumpf 1.58 }
|
1913 mike 1.48
1914 CIMProperty prop = cimInstance.getProperty(pos);
1915
|
1916 mike 1.53 //
1917 // Return the value:
1918 //
|
1919 mike 1.48
|
1920 kumpf 1.58 PEG_METHOD_EXIT();
|
1921 mike 1.48 return prop.getValue();
1922 }
1923
1924 void CIMRepository::setProperty(
1925 const String& nameSpace,
1926 const CIMReference& instanceName,
1927 const String& propertyName,
1928 const CIMValue& newValue)
1929 {
|
1930 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setProperty");
1931
|
1932 mike 1.51 //
1933 // Create the instance to pass to modifyInstance()
1934 //
|
1935 mike 1.53
|
1936 mike 1.51 CIMInstance instance(instanceName.getClassName());
1937 instance.addProperty(CIMProperty(propertyName, newValue));
1938 CIMNamedInstance namedInstance(instanceName, instance);
1939
1940 //
1941 // Create the propertyList to pass to modifyInstance()
1942 //
|
1943 mike 1.53
|
1944 mike 1.51 Array<String> propertyListArray;
1945 propertyListArray.append(propertyName);
1946 CIMPropertyList propertyList(propertyListArray);
1947
1948 //
1949 // Modify the instance to set the value of the given property
1950 //
1951 modifyInstance(nameSpace, namedInstance, false, propertyList);
|
1952 kumpf 1.58
1953 PEG_METHOD_EXIT();
|
1954 mike 1.48 }
1955
1956 CIMQualifierDecl CIMRepository::getQualifier(
1957 const String& nameSpace,
1958 const String& qualifierName)
1959 {
|
1960 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::getQualifier");
1961
|
1962 mike 1.53 //
1963 // Get path of qualifier file:
1964 //
|
1965 mike 1.48
1966 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
|
1967 mike 1.51 nameSpace, qualifierName);
|
1968 mike 1.48
|
1969 mike 1.53 //
1970 // Load qualifier:
1971 //
|
1972 mike 1.48
1973 CIMQualifierDecl qualifierDecl;
1974
1975 try
1976 {
|
1977 mike 1.51 _LoadObject(qualifierFilePath, qualifierDecl);
|
1978 mike 1.48 }
1979 catch (CannotOpenFile&)
1980 {
|
1981 kumpf 1.58 PEG_METHOD_EXIT();
|
1982 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, qualifierName);
|
1983 mike 1.48 }
1984
|
1985 kumpf 1.58 PEG_METHOD_EXIT();
|
1986 mike 1.48 return qualifierDecl;
1987 }
1988
1989 void CIMRepository::setQualifier(
1990 const String& nameSpace,
1991 const CIMQualifierDecl& qualifierDecl)
1992 {
|
1993 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setQualifier");
1994
|
1995 mike 1.48 // -- Get path of qualifier file:
1996
1997 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
|
1998 mike 1.51 nameSpace, qualifierDecl.getName());
|
1999 mike 1.48
2000 // -- If qualifier alread exists, throw exception:
2001
2002 if (FileSystem::existsNoCase(qualifierFilePath))
|
2003 mike 1.53 {
|
2004 kumpf 1.58 PEG_METHOD_EXIT();
|
2005 mike 1.53 throw PEGASUS_CIM_EXCEPTION(
2006 CIM_ERR_ALREADY_EXISTS, qualifierDecl.getName());
2007 }
|
2008 mike 1.48
2009 // -- Save qualifier:
2010
2011 _SaveObject(qualifierFilePath, qualifierDecl);
|
2012 kumpf 1.58
2013 PEG_METHOD_EXIT();
|
2014 mike 1.48 }
2015
2016 void CIMRepository::deleteQualifier(
2017 const String& nameSpace,
2018 const String& qualifierName)
2019 {
|
2020 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteQualifier");
2021
|
2022 mike 1.48 // -- Get path of qualifier file:
2023
2024 String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
|
2025 mike 1.51 nameSpace, qualifierName);
|
2026 mike 1.48
2027 // -- Delete qualifier:
2028
2029 if (!FileSystem::removeFileNoCase(qualifierFilePath))
|
2030 kumpf 1.58 {
2031 PEG_METHOD_EXIT();
|
2032 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, qualifierName);
|
2033 kumpf 1.58 }
2034
2035 PEG_METHOD_EXIT();
|
2036 mike 1.48 }
2037
2038 Array<CIMQualifierDecl> CIMRepository::enumerateQualifiers(
2039 const String& nameSpace)
2040 {
|
2041 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateQualifiers");
2042
|
2043 mike 1.48 String qualifiersRoot = _nameSpaceManager.getQualifiersRoot(nameSpace);
2044
2045 Array<String> qualifierNames;
2046
2047 if (!FileSystem::getDirectoryContents(qualifiersRoot, qualifierNames))
2048 {
|
2049 kumpf 1.58 PEG_METHOD_EXIT();
|
2050 mike 1.51 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
2051 "enumerateQualifiers(): internal error");
|
2052 mike 1.48 }
2053
2054 Array<CIMQualifierDecl> qualifiers;
2055
2056 for (Uint32 i = 0; i < qualifierNames.size(); i++)
2057 {
|
2058 mike 1.51 CIMQualifierDecl qualifier = getQualifier(nameSpace, qualifierNames[i]);
2059 qualifiers.append(qualifier);
|
2060 mike 1.48 }
2061
|
2062 kumpf 1.58 PEG_METHOD_EXIT();
|
2063 mike 1.48 return qualifiers;
2064 }
2065
2066 void CIMRepository::createNameSpace(const String& nameSpace)
2067 {
|
2068 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::createNameSpace");
2069
|
2070 mike 1.48 _nameSpaceManager.createNameSpace(nameSpace);
|
2071 kumpf 1.58
2072 PEG_METHOD_EXIT();
|
2073 mike 1.48 }
2074
2075 Array<String> CIMRepository::enumerateNameSpaces() const
2076 {
|
2077 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::enumerateNameSpaces");
2078
|
2079 mike 1.48 Array<String> nameSpaceNames;
2080 _nameSpaceManager.getNameSpaceNames(nameSpaceNames);
|
2081 kumpf 1.58
2082 PEG_METHOD_EXIT();
|
2083 mike 1.48 return nameSpaceNames;
2084 }
2085
2086 void CIMRepository::deleteNameSpace(const String& nameSpace)
2087 {
|
2088 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::deleteNameSpace");
2089
|
2090 mike 1.48 _nameSpaceManager.deleteNameSpace(nameSpace);
|
2091 kumpf 1.58
2092 PEG_METHOD_EXIT();
|
2093 mike 1.48 }
2094
|
2095 mike 1.51 //----------------------------------------------------------------------
2096 //
|
2097 mike 1.53 // _getInstanceIndexFilePath()
|
2098 mike 1.51 //
2099 // returns the file path of the instance index file.
2100 //
2101 //----------------------------------------------------------------------
2102
|
2103 mike 1.53 String CIMRepository::_getInstanceIndexFilePath(
|
2104 mike 1.48 const String& nameSpace,
2105 const String& className) const
2106 {
|
2107 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstanceIndexFilePath");
2108
|
2109 mike 1.53 String tmp = _nameSpaceManager.getInstanceDataFileBase(
2110 nameSpace, className);
2111
|
2112 mike 1.48 tmp.append(".idx");
|
2113 kumpf 1.58
2114 PEG_METHOD_EXIT();
|
2115 mike 1.48 return tmp;
2116 }
2117
|
2118 mike 1.51 //----------------------------------------------------------------------
2119 //
|
2120 mike 1.53 // _getInstanceDataFilePath()
|
2121 mike 1.51 //
2122 // returns the file path of the instance file.
2123 //
2124 //----------------------------------------------------------------------
2125
|
2126 mike 1.53 String CIMRepository::_getInstanceDataFilePath(
|
2127 mike 1.48 const String& nameSpace,
|
2128 mike 1.51 const String& className) const
|
2129 mike 1.48 {
|
2130 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_getInstanceDataFilePath");
2131
|
2132 mike 1.53 String tmp = _nameSpaceManager.getInstanceDataFileBase(
2133 nameSpace, className);
|
2134 mike 1.51 tmp.append(".instances");
|
2135 kumpf 1.61
|
2136 kumpf 1.58 PEG_METHOD_EXIT();
|
2137 mike 1.48 return tmp;
|
2138 mike 1.51 }
2139
2140 Boolean CIMRepository::_loadInstance(
2141 const String& path,
2142 CIMInstance& object,
2143 Uint32 index,
2144 Uint32 size)
2145 {
|
2146 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_loadInstance");
2147
|
2148 mike 1.51 //
|
2149 mike 1.53 // Load instance (in XML) from instance file into memory:
|
2150 mike 1.51 //
2151
|
2152 mike 1.53 Array<Sint8> data;
|
2153 mike 1.51
|
2154 mike 1.53 if (!InstanceDataFile::loadInstance(path, index, size, data))
|
2155 kumpf 1.58 {
2156 PEG_METHOD_EXIT();
|
2157 mike 1.51 return false;
|
2158 kumpf 1.58 }
|
2159 mike 1.51
2160 //
|
2161 mike 1.53 // Convert XML into an actual object:
|
2162 mike 1.51 //
2163
|
2164 mike 1.53 XmlParser parser((char*)data.getData());
2165 XmlReader::getObject(parser, object);
|
2166 mike 1.51
|
2167 kumpf 1.58 PEG_METHOD_EXIT();
|
2168 mike 1.51 return true;
|
2169 mike 1.48 }
2170
|
2171 bob 1.49 void CIMRepository::setDeclContext(RepositoryDeclContext *context)
2172 {
|
2173 kumpf 1.58 PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::setDeclContext");
2174
2175 _context = context;
2176
2177 PEG_METHOD_EXIT();
|
2178 bob 1.49 }
2179
|
2180 mike 1.48 PEGASUS_NAMESPACE_END
|