IndexShardDaoImpl implements IndexShardDao { @Override public IndexShard create(final IndexShardKey indexShardKey, final String volumeGroupName, final String ownerNodeName, final String indexVersion) { final List<IndexVolume> indexVolumes = indexVolumeDao.getVolumesInGroupOnNode(volumeGroupName, ownerNodeName); if (indexVolumes == null || indexVolumes.size() == 0) { throw new IndexException("Unable to find any index volumes for group with name " + volumeGroupName); } final IndexVolume indexVolume = volumeSelector.select(indexVolumes); if (indexVolume == null) { final String msg = "No shard can be created as no volumes are available for group: " + volumeGroupName + " indexUuid: " + indexShardKey.getIndexUuid(); throw new IndexException(msg); } final IndexShard indexShard = new IndexShard(); indexShard.setIndexUuid(indexShardKey.getIndexUuid()); indexShard.setNodeName(ownerNodeName); indexShard.setPartition(indexShardKey.getPartition()); indexShard.setPartitionFromTime(indexShardKey.getPartitionFromTime()); indexShard.setPartitionToTime(indexShardKey.getPartitionToTime()); indexShard.setVolume(indexVolume); indexShard.setIndexVersion(indexVersion); final IndexShard created = genericDao.create(indexShard); created.setVolume(indexVolume); return created; } @Inject  IndexShardDaoImpl(final IndexDbConnProvider indexDbConnProvider,
                      final IndexVolumeDao indexVolumeDao); @Override Optional<IndexShard> fetch(final long id); @Override ResultPage<IndexShard> find(final FindIndexShardCriteria criteria); @Override IndexShard create(final IndexShardKey indexShardKey,
                             final String volumeGroupName,
                             final String ownerNodeName,
                             final String indexVersion); @Override void delete(final Long id); @Override void setStatus(final Long id,
                          final IndexShard.IndexShardStatus status); @Override void update(final Long id,
                       final Integer documentCount,
                       final Long commitDurationMs,
                       final Long commitMs,
                       final Long fileSize);  }
@Test void createShardEmptyGroup() { final String partitionName = "ALL"; final DocRef index = new DocRef.Builder() .uuid(UUID.randomUUID().toString()) .name(TestData.createIndexName()) .type(IndexDoc.DOCUMENT_TYPE) .build(); final Long shardFrom = System.currentTimeMillis(); final Long shardTo = shardFrom + 3600; final String nodeName = TestData.createNodeName(); final String volumeGroupName = TestData.createVolumeGroupName(); createGroup(volumeGroupName); final IndexShardKey indexShardKey = new IndexShardKey.Builder() .indexUuid(index.getUuid()) .partition(partitionName) .shardNo(0) .partitionFromTime(shardFrom) .partitionToTime(shardTo) .build(); assertThrows(IndexException.class, () -> indexShardDao.create(indexShardKey, volumeGroupName, nodeName, "1.0-test")); }
@Test void createShardNonExistentGroup() { final String partitionName = "ALL"; final DocRef index = new DocRef.Builder() .uuid(UUID.randomUUID().toString()) .name(TestData.createIndexName()) .type(IndexDoc.DOCUMENT_TYPE) .build(); final Long shardFrom = System.currentTimeMillis(); final Long shardTo = shardFrom + 3600; final String nodeName = TestData.createNodeName(); final String volumeGroupName = TestData.createVolumeGroupName(); final IndexShardKey indexShardKey = new IndexShardKey.Builder() .indexUuid(index.getUuid()) .partition(partitionName) .shardNo(0) .partitionFromTime(shardFrom) .partitionToTime(shardTo) .build(); assertThrows(IndexException.class, () -> indexShardDao.create(indexShardKey, volumeGroupName, nodeName, "1.0-test")); }