Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented MID-3188: Notify by e-mail when error occured to speed up…
… reaction in production
- Loading branch information
Showing
6 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
...fications-api/src/main/java/com/evolveum/midpoint/notifications/api/events/TaskEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright (c) 2010-2016 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.notifications.api.events; | ||
|
||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.schema.result.OperationResult; | ||
import com.evolveum.midpoint.schema.result.OperationResultStatus; | ||
import com.evolveum.midpoint.task.api.LightweightIdentifierGenerator; | ||
import com.evolveum.midpoint.task.api.Task; | ||
import com.evolveum.midpoint.task.api.TaskRunResult; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.*; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* @author mederly | ||
*/ | ||
public class TaskEvent extends BaseEvent { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(TaskEvent.class); | ||
|
||
@NotNull private final Task task; | ||
@Nullable private final TaskRunResult taskRunResult; // nullable only if operationType == ADD | ||
@NotNull private final EventOperationType operationType; // only ADD or DELETE | ||
|
||
public TaskEvent(LightweightIdentifierGenerator lightweightIdentifierGenerator, @NotNull Task task, @Nullable TaskRunResult runResult, | ||
@NotNull EventOperationType operationType, String channel) { | ||
super(lightweightIdentifierGenerator); | ||
this.task = task; | ||
this.taskRunResult = runResult; | ||
this.operationType = operationType; | ||
setChannel(channel); | ||
} | ||
|
||
@NotNull | ||
public Task getTask() { | ||
return task; | ||
} | ||
|
||
@Nullable | ||
public TaskRunResult getTaskRunResult() { | ||
return taskRunResult; | ||
} | ||
|
||
@NotNull | ||
public EventOperationType getOperationType() { | ||
return operationType; | ||
} | ||
|
||
public boolean isTemporaryError() { | ||
return taskRunResult != null && taskRunResult.getRunResultStatus() == TaskRunResult.TaskRunResultStatus.TEMPORARY_ERROR; | ||
} | ||
|
||
public boolean isPermanentError() { | ||
return taskRunResult != null && taskRunResult.getRunResultStatus() == TaskRunResult.TaskRunResultStatus.PERMANENT_ERROR; | ||
} | ||
|
||
public boolean isFinished() { | ||
return taskRunResult != null && | ||
(taskRunResult.getRunResultStatus() == TaskRunResult.TaskRunResultStatus.FINISHED || | ||
taskRunResult.getRunResultStatus() == TaskRunResult.TaskRunResultStatus.FINISHED_HANDLER); | ||
} | ||
|
||
public boolean isInterrupted() { | ||
return taskRunResult != null && taskRunResult.getRunResultStatus() == TaskRunResult.TaskRunResultStatus.INTERRUPTED; | ||
} | ||
|
||
public boolean isRestartRequested() { | ||
return taskRunResult != null && taskRunResult.getRunResultStatus() == TaskRunResult.TaskRunResultStatus.RESTART_REQUESTED; | ||
} | ||
|
||
@Override | ||
public boolean isStatusType(EventStatusType eventStatusType) { | ||
if (eventStatusType == null) { | ||
return false; | ||
} | ||
if (taskRunResult == null) { | ||
return eventStatusType == EventStatusType.SUCCESS || eventStatusType == EventStatusType.ALSO_SUCCESS || eventStatusType == EventStatusType.IN_PROGRESS; | ||
} | ||
OperationResult result = taskRunResult.getOperationResult(); | ||
switch (eventStatusType) { | ||
case SUCCESS: | ||
case ALSO_SUCCESS: return result.isSuccess() || result.isHandledError() || result.isWarning(); | ||
case IN_PROGRESS: return false; | ||
case FAILURE: return result.isError(); | ||
case ONLY_FAILURE: return result.isFatalError(); | ||
default: throw new IllegalStateException("Invalid eventStatusType: " + eventStatusType); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isOperationType(EventOperationType eventOperationType) { | ||
return this.operationType == eventOperationType; | ||
} | ||
|
||
@Override | ||
public boolean isCategoryType(EventCategoryType eventCategoryType) { | ||
return eventCategoryType == EventCategoryType.TASK_EVENT; | ||
} | ||
|
||
@Override | ||
public boolean isRelatedToItem(ItemPath itemPath) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isUserRelated() { | ||
return false; | ||
} | ||
|
||
public OperationResultStatus getOperationResultStatus() { | ||
return taskRunResult != null && taskRunResult.getOperationResult() != null ? taskRunResult.getOperationResult().getStatus() : null; | ||
} | ||
|
||
public String getMessage() { | ||
return taskRunResult != null && taskRunResult.getOperationResult() != null ? taskRunResult.getOperationResult().getMessage() : null; | ||
} | ||
|
||
public long getProgress() { | ||
return taskRunResult != null ? taskRunResult.getProgress() : task.getProgress(); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...impl/src/main/java/com/evolveum/midpoint/notifications/impl/NotificationTaskListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (c) 2010-2016 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.notifications.impl; | ||
|
||
import com.evolveum.midpoint.notifications.api.NotificationManager; | ||
import com.evolveum.midpoint.notifications.api.events.TaskEvent; | ||
import com.evolveum.midpoint.task.api.*; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.EventOperationType; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
/** | ||
* One of interfaces of the notifier to midPoint. | ||
* | ||
* Used to catch task-related events. | ||
* | ||
* @author mederly | ||
*/ | ||
@Component | ||
public class NotificationTaskListener implements TaskListener { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(NotificationTaskListener.class); | ||
private static final String OPERATION_PROCESS_EVENT = NotificationTaskListener.class.getName() + "." + "processEvent"; | ||
|
||
@Autowired | ||
private LightweightIdentifierGenerator lightweightIdentifierGenerator; | ||
|
||
@Autowired | ||
private NotificationManager notificationManager; | ||
|
||
@Autowired | ||
private NotificationsUtil notificationsUtil; | ||
|
||
@Autowired | ||
private TaskManager taskManager; | ||
|
||
@PostConstruct | ||
public void init() { | ||
taskManager.registerTaskListener(this); | ||
LOGGER.trace("Task listener registered."); | ||
} | ||
|
||
@Override | ||
public void onTaskStart(Task task) { | ||
createAndProcessEvent(task, null, EventOperationType.ADD); | ||
} | ||
|
||
@Override | ||
public void onTaskFinish(Task task, TaskRunResult runResult) { | ||
createAndProcessEvent(task, runResult, EventOperationType.DELETE); | ||
} | ||
|
||
private void createAndProcessEvent(Task task, TaskRunResult runResult, EventOperationType operationType) { | ||
TaskEvent event = new TaskEvent(lightweightIdentifierGenerator, task, runResult, operationType, task.getChannel()); | ||
|
||
if (task.getOwner() != null) { | ||
event.setRequester(new SimpleObjectRefImpl(notificationsUtil, task.getOwner().asObjectable())); | ||
event.setRequestee(new SimpleObjectRefImpl(notificationsUtil, task.getOwner().asObjectable())); | ||
} else { | ||
LOGGER.debug("No owner for task " + task + ", therefore no requester and requestee will be set for event " + event.getId()); | ||
} | ||
|
||
Task opTask = taskManager.createTaskInstance(OPERATION_PROCESS_EVENT); | ||
notificationManager.processEvent(event, opTask, opTask.getResult()); | ||
} | ||
|
||
@Override | ||
public void onTaskThreadStart(Task task, boolean isRecovering) { | ||
// not implemented | ||
} | ||
|
||
@Override | ||
public void onTaskThreadFinish(Task task) { | ||
// not implemented | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.