“Ignite ClusterGroup.forAttribute”适用于客户端节点吗?

huangapple go评论61阅读模式
英文:

Ignite ClusterGroup.forAttribute works for client nodes?

问题

我刚刚在另一个问题中了解到我可以在客户端节点上运行计算任务,这非常好。
然而,我不想在所有客户端上执行任务,只想在选定的客户端节点上执行。我通过其配置中的属性来识别节点:

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

然后我使用:

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

这似乎不能让我得到具有设置属性的那些客户端的集群组。这对于客户端节点不起作用吗?

英文:

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:

&lt;property name=&quot;userAttributes&quot;&gt;
	&lt;map&gt;
		&lt;entry key=&quot;Role&quot; value=&quot;FOR_COMPUTE&quot; /&gt;
	&lt;/map&gt;
&lt;/property&gt;

Then I use:

ignite.cluster().forClients().forAttribute(&quot;Role&quot;, &quot;FOR_COMPUTE&quot;);

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

答案1

得分: 1

用户属性确实起作用。
仔细检查您的设置。确保您使用正确的配置启动客户端。

运行以下测试:

        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());
        }

您应该会看到正确的结果。

英文:

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(&quot;server&quot;);
        Ignition.start(serverConfig);


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

        Map&lt;String, String&gt; userAttributes = new HashMap&lt;&gt;();
        userAttributes.put(&quot;Role&quot;, &quot;FOR_COMPUTE&quot;);
        clientConfig.setUserAttributes(userAttributes);


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

You should see the correct results.

huangapple
  • 本文由 发表于 2020年9月18日 22:20:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/63957546.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定