use of org.glassfish.internal.deployment.analysis.DeploymentSpan in project Payara by payara.
the class GenericHandler method getDefaultApplicationName.
/**
* Returns the default application name usable for identifying the archive.
* <p>
* This default implementation returns the name portion of
* the archive's URI. The archive's name depends on the type of archive
* (FileArchive vs. JarArchive vs. MemoryMappedArchive, for example).
* <p>
* A concrete subclass can override this method to provide an alternative
* way of deriving the default application name.
*
* @param archive the archive for which the default name is needed
* @param context deployment context
* @return the default application name for the specified archive
*/
@Override
public String getDefaultApplicationName(ReadableArchive archive, DeploymentContext context, String originalAppName) {
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
DeploymentSpan span = tracing.startSpan(DeploymentTracing.AppStage.DETERMINE_APP_NAME, "ApplicationInfoProvider");
// first try to get the name from ApplicationInfoProvider if
// we can find an implementation of this service
ApplicationInfoProvider nameProvider = habitat.getService(ApplicationInfoProvider.class);
span.close();
String appName = null;
if (nameProvider != null) {
appName = nameProvider.getNameFor(archive, context);
if (appName != null) {
if (originalAppName != null && appName.equals(archive.getName())) {
appName = originalAppName;
}
return appName;
}
}
if (originalAppName != null) {
return originalAppName;
}
// now try to get the default
return getDefaultApplicationNameFromArchiveName(archive);
}
use of org.glassfish.internal.deployment.analysis.DeploymentSpan in project Payara by payara.
the class ModuleInfo method start.
public synchronized void start(DeploymentContext context, ProgressTracker tracker) throws Exception {
Logger logger = context.getLogger();
if (started)
return;
loaded = true;
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.MODULE, getName(), DeploymentTracing.AppStage.START)) {
Thread.currentThread().setContextClassLoader(context.getClassLoader());
// registers all deployed items.
for (EngineRef engine : _getEngineRefs()) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, "starting {0}", engine.getContainerInfo().getSniffer().getModuleType());
}
try (DeploymentSpan innerSpan = tracing.startSpan(TraceContext.Level.CONTAINER, engine.getContainerInfo().getSniffer().getModuleType(), DeploymentTracing.AppStage.START)) {
if (!engine.start(context, tracker)) {
logger.log(SEVERE, "Module not started {0}", engine.getApplicationContainer().toString());
throw new Exception("Module not started " + engine.getApplicationContainer().toString());
}
} catch (Exception e) {
DeployCommandParameters dcp = context.getCommandParameters(DeployCommandParameters.class);
if (dcp.isSkipDSFailure() && ExceptionUtil.isDSFailure(e)) {
logger.log(WARNING, "Resource communication failure exception skipped while invoking " + engine.getApplicationContainer().getClass() + " start method", e);
} else {
logger.log(SEVERE, "Exception while invoking " + engine.getApplicationContainer().getClass() + " start method", e);
throw e;
}
}
}
started = true;
if (events != null) {
try (DeploymentSpan innerSpan = tracing.startSpan(DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.MODULE_STARTED.type())) {
events.send(new Event<ModuleInfo>(Deployment.MODULE_STARTED, this), false);
}
}
} finally {
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
use of org.glassfish.internal.deployment.analysis.DeploymentSpan in project Payara by payara.
the class ModuleInfo method reload.
public synchronized void reload(DeploymentContext context, ProgressTracker tracker) throws Exception {
Logger logger = context.getLogger();
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.MODULE, getName(), DeploymentTracing.AppStage.START)) {
Thread.currentThread().setContextClassLoader(context.getClassLoader());
for (EngineRef engine : _getEngineRefs()) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, "Reloading {0}", engine.getContainerInfo().getSniffer().getModuleType());
}
try (DeploymentSpan innerSpan = tracing.startSpan(TraceContext.Level.CONTAINER, engine.getContainerInfo().getSniffer().getModuleType(), DeploymentTracing.AppStage.START)) {
if (!engine.reload(context, tracker)) {
logger.log(SEVERE, "Module not reloaded {0}", engine.getApplicationContainer().toString());
throw new Exception("Module not reloaded " + engine.getApplicationContainer().toString());
}
} catch (Exception e) {
DeployCommandParameters dcp = context.getCommandParameters(DeployCommandParameters.class);
if (dcp.isSkipDSFailure() && ExceptionUtil.isDSFailure(e)) {
logger.log(WARNING, "Resource communication failure exception skipped while invoking " + engine.getApplicationContainer().getClass() + " start method", e);
} else {
logger.log(SEVERE, "Exception while invoking " + engine.getApplicationContainer().getClass() + " reload method", e);
throw e;
}
}
}
} finally {
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
use of org.glassfish.internal.deployment.analysis.DeploymentSpan in project Payara by payara.
the class DeployCommand method preAuthorization.
@Override
public boolean preAuthorization(AdminCommandContext context) {
logger = context.getLogger();
events.register(this);
suppInfo = new DeployCommandSupplementalInfo();
context.getActionReport().setResultType(DeployCommandSupplementalInfo.class, suppInfo);
structuredTracing = System.getProperty("org.glassfish.deployment.trace") != null ? StructuredDeploymentTracing.create(path.getName()) : StructuredDeploymentTracing.createDisabled(path.getName());
timing = new DeploymentTracing(structuredTracing);
final ActionReport report = context.getActionReport();
originalPathValue = path;
if (!path.exists()) {
report.setMessage(localStrings.getLocalString("fnf", "File not found", path.getAbsolutePath()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return false;
}
if (!path.canRead()) {
report.setMessage(localStrings.getLocalString("fnr", "File {0} does not have read permission", path.getAbsolutePath()));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return false;
}
if (snifferManager.hasNoSniffers()) {
String msg = localStrings.getLocalString("nocontainer", "No container services registered, done...");
report.failure(logger, msg);
return false;
}
try (DeploymentSpan span = structuredTracing.startSpan(DeploymentTracing.AppStage.OPENING_ARCHIVE)) {
archive = archiveFactory.openArchive(path, this);
} catch (IOException e) {
final String msg = localStrings.getLocalString("deploy.errOpeningArtifact", "deploy.errOpeningArtifact", path.getAbsolutePath());
if (logReportedErrors) {
report.failure(logger, msg, e);
} else {
report.setMessage(msg + path.getAbsolutePath() + e.toString());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
return false;
}
if (altdd != null) {
archive.addArchiveMetaData(DeploymentProperties.ALT_DD, altdd);
}
if (runtimealtdd != null) {
archive.addArchiveMetaData(DeploymentProperties.RUNTIME_ALT_DD, runtimealtdd);
}
expansionDir = null;
deploymentContext = null;
try (SpanSequence span = structuredTracing.startSequence(DeploymentTracing.AppStage.VALIDATE_TARGET, "command")) {
deployment.validateSpecifiedTarget(target);
span.start(DeploymentTracing.AppStage.OPENING_ARCHIVE, "ArchiveHandler");
archiveHandler = deployment.getArchiveHandler(archive, type);
if (archiveHandler == null) {
report.failure(logger, localStrings.getLocalString("deploy.unknownarchivetype", "Archive type of {0} was not recognized", path));
return false;
}
span.start(DeploymentTracing.AppStage.CREATE_DEPLOYMENT_CONTEXT, "Initial");
Optional<ApplicationState> appState = hotDeployService.getApplicationState(path);
boolean hotswap = hotDeploy && !metadataChanged && appState.map(ApplicationState::isHotswap).orElse(false);
if (!hotswap) {
// create an initial context
initialContext = new DeploymentContextImpl(report, archive, this, env);
} else {
initialContext = hotDeployService.getApplicationState(path).map(ApplicationState::getDeploymentContext).orElseThrow(() -> new RuntimeException());
}
initialContext.setArchiveHandler(archiveHandler);
if (hotDeploy && !metadataChanged && appState.isPresent()) {
if (!appState.get().start(this, initialContext, events)) {
appState.get().close();
return false;
}
} else {
hotDeployService.removeApplicationState(path);
}
structuredTracing.register(initialContext);
span.finish();
span.start(DeploymentTracing.AppStage.PROCESS_EVENTS, Deployment.INITIAL_CONTEXT_CREATED.type());
events.send(new Event<DeploymentContext>(Deployment.INITIAL_CONTEXT_CREATED, initialContext), false);
span.start(DeploymentTracing.AppStage.DETERMINE_APP_NAME);
if (!forceName) {
boolean isModuleDescriptorAvailable = false;
if (archiveHandler.getArchiveType().equals("ejb") && (archive.exists(EJB_JAR_XML) || archive.exists(SUN_EJB_JAR_XML) || archive.exists(GF_EJB_JAR_XML))) {
isModuleDescriptorAvailable = true;
} else if (archiveHandler.getArchiveType().equals("ear") && (archive.exists(APPLICATION_XML) || archive.exists(SUN_APPLICATION_XML) || archive.exists(GF_APPLICATION_XML))) {
isModuleDescriptorAvailable = true;
} else if (archiveHandler.getArchiveType().equals("car") && (archive.exists(APPLICATION_CLIENT_XML) || archive.exists(SUN_APPLICATION_CLIENT_XML) || archive.exists(GF_APPLICATION_CLIENT_XML))) {
isModuleDescriptorAvailable = true;
} else if (archiveHandler.getArchiveType().equals("rar") && (archive.exists(RA_XML))) {
isModuleDescriptorAvailable = true;
}
if (isModuleDescriptorAvailable) {
name = archiveHandler.getDefaultApplicationName(initialContext.getSource(), initialContext, name);
}
}
if (name == null) {
name = archiveHandler.getDefaultApplicationName(initialContext.getSource(), initialContext);
} else {
DeploymentUtils.validateApplicationName(name);
}
boolean isUntagged = VersioningUtils.isUntagged(name);
// no GlassFish versioning support for OSGi budles
if (name != null && !isUntagged && type != null && type.equals("osgi")) {
ActionReport.MessagePart msgPart = context.getActionReport().getTopMessagePart();
msgPart.setChildrenType("WARNING");
ActionReport.MessagePart childPart = msgPart.addChild();
childPart.setMessage(VersioningUtils.LOCALSTRINGS.getLocalString("versioning.deployment.osgi.warning", "OSGi bundles will not use the GlassFish versioning, any version information embedded as part of the name option will be ignored"));
name = VersioningUtils.getUntaggedName(name);
}
// we try to retrieve the version-identifier element's value from DD
if (isUntagged) {
String versionIdentifier = archiveHandler.getVersionIdentifier(initialContext.getSource());
if (versionIdentifier != null && !versionIdentifier.isEmpty()) {
name = name + VersioningUtils.EXPRESSION_SEPARATOR + versionIdentifier;
}
}
if (target == null) {
target = deployment.getDefaultTarget(name, origin, _classicstyle);
}
boolean isRegistered = deployment.isRegistered(name);
isredeploy = isRegistered && force;
return true;
} catch (Exception ex) {
events.unregister(this);
if (initialContext != null && initialContext.getSource() != null) {
try {
initialContext.getSource().close();
} catch (IOException ioex) {
throw new RuntimeException(ioex);
}
}
throw new RuntimeException(ex);
}
}
use of org.glassfish.internal.deployment.analysis.DeploymentSpan in project Payara by payara.
the class ApplicationLifecycle method startEngine.
private EngineInfo startEngine(DeploymentContext context, Sniffer sniffer, String containerName) throws Exception {
final ActionReport report = context.getActionReport();
StructuredDeploymentTracing tracing = StructuredDeploymentTracing.load(context);
// start all the containers associated with sniffers.
try (DeploymentSpan span = tracing.startSpan(TraceContext.Level.CONTAINER, sniffer.getModuleType(), DeploymentTracing.AppStage.PREPARE)) {
EngineInfo engineInfo = containerRegistry.getContainer(containerName);
if (engineInfo == null) {
// need to synchronize on the registry to not end up starting the same container from
// different threads.
Collection<EngineInfo> containersInfo = null;
synchronized (containerRegistry) {
if (containerRegistry.getContainer(containerName) == null) {
DeploymentSpan innerSpan = tracing.startSpan(DeploymentTracing.AppStage.CONTAINER_START);
containersInfo = setupContainer(sniffer, logger, context);
innerSpan.close();
if (containersInfo == null || containersInfo.isEmpty()) {
String msg = "Cannot start container(s) associated to application of type : " + sniffer.getModuleType();
report.failure(logger, msg, null);
throw new Exception(msg);
}
}
}
// now start all containers, by now, they should be all setup...
if (containersInfo != null && !startContainers(containersInfo, logger, context)) {
final String msg = "Aborting, Failed to start container " + containerName;
report.failure(logger, msg, null);
throw new Exception(msg);
}
}
engineInfo = containerRegistry.getContainer(containerName);
if (engineInfo == null) {
final String msg = "Aborting, Failed to start container " + containerName;
report.failure(logger, msg, null);
throw new Exception(msg);
}
return engineInfo;
}
}
Aggregations