org.opensearch.gateway.ShardBatchResponseFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearch Show documentation
Show all versions of opensearch Show documentation
OpenSearch subproject :server
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.gateway;
import org.opensearch.action.support.nodes.BaseNodeResponse;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.gateway.TransportNodesGatewayStartedShardHelper.GatewayStartedShard;
import org.opensearch.gateway.TransportNodesListGatewayStartedShardsBatch.NodeGatewayStartedShardsBatch;
import org.opensearch.indices.store.TransportNodesListShardStoreMetadataBatch.NodeStoreFilesMetadata;
import org.opensearch.indices.store.TransportNodesListShardStoreMetadataBatch.NodeStoreFilesMetadataBatch;
import java.util.Map;
/**
* A factory class to create new responses of batch transport actions like
* {@link TransportNodesListGatewayStartedShardsBatch} or {@link org.opensearch.indices.store.TransportNodesListShardStoreMetadataBatch}
*
* @param Node level response returned by batch transport actions.
* @param Shard level metadata returned by batch transport actions.
*/
public class ShardBatchResponseFactory {
private final boolean primary;
public ShardBatchResponseFactory(boolean primary) {
this.primary = primary;
}
public T getNewResponse(DiscoveryNode node, Map shardData) {
if (primary) {
return (T) new NodeGatewayStartedShardsBatch(node, (Map) shardData);
} else {
return (T) new NodeStoreFilesMetadataBatch(node, (Map) shardData);
}
}
public Map getShardBatchData(T response) {
if (primary) {
return (Map) ((NodeGatewayStartedShardsBatch) response).getNodeGatewayStartedShardsBatch();
} else {
return (Map) ((NodeStoreFilesMetadataBatch) response).getNodeStoreFilesMetadataBatch();
}
}
}