use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.
the class OperationResult method cleanupResult.
/**
* Removes all the successful minor results. Also checks if the result is roughly consistent
* and complete. (e.g. does not have unknown operation status, etc.)
* <p>
* The argument "e" is for easier use of the cleanup in the exceptions handlers. The original exception is passed
* to the IAE that this method produces for easier debugging.
*/
public void cleanupResult(Throwable e) {
if (!canBeCleanedUp()) {
// TEMPORARY fixme
return;
}
OperationResultImportanceType preserveDuringCleanup = getPreserveDuringCleanup();
if (status == OperationResultStatus.UNKNOWN) {
IllegalStateException illegalStateException = new IllegalStateException("Attempt to cleanup result of operation " + operation + " that is still UNKNOWN");
LOGGER.error("Attempt to cleanup result of operation " + operation + " that is still UNKNOWN:\n{}", this.debugDump(), illegalStateException);
throw illegalStateException;
}
if (subresults == null) {
return;
}
Iterator<OperationResult> iterator = subresults.iterator();
while (iterator.hasNext()) {
OperationResult subresult = iterator.next();
if (subresult.getStatus() == OperationResultStatus.UNKNOWN) {
String message = "Subresult " + subresult.getOperation() + " of operation " + operation + " is still UNKNOWN during cleanup";
LOGGER.error("{}:\n{}", message, this.debugDump(), e);
if (e == null) {
throw new IllegalStateException(message);
} else {
throw new IllegalStateException(message + "; during handling of exception " + e, e);
}
}
if (subresult.canCleanup(preserveDuringCleanup)) {
iterator.remove();
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.
the class ModelCrudService method addObject.
/**
* <p>
* Add new object.
* </p>
* <p>
* The OID provided in the input message may be empty. In that case the OID
* will be assigned by the implementation of this method and it will be
* provided as return value.
* </p>
* <p>
* This operation should fail if such object already exists (if object with
* the provided OID already exists).
* </p>
* <p>
* The operation may fail if provided OID is in an unusable format for the
* storage. Generating own OIDs and providing them to this method is not
* recommended for normal operation.
* </p>
* <p>
* Should be atomic. Should not allow creation of two objects with the same
* OID (even if created in parallel).
* </p>
* <p>
* The operation may fail if the object to be created does not conform to
* the underlying schema of the storage system or the schema enforced by the
* implementation.
* </p>
*
* @param object
* object to create
* @param parentResult
* parent OperationResult (in/out)
* @return OID assigned to the created object
* @throws ObjectAlreadyExistsException
* object with specified identifiers already exists, cannot add
* @throws ObjectNotFoundException
* object required to complete the operation was not found (e.g.
* appropriate connector or resource definition)
* @throws SchemaException
* error dealing with resource schema, e.g. created object does
* not conform to schema
* @throws ExpressionEvaluationException
* evaluation of expression associated with the object has failed
* @throws CommunicationException
* @throws ConfigurationException
* @throws PolicyViolationException
* Policy violation was detected during processing of the object
* @throws IllegalArgumentException
* wrong OID format, etc.
* @throws SystemException
* unknown error from underlying layers or other unexpected
* state
*/
@SuppressWarnings("JavaDoc")
public <T extends ObjectType> String addObject(PrismObject<T> object, ModelExecuteOptions options, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
Validate.notNull(object, "Object must not be null.");
Validate.notNull(parentResult, "Result type must not be null.");
object.checkConsistence();
T objectType = object.asObjectable();
prismContext.adopt(objectType);
OperationResult result = parentResult.createSubresult(ADD_OBJECT);
result.addParam(OperationResult.PARAM_OBJECT, object);
ModelImplUtils.resolveReferences(object, repository, false, false, EvaluationTimeType.IMPORT, true, prismContext, result);
String oid;
RepositoryCache.enterLocalCaches(cacheConfigurationManager);
try {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Entering addObject with {}", object);
LOGGER.trace(object.debugDump());
}
if (options == null) {
if (StringUtils.isNotEmpty(objectType.getVersion())) {
options = ModelExecuteOptions.create(prismContext).overwrite();
}
}
ObjectDelta<T> objectDelta = DeltaFactory.Object.createAddDelta(object);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
Collection<ObjectDeltaOperation<? extends ObjectType>> executedChanges = modelService.executeChanges(deltas, options, task, result);
oid = ObjectDeltaOperation.findAddDeltaOid(executedChanges, object);
result.computeStatus();
result.cleanupResult();
} catch (ExpressionEvaluationException | SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | SecurityViolationException | ConfigurationException | RuntimeException ex) {
ModelImplUtils.recordFatalError(result, ex);
throw ex;
} finally {
RepositoryCache.exitLocalCaches();
}
return oid;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.
the class TestDummyResourceAndSchemaCaching method test010GetResource.
@Test
public void test010GetResource() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = createOperationResult();
// Check that there is no schema before test (pre-condition)
PrismObject<ResourceType> resourceBefore = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
ResourceType resourceTypeBefore = resourceBefore.asObjectable();
Element resourceXsdSchemaElementBefore = ResourceTypeUtil.getResourceXsdSchema(resourceTypeBefore);
AssertJUnit.assertNull("Found schema before test connection. Bad test setup?", resourceXsdSchemaElementBefore);
assertVersion(resourceBefore, "0");
// Some connector initialization and other things might happen in previous tests.
// The monitor is static, not part of spring context, it will not be cleared
rememberCounter(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT);
rememberCounter(InternalCounters.RESOURCE_REPOSITORY_READ_COUNT);
rememberCounter(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT);
rememberCounter(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT);
rememberCounter(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT);
rememberCounter(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT);
rememberCounter(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT);
rememberResourceCacheStats();
// WHEN
when();
PrismObject<ResourceType> resourceProvisioning = provisioningService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, task, result);
// THEN
then();
display("Resource", resource);
assertSuccess(result);
assertHasSchema(resourceProvisioning, "provisioning resource");
rememberSchemaMetadata(resourceProvisioning);
// TODO not sure why are there 2 read counts. Should be 1. But this is not that important right now.
// Some overhead on initial resource read is OK. What is important is that it does not increase during
// normal account operations.
assertCounterIncrement(InternalCounters.RESOURCE_REPOSITORY_READ_COUNT, 2);
assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_FETCH_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_SCHEMA_PARSE_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_CAPABILITIES_FETCH_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_INITIALIZATION_COUNT, 1);
assertCounterIncrement(InternalCounters.CONNECTOR_INSTANCE_CONFIGURATION_COUNT, 1);
rememberConnectorInstance(resourceProvisioning);
assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 1);
PrismObject<ResourceType> resourceRepoAfter = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
assertHasSchema(resourceRepoAfter, "repo resource after");
assertSchemaMetadataUnchanged(resourceRepoAfter);
displayDumpable("Resource cache", InternalMonitor.getResourceCacheStats());
assertResourceCacheHitsIncrement(0);
assertResourceCacheMissesIncrement(1);
rememberResourceSchema(ResourceSchemaFactory.getRawSchema(resourceProvisioning));
rememberRefinedResourceSchema(ResourceSchemaFactory.getCompleteSchema(resourceProvisioning));
assertCounterIncrement(InternalCounters.RESOURCE_SCHEMA_PARSE_COUNT, 0);
// Just refresh the resource used by other tests. This one has a complete schema.
resourceBean = resourceProvisioning.asObjectable();
rememberResourceVersion(resourceBean.getVersion());
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkBucketStateType.COMPLETE in project midpoint by Evolveum.
the class GetBucketOperationAttempt method setOrUpdateEstimatedNumberOfBuckets.
private void setOrUpdateEstimatedNumberOfBuckets() throws SchemaException {
Integer number = bucketFactory.estimateNumberOfBuckets();
if (number != null && !number.equals(getNumberOfBuckets(activityState))) {
List<ItemDelta<?, ?>> numberOfBucketsMods = PrismContext.get().deltaFor(TaskType.class).item(activityStateItemPath.append(F_BUCKETING, F_NUMBER_OF_BUCKETS)).replace(number).asItemDeltas();
LOGGER.trace("Going to set # of buckets:\n{}", DebugUtil.debugDumpLazily(numberOfBucketsMods, 1));
modifications.addAll(numberOfBucketsMods);
}
// The number of complete buckets is not changed by this operation, so we can report the progress right now.
bucketProgressHolder.accept(new BucketProgressOverviewType().totalBuckets(number).completeBuckets(BucketingUtil.getCompleteBucketsNumber(currentBuckets)));
}
Aggregations