Search in sources :

Example 1 with GridClientClusterState

use of org.apache.ignite.internal.client.GridClientClusterState in project ignite by apache.

the class ChangeStateCommandHandlerTest method testActivateDeActivate.

/**
     *
     */
public void testActivateDeActivate() throws GridClientException {
    GridClientClusterState state = client.state();
    boolean active = state.active();
    assertTrue(active);
    state.active(false);
    IgniteEx ig1 = grid(0);
    IgniteEx ig2 = grid(1);
    assertFalse(ig1.active());
    assertFalse(ig2.active());
    assertFalse(state.active());
    state.active(true);
    assertTrue(ig1.active());
    assertTrue(ig2.active());
    assertTrue(state.active());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) GridClientClusterState(org.apache.ignite.internal.client.GridClientClusterState)

Example 2 with GridClientClusterState

use of org.apache.ignite.internal.client.GridClientClusterState in project ignite by apache.

the class CommandHandler method main.

/**
     * @param args Args.
     */
public static void main(String[] args) throws GridClientException {
    String host = "127.0.0.1";
    String port = "11212";
    Boolean activate = null;
    if (args.length == 1 && "help".equals(args[0])) {
        System.out.println("Example: --host {ip} --port {port} --{activate/deactivate} " + "or without command --host {ip} --port {port} then will print status.");
        return;
    }
    if (args.length > 5)
        throw new IllegalArgumentException("incorrect number of arguments");
    for (int i = 0; i < args.length; i++) {
        String str = args[i];
        if ("--host".equals(str))
            host = args[i + 1];
        else if ("--port".equals(str))
            port = args[i + 1];
        else if ("--activate".equals(str))
            activate = true;
        else if ("--deactivate".equals(str))
            activate = false;
    }
    if (host == null)
        throw new IllegalArgumentException("host can not be empty");
    if (port == null)
        throw new IllegalArgumentException("port can not be empty");
    GridClientConfiguration cfg = new GridClientConfiguration();
    cfg.setServers(Collections.singletonList(host + ":" + port));
    try (GridClient client = GridClientFactory.start(cfg)) {
        GridClientClusterState state = client.state();
        if (activate != null)
            try {
                state.active(activate);
                System.out.println(host + ":" + port + " - was " + (activate ? "activate" : "deactivate"));
            } catch (Exception e) {
                System.out.println("Something fail during " + (activate ? "activation" : "deactivation") + ", exception message: " + e.getMessage());
            }
        else
            System.out.println(host + ":" + port + " - " + (state.active() ? "active" : "inactive"));
    }
}
Also used : GridClientClusterState(org.apache.ignite.internal.client.GridClientClusterState) GridClient(org.apache.ignite.internal.client.GridClient) GridClientConfiguration(org.apache.ignite.internal.client.GridClientConfiguration) GridClientException(org.apache.ignite.internal.client.GridClientException)

Aggregations

GridClientClusterState (org.apache.ignite.internal.client.GridClientClusterState)2 IgniteEx (org.apache.ignite.internal.IgniteEx)1 GridClient (org.apache.ignite.internal.client.GridClient)1 GridClientConfiguration (org.apache.ignite.internal.client.GridClientConfiguration)1 GridClientException (org.apache.ignite.internal.client.GridClientException)1