Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate RunConsoleCommandMessageTask and RunScriptMessageTask from Bl…
…ockingMessageTask to hz:mc executor
- Loading branch information
Showing
8 changed files
with
228 additions
and
30 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
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
91 changes: 91 additions & 0 deletions
91
...src/main/java/com/hazelcast/internal/management/operation/RunConsoleCommandOperation.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,91 @@ | ||
/* | ||
* Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* 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.hazelcast.internal.management.operation; | ||
|
||
import com.hazelcast.internal.management.ConsoleCommandHandler; | ||
import com.hazelcast.internal.management.ManagementCenterService; | ||
import com.hazelcast.logging.ILogger; | ||
import com.hazelcast.spi.impl.NodeEngineImpl; | ||
import com.hazelcast.spi.impl.executionservice.ExecutionService; | ||
import com.hazelcast.spi.impl.operationservice.AbstractLocalOperation; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
import static com.hazelcast.internal.util.ExceptionUtil.peel; | ||
import static com.hazelcast.internal.util.ExceptionUtil.withTryCatch; | ||
import static com.hazelcast.internal.util.StringUtil.isNullOrEmpty; | ||
|
||
/** | ||
* Operation to run console command. The command is executed on {@link ExecutionService#MC_EXECUTOR} executor. | ||
*/ | ||
public class RunConsoleCommandOperation extends AbstractLocalOperation { | ||
|
||
private final String command; | ||
private final String namespace; | ||
|
||
public RunConsoleCommandOperation(String command, String namespace) { | ||
this.command = command; | ||
this.namespace = namespace; | ||
} | ||
|
||
@Override | ||
public void run() throws Exception { | ||
final ILogger logger = getNodeEngine().getLogger(getClass()); | ||
final ManagementCenterService mcService = ((NodeEngineImpl) getNodeEngine()).getManagementCenterService(); | ||
final ExecutionService executionService = getNodeEngine().getExecutionService(); | ||
|
||
Future<String> future = executionService.submit( | ||
ExecutionService.MC_EXECUTOR, | ||
() -> { | ||
ConsoleCommandHandler handler = mcService.getCommandHandler(); | ||
try { | ||
final String ns = namespace; | ||
String cmd = command; | ||
if (!isNullOrEmpty(ns)) { | ||
// set namespace as a part of the command | ||
cmd = ns + "__" + cmd; | ||
} | ||
return handler.handleCommand(cmd); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw e; | ||
} | ||
}); | ||
|
||
executionService.asCompletableFuture(future).whenComplete( | ||
withTryCatch( | ||
logger, | ||
(output, error) -> sendResponse(error != null ? peel(error) : output) | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public final Object getResponse() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public String getServiceName() { | ||
return ManagementCenterService.SERVICE_NAME; | ||
} | ||
|
||
@Override | ||
public boolean returnsResponse() { | ||
return false; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
hazelcast/src/main/java/com/hazelcast/internal/management/operation/RunScriptOperation.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,80 @@ | ||
/* | ||
* Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* 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.hazelcast.internal.management.operation; | ||
|
||
import com.hazelcast.internal.management.ManagementCenterService; | ||
import com.hazelcast.logging.ILogger; | ||
import com.hazelcast.spi.impl.executionservice.ExecutionService; | ||
import com.hazelcast.spi.impl.operationservice.AbstractLocalOperation; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
import static com.hazelcast.internal.util.ExceptionUtil.peel; | ||
import static com.hazelcast.internal.util.ExceptionUtil.withTryCatch; | ||
|
||
/** | ||
* Operation to execute script on the node. The script is executed on {@link ExecutionService#MC_EXECUTOR} executor. | ||
* <p> | ||
* Note: This operation reuses {@link ScriptExecutorOperation} to execute the script. | ||
* Once MC migrates to client comms, these classes can be merged. | ||
*/ | ||
public class RunScriptOperation extends AbstractLocalOperation { | ||
|
||
private final String engine; | ||
private final String script; | ||
|
||
public RunScriptOperation(String engine, String script) { | ||
this.engine = engine; | ||
this.script = script; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
final ILogger logger = getNodeEngine().getLogger(getClass()); | ||
final ExecutionService executionService = getNodeEngine().getExecutionService(); | ||
final ScriptExecutorOperation legacyOperation = new ScriptExecutorOperation(getNodeEngine(), engine, script); | ||
|
||
Future<Object> future = executionService.submit( | ||
ExecutionService.MC_EXECUTOR, | ||
() -> { | ||
legacyOperation.run(); | ||
return legacyOperation.getResponse(); | ||
}); | ||
|
||
executionService.asCompletableFuture(future).whenComplete( | ||
withTryCatch( | ||
logger, | ||
(result, error) -> sendResponse(error != null ? peel(error) : result) | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
public final Object getResponse() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public String getServiceName() { | ||
return ManagementCenterService.SERVICE_NAME; | ||
} | ||
|
||
@Override | ||
public boolean returnsResponse() { | ||
return false; | ||
} | ||
} |
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
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