Ошибка при создании результата коллекции SqlPredicate в Hazelcast - PullRequest
1 голос
/ 22 октября 2019

Я пытаюсь выполнить простую операцию поиска на карте с помощью Hazelcast SqlPredicate. Кажется, что я столкнулся с некоторой ошибкой, которую я не могу устранить. Вот пример программы, которую я использовал для Hazelcast Cloud.

Программа, подключающаяся к кластеру, успешно подтверждает соединение, получая мою пару значений тестового ключа. Затем, когда я применяю SQLPredicate, он выдает ошибку. Я в настоящее время только несколько дней в Hazelcast, поэтому не уверен, что идет не так в моем коде.

    package com.bsfi.java.client;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
import java.util.UUID;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.client.spi.impl.discovery.HazelcastCloudDiscovery;
import com.hazelcast.client.spi.properties.ClientProperty;
import com.hazelcast.config.GroupConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.query.SqlPredicate;

import java.io.Serializable;

class SampleHazelObject implements Serializable {

    private static final long serialVersionUID = 1L;
    private String schemaName;
    private String sourceId;
    private String sourceData;
    private String timestamp;

    public SampleHazelObject(String schemaName, String sourceId, String sourceData, String timestamp) {
        this.sourceId = sourceId;
        this.schemaName = schemaName; 
        this.sourceData = sourceData;
        this.timestamp = timestamp;
    }

    public String getSourceId() {
        return sourceId;
    }

    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }

    public String getSchemaName() {
        return schemaName;
    }

    public void setSchemaName(String schemaName) {
        this.schemaName = schemaName;
    }

    public String getSourceData() {
        return sourceData;
    }

    public void setSourceData(String sourceData) {
        this.sourceData = sourceData;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }




}


public class ErrorDemo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        String clusterName = "hazelhack";
        String  clusterPassword = "XXXXXXXXXX";
        String discoveryToken = "XXXXXXXXXXX";

        ClientConfig config = new ClientConfig();
        config.setGroupConfig(new GroupConfig(clusterName, clusterPassword));
        config.setProperty("hazelcast.client.statistics.enabled","true");
        config.setProperty(ClientProperty.HAZELCAST_CLOUD_DISCOVERY_TOKEN.getName(), discoveryToken);
        config.setProperty(HazelcastCloudDiscovery.CLOUD_URL_BASE_PROPERTY.getName(), "https://coordinator.hazelcast.cloud");
        HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
        IMap<String, SampleHazelObject> mapEntity = client.getMap("SchemaEntity");

        //      Adding a key value here
        mapEntity.put("keytest", new SampleHazelObject("Entity","9999999999","test data",new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date())));

        System.out.println("Data....: "+mapEntity.get("keytest").getSourceId());
        if(mapEntity.get("keytest").getSourceId().equals("9999999999")) {
            System.out.println("Connection Successful!");
            System.out.println("Now, `map` as one Entity data.");
        }
        else {
            throw new RuntimeException("Connection failed, check your configuration.");
        }

    // Writing completed. Let us try some lookup and querying on the data
    Collection<SampleHazelObject> objHazelList = mapEntity.values(new SqlPredicate("SourceId = '9999999999'" ));

    for(SampleHazelObject hazelObj:  objHazelList) {
    System.out.println("value=" + hazelObj.getSourceData());
    }

    }

}



    class loader for SampleHazelObject : sun.misc.Launcher$AppClassLoader@73d16e93
Oct 23, 2019 7:00:37 AM com.hazelcast.client.HazelcastClient
INFO: hz.client_0 [hazelhack] [3.12.2] A non-empty group password is configured for the Hazelcast client. Starting with Hazelcast version 3.11, clients with the same group name, but with different group passwords (that do not use authentication) will be accepted to a cluster. The group password configuration will be removed completely in a future release.
Oct 23, 2019 7:00:38 AM com.hazelcast.client.spi.ClientInvocationService
INFO: hz.client_0 [hazelhack] [3.12.2] Running with 2 response threads, dynamic=false
Oct 23, 2019 7:00:38 AM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [hazelhack] [3.12.2] HazelcastClient 3.12.2 (20190802 - e34b163) is STARTING
Oct 23, 2019 7:00:38 AM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [hazelhack] [3.12.2] HazelcastClient 3.12.2 (20190802 - e34b163) is STARTED
Oct 23, 2019 7:00:38 AM com.hazelcast.client.connection.nio.ClusterConnectorService
INFO: hz.client_0 [hazelhack] [3.12.2] Trying to connect to cluster with name: hazelhack
Oct 23, 2019 7:00:40 AM com.hazelcast.client.connection.nio.ClusterConnectorService
INFO: hz.client_0 [hazelhack] [3.12.2] Trying to connect to [100.103.97.104]:31629 as owner member
Oct 23, 2019 7:00:42 AM com.hazelcast.client.connection.ClientConnectionManager
INFO: hz.client_0 [hazelhack] [3.12.2] Setting ClientConnection{alive=true, connectionId=1, channel=NioChannel{/192.168.0.104:50119->/3.92.127.167:31629}, remoteEndpoint=[100.103.97.104]:31629, lastReadTime=2019-10-23 07:00:42.092, lastWriteTime=2019-10-23 07:00:41.690, closedTime=never, connected server version=3.12.2} as owner with principal ClientPrincipal{uuid='19d729c6-99c9-4a0e-8a5d-69e6e69c4d4c', ownerUuid='ff72f0dc-664e-4b81-876f-3f4be292136d'}
Oct 23, 2019 7:00:42 AM com.hazelcast.client.connection.ClientConnectionManager
INFO: hz.client_0 [hazelhack] [3.12.2] Authenticated with server [100.103.97.104]:31629, server version:3.12.2 Local address: /192.168.0.104:50119
Oct 23, 2019 7:00:42 AM com.hazelcast.client.spi.impl.ClientMembershipListener
INFO: hz.client_0 [hazelhack] [3.12.2] 

Members [1] {
    Member [100.103.97.104]:31629 - ff72f0dc-664e-4b81-876f-3f4be292136d
}

Oct 23, 2019 7:00:42 AM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [hazelhack] [3.12.2] HazelcastClient 3.12.2 (20190802 - e34b163) is CLIENT_CONNECTED
Oct 23, 2019 7:00:42 AM com.hazelcast.internal.diagnostics.Diagnostics
INFO: hz.client_0 [hazelhack] [3.12.2] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
Oct 23, 2019 7:00:42 AM com.hazelcast.client.impl.statistics.Statistics
INFO: Client statistics is enabled with period 3 seconds.
Data....: 9999999999
Connection Successful!
Now, `map` as one Entity data.
Exception in thread "main" com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: Failed to load class com.bsfi.java.client.SampleHazelObject from other members
    at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:88)
    at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:77)
    at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
    at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:187)
    at com.hazelcast.query.impl.CachedQueryEntry.getValue(CachedQueryEntry.java:75)
    at com.hazelcast.query.impl.CachedQueryEntry.getTargetObject(CachedQueryEntry.java:108)
    at com.hazelcast.query.impl.QueryableEntry.extractAttributeValue(QueryableEntry.java:105)
    at com.hazelcast.query.impl.QueryableEntry.getAttributeValue(QueryableEntry.java:61)
    at com.hazelcast.query.impl.predicates.AbstractPredicate.readAttributeValue(AbstractPredicate.java:145)
    at com.hazelcast.query.impl.predicates.AbstractPredicate.apply(AbstractPredicate.java:62)
    at com.hazelcast.map.impl.query.PartitionScanRunner.run(PartitionScanRunner.java:101)
    at com.hazelcast.map.impl.query.HDPartitionScanExecutor.execute(HDPartitionScanExecutor.java:22)
    at com.hazelcast.map.impl.query.QueryRunner.runPartitionIndexOrPartitionScanQueryOnGivenOwnedPartition(QueryRunner.java:192)
    at com.hazelcast.map.impl.query.HDQueryPartitionOperation.runInternal(HDQueryPartitionOperation.java:28)
    at com.hazelcast.map.impl.operation.HDMapOperation.run(HDMapOperation.java:88)
    at com.hazelcast.spi.Operation.call(Operation.java:170)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:210)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:199)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:147)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:125)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110)
    at ------ submitted from ------.(Unknown Source)
    at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolve(InvocationFuture.java:126)
    at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveAndThrowIfException(InvocationFuture.java:79)
    at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:155)
    at com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.collectResultsFromMissingPartitions(AbstractMapQueryMessageTask.java:260)
    at com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.invokeOnMissingPartitions(AbstractMapQueryMessageTask.java:135)
    at com.hazelcast.client.impl.protocol.task.map.AbstractMapQueryMessageTask.call(AbstractMapQueryMessageTask.java:99)
    at com.hazelcast.client.impl.protocol.task.AbstractCallableMessageTask.processMessage(AbstractCallableMessageTask.java:35)
    at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.initializeAndProcessMessage(AbstractMessageTask.java:129)
    at com.hazelcast.client.impl.protocol.task.AbstractMessageTask.run(AbstractMessageTask.java:109)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
    at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:64)
    at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:80)
    at ------ submitted from ------.(Unknown Source)
    at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:96)
    at com.hazelcast.client.spi.impl.ClientInvocationFuture.resolveAndThrowIfException(ClientInvocationFuture.java:33)
    at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:163)
    at com.hazelcast.client.spi.ClientProxy.invoke(ClientProxy.java:252)
    at com.hazelcast.client.proxy.ClientMapProxy.invokeWithPredicate(ClientMapProxy.java:1379)
    at com.hazelcast.client.proxy.ClientMapProxy.values(ClientMapProxy.java:1367)
    at com.bsfi.java.client.ErrorDemo.main(ErrorDemo.java:115)
Caused by: java.lang.ClassNotFoundException: Failed to load class com.bsfi.java.client.SampleHazelObject from other members
    at com.hazelcast.internal.usercodedeployment.impl.ClassLocator.tryToGetClassFromRemote(ClassLocator.java:157)
    at com.hazelcast.internal.usercodedeployment.impl.ClassLocator.handleClassNotFoundException(ClassLocator.java:95)
    at com.hazelcast.internal.usercodedeployment.UserCodeDeploymentService.handleClassNotFoundException(UserCodeDeploymentService.java:89)
    at com.hazelcast.internal.usercodedeployment.UserCodeDeploymentClassLoader.loadClass(UserCodeDeploymentClassLoader.java:57)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:288)
    at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:252)
    at com.hazelcast.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:699)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1866)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1749)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2040)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1571)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:431)
    at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:84)
    at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:77)
    at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:48)
    at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:187)
    at com.hazelcast.query.impl.CachedQueryEntry.getValue(CachedQueryEntry.java:75)
    at com.hazelcast.query.impl.CachedQueryEntry.getTargetObject(CachedQueryEntry.java:108)
    at com.hazelcast.query.impl.QueryableEntry.extractAttributeValue(QueryableEntry.java:105)
    at com.hazelcast.query.impl.QueryableEntry.getAttributeValue(QueryableEntry.java:61)
    at com.hazelcast.query.impl.predicates.AbstractPredicate.readAttributeValue(AbstractPredicate.java:145)
    at com.hazelcast.query.impl.predicates.AbstractPredicate.apply(AbstractPredicate.java:62)
    at com.hazelcast.map.impl.query.PartitionScanRunner.run(PartitionScanRunner.java:101)
    at com.hazelcast.map.impl.query.HDPartitionScanExecutor.execute(HDPartitionScanExecutor.java:22)
    at com.hazelcast.map.impl.query.QueryRunner.runPartitionIndexOrPartitionScanQueryOnGivenOwnedPartition(QueryRunner.java:192)
    at com.hazelcast.map.impl.query.HDQueryPartitionOperation.runInternal(HDQueryPartitionOperation.java:28)
    at com.hazelcast.map.impl.operation.HDMapOperation.run(HDMapOperation.java:88)
    at com.hazelcast.spi.Operation.call(Operation.java:170)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.call(OperationRunnerImpl.java:210)
    at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:199)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:147)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:125)
    at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:110)

Ответы [ 2 ]

0 голосов
/ 05 ноября 2019

Вам необходимо загрузить com.bsfi.java.client.SampleHazelObject в кластер перед использованием карты. Используйте UserCodeDeployment для загрузки определения класса в работающем кластере, см. Здесь: https://docs.hazelcast.org/docs/3.12.4/manual/html-single/index.html#member-user-code-deployment-beta

0 голосов
/ 22 октября 2019

Весь показанный код ссылается на SampleHazelObject, но сообщения журнала указывают на то, что он пытается загрузить HazelObject, который нигде не отображается и не ссылается ни на что, что я вижу.

Возможно ли, что файл jar, развернутый в облаке, имеет другую (переименованную) версию этого класса, чем та, которая работает на клиенте?

...