Skip to content

Commit

Permalink
[WFCORE-6560] Log installation provisioning information at boot
Browse files Browse the repository at this point in the history
  • Loading branch information
bstansberry committed Oct 16, 2023
1 parent eb66796 commit 3c2c5cc
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ public void initializeStandalone(ServiceTarget target, ManagementModel managemen

Optional<InstallationManagerFactory> im = InstallationManagerFinder.reloadAndFind();
if (im.isPresent()) {
final InstMgrService imService = createImService(target);
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(im.get(), imService));
managementModel.getRootResourceRegistration().registerSubModel(new InstMgrResourceDefinition(imf, imService));
}
}

Expand All @@ -75,20 +76,21 @@ public void initializeHost(ServiceTarget target, ManagementModel managementModel
// real hostname yet.
return;
}
final InstMgrService imService = createImService(target);
final InstallationManagerFactory imf = im.get();
final InstMgrService imService = createImService(target, imf);
hostResource.registerChild(InstMgrResourceDefinition.getPath(InstMgrConstants.TOOL_NAME), PlaceholderResource.INSTANCE);
hostRegistration.registerSubModel(new InstMgrResourceDefinition(im.get(), imService));
hostRegistration.registerSubModel(new InstMgrResourceDefinition(imf, imService));
}
}

private InstMgrService createImService(ServiceTarget target) {
private InstMgrService createImService(ServiceTarget target, InstallationManagerFactory imf) {
ServiceName serviceName = InstMgrResourceDefinition.INSTALLATION_MANAGER_CAPABILITY.getCapabilityServiceName();
ServiceBuilder<?> serviceBuilder = target.addService(serviceName);
Consumer<InstMgrService> consumer = serviceBuilder.provides(serviceName);
Supplier<PathManager> pathManagerSupplier = serviceBuilder.requires(PATH_MANAGER_CAPABILITY.getCapabilityServiceName());
Supplier<ExecutorService> executorSupplier = serviceBuilder.requires(EXECUTOR_CAPABILITY.getCapabilityServiceName());

InstMgrService imService = new InstMgrService(pathManagerSupplier, executorSupplier, consumer);
InstMgrService imService = new InstMgrService(imf, pathManagerSupplier, executorSupplier, consumer);
serviceBuilder.setInstance(imService).setInitialMode(ServiceController.Mode.PASSIVE).install();
return imService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@

package org.wildfly.core.instmgr;

import static org.wildfly.core.instmgr.logging.InstMgrLogger.CONFIG_LOGGER;
import static org.wildfly.core.instmgr.logging.InstMgrLogger.ROOT_LOGGER;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand All @@ -28,12 +33,19 @@
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.wildfly.core.instmgr.logging.InstMgrLogger;
import org.wildfly.installationmanager.Channel;
import org.wildfly.installationmanager.HistoryResult;
import org.wildfly.installationmanager.MavenOptions;
import org.wildfly.installationmanager.spi.InstallationManager;
import org.wildfly.installationmanager.spi.InstallationManagerFactory;

/**
* This is the main service used by the installation manager management operation handlers.
*/
class InstMgrService implements Service {
private static final Logger LOG = Logger.getLogger(InstMgrService.class);

private final InstallationManagerFactory imf;
private final Supplier<PathManager> pathManagerSupplier;
private final Consumer<InstMgrService> consumer;
private final Supplier<ExecutorService> executorSupplier;
Expand All @@ -48,7 +60,8 @@ class InstMgrService implements Service {
private final InstMgrCandidateStatus candidateStatus;
private ExecutorService executor;

InstMgrService(Supplier<PathManager> pathManagerSupplier, Supplier<ExecutorService> executorSupplier, Consumer<InstMgrService> consumer) {
InstMgrService(InstallationManagerFactory imf, Supplier<PathManager> pathManagerSupplier, Supplier<ExecutorService> executorSupplier, Consumer<InstMgrService> consumer) {
this.imf = imf;
this.pathManagerSupplier = pathManagerSupplier;
this.candidateStatus = new InstMgrCandidateStatus();
this.executorSupplier = executorSupplier;
Expand Down Expand Up @@ -83,6 +96,9 @@ public void start(StartContext startContext) throws StartException {
} catch (IOException e) {
throw new StartException(e);
}

logInstallationStatus();

started.set(true);
this.consumer.accept(this);
}
Expand Down Expand Up @@ -195,4 +211,32 @@ Path getControllerTempDir() {
public ExecutorService getMgmtExecutor() {
return executor;
}



private void logInstallationStatus() {
if (CONFIG_LOGGER.isInfoEnabled()) {
MavenOptions mavenOptions = new MavenOptions(null, false);
InstallationManager installationManager = null;
Collection<Channel> channels = null;
List<HistoryResult> history = null;
try {
installationManager = imf.create(homeDir, mavenOptions);
channels = installationManager.listChannels();
CONFIG_LOGGER.provisioningChannels(channels);
if (CONFIG_LOGGER.isDebugEnabled()) {
history = installationManager.history();
CONFIG_LOGGER.provisioningHistory(history);
}
} catch (Exception e) {
if (installationManager == null) {
ROOT_LOGGER.failedToCreateInstallationManager(homeDir, e);
} else if (channels == null) {
ROOT_LOGGER.failedToFindInstallationChannels(e);
} else if (CONFIG_LOGGER.isDebugEnabled() && history == null) {
ROOT_LOGGER.failedToFindInstallationHistory(e);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@

package org.wildfly.core.instmgr.logging;

import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.zip.ZipException;

import org.jboss.as.controller.OperationFailedException;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.wildfly.installationmanager.Channel;
import org.wildfly.installationmanager.HistoryResult;

/**
* Installation Manager logger.
*/
@SuppressWarnings("DefaultAnnotationParam")
@MessageLogger(projectCode = "WFLYIM", length = 4)
public interface InstMgrLogger extends BasicLogger {

InstMgrLogger ROOT_LOGGER = Logger.getMessageLogger(InstMgrLogger.class, "org.wildfly.core.installationmanager");

InstMgrLogger CONFIG_LOGGER = Logger.getMessageLogger(InstMgrLogger.class, "org.jboss.as.config");

@Message(id = 1, value = "There is an installation prepared and ready to be applied. The current prepared installation can be discarded by using the 'clean' operation.")
OperationFailedException serverAlreadyPrepared();

Expand Down Expand Up @@ -81,6 +90,26 @@ public interface InstMgrLogger extends BasicLogger {
@Message(id = 20, value = "No custom patches installed found for the specified manifest maven coordinates: '%s'")
OperationFailedException noCustomPatchFound(String manifestGA);

@LogMessage(level = Logger.Level.INFO)
@Message(id = 21, value = "Installation provisioning is using the following channels: '%s'")
void provisioningChannels(Collection<Channel> channels);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 22, value = "Installation has the following provisioning history: '%s'")
void provisioningHistory(List<HistoryResult> history);

@LogMessage(level = Logger.Level.ERROR)
@Message(id = 23, value = "Cannot report installation status. Cannot create an InstallationManager for path '%s': '%s'")
void failedToCreateInstallationManager(Path homeDir, Exception failure);

@LogMessage(level = Logger.Level.ERROR)
@Message(id = 24, value = "Cannot report installation channels: '%s'")
void failedToFindInstallationChannels(Exception failure);

@LogMessage(level = Logger.Level.ERROR)
@Message(id = 25, value = "Cannot report installation history: '%s'")
void failedToFindInstallationHistory(Exception failure);

////////////////////////////////////////////////
// Messages without IDs

Expand Down

0 comments on commit 3c2c5cc

Please sign in to comment.