use of org.glassfish.internal.deployment.analysis.DeploymentSpan 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);
}
}
use of org.glassfish.internal.deployment.analysis.DeploymentSpan in project Payara by payara.
the class ApplicationLifecycle method prepareModule.
@Override
public ModuleInfo prepareModule(List<EngineInfo> sortedEngineInfos, String moduleName, DeploymentContext context, ProgressTracker tracker) throws Exception {
List<EngineRef> addedEngines = new ArrayList<>();
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
tracing.switchToContext(TraceContext.Level.MODULE, moduleName);
for (EngineInfo engineInfo : sortedEngineInfos) {
// get the deployer
Deployer deployer = engineInfo.getDeployer();
try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, engineInfo.getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE)) {
deployer.prepare(context);
// construct an incomplete EngineRef which will be later
// filled in at loading time
EngineRef engineRef = new EngineRef(engineInfo, null);
addedEngines.add(engineRef);
tracker.add("prepared", EngineRef.class, engineRef);
tracker.add(Deployer.class, deployer);
} catch (Exception e) {
final ActionReport report = context.getActionReport();
report.failure(logger, "Exception while invoking " + deployer.getClass() + " prepare method", e);
throw e;
}
}
if (events != null) {
DeploymentSpan span = tracing.startSpan(TraceContext.Level.MODULE, moduleName, DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.MODULE_PREPARED.type());
events.send(new Event<>(Deployment.MODULE_PREPARED, context), false);
span.close();
}
// I need to create the application info here from the context, or something like this.
// and return the application info from this method for automatic registration in the caller.
// set isComposite property on module props so we know whether to persist
// module level properties inside ModuleInfo
String isComposite = context.getAppProps().getProperty(ServerTags.IS_COMPOSITE);
if (isComposite != null) {
context.getModuleProps().setProperty(ServerTags.IS_COMPOSITE, isComposite);
}
ModuleInfo mi = new ModuleInfo(events, moduleName, addedEngines, context.getModuleProps());
/*
* Save the application config that is potentially attached to each
* engine in the corresponding EngineRefs that have already created.
*
* Later, in registerAppInDomainXML, the appInfo is saved, which in
* turn saves the moduleInfo children and their engineRef children.
* Saving the engineRef assigns the application config to the Engine
* which corresponds directly to the <engine> element in the XML.
* A long way to get this done.
*/
// Application existingApp = applications.getModule(Application.class, moduleName);
// if (existingApp != null) {
ApplicationConfigInfo savedAppConfig = new ApplicationConfigInfo(context.getAppProps());
for (EngineRef er : mi.getEngineRefs()) {
ApplicationConfig c = savedAppConfig.get(mi.getName(), er.getContainerInfo().getSniffer().getModuleType());
if (c != null) {
er.setApplicationConfig(c);
}
}
// }
return mi;
}
use of org.glassfish.internal.deployment.analysis.DeploymentSpan in project Payara by payara.
the class ApplicationLifecycle method startDeployer.
private Deployer startDeployer(DeploymentContext context, String containerName, EngineInfo engineInfo) throws Exception {
final ActionReport report = context.getActionReport();
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, engineInfo.getSniffer().getModuleType(), DeploymentTracing.AppStage.PREPARE, "Deployer")) {
Deployer deployer = engineInfo.getDeployer();
if (deployer == null) {
if (!startContainers(Collections.singleton(engineInfo), logger, context)) {
final String msg = "Aborting, Failed to start container " + containerName;
report.failure(logger, msg, null);
throw new Exception(msg);
}
deployer = engineInfo.getDeployer();
if (deployer == null) {
report.failure(logger, "Got a null deployer out of the " + engineInfo.getContainer().getClass() + " container, is it annotated with @Service ?");
throw new DeploymentException("Deployer not found for container " + containerName);
}
}
return deployer;
}
}
use of org.glassfish.internal.deployment.analysis.DeploymentSpan in project Payara by payara.
the class ApplicationLifecycle method getDeployableParser.
public Parser getDeployableParser(ReadableArchive source, boolean skipScanExternalLibProp, boolean modelUnAnnotatedMembers, StructuredDeploymentTracing tracing, Logger logger) throws IOException {
try {
ResourceLocator locator = determineLocator();
// scan the jar and store the result in the deployment context.
ParsingContext.Builder parsingContextBuilder = new ParsingContext.Builder().logger(logger).executorService(executorService.getUnderlyingExecutorService()).config(new ParsingConfig() {
@Override
public Set<String> getAnnotationsOfInterest() {
return Collections.emptySet();
}
@Override
public Set<String> getTypesOfInterest() {
return Collections.emptySet();
}
@Override
public boolean modelUnAnnotatedMembers() {
return modelUnAnnotatedMembers;
}
});
// workaround bug in Builder
parsingContextBuilder.locator(locator);
ParsingContext parsingContext = parsingContextBuilder.build();
Parser parser = new Parser(parsingContext);
ReadableArchiveScannerAdapter scannerAdapter = new ReadableArchiveScannerAdapter(parser, source);
DeploymentSpan mainScanSpan = tracing.startSpan(DeploymentTracing.AppStage.CLASS_SCANNING, source.getName());
parser.parse(scannerAdapter, () -> mainScanSpan.close());
for (ReadableArchive externalLibArchive : getExternalLibraries(source, skipScanExternalLibProp)) {
ReadableArchiveScannerAdapter libAdapter = null;
try {
DeploymentSpan span = tracing.startSpan(DeploymentTracing.AppStage.CLASS_SCANNING, externalLibArchive.getName());
libAdapter = new ReadableArchiveScannerAdapter(parser, externalLibArchive);
parser.parse(libAdapter, () -> span.close());
} finally {
if (libAdapter != null) {
libAdapter.close();
}
}
}
parser.awaitTermination();
scannerAdapter.close();
return parser;
} catch (InterruptedException e) {
throw new IOException(e);
}
}
use of org.glassfish.internal.deployment.analysis.DeploymentSpan in project Payara by payara.
the class ApplicationLifecycle method loadDeployer.
private void loadDeployer(List<Deployer> results, Deployer deployer, Map<Class, Deployer> typeByDeployer, Map<Class, ApplicationMetaDataProvider> typeByProvider, DeploymentContext dc) throws IOException {
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(dc);
if (results.contains(deployer)) {
return;
}
results.add(deployer);
if (deployer.getMetaData() != null) {
for (Class required : deployer.getMetaData().requires()) {
if (dc.getModuleMetaData(required) != null) {
continue;
}
if (typeByDeployer.containsKey(required)) {
loadDeployer(results, typeByDeployer.get(required), typeByDeployer, typeByProvider, dc);
} else {
ApplicationMetaDataProvider provider = typeByProvider.get(required);
if (provider == null) {
logger.log(SEVERE, KernelLoggerInfo.inconsistentLifecycleState, required);
} else {
LinkedList<ApplicationMetaDataProvider> providers = new LinkedList<>();
addRecursively(providers, typeByProvider, provider);
for (ApplicationMetaDataProvider p : providers) {
// this actually loads all descriptors of the app.
try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.APPLICATION, null, DeploymentTracing.AppStage.LOAD, "DeploymentDescriptor")) {
dc.addModuleMetaData(p.load(dc));
}
}
}
}
}
}
}
Aggregations