Browse code

MAINTBL-25 Fix: remove system.persistence from the upgrade dep chain

Thomas Cataldo authored on 26/11/2019 15:06:57
Showing 119 changed files
... ...
@@ -103,7 +103,6 @@
103 103
    <bundle id="net.bluemind.core.context" version="4.1.0.qualifier"/>
104 104
    <bundle id="net.bluemind.core.elasticsearch.testshelper" version="4.1.0.qualifier"/>
105 105
    <bundle id="net.bluemind.core.jdbc" version="4.1.0.qualifier"/>
106
-   <bundle id="net.bluemind.core.jdbc.schemaextractor" version="4.1.0.qualifier"/>
107 106
    <bundle id="net.bluemind.core.jdbc.tests" version="4.1.0.qualifier"/>
108 107
    <bundle id="net.bluemind.core.jdbc.testshelper" version="4.1.0.qualifier"/>
109 108
    <bundle id="net.bluemind.core.node.testshelper" version="4.1.0.qualifier"/>
... ...
@@ -508,4 +507,5 @@
508 507
    <bundle id="net.bluemind.forest.cloud.service"/>
509 508
    <bundle id="net.bluemind.forest.instance.api"/>
510 509
    <bundle id="net.bluemind.forest.instance.service"/>
510
+   <bundle id="net.bluemind.system.schemaupgrader.runner"/>
511 511
 </site>
... ...
@@ -348,6 +348,7 @@
348 348
       <plugin id="net.bluemind.system.persistance"/>
349 349
       <plugin id="net.bluemind.system.pg"/>
350 350
       <plugin id="net.bluemind.system.schemaupgrader"/>
351
+      <plugin id="net.bluemind.system.schemaupgrader.runner"/>
351 352
       <plugin id="net.bluemind.system.service"/>
352 353
       <plugin id="net.bluemind.system.sqlschema"/>
353 354
       <plugin id="net.bluemind.system.state"/>
... ...
@@ -456,8 +457,8 @@
456 457
 
457 458
    <configurations>
458 459
       <plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="4" />
459
-      <property name="osgi.noShutdown" value="true" />
460 460
       <property name="osgi.configuration.area" value="/var/lib/bm-core/" />
461
+      <property name="osgi.noShutdown" value="true" />
461 462
    </configurations>
462 463
 
463 464
    <preferencesInfo>
... ...
@@ -1,8 +1,9 @@
1 1
 Manifest-Version: 1.0
2 2
 Bundle-ManifestVersion: 2
3
-Bundle-Name: Persistance
3
+Bundle-Name: net.bluemind.addressbook.sqlschema
4 4
 Bundle-SymbolicName: net.bluemind.addressbook.sqlschema;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6 6
 Require-Bundle: net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
7 7
  net.bluemind.core.sqlschema;bundle-version="1.0.0"
8 8
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9
+Automatic-Module-Name: net.bluemind.addressbook.sqlschema
... ...
@@ -6,3 +6,4 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Bundle-Vendor: www.blue-mind.net
7 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 8
 Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0"
9
+Automatic-Module-Name: net.bluemind.authentication.sqlschema
... ...
@@ -7,3 +7,4 @@ Require-Bundle: net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
7 7
  net.bluemind.core.sqlschema;bundle-version="1.0.0",
8 8
  net.bluemind.icalendar.sqlschema;bundle-version="1.0.0"
9 9
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
10
+Automatic-Module-Name: net.bluemind.calendar.sqlschema
10 11
deleted file mode 100644
... ...
@@ -1,7 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<classpath>
3
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
-	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
-	<classpathentry kind="src" path="src/"/>
6
-	<classpathentry kind="output" path="target/classes"/>
7
-</classpath>
8 0
deleted file mode 100644
... ...
@@ -1,29 +0,0 @@
1
-<?xml version="1.0"?>
2
-<projectDescription>
3
-	<name>net.bluemind.core.jdbc.schemaextractor</name>
4
-	<comment/>
5
-	<projects>
6
-	</projects>
7
-	<buildSpec>
8
-		<buildCommand>
9
-			<name>org.eclipse.jdt.core.javabuilder</name>
10
-			<arguments>
11
-			</arguments>
12
-		</buildCommand>
13
-		<buildCommand>
14
-			<name>org.eclipse.pde.ManifestBuilder</name>
15
-			<arguments>
16
-			</arguments>
17
-		</buildCommand>
18
-		<buildCommand>
19
-			<name>org.eclipse.pde.SchemaBuilder</name>
20
-			<arguments>
21
-			</arguments>
22
-		</buildCommand>
23
-	</buildSpec>
24
-	<natures>
25
-		
26
-		<nature>org.eclipse.pde.PluginNature</nature>
27
-		<nature>org.eclipse.jdt.core.javanature</nature>
28
-	</natures>
29
-</projectDescription>
30 0
deleted file mode 100644
... ...
@@ -1,38 +0,0 @@
1
-Manifest-Version: 1.0
2
-Bundle-ManifestVersion: 2
3
-Bundle-Name: Dockerclient
4
-Bundle-SymbolicName: net.bluemind.core.jdbc.schemaextractor;singleton:=true
5
-Bundle-Version: 4.1.0.qualifier
6
-Bundle-RequiredExecutionEnvironment: JavaSE-1.8
7
-Bundle-ClassPath: .
8
-Require-Bundle: net.bluemind.slf4j;bundle-version="1.0.0",
9
- org.eclipse.equinox.app,
10
- com.google.guava;bundle-version="19.0.0",
11
- net.bluemind.core.sqlschema;bundle-version="1.0.0",
12
- net.bluemind.addressbook.sqlschema;bundle-version="1.0.0",
13
- net.bluemind.calendar.sqlschema;bundle-version="1.0.0",
14
- net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
15
- net.bluemind.domain.sqlschema;bundle-version="1.0.0",
16
- net.bluemind.eas.sqlschema;bundle-version="1.0.0",
17
- net.bluemind.globalsettings.sqlschema;bundle-version="1.0.0",
18
- net.bluemind.group.sqlschema;bundle-version="1.0.0",
19
- net.bluemind.server.sqlschema;bundle-version="1.0.0",
20
- net.bluemind.tag.sqlschema;bundle-version="1.0.0",
21
- net.bluemind.todolist.sqlschema;bundle-version="1.0.0",
22
- net.bluemind.user.sqlschema;bundle-version="1.0.0",
23
- net.bluemind.authentication.sqlschema;bundle-version="1.0.0",
24
- net.bluemind.dataprotect.sqlschema;bundle-version="1.0.0",
25
- net.bluemind.device.sqlschema;bundle-version="1.0.0",
26
- net.bluemind.document.sqlschema;bundle-version="1.0.0",
27
- net.bluemind.icalendar.sqlschema;bundle-version="1.0.0",
28
- net.bluemind.im.sqlschema;bundle-version="1.0.0",
29
- net.bluemind.mailbox.identity.sqlschema;bundle-version="1.0.0",
30
- net.bluemind.mailbox.sqlschema;bundle-version="1.0.0",
31
- net.bluemind.resource.sqlschema;bundle-version="1.0.0",
32
- net.bluemind.scheduledjob.sqlschema;bundle-version="1.0.0",
33
- net.bluemind.system.sqlschema;bundle-version="1.0.0",
34
- net.bluemind.webmail.sqlschema;bundle-version="1.0.0",
35
- net.bluemind.role.sqlschema;bundle-version="1.0.0",
36
- org.eclipse.equinox.launcher;bundle-version="1.3.1.0",
37
- net.bluemind.directory.sqlschema;bundle-version="1.0.0",
38
- net.bluemind.filehosting.filesystem.sqlschema;bundle-version="1.0.0"
39 0
deleted file mode 100644
... ...
@@ -1,4 +0,0 @@
1
-bin.includes = META-INF/,\
2
-               .,\
3
-               plugin.xml
4
-source.. = src/
5 0
deleted file mode 100644
... ...
@@ -1,27 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<?eclipse version="3.4"?>
3
-<plugin>
4
-   <extension
5
-         id="schemaextractor"
6
-         point="org.eclipse.core.runtime.applications">
7
-      <application
8
-            cardinality="singleton-global"
9
-            thread="main"
10
-            visible="true">
11
-         <run
12
-               class="net.bluemind.core.jdbc.schemaextractor.ExtractorApplication">
13
-         </run>
14
-      </application>
15
-   </extension>
16
-   <extension
17
-         id="schemaextractor"
18
-         point="org.eclipse.core.runtime.products">
19
-      <product
20
-            application="net.bluemind.core.jdbc.schemaextractor.schemaextractor" name="appName">
21
-         <property
22
-               name="appName" value="appName">
23
-         </property>
24
-      </product>
25
-   </extension>
26
-
27
-</plugin>
28 0
deleted file mode 100644
... ...
@@ -1,11 +0,0 @@
1
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
-  <modelVersion>4.0.0</modelVersion>
3
-  <parent>
4
-    <groupId>net.bluemind</groupId>
5
-    <version>4.1.0-SNAPSHOT</version>
6
-    <artifactId>net.bluemind.ci.plugins</artifactId>
7
-  </parent>
8
-  <artifactId>net.bluemind.core.jdbc.schemaextractor</artifactId>
9
-  <packaging>eclipse-plugin</packaging>
10
-  
11
-</project>
12 0
deleted file mode 100644
... ...
@@ -1,37 +0,0 @@
1
-/* BEGIN LICENSE
2
- * Copyright © Blue Mind SAS, 2012-2016
3
- *
4
- * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
- * solution.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of either the GNU Affero General Public License as
9
- * published by the Free Software Foundation (version 3 of the License).
10
- *
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
- *
16
- * See LICENSE.txt
17
- * END LICENSE
18
- */
19
-package net.bluemind.core.jdbc.schemaextractor;
20
-
21
-import org.eclipse.equinox.app.IApplication;
22
-import org.eclipse.equinox.app.IApplicationContext;
23
-
24
-public class ExtractorApplication implements IApplication {
25
-
26
-	@Override
27
-	public Object start(IApplicationContext context) throws Exception {
28
-		new SchemaExtractor().extract();
29
-		return null;
30
-	}
31
-
32
-	@Override
33
-	public void stop() {
34
-		// do nothing
35
-	}
36
-
37
-}
38 0
deleted file mode 100644
... ...
@@ -1,46 +0,0 @@
1
-/* BEGIN LICENSE
2
- * Copyright © Blue Mind SAS, 2012-2016
3
- *
4
- * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
- * solution.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of either the GNU Affero General Public License as
9
- * published by the Free Software Foundation (version 3 of the License).
10
- *
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
- *
16
- * See LICENSE.txt
17
- * END LICENSE
18
- */
19
-package net.bluemind.core.jdbc.schemaextractor;
20
-
21
-import java.io.File;
22
-import java.io.IOException;
23
-
24
-import com.google.common.io.ByteStreams;
25
-import com.google.common.io.Files;
26
-
27
-import net.bluemind.core.jdbc.SchemaDescriptor;
28
-import net.bluemind.core.jdbc.SchemaDescriptors;
29
-
30
-public class SchemaExtractor {
31
-
32
-	public void extract() throws IOException {
33
-		SchemaDescriptors descriptors = new SchemaDescriptors();
34
-
35
-		StringBuilder sb = new StringBuilder();
36
-		for (SchemaDescriptor descr : descriptors.getDescriptors()) {
37
-			byte[] schema = ByteStreams.toByteArray(descr.read());
38
-			sb.append("-- schema ").append(descr.getName()).append(descr.getVersion()).append("\n");
39
-			sb.append(new String(schema));
40
-			sb.append("\n\n");
41
-			System.out.println("registred schema " + descr.getName());
42
-		}
43
-
44
-		Files.write(sb.toString().getBytes(), new File("target/schema.sql"));
45
-	}
46
-}
... ...
@@ -12,7 +12,6 @@
12 12
 		<module>net.bluemind.dockerclient</module>
13 13
 		<module>net.bluemind.pool.dockerconfig</module>
14 14
 		<module>net.bluemind.tests.feature</module>
15
-		<module>net.bluemind.core.jdbc.schemaextractor</module>
16 15
 		<module>net.bluemind.config.testfragment</module>
17 16
 	</modules>
18 17
 
... ...
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
3 3
 Bundle-Name: ItemStore
4 4
 Bundle-SymbolicName: net.bluemind.core.container.sqlschema;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6
-Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0",
6
+Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0";visibility:=reexport,
7 7
  net.bluemind.system.schemaupgrader;bundle-version="4.1.0"
8 8
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9 9
 Automatic-Module-Name: net.bluemind.core.container.sqlschema
... ...
@@ -27,5 +27,4 @@ Export-Package: net.bluemind.core.rest,
27 27
 Bundle-Activator: net.bluemind.core.rest.RestActivator
28 28
 Eclipse-RegisterBuddy: net.bluemind.lib.vertx
29 29
 Bundle-ActivationPolicy: lazy
30
-Import-Package: org.apache.commons.lang
31 30
 
... ...
@@ -23,9 +23,9 @@ import java.util.ArrayList;
23 23
 import java.util.List;
24 24
 import java.util.Map;
25 25
 
26
-import org.apache.commons.lang.StringUtils;
27 26
 import org.vertx.java.core.buffer.Buffer;
28 27
 
28
+import com.google.common.base.Strings;
29 29
 import com.google.common.collect.ImmutableMap;
30 30
 
31 31
 import io.netty.buffer.Unpooled;
... ...
@@ -90,7 +90,7 @@ public class DefaultBodyParameterCodecs {
90 90
 		@Override
91 91
 		public T parse(RestRequest request) {
92 92
 			String m = request.headers.get("Content-Type");
93
-			if (StringUtils.isEmpty(m)) {
93
+			if (Strings.isNullOrEmpty(m)) {
94 94
 				m = defaultMimeType;
95 95
 			}
96 96
 
... ...
@@ -105,7 +105,7 @@ public class DefaultBodyParameterCodecs {
105 105
 		@Override
106 106
 		public void encode(T object, RestRequest request) {
107 107
 			String m = request.headers.get("Content-Type");
108
-			if (StringUtils.isEmpty(m)) {
108
+			if (Strings.isNullOrEmpty(m)) {
109 109
 				m = defaultMimeType;
110 110
 			}
111 111
 
... ...
@@ -8,3 +8,4 @@ Require-Bundle: net.bluemind.slf4j;bundle-version="1.0.0",
8 8
  org.eclipse.core.runtime,
9 9
  com.google.guava;bundle-version="19.0.0"
10 10
 Export-Package: net.bluemind.core.jdbc
11
+Automatic-Module-Name: net.bluemind.core.sqlschema
... ...
@@ -29,7 +29,8 @@ Require-Bundle: org.eclipse.core.runtime,
29 29
  net.bluemind.core.sessions,
30 30
  net.bluemind.system.config,
31 31
  org.freemarker.freemarker,
32
- net.bluemind.directory.hollow.datamodel.consumer
32
+ net.bluemind.directory.hollow.datamodel.consumer,
33
+ net.bluemind.system.schemaupgrader.runner
33 34
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
34 35
 Export-Package: net.bluemind.dataprotect.service,
35 36
  net.bluemind.dataprotect.service.internal,
... ...
@@ -56,7 +56,7 @@ import net.bluemind.server.api.Server;
56 56
 import net.bluemind.system.api.IInstallation;
57 57
 import net.bluemind.system.api.UpgradeReport;
58 58
 import net.bluemind.system.api.UpgradeReport.Status;
59
-import net.bluemind.system.schemaupgrader.SchemaUpgrade;
59
+import net.bluemind.system.schemaupgrader.runner.SchemaUpgrade;
60 60
 
61 61
 /**
62 62
  * Allows accessing backed-up data through the {@link IServiceProvider}
... ...
@@ -9,3 +9,4 @@ Require-Bundle: org.eclipse.core.runtime,
9 9
  net.bluemind.core.sqlschema
10 10
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
11 11
 Bundle-ActivationPolicy: lazy
12
+Automatic-Module-Name: net.bluemind.dataprotect.sqlschema
... ...
@@ -6,3 +6,4 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Bundle-Vendor: www.blue-mind.net
7 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 8
 Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0"
9
+Automatic-Module-Name: net.bluemind.device.sqlschema
... ...
@@ -3,5 +3,7 @@ Bundle-ManifestVersion: 2
3 3
 Bundle-Name: Persistance SQL Schema
4 4
 Bundle-SymbolicName: net.bluemind.directory.sqlschema;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6
-Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0"
6
+Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0",
7
+ net.bluemind.core.container.sqlschema;bundle-version="4.1.0"
7 8
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9
+Automatic-Module-Name: net.bluemind.directory.sqlschema
... ...
@@ -6,3 +6,4 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Bundle-Vendor: www.blue-mind.net
7 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 8
 Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0"
9
+Automatic-Module-Name: net.bluemind.document.sqlschema
... ...
@@ -1,9 +1,8 @@
1 1
 Manifest-Version: 1.0
2 2
 Bundle-ManifestVersion: 2
3
-Bundle-Name: Tests
3
+Bundle-Name: net.bluemind.domain.service.tests
4 4
 Bundle-SymbolicName: net.bluemind.domain.service.tests;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6
-Fragment-Host: net.bluemind.domain.service
7 6
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 7
 Require-Bundle: org.junit,
9 8
  net.bluemind.core.jdbc.testshelper;bundle-version="1.0.0",
... ...
@@ -17,6 +16,12 @@ Require-Bundle: org.junit,
17 16
  net.bluemind.core.tests.testshelper,
18 17
  net.bluemind.user.service,
19 18
  net.bluemind.resource.service;bundle-version="4.1.0",
20
- net.bluemind.system.api
19
+ net.bluemind.system.api,
20
+ net.bluemind.domain.service,
21
+ net.bluemind.role.api,
22
+ net.bluemind.domain.hook,
23
+ net.bluemind.core.rest.http,
24
+ net.bluemind.core.container.service
25
+Automatic-Module-Name: net.bluemind.domain.service.tests
21 26
 
22 27
 
... ...
@@ -1,5 +1,5 @@
1 1
 source.. = src/
2 2
 bin.includes = META-INF/,\
3 3
                .,\
4
-               fragment.xml
4
+               plugin.xml
5 5
 
6 6
deleted file mode 100644
... ...
@@ -1,11 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<?eclipse version="3.4"?>
3
-<fragment>
4
-   <extension
5
-         point="net.bluemind.domain.domainHook">
6
-      <hook
7
-            class="net.bluemind.domain.service.tests.FakeDomainHook">
8
-      </hook>
9
-   </extension>
10
-
11
-</fragment>
12 0
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<?eclipse version="3.4"?>
3
+<fragment>
4
+   <extension
5
+         point="net.bluemind.domain.domainHook">
6
+      <hook
7
+            class="net.bluemind.domain.service.tests.FakeDomainHook">
8
+      </hook>
9
+   </extension>
10
+
11
+</fragment>
... ...
@@ -6,4 +6,5 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Require-Bundle: net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
7 7
  net.bluemind.core.sqlschema;bundle-version="1.0.0"
8 8
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9
+Automatic-Module-Name: net.bluemind.domain.sqlschema
9 10
 
... ...
@@ -6,3 +6,4 @@ Bundle-Vendor: www.blue-mind.net
6 6
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
7 7
 Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0",
8 8
  net.bluemind.device.sqlschema;bundle-version="1.0.0"
9
+Automatic-Module-Name: net.bluemind.eas.sqlschema
... ...
@@ -7,5 +7,6 @@ Bundle-Vendor: www.blue-mind.net
7 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 8
 Require-Bundle: net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
9 9
  net.bluemind.core.sqlschema;bundle-version="1.0.0"
10
+Automatic-Module-Name: net.bluemind.filehosting.filesystem.sqlschema
10 11
 
11 12
 
... ...
@@ -6,3 +6,4 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Require-Bundle: net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
7 7
  net.bluemind.core.sqlschema;bundle-version="1.0.0"
8 8
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9
+Automatic-Module-Name: net.bluemind.group.sqlschema
... ...
@@ -6,3 +6,4 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Bundle-Vendor: www.blue-mind.net
7 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 8
 Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0"
9
+Automatic-Module-Name: net.bluemind.icalendar.sqlschema
... ...
@@ -7,3 +7,4 @@ Bundle-Vendor: www.blue-mind.net
7 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 8
 Require-Bundle: net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
9 9
  net.bluemind.core.sqlschema;bundle-version="1.0.0"
10
+Automatic-Module-Name: net.bluemind.im.sqlschema
... ...
@@ -4,7 +4,6 @@ Bundle-Name: net.bluemind.mailbox.hook.tests
4 4
 Bundle-SymbolicName: net.bluemind.mailbox.hook.tests;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6 6
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
7
-Fragment-Host: net.bluemind.mailbox.hook
8 7
 Require-Bundle: org.junit,
9 8
  net.bluemind.core.container.api;bundle-version="1.0.0",
10 9
  net.bluemind.core.container.persistance;bundle-version="1.0.0",
... ...
@@ -19,5 +18,7 @@ Require-Bundle: org.junit,
19 18
  net.bluemind.tests.defaultdata,
20 19
  net.bluemind.mailbox.service;bundle-version="1.0.0",
21 20
  net.bluemind.domain.api;bundle-version="1.0.0",
22
- net.bluemind.hsm.service;bundle-version="4.1.0"
21
+ net.bluemind.hsm.service;bundle-version="4.1.0",
22
+ net.bluemind.mailbox.hook
23
+Automatic-Module-Name: net.bluemind.mailbox.hook.tests
23 24
 
... ...
@@ -1,4 +1,4 @@
1 1
 source.. = src/
2 2
 bin.includes = .,\
3 3
                META-INF/,\
4
-               fragment.xml
4
+               plugin.xml
5 5
deleted file mode 100644
... ...
@@ -1,11 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<?eclipse version="3.4"?>
3
-<fragment>
4
-   <extension
5
-         point="net.bluemind.mailbox.hook">
6
-      <hook
7
-            class="net.bluemind.mailbox.hook.TestHook">
8
-      </hook>
9
-   </extension>
10
-
11
-</fragment>
12 0
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<?eclipse version="3.4"?>
3
+<fragment>
4
+   <extension
5
+         point="net.bluemind.mailbox.hook">
6
+      <hook
7
+            class="net.bluemind.mailbox.hook.TestHook">
8
+      </hook>
9
+   </extension>
10
+
11
+</fragment>
... ...
@@ -3,8 +3,7 @@ Bundle-ManifestVersion: 2
3 3
 Bundle-Name: net.bluemind.mailbox.identity.sqlschema
4 4
 Bundle-SymbolicName: net.bluemind.mailbox.identity.sqlschema;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6
-Require-Bundle: net.bluemind.core.container.sqlschema,
7
- net.bluemind.core.sqlschema,
8
- net.bluemind.mailbox.sqlschema;bundle-version="1.0.0"
6
+Require-Bundle: net.bluemind.mailbox.sqlschema;bundle-version="1.0.0"
9 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
10 8
 Bundle-Vendor: blue-mind.net
9
+Automatic-Module-Name: net.bluemind.mailbox.identity.sqlschema
... ...
@@ -3,7 +3,6 @@ Bundle-ManifestVersion: 2
3 3
 Bundle-Name: net.bluemind.mailbox.service.tests
4 4
 Bundle-SymbolicName: net.bluemind.mailbox.service.tests;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6
-Fragment-Host: net.bluemind.mailbox.service
7 6
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 7
 Require-Bundle: org.junit,
9 8
  net.bluemind.core.tests.testshelper,
... ...
@@ -32,6 +31,11 @@ Require-Bundle: org.junit,
32 31
  net.bluemind.resource.service;bundle-version="4.1.0",
33 32
  net.bluemind.backend.cyrus.partitions,
34 33
  net.bluemind.system.stateobserver.testhelper,
35
- net.bluemind.backend.mail.replica.service;bundle-version="4.1.0"
34
+ net.bluemind.backend.mail.replica.service;bundle-version="4.1.0",
35
+ net.bluemind.core.validator;bundle-version="4.1.0",
36
+ net.bluemind.mailbox.persistance,
37
+ net.bluemind.role.api;bundle-version="4.1.0",
38
+ net.bluemind.system.api,
39
+ net.bluemind.config
36 40
 Automatic-Module-Name: net.bluemind.mailbox.service.tests
37 41
 
... ...
@@ -3,8 +3,7 @@ Bundle-ManifestVersion: 2
3 3
 Bundle-Name: net.bluemind.mailbox.sqlschema
4 4
 Bundle-SymbolicName: net.bluemind.mailbox.sqlschema;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6
-Require-Bundle: net.bluemind.core.container.sqlschema,
7
- net.bluemind.core.sqlschema
6
+Require-Bundle: net.bluemind.core.container.sqlschema
8 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9 8
 Bundle-Vendor: blue-mind.net
10 9
 Automatic-Module-Name: net.bluemind.mailbox.sqlschema
... ...
@@ -8,3 +8,4 @@ Require-Bundle: net.bluemind.core.sqlschema,
8 8
  net.bluemind.core.container.sqlschema,
9 9
  net.bluemind.system.schemaupgrader
10 10
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
11
+Automatic-Module-Name: net.bluemind.exchange.mapi.sqlschema
... ...
@@ -6,4 +6,5 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Require-Bundle: net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
7 7
  net.bluemind.resource.sqlschema;bundle-version="1.0.0"
8 8
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9
+Automatic-Module-Name: net.bluemind.resource.sqlschema
9 10
 
... ...
@@ -6,3 +6,4 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Bundle-Vendor: www.blue-mind.net
7 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 8
 Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0"
9
+Automatic-Module-Name: net.bluemind.role.sqlschema
... ...
@@ -6,3 +6,4 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Bundle-Vendor: www.blue-mind.net
7 7
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
8 8
 Require-Bundle: net.bluemind.core.sqlschema;bundle-version="1.0.0"
9
+Automatic-Module-Name: net.bluemind.scheduledjob.sqlschema
... ...
@@ -6,4 +6,5 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
7 7
 Require-Bundle: net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
8 8
  net.bluemind.core.sqlschema;bundle-version="1.0.0"
9
+Automatic-Module-Name: net.bluemind.server.sqlschema
9 10
 
... ...
@@ -6,3 +6,4 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Require-Bundle: net.bluemind.core.container.sqlschema;bundle-version="1.0.0",
7 7
  net.bluemind.core.sqlschema;bundle-version="1.0.0"
8 8
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
9
+Automatic-Module-Name: net.bluemind.globalsettings.sqlschema
... ...
@@ -30,9 +30,9 @@ import org.slf4j.LoggerFactory;
30 30
 
31 31
 import net.bluemind.core.api.fault.ServerFault;
32 32
 import net.bluemind.core.jdbc.JdbcTestHelper;
33
-import net.bluemind.system.persistance.ComponentVersion;
34 33
 import net.bluemind.system.persistance.SchemaVersion;
35 34
 import net.bluemind.system.persistance.SchemaVersion.UpgradePhase;
35
+import net.bluemind.system.schemaupgrader.ComponentVersion;
36 36
 import net.bluemind.system.persistance.SchemaVersionStore;
37 37
 
38 38
 public class SchemaVersionStoreTests {
... ...
@@ -6,6 +6,7 @@ Bundle-Version: 4.1.0.qualifier
6 6
 Require-Bundle: net.bluemind.core.jdbc;bundle-version="1.0.0",
7 7
  net.bluemind.slf4j;bundle-version="1.0.0",
8 8
  net.bluemind.core.commons;bundle-version="1.0.0",
9
- net.bluemind.system.sqlschema;bundle-version="1.0.0";visibility:=reexport
9
+ net.bluemind.system.sqlschema;bundle-version="1.0.0";visibility:=reexport,
10
+ net.bluemind.system.schemaupgrader;visibility:=reexport
10 11
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
11 12
 Export-Package: net.bluemind.system.persistance
12 13
deleted file mode 100644
... ...
@@ -1,33 +0,0 @@
1
-/* BEGIN LICENSE
2
- * Copyright © Blue Mind SAS, 2012-2017
3
- *
4
- * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
- * solution.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of either the GNU Affero General Public License as
9
- * published by the Free Software Foundation (version 3 of the License).
10
- *
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
- *
16
- * See LICENSE.txt
17
- * END LICENSE
18
- */
19
-package net.bluemind.system.persistance;
20
-
21
-public class ComponentVersion {
22
-
23
-	public String identifier;
24
-	public String version;
25
-
26
-	public ComponentVersion() {
27
-	}
28
-
29
-	public ComponentVersion(String identifier, String version) {
30
-		this.identifier = identifier;
31
-		this.version = version;
32
-	}
33
-}
... ...
@@ -30,6 +30,7 @@ import org.slf4j.Logger;
30 30
 import org.slf4j.LoggerFactory;
31 31
 
32 32
 import net.bluemind.core.jdbc.JdbcAbstractStore;
33
+import net.bluemind.system.schemaupgrader.ComponentVersion;
33 34
 
34 35
 public final class SchemaVersionStore extends JdbcAbstractStore {
35 36
 
36 37
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
+	<classpathentry kind="src" path="src"/>
6
+	<classpathentry kind="output" path="bin"/>
7
+</classpath>
0 8
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>net.bluemind.system.schemaupgrader.runner</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.pde.ManifestBuilder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+		<buildCommand>
19
+			<name>org.eclipse.pde.SchemaBuilder</name>
20
+			<arguments>
21
+			</arguments>
22
+		</buildCommand>
23
+	</buildSpec>
24
+	<natures>
25
+		<nature>org.eclipse.pde.PluginNature</nature>
26
+		<nature>org.eclipse.jdt.core.javanature</nature>
27
+	</natures>
28
+</projectDescription>
0 29
new file mode 100644
... ...
@@ -0,0 +1,18 @@
1
+Manifest-Version: 1.0
2
+Bundle-ManifestVersion: 2
3
+Bundle-Name: net.bluemind.system.schemaupgrader.runner
4
+Bundle-SymbolicName: net.bluemind.system.schemaupgrader.runner;singleton:=true
5
+Bundle-Version: 4.1.0.qualifier
6
+Require-Bundle: org.eclipse.core.runtime,
7
+ net.bluemind.slf4j,
8
+ net.bluemind.core.jdbc;bundle-version="1.0.0",
9
+ net.bluemind.eclipse.common,
10
+ net.bluemind.system.api,
11
+ net.bluemind.system.persistance,
12
+ net.bluemind.core.rest,
13
+ net.bluemind.system.schemaupgrader;visibility:=reexport,
14
+ net.bluemind.core.task.spi
15
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
16
+Export-Package: net.bluemind.system.schemaupgrader.runner
17
+Automatic-Module-Name: net.bluemind.system.schemaupgrader.runner
18
+
0 19
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+source.. = src/
2
+output.. = bin/
3
+bin.includes = META-INF/,\
4
+               .
0 5
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
+  <modelVersion>4.0.0</modelVersion>
3
+  <parent>
4
+    <groupId>net.bluemind</groupId>
5
+    <version>4.1.0-SNAPSHOT</version>
6
+    <artifactId>net.bluemind.system.plugins</artifactId>
7
+  </parent>
8
+  <artifactId>net.bluemind.system.schemaupgrader.runner</artifactId>
9
+  <packaging>eclipse-plugin</packaging>
10
+</project>
0 11
new file mode 100644
... ...
@@ -0,0 +1,325 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.system.schemaupgrader.runner;
20
+
21
+import java.util.EnumSet;
22
+import java.util.HashSet;
23
+import java.util.LinkedList;
24
+import java.util.List;
25
+import java.util.Set;
26
+import java.util.concurrent.CompletableFuture;
27
+import java.util.concurrent.TimeUnit;
28
+import java.util.stream.Collectors;
29
+
30
+import javax.sql.DataSource;
31
+
32
+import org.slf4j.Logger;
33
+import org.slf4j.LoggerFactory;
34
+import org.vertx.java.core.AsyncResult;
35
+import org.vertx.java.core.eventbus.Message;
36
+import org.vertx.java.core.json.JsonObject;
37
+
38
+import com.google.common.collect.ImmutableList;
39
+
40
+import net.bluemind.core.api.VersionInfo;
41
+import net.bluemind.core.api.fault.ServerFault;
42
+import net.bluemind.core.jdbc.JdbcAbstractStore;
43
+import net.bluemind.core.rest.ServerSideServiceProvider;
44
+import net.bluemind.core.task.service.IServerTaskMonitor;
45
+import net.bluemind.lib.vertx.VertxPlatform;
46
+import net.bluemind.system.api.UpgradeReport;
47
+import net.bluemind.system.persistance.SchemaVersion;
48
+import net.bluemind.system.persistance.SchemaVersion.UpgradePhase;
49
+import net.bluemind.system.persistance.SchemaVersionStore;
50
+import net.bluemind.system.schemaupgrader.ClassUpdater;
51
+import net.bluemind.system.schemaupgrader.ComponentVersion;
52
+import net.bluemind.system.schemaupgrader.ComponentVersionExtensionPoint;
53
+import net.bluemind.system.schemaupgrader.ISchemaUpgradersProvider;
54
+import net.bluemind.system.schemaupgrader.IVersionedUpdater;
55
+import net.bluemind.system.schemaupgrader.SqlUpdater;
56
+import net.bluemind.system.schemaupgrader.UpdateAction;
57
+import net.bluemind.system.schemaupgrader.UpdateResult;
58
+import net.bluemind.system.schemaupgrader.Updater;
59
+import net.bluemind.system.schemaupgrader.Versions;
60
+
61
+public class SchemaUpgrade {
62
+	private DataSource pool;
63
+	private SchemaVersionStore upgraderStore;
64
+	private boolean onlySchema;
65
+
66
+	public SchemaUpgrade(DataSource pool, boolean onlySchema) {
67
+		super();
68
+		this.pool = pool;
69
+		this.onlySchema = onlySchema;
70
+		this.upgraderStore = new SchemaVersionStore(pool);
71
+	}
72
+
73
+	public SchemaUpgrade(DataSource pool) {
74
+		this(pool, false);
75
+	}
76
+
77
+	private static final Logger logger = LoggerFactory.getLogger(SchemaUpgrade.class);
78
+
79
+	public UpdateResult schemaUpgrade(IServerTaskMonitor monitor, UpgradeReport report, VersionInfo from,
80
+			VersionInfo to) {
81
+		List<ComponentVersion> installedComponents = ComponentVersionExtensionPoint.getComponentsVersion();
82
+		List<ComponentVersion> componentDbVersion = getComponentsVersion();
83
+
84
+		List<ComponentVersion> toUpdate = installedComponents.stream()
85
+				.map(ic -> componentDbVersion.stream().filter(cdb -> cdb.identifier.equals(ic.identifier)).findAny()
86
+						.orElse(new ComponentVersion(ic.identifier,
87
+								"bm/core".equals(ic.identifier) ? from.toString() : "0.0.1")))
88
+				.collect(Collectors.toList());
89
+		monitor.begin(installedComponents.size(), null);
90
+
91
+		for (ComponentVersion comp : toUpdate) {
92
+			VersionInfo lfrom = VersionInfo.checkAndCreate(comp.version);
93
+			logger.info("component version {} : {}", comp.identifier, lfrom);
94
+			UpdateResult schemaUpgrade = schemaUpgrade(monitor.subWork(1), report, lfrom, to, comp.identifier);
95
+
96
+			if (schemaUpgrade.equals(UpdateResult.failed())) {
97
+				monitor.end(false, "Upgrade failed !", "");
98
+				return UpdateResult.failed();
99
+			}
100
+		}
101
+
102
+		updateSchemaVersion(to.major, to.minor, Integer.parseInt(to.release));
103
+		monitor.end(true, "Schema upgrade complete.", "");
104
+		return UpdateResult.ok();
105
+
106
+	}
107
+
108
+	private List<ComponentVersion> getComponentsVersion() {
109
+		try {
110
+			return upgraderStore.getComponentsVersion();
111
+		} catch (Exception e) {
112
+			logger.info("error retrieving database version : {}", e.getMessage(), e);
113
+			return ImmutableList.of();
114
+		}
115
+	}
116
+
117
+	public UpdateResult schemaUpgrade(IServerTaskMonitor subWork, UpgradeReport report, VersionInfo from,
118
+			VersionInfo to, String component) throws ServerFault {
119
+		List<Updater> pathToGlory = null;
120
+		try {
121
+			pathToGlory = getUpgradePath(from, to, component);
122
+		} catch (ServerFault e) {
123
+			return UpdateResult.failed();
124
+		}
125
+		logger.info("Schema update path contains {} updater(s)", pathToGlory.size());
126
+		subWork.begin(pathToGlory.size(), "Starting schema upgrades....");
127
+		Set<UpdateAction> handledActions = EnumSet.noneOf(UpdateAction.class);
128
+
129
+		List<Updater> phase1 = pathToGlory.stream().filter(u -> !u.afterSchemaUpgrade()).collect(Collectors.toList());
130
+
131
+		List<Updater> phase2 = pathToGlory.stream().filter(u -> u.afterSchemaUpgrade() && !onlySchema)
132
+				.collect(Collectors.toList());
133
+
134
+		executeUpdates(subWork, report, handledActions, UpgradePhase.SCHEMA_UPGRADE, phase1);
135
+
136
+		CompletableFuture<Void> ret = new CompletableFuture<>();
137
+		if (ServerSideServiceProvider.mailboxDataSource == null
138
+				|| ServerSideServiceProvider.mailboxDataSource.isEmpty()) {
139
+			VertxPlatform.getVertx().eventBus().sendWithTimeout("mailbox.ds.lookup", new JsonObject(), 7000l,
140
+					(AsyncResult<Message<String>> event) -> {
141
+						if (event.failed()) {
142
+							ret.completeExceptionally(event.cause());
143
+						} else {
144
+							ret.complete(null);
145
+						}
146
+					});
147
+		} else {
148
+			ret.complete(null);
149
+		}
150
+
151
+		try {
152
+			ret.get(10, TimeUnit.SECONDS);
153
+		} catch (Exception e1) {
154
+			logger.warn("Error while looking up mailbox datasource", e1);
155
+			return UpdateResult.failed();
156
+		}
157
+
158
+		subWork.log("going phase 2");
159
+		return executeUpdates(subWork, report, handledActions, UpgradePhase.POST_SCHEMA_UPGRADE, phase2);
160
+	}
161
+
162
+	private UpdateResult executeUpdates(IServerTaskMonitor subWork, UpgradeReport report,
163
+			Set<net.bluemind.system.schemaupgrader.UpdateAction> handledActions, UpgradePhase phase,
164
+			List<Updater> updates) {
165
+		UpdateResult ur = UpdateResult.noop();
166
+		for (Updater u : updates) {
167
+			logger.info("Starting {}", u);
168
+			subWork.log("Starting " + u);
169
+			try {
170
+				ur = u.update(subWork, new HashSet<>(handledActions));
171
+				handledActions.addAll(ur.actions);
172
+			} catch (Exception e) {
173
+				logger.error(e.getMessage(), e);
174
+				subWork.log(e.getMessage());
175
+				ur = UpdateResult.failed();
176
+			}
177
+
178
+			saveUpgraderStatus(ur, u, phase, u.getComponent());
179
+
180
+			if (ur.equals(UpdateResult.failed())) {
181
+				report.upgraders
182
+						.add(UpgradeReport.UpgraderReport.create(u.major(), u.build(), UpgradeReport.Status.FAILED));
183
+				subWork.end(false, "Schema upgrade failed.", "");
184
+				return ur;
185
+			} else {
186
+				report.upgraders
187
+						.add(UpgradeReport.UpgraderReport.create(u.major(), u.build(), UpgradeReport.Status.OK));
188
+
189
+			}
190
+
191
+			subWork.progress(1, "Updater " + u + " complete (result: " + ur + ")");
192
+		}
193
+		return ur;
194
+	}
195
+
196
+	private void saveUpgraderStatus(UpdateResult updateResult, Updater updater, UpgradePhase phase, String component) {
197
+		SchemaVersion upgraderStatus = new SchemaVersion(updater.major(), updater.build()) //
198
+				.phase(phase) //
199
+				.component(component) //
200
+				.success(!updateResult.equals(UpdateResult.failed()));
201
+		upgraderStore.add(upgraderStatus);
202
+	}
203
+
204
+	private void updateSchemaVersion(String major, String minor, int build) {
205
+
206
+		SchemaVersionStore store = new SchemaVersionStore(pool);
207
+
208
+		JdbcAbstractStore.doOrFail(() -> {
209
+			for (ComponentVersion cp : ComponentVersionExtensionPoint.getComponentsVersion()) {
210
+				store.updateComponentVersion(cp.identifier, major + "." + minor + "." + build);
211
+			}
212
+			return null;
213
+		});
214
+	}
215
+
216
+	public List<Updater> getUpgradePath(VersionInfo source, VersionInfo target, String component) throws ServerFault {
217
+		VersionInfo dbScriptStart = VersionInfo.create(source.toString());
218
+		VersionInfo dbScriptEnd = VersionInfo.create(target.toString());
219
+
220
+		// If end is in the dev branch, script major = version major + 1
221
+		if (!dbScriptEnd.stable()) {
222
+			dbScriptEnd.major = "" + ((Integer.parseInt(dbScriptEnd.major)) + 1);
223
+		}
224
+
225
+		// If start from a dev branch, script major = version major + 1
226
+		if (!dbScriptStart.stable()) {
227
+			dbScriptStart.major = "" + ((Integer.parseInt(dbScriptStart.major)) + 1);
228
+		}
229
+
230
+		LinkedList<Updater> upgradePath = new LinkedList<>();
231
+
232
+		logger.info("dbScriptStart: {}, dbScriptEnd: {}", dbScriptStart, dbScriptEnd);
233
+
234
+		ISchemaUpgradersProvider upgradersProvider = ISchemaUpgradersProvider.getSchemaUpgradersProvider();
235
+		if (upgradersProvider == null) {
236
+			StringBuilder msg = new StringBuilder("*********************************************************");
237
+			msg.append("* No upgraders found. Make sure the package bm-core-upgraders is installed.");
238
+			msg.append("*********************************************************");
239
+			logger.warn("{}", msg);
240
+			throw new ServerFault("Upgraders are not available");
241
+		}
242
+
243
+		if (!upgradersProvider.isActive()) {
244
+			StringBuilder msg = new StringBuilder("*********************************************************");
245
+			msg.append("* upgraders is not active. Make sure your subscription is valid.");
246
+			msg.append("*********************************************************");
247
+			logger.warn("{}", msg);
248
+			throw new ServerFault("Upgraders are not available");
249
+
250
+		}
251
+
252
+		List<IVersionedUpdater> allJavaUpdaters = upgradersProvider.allJavaUpdaters(pool);
253
+		List<Updater> allSqlUpdaters = upgradersProvider.allSqlUpdaters(pool);
254
+
255
+		int major = Integer.parseInt(dbScriptStart.major);
256
+		int start;
257
+		int end;
258
+		while (major <= Integer.parseInt(dbScriptEnd.major)) {
259
+			start = 0;
260
+			if (major == Integer.parseInt(dbScriptStart.major)) {
261
+				start = Integer.parseInt(dbScriptStart.release);
262
+			}
263
+			if (major < Integer.parseInt(dbScriptEnd.major)) {
264
+				end = Integer.MAX_VALUE;
265
+			} else {
266
+				end = Integer.parseInt(dbScriptEnd.release);
267
+			}
268
+
269
+			logger.debug("add to upgrade paths: major: {}, start: {}, end: {}", major, start, end);
270
+
271
+			UpdaterFilter filter = new UpdaterFilter(major, start, end, upgraderStore.get(major, start), component);
272
+			collectSqlFiles(upgradePath, filter, allSqlUpdaters);
273
+			collectClassInstances(upgradePath, filter, allJavaUpdaters);
274
+
275
+			major++;
276
+		}
277
+		// make sure, updaters will get executed in order
278
+		Versions.sort(upgradePath);
279
+		return upgradePath;
280
+	}
281
+
282
+	// FIXME add component to classInsance
283
+	private void collectClassInstances(LinkedList<Updater> upgradePath, UpdaterFilter filter,
284
+			List<IVersionedUpdater> updaters) {
285
+		Set<String> classes = new HashSet<>();
286
+		for (IVersionedUpdater instance : updaters) {
287
+			String upgraderClassName = instance.getClass().getName();
288
+			if (!classes.contains(upgraderClassName)) {
289
+				if (filter.accept(instance.major(), instance.buildNumber(), "bm/core",
290
+						instance.afterSchemaUpgrade() ? UpgradePhase.POST_SCHEMA_UPGRADE
291
+								: UpgradePhase.SCHEMA_UPGRADE)) {
292
+					ClassUpdater u = new ClassUpdater(pool, instance, "bm/core");
293
+					upgradePath.add(u);
294
+					logger.info("Accepted {}", u);
295
+				} else {
296
+					logger.debug("Not Accepted {}", new ClassUpdater(pool, instance, "bm/core"));
297
+				}
298
+				classes.add(upgraderClassName);
299
+			} else {
300
+				logger.info("Skipping duplicate java file upgrader {}", upgraderClassName);
301
+			}
302
+		}
303
+	}
304
+
305
+	private void collectSqlFiles(LinkedList<Updater> upgradePath, UpdaterFilter filter, List<Updater> updaters) {
306
+		Set<String> files = new HashSet<>();
307
+		for (Updater u : updaters) {
308
+			String file = ((SqlUpdater) u).file.toString();
309
+
310
+			if (!files.contains(file)) {
311
+				if (filter.accept(u.major(), u.build(), u.getComponent(),
312
+						u.afterSchemaUpgrade() ? UpgradePhase.POST_SCHEMA_UPGRADE : UpgradePhase.SCHEMA_UPGRADE)) {
313
+					upgradePath.add(u);
314
+					files.add(file);
315
+					logger.info("Accepted {}", u);
316
+				} else {
317
+					logger.debug("Not Accepted {}", u);
318
+				}
319
+			} else {
320
+				logger.info("Skipping duplicate sql file upgrader {}", file);
321
+			}
322
+		}
323
+	}
324
+
325
+}
0 326
new file mode 100644
... ...
@@ -0,0 +1,71 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of either the GNU Affero General Public License as
9
+ * published by the Free Software Foundation (version 3 of the License).
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
+ *
16
+ * See LICENSE.txt
17
+ * END LICENSE
18
+ */
19
+package net.bluemind.system.schemaupgrader.runner;
20
+
21
+import java.util.List;
22
+
23
+import net.bluemind.system.persistance.SchemaVersion;
24
+import net.bluemind.system.persistance.SchemaVersion.UpgradePhase;
25
+
26
+public class UpdaterFilter {
27
+
28
+	private final int releaseMajor;
29
+	private final int releaseStart;
30
+	private final int releaseEnd;
31
+	private final List<SchemaVersion> storedUpgraders;
32
+	private String component;
33
+
34
+	public UpdaterFilter(int major, int start, int end, List<SchemaVersion> storedUpgraders, String component) {
35
+		releaseMajor = major;
36
+		releaseStart = start;
37
+		releaseEnd = end;
38
+		this.storedUpgraders = storedUpgraders;
39
+		this.component = component;
40
+	}
41
+
42
+	public boolean accept(int major, int release, String component, UpgradePhase phase) {
43
+		if (!component.equals(this.component)) {
44
+			return false;
45
+		}
46
+		if (upgraderAlreadyPassed(major, release, component, phase)) {
47
+			return false;
48
+		}
49
+		return checkVersion(major, release);
50
+	}
51
+
52
+	private boolean upgraderAlreadyPassed(int major, int release, String component, UpgradePhase phase) {
53
+		SchemaVersion thisUpgrader = new SchemaVersion(major, release).component(component).phase(phase);
54
+		for (SchemaVersion schemaVersion : storedUpgraders) {
55
+			if (thisUpgrader.equals(schemaVersion) && schemaVersion.success) {
56
+				return true;
57
+			}
58
+		}
59
+		return false;
60
+	}
61
+
62
+	private boolean checkVersion(int major, int release) {
63
+		if (major != releaseMajor) {
64
+			return false;
65
+		}
66
+		if (release > releaseStart && release <= releaseEnd) {
67
+			return true;
68
+		}
69
+		return false;
70
+	}
71
+}
... ...
@@ -5,6 +5,10 @@ Bundle-SymbolicName: net.bluemind.system.schemaupgrader.tests;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6 6
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
7 7
 Bundle-Vendor: blue-mind.net
8
-Fragment-Host: net.bluemind.system.schemaupgrader
9 8
 Require-Bundle: org.junit,
10
- net.bluemind.core.jdbc.testshelper;bundle-version="1.0.0"
9
+ net.bluemind.core.jdbc.testshelper;bundle-version="1.0.0",
10
+ net.bluemind.system.schemaupgrader.runner,
11
+ net.bluemind.core.commons,
12
+ net.bluemind.core.task.spi,
13
+ net.bluemind.eclipse.common
14
+Automatic-Module-Name: net.bluemind.system.schemaupgrader.tests
... ...
@@ -3,4 +3,4 @@ output.. = bin/
3 3
 bin.includes = META-INF/,\
4 4
                .,\
5 5
                sql_samples/,\
6
-               fragment.xml
6
+               plugin.xml
7 7
deleted file mode 100644
... ...
@@ -1,38 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<?eclipse version="3.4"?>
3
-<fragment>
4
-   <extension
5
-         point="net.bluemind.system.schemaupgrader.javacode">
6
-      <java
7
-            code="net.bluemind.system.schemaupgrader.tests.samples.JavaCodeUpdater">
8
-      </java>
9
-   </extension>
10
-   <extension
11
-         point="net.bluemind.system.schemaupgrader.sqlscript">
12
-      <sql
13
-            build_number="75"
14
-            ignore_errors="true"
15
-            major="31"
16
-            script="sql_samples/dummy.sql">
17
-      </sql>
18
-      <sql
19
-            after_schema_upgrade="true"
20
-            build_number="76"
21
-            ignore_errors="true"
22
-            major="31"
23
-            script="sql_samples/dummy.sql">
24
-      </sql>
25
-      <sql
26
-            build_number="4"
27
-            ignore_errors="false"
28
-            major="0"
29
-            script="sql_samples/not_found.sql">
30
-      </sql>
31
-   </extension>
32
-   <extension
33
-         point="net.bluemind.system.schemaupgrader.upgradersprovider">
34
-      <upgraders-provider
35
-            class="net.bluemind.system.schemaupgrader.tests.internal.TestSchemaProvider">
36
-      </upgraders-provider>
37
-   </extension>
38
-</fragment>
39 0
new file mode 100644
... ...
@@ -0,0 +1,38 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<?eclipse version="3.4"?>
3
+<fragment>
4
+   <extension
5
+         point="net.bluemind.system.schemaupgrader.javacode">
6
+      <java
7
+            code="net.bluemind.system.schemaupgrader.tests.samples.JavaCodeUpdater">
8
+      </java>
9
+   </extension>
10
+   <extension
11
+         point="net.bluemind.system.schemaupgrader.sqlscript">
12
+      <sql
13
+            build_number="75"
14
+            ignore_errors="true"
15
+            major="31"
16
+            script="sql_samples/dummy.sql">
17
+      </sql>
18
+      <sql
19
+            after_schema_upgrade="true"
20
+            build_number="76"
21
+            ignore_errors="true"
22
+            major="31"
23
+            script="sql_samples/dummy.sql">
24
+      </sql>
25
+      <sql
26
+            build_number="4"
27
+            ignore_errors="false"
28
+            major="0"
29
+            script="sql_samples/not_found.sql">
30
+      </sql>
31
+   </extension>
32
+   <extension
33
+         point="net.bluemind.system.schemaupgrader.upgradersprovider">
34
+      <upgraders-provider
35
+            class="net.bluemind.system.schemaupgrader.tests.internal.TestSchemaProvider">
36
+      </upgraders-provider>
37
+   </extension>
38
+</fragment>
... ...
@@ -34,20 +34,15 @@ import net.bluemind.core.api.VersionInfo;
34 34
 import net.bluemind.core.api.fault.ServerFault;
35 35
 import net.bluemind.core.jdbc.JdbcActivator;
36 36
 import net.bluemind.core.jdbc.JdbcTestHelper;
37
-import net.bluemind.core.task.service.IServerTaskMonitor;
38
-import net.bluemind.system.schemaupgrader.internal.ClassUpdater;
39
-import net.bluemind.system.schemaupgrader.internal.SqlUpdater;
40
-import net.bluemind.system.schemaupgrader.tests.internal.TestMonitor;
37
+import net.bluemind.system.schemaupgrader.runner.SchemaUpgrade;
41 38
 
42 39
 public class SchemaUpgraderTests {
43 40
 	private DataSource pool;
44
-	private IServerTaskMonitor monitor;
45 41
 
46 42
 	@Before
47 43
 	public void before() throws Exception {
48 44
 		JdbcTestHelper.getInstance().beforeTest();
49 45
 		this.pool = JdbcActivator.getInstance().getDataSource();
50
-		this.monitor = new TestMonitor();
51 46
 	}
52 47
 
53 48
 	@After
... ...
@@ -34,7 +34,6 @@ import org.junit.Test;
34 34
 
35 35
 import net.bluemind.core.jdbc.JdbcActivator;
36 36
 import net.bluemind.core.jdbc.JdbcTestHelper;
37
-import net.bluemind.system.schemaupgrader.internal.SqlScripts;
38 37
 
39 38
 public class SqlScriptTests {
40 39
 
... ...
@@ -25,8 +25,8 @@ import javax.sql.DataSource;
25 25
 import net.bluemind.eclipse.common.RunnableExtensionLoader;
26 26
 import net.bluemind.system.schemaupgrader.ISchemaUpgradersProvider;
27 27
 import net.bluemind.system.schemaupgrader.IVersionedUpdater;
28
+import net.bluemind.system.schemaupgrader.SqlScripts;
28 29
 import net.bluemind.system.schemaupgrader.Updater;
29
-import net.bluemind.system.schemaupgrader.internal.SqlScripts;
30 30
 
31 31
 public class TestSchemaProvider implements ISchemaUpgradersProvider {
32 32
 
... ...
@@ -3,18 +3,13 @@ Bundle-ManifestVersion: 2
3 3
 Bundle-Name: net.bluemind.system.schemaupgrader
4 4
 Bundle-SymbolicName: net.bluemind.system.schemaupgrader;singleton:=true
5 5
 Bundle-Version: 4.1.0.qualifier
6
-Bundle-Activator: net.bluemind.system.schemaupgrader.Activator
7
-Require-Bundle: org.eclipse.core.runtime,
8
- net.bluemind.core.task.service,
6
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
9 7
  net.bluemind.slf4j,
10
- net.bluemind.core.jdbc;bundle-version="1.0.0",
11 8
  net.bluemind.eclipse.common,
12 9
  net.bluemind.system.api,
13
- net.bluemind.system.persistance,
14
- net.bluemind.lib.vertx,
15
- net.bluemind.core.rest
10
+ com.google.guava,
11
+ net.bluemind.core.task.spi
16 12
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
17
-Bundle-ActivationPolicy: lazy
18
-Export-Package: net.bluemind.system.schemaupgrader,
19
- net.bluemind.system.schemaupgrader.internal
13
+Export-Package: net.bluemind.system.schemaupgrader
14
+Automatic-Module-Name: net.bluemind.system.schemaupgrader
20 15
 
... ...
@@ -1,6 +1,7 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <?eclipse version="3.4"?>
3 3
 <plugin>
4
+
4 5
    <extension-point id="net.bluemind.system.schemaupgrader.sqlscript" name="sqlscript" schema="schema/net.bluemind.system.schemaupgrader.sqlscript.exsd"/>
5 6
    <extension-point id="net.bluemind.system.schemaupgrader.javacode" name="javacode" schema="schema/net.bluemind.system.schemaupgrader.javacode.exsd"/>
6 7
    <extension-point id="net.bluemind.system.schemaupgrader.upgradersprovider" name="upgradersprovider" schema="schema/net.bluemind.system.schemaupgrader.upgradersprovider.exsd"/>
7 8
deleted file mode 100644
... ...
@@ -1,30 +0,0 @@
1
-package net.bluemind.system.schemaupgrader;
2
-
3
-import org.osgi.framework.BundleActivator;
4
-import org.osgi.framework.BundleContext;
5
-
6
-public class Activator implements BundleActivator {
7
-
8
-	private static BundleContext context;
9
-
10
-	static BundleContext getContext() {
11
-		return context;
12
-	}
13
-
14
-	/*
15
-	 * (non-Javadoc)
16
-	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
17
-	 */
18
-	public void start(BundleContext bundleContext) throws Exception {
19
-		Activator.context = bundleContext;
20
-	}
21
-
22
-	/*
23
-	 * (non-Javadoc)
24
-	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
25
-	 */
26
-	public void stop(BundleContext bundleContext) throws Exception {
27
-		Activator.context = null;
28
-	}
29
-
30
-}
31 0
new file mode 100644
... ...
@@ -0,0 +1,87 @@
1
+/* BEGIN LICENSE
2
+ * Copyright © Blue Mind SAS, 2012-2016
3
+ *
4
+ * This file is part of BlueMind. BlueMind is a messaging and collaborative
5
+ * solution.
6