Search in sources :

Example 26 with TYPE

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

the class GrizzlyService method postConstruct.

/**
 * The component has been injected with any dependency and
 * will be placed into commission by the subsystem.
 */
@Override
public void postConstruct() {
    events.register(this);
    final NetworkConfig networkConfig = config.getNetworkConfig();
    configListener = new DynamicConfigListener(config, LOGGER);
    ObservableBean bean = (ObservableBean) ConfigSupport.getImpl(networkConfig.getNetworkListeners());
    bean.addListener(configListener);
    bean = (ObservableBean) ConfigSupport.getImpl(config.getHttpService());
    bean.addListener(configListener);
    transactions.addListenerForType(SystemProperty.class, configListener);
    configListener.setGrizzlyService(this);
    try {
        boolean isAtLeastOneProxyStarted = false;
        futures = new ArrayList<>();
        // Record how long it took for the listeners to start up
        final long startTime = System.currentTimeMillis();
        // Keep a list of successfully started listeners
        List<NetworkListener> startedListeners = new ArrayList<>();
        for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
            if (createNetworkProxy(listener) != null) {
                isAtLeastOneProxyStarted = true;
                startedListeners.add(listener);
            }
        }
        if (isAtLeastOneProxyStarted) {
            // Get the startup time
            final long startupTime = System.currentTimeMillis() - startTime;
            // Log the listeners which started.
            String boundAddresses = Arrays.toString(startedListeners.stream().map(listener -> listener.getName() + ":" + getRealPort(listener)).collect(Collectors.toList()).toArray());
            LOGGER.log(Level.INFO, KernelLoggerInfo.grizzlyStarted, new Object[] { Grizzly.getDotedVersion(), startupTime, boundAddresses });
            registerContainerAdapters();
        }
    } catch (RuntimeException e) {
        // So far postConstruct can not throw any other exception type
        LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCantStart, e);
        for (NetworkProxy proxy : proxies) {
            try {
                proxy.stop();
            } catch (Exception proxyStopException) {
                LOGGER.log(Level.SEVERE, KernelLoggerInfo.grizzlyCloseException, new Object[] { proxy.getPort(), proxyStopException });
            }
        }
        throw e;
    }
    registerMonitoringStatsProviders();
}
Also used : Arrays(java.util.Arrays) RestrictTo(org.glassfish.api.event.RestrictTo) KernelLoggerInfo(org.glassfish.kernel.KernelLoggerInfo) Events(org.glassfish.api.event.Events) TimeoutException(java.util.concurrent.TimeoutException) RequestDispatcher(org.glassfish.api.container.RequestDispatcher) InetAddress(java.net.InetAddress) Protocol(org.glassfish.grizzly.config.dom.Protocol) Future(java.util.concurrent.Future) GrizzlyNetworkListenerRestartAdapter(org.glassfish.api.container.GrizzlyNetworkListenerRestartAdapter) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) Adapter(org.glassfish.api.container.Adapter) Map(java.util.Map) ServerEnvironment(org.glassfish.api.admin.ServerEnvironment) Futures(org.glassfish.grizzly.utils.Futures) GenericGrizzlyListener(org.glassfish.grizzly.config.GenericGrizzlyListener) Method(java.lang.reflect.Method) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Logger(java.util.logging.Logger) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Collectors(java.util.stream.Collectors) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) MonitoringDataSource(fish.payara.monitoring.collect.MonitoringDataSource) List(java.util.List) HttpCodecFilter(org.glassfish.grizzly.http.HttpCodecFilter) StartupRunLevel(org.glassfish.api.StartupRunLevel) Service(org.jvnet.hk2.annotations.Service) Transactions(org.jvnet.hk2.config.Transactions) Entry(java.util.Map.Entry) HttpService(com.sun.enterprise.config.serverbeans.HttpService) MonitoringDataCollection(fish.payara.monitoring.collect.MonitoringDataCollection) Queue(java.util.Queue) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Result(com.sun.enterprise.util.Result) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) FutureImpl(org.glassfish.grizzly.impl.FutureImpl) ObservableBean(org.jvnet.hk2.config.ObservableBean) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Constants(org.glassfish.common.util.Constants) GrizzlyMonitoring(com.sun.enterprise.v3.services.impl.monitor.GrizzlyMonitoring) Rank(org.glassfish.hk2.api.Rank) EventTypes(org.glassfish.api.event.EventTypes) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) HttpProbe(org.glassfish.grizzly.http.HttpProbe) StringUtils(com.sun.enterprise.util.StringUtils) FutureProvider(org.glassfish.api.FutureProvider) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener) Named(javax.inject.Named) EventListener(org.glassfish.api.event.EventListener) PreDestroy(org.glassfish.hk2.api.PreDestroy) RunLevel(org.glassfish.hk2.runlevel.RunLevel) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService) Mapper(org.glassfish.grizzly.http.server.util.Mapper) HttpHandler(org.glassfish.grizzly.http.server.HttpHandler) IOException(java.io.IOException) NetworkListeners(org.glassfish.grizzly.config.dom.NetworkListeners) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) ApplicationContainer(org.glassfish.api.deployment.ApplicationContainer) UnknownHostException(java.net.UnknownHostException) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer) Grizzly(org.glassfish.grizzly.Grizzly) PostConstruct(org.glassfish.hk2.api.PostConstruct) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) InvocationHandler(java.lang.reflect.InvocationHandler) Config(com.sun.enterprise.config.serverbeans.Config) Collections(java.util.Collections) CountStatistic(org.glassfish.external.statistics.CountStatistic) NetworkConfig(org.glassfish.grizzly.config.dom.NetworkConfig) ArrayList(java.util.ArrayList) TimeoutException(java.util.concurrent.TimeoutException) EndpointRegistrationException(org.glassfish.api.container.EndpointRegistrationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ObservableBean(org.jvnet.hk2.config.ObservableBean) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 27 with TYPE

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

the class HealthCheckService method getCollectiveHealthChecks.

private Map<String, Set<HealthCheck>> getCollectiveHealthChecks(HealthCheckType type) {
    final Map<String, Set<HealthCheck>> healthChecks;
    if (type == READINESS) {
        healthChecks = readiness;
    } else if (type == LIVENESS) {
        healthChecks = liveness;
    } else if (type == STARTUP) {
        healthChecks = startup;
    } else {
        // Make sure we do a deep-copy first, otherwise the first map the foreach consumer gets used on will be a
        // shallow copy: the two maps will essentially be the same map (changes to one affecting the other)
        healthChecks = readiness.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey(), entry -> new HashSet(entry.getValue())));
        BiConsumer<? super String, ? super Set<HealthCheck>> mergeHealthCheckMap = (key, value) -> healthChecks.merge(key, value, (oldValue, newValue) -> {
            oldValue.addAll(newValue);
            return oldValue;
        });
        liveness.forEach(mergeHealthCheckMap);
        startup.forEach(mergeHealthCheckMap);
    }
    return healthChecks;
}
Also used : JsonWriterFactory(javax.json.JsonWriterFactory) Events(org.glassfish.api.event.Events) MonitoringWatchCollector(fish.payara.monitoring.collect.MonitoringWatchCollector) Map(java.util.Map) WebApplication(com.sun.enterprise.web.WebApplication) LIVENESS(fish.payara.microprofile.healthcheck.HealthCheckType.LIVENESS) HealthCheck(org.eclipse.microprofile.health.HealthCheck) PayaraHealthCheckServiceEvents(fish.payara.nucleus.healthcheck.events.PayaraHealthCheckServiceEvents) MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) Collections.emptyList(java.util.Collections.emptyList) UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WARNING(java.util.logging.Level.WARNING) Set(java.util.Set) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Collectors.joining(java.util.stream.Collectors.joining) MonitoringDataSource(fish.payara.monitoring.collect.MonitoringDataSource) List(java.util.List) StartupRunLevel(org.glassfish.api.StartupRunLevel) Service(org.jvnet.hk2.annotations.Service) Entry(java.util.Map.Entry) PostConstruct(javax.annotation.PostConstruct) MicroprofileHealthCheckConfiguration(fish.payara.microprofile.healthcheck.config.MicroprofileHealthCheckConfiguration) Optional(java.util.Optional) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) JsonObjectBuilder(javax.json.JsonObjectBuilder) Deployment(org.glassfish.internal.deployment.Deployment) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) READINESS(fish.payara.microprofile.healthcheck.HealthCheckType.READINESS) JsonGenerator(javax.json.stream.JsonGenerator) InvocationManager(org.glassfish.api.invocation.InvocationManager) JsonArrayBuilder(javax.json.JsonArrayBuilder) Globals(org.glassfish.internal.api.Globals) MonitoringData(fish.payara.monitoring.collect.MonitoringData) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InvocationException(org.glassfish.api.invocation.InvocationException) HealthCheckResponse(org.eclipse.microprofile.health.HealthCheckResponse) BiConsumer(java.util.function.BiConsumer) Json(javax.json.Json) Collections.singletonMap(java.util.Collections.singletonMap) EventListener(org.glassfish.api.event.EventListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) WebComponentInvocation(com.sun.enterprise.web.WebComponentInvocation) RunLevel(org.glassfish.hk2.runlevel.RunLevel) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebContainer(com.sun.enterprise.web.WebContainer) IOException(java.io.IOException) Checker(fish.payara.nucleus.healthcheck.configuration.Checker) STARTUP(fish.payara.microprofile.healthcheck.HealthCheckType.STARTUP) Status(org.eclipse.microprofile.health.HealthCheckResponse.Status) MonitoringWatchSource(fish.payara.monitoring.collect.MonitoringWatchSource) JsonWriter(javax.json.JsonWriter) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) ConfigListener(org.jvnet.hk2.config.ConfigListener) PayaraHealthCheck(fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck) Set(java.util.Set) HashSet(java.util.HashSet) HealthCheck(org.eclipse.microprofile.health.HealthCheck) PayaraHealthCheck(fish.payara.microprofile.healthcheck.checks.PayaraHealthCheck) HashSet(java.util.HashSet)

Example 28 with TYPE

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

the class ConfigDomainParser method parseIDEntry.

private void parseIDEntry(ProviderConfig pConfig, Map<String, GFServerConfigProvider.InterceptEntry> newConfig, String intercept) throws IOException {
    String id = pConfig.getProviderId();
    String type = pConfig.getProviderType();
    String moduleClass = pConfig.getClassName();
    MessagePolicy requestPolicy = parsePolicy((RequestPolicy) pConfig.getRequestPolicy());
    MessagePolicy responsePolicy = parsePolicy((ResponsePolicy) pConfig.getResponsePolicy());
    // get the module options
    Map<String, Object> options = new HashMap<>();
    List<Property> pList = pConfig.getProperty();
    if (pList != null) {
        Iterator<Property> pit = pList.iterator();
        while (pit.hasNext()) {
            Property property = pit.next();
            try {
                options.put(property.getName(), expand(property.getValue()));
            } catch (IllegalStateException ee) {
                // interpret value itself.
                if (_logger.isLoggable(FINE)) {
                    _logger.log(FINE, "jaspic.unexpandedproperty");
                }
                options.put(property.getName(), property.getValue());
            }
        }
    }
    if (_logger.isLoggable(FINE)) {
        _logger.fine("ID Entry: " + "\n    module class: " + moduleClass + "\n    id: " + id + "\n    type: " + type + "\n    request policy: " + requestPolicy + "\n    response policy: " + responsePolicy + "\n    options: " + options);
    }
    // create ID entry
    GFServerConfigProvider.IDEntry idEntry = new GFServerConfigProvider.IDEntry(type, moduleClass, requestPolicy, responsePolicy, options);
    GFServerConfigProvider.InterceptEntry intEntry = newConfig.get(intercept);
    if (intEntry == null) {
        throw new IOException("intercept entry for " + intercept + " must be specified before ID entries");
    }
    if (intEntry.idMap == null) {
        intEntry.idMap = new HashMap<>();
    }
    // map id to Intercept
    intEntry.idMap.put(id, idEntry);
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) AuthMessagePolicy(com.sun.enterprise.security.jaspic.AuthMessagePolicy) MessagePolicy(javax.security.auth.message.MessagePolicy) Property(org.jvnet.hk2.config.types.Property)

Example 29 with TYPE

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

the class ActiveJmsResourceAdapter method setLifecycleProperties.

/**
 * Set MQ4.0 RA lifecycle properties
 */
private void setLifecycleProperties() throws Exception, ConnectorRuntimeException {
    // ConfigContext ctx = ApplicationServer.getServerContext().getConfigContext();
    // If PE:
    // EMBEDDED/LOCAL goto jms-service, get defaultjmshost info and set
    // accordingly
    // if EE:
    // EMBEDDED/LOCAL get this instance and cluster name, search for a
    // jms-host wth this this name in jms-service gets its proeprties
    // and set
    // @siva As of now use default JMS host. As soon as changes for modifying EE
    // cluster to LOCAL is brought in, change this to use system properties
    // for EE to get port, host, adminusername, adminpassword.
    // JmsService jmsService = ServerBeansFactory.getJmsServiceBean(ctx);
    String defaultJmsHost = getJmsService().getDefaultJmsHost();
    if (_logger.isLoggable(Level.FINE))
        logFine("Default JMS Host :: " + defaultJmsHost);
    JmsHost jmsHost = getJmsHost();
    if (jmsHost != null) {
        // todo: && jmsHost.isEnabled()) {
        JavaConfig javaConfig = (JavaConfig) Globals.get(JavaConfig.class);
        ;
        String java_home = javaConfig.getJavaHome();
        // Get broker type from JMS Service.
        // String brokerType = jmsService.getType();
        /*
             * XXX: adjust the brokertype for the new DIRECT mode in 4.1
             * uncomment the line below once we have an MQ integration
             * that has DIRECT mode support
             */
        String brokerType = adjustForDirectMode(getJmsService().getType());
        String brokerPort = jmsHost.getPort();
        brkrPort = brokerPort;
        String adminUserName = jmsHost.getAdminUserName();
        String adminPassword = JmsRaUtil.getUnAliasedPwd(jmsHost.getAdminPassword());
        List jmsHostProps = getJmsService().getProperty();
        String username = null;
        String password = null;
        if (jmsHostProps != null) {
            for (int i = 0; i < jmsHostProps.size(); i++) {
                Property jmsProp = (Property) jmsHostProps.get(i);
                String propName = jmsProp.getName();
                String propValue = jmsProp.getValue();
                if ("user-name".equals(propName)) {
                    username = propValue;
                } else if ("password".equals(propName)) {
                    password = propValue;
                }
            // Add more properties as and when you want.
            }
        }
        if (_logger.isLoggable(Level.FINE))
            logFine("Broker UserName = " + username);
        createMQVarDirectoryIfNecessary();
        String brokerVarDir = getMQVarDir();
        String tmpString = getJmsService().getStartArgs();
        if (tmpString == null) {
            tmpString = "";
        }
        String brokerArgs = tmpString;
        // by adding the start-args for the broker configuration
        if (!tmpString.contains("-jrehome") && availableJDKForStartArgs()) {
            brokerArgs = brokerArgs + buildStartArgsForJREHome(java_home);
        }
        // XX: Extract the information from the optional properties.
        List jmsProperties = getJmsService().getProperty();
        List jmsHostProperties = jmsHost.getProperty();
        Properties jmsServiceProp = listToProperties(jmsProperties);
        Properties jmsHostProp = listToProperties(jmsHostProperties);
        jmsServiceProp.putAll(jmsHostProp);
        if (jmsServiceProp.size() > 0) {
            if (dbProps == null)
                dbProps = new Properties();
            dbProps.putAll(jmsServiceProp);
        }
        /*
	   String jmsPropertiesStr =  null ;
	   if(jmsServiceProp.size() > 0)
	   {
	   try{
	   	StringWriter writer = new StringWriter();
	   	jmsServiceProp.store(writer, "Properties defined in JMSService and JMSHost");
	   	jmsPropertiesStr =  writer.toString();
	   }catch(Exception e){}//todo: log error;
	   } */
        String brokerHomeDir = getBrokerHomeDir();
        String brokerLibDir = getBrokerLibDir();
        if (brokerInstanceName == null) {
            brokerInstanceName = getBrokerInstanceName(getJmsService());
        }
        long brokerTimeOut = getBrokerTimeOut(getJmsService());
        // Need to set the following properties
        // BrokerType, BrokerInstanceName, BrokerPort,
        // BrokerArgs, BrokerHomeDir, BrokerVarDir, BrokerStartTimeout
        // adminUserName, adminPassword
        ConnectorDescriptor cd = getDescriptor();
        /*if(jmsPropertiesStr != null){
            	ConnectorConfigProperty  envProp = new ConnectorConfigProperty  (
                    "BrokerProps", jmsPropertiesStr, "Broker Props", "java.lang.String");
            	setProperty(cd, envProp);
	    }  */
        ConnectorConfigProperty envProp1 = new ConnectorConfigProperty(BROKERTYPE, brokerType, "Broker Type", "java.lang.String");
        setProperty(cd, envProp1);
        ConnectorConfigProperty envProp2 = new ConnectorConfigProperty(BROKERINSTANCENAME, brokerInstanceName, "Broker Instance Name", "java.lang.String");
        setProperty(cd, envProp2);
        ConnectorConfigProperty envProp3 = new ConnectorConfigProperty(BROKERPORT, brokerPort, "Broker Port", "java.lang.String");
        setProperty(cd, envProp3);
        ConnectorConfigProperty envProp4 = new ConnectorConfigProperty(BROKERARGS, brokerArgs, "Broker Args", "java.lang.String");
        setProperty(cd, envProp4);
        ConnectorConfigProperty envProp5 = new ConnectorConfigProperty(BROKERHOMEDIR, brokerHomeDir, "Broker Home Dir", "java.lang.String");
        setProperty(cd, envProp5);
        ConnectorConfigProperty envProp14 = new ConnectorConfigProperty(BROKERLIBDIR, brokerLibDir, "Broker Lib Dir", "java.lang.String");
        setProperty(cd, envProp14);
        ConnectorConfigProperty envProp6 = new ConnectorConfigProperty(BROKERJAVADIR, java_home, "Broker Java Dir", "java.lang.String");
        setProperty(cd, envProp6);
        ConnectorConfigProperty envProp7 = new ConnectorConfigProperty(BROKERVARDIR, brokerVarDir, "Broker Var Dir", "java.lang.String");
        setProperty(cd, envProp7);
        ConnectorConfigProperty envProp8 = new ConnectorConfigProperty(BROKERSTARTTIMEOUT, "" + brokerTimeOut, "Broker Start Timeout", "java.lang.String");
        setProperty(cd, envProp8);
        ConnectorConfigProperty envProp9 = new ConnectorConfigProperty(ADMINUSERNAME, adminUserName, "Broker admin username", "java.lang.String");
        setProperty(cd, envProp9);
        ConnectorConfigProperty envProp10 = new ConnectorConfigProperty(ADMINPASSWORD, adminPassword, "Broker admin password", "java.lang.String");
        setProperty(cd, envProp10);
        ConnectorConfigProperty envProp11 = new ConnectorConfigProperty(USERNAME, username, "Broker username", "java.lang.String");
        setProperty(cd, envProp11);
        ConnectorConfigProperty envProp12 = new ConnectorConfigProperty(PASSWORD, password, "Broker password", "java.lang.String");
        setProperty(cd, envProp12);
    /* //set adminpassfile
            if (!getJmsService().getType().equals(REMOTE)) {
                //For LOCAL and EMBEDDED, we pass in the admin pass file path
                //containing the MQ admin password to enable authenticated
                //startup of the broker.
                String adminPassFilePath = getAdminPassFilePath(adminPassword);
                if (adminPassFilePath != null) {
                    ConnectorConfigProperty  envProp13 = new ConnectorConfigProperty  (
                            ADMINPASSFILE , adminPassFilePath ,
                            "Broker admin password", "java.lang.String");
                    setProperty(cd, envProp13);
                }
            }*/
    }
// Optional
// BrokerBindAddress, RmiRegistryPort
}
Also used : JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig) ConnectorDescriptor(com.sun.enterprise.deployment.ConnectorDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) JmsHost(com.sun.enterprise.connectors.jms.config.JmsHost) Properties(java.util.Properties) Property(org.jvnet.hk2.config.types.Property) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty)

Example 30 with TYPE

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

the class JDBCResourceManager method delete.

public ResourceStatus delete(final Resources resources, final String jndiName, final String target) throws Exception {
    if (jndiName == null) {
        String msg = localStrings.getLocalString("jdbc.resource.noJndiName", "No JNDI name defined for JDBC resource.");
        return new ResourceStatus(ResourceStatus.FAILURE, msg);
    }
    // ensure we already have this resource
    if (ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jndiName) == null) {
        String msg = localStrings.getLocalString("delete.jdbc.resource.notfound", "A JDBC resource named {0} does not exist.", 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.jdbc.resource.resource-ref.exist", "jdbc-resource [ {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.jdbc.resource.no.resource-ref", "jdbc-resource [ {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.jdbc.resource.multiple.resource-refs", "jdbc resource [ {0} ] is referenced in multiple " + "instance/cluster targets, Use delete-resource-ref on appropriate target", jndiName);
                return new ResourceStatus(ResourceStatus.FAILURE, msg);
            }
        }
    }
    try {
        JdbcResource jdbcResource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jndiName);
        if (ResourceConstants.SYSTEM_ALL_REQ.equals(jdbcResource.getObjectType())) {
            String msg = localStrings.getLocalString("delete.jdbc.resource.system-all-req.object-type", "The jdbc resource [ {0} ] cannot be deleted as it is required to be configured in the system.", jndiName);
            return new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
        // delete resource-ref
        resourceUtil.deleteResourceRef(jndiName, target);
        // delete jdbc-resource
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                JdbcResource resource = (JdbcResource) ConnectorsUtil.getResourceByName(resources, JdbcResource.class, jndiName);
                return param.getResources().remove(resource);
            }
        }, resources) == null) {
            String msg = localStrings.getLocalString("jdbc.resource.deletionFailed", "JDBC resource {0} delete failed ", jndiName);
            return new ResourceStatus(ResourceStatus.FAILURE, msg);
        }
    } catch (TransactionFailure tfe) {
        String msg = localStrings.getLocalString("jdbc.resource.deletionFailed", "JDBC resource {0} delete failed ", jndiName);
        ResourceStatus status = new ResourceStatus(ResourceStatus.FAILURE, msg);
        status.setException(tfe);
        return status;
    }
    String msg = localStrings.getLocalString("jdbc.resource.deleteSuccess", "JDBC resource {0} deleted successfully", jndiName);
    return new ResourceStatus(ResourceStatus.SUCCESS, msg);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) JdbcResource(org.glassfish.jdbc.config.JdbcResource) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ResourceStatus(org.glassfish.resourcebase.resources.api.ResourceStatus) Resources(com.sun.enterprise.config.serverbeans.Resources)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)15 Property (org.jvnet.hk2.config.types.Property)15 IOException (java.io.IOException)13 ActionReport (org.glassfish.api.ActionReport)13 PropertyVetoException (java.beans.PropertyVetoException)12 List (java.util.List)10 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)10 Method (java.lang.reflect.Method)9 HashMap (java.util.HashMap)9 Map (java.util.Map)7 Logger (java.util.logging.Logger)7 Service (org.jvnet.hk2.annotations.Service)7 ArrayList (java.util.ArrayList)6 Inject (javax.inject.Inject)6 MultiException (org.glassfish.hk2.api.MultiException)6 ConfigBean (org.jvnet.hk2.config.ConfigBean)6 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)5 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)4 Collection (java.util.Collection)4 DeploymentException (org.glassfish.deployment.common.DeploymentException)4