Search in sources :

Example 96 with ActionReport

use of org.glassfish.api.ActionReport 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;
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) Deployment(org.glassfish.internal.deployment.Deployment) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) File(java.io.File) PropertyVetoException(java.beans.PropertyVetoException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) CreateException(javax.ejb.CreateException)

Example 97 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class CreateJdbcConnectionPool method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    HashMap attrList = new HashMap();
    attrList.put(ResourceConstants.CONNECTION_POOL_NAME, jdbc_connection_pool_id);
    attrList.put(ResourceConstants.DATASOURCE_CLASS, datasourceclassname);
    attrList.put(ServerTags.DESCRIPTION, description);
    attrList.put(ResourceConstants.RES_TYPE, restype);
    attrList.put(ResourceConstants.STEADY_POOL_SIZE, steadypoolsize);
    attrList.put(ResourceConstants.MAX_POOL_SIZE, maxpoolsize);
    attrList.put(ResourceConstants.MAX_WAIT_TIME_IN_MILLIS, maxwait);
    attrList.put(ResourceConstants.POOL_SIZE_QUANTITY, poolresize);
    attrList.put(ResourceConstants.INIT_SQL, initsql);
    attrList.put(ResourceConstants.IDLE_TIME_OUT_IN_SECONDS, idletimeout);
    attrList.put(ResourceConstants.TRANS_ISOLATION_LEVEL, isolationlevel);
    attrList.put(ResourceConstants.IS_ISOLATION_LEVEL_GUARANTEED, isisolationguaranteed.toString());
    attrList.put(ResourceConstants.IS_CONNECTION_VALIDATION_REQUIRED, isconnectvalidatereq.toString());
    attrList.put(ResourceConstants.CONNECTION_VALIDATION_METHOD, validationmethod);
    attrList.put(ResourceConstants.VALIDATION_TABLE_NAME, validationtable);
    attrList.put(ResourceConstants.CONN_FAIL_ALL_CONNECTIONS, failconnection.toString());
    attrList.put(ResourceConstants.NON_TRANSACTIONAL_CONNECTIONS, nontransactionalconnections.toString());
    attrList.put(ResourceConstants.ALLOW_NON_COMPONENT_CALLERS, allownoncomponentcallers.toString());
    attrList.put(ResourceConstants.VALIDATE_ATMOST_ONCE_PERIOD_IN_SECONDS, validateatmostonceperiod);
    attrList.put(ResourceConstants.CONNECTION_LEAK_TIMEOUT_IN_SECONDS, leaktimeout);
    attrList.put(ResourceConstants.CONNECTION_LEAK_RECLAIM, leakreclaim.toString());
    attrList.put(ResourceConstants.CONNECTION_CREATION_RETRY_ATTEMPTS, creationretryattempts);
    attrList.put(ResourceConstants.CONNECTION_CREATION_RETRY_INTERVAL_IN_SECONDS, creationretryinterval);
    attrList.put(ResourceConstants.DRIVER_CLASSNAME, driverclassname);
    attrList.put(ResourceConstants.SQL_TRACE_LISTENERS, sqltracelisteners);
    attrList.put(ResourceConstants.STATEMENT_TIMEOUT_IN_SECONDS, statementtimeout);
    attrList.put(ResourceConstants.STATEMENT_LEAK_TIMEOUT_IN_SECONDS, statementLeaktimeout);
    attrList.put(ResourceConstants.STATEMENT_LEAK_RECLAIM, statementLeakreclaim.toString());
    attrList.put(ResourceConstants.STATEMENT_CACHE_SIZE, statementcachesize);
    attrList.put(ResourceConstants.LAZY_CONNECTION_ASSOCIATION, lazyconnectionassociation.toString());
    attrList.put(ResourceConstants.LAZY_CONNECTION_ENLISTMENT, lazyconnectionenlistment.toString());
    attrList.put(ResourceConstants.ASSOCIATE_WITH_THREAD, associatewiththread.toString());
    attrList.put(ResourceConstants.MATCH_CONNECTIONS, matchconnections.toString());
    attrList.put(ResourceConstants.MAX_CONNECTION_USAGE_COUNT, maxconnectionusagecount);
    attrList.put(ResourceConstants.PING, ping.toString());
    attrList.put(ResourceConstants.POOLING, pooling.toString());
    attrList.put(ResourceConstants.VALIDATION_CLASSNAME, validationclassname);
    attrList.put(ResourceConstants.WRAP_JDBC_OBJECTS, wrapjdbcobjects.toString());
    ResourceStatus rs;
    try {
        JDBCConnectionPoolManager connPoolMgr = new JDBCConnectionPoolManager();
        rs = connPoolMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception e) {
        String actual = e.getMessage();
        String def = "JDBC connection pool: {0} could not be created, reason: {1}";
        report.setMessage(localStrings.getLocalString("create.jdbc.connection.pool.fail", def, jdbc_connection_pool_id, actual));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    if (rs.getMessage() != null) {
        report.setMessage(rs.getMessage());
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    if (rs.getStatus() == ResourceStatus.FAILURE) {
        ec = ActionReport.ExitCode.FAILURE;
        if (rs.getMessage() == null) {
            report.setMessage(localStrings.getLocalString("create.jdbc.connection.pool.fail", "JDBC connection pool {0} creation failed", jdbc_connection_pool_id, ""));
        }
        if (rs.getException() != null)
            report.setFailureCause(rs.getException());
    } else {
        // TODO only for DAS
        if ("true".equalsIgnoreCase(ping.toString())) {
            ActionReport subReport = report.addSubActionsReport();
            ParameterMap parameters = new ParameterMap();
            parameters.set("pool_name", jdbc_connection_pool_id);
            commandRunner.getCommandInvocation("ping-connection-pool", subReport, context.getSubject()).parameters(parameters).execute();
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                subReport.setMessage(localStrings.getLocalString("ping.create.jdbc.connection.pool.fail", "\nAttempting to ping during JDBC Connection Pool " + "Creation : {0} - Failed.", jdbc_connection_pool_id));
                subReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            } else {
                subReport.setMessage(localStrings.getLocalString("ping.create.jdbc.connection.pool.success", "\nAttempting to ping during JDBC Connection Pool " + "Creation : {0} - Succeeded.", jdbc_connection_pool_id));
            }
        }
    }
    report.setActionExitCode(ec);
}
Also used : HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ActionReport(org.glassfish.api.ActionReport)

Example 98 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class CreateJdbcResource method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    HashMap attrList = new HashMap();
    attrList.put(ResourceConstants.JNDI_NAME, jndiName);
    attrList.put(ResourceConstants.POOL_NAME, connectionPoolId);
    attrList.put(ServerTags.DESCRIPTION, description);
    attrList.put(ResourceConstants.ENABLED, enabled.toString());
    ResourceStatus rs;
    try {
        rs = jdbcMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("create.jdbc.resource.failed", "JDBC resource {0} creation failed", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    if (rs.getMessage() != null) {
        report.setMessage(rs.getMessage());
    }
    if (rs.getStatus() == ResourceStatus.FAILURE) {
        ec = ActionReport.ExitCode.FAILURE;
        if (rs.getException() != null)
            report.setFailureCause(rs.getException());
    }
    report.setActionExitCode(ec);
}
Also used : HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ActionReport(org.glassfish.api.ActionReport)

Example 99 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class GetValidationTableNames method execute.

/**
 * @inheritDoc
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
        Set<String> validationTableNames = jdbcAdminService.getValidationTableNames(poolInfo);
        Properties extraProperties = new Properties();
        extraProperties.put("validationTableNames", new ArrayList(validationTableNames));
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage("_get-validation-table-names failed : " + e.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    report.setActionExitCode(ec);
}
Also used : ArrayList(java.util.ArrayList) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Example 100 with ActionReport

use of org.glassfish.api.ActionReport in project Payara by payara.

the class GetValidationClassNames method execute.

/**
 * @inheritDoc
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    try {
        Set<String> validationClassNames = jdbcAdminService.getValidationClassNames(className);
        Properties extraProperties = new Properties();
        extraProperties.put("validationClassNames", new ArrayList(validationClassNames));
        report.setExtraProperties(extraProperties);
    } catch (Exception e) {
        report.setMessage("_get-validation-class-names failed : " + e.getMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    report.setActionExitCode(ec);
}
Also used : ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties)

Aggregations

ActionReport (org.glassfish.api.ActionReport)508 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)86 Properties (java.util.Properties)83 Config (com.sun.enterprise.config.serverbeans.Config)73 PropertyVetoException (java.beans.PropertyVetoException)72 ParameterMap (org.glassfish.api.admin.ParameterMap)66 Logger (java.util.logging.Logger)56 IOException (java.io.IOException)47 ArrayList (java.util.ArrayList)47 HashMap (java.util.HashMap)43 File (java.io.File)41 CommandTarget (org.glassfish.config.support.CommandTarget)30 Target (org.glassfish.internal.api.Target)30 Map (java.util.Map)27 Server (com.sun.enterprise.config.serverbeans.Server)25 List (java.util.List)25 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)24 CommandRunner (org.glassfish.api.admin.CommandRunner)23 ExtendedDeploymentContext (org.glassfish.internal.deployment.ExtendedDeploymentContext)23 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)19