IndexUndeployOperation implements MasterOperation { @Override public List<OperationId> execute(MasterContext context, List<MasterOperation> runningOperations) throws Exception { InteractionProtocol protocol = context.getProtocol(); _indexMD = protocol.getIndexMD(_indexName); Map<String, List<String>> shard2NodesMap = protocol.getShard2NodesMap(Shard.getShardNames(_indexMD.getShards())); Map<String, List<String>> node2ShardsMap = CollectionUtil.invertListMap(shard2NodesMap); Set<String> nodes = node2ShardsMap.keySet(); List<OperationId> nodeOperationIds = new ArrayList<OperationId>(nodes.size()); for (String node : nodes) { List<String> nodeShards = node2ShardsMap.get(node); OperationId operationId = protocol.addNodeOperation(node, new ShardUndeployOperation(nodeShards)); nodeOperationIds.add(operationId); } protocol.unpublishIndex(_indexName); return nodeOperationIds; } IndexUndeployOperation(String indexName); @Override List<OperationId> execute(MasterContext context, List<MasterOperation> runningOperations); @Override void nodeOperationsComplete(MasterContext context, List<OperationResult> results); @Override ExecutionInstruction getExecutionInstruction(List<MasterOperation> runningOperations); @Override String toString();  }
@Test public void testUndeployErrorIndex() throws Exception { List<Node> nodes = Mocks.mockNodes(2); List<NodeQueue> nodeQueues = Mocks.publisNodes(_protocol, nodes); deployIndexWithError(); publisShards(nodes, nodeQueues); assertNotNull(_protocol.getIndexMD(_indexName)); assertNotNull(_protocol.getIndexMD(_indexName).getDeployError()); IndexUndeployOperation undeployOperation = new IndexUndeployOperation(_indexName); undeployOperation.execute(_context, EMPTY_LIST); for (NodeQueue nodeqQueue : nodeQueues) { assertEquals(1, nodeqQueue.size()); assertTrue(nodeqQueue.peek() instanceof ShardUndeployOperation); } assertNull(_protocol.getIndexMD(_indexName)); assertEquals(0, _protocol.getIndices().size()); }