Search in sources :

Example 1 with BucketServerLocation

use of org.apache.geode.internal.cache.BucketServerLocation in project geode by apache.

the class GetClientPRMetadataCommand method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
    String regionFullPath = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    regionFullPath = clientMessage.getPart(0).getString();
    String errMessage = "";
    if (regionFullPath == null) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPRMetadata_THE_INPUT_REGION_PATH_IS_NULL));
        errMessage = LocalizedStrings.GetClientPRMetadata_THE_INPUT_REGION_PATH_IS_NULL.toLocalizedString();
        writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PR_METADATA_ERROR, errMessage.toString(), serverConnection);
        serverConnection.setAsTrue(RESPONDED);
    } else {
        Region region = crHelper.getRegion(regionFullPath);
        if (region == null) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPRMetadata_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH, regionFullPath));
            errMessage = LocalizedStrings.GetClientPRMetadata_REGION_NOT_FOUND.toLocalizedString() + regionFullPath;
            writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PR_METADATA_ERROR, errMessage.toString(), serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        } else {
            try {
                Message responseMsg = serverConnection.getResponseMessage();
                responseMsg.setTransactionId(clientMessage.getTransactionId());
                responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PR_METADATA);
                PartitionedRegion prRgion = (PartitionedRegion) region;
                Map<Integer, List<BucketServerLocation66>> bucketToServerLocations = prRgion.getRegionAdvisor().getAllClientBucketProfiles();
                responseMsg.setNumberOfParts(bucketToServerLocations.size());
                for (List<BucketServerLocation66> serverLocations : bucketToServerLocations.values()) {
                    List<BucketServerLocation> oldServerLocations = new ArrayList<BucketServerLocation>();
                    for (BucketServerLocation66 bs : serverLocations) {
                        oldServerLocations.add(new BucketServerLocation(bs.getBucketId(), bs.getPort(), bs.getHostName(), bs.isPrimary(), bs.getVersion()));
                        responseMsg.addObjPart(oldServerLocations);
                    }
                }
                responseMsg.send();
                clientMessage.clearParts();
            } catch (Exception e) {
                writeException(clientMessage, e, false, serverConnection);
            } finally {
                serverConnection.setAsTrue(Command.RESPONDED);
            }
        }
    }
}
Also used : BucketServerLocation66(org.apache.geode.internal.cache.BucketServerLocation66) LocalizedMessage(org.apache.geode.internal.logging.log4j.LocalizedMessage) Message(org.apache.geode.internal.cache.tier.sockets.Message) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) BucketServerLocation(org.apache.geode.internal.cache.BucketServerLocation) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Region (org.apache.geode.cache.Region)1 BucketServerLocation (org.apache.geode.internal.cache.BucketServerLocation)1 BucketServerLocation66 (org.apache.geode.internal.cache.BucketServerLocation66)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)1 Message (org.apache.geode.internal.cache.tier.sockets.Message)1 LocalizedMessage (org.apache.geode.internal.logging.log4j.LocalizedMessage)1