Search in sources :

Example 61 with SingleConfigCode

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

Example 62 with SingleConfigCode

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

the class ManagedThreadFactoryManager 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.managed.thread.factory.failed", "Managed thread factory {0} creation failed", jndiName) + " " + tfe.getLocalizedMessage();
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("create.managed.thread.factory.success", "Managed thread factory {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 63 with SingleConfigCode

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

the class ManagedExecutorServiceBaseManager 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.managed.executor.service.failed", "Managed executor service {0} creation failed", jndiName) + " " + tfe.getLocalizedMessage();
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("create.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} creation failed", jndiName) + " " + tfe.getLocalizedMessage();
        }
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("create.managed.executor.service.success", "Managed executor service {0} created successfully", jndiName);
    if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
        msg = localStrings.getLocalString("create.managed.scheduled.executor.service.success", "Managed scheduled executor service {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 64 with SingleConfigCode

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

the class ManagedExecutorServiceBaseManager method delete.

public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
    if (jndiName == null) {
        String msg = localStrings.getLocalString("managed.executor.service.noJndiName", "No JNDI name defined for managed executor service.");
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("managed.scheduled.executor.service.noJndiName", "No JNDI name defined for managed scheduled executor service.");
        }
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    Resource resource = null;
    if (getResourceType().equals(ServerTags.MANAGED_EXECUTOR_SERVICE)) {
        resource = ConnectorsUtil.getResourceByName(resources, ManagedExecutorService.class, jndiName);
    } else if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
        resource = ConnectorsUtil.getResourceByName(resources, ManagedScheduledExecutorService.class, jndiName);
    }
    // ensure we already have this resource
    if (resource == null) {
        String msg = localStrings.getLocalString("delete.managed.executor.service.notfound", "A managed executor service named {0} does not exist.", jndiName);
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.notfound", "A managed scheduled executor service named {0} does not exist.", jndiName);
        }
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    if (SYSTEM_ALL_REQ.equals(resource.getObjectType())) {
        String msg = localStrings.getLocalString("delete.concurrent.resource.notAllowed", "The {0} resource cannot be deleted as it is required to be configured in the system.", jndiName);
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    if (environment.isDas()) {
        if ("domain".equals(target)) {
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 0) {
                String msg = localStrings.getLocalString("delete.managed.executor.service.resource-ref.exist", "This managed executor service [ {0} ] is referenced in an instance/cluster target, use delete-resource-ref on appropriate target", jndiName);
                if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                    msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.resource-ref.exist", "This managed scheduled executor service [ {0} ] is referenced in an instance/cluster target, use delete-resource-ref on appropriate target", jndiName);
                }
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
        } else {
            if (!resourceUtil.isResourceRefInTarget(jndiName, target)) {
                String msg = localStrings.getLocalString("delete.managed.executor.service.no.resource-ref", "This managed executor service [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
                if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                    msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.no.resource-ref", "This managed scheduled executor service [ {0} ] is not referenced in target [ {1} ]", jndiName, target);
                }
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
            if (resourceUtil.getTargetsReferringResourceRef(jndiName).size() > 1) {
                String msg = localStrings.getLocalString("delete.managed.executor.service.multiple.resource-refs", "This managed executor service [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
                if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                    msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.multiple.resource-refs", "This managed scheduled executor service [ {0} ] is referenced in multiple instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
                }
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
        }
    }
    try {
        // delete resource-ref
        resourceUtil.deleteResourceRef(jndiName, target);
        // delete managed executor service
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ManagedExecutorServiceBase resource = null;
                if (getResourceType().equals(ServerTags.MANAGED_EXECUTOR_SERVICE)) {
                    resource = (ManagedExecutorService) ConnectorsUtil.getResourceByName(resources, ManagedExecutorService.class, jndiName);
                } else {
                    resource = (ManagedScheduledExecutorService) ConnectorsUtil.getResourceByName(resources, ManagedScheduledExecutorService.class, jndiName);
                }
                return param.getResources().remove(resource);
            }
        }, resources) == null) {
            String msg = localStrings.getLocalString("delete.managed.executor.service.failed", "Managed executor service {0} deletion failed", jndiName);
            if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
                msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} deletion failed", jndiName);
            }
            return new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("delete.managed.executor.service.failed", "Managed executor service {0} deletion failed ", jndiName);
        if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
            msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.failed", "Managed scheduled executor service {0} deletion failed ", jndiName);
        }
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("delete.managed.executor.service.success", "Managed executor service {0} deleted successfully", jndiName);
    if (getResourceType().equals(ServerTags.MANAGED_SCHEDULED_EXECUTOR_SERVICE)) {
        msg = localStrings.getLocalString("delete.managed.scheduled.executor.service.success", "Managed scheduled executor service {0} deleted successfully", jndiName);
    }
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ManagedExecutorService(org.glassfish.concurrent.config.ManagedExecutorService) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Resource(com.sun.enterprise.config.serverbeans.Resource) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) ManagedExecutorServiceBase(org.glassfish.concurrent.config.ManagedExecutorServiceBase) Resources(com.sun.enterprise.config.serverbeans.Resources)

Example 65 with SingleConfigCode

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

the class CreateConnectorWorkSecurityMap method execute.

// TODO common code replicated in ConnectorWorkSecurityMapManager
/**
 * 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 (mapName == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noMapName", "No mapname defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (raName == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noRaName", "No raname defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (principalsMap == null && groupsMap == null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.noMap", "No principalsmap or groupsmap defined for connector work security map."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    if (principalsMap != null && groupsMap != null) {
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.specifyPrincipalsOrGroupsMap", "A work-security-map can have either (any number of) group mapping  " + "or (any number of) principals mapping but not both. Specify" + "--principalsmap or --groupsmap."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we don't already have one of this name
    if (hasDuplicate(domain.getResources(), report))
        return;
    // TODO ASR : need similar validation while creating app-scoped-resource of w-s-m
    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;
            }
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                WorkSecurityMap workSecurityMap = param.createChild(WorkSecurityMap.class);
                workSecurityMap.setName(mapName);
                workSecurityMap.setResourceAdapterName(raName);
                if (principalsMap != null) {
                    for (Map.Entry e : principalsMap.entrySet()) {
                        PrincipalMap principalMap = workSecurityMap.createChild(PrincipalMap.class);
                        principalMap.setEisPrincipal((String) e.getKey());
                        principalMap.setMappedPrincipal((String) e.getValue());
                        workSecurityMap.getPrincipalMap().add(principalMap);
                    }
                } else if (groupsMap != null) {
                    for (Map.Entry e : groupsMap.entrySet()) {
                        GroupMap groupMap = workSecurityMap.createChild(GroupMap.class);
                        groupMap.setEisGroup((String) e.getKey());
                        groupMap.setMappedGroup((String) e.getValue());
                        workSecurityMap.getGroupMap().add(groupMap);
                    }
                } else {
                // no mapping
                }
                param.getResources().add(workSecurityMap);
                return workSecurityMap;
            }
        }, domain.getResources());
    } catch (TransactionFailure tfe) {
        Logger.getLogger(CreateConnectorWorkSecurityMap.class.getName()).log(Level.SEVERE, "create-connector-work-security-map failed", tfe);
        report.setMessage(localStrings.getLocalString("create.connector.work.security.map.fail", "Unable to create connector work security map {0}.", mapName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
        return;
    }
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) PrincipalMap(org.glassfish.connectors.config.PrincipalMap) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) GroupMap(org.glassfish.connectors.config.GroupMap) Module(com.sun.enterprise.config.serverbeans.Module) Map(java.util.Map) PrincipalMap(org.glassfish.connectors.config.PrincipalMap) WorkSecurityMap(org.glassfish.connectors.config.WorkSecurityMap) GroupMap(org.glassfish.connectors.config.GroupMap)

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