Skip to content

Commit

Permalink
Fix maintenance mode check in activities
Browse files Browse the repository at this point in the history
It is now reported as handled error (as it was originally).
  • Loading branch information
mederly committed Jun 28, 2021
1 parent e5207fa commit f20721d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -742,16 +742,6 @@ public static ErrorSelectorType getConnectorErrorCriticality(ResourceType resour
return consistency != null ? consistency.getConnectorErrorCriticality() : null;
}

public static void checkNotInMaintenance(ResourceType resource) throws MaintenanceException {
checkNotInMaintenance(resource.asPrismObject());
}

public static void checkNotInMaintenance(PrismObject<ResourceType> resource) throws MaintenanceException {
if (isInMaintenance(resource)) {
throw new MaintenanceException("Resource " + resource + " is in the maintenance");
}
}

public static boolean isInMaintenance(PrismObject<ResourceType> resource) {
return isInMaintenance(resource.asObjectable());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.model.impl.util.ModelImplUtils;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.repo.common.activity.ActivityExecutionException;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.MaintenanceException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectSetType;
Expand Down Expand Up @@ -100,8 +100,8 @@ public void checkResourceUp() {
}
}

public void checkNotInMaintenance() throws MaintenanceException {
ResourceTypeUtil.checkNotInMaintenance(resource);
public void checkNotInMaintenance() throws ActivityExecutionException {
SyncTaskHelper.checkNotInMaintenance(resource);
}

ObjectQuery createBasicQuery() throws SchemaException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

package com.evolveum.midpoint.model.impl.sync.tasks;

import static com.evolveum.midpoint.schema.result.OperationResultStatus.HANDLED_ERROR;
import static com.evolveum.midpoint.schema.util.ResourceTypeUtil.isInMaintenance;

import static java.util.Objects.requireNonNull;

import static com.evolveum.midpoint.schema.result.OperationResultStatus.FATAL_ERROR;
Expand Down Expand Up @@ -50,12 +53,8 @@ public <O extends ObjectType> ResourceSearchSpecification createSearchSpecificat
ResourceObjectSetType set, Task task, OperationResult opResult)
throws ActivityExecutionException, SchemaException {

ResourceObjectClassSpecification resourceObjectClassSpecification;
try {
resourceObjectClassSpecification = createObjectClassSpecInternal(set, false, task, opResult);
} catch (MaintenanceException e) {
throw new AssertionError(e);
}
ResourceObjectClassSpecification resourceObjectClassSpecification =
createObjectClassSpecInternal(set, false, task, opResult);

ObjectQuery basicQuery = resourceObjectClassSpecification.createBasicQuery();
ObjectQuery query;
Expand All @@ -82,7 +81,7 @@ public <O extends ObjectType> ResourceSearchSpecification createSearchSpecificat
@NotNull
public ResourceObjectClassSpecification createObjectClassSpec(@NotNull ResourceObjectSetType resourceObjectSet,
Task task, OperationResult opResult)
throws ActivityExecutionException, MaintenanceException {
throws ActivityExecutionException {
ResourceObjectClassSpecification objectClassSpec =
createObjectClassSpecInternal(resourceObjectSet, true, task, opResult);

Expand All @@ -93,12 +92,12 @@ public ResourceObjectClassSpecification createObjectClassSpec(@NotNull ResourceO
@NotNull
private ResourceObjectClassSpecification createObjectClassSpecInternal(@NotNull ResourceObjectSetType resourceObjectSet,
boolean checkForMaintenance, Task task, OperationResult opResult)
throws ActivityExecutionException, MaintenanceException {
throws ActivityExecutionException {

String resourceOid = getResourceOid(resourceObjectSet);
ResourceType resource = getResource(resourceOid, task, opResult);
if (checkForMaintenance) {
ResourceTypeUtil.checkNotInMaintenance(resource);
checkNotInMaintenance(resource);
}

RefinedResourceSchema refinedSchema = getRefinedResourceSchema(resource);
Expand All @@ -120,10 +119,10 @@ private ResourceObjectClassSpecification createObjectClassSpecInternal(@NotNull

@NotNull
public ResourceObjectClassSpecification createObjectClassSpecForShadow(ShadowType shadow, Task task, OperationResult opResult)
throws ActivityExecutionException, MaintenanceException, SchemaException {
throws ActivityExecutionException, SchemaException {
String resourceOid = ShadowUtil.getResourceOid(shadow);
ResourceType resource = getResource(resourceOid, task, opResult);
ResourceTypeUtil.checkNotInMaintenance(resource);
checkNotInMaintenance(resource);
RefinedResourceSchema refinedSchema = getRefinedResourceSchema(resource);

// TODO reconsider the algorithm used for deriving object class
Expand Down Expand Up @@ -179,4 +178,13 @@ public ResourceObjectClassSpecification createObjectClassSpecForShadow(ShadowTyp
PERMANENT_ERROR);
}
}

/**
* This method is to be used on the activity start. So it should fail gracefully - maintenance is not a fatal error here.
*/
static void checkNotInMaintenance(ResourceType resource) throws ActivityExecutionException {
if (isInMaintenance(resource)) {
throw new ActivityExecutionException("Resource is in maintenance", HANDLED_ERROR, TEMPORARY_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public boolean importSingleShadow(String shadowOid, Task task, OperationResult p
result.computeStatusIfUnknown();
return !result.isError();
} catch (ActivityExecutionException t) {
result.recordFatalError(t);
result.recordStatus(t.getOpResultStatus(), t.getMessage(), t);
throw new SystemException(t); // FIXME unwrap the exception
} catch (Throwable t) {
result.recordFatalError(t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import static com.evolveum.midpoint.prism.PrismObject.cast;
import static com.evolveum.midpoint.schema.GetOperationOptions.disableReadOnly;
import static com.evolveum.midpoint.schema.util.ResourceTypeUtil.checkNotInMaintenance;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -322,7 +321,8 @@ public <T extends ObjectType> String addObject(PrismObject<T> object, OperationP
SynchronizationOperationResult liveSyncResult;

try {
PrismObject<ResourceType> resource = getResource(resourceOid, task, result); // TODO avoid double fetching the resource
// TODO avoid double fetching the resource
PrismObject<ResourceType> resource = getObject(ResourceType.class, resourceOid, null, task, result);

LOGGER.debug("Start synchronization of {}", resource);
liveSyncResult = liveSynchronizer.synchronize(shadowCoordinates, task, simulate, handler, result);
Expand All @@ -347,12 +347,6 @@ public <T extends ObjectType> String addObject(PrismObject<T> object, OperationP
return new SynchronizationResult(liveSyncResult.getChangesProcessed());
}

private PrismObject<ResourceType> getResource(String resourceOid, Task task, OperationResult result) throws ObjectNotFoundException, CommunicationException, SchemaException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
PrismObject<ResourceType> resource = getObject(ResourceType.class, resourceOid, null, task, result);
checkNotInMaintenance(resource);
return resource;
}

@Override
public void processAsynchronousUpdates(@NotNull ResourceShadowDiscriminator shadowCoordinates,
@NotNull AsyncUpdateEventHandler handler, @NotNull Task task, @NotNull OperationResult parentResult)
Expand Down

0 comments on commit f20721d

Please sign in to comment.