Search in sources :

Example 1 with MaintenanceAction

use of org.apache.ignite.maintenance.MaintenanceAction 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)

Example 2 with MaintenanceAction

use of org.apache.ignite.maintenance.MaintenanceAction in project ignite by apache.

the class WalEnableDisableWithNodeShutdownTest method startNodeWithMaintenance.

/**
 */
private Ignite startNodeWithMaintenance(String consistentId) throws Exception {
    Ignite node;
    try {
        node = Ignition.start(igniteCfg(false, consistentId));
    } catch (Exception ex) {
        assertTrue(X.hasCause(ex, "Cache groups with potentially corrupted partition files", IgniteException.class));
        node = Ignition.start(igniteCfg(false, consistentId));
        node.compute().run(new IgniteRunnable() {

            /**
             */
            @IgniteInstanceResource
            private Ignite ignite;

            /**
             */
            @Override
            public void run() {
                MaintenanceRegistry mntcRegistry = ((IgniteEx) ignite).context().maintenanceRegistry();
                List<MaintenanceAction<?>> actions = mntcRegistry.actionsForMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
                actions.stream().filter(a -> a.name().equals(CleanCacheStoresMaintenanceAction.ACTION_NAME)).findFirst().get().execute();
                mntcRegistry.unregisterMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
            }
        });
        node.close();
        node = Ignition.start(igniteCfg(false, consistentId));
    }
    return node;
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteException(org.apache.ignite.IgniteException) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) CleanCacheStoresMaintenanceAction(org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction) X(org.apache.ignite.internal.util.typedef.X) After(org.junit.After) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) LinkedList(java.util.LinkedList) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheMode(org.apache.ignite.cache.CacheMode) CORRUPTED_DATA_FILES_MNTC_TASK_NAME(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CORRUPTED_DATA_FILES_MNTC_TASK_NAME) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) CleanCacheStoresMaintenanceAction(org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction) Ignite(org.apache.ignite.Ignite) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 3 with MaintenanceAction

use of org.apache.ignite.maintenance.MaintenanceAction in project ignite by apache.

the class MaintenanceProcessor method registerWorkflowCallback.

/**
 * {@inheritDoc}
 */
@Override
public void registerWorkflowCallback(@NotNull String maintenanceTaskName, @NotNull MaintenanceWorkflowCallback cb) {
    if (disabled)
        throw new IgniteException(DISABLED_ERR_MSG);
    List<MaintenanceAction<?>> actions = cb.allActions();
    if (actions == null || actions.isEmpty())
        throw new IgniteException("Maintenance workflow callback should provide at least one maintenance action");
    int size = actions.size();
    long distinctSize = actions.stream().map(MaintenanceAction::name).distinct().count();
    if (distinctSize < size)
        throw new IgniteException("All actions of a single workflow should have unique names: " + actions.stream().map(MaintenanceAction::name).collect(Collectors.joining(", ")));
    Optional<String> wrongActionName = actions.stream().map(MaintenanceAction::name).filter(name -> !U.alphanumericUnderscore(name)).findFirst();
    if (wrongActionName.isPresent())
        throw new IgniteException("All actions' names should contain only alphanumeric and underscore symbols: " + wrongActionName.get());
    workflowCallbacks.put(maintenanceTaskName, cb);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) U(org.apache.ignite.internal.util.typedef.internal.U) IOException(java.io.IOException) MaintenanceTask(org.apache.ignite.maintenance.MaintenanceTask) Collectors(java.util.stream.Collectors) GridKernalContext(org.apache.ignite.internal.GridKernalContext) MaintenanceWorkflowCallback(org.apache.ignite.maintenance.MaintenanceWorkflowCallback) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) Map(java.util.Map) CU(org.apache.ignite.internal.util.typedef.internal.CU) Optional(java.util.Optional) GridProcessorAdapter(org.apache.ignite.internal.processors.GridProcessorAdapter) NotNull(org.jetbrains.annotations.NotNull) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) IgniteException(org.apache.ignite.IgniteException)

Example 4 with MaintenanceAction

use of org.apache.ignite.maintenance.MaintenanceAction in project ignite by apache.

the class WalEnableDisableWithRestartsTest method startNodeWithMaintenance.

/**
 */
private Ignite startNodeWithMaintenance(String consistentId) throws Exception {
    Ignite node;
    try {
        node = Ignition.start(igniteCfg(false, consistentId));
    } catch (Exception ex) {
        if (!X.hasCause(ex, "Cache groups with potentially corrupted partition files", IgniteException.class))
            throw ex;
        node = Ignition.start(igniteCfg(false, consistentId));
        node.compute().run(new IgniteRunnable() {

            /**
             */
            @IgniteInstanceResource
            private Ignite ignite;

            /**
             */
            @Override
            public void run() {
                MaintenanceRegistry mntcRegistry = ((IgniteEx) ignite).context().maintenanceRegistry();
                List<MaintenanceAction<?>> actions = mntcRegistry.actionsForMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
                actions.stream().filter(a -> a.name().equals(CleanCacheStoresMaintenanceAction.ACTION_NAME)).findFirst().get().execute();
                mntcRegistry.unregisterMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
            }
        });
        node.close();
        node = Ignition.start(igniteCfg(false, consistentId));
    }
    return node;
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteException(org.apache.ignite.IgniteException) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) CleanCacheStoresMaintenanceAction(org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction) X(org.apache.ignite.internal.util.typedef.X) After(org.junit.After) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) LinkedList(java.util.LinkedList) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheMode(org.apache.ignite.cache.CacheMode) CORRUPTED_DATA_FILES_MNTC_TASK_NAME(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CORRUPTED_DATA_FILES_MNTC_TASK_NAME) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) CleanCacheStoresMaintenanceAction(org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction) Ignite(org.apache.ignite.Ignite) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Aggregations

List (java.util.List)4 IgniteException (org.apache.ignite.IgniteException)4 MaintenanceAction (org.apache.ignite.maintenance.MaintenanceAction)4 MaintenanceRegistry (org.apache.ignite.maintenance.MaintenanceRegistry)4 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Ignite (org.apache.ignite.Ignite)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 Ignition (org.apache.ignite.Ignition)2 CacheAtomicityMode (org.apache.ignite.cache.CacheAtomicityMode)2 CacheMode (org.apache.ignite.cache.CacheMode)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)2 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 GridKernalContext (org.apache.ignite.internal.GridKernalContext)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 CleanCacheStoresMaintenanceAction (org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction)2 CORRUPTED_DATA_FILES_MNTC_TASK_NAME (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CORRUPTED_DATA_FILES_MNTC_TASK_NAME)2