Search in sources :

Example 1 with ClusterMetaEntity

use of org.apache.zeppelin.cluster.meta.ClusterMetaEntity in project zeppelin by apache.

the class ClusterManager method getClusterMeta.

// get metadata by cluster metadata
public HashMap<String, HashMap<String, Object>> getClusterMeta(ClusterMetaType metaType, String metaKey) {
    HashMap<String, HashMap<String, Object>> clusterMeta = new HashMap<>();
    if (!raftInitialized()) {
        LOGGER.error("Raft incomplete initialization!");
        return clusterMeta;
    }
    ClusterMetaEntity entity = new ClusterMetaEntity(GET_OPERATION, metaType, metaKey, null);
    byte[] mateData = null;
    try {
        mateData = raftSessionClient.execute(operation(ClusterStateMachine.GET, clientSerializer.encode(entity))).get(3, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage());
    } catch (ExecutionException e) {
        LOGGER.error(e.getMessage());
    } catch (TimeoutException e) {
        LOGGER.error(e.getMessage());
    }
    if (null != mateData) {
        clusterMeta = clientSerializer.decode(mateData);
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("getClusterMeta >>> {}", clusterMeta.toString());
    }
    return clusterMeta;
}
Also used : ClusterMetaEntity(org.apache.zeppelin.cluster.meta.ClusterMetaEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ClusterMetaEntity

use of org.apache.zeppelin.cluster.meta.ClusterMetaEntity in project zeppelin by apache.

the class ClusterManager method putClusterMeta.

// put metadata into cluster metadata
public void putClusterMeta(ClusterMetaType type, String key, HashMap<String, Object> values) {
    ClusterMetaEntity metaEntity = new ClusterMetaEntity(PUT_OPERATION, type, key, values);
    boolean result = putClusterMeta(metaEntity);
    if (false == result) {
        LOGGER.warn("putClusterMeta failure, Cache metadata to queue.");
        clusterMetaQueue.add(metaEntity);
    }
}
Also used : ClusterMetaEntity(org.apache.zeppelin.cluster.meta.ClusterMetaEntity)

Example 3 with ClusterMetaEntity

use of org.apache.zeppelin.cluster.meta.ClusterMetaEntity in project zeppelin by apache.

the class ClusterManager method deleteClusterMeta.

// delete metadata from cluster metadata
public void deleteClusterMeta(ClusterMetaType type, String key) {
    ClusterMetaEntity metaEntity = new ClusterMetaEntity(DELETE_OPERATION, type, key, null);
    boolean result = deleteClusterMeta(metaEntity);
    if (false == result) {
        LOGGER.warn("deleteClusterMeta faild, Cache data to queue.");
        clusterMetaQueue.add(metaEntity);
    }
}
Also used : ClusterMetaEntity(org.apache.zeppelin.cluster.meta.ClusterMetaEntity)

Example 4 with ClusterMetaEntity

use of org.apache.zeppelin.cluster.meta.ClusterMetaEntity in project zeppelin by apache.

the class ClusterManager method start.

public void start() {
    if (!zConf.isClusterMode()) {
        return;
    }
    // RaftClient Thread
    new Thread(new Runnable() {

        @Override
        public void run() {
            LOGGER.info("RaftClientThread run() >>>");
            int raftClientPort = 0;
            try {
                raftClientPort = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces();
            } catch (IOException e) {
                LOGGER.error(e.getMessage());
            }
            MemberId memberId = MemberId.from(zeplServerHost + ":" + raftClientPort);
            Address address = Address.from(zeplServerHost, raftClientPort);
            raftAddressMap.put(memberId, address);
            MessagingService messagingManager = NettyMessagingService.builder().withAddress(address).build().start().join();
            RaftClientProtocol protocol = new RaftClientMessagingProtocol(messagingManager, protocolSerializer, raftAddressMap::get);
            raftClient = RaftClient.builder().withMemberId(memberId).withPartitionId(PartitionId.from("partition", 1)).withProtocol(protocol).build();
            raftClient.connect(clusterMemberIds).join();
            raftSessionClient = createProxy(raftClient);
            LOGGER.info("RaftClientThread run() <<<");
        }
    }).start();
    // Cluster Meta Consume Thread
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                while (getRunning().get()) {
                    ClusterMetaEntity metaEntity = clusterMetaQueue.peek();
                    if (null != metaEntity) {
                        // Determine whether the client is connected
                        int retry = 0;
                        while (!raftInitialized()) {
                            retry++;
                            if (0 == retry % 30) {
                                LOGGER.warn("Raft incomplete initialization! retry[{}]", retry);
                            }
                            Thread.sleep(100);
                        }
                        boolean success = false;
                        switch(metaEntity.getOperation()) {
                            case DELETE_OPERATION:
                                success = deleteClusterMeta(metaEntity);
                                break;
                            case PUT_OPERATION:
                                success = putClusterMeta(metaEntity);
                                break;
                        }
                        if (true == success) {
                            // The operation was successfully deleted
                            clusterMetaQueue.remove(metaEntity);
                            LOGGER.info("Cluster Meta Consume success! {}", metaEntity);
                        } else {
                            LOGGER.error("Cluster Meta Consume faild!");
                        }
                    } else {
                        Thread.sleep(100);
                    }
                }
            } catch (InterruptedException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }).start();
}
Also used : RaftClientProtocol(io.atomix.protocols.raft.protocol.RaftClientProtocol) Address(io.atomix.utils.net.Address) InetAddress(java.net.InetAddress) IOException(java.io.IOException) MessagingService(io.atomix.cluster.messaging.MessagingService) NettyMessagingService(io.atomix.cluster.messaging.impl.NettyMessagingService) MemberId(io.atomix.cluster.MemberId) ClusterMetaEntity(org.apache.zeppelin.cluster.meta.ClusterMetaEntity) RaftClientMessagingProtocol(org.apache.zeppelin.cluster.protocol.RaftClientMessagingProtocol)

Aggregations

ClusterMetaEntity (org.apache.zeppelin.cluster.meta.ClusterMetaEntity)4 MemberId (io.atomix.cluster.MemberId)1 MessagingService (io.atomix.cluster.messaging.MessagingService)1 NettyMessagingService (io.atomix.cluster.messaging.impl.NettyMessagingService)1 RaftClientProtocol (io.atomix.protocols.raft.protocol.RaftClientProtocol)1 Address (io.atomix.utils.net.Address)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 RaftClientMessagingProtocol (org.apache.zeppelin.cluster.protocol.RaftClientMessagingProtocol)1