mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-17 10:41:06 +01:00
Merge pull request #1079 from scm-manager/feature/real_jvm_restart
Real jvm restart
This commit is contained in:
@@ -21,9 +21,10 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -45,6 +46,7 @@ import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* RESTful Web Service Resource to manage the configuration.
|
||||
@@ -61,6 +63,8 @@ public class ConfigResource {
|
||||
private final ScmConfiguration configuration;
|
||||
private final NamespaceStrategyValidator namespaceStrategyValidator;
|
||||
|
||||
private Consumer<ScmConfiguration> store = (config) -> ScmConfigurationUtil.getInstance().store(config);
|
||||
|
||||
@Inject
|
||||
public ConfigResource(ConfigDtoToScmConfigurationMapper dtoToConfigMapper,
|
||||
ScmConfigurationToConfigDtoMapper configToDtoMapper,
|
||||
@@ -71,6 +75,11 @@ public class ConfigResource {
|
||||
this.namespaceStrategyValidator = namespaceStrategyValidator;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setStore(Consumer<ScmConfiguration> store) {
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the global scm config.
|
||||
*/
|
||||
@@ -137,7 +146,7 @@ public class ConfigResource {
|
||||
ScmConfiguration config = dtoToConfigMapper.map(configDto);
|
||||
synchronized (ScmConfiguration.class) {
|
||||
configuration.load(config);
|
||||
ScmConfigurationUtil.getInstance().store(configuration);
|
||||
store.accept(configuration);
|
||||
}
|
||||
|
||||
return Response.noContent().build();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Embedded;
|
||||
@@ -31,6 +31,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import sonia.scm.lifecycle.Restarter;
|
||||
import sonia.scm.plugin.AvailablePlugin;
|
||||
import sonia.scm.plugin.InstalledPlugin;
|
||||
import sonia.scm.plugin.PluginManager;
|
||||
@@ -56,12 +57,14 @@ public class PendingPluginResource {
|
||||
private final PluginManager pluginManager;
|
||||
private final ResourceLinks resourceLinks;
|
||||
private final PluginDtoMapper mapper;
|
||||
private final Restarter restarter;
|
||||
|
||||
@Inject
|
||||
public PendingPluginResource(PluginManager pluginManager, ResourceLinks resourceLinks, PluginDtoMapper mapper) {
|
||||
public PendingPluginResource(PluginManager pluginManager, ResourceLinks resourceLinks, PluginDtoMapper mapper, Restarter restarter) {
|
||||
this.pluginManager = pluginManager;
|
||||
this.resourceLinks = resourceLinks;
|
||||
this.mapper = mapper;
|
||||
this.restarter = restarter;
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -118,7 +121,9 @@ public class PendingPluginResource {
|
||||
PluginPermissions.manage().isPermitted() &&
|
||||
(!installDtos.isEmpty() || !updateDtos.isEmpty() || !uninstallDtos.isEmpty())
|
||||
) {
|
||||
linksBuilder.single(link("execute", resourceLinks.pendingPluginCollection().executePending()));
|
||||
if (restarter.isSupported()) {
|
||||
linksBuilder.single(link("execute", resourceLinks.pendingPluginCollection().executePending()));
|
||||
}
|
||||
linksBuilder.single(link("cancel", resourceLinks.pendingPluginCollection().cancelPending()));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,12 +21,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Links;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.MappingTarget;
|
||||
import sonia.scm.lifecycle.Restarter;
|
||||
import sonia.scm.plugin.AvailablePlugin;
|
||||
import sonia.scm.plugin.InstalledPlugin;
|
||||
import sonia.scm.plugin.Plugin;
|
||||
@@ -47,6 +48,9 @@ public abstract class PluginDtoMapper {
|
||||
@Inject
|
||||
private ResourceLinks resourceLinks;
|
||||
|
||||
@Inject
|
||||
private Restarter restarter;
|
||||
|
||||
public abstract void map(PluginInformation plugin, @MappingTarget PluginDto dto);
|
||||
|
||||
public PluginDto mapInstalled(InstalledPlugin plugin, List<AvailablePlugin> availablePlugins) {
|
||||
@@ -78,12 +82,20 @@ public abstract class PluginDtoMapper {
|
||||
.self(information.getName()));
|
||||
|
||||
if (!plugin.isPending() && PluginPermissions.manage().isPermitted()) {
|
||||
links.single(link("install", resourceLinks.availablePlugin().install(information.getName())));
|
||||
String href = resourceLinks.availablePlugin().install(information.getName());
|
||||
appendLink(links, "install", href);
|
||||
}
|
||||
|
||||
return new PluginDto(links.build());
|
||||
}
|
||||
|
||||
private void appendLink(Links.Builder links, String name, String href) {
|
||||
links.single(link(name, href));
|
||||
if (restarter.isSupported()) {
|
||||
links.single(link(name + "WithRestart", href + "?restart=true"));
|
||||
}
|
||||
}
|
||||
|
||||
private PluginDto createDtoForInstalled(InstalledPlugin plugin, List<AvailablePlugin> availablePlugins) {
|
||||
PluginInformation information = plugin.getDescriptor().getInformation();
|
||||
Optional<AvailablePlugin> availablePlugin = checkForUpdates(plugin, availablePlugins);
|
||||
@@ -96,13 +108,16 @@ public abstract class PluginDtoMapper {
|
||||
&& !availablePlugin.get().isPending()
|
||||
&& PluginPermissions.manage().isPermitted()
|
||||
) {
|
||||
links.single(link("update", resourceLinks.availablePlugin().install(information.getName())));
|
||||
String href = resourceLinks.availablePlugin().install(information.getName());
|
||||
appendLink(links, "update", href);
|
||||
}
|
||||
|
||||
if (plugin.isUninstallable()
|
||||
&& (!availablePlugin.isPresent() || !availablePlugin.get().isPending())
|
||||
&& PluginPermissions.manage().isPermitted()
|
||||
) {
|
||||
links.single(link("uninstall", resourceLinks.installedPlugin().uninstall(information.getName())));
|
||||
String href = resourceLinks.installedPlugin().uninstall(information.getName());
|
||||
appendLink(links, "uninstall", href);
|
||||
}
|
||||
|
||||
PluginDto dto = new PluginDto(links.build());
|
||||
|
||||
Reference in New Issue
Block a user