DonTequila
DonTequila

Reputation: 162

Ignite ClusterGroup.forAttribute works for client nodes?

I just learned in another question that I can run compute tasks on client nodes, which is great. However, I don't want to execute tasks on all clients, only selected client nodes. I identify nodes by attributes in their config:

<property name="userAttributes">
    <map>
        <entry key="Role" value="FOR_COMPUTE" />
    </map>
</property>

Then I use:

ignite.cluster().forClients().forAttribute("Role", "FOR_COMPUTE");

This doesn't seem to get me a clusergroup with those clients that have the attribute set. Does this not work for client nodes?

Upvotes: 1

Views: 181

Answers (1)

Alex K
Alex K

Reputation: 841

The user attributes do work. Double check your setup. Make sure you are starting your client with the correct config.

Run the following test:

        IgniteConfiguration serverConfig = new IgniteConfiguration();
        serverConfig.setIgniteInstanceName("server");
        Ignition.start(serverConfig);


        IgniteConfiguration clientConfig = new IgniteConfiguration();
        clientConfig.setClientMode(true);
        clientConfig.setIgniteInstanceName("client");

        Map<String, String> userAttributes = new HashMap<>();
        userAttributes.put("Role", "FOR_COMPUTE");
        clientConfig.setUserAttributes(userAttributes);


        Ignite ignite = Ignition.start(clientConfig);
        System.out.println("Role user attribute value: " + ignite.cluster().localNode().attribute("Role"));
        ClusterGroup filteredNodes = ignite.cluster().forClients().forAttribute("Role", "FOR_COMPUTE");
        for (ClusterNode node:  filteredNodes.nodes()) {
            System.out.println("filtered id: "+ node.id());
        }

You should see the correct results.

Upvotes: 1

Related Questions