Search in sources :

Example 66 with SingleConfigCode

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

the class DeleteAdminObject 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();
    if (jndiName == null) {
        report.setMessage(localStrings.getLocalString("delete.admin.object.noJndiName", "No JNDI name defined for administered object."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we already have this resource
    if (!isResourceExists(domain.getResources(), jndiName)) {
        report.setMessage(localStrings.getLocalString("delete.admin.object.notfound", "An administered object named {0} does not exist.", jndiName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (environment.isDas()) {
        if (domain.getConfigNamed(target) != null) {
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
                report.setMessage(localStrings.getLocalString("delete.admin.object.resource-ref.exist", "admin-object [ {0} ] is referenced in an" + "instance/cluster target, Use delete-resource-ref on appropriate target", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        } else {
            if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
                report.setMessage(localStrings.getLocalString("delete.admin.object.no.resource-ref", "admin-object [ {0} ] is not referenced in target [ {1} ]", jndiName, target));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
                report.setMessage(localStrings.getLocalString("delete.admin.object.multiple.resource-refs", "admin-object [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName));
                report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                return;
            }
        }
    }
    try {
        // delete resource-ref
        resourceUtil.deleteResourceRef(jndiName, target);
        // delete admin-object-resource
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                Resource resource = ConnectorsUtil.getResourceByName(domain.getResources(), AdminObjectResource.class, jndiName);
                return param.getResources().remove(resource);
            }
        }, domain.getResources()) == null) {
            report.setMessage(localStrings.getLocalString("delete.admin.object.fail", "Unable to delete administered object {0}", jndiName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("delete.admin.object.fail", "Unable to delete administered object {0}", jndiName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    report.setMessage(localStrings.getLocalString("delete.admin.object.success", "Administered object {0} deleted", jndiName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) AdminObjectResource(org.glassfish.connectors.config.AdminObjectResource) Resource(com.sun.enterprise.config.serverbeans.Resource) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Example 67 with SingleConfigCode

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

the class DeleteConnectorWorkSecurityMap 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();
    // ensure we already have this resource
    if (!isResourceExists()) {
        report.setMessage(localStrings.getLocalString("delete.connector.work.security.map.notFound", "A connector work security map named {0} for resource adapter {1} does not exist.", mapName, raName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        // delete connector-work-security-map
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            Collection<WorkSecurityMap> workSecurityMaps = domain.getResources().getResources(WorkSecurityMap.class);

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                for (WorkSecurityMap resource : workSecurityMaps) {
                    if (resource.getName().equals(mapName) && resource.getResourceAdapterName().equals(raName)) {
                        param.getResources().remove(resource);
                        break;
                    }
                }
                return workSecurityMaps;
            }
        }, domain.getResources());
    } catch (TransactionFailure tfe) {
        Logger.getLogger(DeleteConnectorWorkSecurityMap.class.getName()).log(Level.SEVERE, "delete-connector-work-security-map failed", tfe);
        report.setMessage(localStrings.getLocalString("" + "delete.connector.work.security.map.fail", "Unable to delete connector work security map {0} for resource adapter {1}", mapName, raName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Example 68 with SingleConfigCode

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

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

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

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)153 PropertyVetoException (java.beans.PropertyVetoException)130 ActionReport (org.glassfish.api.ActionReport)76 Config (com.sun.enterprise.config.serverbeans.Config)47 Property (org.jvnet.hk2.config.types.Property)27 Resources (com.sun.enterprise.config.serverbeans.Resources)25 List (java.util.List)23 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)19 ResourceStatus (org.glassfish.resourcebase.resources.api.ResourceStatus)17 CommandTarget (org.glassfish.config.support.CommandTarget)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Protocol (org.glassfish.grizzly.config.dom.Protocol)15 Target (org.glassfish.internal.api.Target)15 Test (org.junit.Test)15 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)13 ArrayList (java.util.ArrayList)11 Protocols (org.glassfish.grizzly.config.dom.Protocols)11 Resource (com.sun.enterprise.config.serverbeans.Resource)9 SecurityService (com.sun.enterprise.config.serverbeans.SecurityService)9 Properties (java.util.Properties)9