Search in sources :

Example 36 with ResourceStatus

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

the class JDBCConnectionPoolManager method create.

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

            @Override
            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                return createResource(param, properties);
            }
        }, resources);
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("create.jdbc.connection.pool.fail", "JDBC connection pool {0} create failed: {1}", jdbcconnectionpoolid, tfe.getMessage());
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    String msg = localStrings.getLocalString("create.jdbc.connection.pool.success", "JDBC connection pool {0} created successfully", jdbcconnectionpoolid);
    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)

Example 37 with ResourceStatus

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

the class ResourceAdapterConfigManager method createConfigBean.

public Resource createConfigBean(Resources resources, HashMap attributes, Properties properties, boolean validate) throws Exception {
    setParams(attributes);
    ResourceStatus status = null;
    if (!validate) {
        status = new ResourceStatus(ResourceStatus.SUCCESS, "");
    } else {
        status = isValid(resources);
    }
    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 38 with ResourceStatus

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

the class CreateAdminObject 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(RES_TYPE, resType);
    attrList.put(ADMIN_OBJECT_CLASS_NAME, className);
    attrList.put(ResourceConstants.ENABLED, enabled.toString());
    attrList.put(JNDI_NAME, jndiName);
    attrList.put(ServerTags.DESCRIPTION, description);
    attrList.put(RES_ADAPTER, raName);
    ResourceStatus rs;
    try {
        AdminObjectManager adminObjMgr = adminObjectManagerProvider.get();
        rs = adminObjMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception e) {
        Logger.getLogger(CreateAdminObject.class.getName()).log(Level.SEVERE, "Something went wrong in create-admin-object", e);
        String def = "Admin object: {0} could not be created, reason: {1}";
        report.setMessage(localStrings.getLocalString("create.admin.object.fail", def, jndiName) + " " + e.getLocalizedMessage());
        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.getMessage() == null) {
            report.setMessage(localStrings.getLocalString("create.admin.object.fail", "Admin object {0} creation failed", jndiName, ""));
        }
        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 39 with ResourceStatus

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

the class CreateConnectorResource 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(POOL_NAME, poolName);
    attrList.put(ResourceConstants.ENABLED, enabled.toString());
    attrList.put(JNDI_NAME, jndiName);
    attrList.put(ServerTags.DESCRIPTION, description);
    attrList.put(ServerTags.OBJECT_TYPE, objectType);
    ResourceStatus rs;
    try {
        rs = connResMgr.create(domain.getResources(), attrList, properties, target);
    } catch (Exception e) {
        Logger.getLogger(CreateConnectorResource.class.getName()).log(Level.SEVERE, "Unable to create connector resource " + jndiName, e);
        String def = "Connector resource: {0} could not be created, reason: {1}";
        report.setMessage(localStrings.getLocalString("create.connector.resource.fail", def, jndiName) + " " + e.getLocalizedMessage());
        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.getMessage() == null) {
            report.setMessage(localStrings.getLocalString("create.connector.resource.fail", "Connector resource {0} creation failed", jndiName, ""));
        }
        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 40 with ResourceStatus

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

the class AddResources 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();
    // Check if the path xmlFile exists
    if (!xmlFile.exists()) {
        report.setMessage(localStrings.getLocalString("FileNotFound", "The system cannot find the path specified: {0}", xmlFile.getName()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        final ArrayList results = ResourcesManager.createResources(domain.getResources(), xmlFile, target, resourceFactory);
        final Iterator resultsIter = results.iterator();
        report.getTopMessagePart().setChildrenType("Command");
        boolean isSuccess = false;
        while (resultsIter.hasNext()) {
            ResourceStatus rs = ((ResourceStatus) resultsIter.next());
            final String msgToAdd = rs.getMessage();
            if ((msgToAdd != null) && (!msgToAdd.equals(""))) {
                final ActionReport.MessagePart part = report.getTopMessagePart().addChild();
                part.setMessage(msgToAdd);
            }
            if (rs.getStatus() == ResourceStatus.SUCCESS || rs.isAlreadyExists())
                isSuccess = true;
        }
        report.setActionExitCode((isSuccess) ? ActionReport.ExitCode.SUCCESS : ActionReport.ExitCode.FAILURE);
        if (!isSuccess)
            report.setMessage(localStrings.getLocalString("add.resources.failed", "add-resources <{0}> failed", xmlFile.getName()));
    } catch (Exception ex) {
        Logger.getLogger(AddResources.class.getName()).log(Level.SEVERE, "Something went wrong in add-resources", ex);
        report.setMessage(localStrings.getLocalString("add.resources.failed", "add-resources <{0}> failed", xmlFile.getName()));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        // Need to fix, doesn't show the error from exception, though it writes in the log
        report.setFailureCause(ex);
    }
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) 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