use of org.glassfish.internal.deployment.Deployment in project Payara by payara.
the class PersistentEJBTimerService method deployEJBTimerService.
private static boolean deployEJBTimerService(File root, File appScratchFile, String resourceName, boolean is_upgrade) {
boolean deployed = false;
logger.log(Level.INFO, "Loading EJBTimerService. Please wait.");
File app = null;
try {
app = FileUtils.getManagedFile(TIMER_SERVICE_APP_NAME + ".war", new File(root, "lib/install/applications/"));
} catch (Exception e) {
logger.log(Level.WARNING, "Caught unexpected exception", e);
}
if (app == null || !app.exists()) {
logger.log(Level.WARNING, "Cannot deploy or load persistent EJBTimerService: " + "required WAR file (" + TIMER_SERVICE_APP_NAME + ".war) is not installed");
} else {
DeployCommandParameters params = new DeployCommandParameters(app);
params.name = TIMER_SERVICE_APP_NAME;
try {
EjbContainerUtil _ejbContainerUtil = EjbContainerUtilImpl.getInstance();
// first access of the Timer Service application
if (_ejbContainerUtil.isDas() && appScratchFile.createNewFile() && !is_upgrade) {
params.origin = OpsParams.Origin.deploy;
} else {
params.origin = OpsParams.Origin.load;
}
params.target = _ejbContainerUtil.getServerEnvironment().getInstanceName();
ActionReport report = _ejbContainerUtil.getServices().getService(ActionReport.class, "plain");
Deployment deployment = _ejbContainerUtil.getDeployment();
ExtendedDeploymentContext dc = deployment.getBuilder(logger, params, report).source(app).build();
dc.addTransientAppMetaData(DatabaseConstants.JTA_DATASOURCE_JNDI_NAME_OVERRIDE, resourceName);
Properties appProps = dc.getAppProps();
appProps.setProperty(ServerTags.OBJECT_TYPE, DeploymentProperties.SYSTEM_ALL);
deployment.deploy(dc);
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
logger.log(Level.WARNING, "Cannot deploy or load EJBTimerService: ", report.getFailureCause());
} else {
deployed = true;
}
} catch (Exception e) {
logger.log(Level.WARNING, "Cannot deploy or load EJBTimerService: ", e);
} finally {
if (!deployed && params.origin.isDeploy() && appScratchFile.exists()) {
// Remove marker file if deploy failed
if (!appScratchFile.delete()) {
logger.log(Level.WARNING, "Failed to remove the marker file " + appScratchFile);
}
}
}
}
return deployed;
}
use of org.glassfish.internal.deployment.Deployment in project Payara by payara.
the class VirtualServer method removeContext.
/**
* Stops the given <tt>context</tt> and removes it from this <tt>VirtualServer</tt>.
*
* @throws org.glassfish.embeddable.GlassFishException
*/
@Override
public void removeContext(Context context) throws GlassFishException {
ActionReport report = services.getService(ActionReport.class, "plain");
Deployment deployment = services.getService(Deployment.class);
String name;
if (context instanceof ContextFacade) {
name = ((ContextFacade) context).getAppName();
} else {
name = context.getPath();
}
ApplicationInfo appInfo = deployment.get(name);
if (appInfo == null) {
report.setMessage("Cannot find deployed application of name " + name);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishException("Cannot find deployed application of name " + name);
}
ReadableArchive source = appInfo.getSource();
if (source == null) {
report.setMessage("Cannot get source archive for undeployment");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishException("Cannot get source archive for undeployment");
}
UndeployCommandParameters params = new UndeployCommandParameters(name);
params.origin = UndeployCommandParameters.Origin.undeploy;
params.target = "server";
ExtendedDeploymentContext deploymentContext = null;
try {
deploymentContext = deployment.getBuilder(_logger, params, report).source(source).build();
deployment.undeploy(name, deploymentContext);
deployment.unregisterAppFromDomainXML(name, "server");
} catch (IOException e) {
_logger.log(Level.SEVERE, LogFacade.REMOVE_CONTEXT_ERROR, e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
throw new GlassFishException("Cannot create context for undeployment ", e);
} catch (TransactionFailure e) {
throw new GlassFishException(e);
} finally {
if (deploymentContext != null) {
deploymentContext.clean();
}
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, LogFacade.REMOVED_CONTEXT, name);
}
}
use of org.glassfish.internal.deployment.Deployment in project Payara by payara.
the class EventsTest method badUndeployTest.
@Test
public void badUndeployTest() throws Exception {
Deployment deployment = habitat.getService(Deployment.class);
UndeployCommandParameters params = new UndeployCommandParameters("notavalidname");
params.target = "server";
ActionReport report = habitat.getService(ActionReport.class, "hk2-agent");
ExtendedDeploymentContext dc = deployment.getBuilder(Logger.getAnonymousLogger(), params, report).source(application).build();
deployment.undeploy("notavalidname", dc);
Assert.assertEquals(report.getActionExitCode(), ActionReport.ExitCode.FAILURE);
}
use of org.glassfish.internal.deployment.Deployment in project Payara by payara.
the class EventsTest method deployUndeployTest.
@Test
public void deployUndeployTest() throws Exception {
final List<EventTypes> myTestEvents = getSingletonModuleSuccessfullDeploymentEvents();
Events events = habitat.getService(Events.class);
EventListener listener = new EventListener() {
public void event(Event event) {
if (myTestEvents.contains(event.type())) {
myTestEvents.remove(event.type());
}
}
};
events.register(listener);
Deployment deployment = habitat.getService(Deployment.class);
DeployCommandParameters params = new DeployCommandParameters(application);
params.name = "fakeApplication";
params.target = "server";
ActionReport report = habitat.getService(ActionReport.class, "hk2-agent");
ExtendedDeploymentContext dc = deployment.getBuilder(Logger.getAnonymousLogger(), params, report).source(application).build();
deployment.deploy(dc);
events.unregister(listener);
for (EventTypes et : myTestEvents) {
System.out.println("An expected event of type " + et.type() + " was not received");
}
try {
final List<EventTypes> myTestEvents2 = getSingletonModuleSuccessfullUndeploymentEvents();
EventListener listener2 = new EventListener() {
public void event(Event event) {
if (myTestEvents2.contains(event.type())) {
myTestEvents2.remove(event.type());
}
}
};
events.register(listener2);
UndeployCommandParameters params2 = new UndeployCommandParameters("fakeApplication");
params2.target = "server";
ActionReport report2 = habitat.getService(ActionReport.class, "hk2-agent");
ExtendedDeploymentContext dc2 = deployment.getBuilder(Logger.getAnonymousLogger(), params2, report2).source(application).build();
deployment.undeploy("fakeApplication", dc2);
events.unregister(listener2);
for (EventTypes et : myTestEvents2) {
System.out.println("An expected event of type " + et.type() + " was not received");
}
} catch (Throwable t) {
t.printStackTrace();
}
}
use of org.glassfish.internal.deployment.Deployment in project Payara by payara.
the class ApplicationState method start.
/**
* Starts the Application state for new deployment by copying the cached
* metadata and properties to the new {@code DeploymentContext} instance.
*
* @param commandParams
* @param newContext
* @param events
* @return
*/
public boolean start(DeployCommandParameters commandParams, ExtendedDeploymentContext newContext, Events events) {
validateInactiveState();
this.active = true;
if (commandParams.sourcesChanged != null) {
this.classesChanged = new HashMap<>();
for (String sourcePath : commandParams.sourcesChanged) {
String className = getClassName(sourcePath);
if (className != null) {
this.classesChanged.put(className, sourcePath);
}
}
}
if (hotswap) {
final Map<Class<?>, byte[]> reloadMap = new HashMap<>();
ResourceClassLoader previousResourceClassLoader = ResourceClassLoader.class.cast(applicationClassLoader);
ConcurrentHashMap<String, ResourceEntry> previousResourceEntries = previousResourceClassLoader.getResourceEntries();
previousResourceEntries.entrySet().stream().filter(e -> classesChanged.containsKey(e.getKey())).forEach(e -> {
Class clazz = previousResourceClassLoader.reloadResourceEntry(e.getKey(), classesChanged.get(e.getKey()), e.getValue());
reloadMap.put(clazz, e.getValue().binaryContent);
});
// Update application classloader
HotSwapHelper.hotswap(reloadMap);
newContext.setClassLoader(applicationClassLoader);
ProgressTracker tracker = newContext.getTransientAppMetaData(ExtendedDeploymentContext.TRACKER, ProgressTracker.class);
try {
// Reload application metadata
reloadApplicationMetaData(newContext);
// Reload application engines
applicationInfo.reload(newContext, tracker);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return false;
} else {
if (this.applicationInfo != null) {
this.previousClassLoaders = getClassLoaders(this.applicationInfo);
}
newContext.getAppProps().putAll(this.deploymentContext.getAppProps());
newContext.getModulePropsMap().putAll(this.deploymentContext.getModulePropsMap());
this.deploymentContext = newContext;
Set<Class> requiredMetaDataClasses = requiredMetaDataClasses();
this.modulesMetaData.values().stream().filter(md -> !requiredMetaDataClasses.contains(md.getClass())).forEach(newContext::addModuleMetaData);
this.getDescriptorMetadata().entrySet().forEach(e -> newContext.addTransientAppMetaData(e.getKey(), e.getValue()));
if (applicationClassLoader != null && applicationClassLoader instanceof ResourceClassLoader) {
ClassLoader newClassLoader = newContext.getArchiveHandler().getClassLoader(applicationClassLoader.getParent(), newContext);
ResourceClassLoader newResourceClassLoader = ResourceClassLoader.class.cast(newClassLoader);
ResourceClassLoader previousResourceClassLoader = ResourceClassLoader.class.cast(applicationClassLoader);
ConcurrentHashMap<String, ResourceEntry> previousResourceEntries = previousResourceClassLoader.getResourceEntries();
previousResourceEntries.entrySet().stream().filter(e -> !classesChanged.containsKey(e.getKey())).forEach(e -> newResourceClassLoader.addResourceEntry(e.getKey(), classesChanged.get(e.getKey()), e.getValue()));
newContext.setClassLoader(newClassLoader);
if (this.applicationInfo != null) {
// unload previous app
events.send(new EventListener.Event<>(Deployment.APPLICATION_UNLOADED, this.applicationInfo), false);
}
}
}
return true;
}
Aggregations