Search in sources :

Example 1 with NodeTool

use of io.datarouter.storage.node.NodeTool in project datarouter by hotpads.

the class SqsQueueRegistryService method getSqsQueuesForClient.

public Pair<List<Twin<String>>, List<String>> getSqsQueuesForClient(ClientId clientId) {
    Set<String> knownQueuesUrls = new HashSet<>();
    AmazonSQS sqs = sqsClientManager.getAmazonSqs(clientId);
    List<? extends BaseSqsNode<?, ?, ?>> sqsNodes = Scanner.of(nodes.getPhysicalNodesForClient(clientId.getName())).map(NodeTool::extractSinglePhysicalNode).map(physicalNode -> (BaseSqsNode<?, ?, ?>) physicalNode).list();
    List<Twin<String>> knownQueueUrlByName = Scanner.of(sqsNodes).map(BaseSqsNode::getQueueUrlAndName).map(Supplier::get).each(twin -> knownQueuesUrls.add(twin.getLeft())).list();
    List<String> unreferencedQueues = Scanner.of(sqsNodes).map(BaseSqsNode::buildNamespace).distinct().map(sqs::listQueues).concatIter(ListQueuesResult::getQueueUrls).exclude(knownQueuesUrls::contains).map(queueUrl -> StringTool.getStringAfterLastOccurrence("/", queueUrl)).include(queueName -> sqsQueueExists(sqs, queueName)).list();
    return new Pair<>(knownQueueUrlByName, unreferencedQueues);
}
Also used : Twin(io.datarouter.util.tuple.Twin) Scanner(io.datarouter.scanner.Scanner) NodeTool(io.datarouter.storage.node.NodeTool) Set(java.util.Set) ListQueuesResult(com.amazonaws.services.sqs.model.ListQueuesResult) Singleton(javax.inject.Singleton) StringTool(io.datarouter.util.string.StringTool) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) Inject(javax.inject.Inject) SqsClientManager(io.datarouter.aws.sqs.SqsClientManager) List(java.util.List) QueueDoesNotExistException(com.amazonaws.services.sqs.model.QueueDoesNotExistException) ClientId(io.datarouter.storage.client.ClientId) AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) BaseSqsNode(io.datarouter.aws.sqs.BaseSqsNode) DatarouterNodes(io.datarouter.storage.node.DatarouterNodes) Pair(io.datarouter.util.tuple.Pair) ListQueuesResult(com.amazonaws.services.sqs.model.ListQueuesResult) AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) Twin(io.datarouter.util.tuple.Twin) NodeTool(io.datarouter.storage.node.NodeTool) BaseSqsNode(io.datarouter.aws.sqs.BaseSqsNode) Supplier(java.util.function.Supplier) HashSet(java.util.HashSet) Pair(io.datarouter.util.tuple.Pair)

Aggregations

AmazonSQS (com.amazonaws.services.sqs.AmazonSQS)1 ListQueuesResult (com.amazonaws.services.sqs.model.ListQueuesResult)1 QueueDoesNotExistException (com.amazonaws.services.sqs.model.QueueDoesNotExistException)1 BaseSqsNode (io.datarouter.aws.sqs.BaseSqsNode)1 SqsClientManager (io.datarouter.aws.sqs.SqsClientManager)1 Scanner (io.datarouter.scanner.Scanner)1 ClientId (io.datarouter.storage.client.ClientId)1 DatarouterNodes (io.datarouter.storage.node.DatarouterNodes)1 NodeTool (io.datarouter.storage.node.NodeTool)1 StringTool (io.datarouter.util.string.StringTool)1 Pair (io.datarouter.util.tuple.Pair)1 Twin (io.datarouter.util.tuple.Twin)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Supplier (java.util.function.Supplier)1 Inject (javax.inject.Inject)1 Singleton (javax.inject.Singleton)1