use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.
the class MTProvisionCommand method execute.
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
final Logger logger = context.getLogger();
if (app == null) {
report.setMessage("Application " + appname + " needs to be deployed first before provisioned to tenant");
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
ReadableArchive archive = null;
DeployCommandParameters commandParams = app.getDeployParameters(appRef);
commandParams.contextroot = contextroot;
commandParams.target = DeploymentUtils.DAS_TARGET_NAME;
commandParams.name = DeploymentUtils.getInternalNameForTenant(appname, tenant);
commandParams.enabled = Boolean.TRUE;
commandParams.origin = DeployCommandParameters.Origin.mt_provision;
try {
URI uri = new URI(app.getLocation());
File file = new File(uri);
if (!file.exists()) {
throw new Exception(localStrings.getLocalString("fnf", "File not found", file.getAbsolutePath()));
}
archive = archiveFactory.openArchive(file);
ExtendedDeploymentContext deploymentContext = deployment.getBuilder(logger, commandParams, report).source(archive).build();
Properties appProps = deploymentContext.getAppProps();
appProps.putAll(app.getDeployProperties());
// app props so we also need to override that
if (contextroot != null) {
appProps.setProperty(ServerTags.CONTEXT_ROOT, contextroot);
}
deploymentContext.setModulePropsMap(app.getModulePropertiesMap());
deploymentContext.setTenant(tenant, appname);
expandCustomizationJar(deploymentContext.getTenantDir());
deployment.deploy(deploymentContext);
deployment.registerTenantWithAppInDomainXML(appname, deploymentContext);
} catch (Throwable e) {
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
report.setFailureCause(e);
} finally {
try {
if (archive != null) {
archive.close();
}
} catch (IOException e) {
// ignore
}
}
}
use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.
the class MEJBNamingObjectProxy method deployMEJB.
private void deployMEJB() throws IOException {
_logger.info("Loading MEJB app on JNDI look up");
ServerContext serverContext = habitat.getService(ServerContext.class);
File mejbArchive = new File(serverContext.getInstallRoot(), "lib/install/applications/mejb.jar");
DeployCommandParameters deployParams = new DeployCommandParameters(mejbArchive);
String targetName = habitat.<Server>getService(Server.class, ServerEnvironment.DEFAULT_INSTANCE_NAME).getName();
deployParams.target = targetName;
deployParams.name = "mejb";
ActionReport report = habitat.getService(ActionReport.class, "plain");
Deployment deployment = habitat.getService(Deployment.class);
ExtendedDeploymentContext dc = deployment.getBuilder(_logger, deployParams, report).source(mejbArchive).build();
deployment.deploy(dc);
if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) {
throw new RuntimeException("Failed to deploy MEJB app: " + report.getFailureCause());
}
}
use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.
the class JPADeployer method createEMFs.
/**
* CreateEMFs and save them in persistence
* @param context
*/
private void createEMFs(DeploymentContext context) {
Application application = context.getModuleMetaData(Application.class);
Set<BundleDescriptor> bundles = application.getBundleDescriptors();
// Iterate through all the bundles for the app and collect pu references in referencedPus
boolean hasScopedResource = false;
final List<PersistenceUnitDescriptor> referencedPus = new ArrayList<PersistenceUnitDescriptor>();
for (BundleDescriptor bundle : bundles) {
Collection<? extends PersistenceUnitDescriptor> pusReferencedFromBundle = bundle.findReferencedPUs();
for (PersistenceUnitDescriptor pud : pusReferencedFromBundle) {
referencedPus.add(pud);
if (hasScopedResource(pud)) {
hasScopedResource = true;
}
}
}
if (hasScopedResource) {
// Scoped resources are registered by connector runtime after prepare(). That is too late for JPA
// This is a hack to initialize connectorRuntime for scoped resources
connectorRuntime.registerDataSourceDefinitions(application);
}
// Iterate through all the PUDs for this bundle and if it is referenced, load the corresponding pu
PersistenceUnitDescriptorIterator pudIterator = new PersistenceUnitDescriptorIterator() {
@Override
void visitPUD(PersistenceUnitDescriptor pud, DeploymentContext context) {
if (referencedPus.contains(pud)) {
boolean isDas = isDas();
if (isDas && !isTargetDas(context.getCommandParameters(DeployCommandParameters.class))) {
DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
// If on DAS and not generating schema for remotes then return here
String jpaScemaGeneration = pud.getProperties().getProperty("javax.persistence.schema-generation.database.action", "none").toLowerCase();
String eclipselinkSchemaGeneration = pud.getProperties().getProperty("eclipselink.ddl-generation", "none").toLowerCase();
if ("none".equals(jpaScemaGeneration) && "none".equals(eclipselinkSchemaGeneration)) {
return;
} else {
InternalSystemAdministrator kernelIdentity = Globals.getDefaultHabitat().getService(InternalSystemAdministrator.class);
CommandRunner commandRunner = Globals.getDefaultHabitat().getService(CommandRunner.class);
CommandRunner.CommandInvocation getTranslatedValueCommand = commandRunner.getCommandInvocation("_get-translated-config-value", new PlainTextActionReporter(), kernelIdentity.getSubject());
ParameterMap params = new ParameterMap();
params.add("propertyName", pud.getJtaDataSource());
params.add("target", deployParams.target);
getTranslatedValueCommand.parameters(params);
getTranslatedValueCommand.execute();
ActionReport report = getTranslatedValueCommand.report();
if (report.hasSuccesses() && report.getSubActionsReport().size() == 1) {
ActionReport subReport = report.getSubActionsReport().get(0);
String value = subReport.getMessage().replace(deployParams.target + ":", "");
pud.setJtaDataSource(value.trim());
} else {
logger.log(Level.SEVERE, report.getMessage(), report.getFailureCause());
}
}
}
// While running in embedded mode, it is not possible to guarantee that entity classes are not loaded by the app classloader before transformers are installed
// If that happens, weaving will not take place and EclipseLink will throw up. Provide users an option to disable weaving by passing the flag.
// Note that we enable weaving if not explicitly disabled by user
boolean weavingEnabled = Boolean.valueOf(sc.getArguments().getProperty("org.glassfish.persistence.embedded.weaving.enabled", "true"));
ProviderContainerContractInfo providerContainerContractInfo = weavingEnabled ? new ServerProviderContainerContractInfo(context, connectorRuntime, isDas) : new EmbeddedProviderContainerContractInfo(context, connectorRuntime, isDas);
try {
((ExtendedDeploymentContext) context).prepareScratchDirs();
} catch (IOException e) {
// There is no way to recover if we are not able to create the scratch dirs. Just rethrow the exception.
throw new RuntimeException(e);
}
try {
PersistenceUnitLoader puLoader = new PersistenceUnitLoader(pud, providerContainerContractInfo);
// Store the puLoader in context. It is retrieved to execute java2db and to
// store the loaded emfs in a JPAApplicationContainer object for cleanup
context.addTransientAppMetaData(getUniquePuIdentifier(pud), puLoader);
} catch (Exception e) {
DeployCommandParameters dcp = context.getCommandParameters(DeployCommandParameters.class);
if (dcp.isSkipDSFailure() && ExceptionUtil.isDSFailure(e)) {
logger.log(Level.WARNING, "Resource communication failure exception skipped while loading the pu " + pud.getName(), e);
} else {
if (e.getCause() instanceof ConnectorRuntimeException) {
logger.log(Level.SEVERE, "{0} is not a valid data source. If you are using variable replacement then" + "ensure that is available on the DAS.");
}
throw e;
}
}
}
}
};
pudIterator.iteratePUDs(context);
}
use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.
the class JPADeployer method event.
@Override
public void event(Event event) {
if (logger.isLoggable(Level.FINEST)) {
logger.finest("JpaDeployer.event():" + event.name());
}
if (event.is(Deployment.APPLICATION_PREPARED)) {
ExtendedDeploymentContext context = (ExtendedDeploymentContext) event.hook();
DeployCommandParameters deployCommandParameters = context.getCommandParameters(DeployCommandParameters.class);
if (logger.isLoggable(Level.FINE)) {
logger.fine("JpaDeployer.event(): Handling APPLICATION_PREPARED origin is:" + deployCommandParameters.origin);
}
// an application-ref is being created on DAS. Process the app
if (!deployCommandParameters.origin.isCreateAppRef() || isTargetDas(deployCommandParameters)) {
Map<String, ExtendedDeploymentContext> deploymentContexts = context.getModuleDeploymentContexts();
for (DeploymentContext deploymentContext : deploymentContexts.values()) {
// bundle level pus
iterateInitializedPUsAtApplicationPrepare(deploymentContext);
}
// app level pus
iterateInitializedPUsAtApplicationPrepare(context);
}
} else if (event.is(Deployment.APPLICATION_DISABLED)) {
logger.fine("JpaDeployer.event(): APPLICATION_DISABLED");
// APPLICATION_DISABLED will be generated when an app is disabled/undeployed/appserver goes down.
// close all the emfs created for this app
ApplicationInfo appInfo = (ApplicationInfo) event.hook();
closeEMFs(appInfo);
}
}
use of org.glassfish.api.deployment.DeployCommandParameters in project Payara by payara.
the class JPADeployer method isEMFCreationRequired.
/**
* @param context
* @return true if emf creation is required false otherwise
*/
private boolean isEMFCreationRequired(DeploymentContext context) {
/*
Here are various use cases that needs to be handled.
This method handles EMF creation part, APPLICATION_PREPARED event handle handles java2db and closing of emf
To summarize,
-Unconditionally create EMFs on DAS for java2db if it is deploy. We will close this EMF in APPLICATION_PREPARED after java2db if (target!= DAS || enable=false)
-We will not create EMFs on instance if application is not enabled
------------------------------------------------------------------------------------
Scenario Expected Behavior
------------------------------------------------------------------------------------
deploy --target=server --enabled=true. DAS(EMF created, java2db, EMF remains open)
-restart DAS(EMF created, EMF remains open)
-undeploy DAS(EMF closed. Drop tables)
-create-application-ref instance1 DAS(No action)
INSTANCE1(EMF created)
deploy --target=server --enabled=false. DAS(EMF created,java2db, EMF closed in APPLICATION_PREPARED)
-restart DAS(No EMF created)
-undeploy DAS(No EMF to close, Drop tables)
-enable DAS(EMF created)
-undelpoy DAS(EMF closed, Drop tables)
-create-application-ref instance1 DAS(No action)
INSTANCE1(EMF created)
deploy --target=instance1 --enabled=true DAS(EMF created, java2db, EMF closed in APPLICATION_PREPARED)
INSTANCE1(EMF created)
-create-application-ref instance2 INSTANCE2(EMF created)
-restart DAS(No EMF created)
INSTANCE1(EMF created)
INSTANCE2(EMF created)
-undeploy DAS(No EMF to close, Drop tables)
INSTANCE1(EMF closed)
-create-application-ref server DAS(EMF created)
-delete-application-ref server DAS(EMF closed)
undeploy INSTANCE1(EMF closed)
deploy --target=instance --enabled=false. DAS(EMF created, java2db, EMF closed in APPLICATION_PREPARED)
INSTANCE1(No EMF created)
-create-application-ref instance2 DAS(No action)
INSTANCE2(No Action)
-restart DAS(No EMF created)
INSTANCE1(No EMF created)
INSTANCE2(No EMF created)
-undeploy DAS(No EMF to close, Drop tables)
INSTANCE1(No EMF to close)
INSTANCE2(No EMF to close)
-enable --target=instance1 DAS(No EMF created)
INSTANCE1(EMF created)
*/
boolean createEMFs = false;
DeployCommandParameters deployCommandParameters = context.getCommandParameters(DeployCommandParameters.class);
boolean deploy = deployCommandParameters.origin.isDeploy();
boolean enabled = deployCommandParameters.enabled;
boolean isDas = isDas();
if (logger.isLoggable(Level.FINER)) {
logger.finer("isEMFCreationRequired(): deploy: " + deploy + " enabled: " + enabled + " isDas: " + isDas);
}
if (isDas) {
if (deploy) {
// Always create emfs on DAS while deploying to take care of java2db and PU validation on deploy
createEMFs = true;
} else {
// We reach here for (!deploy && das) => server restart or enabling a disabled app on DAS
boolean isTargetDas = isTargetDas(deployCommandParameters);
if (logger.isLoggable(Level.FINER)) {
logger.finer("isEMFCreationRequired(): isTargetDas: " + isTargetDas);
}
if (enabled && isTargetDas) {
createEMFs = true;
}
}
} else {
// !das => on an instance
if (enabled) {
createEMFs = true;
}
}
if (logger.isLoggable(Level.FINER)) {
logger.finer("isEMFCreationRequired(): returning createEMFs:" + createEMFs);
}
return createEMFs;
}
Aggregations