Search in sources :

Example 31 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class ResourceAdapterConfigManager method create.

public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
    setParams(attributes);
    ResourceStatus validationStatus = isValid(resources);
    if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
        return validationStatus;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ResourceAdapterConfig newResource = createConfigBean(param, properties);
                param.getResources().add(newResource);
                return newResource;
            }
        }, resources);
    } catch (TransactionFailure tfe) {
        Logger.getLogger(ResourceAdapterConfigManager.class.getName()).log(Level.SEVERE, "TransactionFailure: create-resource-adapter-config", tfe);
        String msg = localStrings.getLocalString("create.resource.adapter.config.fail", "Unable to create resource adapter config", raName) + " " + tfe.getLocalizedMessage();
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    String msg = localStrings.getLocalString("create.resource.adapter.config.success", "Resource adapter config {0} created successfully", raName);
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 32 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus 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 33 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class JDBCResourceManager method create.

public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
    setAttributes(attributes, target);
    ResourceStatus validationStatus = isValid(resources, true, target);
    if (validationStatus.getStatus() == ResourceStatus.FAILURE) {
        return validationStatus;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                return createResource(param, properties);
            }
        }, resources);
        resourceUtil.createResourceRef(jndiName, enabledValueForTarget, target);
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("create.jdbc.resource.fail", "JDBC resource {0} create failed ", jndiName) + " " + tfe.getLocalizedMessage();
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("create.jdbc.resource.success", "JDBC resource {0} created successfully", jndiName);
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 34 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus in project Payara by payara.

the class JDBCResourceManager method createConfigBean.

public Resource createConfigBean(final Resources resources, HashMap attributes, final Properties properties, boolean validate) throws Exception {
    setAttributes(attributes, null);
    ResourceStatus status = null;
    if (!validate) {
        status = new ResourceStatus(ResourceStatus.SUCCESS, "");
    } else {
        status = isValid(resources, false, null);
    }
    if (status.getStatus() == ResourceStatus.SUCCESS) {
        return createConfigBean(resources, properties);
    } else {
        throw new ResourceException(status.getMessage());
    }
}
Also used : ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ResourceException(javax.resource.ResourceException)

Example 35 with ResourceStatus

use of org.glassfish.resourcebase.resources.api.ResourceStatus 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
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    HashMap<String, String> 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());
    attrList.put(ResourceConstants.LOG_JDBC_CALLS, logJdbcCalls.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)

Aggregations

ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)60 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)17 HashMap (java.util.HashMap)15 ActionReport (org.glassfish.api.ActionReport)15 Resources (com.sun.enterprise.config.serverbeans.Resources)14 PropertyVetoException (java.beans.PropertyVetoException)14 ResourceException (javax.resource.ResourceException)13 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)4 Resource (com.sun.enterprise.config.serverbeans.Resource)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 ContextService (org.glassfish.concurrent.config.ContextService)2 ManagedExecutorService (org.glassfish.concurrent.config.ManagedExecutorService)2 ManagedThreadFactory (org.glassfish.concurrent.config.ManagedThreadFactory)2 JdbcResource (org.glassfish.jdbc.config.JdbcResource)2 MailResource (org.glassfish.resources.javamail.config.MailResource)2 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)1 Module (com.sun.enterprise.config.serverbeans.Module)1 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)1