@Override
    public void upgrade() {
        if (clusterConfigService.get(V20161216123500_Succeeded.class) != null) {
            return;
        }

        // The default index set must have been created first.
        checkState(clusterConfigService.get(DefaultIndexSetCreated.class) != null, "The default index set hasn't been created yet. This is a bug!");

        final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
        migrateIndexSet(defaultIndexSet, elasticsearchConfiguration.getDefaultIndexTemplateName());

        final List<IndexSetConfig> allWithoutDefault = indexSetService.findAll()
                .stream()
                .filter(indexSetConfig -> !indexSetConfig.equals(defaultIndexSet))
                .collect(Collectors.toList());

        for (IndexSetConfig indexSetConfig : allWithoutDefault) {
            migrateIndexSet(indexSetConfig, indexSetConfig.indexPrefix() + "-template");
        }


        clusterConfigService.write(V20161216123500_Succeeded.create());
    }
@Test
    public void migrationDoesNotRunAgainIfMigrationWasSuccessfulBefore() {
        when(clusterConfigService.get(V20161216123500_Succeeded.class)).thenReturn(V20161216123500_Succeeded.create());
        migration.upgrade();

        verify(clusterConfigService).get(V20161216123500_Succeeded.class);
        verifyNoMoreInteractions(clusterConfigService);
        verifyNoMoreInteractions(indexSetService);
    }