use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing in project Payara by payara.
the class ApplicationLifecycle method setupContainerInfos.
/**
* set up containers and prepare the sorted ModuleInfos
* @param handler
* @param sniffers
* @param context
* @return
* @throws java.lang.Exception
*/
@Override
public List<EngineInfo> setupContainerInfos(final ArchiveHandler handler, Collection<? extends Sniffer> sniffers, DeploymentContext context) throws Exception {
final ActionReport report = context.getActionReport();
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
Map<Deployer, EngineInfo> containerInfosByDeployers = new LinkedHashMap<>();
for (Sniffer sniffer : sniffers) {
if (sniffer.getContainersNames() == null || sniffer.getContainersNames().length == 0) {
report.failure(logger, "no container associated with application of type : " + sniffer.getModuleType(), null);
throw new DeploymentException(localStrings.getLocalString("unknowncontainertype", "There is no installed container capable of handling this application {0}", context.getSource().getName()));
}
final String containerName = sniffer.getContainersNames()[0];
EngineInfo engineInfo = startEngine(context, sniffer, containerName);
Deployer deployer = startDeployer(context, containerName, engineInfo);
containerInfosByDeployers.put(deployer, engineInfo);
}
// all containers that have recognized parts of the application being deployed
// have now been successfully started. Start the deployment process.
List<EngineInfo> sortedEngineInfos = new ArrayList<>();
// ok everything is satisfied, just a matter of running things in order
List<Deployer> orderedDeployers = loadDeployers(containerInfosByDeployers, context);
// now load metadata from deployers.
for (Deployer deployer : orderedDeployers) {
if (logger.isLoggable(Level.FINE)) {
logger.log(FINE, "Ordered Deployer {0}", deployer.getClass());
}
final MetaData metadata = deployer.getMetaData();
EngineInfo engineInfo = containerInfosByDeployers.get(deployer);
try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, engineInfo.getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE, "MetaData")) {
if (metadata != null) {
if (metadata.provides() == null || metadata.provides().length == 0) {
deployer.loadMetaData(null, context);
} else {
for (Class<?> provide : metadata.provides()) {
if (context.getModuleMetaData(provide) == null) {
context.addModuleMetaData(deployer.loadMetaData(provide, context));
} else {
deployer.loadMetaData(null, context);
}
}
}
} else {
deployer.loadMetaData(null, context);
}
} catch (Exception e) {
report.failure(logger, "Exception while invoking " + deployer.getClass() + " prepare method", e);
throw e;
}
sortedEngineInfos.add(containerInfosByDeployers.get(deployer));
}
return sortedEngineInfos;
}
use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing in project Payara by payara.
the class ApplicationLifecycle method loadDeployers.
private List<Deployer> loadDeployers(Map<Deployer, EngineInfo> containerInfosByDeployers, DeploymentContext context) throws IOException {
final ActionReport report = context.getActionReport();
final Map<Class, ApplicationMetaDataProvider> typeByProvider = getTypeByProvider();
final Map<Class, Deployer> typeByDeployer = getTypeByDeployer(containerInfosByDeployers);
final StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
for (Deployer deployer : containerInfosByDeployers.keySet()) {
if (deployer.getMetaData() != null) {
for (Class dependency : deployer.getMetaData().requires()) {
if (!typeByDeployer.containsKey(dependency) && !typeByProvider.containsKey(dependency)) {
Service s = deployer.getClass().getAnnotation(Service.class);
String serviceName;
if (s != null && s.name() != null && s.name().length() > 0) {
serviceName = s.name();
} else {
serviceName = deployer.getClass().getSimpleName();
}
report.failure(logger, serviceName + " deployer requires " + dependency + " but no other deployer provides it", null);
return null;
}
}
}
}
List<Deployer> orderedDeployers = new ArrayList<>();
for (Map.Entry<Deployer, EngineInfo> entry : containerInfosByDeployers.entrySet()) {
Deployer deployer = entry.getKey();
if (logger.isLoggable(Level.FINE)) {
logger.log(FINE, "Keyed Deployer {0}", deployer.getClass());
}
DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, entry.getValue().getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE);
loadDeployer(orderedDeployers, deployer, typeByDeployer, typeByProvider, context);
span.close();
}
return orderedDeployers;
}
use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing in project Payara by payara.
the class DolProvider method getNameFor.
/**
* return the name for the given application
*
* @param archive
* @param context
* @return
*/
@Override
public String getNameFor(ReadableArchive archive, DeploymentContext context) {
if (context == null) {
return null;
}
DeployCommandParameters params = context.getCommandParameters(DeployCommandParameters.class);
Application application;
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
try (DeploymentSpan span = tracing.startSpan(DeploymentTracing.AppStage.DETERMINE_APP_NAME, "DeploymentDescriptors")) {
// name for ear and module name for standalone module
if (params.altdd != null || archive.exists("META-INF/application.xml") || archive.exists("WEB-INF/web.xml") || archive.exists("META-INF/ejb-jar.xml") || archive.exists("META-INF/application-client.xml") || archive.exists("META-INF/ra.xml")) {
String archiveType = context.getArchiveHandler().getArchiveType();
application = applicationFactory.createApplicationFromStandardDD(archive, archiveType);
ApplicationHolder holder = new ApplicationHolder(application);
context.addModuleMetaData(holder);
return application.getAppName();
}
} catch (Exception e) {
Logger.getAnonymousLogger().log(Level.WARNING, "Error occurred", e);
}
return null;
}
use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing in project Payara by payara.
the class ApplicationInfo method load.
@Override
public void load(ExtendedDeploymentContext context, ProgressTracker tracker) throws Exception {
Logger logger = context.getLogger();
if (isLoaded) {
logger.fine("Application is already loaded.");
return;
}
context.setPhase(ExtendedDeploymentContext.Phase.LOAD);
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
DeploymentSpan span = tracing.startSpan(TraceContext.Level.APPLICATION, name, DeploymentTracing.AppStage.LOAD);
super.load(context, tracker);
appClassLoader = context.getClassLoader();
for (ModuleInfo module : modules) {
module.load(getSubContext(module, context), tracker);
}
populateApplicationServiceLocator();
isLoaded = true;
span.close();
if (events != null) {
span = tracing.startSpan(TraceContext.Level.APPLICATION, name, DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.APPLICATION_LOADED.type());
events.send(new Event<ApplicationInfo>(Deployment.APPLICATION_LOADED, this), false);
span.close();
}
}
use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing in project Payara by payara.
the class ModuleInfo method load.
public void load(ExtendedDeploymentContext context, ProgressTracker tracker) throws Exception {
Logger logger = context.getLogger();
context.setPhase(ExtendedDeploymentContext.Phase.LOAD);
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
moduleClassLoader = context.getClassLoader();
Set<EngineRef> filteredEngines = new LinkedHashSet<>();
LinkedList<EngineRef> filteredReversedEngines = new LinkedList<>();
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.MODULE, name, DeploymentTracing.AppStage.LOAD)) {
Thread.currentThread().setContextClassLoader(context.getClassLoader());
for (EngineRef engine : _getEngineRefs()) {
final EngineInfo engineInfo = engine.getContainerInfo();
// get the container.
Deployer deployer = engineInfo.getDeployer();
try (DeploymentSpan containerSpan = tracing.startSpan(TraceContext.Level.CONTAINER, engineInfo.getSniffer().getModuleType(), DeploymentTracing.AppStage.LOAD)) {
ApplicationContainer appCtr = deployer.load(engineInfo.getContainer(), context);
if (appCtr == null) {
String msg = "Cannot load application in " + engineInfo.getContainer().getName() + " container";
logger.fine(msg);
continue;
}
engine.load(context, tracker);
engine.setApplicationContainer(appCtr);
filteredEngines.add(engine);
filteredReversedEngines.addFirst(engine);
} catch (Exception e) {
logger.log(SEVERE, "Exception while invoking " + deployer.getClass() + " load method", e);
throw e;
}
}
engines = filteredEngines;
reversedEngines = filteredReversedEngines;
if (events != null) {
try (DeploymentSpan innerSpan = tracing.startSpan(TraceContext.Level.MODULE, name, DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.MODULE_LOADED.type())) {
events.send(new Event<ModuleInfo>(Deployment.MODULE_LOADED, this), false);
}
}
} finally {
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
Aggregations