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;
import java.util.Arrays;
import java.util.Iterator;
import org.eclipse.equinox.p2.operations.Update;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
import org.osgi.service.component.annotations.Activate;
......@@ -14,52 +16,58 @@ import info.elexis.server.core.p2.internal.ProvisioningHelper;
@Component(service = CommandProvider.class, immediate = true)
public class ConsoleCommandProvider extends AbstractConsoleCommandProvider {
@Activate
public void activate(){
public void activate() {
register(this.getClass());
}
@CmdAdvisor(description = "feature de-/installation and update repository management")
public void _p2(CommandInterpreter ci){
public void _p2(CommandInterpreter 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")
public String __p2_executeUpdate(){
public String __p2_update_execute() {
return ProvisioningHelper.updateAllFeatures().getMessage();
}
@CmdAdvisor(description = "list the installed features")
public String __p2_features_listLocal(){
public String __p2_features_listLocal() {
return ProvisioningHelper
.getAllInstalledFeatures().stream().map(i -> i.getId() + " (" + i.getVersion() + ") "
+ i.getProperty("git-repo-url") + " " + i.getProperty("git-rev"))
.reduce((u, t) -> u + "\n" + t).get();
.getAllInstalledFeatures().stream().map(i -> i.getId() + " (" + i.getVersion() + ") "
+ i.getProperty("git-repo-url") + " " + i.getProperty("git-rev"))
.reduce((u, t) -> u + "\n" + t).get();
}
@CmdAdvisor(description = "install a feature")
public String __p2_features_install(Iterator<String> args){
public String __p2_features_install(Iterator<String> args) {
if (args.hasNext()) {
return ProvisioningHelper.unInstallFeature(args.next(), true);
}
return missingArgument("featureName");
}
@CmdAdvisor(description = "uninstall a feature")
public String __p2_features_uninstall(Iterator<String> args){
public String __p2_features_uninstall(Iterator<String> args) {
if (args.hasNext()) {
return ProvisioningHelper.unInstallFeature(args.next(), false);
}
return missingArgument("featureName");
}
@CmdAdvisor(description = "list configured repositories")
public String __p2_repo_list(){
public String __p2_repo_list() {
return HTTPServiceHelper.getRepoInfo(null).toString();
}
public String __p2_repo_add(Iterator<String> args){
public String __p2_repo_add(Iterator<String> args) {
if (args.hasNext()) {
final String url = args.next();
String user = null;
......@@ -70,18 +78,17 @@ public class ConsoleCommandProvider extends AbstractConsoleCommandProvider {
if (args.hasNext()) {
password = args.next();
}
return HTTPServiceHelper.doRepositoryAdd(url, user, password).getStatusInfo()
.toString();
return HTTPServiceHelper.doRepositoryAdd(url, user, password).getStatusInfo().toString();
}
return missingArgument("url [user] [password]");
}
public String __p2_repo_remove(Iterator<String> args){
public String __p2_repo_remove(Iterator<String> args) {
if (args.hasNext()) {
final String url = args.next();
return HTTPServiceHelper.doRepositoryRemove(url).getStatusInfo().toString();
}
return missingArgument("url");
}
}
......@@ -86,7 +86,7 @@ public class ProvisioningHelper {
IMetadataRepositoryManager metadataRepoMgr = Provisioner.getInstance().getMetadataRepositoryManager();
if (metadataRepoMgr.contains(location)) {
result &= metadataRepoMgr.removeRepository(location);
log.debug("Removed metadata repository {}", location);
log.debug("Removed metadata repository {}", location);
}
return result;
......@@ -107,7 +107,20 @@ public class ProvisioningHelper {
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();
ProvisioningHelper.refreshRepositories();
......@@ -121,30 +134,26 @@ public class ProvisioningHelper {
UpdateOperation operation = new UpdateOperation(session, units.toUnmodifiableSet());
IStatus status = operation.resolveModal(new TimeoutProgressMonitor(15000));
log.info("[UPDATE] Check for updates {} | severity {} | code {}", status.getMessage(), status.getSeverity(),
status.getCode());
if (status.getSeverity() == Status.ERROR) {
StatusUtil.logStatus("determine updates", log, status);
}
if ((!status.isOK() && status.getCode() == 10000 && status.getSeverity() == 1)) {
// no updates available
return status;
return null;
} else {
Update[] possibleUpdates = operation.getPossibleUpdates();
for (Update update : possibleUpdates) {
log.debug("[UPDATE] Found update {}", update.replacement);
}
return operation;
}
}
if (status.getSeverity() != IStatus.ERROR) {
IStatus stat = ProvisioningHelper.performOperation(operation);
log.info("[UPDATE] Finished {} | severity {} | code {}", stat.getMessage(),
stat.getSeverity(), stat.getCode());
// TODO perform restart
} else {
log.warn("[UPDATE] FAILED {} | severity {} | code {}", status.getMessage(),
status.getSeverity(), status.getCode());
StatusUtil.logStatus(log, status);
public static IStatus updateAllFeatures() {
UpdateOperation updateOperation = determinePossibleUpdates();
if (updateOperation == null) {
return Status.OK_STATUS;
}
return status;
IStatus stat = ProvisioningHelper.performOperation(updateOperation);
StatusUtil.logStatus("update finished", log, stat);
return stat;
}
public static Collection<IInstallableUnit> getAllInstalledFeatures() {
......@@ -204,8 +213,8 @@ public class ProvisioningHelper {
/**
*
* @param featureName
* @param install
* <code>true</code> to install, <code>false</code> to uninstall
* @param install <code>true</code> to install, <code>false</code> to
* uninstall
* @return
*/
public static String unInstallFeature(String featureName, boolean install) {
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?>
<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl -->
<target name="Elexis-Server" sequenceNumber="1562681306">
<target name="Elexis-Server" sequenceNumber="1562917366">
<locations>
<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"/>
......@@ -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.multipart.feature.feature.group" version="2.2.0.201905211243"/>
<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.importer.div" version="3.2.0.20190703-1208"/>
<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