NSAmelchev commented on a change in pull request #7358: IGNITE-12614 : Disallow 
silent deactivation of cluster to prevent in-mem data loss.
URL: https://github.com/apache/ignite/pull/7358#discussion_r375281032
 
 

 ##########
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/commandline/DeactivateCommand.java
 ##########
 @@ -59,25 +69,51 @@
      * @param clientCfg Client configuration.
      * @throws Exception If failed to deactivate.
      */
-    @Override public Object execute(GridClientConfiguration clientCfg, Logger 
logger) throws Exception {
-        logger.warning("Command deprecated. Use " + SET_STATE.toString() + " 
instead.");
+    @Override public Object execute(GridClientConfiguration clientCfg, Logger 
log) throws Exception {
+        log.warning("Command deprecated. Use " + SET_STATE.toString() + " 
instead.");
 
         try (GridClient client = Command.startClient(clientCfg)) {
+
+            //Search for in-memory-only caches. Warn of possible data loss.
+            if (!force) {
+                String msg = 
ClusterStateChangeCommand.isClusterReadyForDeactivation((cls) -> {
+                    try {
+                        return TaskExecutor.executeTask(client, cls, null, 
clientCfg);
+                    }
+                    catch (GridClientException e) {
+                        throw new RuntimeException("Failed to launch task for 
checking check if cluster is ready for deactivation.", e);
+                    }
+                });
+                if (!msg.isEmpty())
+                    throw new IllegalStateException(msg + " Type --force to 
proceed.");
+            }
+
             GridClientClusterState state = client.state();
 
             state.active(false);
 
-            logger.info("Cluster deactivated");
+            log.info("Cluster deactivated.");
         }
         catch (Exception e) {
-            logger.severe("Failed to deactivate cluster.");
+            log.severe("Failed to deactivate cluster.");
 
             throw e;
         }
 
         return null;
     }
 
+    /** {@inheritDoc} */
+    @Override public void parseArguments(CommandArgIterator argIter) {
+        if (argIter.hasNextArg()) {
+            String arg = argIter.peekNextArg();
+            if ("--force".equalsIgnoreCase(arg)) {
 
 Review comment:
   Can we define the force command as an static var?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to