Search in sources :

Example 41 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.

the class ResourceAdapterConfigManager method createConfigBean.

private ResourceAdapterConfig createConfigBean(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
    ResourceAdapterConfig newResource = param.createChild(ResourceAdapterConfig.class);
    newResource.setResourceAdapterName(raName);
    if (threadPoolIds != null) {
        newResource.setThreadPoolIds(threadPoolIds);
    }
    newResource.setObjectType(objectType);
    if (name != null) {
        newResource.setName(name);
    }
    if (properties != null) {
        for (Map.Entry e : properties.entrySet()) {
            Property prop = newResource.createChild(Property.class);
            prop.setName((String) e.getKey());
            prop.setValue((String) e.getValue());
            newResource.getProperty().add(prop);
        }
    }
    return newResource;
}
Also used : ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) HashMap(java.util.HashMap) Map(java.util.Map) Property(org.jvnet.hk2.config.types.Property)

Example 42 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure 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 43 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.

the class EJBTimerServiceUpgrade method doUpgrade.

private void doUpgrade(EjbTimerService ts) {
    String value = ts.getMinimumDeliveryIntervalInMillis();
    if (value == null || "7000".equals(value)) {
        value = "" + EjbContainerUtil.MINIMUM_TIMER_DELIVERY_INTERVAL;
    }
    List<Property> properties = ts.getProperty();
    if (properties != null) {
        for (Property p : properties) {
            if (p.getName().equals(EjbContainerUtil.TIMER_SERVICE_UPGRADED)) {
                // Already set
                return;
            }
        }
    }
    try {
        final String minDelivery = value;
        ConfigSupport.apply(new SingleConfigCode<EjbTimerService>() {

            public Object run(EjbTimerService ts) throws PropertyVetoException, TransactionFailure {
                Property prop = ts.createChild(Property.class);
                ts.getProperty().add(prop);
                prop.setName(EjbContainerUtil.TIMER_SERVICE_UPGRADED);
                prop.setValue("false");
                ts.setMinimumDeliveryIntervalInMillis(minDelivery);
                return null;
            }
        }, ts);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Property(org.jvnet.hk2.config.types.Property) EjbTimerService(org.glassfish.ejb.config.EjbTimerService) PropertyVetoException(java.beans.PropertyVetoException)

Example 44 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure in project Payara by payara.

the class PersistentEJBTimerService method isUpgrade.

private static boolean isUpgrade(String resource, EjbTimerService _ejbt, File root) {
    boolean upgrade = false;
    Property prop = null;
    if (_ejbt != null) {
        List<Property> properties = _ejbt.getProperty();
        if (properties != null) {
            for (Property p : properties) {
                if (p.getName().equals(EjbContainerUtil.TIMER_SERVICE_UPGRADED)) {
                    String value = p.getValue();
                    if (value != null && "false".equals(value)) {
                        upgrade = true;
                        prop = p;
                        break;
                    }
                }
            }
        }
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("===> Upgrade? <==");
    }
    if (upgrade) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("===> Upgrade! <==");
        }
        boolean success = false;
        try {
            File dir = new File(root, "lib/install/databases/upgrade");
            if (!dir.exists()) {
                logger.log(Level.WARNING, "Cannot upgrade EJBTimerService: " + "required directory is not available");
            } else {
                Java2DBProcessorHelper h = new Java2DBProcessorHelper(TIMER_SERVICE_APP_NAME);
                success = h.executeDDLStatement(dir.getCanonicalPath() + "/ejbtimer_upgrade_", resource);
                ConfigSupport.apply(new SingleConfigCode<Property>() {

                    public Object run(Property p) throws PropertyVetoException, TransactionFailure {
                        p.setValue("true");
                        return null;
                    }
                }, prop);
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "", e);
        }
        if (!success) {
            logger.log(Level.SEVERE, "Failed to upgrade EJBTimerService: see log for details");
        }
    }
    return upgrade;
}
Also used : Java2DBProcessorHelper(org.glassfish.persistence.common.Java2DBProcessorHelper) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Property(org.jvnet.hk2.config.types.Property) File(java.io.File) PropertyVetoException(java.beans.PropertyVetoException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) CreateException(javax.ejb.CreateException)

Example 45 with TransactionFailure

use of org.jvnet.hk2.config.TransactionFailure 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)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)191 PropertyVetoException (java.beans.PropertyVetoException)132 ActionReport (org.glassfish.api.ActionReport)86 Property (org.jvnet.hk2.config.types.Property)61 Config (com.sun.enterprise.config.serverbeans.Config)52 HashMap (java.util.HashMap)30 Test (org.junit.Test)27 Resources (com.sun.enterprise.config.serverbeans.Resources)25 Map (java.util.Map)25 List (java.util.List)21 CommandTarget (org.glassfish.config.support.CommandTarget)21 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)21 Target (org.glassfish.internal.api.Target)21 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)20 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 ConfigBean (org.jvnet.hk2.config.ConfigBean)20 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)18 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)16 ParameterMap (org.glassfish.api.admin.ParameterMap)14