use of com.sun.enterprise.admin.report.PlainTextActionReporter in project Payara by payara.
the class PlainTextActionReporterTest method babyTest.
@Test
public void babyTest() throws Exception {
ActionReport report = new PlainTextActionReporter();
report.setActionDescription("My Action Description");
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ActionReport.MessagePart top = report.getTopMessagePart();
top.setMessage("BabyTest Message Here!!");
report.writeReport(System.out);
}
use of com.sun.enterprise.admin.report.PlainTextActionReporter 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 com.sun.enterprise.admin.report.PlainTextActionReporter in project Payara by payara.
the class RealmUtil method createAuthRealm.
static void createAuthRealm(String name, String realmClass, String loginModule, Properties props) {
ServiceLocator serviceLocator = Globals.getDefaultHabitat();
InserverCommandRunnerHelper commandRunnerHelper = serviceLocator.getService(InserverCommandRunnerHelper.class);
EmbeddedSystemAdministrator administrator = serviceLocator.getService(EmbeddedSystemAdministrator.class);
ParameterMap parameters = new ParameterMap();
parameters.insert("authrealmname", name);
parameters.insert("property", props.entrySet().stream().map(prop -> escapeRealmProperty(prop.getKey().toString()) + '=' + escapeRealmProperty(prop.getValue().toString())).collect(joining(":")));
parameters.insert("classname", realmClass);
if (loginModule != null) {
parameters.insert("login-module", loginModule);
}
ActionReport report = new PlainTextActionReporter();
ActionReport outreport = commandRunnerHelper.runCommand("create-auth-realm", parameters, report, administrator.getSubject());
if (outreport.getActionExitCode() == ActionReport.ExitCode.FAILURE) {
throw new IllegalStateException("Error in creating Auth realm: " + name);
}
}
use of com.sun.enterprise.admin.report.PlainTextActionReporter in project Payara by payara.
the class PlainTextActionReporterTest method papaTest.
@Test
public void papaTest() throws Exception {
ActionReport report = new PlainTextActionReporter();
report.setActionDescription("My Action Description");
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
ActionReport.MessagePart top = report.getTopMessagePart();
top.setMessage("Papa Test Top Message");
top.setChildrenType("Module");
for (int i = 0; i < 8; i++) {
ActionReport.MessagePart childPart = top.addChild();
childPart.setMessage("child" + i + " Message here");
childPart.addProperty("ChildKey" + i, "ChildValue" + i);
childPart.addProperty("AnotherChildKey" + i, "AnotherChildValue" + i);
for (int j = 0; j < 3; j++) {
ActionReport.MessagePart grandkids = childPart.addChild();
grandkids.setMessage("Grand Kid#" + j + " from child#" + i + " Top Message");
grandkids.addProperty("Grand Kid#" + j + " from child#" + i + "key", "value");
}
}
report.writeReport(System.out);
}
use of com.sun.enterprise.admin.report.PlainTextActionReporter in project Payara by payara.
the class CommandResource method fixActionReporterSpecialCases.
/**
* Some ActionReporters has special logic which must be reflected here
*/
private void fixActionReporterSpecialCases(ActionReporter ar) {
if (ar == null) {
return;
}
if (ar instanceof PlainTextActionReporter) {
PlainTextActionReporter par = (PlainTextActionReporter) ar;
StringBuilder finalOutput = new StringBuilder();
par.getCombinedMessages(par, finalOutput);
String outs = finalOutput.toString();
if (!StringUtils.ok(outs)) {
par.getTopMessagePart().setMessage(strings.getLocalString("get.mon.no.data", "No monitoring data to report.") + "\n");
}
}
}
Aggregations