Search in sources :

Example 21 with ResourceStatus

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

the class ConnectorWorkSecurityMapResourceManager method createConfigBean.

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

Example 22 with ResourceStatus

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

the class CreateConnectorConnectionPool 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.RES_ADAPTER_NAME, raname);
    attrList.put(ResourceConstants.CONN_DEF_NAME, connectiondefinition);
    attrList.put(ServerTags.DESCRIPTION, description);
    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.IDLE_TIME_OUT_IN_SECONDS, idletimeout);
    attrList.put(ResourceConstants.IS_CONNECTION_VALIDATION_REQUIRED, isconnectvalidatereq.toString());
    attrList.put(ResourceConstants.CONN_FAIL_ALL_CONNECTIONS, failconnection.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.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.CONNECTOR_CONNECTION_POOL_NAME, poolname);
    attrList.put(ResourceConstants.CONN_TRANSACTION_SUPPORT, transactionsupport);
    attrList.put(ResourceConstants.PING, ping.toString());
    attrList.put(ResourceConstants.POOLING, pooling.toString());
    ResourceStatus rs;
    try {
        ConnectorConnectionPoolManager connPoolMgr = connectorConnectionPoolManagerProvider.get();
        rs = connPoolMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception e) {
        Logger.getLogger(CreateConnectorConnectionPool.class.getName()).log(Level.SEVERE, "Unable to create connector connection pool " + poolname, e);
        String def = "Connector connection pool: {0} could not be created, reason: {1}";
        report.setMessage(localStrings.getLocalString("create.connector.connection.pool.fail", def, poolname) + " " + e.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    if (rs.getStatus() == ResourceStatus.FAILURE) {
        ec = ActionReport.ExitCode.FAILURE;
        if (rs.getMessage() != null) {
            report.setMessage(rs.getMessage());
        } else {
            report.setMessage(localStrings.getLocalString("create.connector.connection.pool.fail", "Connector connection pool {0} creation failed.", poolname));
        }
        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", poolname);
            commandRunner.getCommandInvocation("ping-connection-pool", subReport, context.getSubject()).parameters(parameters).execute();
            if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
                subReport.setMessage(localStrings.getLocalString("ping.create.connector.connection.pool.fail", "\nAttempting to ping during Connector Connection " + "Pool Creation : {0} - Failed.", poolname));
                subReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
            } else {
                subReport.setMessage(localStrings.getLocalString("ping.create.connector.connection.pool.success", "\nAttempting to ping during Connector Connection " + "Pool Creation : {0} - Succeeded.", poolname));
            }
        }
    }
    if (rs.getMessage() != null) {
        report.setMessage(rs.getMessage());
    }
    report.setActionExitCode(ec);
}
Also used : HashMap(java.util.HashMap) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ActionReport(org.glassfish.api.ActionReport)

Example 23 with ResourceStatus

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

the class CreateResourceAdapterConfig 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(RESOURCE_ADAPTER_CONFIG_NAME, raName);
    // attrList.put("name", name);
    attrList.put(THREAD_POOL_IDS, threadPoolIds);
    attrList.put(ServerTags.OBJECT_TYPE, objectType);
    ResourceStatus rs;
    // TODO ASR : need similar validation while creating app-scoped-resource of resource-adapter-config
    String appName = raName;
    if (!ConnectorsUtil.isStandAloneRA(raName)) {
        appName = ConnectorsUtil.getApplicationNameOfEmbeddedRar(raName);
        Application application = applications.getApplication(appName);
        if (application != null) {
            // embedded RAR
            String resourceAdapterName = ConnectorsUtil.getRarNameFromApplication(raName);
            Module module = application.getModule(resourceAdapterName);
            if (module != null) {
                Resources msr = module.getResources();
                if (msr != null) {
                    if (hasDuplicate(msr, report))
                        return;
                }
            }
        }
    } else {
        // standalone RAR
        Application application = applications.getApplication(appName);
        if (application != null) {
            Resources appScopedResources = application.getResources();
            if (appScopedResources != null) {
                if (hasDuplicate(appScopedResources, report))
                    return;
            }
        }
    }
    ResourceAdapterConfigManager resAdapterConfigMgr = new ResourceAdapterConfigManager();
    try {
        rs = resAdapterConfigMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception ex) {
        Logger.getLogger(CreateResourceAdapterConfig.class.getName()).log(Level.SEVERE, "Unable to create resource adapter config for " + raName, ex);
        String def = "Resource adapter config: {0} could not be created, reason: {1}";
        report.setMessage(localStrings.getLocalString("create.resource.adapter.config.fail", def, raName) + " " + ex.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(ex);
        return;
    }
    ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
    if (rs.getStatus() == ResourceStatus.FAILURE) {
        ec = ActionReport.ExitCode.FAILURE;
        if (rs.getMessage() != null) {
            report.setMessage(rs.getMessage());
        } else {
            report.setMessage(localStrings.getLocalString("create.resource.adapter.config.fail", "Resource adapter config {0} creation failed", raName, ""));
        }
        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) Module(com.sun.enterprise.config.serverbeans.Module)

Example 24 with ResourceStatus

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

the class ConnectorConnectionPoolManager method validateConnectorConnPoolAttributes.

private ResourceStatus validateConnectorConnPoolAttributes(String raName, String connDef) throws ConnectorRuntimeException {
    ResourceStatus status = isValidRAName(raName);
    if (status.getStatus() == ResourceStatus.SUCCESS) {
        if (!isValidConnectionDefinition(connDef, raName)) {
            String msg = localStrings.getLocalString("admin.mbeans.rmb.invalid_ra_connectdef_not_found", "Invalid connection definition. Connector Module with connection definition {0} not found.", connDef);
            status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
    }
    return status;
}
Also used : ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus)

Example 25 with ResourceStatus

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

the class ConnectorConnectionPoolManager method create.

public ResourceStatus create(Resources resources, HashMap attributes, final Properties properties, String target) throws Exception {
    setParams(attributes);
    ResourceStatus validationStatus = isValid(resources, true);
    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);
    } catch (TransactionFailure tfe) {
        Logger.getLogger(ConnectorConnectionPoolManager.class.getName()).log(Level.SEVERE, "create-connector-connection-pool failed", tfe);
        String msg = localStrings.getLocalString("create.connector.connection.pool.fail", "Connector connection pool {0} create failed: {1}", poolname) + " " + tfe.getLocalizedMessage();
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    String msg = localStrings.getLocalString("create.connector.connection.pool.success", "Connector connection pool {0} created successfully", poolname);
    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)

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