Search in sources :

Example 1 with DEFRAGMENTATION_MNTC_TASK_NAME

use of org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.DEFRAGMENTATION_MNTC_TASK_NAME in project ignite by apache.

the class IgniteDefragmentationImpl method cancel.

/**
 * {@inheritDoc}
 */
@Override
public CancelResult cancel() throws IgniteCheckedException {
    final MaintenanceRegistry maintenanceRegistry = ctx.maintenanceRegistry();
    if (!maintenanceRegistry.isMaintenanceMode()) {
        boolean deleted = maintenanceRegistry.unregisterMaintenanceTask(DEFRAGMENTATION_MNTC_TASK_NAME);
        return deleted ? CancelResult.CANCELLED_SCHEDULED : CancelResult.SCHEDULED_NOT_FOUND;
    } else {
        List<MaintenanceAction<?>> actions;
        try {
            actions = maintenanceRegistry.actionsForMaintenanceTask(DEFRAGMENTATION_MNTC_TASK_NAME);
        } catch (IgniteException e) {
            return CancelResult.COMPLETED_OR_CANCELLED;
        }
        Optional<MaintenanceAction<?>> stopAct = actions.stream().filter(a -> "stop".equals(a.name())).findAny();
        assert stopAct.isPresent();
        try {
            Object res = stopAct.get().execute();
            assert res instanceof Boolean;
            boolean cancelled = (Boolean) res;
            return cancelled ? CancelResult.CANCELLED : CancelResult.COMPLETED_OR_CANCELLED;
        } catch (Exception e) {
            throw new IgniteCheckedException("Exception occurred: " + e.getMessage(), e);
        }
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) HashMap(java.util.HashMap) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) GridKernalContext(org.apache.ignite.internal.GridKernalContext) DefragmentationParameters.toStore(org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters.toStore) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) List(java.util.List) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) Status(org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.Status) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) Map(java.util.Map) Optional(java.util.Optional) Collections(java.util.Collections) DEFRAGMENTATION_MNTC_TASK_NAME(org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.DEFRAGMENTATION_MNTC_TASK_NAME) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Aggregations

Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 DEFRAGMENTATION_MNTC_TASK_NAME (org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.DEFRAGMENTATION_MNTC_TASK_NAME)1 Status (org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager.Status)1 DefragmentationParameters.toStore (org.apache.ignite.internal.processors.cache.persistence.defragmentation.maintenance.DefragmentationParameters.toStore)1 MaintenanceAction (org.apache.ignite.maintenance.MaintenanceAction)1 MaintenanceRegistry (org.apache.ignite.maintenance.MaintenanceRegistry)1 MaintenanceTask (org.apache.ignite.maintenance.MaintenanceTask)1