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