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);
}
}
}
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;
}
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);
}
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;
}
Aggregations