use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing 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.StructuredDeploymentTracing in project Payara by payara.
the class ApplicationLifecycle method initialize.
@Override
public void initialize(ApplicationInfo appInfo, Collection<? extends Sniffer> sniffers, ExtendedDeploymentContext context) {
if (appInfo == null) {
return;
}
appRegistry.removeTransient(appInfo.getName());
final ActionReport report = context.getActionReport();
ProgressTracker tracker = context.getTransientAppMetaData(ExtendedDeploymentContext.TRACKER, ProgressTracker.class);
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
// associated engines and the application info is created and registered
if (loadOnCurrentInstance(context)) {
try (SpanSequence span = tracing.startSequence(DeploymentTracing.AppStage.INITIALIZE)) {
notifyLifecycleInterceptorsBefore(ExtendedDeploymentContext.Phase.START, context);
appInfo.initialize();
appInfo.getModuleInfos().forEach(moduleInfo -> moduleInfo.getEngineRefs().forEach(engineRef -> tracker.add("initialized", EngineRef.class, engineRef)));
span.start(DeploymentTracing.AppStage.START);
appInfo.start(context, tracker);
notifyLifecycleInterceptorsAfter(ExtendedDeploymentContext.Phase.START, context);
} catch (Throwable loadException) {
logger.log(SEVERE, KernelLoggerInfo.lifecycleException, loadException);
report.failure(logger, "Exception while loading the app", null);
report.setFailureCause(loadException);
tracker.actOn(logger);
} finally {
context.postDeployClean(false);
if (report.getActionExitCode() == ActionReport.ExitCode.FAILURE) {
// warning status code is not a failure
events.send(new Event<>(Deployment.DEPLOYMENT_FAILURE, context));
} else {
events.send(new Event<>(Deployment.DEPLOYMENT_SUCCESS, appInfo));
}
}
currentDeploymentContext.get().pop();
}
}
use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing in project Payara by payara.
the class ApplicationLifecycle method getDeployableTypes.
@Override
@SuppressWarnings("squid:S2095")
public Types getDeployableTypes(DeploymentContext context) throws IOException {
synchronized (context) {
Types types = context.getTransientAppMetaData(Types.class.getName(), Types.class);
if (types != null) {
return types;
}
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
Boolean skipScanExternalLibProp = Boolean.valueOf(context.getAppProps().getProperty(DeploymentProperties.SKIP_SCAN_EXTERNAL_LIB));
Parser parser = getDeployableParser(context.getSource(), skipScanExternalLibProp, false, tracing, context.getLogger());
ParsingContext parsingContext = parser.getContext();
context.addTransientAppMetaData(Types.class.getName(), parsingContext.getTypes());
context.addTransientAppMetaData(Parser.class.getName(), parser);
return parsingContext.getTypes();
}
}
use of org.glassfish.internal.deployment.analysis.StructuredDeploymentTracing 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.StructuredDeploymentTracing 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