Commit 5d951c09 authored by Marco Descher's avatar Marco Descher

[15349] Update productive target, add p2 feature to check updates

parent c39fb3c3
Pipeline #10435 passed with stages
in 2 minutes and 22 seconds
package info.elexis.server.core.p2.console; package info.elexis.server.core.p2.console;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.equinox.p2.operations.Update;
import org.eclipse.osgi.framework.console.CommandInterpreter; import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider; import org.eclipse.osgi.framework.console.CommandProvider;
import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Activate;
...@@ -14,52 +16,58 @@ import info.elexis.server.core.p2.internal.ProvisioningHelper; ...@@ -14,52 +16,58 @@ import info.elexis.server.core.p2.internal.ProvisioningHelper;
@Component(service = CommandProvider.class, immediate = true) @Component(service = CommandProvider.class, immediate = true)
public class ConsoleCommandProvider extends AbstractConsoleCommandProvider { public class ConsoleCommandProvider extends AbstractConsoleCommandProvider {
@Activate @Activate
public void activate(){ public void activate() {
register(this.getClass()); register(this.getClass());
} }
@CmdAdvisor(description = "feature de-/installation and update repository management") @CmdAdvisor(description = "feature de-/installation and update repository management")
public void _p2(CommandInterpreter ci){ public void _p2(CommandInterpreter ci) {
executeCommand("p2", ci); executeCommand("p2", ci);
} }
@CmdAdvisor(description = "get possible updates")
public void __p2_update_check() {
Update[] possibleUpdates = ProvisioningHelper.getPossibleUpdates();
Arrays.asList(possibleUpdates).stream().forEach(c -> ci.println(c));
}
@CmdAdvisor(description = "update all installed features") @CmdAdvisor(description = "update all installed features")
public String __p2_executeUpdate(){ public String __p2_update_execute() {
return ProvisioningHelper.updateAllFeatures().getMessage(); return ProvisioningHelper.updateAllFeatures().getMessage();
} }
@CmdAdvisor(description = "list the installed features") @CmdAdvisor(description = "list the installed features")
public String __p2_features_listLocal(){ public String __p2_features_listLocal() {
return ProvisioningHelper return ProvisioningHelper
.getAllInstalledFeatures().stream().map(i -> i.getId() + " (" + i.getVersion() + ") " .getAllInstalledFeatures().stream().map(i -> i.getId() + " (" + i.getVersion() + ") "
+ i.getProperty("git-repo-url") + " " + i.getProperty("git-rev")) + i.getProperty("git-repo-url") + " " + i.getProperty("git-rev"))
.reduce((u, t) -> u + "\n" + t).get(); .reduce((u, t) -> u + "\n" + t).get();
} }
@CmdAdvisor(description = "install a feature") @CmdAdvisor(description = "install a feature")
public String __p2_features_install(Iterator<String> args){ public String __p2_features_install(Iterator<String> args) {
if (args.hasNext()) { if (args.hasNext()) {
return ProvisioningHelper.unInstallFeature(args.next(), true); return ProvisioningHelper.unInstallFeature(args.next(), true);
} }
return missingArgument("featureName"); return missingArgument("featureName");
} }
@CmdAdvisor(description = "uninstall a feature") @CmdAdvisor(description = "uninstall a feature")
public String __p2_features_uninstall(Iterator<String> args){ public String __p2_features_uninstall(Iterator<String> args) {
if (args.hasNext()) { if (args.hasNext()) {
return ProvisioningHelper.unInstallFeature(args.next(), false); return ProvisioningHelper.unInstallFeature(args.next(), false);
} }
return missingArgument("featureName"); return missingArgument("featureName");
} }
@CmdAdvisor(description = "list configured repositories") @CmdAdvisor(description = "list configured repositories")
public String __p2_repo_list(){ public String __p2_repo_list() {
return HTTPServiceHelper.getRepoInfo(null).toString(); return HTTPServiceHelper.getRepoInfo(null).toString();
} }
public String __p2_repo_add(Iterator<String> args){ public String __p2_repo_add(Iterator<String> args) {
if (args.hasNext()) { if (args.hasNext()) {
final String url = args.next(); final String url = args.next();
String user = null; String user = null;
...@@ -70,18 +78,17 @@ public class ConsoleCommandProvider extends AbstractConsoleCommandProvider { ...@@ -70,18 +78,17 @@ public class ConsoleCommandProvider extends AbstractConsoleCommandProvider {
if (args.hasNext()) { if (args.hasNext()) {
password = args.next(); password = args.next();
} }
return HTTPServiceHelper.doRepositoryAdd(url, user, password).getStatusInfo() return HTTPServiceHelper.doRepositoryAdd(url, user, password).getStatusInfo().toString();
.toString();
} }
return missingArgument("url [user] [password]"); return missingArgument("url [user] [password]");
} }
public String __p2_repo_remove(Iterator<String> args){ public String __p2_repo_remove(Iterator<String> args) {
if (args.hasNext()) { if (args.hasNext()) {
final String url = args.next(); final String url = args.next();
return HTTPServiceHelper.doRepositoryRemove(url).getStatusInfo().toString(); return HTTPServiceHelper.doRepositoryRemove(url).getStatusInfo().toString();
} }
return missingArgument("url"); return missingArgument("url");
} }
} }
...@@ -86,7 +86,7 @@ public class ProvisioningHelper { ...@@ -86,7 +86,7 @@ public class ProvisioningHelper {
IMetadataRepositoryManager metadataRepoMgr = Provisioner.getInstance().getMetadataRepositoryManager(); IMetadataRepositoryManager metadataRepoMgr = Provisioner.getInstance().getMetadataRepositoryManager();
if (metadataRepoMgr.contains(location)) { if (metadataRepoMgr.contains(location)) {
result &= metadataRepoMgr.removeRepository(location); result &= metadataRepoMgr.removeRepository(location);
log.debug("Removed metadata repository {}", location); log.debug("Removed metadata repository {}", location);
} }
return result; return result;
...@@ -107,7 +107,20 @@ public class ProvisioningHelper { ...@@ -107,7 +107,20 @@ public class ProvisioningHelper {
registerHttpAuthentication(location, username, password); registerHttpAuthentication(location, username, password);
} }
public static IStatus updateAllFeatures() { public static Update[] getPossibleUpdates() {
UpdateOperation updateOperation = determinePossibleUpdates();
if (updateOperation != null) {
return updateOperation.getPossibleUpdates();
}
return new Update[] {};
}
/**
*
* @return an {@link UpdateOperation} if updates where found, else
* <code>null</code>
*/
private static UpdateOperation determinePossibleUpdates() {
IProvisioningAgent agent = Provisioner.getInstance().getProvisioningAgent(); IProvisioningAgent agent = Provisioner.getInstance().getProvisioningAgent();
ProvisioningHelper.refreshRepositories(); ProvisioningHelper.refreshRepositories();
...@@ -121,30 +134,26 @@ public class ProvisioningHelper { ...@@ -121,30 +134,26 @@ public class ProvisioningHelper {
UpdateOperation operation = new UpdateOperation(session, units.toUnmodifiableSet()); UpdateOperation operation = new UpdateOperation(session, units.toUnmodifiableSet());
IStatus status = operation.resolveModal(new TimeoutProgressMonitor(15000)); IStatus status = operation.resolveModal(new TimeoutProgressMonitor(15000));
log.info("[UPDATE] Check for updates {} | severity {} | code {}", status.getMessage(), status.getSeverity(), if (status.getSeverity() == Status.ERROR) {
status.getCode()); StatusUtil.logStatus("determine updates", log, status);
}
if ((!status.isOK() && status.getCode() == 10000 && status.getSeverity() == 1)) { if ((!status.isOK() && status.getCode() == 10000 && status.getSeverity() == 1)) {
// no updates available // no updates available
return status; return null;
} else { } else {
Update[] possibleUpdates = operation.getPossibleUpdates(); return operation;
for (Update update : possibleUpdates) {
log.debug("[UPDATE] Found update {}", update.replacement);
}
} }
}
if (status.getSeverity() != IStatus.ERROR) { public static IStatus updateAllFeatures() {
IStatus stat = ProvisioningHelper.performOperation(operation); UpdateOperation updateOperation = determinePossibleUpdates();
log.info("[UPDATE] Finished {} | severity {} | code {}", stat.getMessage(), if (updateOperation == null) {
stat.getSeverity(), stat.getCode()); return Status.OK_STATUS;
// TODO perform restart
} else {
log.warn("[UPDATE] FAILED {} | severity {} | code {}", status.getMessage(),
status.getSeverity(), status.getCode());
StatusUtil.logStatus(log, status);
} }
return status; IStatus stat = ProvisioningHelper.performOperation(updateOperation);
StatusUtil.logStatus("update finished", log, stat);
return stat;
} }
public static Collection<IInstallableUnit> getAllInstalledFeatures() { public static Collection<IInstallableUnit> getAllInstalledFeatures() {
...@@ -204,8 +213,8 @@ public class ProvisioningHelper { ...@@ -204,8 +213,8 @@ public class ProvisioningHelper {
/** /**
* *
* @param featureName * @param featureName
* @param install * @param install <code>true</code> to install, <code>false</code> to
* <code>true</code> to install, <code>false</code> to uninstall * uninstall
* @return * @return
*/ */
public static String unInstallFeature(String featureName, boolean install) { public static String unInstallFeature(String featureName, boolean install) {
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?> <?pde?>
<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl --> <!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl -->
<target name="Elexis-Server" sequenceNumber="1562681306"> <target name="Elexis-Server" sequenceNumber="1562917366">
<locations> <locations>
<location includeMode="slicer" includeAllPlatforms="true" includeSource="true" includeConfigurePhase="false" type="InstallableUnit"> <location includeMode="slicer" includeAllPlatforms="true" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.osgi.framework.system.packages.extra" version="1.0.0.20190124-1239"/> <unit id="org.osgi.framework.system.packages.extra" version="1.0.0.20190124-1239"/>
...@@ -77,7 +77,7 @@ ...@@ -77,7 +77,7 @@
<unit id="com.eclipsesource.jaxrs.provider.swagger.feature.feature.group" version="1.1.1.201905211243"/> <unit id="com.eclipsesource.jaxrs.provider.swagger.feature.feature.group" version="1.1.1.201905211243"/>
<unit id="com.eclipsesource.jaxrs.provider.multipart.feature.feature.group" version="2.2.0.201905211243"/> <unit id="com.eclipsesource.jaxrs.provider.multipart.feature.feature.group" version="2.2.0.201905211243"/>
<unit id="ch.rgw.utility" version="3.8.0.20190425-1427"/> <unit id="ch.rgw.utility" version="3.8.0.20190425-1427"/>
<unit id="ch.elexis.core" version="3.8.0.20190704-0852"/> <unit id="ch.elexis.core" version="3.8.0.20190712-0701"/>
<unit id="ch.elexis.core.l10n" version="3.8.0.20190703-1208"/> <unit id="ch.elexis.core.l10n" version="3.8.0.20190703-1208"/>
<unit id="ch.elexis.core.importer.div" version="3.2.0.20190703-1208"/> <unit id="ch.elexis.core.importer.div" version="3.2.0.20190703-1208"/>
<unit id="ch.elexis.core.hl7.v2x" version="3.2.0.20190416-1216"/> <unit id="ch.elexis.core.hl7.v2x" version="3.2.0.20190416-1216"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment