/
ResourceManager.java
1341 lines (1160 loc) · 65 KB
/
ResourceManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.provisioning.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.schema.PrismSchemaImpl;
import com.evolveum.midpoint.schema.processor.*;
import com.evolveum.prism.xml.ns._public.types_3.SchemaDefinitionType;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.evolveum.midpoint.prism.delta.ContainerDelta;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.prism.delta.PropertyDelta;
import com.evolveum.midpoint.prism.delta.ReferenceDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.schema.PrismSchema;
import com.evolveum.midpoint.provisioning.api.GenericConnectorException;
import com.evolveum.midpoint.provisioning.api.ProvisioningOperationOptions;
import com.evolveum.midpoint.provisioning.ucf.api.ConnectorInstance;
import com.evolveum.midpoint.provisioning.ucf.api.ExecuteProvisioningScriptOperation;
import com.evolveum.midpoint.provisioning.ucf.api.GenericFrameworkException;
import com.evolveum.midpoint.provisioning.util.ProvisioningUtil;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.common.expression.Expression;
import com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext;
import com.evolveum.midpoint.repo.common.expression.ExpressionFactory;
import com.evolveum.midpoint.repo.common.expression.ExpressionVariables;
import com.evolveum.midpoint.schema.CapabilityUtil;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ConnectorTestOperation;
import com.evolveum.midpoint.schema.internals.InternalCounters;
import com.evolveum.midpoint.schema.internals.InternalMonitor;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.statistics.ConnectorOperationalStatus;
import com.evolveum.midpoint.schema.util.ConnectorTypeUtil;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.task.api.StateReporter;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.CommunicationException;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.exception.SecurityViolationException;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.exception.TunnelException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CachingMetadataType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilitiesType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorInstanceSpecificationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationalStateType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SchemaGenerationConstraintsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.XmlSchemaType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ActivationCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.CapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.SchemaCapabilityType;
import com.evolveum.midpoint.xml.ns._public.resource.capabilities_3.ScriptCapabilityType;
@Component
public class ResourceManager {
@Autowired(required = true)
@Qualifier("cacheRepositoryService")
private RepositoryService repositoryService;
@Autowired(required = true)
private ResourceCache resourceCache;
@Autowired(required = true)
private ConnectorManager connectorManager;
@Autowired(required = true)
private PrismContext prismContext;
@Autowired(required = true)
private ExpressionFactory expressionFactory;
private static final Trace LOGGER = TraceManager.getTrace(ResourceManager.class);
private static final String OPERATION_COMPLETE_RESOURCE = ResourceManager.class.getName() + ".completeResource";
public PrismObject<ResourceType> getResource(PrismObject<ResourceType> repositoryObject, GetOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException{
InternalMonitor.getResourceCacheStats().recordRequest();
PrismObject<ResourceType> cachedResource = resourceCache.get(repositoryObject, options);
if (cachedResource != null) {
InternalMonitor.getResourceCacheStats().recordHit();
return cachedResource;
}
LOGGER.debug("Storing fetched resource {}, version {} to cache (previously cached version {})",
repositoryObject.getOid(), repositoryObject.getVersion(), resourceCache.getVersion(repositoryObject.getOid()));
return loadAndCacheResource(repositoryObject, options, task, parentResult);
}
public PrismObject<ResourceType> getResource(String oid, GetOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException{
InternalMonitor.getResourceCacheStats().recordRequest();
String version = repositoryService.getVersion(ResourceType.class, oid, parentResult);
PrismObject<ResourceType> cachedResource = resourceCache.get(oid, version, options);
if (cachedResource != null) {
InternalMonitor.getResourceCacheStats().recordHit();
if (LOGGER.isTraceEnabled()){
LOGGER.trace("Returning resource from cache:\n{}", cachedResource.debugDump());
}
return cachedResource;
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Fetching resource {}, version {}, storing to cache (previously cached version {})",
oid, version, resourceCache.getVersion(oid));
}
Collection<SelectorOptions<GetOperationOptions>> repoOptions = null;
if (GetOperationOptions.isReadOnly(options)) {
repoOptions = SelectorOptions.createCollection(GetOperationOptions.createReadOnly());
}
PrismObject<ResourceType> repositoryObject = readResourceFromRepository(oid, repoOptions, parentResult);
return loadAndCacheResource(repositoryObject, options, task, parentResult);
}
private PrismObject<ResourceType> readResourceFromRepository(String oid, Collection<SelectorOptions<GetOperationOptions>> repoOptions, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
InternalMonitor.recordCount(InternalCounters.RESOURCE_REPOSITORY_READ_COUNT);
return repositoryService.getObject(ResourceType.class, oid, repoOptions, parentResult);
}
private PrismObject<ResourceType> loadAndCacheResource(PrismObject<ResourceType> repositoryObject,
GetOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
PrismObject<ResourceType> completedResource = completeResource(repositoryObject, null, false, null, options, task, parentResult);
if (!isComplete(completedResource)) {
// No not cache non-complete resources (e.g. those retrieved with noFetch)
LOGGER.trace("Not putting resource {} ({}) into cache because it's not complete", repositoryObject.getName(), repositoryObject.getOid());
return completedResource;
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Putting resource in cache:\n{}", completedResource.debugDump());
Element xsdSchemaElement = ResourceTypeUtil.getResourceXsdSchema(completedResource);
if (xsdSchemaElement == null) {
LOGGER.trace("Schema: null");
} else {
LOGGER.trace("Schema:\n{}",
DOMUtil.serializeDOMToString(ResourceTypeUtil.getResourceXsdSchema(completedResource)));
}
}
OperationResult completeResourceResult = parentResult.findSubresult(OPERATION_COMPLETE_RESOURCE);
if (completeResourceResult.isSuccess()) {
// Cache only resources that are completely OK
resourceCache.put(completedResource);
} else {
LOGGER.trace("Not putting {} into cache because the completeResource operation status is {}",
ObjectTypeUtil.toShortString(repositoryObject), completeResourceResult.getStatus());
}
InternalMonitor.getResourceCacheStats().recordMiss();
return completedResource;
}
public void deleteResource(String oid, ProvisioningOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException {
resourceCache.remove(oid);
repositoryService.deleteObject(ResourceType.class, oid, parentResult);
}
/**
* Make sure that the resource is complete.
*
* It will check if the resource has a sufficiently fresh schema, etc.
*
* Returned resource may be the same or may be a different instance, but it
* is guaranteed that it will be "fresher" and will correspond to the
* repository state (assuming that the provided resource also corresponded
* to the repository state).
*
* The connector schema that was fetched before can be supplied to this
* method. This is just an optimization. It comes handy e.g. in test
* connection case.
*
* Note: This is not really the best place for this method. Need to figure
* out correct place later.
*
* @param repoResource
* Resource to check
* @param resourceSchema
* schema that was freshly pre-fetched (or null)
* @param parentResult
*
* @return completed resource
*/
private PrismObject<ResourceType> completeResource(PrismObject<ResourceType> repoResource, ResourceSchema resourceSchema,
boolean fetchedSchema, Map<String,Collection<Object>> capabilityMap, GetOperationOptions options, Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException,
CommunicationException, ConfigurationException, ExpressionEvaluationException {
// do not add as a subresult..it will be added later, if the completing
// of resource will be successfull.if not, it will be only set as a
// fetch result in the resource..
OperationResult result = parentResult.createMinorSubresult(OPERATION_COMPLETE_RESOURCE);
try {
applyConnectorSchemaToResource(repoResource, task, result);
} catch (SchemaException e) {
String message = "Schema error while applying connector schema to connectorConfiguration section of "+repoResource+": "+e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return repoResource;
} catch (ObjectNotFoundException e) {
String message = "Object not found error while processing connector configuration of "+repoResource+": "+e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return repoResource;
} catch (RuntimeException e) {
String message = "Unexpected error while processing connector configuration of "+repoResource+": "+e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return repoResource;
}
PrismObject<ResourceType> newResource;
if (isComplete(repoResource)) {
// The resource is complete.
newResource = repoResource;
} else {
// The resource is NOT complete. Try to fetch schema and capabilities
if (GetOperationOptions.isNoFetch(options)) {
// We need to fetch schema, but the noFetch option is specified. Therefore return whatever we have.
result.recordSuccessIfUnknown();
return repoResource;
}
try {
completeSchemaAndCapabilities(repoResource, resourceSchema, fetchedSchema, capabilityMap, task, result);
} catch (Exception ex) {
// Catch the exceptions. There are not critical. We need to catch them all because the connector may
// throw even undocumented runtime exceptions.
// Even non-complete resource may still be usable. The fetchResult indicates that there was an error
result.recordPartialError("Cannot complete resource schema and capabilities: "+ex.getMessage(), ex);
return repoResource;
}
try {
// Now we need to re-read the resource from the repository and re-aply the schemas. This ensures that we will
// cache the correct version and that we avoid race conditions, etc.
newResource = readResourceFromRepository(repoResource.getOid(), null, result);
applyConnectorSchemaToResource(newResource, task, result);
} catch (SchemaException e) {
result.recordFatalError(e);
throw e;
} catch (ObjectNotFoundException e) {
result.recordFatalError(e);
throw e;
} catch (RuntimeException e) {
result.recordFatalError(e);
throw e;
}
}
try {
// make sure it has parsed resource and refined schema. We are going to cache
// it, so we want to cache it with the parsed schemas
RefinedResourceSchemaImpl.getResourceSchema(newResource, prismContext);
RefinedResourceSchemaImpl.getRefinedSchema(newResource);
} catch (SchemaException e) {
String message = "Schema error while processing schemaHandling section of "+newResource+": "+e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return newResource;
} catch (RuntimeException e) {
String message = "Unexpected error while processing schemaHandling section of "+newResource+": "+e.getMessage();
result.recordPartialError(message, e);
LOGGER.warn(message, e);
return newResource;
}
result.recordSuccessIfUnknown();
return newResource;
}
private boolean isComplete(PrismObject<ResourceType> resource) {
ResourceType resourceType = resource.asObjectable();
Element xsdSchema = ResourceTypeUtil.getResourceXsdSchema(resource);
if (xsdSchema == null) {
return false;
}
CapabilitiesType capabilitiesType = resourceType.getCapabilities();
if (capabilitiesType == null) {
return false;
}
CachingMetadataType capCachingMetadata = capabilitiesType.getCachingMetadata();
if (capCachingMetadata == null) {
return false;
}
return true;
}
private void completeSchemaAndCapabilities(PrismObject<ResourceType> resource, ResourceSchema resourceSchema, boolean fetchedSchema,
Map<String,Collection<Object>> capabilityMap, Task task, OperationResult result)
throws SchemaException, CommunicationException, ObjectNotFoundException, GenericFrameworkException, ConfigurationException {
Collection<ItemDelta<?,?>> modifications = new ArrayList<>();
// Capabilities
// we need to process capabilities first. Schema is one of the connector capabilities.
// We need to determine this capability to select the right connector for schema retrieval.
completeCapabilities(resource, capabilityMap != null, capabilityMap, modifications, result);
if (resourceSchema == null) {
// Try to get existing schema from resource. We do not want to override this if it exists
// (but we still want to refresh the capabilities, that happens below)
resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
}
if (resourceSchema == null || resourceSchema.isEmpty()) {
LOGGER.trace("Fetching resource schema for {}", resource);
resourceSchema = fetchResourceSchema(resource, capabilityMap, task, result);
if (resourceSchema == null) {
LOGGER.warn("No resource schema fetched from {}", resource);
} else if (resourceSchema.isEmpty()) {
LOGGER.warn("Empty resource schema fetched from {}", resource);
} else {
LOGGER.debug("Fetched resource schema for {}: {} definitions", resource, resourceSchema.getDefinitions().size());
fetchedSchema = true;
}
}
if (fetchedSchema) {
adjustSchemaForSimulatedCapabilities(resource, resourceSchema);
ContainerDelta<XmlSchemaType> schemaContainerDelta = createSchemaUpdateDelta(resource, resourceSchema);
modifications.add(schemaContainerDelta);
// We have successfully fetched the resource schema. Therefore the resource must be up.
modifications.add(createResourceAvailabilityStatusDelta(resource, AvailabilityStatusType.UP));
}
if (!modifications.isEmpty()) {
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Completing {}:\n{}", resource, DebugUtil.debugDump(modifications, 1));
}
repositoryService.modifyObject(ResourceType.class, resource.getOid(), modifications, result);
} catch (ObjectAlreadyExistsException ex) {
// This should not happen
throw new SystemException(ex);
}
}
}
private void completeCapabilities(PrismObject<ResourceType> resource, boolean forceRefresh, Map<String,Collection<Object>> capabilityMap, Collection<ItemDelta<?, ?>> modifications,
OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException {
ResourceType resourceType = resource.asObjectable();
ConnectorSpec defaultConnectorSpec = getDefaultConnectorSpec(resource);
CapabilitiesType resourceCapType = resourceType.getCapabilities();
if (resourceCapType == null) {
resourceCapType = new CapabilitiesType();
resourceType.setCapabilities(resourceCapType);
}
completeConnectorCapabilities(defaultConnectorSpec, resourceCapType, new ItemPath(ResourceType.F_CAPABILITIES), forceRefresh,
capabilityMap==null?null:capabilityMap.get(null),
modifications, result);
for (ConnectorInstanceSpecificationType additionalConnectorType: resource.asObjectable().getAdditionalConnector()) {
ConnectorSpec connectorSpec = getConnectorSpec(resource, additionalConnectorType);
CapabilitiesType connectorCapType = additionalConnectorType.getCapabilities();
if (connectorCapType == null) {
connectorCapType = new CapabilitiesType();
additionalConnectorType.setCapabilities(connectorCapType);
}
ItemPath itemPath = additionalConnectorType.asPrismContainerValue().getPath().subPath(ConnectorInstanceSpecificationType.F_CAPABILITIES);
completeConnectorCapabilities(connectorSpec, connectorCapType, itemPath, forceRefresh,
capabilityMap==null?null:capabilityMap.get(additionalConnectorType.getName()),
modifications, result);
}
}
private void completeConnectorCapabilities(ConnectorSpec connectorSpec, CapabilitiesType capType, ItemPath itemPath, boolean forceRefresh,
Collection<Object> retrievedCapabilities, Collection<ItemDelta<?, ?>> modifications, OperationResult result)
throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException {
if (!forceRefresh && capType.getNative() != null && !capType.getNative().getAny().isEmpty()) {
return;
}
if (retrievedCapabilities == null) {
try {
InternalMonitor.recordCount(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT);
ConnectorInstance connector = connectorManager.getConfiguredConnectorInstance(connectorSpec, false, result);
retrievedCapabilities = connector.fetchCapabilities(result);
} catch (GenericFrameworkException e) {
throw new GenericConnectorException("Generic error in connector " + connectorSpec + ": "
+ e.getMessage(), e);
}
}
CapabilityCollectionType nativeCapType = new CapabilityCollectionType();
capType.setNative(nativeCapType);
nativeCapType.getAny().addAll(retrievedCapabilities);
CachingMetadataType cachingMetadata = MiscSchemaUtil.generateCachingMetadata();
capType.setCachingMetadata(cachingMetadata);
ObjectDelta<ResourceType> capabilitiesReplaceDelta = ObjectDelta.createModificationReplaceContainer(ResourceType.class, connectorSpec.getResource().getOid(),
itemPath, prismContext, capType.asPrismContainerValue().clone());
modifications.addAll(capabilitiesReplaceDelta.getModifications());
}
private ContainerDelta<XmlSchemaType> createSchemaUpdateDelta(PrismObject<ResourceType> resource, ResourceSchema resourceSchema) throws SchemaException {
Document xsdDoc = null;
try {
// Convert to XSD
LOGGER.trace("Serializing XSD resource schema for {} to DOM", resource);
xsdDoc = resourceSchema.serializeToXsd();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Serialized XSD resource schema for {}:\n{}",
resource, DOMUtil.serializeDOMToString(xsdDoc));
}
} catch (SchemaException e) {
throw new SchemaException("Error processing resource schema for "
+ resource + ": " + e.getMessage(), e);
}
Element xsdElement = DOMUtil.getFirstChildElement(xsdDoc);
if (xsdElement == null) {
throw new SchemaException("No schema was generated for " + resource);
}
CachingMetadataType cachingMetadata = MiscSchemaUtil.generateCachingMetadata();
// Store generated schema into repository (modify the original
// Resource)
LOGGER.info("Storing generated schema in resource {}", resource);
ContainerDelta<XmlSchemaType> schemaContainerDelta = ContainerDelta.createDelta(
ResourceType.F_SCHEMA, ResourceType.class, prismContext);
PrismContainerValue<XmlSchemaType> cval = new PrismContainerValue<XmlSchemaType>(prismContext);
schemaContainerDelta.setValueToReplace(cval);
PrismProperty<CachingMetadataType> cachingMetadataProperty = cval
.createProperty(XmlSchemaType.F_CACHING_METADATA);
cachingMetadataProperty.setRealValue(cachingMetadata);
List<QName> objectClasses = ResourceTypeUtil.getSchemaGenerationConstraints(resource);
if (objectClasses != null) {
PrismProperty<SchemaGenerationConstraintsType> generationConstraints = cval
.createProperty(XmlSchemaType.F_GENERATION_CONSTRAINTS);
SchemaGenerationConstraintsType constraints = new SchemaGenerationConstraintsType();
constraints.getGenerateObjectClass().addAll(objectClasses);
generationConstraints.setRealValue(constraints);
}
PrismProperty<SchemaDefinitionType> definitionProperty = cval.createProperty(XmlSchemaType.F_DEFINITION);
ObjectTypeUtil.setXsdSchemaDefinition(definitionProperty, xsdElement);
return schemaContainerDelta;
}
/**
* Apply proper definition (connector schema) to the resource.
*/
private void applyConnectorSchemaToResource(PrismObject<ResourceType> resource, Task task, OperationResult result)
throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
try {
resource.modifyUnfrozen(() -> {
try {
PrismObjectDefinition<ResourceType> newResourceDefinition = resource.getDefinition().clone();
for (ConnectorSpec connectorSpec : getAllConnectorSpecs(resource)) {
applyConnectorSchemaToResource(connectorSpec, newResourceDefinition, resource, task, result);
}
resource.setDefinition(newResourceDefinition);
} catch (Exception e) {
throw new TunnelException(e);
}
});
} catch (TunnelException te) {
Throwable originalException = te.getCause();
if (originalException instanceof SchemaException) {
throw (SchemaException) originalException;
} else if (originalException instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) originalException;
} else if (originalException instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) originalException;
} else if (originalException instanceof RuntimeException) {
throw (RuntimeException) originalException;
} else {
throw new IllegalStateException("Unexpected exception: "+te+": "+te.getMessage(), te);
}
}
}
/**
* Apply proper definition (connector schema) to the resource.
*/
private void applyConnectorSchemaToResource(ConnectorSpec connectorSpec, PrismObjectDefinition<ResourceType> resourceDefinition,
PrismObject<ResourceType> resource, Task task, OperationResult result)
throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
ConnectorType connectorType = connectorManager.getConnectorTypeReadOnly(connectorSpec, result);
PrismSchema connectorSchema = connectorManager.getConnectorSchema(connectorType);
if (connectorSchema == null) {
throw new SchemaException("No connector schema in " + connectorType);
}
PrismContainerDefinition<ConnectorConfigurationType> configurationContainerDefinition = ConnectorTypeUtil
.findConfigurationContainerDefinition(connectorType, connectorSchema);
if (configurationContainerDefinition == null) {
throw new SchemaException("No configuration container definition in schema of " + connectorType);
}
configurationContainerDefinition = configurationContainerDefinition.clone();
PrismContainer<ConnectorConfigurationType> configurationContainer = connectorSpec.getConnectorConfiguration();
// We want element name, minOccurs/maxOccurs and similar definition to be taken from the original, not the schema
// the element is global in the connector schema. therefore it does not have correct maxOccurs
if (configurationContainer != null) {
configurationContainerDefinition.adoptElementDefinitionFrom(configurationContainer.getDefinition());
configurationContainer.applyDefinition(configurationContainerDefinition, true);
try {
configurationContainer.accept(visitable -> {
if ((visitable instanceof PrismProperty<?>)) {
try {
evaluateExpression((PrismProperty<?>)visitable, resource, task, result);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | CommunicationException | ConfigurationException | SecurityViolationException e) {
throw new TunnelException(e);
}
}
});
} catch (TunnelException te) {
Throwable e = te.getCause();
if (e instanceof SchemaException) {
throw (SchemaException)e;
} else if (e instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException)e;
} else if (e instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException)e;
} else if (e instanceof CommunicationException) {
throw (CommunicationException)e;
} else if (e instanceof ConfigurationException) {
throw (ConfigurationException)e;
} else if (e instanceof SecurityViolationException) {
throw (SecurityViolationException)e;
} else if (e instanceof RuntimeException) {
throw (RuntimeException)e;
} else if (e instanceof Error) {
throw (Error)e;
} else {
throw new SystemException(e);
}
}
} else {
configurationContainerDefinition.adoptElementDefinitionFrom(
resourceDefinition.findContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION));
}
if (connectorSpec.getConnectorName() == null) {
// Default connector, for compatibility
// It does not make sense to update this for any other connectors.
// We cannot have one definition for addiitionalConnector[1]/connectorConfiguraiton and
// different definition for addiitionalConnector[2]/connectorConfiguraiton in the object definition.
// The way to go is to set up definitions on the container level.
resourceDefinition.replaceDefinition(ResourceType.F_CONNECTOR_CONFIGURATION, configurationContainerDefinition);
}
}
private <T> void evaluateExpression(PrismProperty<T> configurationProperty, PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
PrismPropertyDefinition<T> propDef = configurationProperty.getDefinition();
String shortDesc = "connector configuration property "+configurationProperty+" in "+resource;
List<PrismPropertyValue<T>> extraValues = new ArrayList<>();
for (PrismPropertyValue<T> configurationPropertyValue: configurationProperty.getValues()) {
ExpressionWrapper expressionWrapper = configurationPropertyValue.getExpression();
if (expressionWrapper == null) {
return;
}
Object expressionObject = expressionWrapper.getExpression();
if (!(expressionObject instanceof ExpressionType)) {
throw new IllegalStateException("Expected that expression in "+configurationPropertyValue+" will be ExpressionType, but it was "+expressionObject);
}
ExpressionType expressionType = (ExpressionType) expressionWrapper.getExpression();
Expression<PrismPropertyValue<T>, PrismPropertyDefinition<T>> expression = expressionFactory.makeExpression(expressionType, propDef, shortDesc, task, result);
ExpressionVariables variables = new ExpressionVariables();
// TODO: populate variables
ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(null, variables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<T>> expressionOutputTriple = expression.evaluate(expressionContext);
Collection<PrismPropertyValue<T>> expressionOutputValues = expressionOutputTriple.getNonNegativeValues();
if (expressionOutputValues != null && !expressionOutputValues.isEmpty()) {
Iterator<PrismPropertyValue<T>> iterator = expressionOutputValues.iterator();
PrismPropertyValue<T> firstValue = iterator.next();
configurationPropertyValue.setValue(firstValue.getValue());
while (iterator.hasNext()) {
extraValues.add(iterator.next());
}
}
}
for (PrismPropertyValue<T> extraValue: extraValues) {
configurationProperty.add(extraValue);
}
}
private ResourceSchema fetchResourceSchema(PrismObject<ResourceType> resource, Map<String,Collection<Object>> capabilityMap, Task task, OperationResult parentResult)
throws CommunicationException, GenericFrameworkException, ConfigurationException, ObjectNotFoundException, SchemaException {
ConnectorSpec connectorSpec = selectConnectorSpec(resource, capabilityMap, SchemaCapabilityType.class);
if (connectorSpec == null) {
LOGGER.trace("No connector has schema capability, cannot fetch resource schema");
return null;
}
InternalMonitor.recordCount(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT);
List<QName> generateObjectClasses = ResourceTypeUtil.getSchemaGenerationConstraints(resource);
ConnectorInstance connectorInstance = connectorManager.getConfiguredConnectorInstance(connectorSpec, false, parentResult);
LOGGER.trace("Trying to get schema from {}", connectorSpec);
ResourceSchema resourceSchema = connectorInstance.fetchResourceSchema(generateObjectClasses, parentResult);
if (ResourceTypeUtil.isValidateSchema(resource.asObjectable())) {
ResourceTypeUtil.validateSchema(resourceSchema, resource);
}
return resourceSchema;
}
public void testConnection(PrismObject<ResourceType> resource, Task task, OperationResult parentResult) {
List<ConnectorSpec> allConnectorSpecs;
try {
allConnectorSpecs = getAllConnectorSpecs(resource);
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
parentResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
}
Map<String,Collection<Object>> capabilityMap = new HashMap<>();
for (ConnectorSpec connectorSpec: allConnectorSpecs) {
OperationResult connectorTestResult = parentResult
.createSubresult(ConnectorTestOperation.CONNECTOR_TEST.getOperation());
connectorTestResult.addParam(OperationResult.PARAM_NAME, connectorSpec.getConnectorName());
connectorTestResult.addParam(OperationResult.PARAM_OID, connectorSpec.getConnectorOid());
testConnectionConnector(connectorSpec, capabilityMap, task, connectorTestResult);
connectorTestResult.computeStatus();
if (!connectorTestResult.isAcceptable()) {
//nothing more to do.. if it failed while testing connection, status is set.
// we do not need to continue and waste the time.
return;
}
}
// === test SCHEMA ===
OperationResult schemaResult = parentResult.createSubresult(ConnectorTestOperation.RESOURCE_SCHEMA
.getOperation());
ResourceSchema schema = null;
try {
schema = fetchResourceSchema(resource, capabilityMap, task, schemaResult);
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Communication error: " + e.getMessage(), e);
return;
} catch (GenericFrameworkException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Generic error: " + e.getMessage(), e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
} catch (ObjectNotFoundException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
}
if (schema == null || schema.isEmpty()) {
// Resource does not support schema
// If there is a static schema in resource definition this may still be OK
try {
schema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError(e);
return;
}
if (schema == null || schema.isEmpty()) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Connector does not support schema and no static schema available");
return;
}
}
// Invoke completeResource(). This will store the fetched schema to the
// ResourceType
// if there is no <schema> definition already. Therefore the
// testResource() can be used to
// generate the resource schema - until we have full schema caching
// capability.
try {
resource = completeResource(resource, schema, true, capabilityMap, null, task, schemaResult);
} catch (ObjectNotFoundException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError(
"Object not found (unexpected error, probably a bug): " + e.getMessage(), e);
return;
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError(
"Schema processing error (probably connector bug): " + e.getMessage(), e);
return;
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Communication error: " + e.getMessage(), e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Configuration error: " + e.getMessage(), e);
return;
} catch (ExpressionEvaluationException e) {
modifyResourceAvailabilityStatus(resource, AvailabilityStatusType.BROKEN, parentResult);
schemaResult.recordFatalError("Expression error: " + e.getMessage(), e);
return;
}
schemaResult.recordSuccess();
// TODO: connector sanity (e.g. refined schema, at least one account type, identifiers
// in schema, etc.)
}
public void testConnectionConnector(ConnectorSpec connectorSpec, Map<String,Collection<Object>> capabilityMap, Task task, OperationResult parentResult) {
// === test INITIALIZATION ===
OperationResult initResult = parentResult
.createSubresult(ConnectorTestOperation.CONNECTOR_INITIALIZATION.getOperation());
ConnectorInstance connector;
try {
// Make sure we are getting non-configured instance.
connector = connectorManager.createConnectorInstance(connectorSpec, initResult);
initResult.recordSuccess();
} catch (ObjectNotFoundException e) {
// The connector was not found. The resource definition is either
// wrong or the connector is not installed.
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("The connector was not found: "+e.getMessage(), e);
return;
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("Schema error while dealing with the connector definition: "+e.getMessage(), e);
return;
} catch (RuntimeException | Error e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("Unexpected runtime error: "+e.getMessage(), e);
return;
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("Communication error: "+e.getMessage(), e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
initResult.recordFatalError("Configuration error: "+e.getMessage(), e);
return;
}
LOGGER.debug("Testing connection using {}", connectorSpec);
// === test CONFIGURATION ===
OperationResult configResult = parentResult
.createSubresult(ConnectorTestOperation.CONNECTOR_CONFIGURATION.getOperation());
try {
PrismObject<ResourceType> resource = connectorSpec.getResource();
PrismObjectDefinition<ResourceType> newResourceDefinition = resource.getDefinition().clone();
applyConnectorSchemaToResource(connectorSpec, newResourceDefinition, resource, task, configResult);
PrismContainerValue<ConnectorConfigurationType> connectorConfiguration = connectorSpec.getConnectorConfiguration().getValue();
connector.configure(connectorConfiguration, configResult);
// We need to explicitly initialize the instance, e.g. in case that the schema and capabilities
// cannot be detected by the connector and therefore are provided in the resource
//
// NOTE: the capabilities and schema that are used here are NOT necessarily those that are detected by the resource.
// The detected schema will come later. The schema here is the one that is stored in the resource
// definition (ResourceType). This may be schema that was detected previously. But it may also be a schema
// that was manually defined. This is needed to be passed to the connector in case that the connector
// cannot detect the schema and needs schema/capabilities definition to establish a connection.
// Most connectors will just ignore the schema and capabilities that are provided here.
// But some connectors may need it (e.g. CSV connector working with CSV file without a header).
//
ResourceSchema previousResourceSchema = RefinedResourceSchemaImpl.getResourceSchema(connectorSpec.getResource(), prismContext);
Collection<Object> previousCapabilities = ResourceTypeUtil.getNativeCapabilitiesCollection(connectorSpec.getResource().asObjectable());
connector.initialize(previousResourceSchema, previousCapabilities, ResourceTypeUtil.isCaseIgnoreAttributeNames(connectorSpec.getResource().asObjectable()), configResult);
configResult.recordSuccess();
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Communication error", e);
return;
} catch (GenericFrameworkException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Generic error", e);
return;
} catch (SchemaException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Schema error", e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Configuration error", e);
return;
} catch (ObjectNotFoundException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Object not found", e);
return;
} catch (ExpressionEvaluationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Expression error", e);
return;
} catch (SecurityViolationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Security violation", e);
return;
} catch (RuntimeException | Error e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
configResult.recordFatalError("Unexpected runtime error", e);
return;
}
// === test CONNECTION ===
// delegate the main part of the test to the connector
connector.test(parentResult);
parentResult.computeStatus();
if (!parentResult.isAcceptable()) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.DOWN, parentResult);
// No point in going on. Following tests will fail anyway, they will
// just produce misleading
// messages.
return;
} else {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.UP, parentResult);
}
// === test CAPABILITIES ===
OperationResult capabilitiesResult = parentResult
.createSubresult(ConnectorTestOperation.CONNECTOR_CAPABILITIES.getOperation());
try {
InternalMonitor.recordCount(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT);
Collection<Object> retrievedCapabilities = connector.fetchCapabilities(capabilitiesResult);
capabilityMap.put(connectorSpec.getConnectorName(), retrievedCapabilities);
capabilitiesResult.recordSuccess();
} catch (CommunicationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
capabilitiesResult.recordFatalError("Communication error", e);
return;
} catch (GenericFrameworkException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
capabilitiesResult.recordFatalError("Generic error", e);
return;
} catch (ConfigurationException e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
capabilitiesResult.recordFatalError("Configuration error", e);
return;
} catch (RuntimeException | Error e) {
modifyResourceAvailabilityStatus(connectorSpec.getResource(), AvailabilityStatusType.BROKEN, parentResult);
capabilitiesResult.recordFatalError("Unexpected runtime error", e);
return;
}
connectorManager.cacheConfifuredConnector(connectorSpec, connector);
}
public void modifyResourceAvailabilityStatus(PrismObject<ResourceType> resource, AvailabilityStatusType status, OperationResult result){
ResourceType resourceType = resource.asObjectable();
synchronized (resource) {
if (resourceType.getOperationalState() == null || resourceType.getOperationalState().getLastAvailabilityStatus() == null || resourceType.getOperationalState().getLastAvailabilityStatus() != status) {
List<PropertyDelta<?>> modifications = new ArrayList<>();
PropertyDelta<?> statusDelta = createResourceAvailabilityStatusDelta(resource, status);
modifications.add(statusDelta);
try {
repositoryService.modifyObject(ResourceType.class, resourceType.getOid(), modifications, result);
} catch(SchemaException | ObjectAlreadyExistsException | ObjectNotFoundException ex) {
throw new SystemException(ex);
}
}
resource.modifyUnfrozen(() -> {
if (resourceType.getOperationalState() == null) {
OperationalStateType operationalState = new OperationalStateType();
operationalState.setLastAvailabilityStatus(status);
resourceType.setOperationalState(operationalState);
} else {
resourceType.getOperationalState().setLastAvailabilityStatus(status);
}
});
}
}
private PropertyDelta<?> createResourceAvailabilityStatusDelta(PrismObject<ResourceType> resource, AvailabilityStatusType status) {
PropertyDelta<?> statusDelta = PropertyDelta.createModificationReplaceProperty(OperationalStateType.F_LAST_AVAILABILITY_STATUS, resource.getDefinition(), status);
statusDelta.setParentPath(new ItemPath(ResourceType.F_OPERATIONAL_STATE));
return statusDelta;
}
/**
* Adjust scheme with respect to capabilities. E.g. disable attributes that
* are used for special purpose (such as account activation simulation).
*
* TODO treat also objectclass-specific capabilities here
*/
private void adjustSchemaForSimulatedCapabilities(PrismObject<ResourceType> resource, ResourceSchema resourceSchema) {
ResourceType resourceType = resource.asObjectable();