diff --git a/controller/src/main/java/org/jboss/as/controller/AbstractControllerService.java b/controller/src/main/java/org/jboss/as/controller/AbstractControllerService.java index de5385e5359..faec842ea5f 100644 --- a/controller/src/main/java/org/jboss/as/controller/AbstractControllerService.java +++ b/controller/src/main/java/org/jboss/as/controller/AbstractControllerService.java @@ -177,6 +177,7 @@ private static int getBootStackSize() { private final CapabilityRegistry capabilityRegistry; private final ConfigurationExtension configExtension; private volatile ModelControllerClientFactory clientFactory; + protected final Supplier pathManagerSupplier; /** * Construct a new instance. @@ -200,7 +201,7 @@ protected AbstractControllerService(final ProcessType processType, final Running final ManagedAuditLogger auditLogger, final DelegatingConfigurableAuthorizer authorizer, final ManagementSecurityIdentitySupplier securityIdentitySupplier, final CapabilityRegistry capabilityRegistry) { this(null, null, processType, Stability.DEFAULT, runningModeControl, configurationPersister, processState, rootResourceDefinition, null, - prepareStep, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, null); + prepareStep, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, null, null); } /** @@ -229,7 +230,7 @@ protected AbstractControllerService(final Supplier executorServ final ManagementSecurityIdentitySupplier securityIdentitySupplier, final CapabilityRegistry capabilityRegistry, final ConfigurationExtension configExtension) { this(executorService, instabilityListener, processType, Stability.DEFAULT, runningModeControl, configurationPersister, processState, rootResourceDefinition, null, - prepareStep, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, configExtension); + prepareStep, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, configExtension, null); } /** @@ -247,6 +248,7 @@ protected AbstractControllerService(final Supplier executorServ * @param authorizer handles authorization * @param capabilityRegistry the capability registry */ + @Deprecated protected AbstractControllerService(final Supplier executorService, final Supplier instabilityListener, final ProcessType processType, Stability stability, final RunningModeControl runningModeControl, @@ -257,7 +259,36 @@ protected AbstractControllerService(final Supplier executorServ final ManagementSecurityIdentitySupplier securityIdentitySupplier, final CapabilityRegistry capabilityRegistry, final ConfigurationExtension configExtension) { this(executorService, instabilityListener, processType, stability, runningModeControl, configurationPersister, processState, rootResourceDefinition, null, - prepareStep, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, configExtension); + prepareStep, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, configExtension, null); + } + + /** + * Construct a new instance. + * + * @param processType the type of process being controlled + * @param stability the stability level of the controlled process + * @param runningModeControl the controller of the process' running mode + * @param configurationPersister the configuration persister + * @param processState the controlled process state + * @param rootResourceDefinition the root resource definition + * @param prepareStep the prepare step to prepend to operation execution + * @param expressionResolver the expression resolver + * @param auditLogger the audit logger + * @param authorizer handles authorization + * @param capabilityRegistry the capability registry + */ + protected AbstractControllerService(final Supplier executorService, + final Supplier instabilityListener, + final ProcessType processType, Stability stability, final RunningModeControl runningModeControl, + final ConfigurationPersister configurationPersister, + final ControlledProcessState processState, final ResourceDefinition rootResourceDefinition, + final OperationStepHandler prepareStep, final ExpressionResolver expressionResolver, + final ManagedAuditLogger auditLogger, final DelegatingConfigurableAuthorizer authorizer, + final ManagementSecurityIdentitySupplier securityIdentitySupplier, + final CapabilityRegistry capabilityRegistry, final ConfigurationExtension configExtension, + final Supplier pathManagerSupplier) { + this(executorService, instabilityListener, processType, stability, runningModeControl, configurationPersister, processState, rootResourceDefinition, null, + prepareStep, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, configExtension, pathManagerSupplier); } private AbstractControllerService(final Supplier executorService, @@ -267,7 +298,8 @@ private AbstractControllerService(final Supplier executorServic final ResourceDefinition rootResourceDefinition, final DescriptionProvider rootDescriptionProvider, final OperationStepHandler prepareStep, final ExpressionResolver expressionResolver, final ManagedAuditLogger auditLogger, final DelegatingConfigurableAuthorizer authorizer, final ManagementSecurityIdentitySupplier securityIdentitySupplier, - final CapabilityRegistry capabilityRegistry, final ConfigurationExtension configExtension) { + final CapabilityRegistry capabilityRegistry, final ConfigurationExtension configExtension, + final Supplier pathManagerSupplier) { assert rootDescriptionProvider == null : "description provider cannot be used anymore"; assert rootResourceDefinition != null : "Null root resource definition"; assert expressionResolver != null : "Null expressionResolver"; @@ -276,6 +308,7 @@ private AbstractControllerService(final Supplier executorServic assert securityIdentitySupplier != null : "Null securityIdentitySupplier"; assert capabilityRegistry != null : "Null capabilityRegistry"; assert stability != null : "Null stability"; + assert pathManagerSupplier != null; this.executorService = executorService; this.instabilityListener = instabilityListener; this.processType = processType; @@ -292,6 +325,7 @@ private AbstractControllerService(final Supplier executorServic this.bootErrorCollector = new BootErrorCollector(); this.capabilityRegistry = capabilityRegistry.createShadowCopy(); //create shadow copy of proper registry so changes can only be visible by .publish() this.configExtension = configExtension; + this.pathManagerSupplier = pathManagerSupplier; } @Override @@ -698,10 +732,10 @@ public void execute(OperationContext context, ModelNode operation) throws Operat assert !processType.isHostController() || hostName != null; for (ModelControllerServiceInitialization init : sl) { if (processType.isHostController()) { - init.initializeHost(context.getServiceTarget(), managementModel, hostName, processType); + init.initializeHost(context.getServiceTarget(), managementModel, hostName, processType, pathManagerSupplier.get()); init.initializeDomain(context.getServiceTarget(), managementModel); } else { - init.initializeStandalone(context.getServiceTarget(), managementModel, processType); + init.initializeStandalone(context.getServiceTarget(), managementModel, processType, pathManagerSupplier.get()); } } diff --git a/controller/src/main/java/org/jboss/as/controller/ModelControllerServiceInitialization.java b/controller/src/main/java/org/jboss/as/controller/ModelControllerServiceInitialization.java index 4d45c62f3c5..3fdc9e19a68 100644 --- a/controller/src/main/java/org/jboss/as/controller/ModelControllerServiceInitialization.java +++ b/controller/src/main/java/org/jboss/as/controller/ModelControllerServiceInitialization.java @@ -5,6 +5,7 @@ package org.jboss.as.controller; +import org.jboss.as.controller.services.path.PathManager; import org.jboss.msc.service.ServiceTarget; /** @@ -20,8 +21,9 @@ public interface ModelControllerServiceInitialization { * @param target the service target * @param managementModel the management model * @param processType The ProcessType used to identify what type of server we are running in. + * @param pathManager The PathManager for the running server */ - void initializeStandalone(ServiceTarget target, ManagementModel managementModel, ProcessType processType); + void initializeStandalone(ServiceTarget target, ManagementModel managementModel, ProcessType processType, PathManager pathManager); /** * Initialize the domain controller. @@ -37,7 +39,8 @@ public interface ModelControllerServiceInitialization { * @param managementModel the management model * @param hostName the name of the host * @param processType The ProcessType that to identify what type of server we are running in. + * @param pathManager The PathManager for the running server */ - void initializeHost(ServiceTarget target, ManagementModel managementModel, String hostName, ProcessType processType); + void initializeHost(ServiceTarget target, ManagementModel managementModel, String hostName, ProcessType processType, PathManager pathManager); } diff --git a/controller/src/test/java/org/jboss/as/controller/TestModelControllerService.java b/controller/src/test/java/org/jboss/as/controller/TestModelControllerService.java index 7d245338b4f..6dd097257e5 100644 --- a/controller/src/test/java/org/jboss/as/controller/TestModelControllerService.java +++ b/controller/src/test/java/org/jboss/as/controller/TestModelControllerService.java @@ -20,6 +20,8 @@ import org.jboss.as.controller.persistence.ConfigurationExtension; import org.jboss.as.controller.persistence.ConfigurationPersister; import org.jboss.as.controller.persistence.NullConfigurationPersister; +import org.jboss.as.controller.services.path.PathManager; +import org.jboss.as.controller.services.path.PathManagerService; import org.jboss.as.version.Stability; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; @@ -31,6 +33,8 @@ */ public abstract class TestModelControllerService extends AbstractControllerService { + protected static final Supplier DEFAULT_PATH_MANAGER = () -> new PathManagerService() { + }; private final ControlledProcessState processState; final AtomicBoolean state = new AtomicBoolean(true); private final CountDownLatch latch = new CountDownLatch(2); @@ -74,7 +78,7 @@ protected TestModelControllerService(final ProcessType processType, final Runnin final ConfigurationPersister configurationPersister, final ControlledProcessState processState, final ResourceDefinition rootResourceDefinition, final CapabilityRegistry capabilityRegistry, final ConfigurationExtension configExtension) { super(executorService, null, processType, Stability.DEFAULT, runningModeControl, configurationPersister, processState, rootResourceDefinition, null, ExpressionResolver.TEST_RESOLVER, - AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry, configExtension); + AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry, configExtension, DEFAULT_PATH_MANAGER); this.processState = processState; this.capabilityRegistry = capabilityRegistry; } diff --git a/domain-http/interface/src/test/java/org/jboss/as/domain/http/server/TestModelControllerService.java b/domain-http/interface/src/test/java/org/jboss/as/domain/http/server/TestModelControllerService.java index b7a7f31a4ae..4752559e521 100644 --- a/domain-http/interface/src/test/java/org/jboss/as/domain/http/server/TestModelControllerService.java +++ b/domain-http/interface/src/test/java/org/jboss/as/domain/http/server/TestModelControllerService.java @@ -25,6 +25,8 @@ import org.jboss.as.controller.audit.AuditLogger; import org.jboss.as.controller.descriptions.NonResolvingResourceDescriptionResolver; import org.jboss.as.controller.persistence.ConfigurationPersister; +import org.jboss.as.controller.services.path.PathManager; +import org.jboss.as.controller.services.path.PathManagerService; import org.jboss.as.version.Stability; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; @@ -35,6 +37,8 @@ * @author Yeray Borges */ public abstract class TestModelControllerService extends AbstractControllerService { + protected static final Supplier DEFAULT_PATH_MANAGER = () -> new PathManagerService() { + }; private final CountDownLatch latch = new CountDownLatch(2); private final CapabilityRegistry capabilityRegistry; @@ -56,7 +60,7 @@ protected TestModelControllerService(final ProcessType processType, Stability st final ConfigurationPersister configurationPersister, final ControlledProcessState processState, final ResourceDefinition rootResourceDefinition, final CapabilityRegistry capabilityRegistry) { super(executorService, null, processType, stability, runningModeControl, configurationPersister, processState, rootResourceDefinition, null, ExpressionResolver.TEST_RESOLVER, - AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry, null); + AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry, null, DEFAULT_PATH_MANAGER); this.capabilityRegistry = capabilityRegistry; } diff --git a/host-controller/src/main/java/org/jboss/as/host/controller/DomainModelControllerService.java b/host-controller/src/main/java/org/jboss/as/host/controller/DomainModelControllerService.java index 755e4c3c172..6bb2fbfe151 100644 --- a/host-controller/src/main/java/org/jboss/as/host/controller/DomainModelControllerService.java +++ b/host-controller/src/main/java/org/jboss/as/host/controller/DomainModelControllerService.java @@ -118,6 +118,7 @@ import org.jboss.as.controller.registry.ResourceProvider; import org.jboss.as.controller.remote.AbstractModelControllerOperationHandlerFactoryService; import org.jboss.as.controller.remote.ModelControllerOperationHandlerFactory; +import org.jboss.as.controller.services.path.PathManager; import org.jboss.as.controller.services.path.PathManagerService; import org.jboss.as.controller.transform.Transformers; import org.jboss.as.domain.controller.DomainController; @@ -287,13 +288,14 @@ static void addService(final ServiceTarget serviceTarget, final ServiceBuilder sb = serviceTarget.addService(SERVICE_NAME); final Supplier esSupplier = sb.requires(HC_EXECUTOR_SERVICE_NAME); + final Supplier pathManagerSupplier = sb.requires(PATH_MANAGER_CAPABILITY.getCapabilityServiceName()); final DomainModelControllerService service = new DomainModelControllerService(esSupplier, environment, runningModeControl, processState, hostControllerInfo, contentRepository, hostProxies, serverProxies, prepareStepHandler, ignoredRegistry, bootstrapListener, pathManager, expressionResolver, new DomainDelegatingResourceDefinition(), - hostExtensionRegistry, extensionRegistry, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, domainHostExcludeRegistry); + hostExtensionRegistry, extensionRegistry, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, domainHostExcludeRegistry, + pathManagerSupplier); sb.setInstance(service); sb.addDependency(ProcessControllerConnectionService.SERVICE_NAME, ProcessControllerConnectionService.class, service.injectedProcessControllerConnection); - sb.requires(PATH_MANAGER_CAPABILITY.getCapabilityServiceName()); // ensure this is up service.consoleAvailabilitySupplier = sb.requires(CONSOLE_AVAILABILITY_CAPABILITY.getCapabilityServiceName()); sb.install(); @@ -321,9 +323,10 @@ private DomainModelControllerService(final Supplier executorSer final DelegatingConfigurableAuthorizer authorizer, final ManagementSecurityIdentitySupplier securityIdentitySupplier, final CapabilityRegistry capabilityRegistry, - final DomainHostExcludeRegistry domainHostExcludeRegistry) { + final DomainHostExcludeRegistry domainHostExcludeRegistry, + final Supplier pathManagerSupplier) { super(executorService, null, environment.getProcessType(), environment.getStability(), runningModeControl, null, processState, - rootResourceDefinition, prepareStepHandler, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, null); + rootResourceDefinition, prepareStepHandler, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, null, pathManagerSupplier); this.environment = environment; this.runningModeControl = runningModeControl; this.processState = processState; diff --git a/host-controller/src/test/java/org/jboss/as/host/controller/util/TestModelControllerService.java b/host-controller/src/test/java/org/jboss/as/host/controller/util/TestModelControllerService.java index 4736eec2316..a29525538e3 100644 --- a/host-controller/src/test/java/org/jboss/as/host/controller/util/TestModelControllerService.java +++ b/host-controller/src/test/java/org/jboss/as/host/controller/util/TestModelControllerService.java @@ -31,8 +31,10 @@ import org.jboss.as.controller.persistence.ConfigurationPersister; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; +import org.jboss.as.controller.services.path.PathManagerService; import org.jboss.as.domain.controller.operations.ApplyExtensionsHandler; import org.jboss.as.host.controller.mgmt.HostControllerRegistrationHandler; +import org.jboss.as.version.Stability; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; @@ -55,8 +57,10 @@ protected TestModelControllerService(final ProcessType processType, final Config final ResourceDefinition rootResourceDefinition, final ManagedAuditLogger auditLogger, final AbstractControllerTestBase.DelegatingResourceDefinitionInitializer initializer, final CapabilityRegistry capabilityRegistry) { - super(processType, new RunningModeControl(RunningMode.NORMAL), configurationPersister, processState, rootResourceDefinition, - null, ExpressionResolver.TEST_RESOLVER, auditLogger, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry); + super(null, null, processType, Stability.DEFAULT, new RunningModeControl(RunningMode.NORMAL), + configurationPersister, processState, rootResourceDefinition, null, ExpressionResolver.TEST_RESOLVER, + auditLogger, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), + capabilityRegistry, null, ()->new PathManagerService() {}); this.processState = processState; internalExecutor = new InternalExecutor(); this.initializer = initializer; diff --git a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrInitialization.java b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrInitialization.java index 8cd9d251652..9b4aa0f3f83 100644 --- a/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrInitialization.java +++ b/installation-manager/src/main/java/org/wildfly/core/instmgr/InstMgrInitialization.java @@ -7,6 +7,7 @@ import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST; +import java.nio.file.Path; import java.util.Optional; import java.util.concurrent.Executor; import java.util.function.Consumer; @@ -22,11 +23,13 @@ import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.PlaceholderResource; import org.jboss.as.controller.registry.Resource; +import org.jboss.as.controller.services.path.PathEntry; import org.jboss.as.controller.services.path.PathManager; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; +import org.wildfly.core.instmgr.logging.InstMgrLogger; import org.wildfly.installationmanager.InstallationManagerFinder; import org.wildfly.installationmanager.spi.InstallationManagerFactory; @@ -39,17 +42,23 @@ public final class InstMgrInitialization implements ModelControllerServiceInitialization { @Override - public void initializeStandalone(ServiceTarget target, ManagementModel managementModel, ProcessType processType) { + public void initializeStandalone(ServiceTarget target, ManagementModel managementModel, ProcessType processType, PathManager pathManager) { if (processType == ProcessType.EMBEDDED_SERVER) { return; } + final PathEntry pathEntry = pathManager.getPathEntry("jboss.home.dir"); + Optional im = InstallationManagerFinder.reloadAndFind(); if (im.isPresent()) { final InstallationManagerFactory imf = im.get(); - final InstMgrService imService = createImService(target, imf); - managementModel.getRootResource().registerChild(InstMgrResourceDefinition.getPath(InstMgrConstants.TOOL_NAME), PlaceholderResource.INSTANCE); - managementModel.getRootResourceRegistration().registerSubModel(new InstMgrResourceDefinition(imf, imService)); + if (imf.isManagedInstallation(Path.of(pathEntry.resolvePath()))) { + final InstMgrService imService = createImService(target, imf); + managementModel.getRootResource().registerChild(InstMgrResourceDefinition.getPath(InstMgrConstants.TOOL_NAME), PlaceholderResource.INSTANCE); + managementModel.getRootResourceRegistration().registerSubModel(new InstMgrResourceDefinition(imf, imService)); + } else { + InstMgrLogger.ROOT_LOGGER.debug("The server installation is missing installation manager metadata. Disabling installation-manager integration."); + } } } @@ -59,7 +68,7 @@ public void initializeDomain(ServiceTarget target, ManagementModel managementMod } @Override - public void initializeHost(ServiceTarget target, ManagementModel managementModel, String hostName, ProcessType processType) { + public void initializeHost(ServiceTarget target, ManagementModel managementModel, String hostName, ProcessType processType, PathManager pathManager) { if (processType == ProcessType.EMBEDDED_HOST_CONTROLLER) { return; } @@ -76,10 +85,16 @@ public void initializeHost(ServiceTarget target, ManagementModel managementModel // real hostname yet. return; } + + final PathEntry pathEntry = pathManager.getPathEntry("jboss.home.dir"); final InstallationManagerFactory imf = im.get(); - final InstMgrService imService = createImService(target, imf); - hostResource.registerChild(InstMgrResourceDefinition.getPath(InstMgrConstants.TOOL_NAME), PlaceholderResource.INSTANCE); - hostRegistration.registerSubModel(new InstMgrResourceDefinition(imf, imService)); + if (imf.isManagedInstallation(Path.of(pathEntry.resolvePath()))) { + final InstMgrService imService = createImService(target, imf); + hostResource.registerChild(InstMgrResourceDefinition.getPath(InstMgrConstants.TOOL_NAME), PlaceholderResource.INSTANCE); + hostRegistration.registerSubModel(new InstMgrResourceDefinition(imf, imService)); + } else { + InstMgrLogger.ROOT_LOGGER.debug("The server installation is missing installation manager metadata. Disabling installation-manager integration."); + } } } diff --git a/installation-manager/src/test/java/org/wildfly/core/instmgr/AbstractControllerTestBase.java b/installation-manager/src/test/java/org/wildfly/core/instmgr/AbstractControllerTestBase.java index 4a1141228a7..d77679a1f25 100644 --- a/installation-manager/src/test/java/org/wildfly/core/instmgr/AbstractControllerTestBase.java +++ b/installation-manager/src/test/java/org/wildfly/core/instmgr/AbstractControllerTestBase.java @@ -46,6 +46,7 @@ import org.jboss.as.controller.persistence.ModelMarshallingContext; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; +import org.jboss.as.controller.services.path.PathManager; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.msc.Service; @@ -183,10 +184,10 @@ public ModelNode executeCheckForFailure(Operation operation) throws IOException } } - public void setupController() throws InterruptedException, IOException { + public void setupController(Supplier pathManagerSupplier) throws InterruptedException, IOException { container = ServiceContainer.Factory.create("test"); ServiceTarget target = container.subTarget(); - ModelControllerService svc = createModelControllerService(processType, resourceDefinition); + ModelControllerService svc = createModelControllerService(processType, resourceDefinition, pathManagerSupplier); target.addService(ServiceName.of("ModelController")).setInstance(svc).install(); svc.awaitStartup(30, TimeUnit.SECONDS); controller = svc.getValue(); @@ -208,8 +209,9 @@ public void shutdownServiceContainer() throws IOException { } } - protected ModelControllerService createModelControllerService(ProcessType processType, ResourceDefinition resourceDefinition) { - return new ModelControllerService(processType, resourceDefinition); + protected ModelControllerService createModelControllerService(ProcessType processType, ResourceDefinition resourceDefinition, + Supplier pathManagerSupplier) { + return new ModelControllerService(processType, resourceDefinition, pathManagerSupplier); } protected void addBootOperations(List bootOperations) { @@ -232,8 +234,8 @@ public ModelControllerService(final ProcessType processType, RunningModeControl ); } - public ModelControllerService(final ProcessType processType, ResourceDefinition resourceDefinition) { - super(processType, new EmptyConfigurationPersister(), new ControlledProcessState(true), resourceDefinition); + public ModelControllerService(final ProcessType processType, ResourceDefinition resourceDefinition, Supplier pathManagerSupplier) { + super(processType, new EmptyConfigurationPersister(), new ControlledProcessState(true), resourceDefinition, pathManagerSupplier); } @Override diff --git a/installation-manager/src/test/java/org/wildfly/core/instmgr/InstMgrResourceTestCase.java b/installation-manager/src/test/java/org/wildfly/core/instmgr/InstMgrResourceTestCase.java index 7e65046d51d..cf64511a834 100644 --- a/installation-manager/src/test/java/org/wildfly/core/instmgr/InstMgrResourceTestCase.java +++ b/installation-manager/src/test/java/org/wildfly/core/instmgr/InstMgrResourceTestCase.java @@ -97,7 +97,7 @@ public void setupController() throws InterruptedException, IOException { prop.setProperty(InstMgrCandidateStatus.INST_MGR_STATUS_KEY, InstMgrCandidateStatus.Status.CLEAN.name()); prop.store(out, null); } - super.setupController(); + super.setupController(()->pathManagerService); } @After diff --git a/installation-manager/src/test/java/org/wildfly/core/instmgr/TestModelControllerService.java b/installation-manager/src/test/java/org/wildfly/core/instmgr/TestModelControllerService.java index 6e9dacf2697..0c39bca4688 100644 --- a/installation-manager/src/test/java/org/wildfly/core/instmgr/TestModelControllerService.java +++ b/installation-manager/src/test/java/org/wildfly/core/instmgr/TestModelControllerService.java @@ -17,9 +17,7 @@ import org.jboss.as.controller.ControlledProcessState.State; import org.jboss.as.controller.ExpressionResolver; import org.jboss.as.controller.OperationDefinition; -import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ProcessType; -import org.jboss.as.controller.ResourceBuilder; import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.RunningMode; import org.jboss.as.controller.RunningModeControl; @@ -30,7 +28,9 @@ import org.jboss.as.controller.descriptions.NonResolvingResourceDescriptionResolver; import org.jboss.as.controller.persistence.ConfigurationExtension; import org.jboss.as.controller.persistence.ConfigurationPersister; -import org.jboss.as.controller.persistence.NullConfigurationPersister; +import org.jboss.as.controller.services.path.PathManager; +import org.jboss.as.controller.services.path.PathManagerService; +import org.jboss.as.version.Stability; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; @@ -46,45 +46,33 @@ public abstract class TestModelControllerService extends AbstractControllerServi private final CountDownLatch latch = new CountDownLatch(2); private final CapabilityRegistry capabilityRegistry; - protected TestModelControllerService() { - this(ProcessType.EMBEDDED_SERVER, new NullConfigurationPersister(), new ControlledProcessState(true)); - } - - protected TestModelControllerService(ProcessType processType) { - this(processType, new NullConfigurationPersister(), new ControlledProcessState(true)); - } - - protected TestModelControllerService(ProcessType processType, final ConfigurationPersister configurationPersister, final ControlledProcessState processState) { - this(processType, configurationPersister, processState, - ResourceBuilder.Factory.create(PathElement.pathElement("root"), NonResolvingResourceDescriptionResolver.INSTANCE).build()); - } - - protected TestModelControllerService(final ConfigurationPersister configurationPersister, final ControlledProcessState processState) { - this(ProcessType.EMBEDDED_SERVER, configurationPersister, processState, - ResourceBuilder.Factory.create(PathElement.pathElement("root"), NonResolvingResourceDescriptionResolver.INSTANCE).build()); - } - protected TestModelControllerService(final ProcessType processType, final ConfigurationPersister configurationPersister, final ControlledProcessState processState, - final ResourceDefinition rootResourceDefinition) { - this(processType, configurationPersister, processState, rootResourceDefinition, new CapabilityRegistry(processType.isServer())); + final ResourceDefinition rootResourceDefinition, final Supplier pathManagerSupplier) { + this(processType, configurationPersister, processState, rootResourceDefinition, new CapabilityRegistry(processType.isServer()), + pathManagerSupplier); } protected TestModelControllerService(final ProcessType processType, final RunningModeControl runningModeControl, Supplier executorService, final ConfigurationPersister configurationPersister, final ControlledProcessState processState, final ResourceDefinition rootResourceDefinition) { - this(processType, runningModeControl,executorService, configurationPersister, processState, rootResourceDefinition, new CapabilityRegistry(processType.isServer()), null); + this(processType, runningModeControl,executorService, configurationPersister, processState, rootResourceDefinition, new CapabilityRegistry(processType.isServer()), null, + () -> new PathManagerService() {}); } protected TestModelControllerService(final ProcessType processType, final ConfigurationPersister configurationPersister, final ControlledProcessState processState, - final ResourceDefinition rootResourceDefinition, final CapabilityRegistry capabilityRegistry) { - this(processType, new RunningModeControl(RunningMode.NORMAL), null, configurationPersister, processState, rootResourceDefinition, capabilityRegistry, null); + final ResourceDefinition rootResourceDefinition, final CapabilityRegistry capabilityRegistry, + final Supplier pathManagerSupplier) { + this(processType, new RunningModeControl(RunningMode.NORMAL), null, configurationPersister, processState, rootResourceDefinition, capabilityRegistry, null, + pathManagerSupplier); } protected TestModelControllerService(final ProcessType processType, final RunningModeControl runningModeControl, Supplier executorService, final ConfigurationPersister configurationPersister, final ControlledProcessState processState, - final ResourceDefinition rootResourceDefinition, final CapabilityRegistry capabilityRegistry, final ConfigurationExtension configExtension) { - super(executorService, null, processType, runningModeControl, configurationPersister, processState, rootResourceDefinition, null, ExpressionResolver.TEST_RESOLVER, - AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry, configExtension); + final ResourceDefinition rootResourceDefinition, final CapabilityRegistry capabilityRegistry, + final ConfigurationExtension configExtension, final Supplier pathManagerSupplier) { + super(executorService, null, processType, Stability.DEFAULT, runningModeControl, configurationPersister, processState, rootResourceDefinition, null, ExpressionResolver.TEST_RESOLVER, + AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry, configExtension, + pathManagerSupplier); this.processState = processState; this.capabilityRegistry = capabilityRegistry; } diff --git a/jmx/src/main/java/org/jboss/as/jmx/model/ManagementModelIntegration.java b/jmx/src/main/java/org/jboss/as/jmx/model/ManagementModelIntegration.java index 7e3beb8a7a0..aea04564f3a 100644 --- a/jmx/src/main/java/org/jboss/as/jmx/model/ManagementModelIntegration.java +++ b/jmx/src/main/java/org/jboss/as/jmx/model/ManagementModelIntegration.java @@ -10,6 +10,7 @@ import org.jboss.as.controller.ProcessType; import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; +import org.jboss.as.controller.services.path.PathManager; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; @@ -29,7 +30,7 @@ public class ManagementModelIntegration implements ModelControllerServiceInitial public static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("jmx", "management", "integration"); @Override - public void initializeStandalone(ServiceTarget target, ManagementModel managementModel, ProcessType processType) { + public void initializeStandalone(ServiceTarget target, ManagementModel managementModel, ProcessType processType, PathManager pathManager) { ManagementModelProvider provider = new ManagementModelProvider(new ResourceAndRegistration(managementModel)); target.addService(SERVICE_NAME, provider).setInitialMode(ServiceController.Mode.ON_DEMAND).install(); @@ -41,7 +42,7 @@ public void initializeDomain(ServiceTarget target, ManagementModel managementMod } @Override - public void initializeHost(ServiceTarget target, ManagementModel managementModel, String hostName, ProcessType processType) { + public void initializeHost(ServiceTarget target, ManagementModel managementModel, String hostName, ProcessType processType, PathManager pathManager) { // not relevant to host controller; ManagementModelProvider provider = new ManagementModelProvider(new ResourceAndRegistration(managementModel)); diff --git a/jmx/src/test/java/org/jboss/as/jmx/test/util/TestModelControllerService.java b/jmx/src/test/java/org/jboss/as/jmx/test/util/TestModelControllerService.java index d482c18ad7a..53dce845e46 100644 --- a/jmx/src/test/java/org/jboss/as/jmx/test/util/TestModelControllerService.java +++ b/jmx/src/test/java/org/jboss/as/jmx/test/util/TestModelControllerService.java @@ -9,6 +9,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Supplier; import org.jboss.as.controller.AbstractControllerService; import org.jboss.as.controller.ControlledProcessState; @@ -26,6 +27,9 @@ import org.jboss.as.controller.CapabilityRegistry; import org.jboss.as.controller.persistence.ConfigurationPersister; import org.jboss.as.controller.registry.Resource; +import org.jboss.as.controller.services.path.PathManager; +import org.jboss.as.controller.services.path.PathManagerService; +import org.jboss.as.version.Stability; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; @@ -36,6 +40,8 @@ */ public abstract class TestModelControllerService extends AbstractControllerService { + protected static final Supplier DEFAULT_PATH_MANAGER = () -> new PathManagerService() { + }; private final ControlledProcessState processState; final AtomicBoolean state = new AtomicBoolean(true); private final ProcessType processType; @@ -43,9 +49,15 @@ public abstract class TestModelControllerService extends AbstractControllerServi protected TestModelControllerService(final ProcessType processType, final ConfigurationPersister configurationPersister, final ControlledProcessState processState, final ResourceDefinition rootResourceDefinition, final ManagedAuditLogger auditLogger, final DelegatingConfigurableAuthorizer authorizer) { - super(processType, new RunningModeControl(RunningMode.NORMAL), configurationPersister, processState, rootResourceDefinition, - null, ExpressionResolver.TEST_RESOLVER, auditLogger, authorizer == null ? new DelegatingConfigurableAuthorizer() : authorizer, - new ManagementSecurityIdentitySupplier(), new CapabilityRegistry(true)); + super(null, + null, + processType, Stability.DEFAULT, new RunningModeControl(RunningMode.NORMAL), + configurationPersister, + processState, rootResourceDefinition, null, ExpressionResolver.TEST_RESOLVER, + auditLogger, authorizer == null ? new DelegatingConfigurableAuthorizer() : authorizer, + new ManagementSecurityIdentitySupplier(), + new CapabilityRegistry(true), null, + DEFAULT_PATH_MANAGER); this.processState = processState; this.processType = processType; } diff --git a/model-test/src/main/java/org/jboss/as/model/test/ModelTestModelControllerService.java b/model-test/src/main/java/org/jboss/as/model/test/ModelTestModelControllerService.java index fe36092aeee..b2748a0871a 100644 --- a/model-test/src/main/java/org/jboss/as/model/test/ModelTestModelControllerService.java +++ b/model-test/src/main/java/org/jboss/as/model/test/ModelTestModelControllerService.java @@ -12,6 +12,7 @@ import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Supplier; import org.jboss.as.controller.AbstractControllerService; import org.jboss.as.controller.CapabilityRegistry; @@ -43,6 +44,8 @@ import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; +import org.jboss.as.controller.services.path.PathManager; +import org.jboss.as.controller.services.path.PathManagerService; import org.jboss.as.controller.transform.TransformerRegistry; import org.jboss.as.version.Stability; import org.jboss.dmr.ModelNode; @@ -61,6 +64,8 @@ //TODO find better way to support legacy ModelTestModelControllerService without need for having all old methods still present on AbstractControllerService public abstract class ModelTestModelControllerService extends AbstractControllerService { + protected static final Supplier DEFAULT_PATH_MANAGER = () -> new PathManagerService() { + }; private final CountDownLatch latch = new CountDownLatch(1); private final StringConfigurationPersister persister; private final TransformerRegistry transformerRegistry; @@ -202,7 +207,8 @@ protected ModelTestModelControllerService(final ProcessType processType, final S new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry, - null); + null, + DEFAULT_PATH_MANAGER); this.persister = persister; this.transformerRegistry = transformerRegistry; this.validateOpsFilter = validateOpsFilter; @@ -228,7 +234,8 @@ protected ModelTestModelControllerService(final ProcessType processType, Stabili AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), capabilityRegistry, - null); + null, + DEFAULT_PATH_MANAGER); this.persister = persister; this.transformerRegistry = transformerRegistry; this.validateOpsFilter = validateOpsFilter; diff --git a/platform-mbean/src/test/java/org/jboss/as/platform/mbean/PlatformMBeanTestModelControllerService.java b/platform-mbean/src/test/java/org/jboss/as/platform/mbean/PlatformMBeanTestModelControllerService.java index 081c357add3..dedd203c887 100644 --- a/platform-mbean/src/test/java/org/jboss/as/platform/mbean/PlatformMBeanTestModelControllerService.java +++ b/platform-mbean/src/test/java/org/jboss/as/platform/mbean/PlatformMBeanTestModelControllerService.java @@ -6,6 +6,7 @@ package org.jboss.as.platform.mbean; import java.util.concurrent.CountDownLatch; +import java.util.function.Supplier; import org.jboss.as.controller.AbstractControllerService; import org.jboss.as.controller.ControlledProcessState; @@ -28,6 +29,9 @@ import org.jboss.as.controller.persistence.NullConfigurationPersister; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; +import org.jboss.as.controller.services.path.PathManager; +import org.jboss.as.controller.services.path.PathManagerService; +import org.jboss.as.version.Stability; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; @@ -38,6 +42,8 @@ */ public class PlatformMBeanTestModelControllerService extends AbstractControllerService { + protected static final Supplier DEFAULT_PATH_MANAGER = () -> new PathManagerService() { + }; final CountDownLatch latch = new CountDownLatch(2); /** @@ -45,9 +51,12 @@ public class PlatformMBeanTestModelControllerService extends AbstractControllerS * */ protected PlatformMBeanTestModelControllerService() { - super(ProcessType.EMBEDDED_SERVER, new RunningModeControl(RunningMode.NORMAL), new NullConfigurationPersister(), new ControlledProcessState(true), - ResourceBuilder.Factory.create(PathElement.pathElement("root"),NonResolvingResourceDescriptionResolver.INSTANCE).build(), null, ExpressionResolver.TEST_RESOLVER, - AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), new CapabilityRegistry(true)); + super(null, null, ProcessType.EMBEDDED_SERVER, Stability.DEFAULT, + new RunningModeControl(RunningMode.NORMAL), new NullConfigurationPersister(), + new ControlledProcessState(true), ResourceBuilder.Factory.create(PathElement.pathElement("root"), + NonResolvingResourceDescriptionResolver.INSTANCE).build(), null, ExpressionResolver.TEST_RESOLVER, + AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), + new CapabilityRegistry(true), null, DEFAULT_PATH_MANAGER); } @Override diff --git a/pom.xml b/pom.xml index 7d25ed6b22e..e0eb34872d1 100644 --- a/pom.xml +++ b/pom.xml @@ -241,6 +241,7 @@ 1.7.0.Final 1.3.0.Final 1.0.3.Final + 1.1.0.Final-SNAPSHOT 1.0.0.Beta3 8.0.2.Final 2.2.5.Final diff --git a/server/src/main/java/org/jboss/as/server/ServerService.java b/server/src/main/java/org/jboss/as/server/ServerService.java index 002ca2ff58a..00c2a565a0d 100644 --- a/server/src/main/java/org/jboss/as/server/ServerService.java +++ b/server/src/main/java/org/jboss/as/server/ServerService.java @@ -151,7 +151,6 @@ public final class ServerService extends AbstractControllerService { private final InjectedValue injectedModuleLoader = new InjectedValue(); private final InjectedValue injectedExternalModule = new InjectedValue<>(); - private final InjectedValue injectedPathManagerService = new InjectedValue(); private final Bootstrap.Configuration configuration; private final BootstrapListener bootstrapListener; @@ -184,10 +183,11 @@ private ServerService(final Supplier executorService, final OperationStepHandler prepareStep, final BootstrapListener bootstrapListener, final ServerDelegatingResourceDefinition rootResourceDefinition, final RunningModeControl runningModeControl, final ManagedAuditLogger auditLogger, final DelegatingConfigurableAuthorizer authorizer, final ManagementSecurityIdentitySupplier securityIdentitySupplier, - final CapabilityRegistry capabilityRegistry, final ServerSuspendController suspendController, final RuntimeExpressionResolver expressionResolver) { + final CapabilityRegistry capabilityRegistry, final ServerSuspendController suspendController, final RuntimeExpressionResolver expressionResolver, + final Supplier pathManagerSupplier) { super(executorService, instabilityListener, getProcessType(configuration.getServerEnvironment()), getStability(configuration.getServerEnvironment()), runningModeControl, null, processState, rootResourceDefinition, prepareStep, expressionResolver, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, - configuration.getServerEnvironment().getConfigurationExtension()); + configuration.getServerEnvironment().getConfigurationExtension(), pathManagerSupplier); this.configuration = configuration; this.bootstrapListener = bootstrapListener; this.processState = processState; @@ -248,15 +248,15 @@ public ThreadFactory run() { final Supplier esSupplier = allowMCE ? serviceBuilder.requires(MANAGEMENT_EXECUTOR) : null; final boolean isDomainEnv = configuration.getServerEnvironment().getLaunchType() == ServerEnvironment.LaunchType.DOMAIN; final Supplier cilSupplier = isDomainEnv ? serviceBuilder.requires(HostControllerConnectionService.SERVICE_NAME) : null; + final Supplier pathManagerSupplier = serviceBuilder.requires(PATH_MANAGER_CAPABILITY.getCapabilityServiceName()); ServerService service = new ServerService(esSupplier, cilSupplier, configuration, processState, null, bootstrapListener, new ServerDelegatingResourceDefinition(), - runningModeControl, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, suspendController, expressionResolver); + runningModeControl, auditLogger, authorizer, securityIdentitySupplier, capabilityRegistry, suspendController, expressionResolver, pathManagerSupplier); serviceBuilder.setInstance(service); serviceBuilder.addDependency(DeploymentMountProvider.SERVICE_NAME,DeploymentMountProvider.class, service.injectedDeploymentRepository); serviceBuilder.addDependency(ContentRepository.SERVICE_NAME, ContentRepository.class, service.injectedContentRepository); serviceBuilder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.injectedModuleLoader); serviceBuilder.addDependency(EXTERNAL_MODULE_CAPABILITY.getCapabilityServiceName(), ExternalModule.class, service.injectedExternalModule); - serviceBuilder.addDependency(PATH_MANAGER_CAPABILITY.getCapabilityServiceName(), PathManager.class, service.injectedPathManagerService); serviceBuilder.requires(CONSOLE_AVAILABILITY_CAPABILITY.getCapabilityServiceName()); serviceBuilder.install(); @@ -274,7 +274,7 @@ public synchronized void start(final StartContext context) throws StartException extensibleConfigurationPersister, configuration.getServerEnvironment(), processState, runningModeControl, configuration.getExtensionRegistry(), getExecutorService() != null, - (PathManagerService)injectedPathManagerService.getValue(), + (PathManagerService)pathManagerSupplier.get(), new DomainServerCommunicationServices.OperationIDUpdater() { @Override public void updateOperationID(final int operationID) { @@ -477,7 +477,7 @@ protected void initModel(ManagementModel managementModel, Resource modelControll rootResource.registerChild(PathElement.pathElement(ModelDescriptionConstants.CORE_SERVICE, ModelDescriptionConstants.CAPABILITY_REGISTRY), Resource.Factory.create()); managementResource.registerChild(AccessAuthorizationResourceDefinition.PATH_ELEMENT, AccessAuthorizationResourceDefinition.createResource(authorizer.getWritableAuthorizerConfiguration())); rootResource.registerChild(ServerEnvironmentResourceDescription.RESOURCE_PATH, Resource.Factory.create()); - ((PathManagerService)injectedPathManagerService.getValue()).addPathManagerResources(rootResource); + ((PathManagerService)pathManagerSupplier.get()).addPathManagerResources(rootResource); VersionModelInitializer.registerRootResource(rootResource, configuration.getServerEnvironment() != null ? configuration.getServerEnvironment().getProductConfig() : null); diff --git a/server/src/test/java/org/jboss/as/server/test/InterfaceManagementUnitTestCase.java b/server/src/test/java/org/jboss/as/server/test/InterfaceManagementUnitTestCase.java index 5ed30ff3fe5..ce2a85f1738 100644 --- a/server/src/test/java/org/jboss/as/server/test/InterfaceManagementUnitTestCase.java +++ b/server/src/test/java/org/jboss/as/server/test/InterfaceManagementUnitTestCase.java @@ -287,8 +287,11 @@ private static class ModelControllerService extends AbstractControllerService { ModelControllerService(final ControlledProcessState processState, final StringConfigurationPersister persister, final ServerDelegatingResourceDefinition rootResourceDefinition) { - super(ProcessType.EMBEDDED_SERVER, new RunningModeControl(RunningMode.ADMIN_ONLY), persister, processState, rootResourceDefinition, null, ExpressionResolver.TEST_RESOLVER, - AuditLogger.NO_OP_LOGGER, new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), new CapabilityRegistry(true)); + super(null, null, ProcessType.EMBEDDED_SERVER, Stability.DEFAULT, + new RunningModeControl(RunningMode.ADMIN_ONLY), persister, processState, rootResourceDefinition, + null, ExpressionResolver.TEST_RESOLVER, AuditLogger.NO_OP_LOGGER, + new DelegatingConfigurableAuthorizer(), new ManagementSecurityIdentitySupplier(), + new CapabilityRegistry(true), null, ()->MOCK_PATH_MANAGER); this.persister = persister; this.processState = processState; this.rootResourceDefinition = rootResourceDefinition; diff --git a/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/installationmanager/InstallationManagerDisabledTestCase.java b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/installationmanager/InstallationManagerDisabledTestCase.java new file mode 100644 index 00000000000..1aa1a92588e --- /dev/null +++ b/testsuite/domain/src/test/java/org/jboss/as/test/integration/domain/installationmanager/InstallationManagerDisabledTestCase.java @@ -0,0 +1,87 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.as.test.integration.domain.installationmanager; + +import static org.junit.Assert.assertThrows; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.jboss.as.test.integration.domain.management.util.DomainTestSupport; +import org.jboss.as.test.integration.management.base.AbstractCliTestBase; +import org.jboss.as.test.module.util.TestModule; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.wildfly.test.installationmanager.RejectingInstallationManagerFactory; +import org.wildfly.test.installationmanager.TestInstallationManager; +import org.wildfly.test.installationmanager.TestInstallationManagerFactory; + +public class InstallationManagerDisabledTestCase extends AbstractCliTestBase { + + private static final String MODULE_NAME = "org.jboss.prospero"; + private static DomainTestSupport testSupport; + private static TestModule testModule; + + static final Path TARGET_DIR = Paths.get(System.getProperty("basedir", ".")).resolve("target"); + + @BeforeClass + public static void setupDomain() throws Exception { + TestInstallationManagerFactory.validInstallation = false; + createTestModule(); + testSupport = DomainTestSupport.createAndStartDefaultSupport(InstallationManagerIntegrationTestCase.class.getSimpleName()); + AbstractCliTestBase.initCLI(DomainTestSupport.primaryAddress); + } + + @AfterClass + public static void tearDownDomain() throws Exception { + TestInstallationManagerFactory.validInstallation = true; + try { + AbstractCliTestBase.closeCLI(); + if (testSupport != null) { + testSupport.close(); + } + testSupport = null; + } finally { + testModule.remove(); + } + } + + private static void createTestModule() throws IOException { + testModule = new TestModule(MODULE_NAME, "org.wildfly.installation-manager.api"); + testModule.addResource("test-mock-installation-manager.jar").addClass(TestInstallationManager.class).addClass(RejectingInstallationManagerFactory.class) + .addAsManifestResource(new StringAsset(RejectingInstallationManagerFactory.class.getName()), + "services/org.wildfly.installationmanager.spi.InstallationManagerFactory"); + testModule.create(true); + } + + @After + public void clean() throws IOException { + for(File testZip : TARGET_DIR.toFile().listFiles((dir, name) -> name.startsWith("installation-manager") && name.endsWith(".zip"))) { + Files.deleteIfExists(testZip.toPath()); + } + } + + @Test + public void installerSubsystemIsNotAvailableWhenServerLacksInstManMetadata() throws Exception { + String host = "primary"; + AssertionError exception = assertThrows(AssertionError.class, () -> { + try { + cli.sendLine("installer history --host=" + host); + } catch (Exception e) { + e.printStackTrace(); + } + }); + String expectedMessage = "The command is not available in the current context"; + String actualMessage = exception.getMessage(); + Assert.assertTrue(actualMessage, actualMessage.contains(expectedMessage)); + } +} diff --git a/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/RejectingInstallationManagerFactory.java b/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/RejectingInstallationManagerFactory.java new file mode 100644 index 00000000000..13d60e6160a --- /dev/null +++ b/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/RejectingInstallationManagerFactory.java @@ -0,0 +1,24 @@ +package org.wildfly.test.installationmanager; + +import java.nio.file.Path; + +import org.wildfly.installationmanager.MavenOptions; +import org.wildfly.installationmanager.spi.InstallationManager; +import org.wildfly.installationmanager.spi.InstallationManagerFactory; + +public class RejectingInstallationManagerFactory implements InstallationManagerFactory { + @Override + public InstallationManager create(Path installationDir, MavenOptions mavenOptions) throws Exception { + return null; + } + + @Override + public boolean isManagedInstallation(Path installationDir) { + return false; + } + + @Override + public String getName() { + return null; + } +} diff --git a/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManager.java b/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManager.java index 91b5a3928e4..5dea6733fb8 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManager.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManager.java @@ -15,6 +15,7 @@ import java.time.Instant; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -22,8 +23,10 @@ import java.util.zip.ZipOutputStream; import org.wildfly.installationmanager.ArtifactChange; +import org.wildfly.installationmanager.CandidateType; import org.wildfly.installationmanager.Channel; import org.wildfly.installationmanager.ChannelChange; +import org.wildfly.installationmanager.FileConflict; import org.wildfly.installationmanager.HistoryResult; import org.wildfly.installationmanager.InstallationChanges; import org.wildfly.installationmanager.ManifestVersion; @@ -271,6 +274,21 @@ public Collection getInstalledVersions() throws Exception { return installedVersions; } + @Override + public Collection verifyCandidate(Path candidatePath, CandidateType candidateType) throws Exception { + return Collections.emptyList(); + } + + @Override + public String generateApplyRevertCommand(Path scriptHome, Path candidatePath, OsShell shell, boolean noConflictsOnly) throws OperationNotAvailableException { + return null; + } + + @Override + public String generateApplyUpdateCommand(Path scriptHome, Path candidatePath, OsShell shell, boolean noConflictsOnly) throws OperationNotAvailableException { + return null; + } + public static void zipDir(Path inputFile, Path target) throws IOException { try (FileOutputStream fos = new FileOutputStream(target.toFile()); ZipOutputStream zos = new ZipOutputStream(fos)) { ZipEntry entry = new ZipEntry(inputFile.getFileName().toString()); diff --git a/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManagerFactory.java b/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManagerFactory.java index f52df18e1a5..aef7630d7af 100644 --- a/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManagerFactory.java +++ b/testsuite/shared/src/main/java/org/wildfly/test/installationmanager/TestInstallationManagerFactory.java @@ -18,6 +18,7 @@ public class TestInstallationManagerFactory implements InstallationManagerFactor public static InstallationManager installationManager; public static Path installationDir; public static MavenOptions mavenOptions; + public static boolean validInstallation = true; @Override public InstallationManager create(Path installationDir, MavenOptions mavenOptions) throws Exception { @@ -31,4 +32,9 @@ public InstallationManager create(Path installationDir, MavenOptions mavenOption public String getName() { return "test"; } + + @Override + public boolean isManagedInstallation(Path installationDir) { + return validInstallation; + } }