-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IGNITE-18312 [IEP-81] Use IgniteClient instead of GridClient in contr…
…ol-utility (#11648)
- Loading branch information
1 parent
12cc804
commit 789ef9f
Showing
58 changed files
with
904 additions
and
317 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
92 changes: 92 additions & 0 deletions
92
...-utility/src/main/java/org/apache/ignite/internal/commandline/CliIgniteClientInvoker.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,92 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.ignite.internal.commandline; | ||
|
||
import java.util.function.Consumer; | ||
import org.apache.ignite.Ignition; | ||
import org.apache.ignite.client.IgniteClient; | ||
import org.apache.ignite.configuration.ClientConfiguration; | ||
import org.apache.ignite.internal.client.GridClientNode; | ||
import org.apache.ignite.internal.client.GridClientNodeStateBeforeStart; | ||
import org.apache.ignite.internal.client.thin.TcpIgniteClient; | ||
import org.apache.ignite.internal.dto.IgniteDataTransferObject; | ||
import org.apache.ignite.internal.management.api.BeforeNodeStartCommand; | ||
import org.apache.ignite.internal.management.api.Command; | ||
import org.apache.ignite.internal.management.api.CommandInvoker; | ||
import org.apache.ignite.internal.management.api.CommandUtils; | ||
import org.apache.ignite.internal.util.typedef.F; | ||
import org.apache.ignite.internal.util.typedef.internal.U; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import static org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.MANAGEMENT_CLIENT_ATTR; | ||
|
||
/** | ||
* Adapter of new management API command for {@code control.sh} execution flow. | ||
*/ | ||
public class CliIgniteClientInvoker<A extends IgniteDataTransferObject> extends CommandInvoker<A> implements CloseableCliCommandInvoker { | ||
/** Client configuration. */ | ||
private final ClientConfiguration cfg; | ||
|
||
/** Client. */ | ||
private IgniteClient client; | ||
|
||
/** @param cmd Command to execute. */ | ||
public CliIgniteClientInvoker(Command<A, ?> cmd, A arg, ClientConfiguration cfg) { | ||
super(cmd, arg, null); | ||
|
||
this.cfg = cfg; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override protected GridClientNode defaultNode() { | ||
return CommandUtils.clusterToClientNode(igniteClient().cluster().forOldest().node()); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override protected @Nullable IgniteClient igniteClient() { | ||
if (client == null) { | ||
if (cmd instanceof BeforeNodeStartCommand) { | ||
cfg.setUserAttributes(F.asMap(MANAGEMENT_CLIENT_ATTR, Boolean.TRUE.toString())); | ||
cfg.setAutoBinaryConfigurationEnabled(false); | ||
} | ||
|
||
client = Ignition.startClient(cfg); | ||
} | ||
|
||
return client; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public String confirmationPrompt() { | ||
return cmd.confirmationPrompt(arg); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public <R> R invokeBeforeNodeStart(Consumer<String> printer) throws Exception { | ||
return ((BeforeNodeStartCommand<A, R>)cmd).execute(new GridClientNodeStateBeforeStart() { | ||
@Override public void stopWarmUp() { | ||
((TcpIgniteClient)igniteClient()).stopWarmUp(); | ||
} | ||
}, arg, printer); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override public void close() { | ||
U.closeQuiet(client); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...lity/src/main/java/org/apache/ignite/internal/commandline/CloseableCliCommandInvoker.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,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.ignite.internal.commandline; | ||
|
||
import java.util.function.Consumer; | ||
import org.apache.ignite.internal.management.api.CommandInvoker; | ||
|
||
/** | ||
* CLI command invoker. | ||
*/ | ||
public interface CloseableCliCommandInvoker extends AutoCloseable { | ||
/** @return Message text to show user for. {@code null} means that confirmantion is not required. */ | ||
String confirmationPrompt(); | ||
|
||
/** @see CommandInvoker#prepare(Consumer) */ | ||
boolean prepare(Consumer<String> printer) throws Exception; | ||
|
||
/** @see CommandInvoker#invoke(Consumer, boolean) */ | ||
<R> R invoke(Consumer<String> printer, boolean verbose) throws Exception; | ||
|
||
/** */ | ||
<R> R invokeBeforeNodeStart(Consumer<String> printer) throws Exception; | ||
} |
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
Oops, something went wrong.