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