Search in sources :

Example 6 with PlainTextActionReporter

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);
}
Also used : ActionReport(org.glassfish.api.ActionReport) PlainTextActionReporter(com.sun.enterprise.admin.report.PlainTextActionReporter) Test(org.junit.Test)

Example 7 with PlainTextActionReporter

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);
}
Also used : ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) CommandRunner(org.glassfish.api.admin.CommandRunner) PlainTextActionReporter(com.sun.enterprise.admin.report.PlainTextActionReporter) InternalSystemAdministrator(org.glassfish.internal.api.InternalSystemAdministrator) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ParameterMap(org.glassfish.api.admin.ParameterMap) IOException(java.io.IOException) CommandException(org.glassfish.api.admin.CommandException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) IOException(java.io.IOException) PersistenceException(javax.persistence.PersistenceException) DeploymentException(org.glassfish.deployment.common.DeploymentException) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) DeploymentContext(org.glassfish.api.deployment.DeploymentContext) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext)

Example 8 with PlainTextActionReporter

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);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) EmbeddedSystemAdministrator(org.glassfish.internal.api.EmbeddedSystemAdministrator) InserverCommandRunnerHelper(com.sun.enterprise.v3.admin.InserverCommandRunnerHelper) ParameterMap(org.glassfish.api.admin.ParameterMap) ActionReport(org.glassfish.api.ActionReport) PlainTextActionReporter(com.sun.enterprise.admin.report.PlainTextActionReporter)

Example 9 with PlainTextActionReporter

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);
}
Also used : ActionReport(org.glassfish.api.ActionReport) PlainTextActionReporter(com.sun.enterprise.admin.report.PlainTextActionReporter) Test(org.junit.Test)

Example 10 with PlainTextActionReporter

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");
        }
    }
}
Also used : PlainTextActionReporter(com.sun.enterprise.admin.report.PlainTextActionReporter)

Aggregations

PlainTextActionReporter (com.sun.enterprise.admin.report.PlainTextActionReporter)14 ActionReport (org.glassfish.api.ActionReport)11 Test (org.junit.Test)6 IOException (java.io.IOException)3 ParameterMap (org.glassfish.api.admin.ParameterMap)3 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)3 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)3 File (java.io.File)2 AdminCommandContext (org.glassfish.api.admin.AdminCommandContext)2 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 ActionReporter (com.sun.enterprise.admin.report.ActionReporter)1 ApplicationRef (com.sun.enterprise.config.serverbeans.ApplicationRef)1 Applications (com.sun.enterprise.config.serverbeans.Applications)1 ArchiveFactory (com.sun.enterprise.deploy.shared.ArchiveFactory)1 Application (com.sun.enterprise.deployment.Application)1 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)1 InserverCommandRunnerHelper (com.sun.enterprise.v3.admin.InserverCommandRunnerHelper)1 RestartDomainCommand (com.sun.enterprise.v3.admin.RestartDomainCommand)1 PropertyVetoException (java.beans.PropertyVetoException)1