]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6992 make sonar.core.id persistent and always a UUID
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 9 Sep 2016 09:06:22 +0000 (11:06 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 12 Sep 2016 08:50:56 +0000 (10:50 +0200)
14 files changed:
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdManager.java [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java
server/sonar-server/src/main/java/org/sonar/server/platform/StartupMetadata.java
server/sonar-server/src/main/java/org/sonar/server/platform/StartupMetadataPersister.java
server/sonar-server/src/main/java/org/sonar/server/platform/StartupMetadataProvider.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel2.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel3.java
server/sonar-server/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevelSafeMode.java
server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdManagerTest.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/platform/ServerImplTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/StartupMetadataPersisterTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/StartupMetadataProviderTest.java

index a6a97ed4abefcf115b2eea26cf1a949f9f7e35c5..43386927a5703d55d65b5f5ab14acc6b84b8febc 100644 (file)
@@ -102,6 +102,7 @@ import org.sonar.server.notification.email.EmailNotificationChannel;
 import org.sonar.server.platform.DatabaseServerCompatibility;
 import org.sonar.server.platform.DefaultServerUpgradeStatus;
 import org.sonar.server.platform.ServerFileSystemImpl;
+import org.sonar.server.platform.ServerIdManager;
 import org.sonar.server.platform.ServerImpl;
 import org.sonar.server.platform.ServerLifecycleNotifier;
 import org.sonar.server.platform.ServerLogging;
@@ -274,6 +275,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
   private static Object[] level3Components() {
     return new Object[] {
       new StartupMetadataProvider(),
+      ServerIdManager.class,
       UriReader.class,
       ServerImpl.class
     };
index fed55130524f70b0e098230f08764665db8f0fce..fa04a3ace0f56398e3e4753137341ff20962af34 100644 (file)
@@ -97,7 +97,7 @@ public class ComputeEngineContainerImplTest {
     );
     assertThat(picoContainer.getParent().getComponentAdapters()).hasSize(
       CONTAINER_ITSELF
-        + 3 // level 3
+        + 4 // level 3
     );
     assertThat(picoContainer.getParent().getParent().getComponentAdapters()).hasSize(
       CONTAINER_ITSELF
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdManager.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerIdManager.java
new file mode 100644 (file)
index 0000000..bd83efb
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import javax.annotation.Nullable;
+import org.picocontainer.Startable;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.SonarQubeSide;
+import org.sonar.api.SonarRuntime;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.property.PropertyDto;
+import org.sonar.server.platform.cluster.Cluster;
+
+import static com.google.common.base.Preconditions.checkState;
+import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.sonar.api.CoreProperties.SERVER_ID;
+
+public class ServerIdManager implements Startable {
+  private final DbClient dbClient;
+  private final SonarRuntime runtime;
+  private final Cluster cluster;
+  private final UuidFactory uuidFactory;
+
+  public ServerIdManager(DbClient dbClient, SonarRuntime runtime, Cluster cluster, UuidFactory uuidFactory) {
+    this.dbClient = dbClient;
+    this.runtime = runtime;
+    this.cluster = cluster;
+    this.uuidFactory = uuidFactory;
+  }
+
+  @Override
+  public void start() {
+    try (DbSession dbSession = dbClient.openSession(false)) {
+      PropertyDto dto = dbClient.propertiesDao().selectGlobalProperty(dbSession, SERVER_ID);
+      if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && cluster.isStartupLeader()) {
+        persistServerIdIfMissingOrOldFormatted(dbSession, dto);
+      } else {
+        ensureServerIdIsSet(dto);
+      }
+    }
+  }
+
+  /**
+   * Insert or update {@link CoreProperties#SERVER_ID} property in DB to a UUID if it doesn't exist or if it's a date
+   * (per the old format of {@link CoreProperties#SERVER_ID} before 6.1).
+   */
+  private void persistServerIdIfMissingOrOldFormatted(DbSession dbSession, @Nullable PropertyDto dto) {
+    if (dto == null || dto.getValue().isEmpty() || isDate(dto.getValue())) {
+      dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(SERVER_ID).setValue(uuidFactory.create()));
+      dbSession.commit();
+    }
+  }
+
+  /**
+   * Checks whether the specified value is a date according to the old format of the {@link CoreProperties#SERVER_ID}.
+   */
+  private static boolean isDate(String value) {
+    try {
+      new SimpleDateFormat("yyyyMMddHHmmss").parse(value);
+      return true;
+    } catch (ParseException e) {
+      return false;
+    }
+  }
+
+  private static void ensureServerIdIsSet(@Nullable PropertyDto dto) {
+    checkState(dto != null, "Property %s is missing in database", SERVER_ID);
+    checkState(!isBlank(dto.getValue()), "Property %s is set but empty in database", SERVER_ID);
+  }
+
+  @Override
+  public void stop() {
+    // nothing to do
+  }
+}
index 222183ce84f3831a7b6e595e4dd8d0027f27bece..4a0bf655dd3a10cde65bfb6c2439f19918c99104 100644 (file)
@@ -48,7 +48,7 @@ public class ServerImpl extends Server {
 
   @Override
   public String getId() {
-    return state.getStartupId();
+    return settings.getString(CoreProperties.SERVER_ID);
   }
 
   @Override
index 87739be59aae78cb20ca54baad4e878ae160a67d..2f36e2de73c27bcc245ed4c96094bfa87cff1d0e 100644 (file)
@@ -23,25 +23,17 @@ import javax.annotation.concurrent.Immutable;
 import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.server.ServerSide;
 
-import static java.util.Objects.requireNonNull;
-
 @ComputeEngineSide
 @ServerSide
 @Immutable
 public class StartupMetadata {
 
-  private final String startupId;
   private final long startedAt;
 
-  public StartupMetadata(String startupId, long startedAt) {
-    this.startupId = requireNonNull(startupId);
+  public StartupMetadata(long startedAt) {
     this.startedAt = startedAt;
   }
 
-  public String getStartupId() {
-    return startupId;
-  }
-
   public long getStartedAt() {
     return startedAt;
   }
index ac9ee2861ee97daab834bb281d1b0c4f2c310649..adad891ff41e2eb3335230691296894ae098da63 100644 (file)
@@ -50,7 +50,6 @@ public class StartupMetadataPersister implements Startable {
   @Override
   public void start() {
     String startedAt = DateUtils.formatDateTime(new Date(metadata.getStartedAt()));
-    save(CoreProperties.SERVER_ID, metadata.getStartupId());
     save(CoreProperties.SERVER_STARTTIME, startedAt);
   }
 
index 3471353721fc090aa44a88492ed3468104ea54e1..b046dbcf957887986ae599dcf3057bb48e906881 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
-import org.sonar.core.util.UuidFactory;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.property.PropertyDto;
@@ -35,6 +34,7 @@ import org.sonar.server.platform.cluster.Cluster;
 
 import static com.google.common.base.Preconditions.checkState;
 import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.sonar.api.CoreProperties.SERVER_STARTTIME;
 
 @ComputeEngineSide
 @ServerSide
@@ -42,10 +42,10 @@ public class StartupMetadataProvider extends ProviderAdapter {
 
   private StartupMetadata cache = null;
 
-  public StartupMetadata provide(UuidFactory uuidFactory, System2 system, SonarRuntime runtime, Cluster cluster, DbClient dbClient) {
+  public StartupMetadata provide(System2 system, SonarRuntime runtime, Cluster cluster, DbClient dbClient) {
     if (cache == null) {
       if (runtime.getSonarQubeSide() == SonarQubeSide.SERVER && cluster.isStartupLeader()) {
-        cache = generate(uuidFactory, system);
+        cache = generate(system);
       } else {
         cache = load(dbClient);
       }
@@ -54,13 +54,14 @@ public class StartupMetadataProvider extends ProviderAdapter {
   }
 
   /**
-   * Generate a UUID. It is not persisted yet as db structure may not be up-to-date if migrations
-   * have to be executed. This is done later by {@link StartupMetadataPersister}
+   * Generate {@link CoreProperties#SERVER_ID} if it doesn't exist yet, otherwise just load it from DB, and always
+   * generate a {@link CoreProperties#SERVER_STARTTIME}.
+   * <p>
+   * Persistence is performed by {@link StartupMetadataPersister}.
+   * </p>
    */
-  private static StartupMetadata generate(UuidFactory uuidFactory, System2 system) {
-    String startupId = uuidFactory.create();
-    long startedAt = system.now();
-    return new StartupMetadata(startupId, startedAt);
+  private static StartupMetadata generate(System2 system) {
+    return new StartupMetadata(system.now());
   }
 
   /**
@@ -68,9 +69,8 @@ public class StartupMetadataProvider extends ProviderAdapter {
    */
   private static StartupMetadata load(DbClient dbClient) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      String startupId = selectProperty(dbClient, dbSession, CoreProperties.SERVER_ID);
-      String startedAt = selectProperty(dbClient, dbSession, CoreProperties.SERVER_STARTTIME);
-      return new StartupMetadata(startupId, DateUtils.parseDateTime(startedAt).getTime());
+      String startedAt = selectProperty(dbClient, dbSession, SERVER_STARTTIME);
+      return new StartupMetadata(DateUtils.parseDateTime(startedAt).getTime());
     }
   }
 
index 19fa44aac740f26dcc53002988f763da2aff62ad..b3786b8dc7d400eff78dce8b7b4a134a4d3b567b 100644 (file)
@@ -27,7 +27,6 @@ import org.sonar.core.platform.PluginLoader;
 import org.sonar.db.charset.DatabaseCharsetChecker;
 import org.sonar.db.version.MigrationStepModule;
 import org.sonar.server.platform.DefaultServerUpgradeStatus;
-import org.sonar.server.platform.ServerImpl;
 import org.sonar.server.platform.StartupMetadataProvider;
 import org.sonar.server.platform.db.CheckDatabaseCharsetAtStartup;
 import org.sonar.server.platform.db.migrations.DatabaseMigrator;
@@ -50,7 +49,6 @@ public class PlatformLevel2 extends PlatformLevel {
   protected void configureLevel() {
     add(
       new StartupMetadataProvider(),
-      ServerImpl.class,
       DefaultServerUpgradeStatus.class,
       Durations.class,
       JRubyI18n.class,
@@ -71,7 +69,6 @@ public class PlatformLevel2 extends PlatformLevel {
       DefaultI18n.class,
       RuleI18nManager.class,
 
-      
       // DB migration
       PlatformDatabaseMigrationExecutorServiceImpl.class,
       PlatformDatabaseMigration.class,
index c3486905b8e9fc889a395e30408b2e097f5ab9b3..74638e69925c28e9f8082534b2ff98445e66997f 100644 (file)
@@ -22,6 +22,8 @@ package org.sonar.server.platform.platformlevel;
 import org.sonar.api.utils.UriReader;
 import org.sonar.server.platform.ServerIdGenerator;
 import org.sonar.server.platform.ServerIdLoader;
+import org.sonar.server.platform.ServerIdManager;
+import org.sonar.server.platform.ServerImpl;
 import org.sonar.server.platform.StartupMetadataPersister;
 import org.sonar.server.setting.DatabaseSettingLoader;
 import org.sonar.server.setting.DatabaseSettingsEnabler;
@@ -36,6 +38,8 @@ public class PlatformLevel3 extends PlatformLevel {
   protected void configureLevel() {
     addIfStartupLeader(StartupMetadataPersister.class);
     add(
+      ServerIdManager.class,
+      ServerImpl.class,
       DatabaseSettingLoader.class,
       DatabaseSettingsEnabler.class,
       UriReader.class,
index f003f7d7bab67a47a0d0af90b28a9e29861d6ba9..69c2d95c00b3884a0b035cdeff44c362d09f92de 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.platform.platformlevel;
 
+import org.sonar.server.platform.ServerImpl;
 import org.sonar.server.platform.ws.DbMigrationStatusAction;
 import org.sonar.server.platform.ws.MigrateDbAction;
 import org.sonar.server.platform.ws.StatusAction;
@@ -35,6 +36,7 @@ public class PlatformLevelSafeMode extends PlatformLevel {
   @Override
   protected void configureLevel() {
     add(
+      ServerImpl.class,
       // Server WS
       StatusAction.class,
       MigrateDbAction.class,
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdManagerTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ServerIdManagerTest.java
new file mode 100644 (file)
index 0000000..ed46ec0
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.SonarQubeSide;
+import org.sonar.api.SonarRuntime;
+import org.sonar.api.internal.SonarRuntimeImpl;
+import org.sonar.api.utils.System2;
+import org.sonar.api.utils.Version;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.property.PropertyDto;
+import org.sonar.server.platform.cluster.ClusterMock;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.api.SonarQubeSide.COMPUTE_ENGINE;
+import static org.sonar.api.SonarQubeSide.SERVER;
+
+public class ServerIdManagerTest {
+  private static final Version SOME_VERSION = Version.create(5, 6);
+  private static final String SOME_UUID = "some uuid";
+
+  @Rule
+  public final DbTester dbTester = DbTester.create(System2.INSTANCE);
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private DbClient dbClient = dbTester.getDbClient();
+  private DbSession dbSession = dbTester.getSession();
+  private ClusterMock cluster = new ClusterMock();
+  private UuidFactory uuidFactory = mock(UuidFactory.class);
+
+  private static SonarRuntime runtimeFor(SonarQubeSide side) {
+    return SonarRuntimeImpl.forSonarQube(SOME_VERSION, side);
+  }
+
+  @Test
+  public void start_persists_new_serverId_if_server_startupLeader_and_serverId_does_not_exist() {
+    when(uuidFactory.create()).thenReturn(SOME_UUID);
+    cluster.setStartupLeader(true);
+
+    new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory)
+      .start();
+
+    assertThat(dbClient.propertiesDao().selectGlobalProperty(dbSession, CoreProperties.SERVER_ID))
+      .extracting(PropertyDto::getValue)
+      .containsOnly(SOME_UUID);
+  }
+
+  @Test
+  public void start_persists_new_serverId_if_server_startupLeader_and_serverId_is_an_old_date() {
+    insertPropertyCoreId("20161123150657");
+    when(uuidFactory.create()).thenReturn(SOME_UUID);
+    cluster.setStartupLeader(true);
+
+    new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory)
+        .start();
+
+    assertThat(dbClient.propertiesDao().selectGlobalProperty(dbSession, CoreProperties.SERVER_ID))
+        .extracting(PropertyDto::getValue)
+        .containsOnly(SOME_UUID);
+  }
+
+  private void insertPropertyCoreId(String value) {
+    dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey(CoreProperties.SERVER_ID).setValue(value));
+    dbSession.commit();
+  }
+
+  @Test
+  public void start_persists_new_serverId_if_server_startupLeader_and_serverId_is_empty() {
+    insertPropertyCoreId("");
+    when(uuidFactory.create()).thenReturn(SOME_UUID);
+    cluster.setStartupLeader(true);
+
+    new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory)
+        .start();
+
+    assertThat(dbClient.propertiesDao().selectGlobalProperty(dbSession, CoreProperties.SERVER_ID))
+        .extracting(PropertyDto::getValue)
+        .containsOnly(SOME_UUID);
+  }
+
+  @Test
+  public void start_fails_with_ISE_if_serverId_is_null_and_server_is_not_startupLeader() {
+    cluster.setStartupLeader(false);
+
+    ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory);
+
+    expectMissingCoreIdException();
+    
+    underTest.start();
+  }
+
+  @Test
+  public void start_fails_with_ISE_if_serverId_is_empty_and_server_is_not_startupLeader() {
+    insertPropertyCoreId("");
+    cluster.setStartupLeader(false);
+
+    ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory);
+
+    expectEmptyCoreIdException();
+
+    underTest.start();
+  }
+
+  @Test
+  public void start_fails_with_ISE_if_serverId_is_null_and_not_server() {
+    cluster.setStartupLeader(false);
+
+    ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(COMPUTE_ENGINE), cluster, uuidFactory);
+
+    expectMissingCoreIdException();
+
+    underTest.start();
+  }
+
+  @Test
+  public void start_fails_with_ISE_if_serverId_is_empty_and_not_server() {
+    insertPropertyCoreId("");
+
+    ServerIdManager underTest = new ServerIdManager(dbClient, runtimeFor(COMPUTE_ENGINE), cluster, uuidFactory);
+
+    expectEmptyCoreIdException();
+
+    underTest.start();
+  }
+
+  @Test
+  public void start_does_not_fail_if_serverId_exists_and_server_is_not_startupLeader() {
+    insertPropertyCoreId(SOME_UUID);
+    cluster.setStartupLeader(false);
+
+    new ServerIdManager(dbClient, runtimeFor(SERVER), cluster, uuidFactory).start();
+  }
+
+  @Test
+  public void start_does_not_fail_if_serverId_exists_and_not_server() {
+    insertPropertyCoreId(SOME_UUID);
+
+    new ServerIdManager(dbClient, runtimeFor(COMPUTE_ENGINE), cluster, uuidFactory).start();
+  }
+
+  private void expectEmptyCoreIdException() {
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("Property sonar.core.id is set but empty in database");
+  }
+
+  private void expectMissingCoreIdException() {
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("Property sonar.core.id is missing in database");
+  }
+}
index 1231868b60a1bffeb6a758d2e810441577f04ac5..1ef5104a9db24a7d87d0151bf118222450a25f1a 100644 (file)
@@ -75,9 +75,14 @@ public class ServerImplTest {
   public void test_startup_information() throws IOException {
     long time = 123_456_789L;
     when(state.getStartedAt()).thenReturn(time);
-    when(state.getStartupId()).thenReturn("an_id");
 
     assertThat(underTest.getStartedAt().getTime()).isEqualTo(time);
+  }
+
+  @Test
+  public void test_id() throws IOException {
+    settings.setProperty(CoreProperties.SERVER_ID, "an_id");
+
     assertThat(underTest.getId()).isEqualTo("an_id");
   }
 
index 364d0126b17c517ee0596060d5cff3e6328dd851..286ce30467fe365dee0c5b83541ec88762867e5c 100644 (file)
@@ -34,18 +34,16 @@ public class StartupMetadataPersisterTest {
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
-
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  private StartupMetadata metadata = new StartupMetadata("an_id", 123_456_789L);
+  private StartupMetadata metadata = new StartupMetadata(123_456_789L);
   private StartupMetadataPersister underTest = new StartupMetadataPersister(metadata, dbTester.getDbClient());
 
   @Test
   public void persist_metadata_at_startup() {
     underTest.start();
 
-    assertPersistedProperty(CoreProperties.SERVER_ID, metadata.getStartupId());
     assertPersistedProperty(CoreProperties.SERVER_STARTTIME, DateUtils.formatDateTime(metadata.getStartedAt()));
 
     underTest.stop();
index 9b3348860064ec75822145b6fc15af61cb4468be..4cce0bdac9247cc77e66b868d906da33efebeb0b 100644 (file)
@@ -29,7 +29,6 @@ import org.sonar.api.internal.SonarRuntimeImpl;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.api.utils.Version;
-import org.sonar.core.util.UuidFactory;
 import org.sonar.db.DbTester;
 import org.sonar.db.property.PropertyDto;
 import org.sonar.server.platform.cluster.ClusterMock;
@@ -42,7 +41,6 @@ import static org.mockito.Mockito.when;
 public class StartupMetadataProviderTest {
 
   private static final long A_DATE = 1_500_000_000_000L;
-  private static final String AN_ID = "generated_id";
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
@@ -50,27 +48,23 @@ public class StartupMetadataProviderTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
 
-  private UuidFactory uuidFactory = mock(UuidFactory.class);
   private StartupMetadataProvider underTest = new StartupMetadataProvider();
   private System2 system = mock(System2.class);
   private ClusterMock cluster = new ClusterMock();
 
   @Test
-  public void generate_and_do_not_persist_metadata_if_server_is_startup_leader() {
-    when(uuidFactory.create()).thenReturn(AN_ID);
+  public void generate_SERVER_STARTIME_but_do_not_persist_it_if_server_is_startup_leader() {
     when(system.now()).thenReturn(A_DATE);
     SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(6, 1), SonarQubeSide.SERVER);
     cluster.setStartupLeader(true);
 
-    StartupMetadata metadata = underTest.provide(uuidFactory, system, runtime, cluster, dbTester.getDbClient());
+    StartupMetadata metadata = underTest.provide(system, runtime, cluster, dbTester.getDbClient());
     assertThat(metadata.getStartedAt()).isEqualTo(A_DATE);
-    assertThat(metadata.getStartupId()).isEqualTo(AN_ID);
 
-    assertNotPersistedProperty(CoreProperties.SERVER_ID);
     assertNotPersistedProperty(CoreProperties.SERVER_STARTTIME);
 
     // keep a cache
-    StartupMetadata secondMetadata = underTest.provide(uuidFactory, system, runtime, cluster, dbTester.getDbClient());
+    StartupMetadata secondMetadata = underTest.provide(system, runtime, cluster, dbTester.getDbClient());
     assertThat(secondMetadata).isSameAs(metadata);
   }
 
@@ -102,27 +96,25 @@ public class StartupMetadataProviderTest {
     cluster.setStartupLeader(false);
 
     expectedException.expect(IllegalStateException.class);
-    expectedException.expectMessage("Property sonar.core.id is missing in database");
-    underTest.provide(uuidFactory, system, runtime, cluster, dbTester.getDbClient());
+    expectedException.expectMessage("Property sonar.core.startTime is missing in database");
+    underTest.provide(system, runtime, cluster, dbTester.getDbClient());
   }
 
   private void testLoadingFromDatabase(SonarRuntime runtime, boolean isStartupLeader) {
-    new StartupMetadataPersister(new StartupMetadata(AN_ID, A_DATE), dbTester.getDbClient()).start();
+    new StartupMetadataPersister(new StartupMetadata(A_DATE), dbTester.getDbClient()).start();
     cluster.setStartupLeader(isStartupLeader);
 
-    StartupMetadata metadata = underTest.provide(uuidFactory, system, runtime, cluster, dbTester.getDbClient());
+    StartupMetadata metadata = underTest.provide(system, runtime, cluster, dbTester.getDbClient());
     assertThat(metadata.getStartedAt()).isEqualTo(A_DATE);
-    assertThat(metadata.getStartupId()).isEqualTo(AN_ID);
 
     // still in database
-    assertPersistedProperty(CoreProperties.SERVER_ID, AN_ID);
     assertPersistedProperty(CoreProperties.SERVER_STARTTIME, DateUtils.formatDateTime(A_DATE));
 
     // keep a cache
-    StartupMetadata secondMetadata = underTest.provide(uuidFactory, system, runtime, cluster, dbTester.getDbClient());
+    StartupMetadata secondMetadata = underTest.provide(system, runtime, cluster, dbTester.getDbClient());
     assertThat(secondMetadata).isSameAs(metadata);
 
-    verifyZeroInteractions(uuidFactory, system);
+    verifyZeroInteractions(system);
   }
 
   private void assertPersistedProperty(String propertyKey, String expectedValue) {