geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject geode git commit: GEODE-3284: Initial GetAvailableServers Operation commit
Date Mon, 31 Jul 2017 16:24:02 GMT
Repository: geode
Updated Branches:
  refs/heads/feature/GEODE-3284 [created] 43591b3b0


GEODE-3284: Initial GetAvailableServers Operation commit


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/43591b3b
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/43591b3b
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/43591b3b

Branch: refs/heads/feature/GEODE-3284
Commit: 43591b3b0d2daf8fa92e8d6d23bac081c5c3c378
Parents: 0debd20
Author: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Authored: Mon Jul 31 09:23:53 2017 -0700
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Mon Jul 31 09:23:53 2017 -0700

----------------------------------------------------------------------
 .../GetAvailableServersOperationHandler.java    |  83 ++++++++++++++
 .../registry/OperationContextRegistry.java      |   6 +
 .../utilities/ProtobufRequestUtilities.java     |  26 +++--
 .../protobuf/utilities/ProtobufUtilities.java   |  48 ++++----
 geode-protobuf/src/main/proto/basicTypes.proto  |   3 +-
 .../src/main/proto/clientProtocol.proto         |  10 +-
 geode-protobuf/src/main/proto/region_API.proto  |   8 --
 geode-protobuf/src/main/proto/server_API.proto  |   4 +-
 .../protocol/GetAvailableServersDUnitTest.java  | 113 +++++++++++++++++++
 ...ailableServersOperationHandlerJUnitTest.java | 105 +++++++++++++++++
 10 files changed, 350 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandler.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandler.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandler.java
new file mode 100644
index 0000000..30cec43
--- /dev/null
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandler.java
@@ -0,0 +1,83 @@
+/*
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.geode.protocol.protobuf.operations;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.client.internal.locator.GetAllServersRequest;
+import org.apache.geode.cache.client.internal.locator.GetAllServersResponse;
+import org.apache.geode.distributed.internal.ServerLocation;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.distributed.internal.tcpserver.TcpClient;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.protocol.operations.OperationHandler;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.Failure;
+import org.apache.geode.protocol.protobuf.Result;
+import org.apache.geode.protocol.protobuf.ServerAPI;
+import org.apache.geode.protocol.protobuf.Success;
+import org.apache.geode.serialization.SerializationService;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+public class GetAvailableServersOperationHandler implements OperationHandler<ServerAPI.GetAvailableServersRequest,ServerAPI.GetAvailableServersResponse>
{
+
+  @Override
+  public Result<ServerAPI.GetAvailableServersResponse> process(
+      SerializationService serializationService, ServerAPI.GetAvailableServersRequest request,
+      Cache cache) {
+
+    //TODO Iterate over "known" locators, connect to first one and execute "GetAllServersRequest"
message
+    /*
+    InternalDistributedSystem distributedSystem =
+        (InternalDistributedSystem) cache.getDistributedSystem();
+    Properties properties = distributedSystem.getProperties();
+    String locatorsString = properties.getProperty(ConfigurationProperties.LOCATORS);*/
+
+    InternalDistributedMember
+        coordinator =
+        ((GemFireCacheImpl) cache).getDistributionManager().getMembershipManager().getView()
+            .getCoordinator();
+
+    TcpClient tcpClient = getTcpClient();
+    try {
+      GetAllServersResponse getAllServersResponse =
+          (GetAllServersResponse) tcpClient.requestToServer(coordinator.getInetAddress(),
coordinator.getPort(),
+              new GetAllServersRequest(), 1000, true);
+      Collection<BasicTypes.Server> servers =
+          (Collection<BasicTypes.Server>) getAllServersResponse.getServers().stream()
+              .map(serverLocation -> getServerProtobufMessage(
+                  (ServerLocation) serverLocation)).collect(Collectors.toList());
+      ServerAPI.GetAvailableServersResponse.Builder builder =
+          ServerAPI.GetAvailableServersResponse.newBuilder().addAllServers(servers);
+      return Success.of(builder.build());
+    } catch (IOException | ClassNotFoundException e) {
+        return Failure.of(BasicTypes.ErrorResponse.newBuilder().setMessage(e.getMessage()).build());
+    }
+  }
+
+  protected TcpClient getTcpClient() {
+    return new TcpClient();
+  }
+
+  private BasicTypes.Server getServerProtobufMessage(ServerLocation serverLocation) {
+    BasicTypes.Server.Builder serverBuilder = BasicTypes.Server.newBuilder();
+    serverBuilder.setHostname(serverLocation.getHostName()).setPort(serverLocation.getPort());
+    return serverBuilder.build();
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/registry/OperationContextRegistry.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/registry/OperationContextRegistry.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/registry/OperationContextRegistry.java
index 37bb322..dd6a392 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/registry/OperationContextRegistry.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/registry/OperationContextRegistry.java
@@ -22,6 +22,7 @@ import org.apache.geode.protocol.protobuf.ClientProtocol;
 import org.apache.geode.protocol.protobuf.ClientProtocol.Request.RequestAPICase;
 import org.apache.geode.protocol.protobuf.OperationContext;
 import org.apache.geode.protocol.protobuf.operations.GetAllRequestOperationHandler;
+import org.apache.geode.protocol.protobuf.operations.GetAvailableServersOperationHandler;
 import org.apache.geode.protocol.protobuf.operations.GetRegionNamesRequestOperationHandler;
 import org.apache.geode.protocol.protobuf.operations.GetRegionRequestOperationHandler;
 import org.apache.geode.protocol.protobuf.operations.GetRequestOperationHandler;
@@ -75,5 +76,10 @@ public class OperationContextRegistry {
         new OperationContext<>(ClientProtocol.Request::getGetRegionRequest,
             new GetRegionRequestOperationHandler(),
             opsResp -> ClientProtocol.Response.newBuilder().setGetRegionResponse(opsResp)));
+
+    operationContexts.put(RequestAPICase.GETAVAILABLESERVERSREQUEST,
+        new OperationContext<>(ClientProtocol.Request::getGetAvailableServersRequest,
+            new GetAvailableServersOperationHandler(),
+            opsResp-> ClientProtocol.Response.newBuilder().setGetAvailableServersResponse(opsResp)));
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java
index 01be750..02be007 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufRequestUtilities.java
@@ -14,11 +14,12 @@
  */
 package org.apache.geode.protocol.protobuf.utilities;
 
-import java.util.Set;
-
 import org.apache.geode.protocol.protobuf.BasicTypes;
 import org.apache.geode.protocol.protobuf.ClientProtocol;
 import org.apache.geode.protocol.protobuf.RegionAPI;
+import org.apache.geode.protocol.protobuf.ServerAPI;
+
+import java.util.Set;
 
 /**
  * This class contains helper functions for generating ClientProtocol.Request objects
@@ -29,13 +30,12 @@ import org.apache.geode.protocol.protobuf.RegionAPI;
 public abstract class ProtobufRequestUtilities {
   /**
    * Creates a request object containing a RegionAPI.GetRequest
-   * 
    * @param regionName - Name of the region being fetched from
    * @param key - Encoded key, see createEncodedValue in {@link ProtobufRequestUtilities}
    * @return Request object containing the passed params.
    */
   public static ClientProtocol.Request createGetRequest(String regionName,
-      BasicTypes.EncodedValue key) {
+                                                        BasicTypes.EncodedValue key) {
     RegionAPI.GetRequest getRequest =
         RegionAPI.GetRequest.newBuilder().setRegionName(regionName).setKey(key).build();
     return ClientProtocol.Request.newBuilder().setGetRequest(getRequest).build();
@@ -43,13 +43,12 @@ public abstract class ProtobufRequestUtilities {
 
   /**
    * Creates a request object containing a RegionAPI.RemoveRequest
-   * 
    * @param regionName - Name of the region being deleted from
    * @param key - Encoded key, see createEncodedValue in {@link ProtobufRequestUtilities}
    * @return Request object containing the passed params.
    */
   public static ClientProtocol.Request createRemoveRequest(String regionName,
-      BasicTypes.EncodedValue key) {
+                                                           BasicTypes.EncodedValue key) {
     RegionAPI.RemoveRequest removeRequest =
         RegionAPI.RemoveRequest.newBuilder().setRegionName(regionName).setKey(key).build();
     return ClientProtocol.Request.newBuilder().setRemoveRequest(removeRequest).build();
@@ -57,7 +56,6 @@ public abstract class ProtobufRequestUtilities {
 
   /**
    * Creates a request object containing a RegionAPI.GetRegionNamesRequest
-   * 
    * @return Request object for a getRegionNames operation
    */
   public static RegionAPI.GetRegionNamesRequest createGetRegionNamesRequest() {
@@ -66,7 +64,6 @@ public abstract class ProtobufRequestUtilities {
 
   /**
    * Creates a request object containing a RegionAPI.PutRequest
-   * 
    * @param region - Name of the region to put data in
    * @param entry - Encoded key,value pair, see createEntry in {@link ProtobufRequestUtilities}
    * @return Request object containing the passed params.
@@ -79,13 +76,12 @@ public abstract class ProtobufRequestUtilities {
 
   /**
    * Create a request to get the values for multiple keys
-   * 
    * @param regionName - Name of the region to fetch from
    * @param keys - Set of keys being fetched
    * @return Request object containing the getAll request
    */
   public static RegionAPI.GetAllRequest createGetAllRequest(String regionName,
-      Set<BasicTypes.EncodedValue> keys) {
+                                                            Set<BasicTypes.EncodedValue>
keys) {
     RegionAPI.GetAllRequest.Builder getAllRequestBuilder =
         RegionAPI.GetAllRequest.newBuilder().setRegionName(regionName);
     getAllRequestBuilder.addAllKey(keys);
@@ -94,16 +90,22 @@ public abstract class ProtobufRequestUtilities {
 
   /**
    * Create a request to insert multiple entries in a region
-   * 
    * @param regionName - Region to which entries are being added
    * @param entries - key, value pairs to add to the region
    * @return Request object containing the putAll request for the passed parameters
    */
   public static ClientProtocol.Request createPutAllRequest(String regionName,
-      Set<BasicTypes.Entry> entries) {
+                                                           Set<BasicTypes.Entry> entries)
{
     RegionAPI.PutAllRequest.Builder putAllRequestBuilder =
         RegionAPI.PutAllRequest.newBuilder().setRegionName(regionName);
     putAllRequestBuilder.addAllEntry(entries);
     return ClientProtocol.Request.newBuilder().setPutAllRequest(putAllRequestBuilder).build();
   }
+
+  public static ServerAPI.GetAvailableServersRequest createGetAvailableServersRequest() {
+    ServerAPI.GetAvailableServersRequest.Builder
+        builder =
+        ServerAPI.GetAvailableServersRequest.newBuilder();
+    return builder.build();
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java
b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java
index c7bf6aa..bb59fa5 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/utilities/ProtobufUtilities.java
@@ -15,6 +15,7 @@
 package org.apache.geode.protocol.protobuf.utilities;
 
 import com.google.protobuf.ByteString;
+
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionAttributes;
 import org.apache.geode.protocol.protobuf.BasicTypes;
@@ -29,24 +30,22 @@ import org.apache.geode.serialization.registry.exception.CodecNotRegisteredForTy
 /**
  * This class contains helper functions for assistance in creating protobuf objects. This
class is
  * mainly focused on helper functions which can be used in building BasicTypes for use in
other
- * messages or those used to create the top level Message objects.
- * <p>
- * Helper functions specific to creating ClientProtocol.Responses can be found at
- * {@link ProtobufResponseUtilities} Helper functions specific to creating ClientProtocol.Requests
- * can be found at {@link ProtobufRequestUtilities}
+ * messages or those used to create the top level Message objects. <p> Helper functions
specific to
+ * creating ClientProtocol.Responses can be found at {@link ProtobufResponseUtilities} Helper
+ * functions specific to creating ClientProtocol.Requests can be found at {@link
+ * ProtobufRequestUtilities}
  */
 public abstract class ProtobufUtilities {
   /**
    * Creates a object containing the type and value encoding of a piece of data
-   *
    * @param serializationService - object which knows how to encode objects for the protobuf
-   *        protocol {@link ProtobufSerializationService}
+   * protocol {@link ProtobufSerializationService}
    * @param unencodedValue - the value object which is to be encoded
    * @return a protobuf EncodedValue object
    * @throws UnsupportedEncodingTypeException - The object passed doesn't have a corresponding
-   *         SerializationType
+   * SerializationType
    * @throws CodecNotRegisteredForTypeException - There isn't a protobuf codec for the
-   *         SerializationType of the passed object
+   * SerializationType of the passed object
    */
   public static BasicTypes.EncodedValue createEncodedValue(
       SerializationService serializationService, Object unencodedValue)
@@ -60,31 +59,29 @@ public abstract class ProtobufUtilities {
 
   /**
    * Creates a protobuf key,value pair from an encoded key and value
-   *
    * @param key - an EncodedValue containing the key of the entry
    * @param value - an EncodedValue containing the value of the entry
    * @return a protobuf Entry object containing the passed key and value
    */
   public static BasicTypes.Entry createEntry(BasicTypes.EncodedValue key,
-      BasicTypes.EncodedValue value) {
+                                             BasicTypes.EncodedValue value) {
     return BasicTypes.Entry.newBuilder().setKey(key).setValue(value).build();
   }
 
   /**
    * Creates a protobuf key,value pair from unencoded data
-   *
    * @param serializationService - object which knows how to encode objects for the protobuf
-   *        protocol {@link ProtobufSerializationService}
+   * protocol {@link ProtobufSerializationService}
    * @param unencodedKey - the unencoded key for the entry
    * @param unencodedValue - the unencoded value for the entry
    * @return a protobuf Entry containing the encoded key and value
    * @throws UnsupportedEncodingTypeException - The key or value passed doesn't have a corresponding
-   *         SerializationType
+   * SerializationType
    * @throws CodecNotRegisteredForTypeException - There isn't a protobuf codec for the
-   *         SerializationType of the passed key or value
+   * SerializationType of the passed key or value
    */
   public static BasicTypes.Entry createEntry(SerializationService serializationService,
-      Object unencodedKey, Object unencodedValue)
+                                             Object unencodedKey, Object unencodedValue)
       throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
     return createEntry(createEncodedValue(serializationService, unencodedKey),
         createEncodedValue(serializationService, unencodedValue));
@@ -92,7 +89,6 @@ public abstract class ProtobufUtilities {
 
   /**
    * This creates a protobuf message containing a ClientProtocol.Response
-   *
    * @param messageHeader - The header for the message
    * @param response - The response for the message
    * @return a protobuf Message containing the above parameters
@@ -105,7 +101,6 @@ public abstract class ProtobufUtilities {
 
   /**
    * This creates a protobuf message containing a ClientProtocol.Request
-   *
    * @param messageHeader - The header for the message
    * @param request - The request for the message
    * @return a protobuf Message containing the above parameters
@@ -118,7 +113,6 @@ public abstract class ProtobufUtilities {
 
   /**
    * This creates a protobuf message containing a ClientProtocol.Request
-   *
    * @param getAllRequest - The request for the message
    * @return a protobuf Message containing the above parameters
    */
@@ -129,7 +123,6 @@ public abstract class ProtobufUtilities {
 
   /**
    * This builds the MessageHeader for a response which matches an incoming request
-   *
    * @param request - The request message that we're responding to.
    * @return the MessageHeader the response to the passed request
    */
@@ -140,7 +133,6 @@ public abstract class ProtobufUtilities {
 
   /**
    * This creates a MessageHeader
-   *
    * @param correlationId - An identifier used to correlate requests and responses
    * @return a MessageHeader containing the above parameters
    */
@@ -150,18 +142,17 @@ public abstract class ProtobufUtilities {
 
   /**
    * This will return the object encoded in a protobuf EncodedValue
-   *
    * @param serializationService - object which knows how to encode objects for the protobuf
-   *        protocol {@link ProtobufSerializationService}
+   * protocol {@link ProtobufSerializationService}
    * @param encodedValue - The value to be decoded
    * @return the object encoded in the passed encodedValue
    * @throws UnsupportedEncodingTypeException - There isn't a SerializationType matching
the
-   *         encodedValues type
+   * encodedValues type
    * @throws CodecNotRegisteredForTypeException - There isn't a protobuf codec for the
-   *         SerializationType matching the encodedValues type
+   * SerializationType matching the encodedValues type
    */
   public static Object decodeValue(SerializationService serializationService,
-      BasicTypes.EncodedValue encodedValue)
+                                   BasicTypes.EncodedValue encodedValue)
       throws UnsupportedEncodingTypeException, CodecNotRegisteredForTypeException {
     BasicTypes.EncodingType encoding = encodedValue.getEncodingType();
     byte[] bytes = encodedValue.getValue().toByteArray();
@@ -169,7 +160,6 @@ public abstract class ProtobufUtilities {
   }
 
   /**
-   * @param region
    * @return a Protobuf BasicTypes.Region message that represents the {@link Region}
    */
   public static BasicTypes.Region createRegionMessageFromRegion(Region region) {
@@ -197,4 +187,8 @@ public abstract class ProtobufUtilities {
     return ClientProtocol.Request.newBuilder().setGetRegionNamesRequest(getRegionNamesRequest)
         .build();
   }
+
+  public static ClientProtocol.Request.Builder createProtobufRequestBuilder() {
+    return ClientProtocol.Request.newBuilder();
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/main/proto/basicTypes.proto
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/proto/basicTypes.proto b/geode-protobuf/src/main/proto/basicTypes.proto
index ad254cd..a9d07d8 100644
--- a/geode-protobuf/src/main/proto/basicTypes.proto
+++ b/geode-protobuf/src/main/proto/basicTypes.proto
@@ -61,7 +61,8 @@ message Region {
 }
 
 message Server {
-    string url = 1;
+    string hostname = 1;
+    int32 port = 2;
 }
 
 message ErrorResponse {

http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/main/proto/clientProtocol.proto
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/proto/clientProtocol.proto b/geode-protobuf/src/main/proto/clientProtocol.proto
index 6b037ca..c64d4de 100644
--- a/geode-protobuf/src/main/proto/clientProtocol.proto
+++ b/geode-protobuf/src/main/proto/clientProtocol.proto
@@ -43,13 +43,12 @@ message Request {
         GetAllRequest getAllRequest = 5;
         RemoveRequest removeRequest = 6;
         RemoveAllRequest removeAllRequest = 7;
-        ListKeysRequest listKeysRequest = 8;
 
         CreateRegionRequest createRegionRequest = 21;
         DestroyRegionRequest destroyRegionRequest = 22;
 
-        PingRequest pingRequest = 41;
-        GetServersRequest getServersRequest = 42;
+//        PingRequest pingRequest = 41;
+        GetAvailableServersRequest getAvailableServersRequest = 42;
         GetRegionNamesRequest getRegionNamesRequest = 43;
         GetRegionRequest getRegionRequest = 44;
 
@@ -64,15 +63,14 @@ message Response {
         GetAllResponse getAllResponse = 5;
         RemoveResponse removeResponse = 6;
         RemoveAllResponse removeAllResponse = 7;
-        ListKeysResponse listKeysResponse = 8;
 
         ErrorResponse errorResponse = 13;
 
         CreateRegionResponse createRegionResponse = 20;
         DestroyRegionResponse destroyRegionResponse = 21;
 
-        PingResponse pingResponse = 41;
-        GetServersResponse getServersResponse = 42;
+//        PingResponse pingResponse = 41;
+        GetAvailableServersResponse getAvailableServersResponse = 42;
         GetRegionNamesResponse getRegionNamesResponse = 43;
         GetRegionResponse getRegionResponse = 44;
     }

http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/main/proto/region_API.proto
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/proto/region_API.proto b/geode-protobuf/src/main/proto/region_API.proto
index bf2c15e..2a93a7d 100644
--- a/geode-protobuf/src/main/proto/region_API.proto
+++ b/geode-protobuf/src/main/proto/region_API.proto
@@ -55,14 +55,6 @@ message GetAllResponse {
     repeated Entry entries = 1;
 }
 
-message ListKeysRequest {
-    string regionName = 1;
-}
-
-message ListKeysResponse {
-    repeated EncodedValue key = 1;
-}
-
 message RemoveRequest {
     string regionName = 1;
     EncodedValue key = 2;

http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/main/proto/server_API.proto
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/proto/server_API.proto b/geode-protobuf/src/main/proto/server_API.proto
index 8c4e345..81622cc 100644
--- a/geode-protobuf/src/main/proto/server_API.proto
+++ b/geode-protobuf/src/main/proto/server_API.proto
@@ -27,10 +27,10 @@ message PingResponse {
     int32 sequenceNumber = 1;
 }
 
-message GetServersRequest {
+message GetAvailableServersRequest {
 
 }
 
-message GetServersResponse {
+message GetAvailableServersResponse {
     repeated Server servers = 1;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/test/java/org/apache/geode/protocol/GetAvailableServersDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/GetAvailableServersDUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/protocol/GetAvailableServersDUnitTest.java
new file mode 100644
index 0000000..8b34ace
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/GetAvailableServersDUnitTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.geode.protocol;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.protocol.exception.InvalidProtocolMessageException;
+import org.apache.geode.protocol.protobuf.ClientProtocol;
+import org.apache.geode.protocol.protobuf.ServerAPI;
+import org.apache.geode.protocol.protobuf.serializer.ProtobufProtocolSerializer;
+import org.apache.geode.protocol.protobuf.utilities.ProtobufRequestUtilities;
+import org.apache.geode.protocol.protobuf.utilities.ProtobufUtilities;
+import org.apache.geode.test.dunit.DistributedTestUtils;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
+import org.apache.geode.test.dunit.rules.DistributedRestoreSystemProperties;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.IOException;
+import java.net.Socket;
+
+@Category(DistributedTest.class)
+public class GetAvailableServersDUnitTest extends JUnit4CacheTestCase {
+
+  @Rule
+  public DistributedRestoreSystemProperties
+      distributedRestoreSystemProperties =
+      new DistributedRestoreSystemProperties();
+
+  @Before
+  public void setup() {
+
+  }
+
+  @Test
+  public void testGetAllAvailableServersRequest()
+      throws IOException, InvalidProtocolMessageException {
+    Host host = Host.getHost(0);
+    VM vm0 = host.getVM(0);
+    VM vm1 = host.getVM(1);
+    VM vm2 = host.getVM(2);
+
+    int locatorPort = DistributedTestUtils.getDUnitLocatorPort();
+
+//    int cacheServer1Port = vm0.invoke("Start Cache1", () -> startCacheWithCacheServer());
+    int cacheServer1Port = startCacheWithCacheServer();
+    int cacheServer2Port = vm1.invoke("Start Cache2", () -> startCacheWithCacheServer());
+    int cacheServer3Port = vm2.invoke("Start Cache3", () -> startCacheWithCacheServer());
+
+    vm0.invoke(() -> {
+      Socket socket = new Socket(host.getHostName(), cacheServer1Port);
+      socket.getOutputStream().write(110);
+
+      ClientProtocol.Request.Builder protobufRequestBuilder =
+          ProtobufUtilities.createProtobufRequestBuilder();
+      ClientProtocol.Message
+          getAvailableServersRequestMessage =
+          ProtobufUtilities.createProtobufMessage(ProtobufUtilities.createMessageHeader(1233445),
+              protobufRequestBuilder.setGetAvailableServersRequest(
+                  ProtobufRequestUtilities.createGetAvailableServersRequest()).build());
+
+      ProtobufProtocolSerializer protobufProtocolSerializer = new ProtobufProtocolSerializer();
+      protobufProtocolSerializer
+          .serialize(getAvailableServersRequestMessage, socket.getOutputStream());
+
+      ClientProtocol.Message getAvailableServersResponseMessage =
+          protobufProtocolSerializer.deserialize(socket.getInputStream());
+      assertEquals(1233445,
+          getAvailableServersResponseMessage.getMessageHeader().getCorrelationId());
+      assertEquals(ClientProtocol.Message.MessageTypeCase.RESPONSE,
+          getAvailableServersResponseMessage.getMessageTypeCase());
+      ClientProtocol.Response messageResponse = getAvailableServersResponseMessage.getResponse();
+      assertEquals(ClientProtocol.Response.ResponseAPICase.GETAVAILABLESERVERSRESPONSE,
+          messageResponse.getResponseAPICase());
+      ServerAPI.GetAvailableServersResponse
+          getAvailableServersResponse =
+          messageResponse.getGetAvailableServersResponse();
+      assertEquals(3, getAvailableServersResponse.getServersCount());
+    });
+  }
+
+  private Integer startCacheWithCacheServer() throws IOException {
+    System.setProperty("geode.feature-protobuf-protocol", "true");
+
+    InternalCache cache = getCache();
+    CacheServer cacheServer = cache.addCacheServer();
+    cacheServer.setPort(0);
+    cacheServer.start();
+    return cacheServer.getPort();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/43591b3b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandlerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandlerJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandlerJUnitTest.java
new file mode 100644
index 0000000..c973c72
--- /dev/null
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/operations/GetAvailableServersOperationHandlerJUnitTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.geode.protocol.protobuf.operations;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.sun.tools.javac.util.List;
+import org.apache.geode.cache.client.internal.locator.GetAllServersResponse;
+import org.apache.geode.distributed.internal.DM;
+import org.apache.geode.distributed.internal.ServerLocation;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
+import org.apache.geode.distributed.internal.membership.MembershipManager;
+import org.apache.geode.distributed.internal.membership.NetView;
+import org.apache.geode.distributed.internal.tcpserver.TcpClient;
+import org.apache.geode.internal.cache.CacheServerImpl;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.protocol.protobuf.BasicTypes;
+import org.apache.geode.protocol.protobuf.Result;
+import org.apache.geode.protocol.protobuf.ServerAPI;
+import org.apache.geode.protocol.protobuf.ServerAPI.GetAvailableServersResponse;
+import org.apache.geode.protocol.protobuf.Success;
+import org.apache.geode.protocol.protobuf.utilities.ProtobufRequestUtilities;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.mockito.invocation.InvocationOnMock;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.ArrayList;
+
+@Category(UnitTest.class)
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(GetAvailableServersOperationHandler.class)
+public class GetAvailableServersOperationHandlerJUnitTest extends OperationHandlerJUnitTest
{
+
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+  }
+
+  @Test
+  public void testServerReturnedFromHandler() throws Exception {
+    operationHandler = mock(GetAvailableServersOperationHandler.class);
+    cacheStub = mock(GemFireCacheImpl.class);
+    when(operationHandler.process(any(), any(), any())).thenCallRealMethod();
+
+    CacheServerImpl mockCacheServer = mock(CacheServerImpl.class);
+    DM mockDM = mock(DM.class);
+    MembershipManager mockMembershipManager = mock(MembershipManager.class);
+    NetView mockView = mock(NetView.class);
+    InternalDistributedMember mockCoordinator = mock(InternalDistributedMember.class);
+    TcpClient mockTCPClient = PowerMockito.mock(TcpClient.class, (InvocationOnMock invocation)
-> new GetAllServersResponse(new ArrayList(List.of(new ServerLocation("hostname1", 12345),
+        new ServerLocation("hostname2", 23456)))));
+
+    when(cacheStub.getCacheServers()).thenReturn(List.of(mockCacheServer));
+    when(mockCacheServer.getExternalAddress()).thenReturn("externalHostName");
+    when(mockCacheServer.getPort()).thenReturn(23456);
+    when(((GemFireCacheImpl) cacheStub).getDistributionManager()).thenReturn(mockDM);
+    when(mockDM.getMembershipManager()).thenReturn(mockMembershipManager);
+    when(mockMembershipManager.getView()).thenReturn(mockView);
+    when(mockView.getCoordinator()).thenReturn(mockCoordinator);
+
+    when(((GetAvailableServersOperationHandler) operationHandler).getTcpClient())
+        .thenReturn(mockTCPClient);
+
+    ServerAPI.GetAvailableServersRequest
+        getAvailableServersRequest =
+        ProtobufRequestUtilities.createGetAvailableServersRequest();
+    Result
+        operationHandlerResult =
+        operationHandler.process(serializationServiceStub, getAvailableServersRequest, cacheStub);
+    assertTrue(operationHandlerResult instanceof Success);
+    GetAvailableServersResponse
+        getAvailableServersResponse =
+        (GetAvailableServersResponse) operationHandlerResult.getMessage();
+
+    assertEquals(2, getAvailableServersResponse.getServersCount());
+    BasicTypes.Server server = getAvailableServersResponse.getServers(0);
+    assertEquals("hostname1", server.getHostname());
+    assertEquals(12345, server.getPort());
+    server = getAvailableServersResponse.getServers(1);
+    assertEquals("hostname2", server.getHostname());
+    assertEquals(23456, server.getPort());
+  }
+}
\ No newline at end of file


Mime
View raw message