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