phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [phoenix-queryserver] swaroopak commented on a change in pull request #5: PHOENIX-5255: Create Orchestrator for QueryServerCanaryTool in phoenix-queryserver project
Date Tue, 30 Apr 2019 03:46:43 GMT
swaroopak commented on a change in pull request #5: PHOENIX-5255: Create Orchestrator for QueryServerCanaryTool
in phoenix-queryserver project
URL: https://github.com/apache/phoenix-queryserver/pull/5#discussion_r279606603
 
 

 ##########
 File path: queryserver-orchestrator/src/main/java/org/apache/phoenix/queryserver/orchestrator/TestExecutorClient.java
 ##########
 @@ -0,0 +1,122 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.phoenix.queryserver.orchestrator;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.recipes.leader.CancelLeadershipException;
+import org.apache.curator.framework.recipes.leader.LeaderSelector;
+import org.apache.curator.framework.recipes.leader.LeaderSelectorListenerAdapter;
+import org.apache.curator.framework.state.ConnectionState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+public class TestExecutorClient extends LeaderSelectorListenerAdapter implements Closeable
{
+
+    private static final Logger logger = LoggerFactory.getLogger(TestExecutorClient.class);
+    private final LeaderSelector leaderSelector;
+
+    private Map<String, String> params;
+    private  ToolWrapper toolWrapper;
+
+    public TestExecutorClient(CuratorFramework client, String path, Map<String, String>
params, ToolWrapper tool) {
+
+        // create a leader selector using the given path for management
+        // all participants in a given leader selection must use the same path
+        // ExampleClient here is also a LeaderSelectorListener but this isn't required
+        this.leaderSelector = new LeaderSelector(client, path, this);
+
+        // for most cases you will want your instance to requeue when it relinquishes leadership
+        this.leaderSelector.autoRequeue();
+
+        this.params = params;
+        this.toolWrapper = tool;
+    }
+
+    public void start() {
+        // the selection for this instance doesn't start until the leader selector is started
+        // leader selection is done in the background so this call to leaderSelector.start()
+        // returns immediately
+        leaderSelector.start();
+    }
+
+    public void close() {
+        leaderSelector.close();
+    }
+
+    @Override
+    public void takeLeadership(CuratorFramework client) throws Exception {
+        // we are now the leader. This method should not return until we want to relinquish
+        // leadership
+        logger.info("Took leadership.");
+
+        while (true) {
+            logger.info("Starting test case suite execution.");
+
+            executeQueryServerCanaryTool();
+
+            logger.info("Test suite execution completed. Waiting for " + params.get("interval")
+                    + " secs before executing next run.");
+
+            TimeUnit.SECONDS.sleep(Integer.parseInt(params.get("interval")));
+        }
+    }
+
+    @Override
+    public void stateChanged(CuratorFramework client, ConnectionState newState) {
+        logger.info("ZK Connection State Changed to [{}]", newState.name());
+        switch(newState) {
+            case CONNECTED:
+                logger.info("The host became the leader at " +System.currentTimeMillis());
+                break;
+            case LOST:
+                logger.info("The host lost leadership at "+ System.currentTimeMillis());
+                throw new CancelLeadershipException();
 
 Review comment:
   yet to be addressed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message