Search in sources :

Example 6 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class GMSAdapterImpl method readGMSConfigProps.

private void readGMSConfigProps(Properties configProps) {
    configProps.put(MEMBERTYPE_STRING, isDas ? SPECTATOR : CORE);
    for (ServiceProviderConfigurationKeys key : ServiceProviderConfigurationKeys.values()) {
        String keyName = key.toString();
        try {
            switch(key) {
                case MULTICASTADDRESS:
                    if (cluster != null) {
                        String value = cluster.getGmsMulticastAddress();
                        if (value != null) {
                            configProps.put(keyName, value);
                        }
                    }
                    break;
                case MULTICASTPORT:
                    if (cluster != null) {
                        String value = cluster.getGmsMulticastPort();
                        if (value != null) {
                            configProps.put(keyName, value);
                        }
                    }
                    break;
                case FAILURE_DETECTION_TIMEOUT:
                    if (clusterConfig != null) {
                        String value = clusterConfig.getGroupManagementService().getFailureDetection().getHeartbeatFrequencyInMillis();
                        if (value != null) {
                            configProps.put(keyName, value);
                        }
                    }
                    break;
                case FAILURE_DETECTION_RETRIES:
                    if (clusterConfig != null) {
                        String value = clusterConfig.getGroupManagementService().getFailureDetection().getMaxMissedHeartbeats();
                        if (value != null) {
                            configProps.put(keyName, value);
                        }
                    }
                    break;
                case FAILURE_VERIFICATION_TIMEOUT:
                    if (clusterConfig != null) {
                        String value = clusterConfig.getGroupManagementService().getFailureDetection().getVerifyFailureWaittimeInMillis();
                        if (value != null) {
                            configProps.put(keyName, value);
                        }
                    }
                    break;
                case DISCOVERY_TIMEOUT:
                    if (clusterConfig != null) {
                        String value = clusterConfig.getGroupManagementService().getGroupDiscoveryTimeoutInMillis();
                        if (value != null) {
                            configProps.put(keyName, value);
                        }
                    }
                    break;
                case IS_BOOTSTRAPPING_NODE:
                    configProps.put(keyName, isDas ? Boolean.TRUE.toString() : Boolean.FALSE.toString());
                    break;
                case BIND_INTERFACE_ADDRESS:
                    if (cluster != null) {
                        String value = cluster.getGmsBindInterfaceAddress();
                        if (value != null) {
                            value = value.trim();
                        }
                        if (value != null && value.length() > 1 && value.charAt(0) != '$') {
                            // Only supported IPv4 address in gf v2.
                            if (NetworkUtility.isBindAddressValid(value)) {
                                configProps.put(keyName, value);
                            } else {
                                GMS_LOGGER.log(LogLevel.SEVERE, GMS_BIND_INT_ADDRESS_INVALID, value);
                            }
                        }
                    }
                    break;
                case FAILURE_DETECTION_TCP_RETRANSMIT_TIMEOUT:
                    if (clusterConfig != null) {
                        String value = clusterConfig.getGroupManagementService().getFailureDetection().getVerifyFailureConnectTimeoutInMillis();
                        if (value != null) {
                            configProps.put(keyName, value);
                        }
                    }
                    break;
                case MULTICAST_POOLSIZE:
                case INCOMING_MESSAGE_QUEUE_SIZE:
                // case MAX_MESSAGE_LENGTH:    todo uncomment with shoal-gms.jar with this defined is promoted.
                case FAILURE_DETECTION_TCP_RETRANSMIT_PORT:
                    if (clusterConfig != null) {
                        Property prop = clusterConfig.getGroupManagementService().getProperty(keyName);
                        if (prop == null) {
                            if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
                                GMS_LOGGER.log(LogLevel.FINE, String.format("No config property found for %s", keyName));
                            }
                            break;
                        }
                        String value = prop.getValue().trim();
                        if (value != null) {
                            configProps.put(keyName, value);
                        }
                    /*
                            int positiveint = 0;
                            try {
                                positiveint = Integer.getInteger(value);
                            } catch (Throwable t) {}

                            // todo
                            if (positiveint > 0) {
                                configProps.put(keyName, positiveint);
                            } // todo else log event that invalid value was provided.
                            */
                    }
                    break;
                // Must place here or they will get flagged as not handled.
                case LOOPBACK:
                case VIRTUAL_MULTICAST_URI_LIST:
                    break;
                default:
                    if (GMS_LOGGER.isLoggable(LogLevel.FINE)) {
                        GMS_LOGGER.log(LogLevel.FINE, String.format("service provider key %s ignored", keyName));
                    }
                    break;
            }
        /* end switch over ServiceProviderConfigurationKeys enum */
        } catch (Throwable t) {
            GMS_LOGGER.log(LogLevel.WARNING, GMS_EXCEPTION_PROCESSING_CONFIG, t.getLocalizedMessage());
        }
    }
    /* end for loop over ServiceProviderConfigurationKeys */
    // check for Grizzly transport specific properties in GroupManagementService property list and then cluster property list.
    // cluster property is more specific than group-mangement-service, so allow cluster property to override group-management-service proeprty
    // if a GrizzlyConfigConstant property is in both list.
    List<Property> props = null;
    if (clusterConfig != null) {
        props = clusterConfig.getGroupManagementService().getProperty();
        for (Property prop : props) {
            String name = prop.getName().trim();
            String value = prop.getValue().trim();
            if (name == null || value == null) {
                continue;
            }
            if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
                GMS_LOGGER.log(LogLevel.CONFIG, "processing group-management-service property name=" + name + " value= " + value);
            }
            if (value.startsWith("${")) {
                if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
                    GMS_LOGGER.log(LogLevel.CONFIG, "skipping group-management-service property name=" + name + " since value is unresolved symbolic token=" + value);
                }
            } else {
                if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
                    GMS_LOGGER.log(LogLevel.CONFIG, "processing group-management-service property name=" + name + " value= " + value);
                }
                if (name.startsWith(GMS_PROPERTY_PREFIX)) {
                    name = name.replaceFirst(GMS_PROPERTY_PREFIX_REGEXP, "");
                }
                configProps.put(name, value);
                if (!validateGMSProperty(name)) {
                    GMS_LOGGER.log(LogLevel.WARNING, GMS_EXCEPTION_IGNORING_PROPERTY, new Object[] { name, value, "" });
                }
            }
        }
    }
    if (cluster != null) {
        props = cluster.getProperty();
        for (Property prop : props) {
            String name = prop.getName().trim();
            String value = prop.getValue().trim();
            if (name == null || value == null) {
                continue;
            }
            if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
                GMS_LOGGER.log(LogLevel.CONFIG, "processing cluster property name=" + name + " value= " + value);
            }
            if (value.startsWith("${")) {
                if (GMS_LOGGER.isLoggable(LogLevel.CONFIG)) {
                    GMS_LOGGER.log(LogLevel.CONFIG, "skipping cluster property name=" + name + " since value is unresolved symbolic token=" + value);
                }
            } else {
                if (name.startsWith(GMS_PROPERTY_PREFIX)) {
                    name = name.replaceFirst(GMS_PROPERTY_PREFIX_REGEXP, "");
                }
                // impossible to register handlers in a regular app before gms starts up.
                if (name.compareTo("ALIVEANDREADY_LOGGING") == 0) {
                    aliveAndReadyLoggingEnabled = Boolean.parseBoolean(value);
                } else if (name.compareTo("LISTENER_PORT") == 0) {
                    // special case mapping.  Glassfish Cluster property GMS_LISTENER_PORT maps to Grizzly Config Constants TCPSTARTPORT and TCPENDPORT.
                    configProps.put(GrizzlyConfigConstants.TCPSTARTPORT.toString(), value);
                    configProps.put(GrizzlyConfigConstants.TCPENDPORT.toString(), value);
                } else if (name.compareTo("TEST_FAILURE_RECOVERY") == 0) {
                    testFailureRecoveryHandler = Boolean.parseBoolean(value);
                } else if (ServiceProviderConfigurationKeys.DISCOVERY_URI_LIST.name().equals(name) && "generate".equals(value)) {
                    value = generateDiscoveryUriList();
                    configProps.put(name, value);
                } else {
                    // handle normal case.  one to one mapping.
                    configProps.put(name, value);
                    GMS_LOGGER.log(LogLevel.CONFIG, "processing cluster property name=" + name + " value= " + value);
                    if (!validateGMSProperty(name)) {
                        GMS_LOGGER.log(LogLevel.WARNING, GMS_EXCEPTION_CLUSTER_PROPERTY_ERROR, new Object[] { name, value, "" });
                    }
                }
            }
        }
    }
}
Also used : ServiceProviderConfigurationKeys(com.sun.enterprise.ee.cms.core.ServiceProviderConfigurationKeys) Property(org.jvnet.hk2.config.types.Property)

Example 7 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class AdminConsoleStartupService method postConstruct.

@Override
public void postConstruct() {
    if (adminConsoleAdapter == null) {
        // there may be no console in this environment.
        return;
    }
    /* This service must run only on the server where the console should run. Currently, that server is DAS. If and when
         *  the console becomes dis-associated with DAS, this logic will need to be modified.
         */
    if (!env.isDas())
        return;
    // FIXME : Use ServerTags, when this is finalized.
    Property initProp = adminService.getProperty("adminConsoleStartup");
    String initPropVal = "DEFAULT";
    if (initProp != null) {
        initPropVal = initProp.getValue();
        if (!(initPropVal.equals("ALWAYS") || initPropVal.equals("NEVER") || initPropVal.equals("DEFAULT"))) {
            initPropVal = "DEFAULT";
        }
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "AdminConsoleStartupService, console loading option is {0}", initPropVal);
    }
    if (initPropVal.equalsIgnoreCase("DEFAULT")) {
        handleDefault();
    } else if (initPropVal.equalsIgnoreCase("ALWAYS")) {
        handleHigh();
    }
}
Also used : Property(org.jvnet.hk2.config.types.Property)

Example 8 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class WebServiceReferenceManagerImpl method resolveWSReference.

public Object resolveWSReference(ServiceReferenceDescriptor desc, Context context) throws NamingException {
    // Taken from NamingManagerImpl.getClientServiceObject
    Class serviceInterfaceClass = null;
    Object returnObj = null;
    WsUtil wsUtil = new WsUtil();
    // Implementation for new lookup element in WebserviceRef
    InitialContext iContext = new InitialContext();
    if (desc.hasLookupName()) {
        return iContext.lookup(desc.getLookupName());
    }
    try {
        WSContainerResolver.set(desc);
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        serviceInterfaceClass = cl.loadClass(desc.getServiceInterface());
        resolvePortComponentLinks(desc);
        javax.xml.rpc.Service serviceDelegate = null;
        javax.xml.ws.Service jaxwsDelegate = null;
        Object injValue = null;
        if (desc.hasGeneratedServiceInterface() || desc.hasWsdlFile()) {
            String serviceImplName = desc.getServiceImplClassName();
            if (serviceImplName != null) {
                Class serviceImplClass = cl.loadClass(serviceImplName);
                serviceDelegate = (javax.xml.rpc.Service) serviceImplClass.newInstance();
            } else {
                // as the interface through DD
                if (javax.xml.ws.Service.class.isAssignableFrom(serviceInterfaceClass) && !javax.xml.ws.Service.class.equals(serviceInterfaceClass)) {
                    // OK - the interface class is indeed the generated service class; get an instance
                    injValue = initiateInstance(serviceInterfaceClass, desc);
                } else {
                    // interface, therefore I take the first one.
                    if (desc.isInjectable()) {
                        InjectionTarget target = desc.getInjectionTargets().iterator().next();
                        Class serviceType = null;
                        if (target.isFieldInjectable()) {
                            java.lang.reflect.Field f = target.getField();
                            if (f == null) {
                                String fName = target.getFieldName();
                                Class targetClass = cl.loadClass(target.getClassName());
                                try {
                                    f = targetClass.getDeclaredField(fName);
                                }// ignoring exception
                                 catch (java.lang.NoSuchFieldException nsfe) {
                                }
                            }
                            if (f != null) {
                                serviceType = f.getType();
                            }
                        }
                        if (target.isMethodInjectable()) {
                            Method m = target.getMethod();
                            if (m == null) {
                                String mName = target.getMethodName();
                                Class targetClass = cl.loadClass(target.getClassName());
                                try {
                                    m = targetClass.getDeclaredMethod(mName);
                                }// ignoring exception
                                 catch (java.lang.NoSuchMethodException nsfe) {
                                }
                            }
                            if (m != null && m.getParameterTypes().length == 1) {
                                serviceType = m.getParameterTypes()[0];
                            }
                        }
                        if (serviceType != null) {
                            Class loadedSvcClass = cl.loadClass(serviceType.getCanonicalName());
                            injValue = initiateInstance(loadedSvcClass, desc);
                        }
                    }
                }
                // Unable to get hold of generated service class -> try the Service.create avenue to get a Service
                if (injValue == null) {
                    // Here create the service with WSDL (overridden wsdl if wsdl-override is present)
                    // so that JAXWS runtime uses this wsdl @ runtime
                    javax.xml.ws.Service svc = javax.xml.ws.Service.create((new WsUtil()).privilegedGetServiceRefWsdl(desc), desc.getServiceName());
                    jaxwsDelegate = new JAXWSServiceDelegate(desc, svc, cl);
                }
            }
            if (desc.hasHandlers()) {
                // We need the service's ports to configure the
                // handler chain (since service-ref handler chain can
                // optionally specify handler-port association)
                // so create a configured service and call getPorts
                javax.xml.rpc.Service configuredService = wsUtil.createConfiguredService(desc);
                Iterator ports = configuredService.getPorts();
                wsUtil.configureHandlerChain(desc, serviceDelegate, ports, cl);
            }
            // check if this is a post 1.1 web service
            if (javax.xml.ws.Service.class.isAssignableFrom(serviceInterfaceClass)) {
                // This is a JAXWS based webservice client;
                // process handlers and mtom setting
                // moved test for handlers into wsUtil, in case
                // we have to add system handler
                javax.xml.ws.Service service = (injValue != null ? (javax.xml.ws.Service) injValue : jaxwsDelegate);
                if (service != null) {
                    // Now configure client side handlers
                    wsUtil.configureJAXWSClientHandlers(service, desc);
                }
                // the requested resource is not the service but one of its port.
                if (injValue != null && desc.getInjectionTargetType() != null) {
                    Class requestedPortType = service.getClass().getClassLoader().loadClass(desc.getInjectionTargetType());
                    ArrayList<WebServiceFeature> wsFeatures = getWebServiceFeatures(desc);
                    if (wsFeatures.size() > 0) {
                        injValue = service.getPort(requestedPortType, wsFeatures.toArray(new WebServiceFeature[wsFeatures.size()]));
                    } else {
                        injValue = service.getPort(requestedPortType);
                    }
                }
            }
        } else {
            // Generic service interface / no WSDL
            QName serviceName = desc.getServiceName();
            if (serviceName == null) {
                // ServiceFactory API requires a service-name.
                // However, 109 does not allow getServiceName() to be
                // called, so it's ok to use a dummy value.
                serviceName = new QName("urn:noservice", "servicename");
            }
            ServiceFactory serviceFac = ServiceFactory.newInstance();
            serviceDelegate = serviceFac.createService(serviceName);
        }
        // Create a proxy for the service object.
        // Get a proxy only in jaxrpc case because in jaxws the service class is not
        // an interface any more
        InvocationHandler handler = null;
        if (serviceDelegate != null) {
            handler = new ServiceInvocationHandler(desc, serviceDelegate, cl);
            returnObj = Proxy.newProxyInstance(cl, new Class[] { serviceInterfaceClass }, handler);
        } else if (jaxwsDelegate != null) {
            returnObj = jaxwsDelegate;
        } else if (injValue != null) {
            returnObj = injValue;
        }
    } catch (PrivilegedActionException pae) {
        logger.log(Level.WARNING, LogUtils.EXCEPTION_THROWN, pae);
        NamingException ne = new NamingException();
        ne.initCause(pae.getCause());
        throw ne;
    } catch (Exception e) {
        logger.log(Level.WARNING, LogUtils.EXCEPTION_THROWN, e);
        NamingException ne = new NamingException();
        ne.initCause(e);
        throw ne;
    } finally {
        WSContainerResolver.unset();
    }
    return returnObj;
}
Also used : ServiceFactory(javax.xml.rpc.ServiceFactory) java.lang.reflect(java.lang.reflect) Iterator(java.util.Iterator) NamingException(javax.naming.NamingException) PrivilegedActionException(java.security.PrivilegedActionException) QName(javax.xml.namespace.QName) Service(org.jvnet.hk2.annotations.Service) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) PrivilegedActionException(java.security.PrivilegedActionException) WebServiceException(javax.xml.ws.WebServiceException) WebServiceFeature(javax.xml.ws.WebServiceFeature)

Example 9 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class SetMonitoringServiceConfiguration method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport actionReport = context.getActionReport();
    config = targetUtil.getConfig(target);
    if (config != null) {
        monitoringService = config.getMonitoringService();
    } else {
        actionReport.setMessage("Cound not find target: " + target);
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {

            @Override
            public Object run(final MonitoringService monitoringServiceProxy) throws PropertyVetoException, TransactionFailure {
                if (monitoringEnabled != null) {
                    monitoringServiceProxy.setMonitoringEnabled(String.valueOf(monitoringEnabled));
                }
                if (mbeanEnabled != null) {
                    monitoringServiceProxy.setMbeanEnabled(String.valueOf(mbeanEnabled));
                }
                if (dtraceEnabled != null) {
                    monitoringServiceProxy.setDtraceEnabled(String.valueOf(dtraceEnabled));
                }
                if (amxEnabled != null) {
                    AMXConfiguration amxConfiguration = config.getExtensionByType(AMXConfiguration.class);
                    ConfigSupport.apply(new SingleConfigCode<AMXConfiguration>() {

                        @Override
                        public Object run(final AMXConfiguration amxConfigurationProxy) throws PropertyVetoException, TransactionFailure {
                            amxConfigurationProxy.setEnabled((String.valueOf(amxEnabled)));
                            return amxConfigurationProxy;
                        }
                    }, amxConfiguration);
                }
                actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
                return monitoringServiceProxy;
            }
        }, monitoringService);
    } catch (TransactionFailure ex) {
        logger.log(Level.WARNING, "Failed to execute the command set-monitoring-service-configuration: {0}", ex.getCause().getMessage());
        actionReport.setMessage(ex.getCause().getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) AMXConfiguration(fish.payara.admin.amx.config.AMXConfiguration) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ActionReport(org.glassfish.api.ActionReport) MonitoringService(com.sun.enterprise.config.serverbeans.MonitoringService)

Example 10 with Service

use of org.jvnet.hk2.annotations.Service in project Payara by payara.

the class DirectCreationTest method doTest.

public void doTest() throws TransactionFailure {
    AdminService service = habitat.getService(AdminService.class);
    ConfigBean serviceBean = (ConfigBean) ConfigBean.unwrap(service);
    Class<?>[] subTypes = null;
    try {
        subTypes = ConfigSupport.getSubElementsTypes(serviceBean);
    } catch (ClassNotFoundException e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    ConfigSupport support = getBaseServiceLocator().getService(ConfigSupport.class);
    assertNotNull("ConfigSupport not found", support);
    for (Class<?> subType : subTypes) {
        // TODO:  JL force compilation error to mark this probably edit point for grizzly config
        if (subType.getName().endsWith("DasConfig")) {
            Map<String, String> configChanges = new HashMap<String, String>();
            configChanges.put("dynamic-reload-enabled", "true");
            configChanges.put("autodeploy-dir", "funky-dir");
            support.createAndSet(serviceBean, (Class<? extends ConfigBeanProxy>) subType, configChanges);
            break;
        }
    }
    support.createAndSet(serviceBean, DasConfig.class, (List) null);
    List<AttributeChanges> profilerChanges = new ArrayList<AttributeChanges>();
    String[] values = { "-Xmx512m", "-RFtrq", "-Xmw24" };
    ConfigSupport.MultipleAttributeChanges multipleChanges = new ConfigSupport.MultipleAttributeChanges("jvm-options", values);
    String[] values1 = { "profile" };
    ConfigSupport.MultipleAttributeChanges multipleChanges1 = new ConfigSupport.MultipleAttributeChanges("name", values1);
    profilerChanges.add(multipleChanges);
    profilerChanges.add(multipleChanges1);
    support.createAndSet((ConfigBean) ConfigBean.unwrap(habitat.<JavaConfig>getService(JavaConfig.class)), Profiler.class, profilerChanges);
}
Also used : AdminService(com.sun.enterprise.config.serverbeans.AdminService) ConfigSupport(org.jvnet.hk2.config.ConfigSupport) AttributeChanges(org.jvnet.hk2.config.AttributeChanges) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConfigBean(org.jvnet.hk2.config.ConfigBean) JavaConfig(com.sun.enterprise.config.serverbeans.JavaConfig)

Aggregations

TransactionFailure (org.jvnet.hk2.config.TransactionFailure)34 PropertyVetoException (java.beans.PropertyVetoException)26 ActionReport (org.glassfish.api.ActionReport)25 Config (com.sun.enterprise.config.serverbeans.Config)21 Property (org.jvnet.hk2.config.types.Property)17 ArrayList (java.util.ArrayList)9 Properties (java.util.Properties)9 HealthCheckServiceConfiguration (fish.payara.nucleus.healthcheck.configuration.HealthCheckServiceConfiguration)7 Service (org.jvnet.hk2.annotations.Service)7 File (java.io.File)6 HashMap (java.util.HashMap)6 List (java.util.List)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 StuckThreadsChecker (fish.payara.nucleus.healthcheck.configuration.StuckThreadsChecker)4 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 ObservableBean (org.jvnet.hk2.config.ObservableBean)4 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)4 Transactions (org.jvnet.hk2.config.Transactions)4 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)4 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)4