use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.
the class DolProvider method processDOL.
private Application processDOL(DeploymentContext dc) throws IOException {
ReadableArchive sourceArchive = dc.getSource();
sourceArchive.setExtraData(Types.class, dc.getTransientAppMetaData(Types.class.getName(), Types.class));
sourceArchive.setExtraData(Parser.class, dc.getTransientAppMetaData(Parser.class.getName(), Parser.class));
ClassLoader cl = dc.getClassLoader();
DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
sourceArchive.addArchiveMetaData(DeploymentProperties.APP_PROPS, dc.getAppProps());
sourceArchive.addArchiveMetaData(DeploymentProperties.COMMAND_PARAMS, params);
String name = params.name();
String archiveType = dc.getArchiveHandler().getArchiveType();
Archivist archivist = archivistFactory.getArchivist(archiveType, cl);
if (archivist == null) {
// an empty Application object
return Application.createApplication();
}
archivist.setAnnotationProcessingRequested(true);
String xmlValidationLevel = dasConfig.getDeployXmlValidation();
archivist.setXMLValidationLevel(xmlValidationLevel);
if (xmlValidationLevel.equals("none")) {
archivist.setXMLValidation(false);
}
archivist.setRuntimeXMLValidationLevel(xmlValidationLevel);
if (xmlValidationLevel.equals("none")) {
archivist.setRuntimeXMLValidation(false);
}
Collection<Sniffer> sniffers = dc.getTransientAppMetaData(DeploymentProperties.SNIFFERS, Collection.class);
archivist.setExtensionArchivists(archivistFactory.getExtensionsArchivists(sniffers, archivist.getModuleType()));
ApplicationHolder holder = dc.getModuleMetaData(ApplicationHolder.class);
File deploymentPlan = params.deploymentplan;
handleDeploymentPlan(deploymentPlan, archivist, sourceArchive, holder);
long start = System.currentTimeMillis();
Application application = null;
if (holder != null) {
application = holder.app;
application.setAppName(name);
application.setClassLoader(cl);
application.setRoleMapper(null);
if (application.isVirtual()) {
ModuleDescriptor md = application.getStandaloneBundleDescriptor().getModuleDescriptor();
md.setModuleName(name);
}
try {
applicationFactory.openWith(application, sourceArchive, archivist);
} catch (SAXParseException e) {
throw new IOException(e);
}
} else {
// and it's a standalone module
try {
application = applicationFactory.openArchive(name, archivist, sourceArchive, true);
application.setAppName(name);
ModuleDescriptor md = application.getStandaloneBundleDescriptor().getModuleDescriptor();
md.setModuleName(name);
} catch (SAXParseException e) {
throw new IOException(e);
}
}
application.setRegistrationName(name);
sourceArchive.removeExtraData(Types.class);
sourceArchive.removeExtraData(Parser.class);
Logger.getAnonymousLogger().log(Level.FINE, "DOL Loading time" + (System.currentTimeMillis() - start));
return application;
}
use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.
the class EarHandler method getApplicationHolder.
private ApplicationHolder getApplicationHolder(ReadableArchive source, DeploymentContext context, boolean isDirectory) {
ApplicationHolder holder = context.getModuleMetaData(ApplicationHolder.class);
if (holder == null || holder.app == null) {
try {
DeployCommandParameters params = context.getCommandParameters(DeployCommandParameters.class);
if (params != null && params.altdd != null) {
source.addArchiveMetaData(DeploymentProperties.ALT_DD, params.altdd);
}
long start = System.currentTimeMillis();
ApplicationArchivist archivist = habitat.getService(ApplicationArchivist.class);
archivist.setAnnotationProcessingRequested(true);
String xmlValidationLevel = dasConfig.getDeployXmlValidation();
archivist.setXMLValidationLevel(xmlValidationLevel);
if (xmlValidationLevel.equals("none")) {
archivist.setXMLValidation(false);
}
holder = new ApplicationHolder(archivist.createApplication(source, isDirectory));
Boolean cdiEnabled = new GFApplicationXmlParser(source).isEnableImplicitCDI();
if (cdiEnabled != null) {
context.getAppProps().put(RuntimeTagNames.PAYARA_ENABLE_IMPLICIT_CDI, cdiEnabled.toString().toLowerCase());
}
_logger.fine("time to read application.xml " + (System.currentTimeMillis() - start));
} catch (IOException | XMLStreamException | SAXParseException e) {
throw new RuntimeException(e);
}
context.addModuleMetaData(holder);
}
if (holder.app == null) {
throw new RuntimeException(strings.get("errReadMetadata"));
}
return holder;
}
use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.
the class CreateLifecycleModuleCommand method execute.
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
try {
validateTarget(target, name);
} catch (IllegalArgumentException ie) {
report.setMessage(ie.getMessage());
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
DeployCommandParameters commandParams = new DeployCommandParameters();
commandParams.name = name;
commandParams.enabled = enabled;
commandParams.description = description;
commandParams.target = target;
// create a dummy context to hold params and props
ExtendedDeploymentContext deploymentContext = new DeploymentContextImpl(report, null, commandParams, null);
Properties appProps = deploymentContext.getAppProps();
if (property != null) {
appProps.putAll(property);
}
// set to default "user", deployers can override it
appProps.setProperty(ServerTags.OBJECT_TYPE, "user");
appProps.setProperty(ServerTags.CLASS_NAME, classname);
if (classpath != null) {
appProps.setProperty(ServerTags.CLASSPATH, classpath);
}
if (loadorder != null) {
appProps.setProperty(ServerTags.LOAD_ORDER, loadorder);
}
appProps.setProperty(ServerTags.IS_FAILURE_FATAL, failurefatal.toString());
appProps.setProperty(ServerTags.IS_LIFECYCLE, "true");
try {
Transaction t = deployment.prepareAppConfigChanges(deploymentContext);
deployment.registerAppInDomainXML(null, deploymentContext, t);
} catch (Exception e) {
report.setMessage("Failed to create lifecycle module: " + e);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.
the class InstanceLifecycleModuleCommand method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
try {
Application application = applications.getApplication(name);
Transaction t = new Transaction();
// create a dummy context to hold params and props
DeployCommandParameters commandParams = new DeployCommandParameters();
commandParams.name = name;
commandParams.target = target;
commandParams.enabled = enabled;
commandParams.virtualservers = virtualservers;
ExtendedDeploymentContext lifecycleContext = new DeploymentContextImpl(report, null, commandParams, null);
lifecycleContext.getAppProps().putAll(appprops);
if (application != null) {
// application element already been synchronized over
// just write application-ref
deployment.registerAppInDomainXML(null, lifecycleContext, t, true);
} else {
// write both
t = deployment.prepareAppConfigChanges(lifecycleContext);
deployment.registerAppInDomainXML(null, lifecycleContext, t);
}
} catch (Exception e) {
report.failure(logger, e.getMessage());
}
}
use of org.glassfish.api.deployment.DeployCommandParameters 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();
}
}
Aggregations