Search in sources :

Example 26 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class TestSnmpNotifier method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    SnmpNotifierConfiguration snmpConfig = config.getExtensionByType(SnmpNotifierConfiguration.class);
    if (community == null) {
        community = snmpConfig.getCommunity();
    }
    if (oid == null) {
        oid = snmpConfig.getOid();
    }
    if (version == null) {
        version = snmpConfig.getVersion();
    }
    if (hostName == null) {
        hostName = snmpConfig.getHost();
    }
    if (port == null) {
        port = snmpConfig.hashCode();
    }
    // prepare SNMP message
    SnmpNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    SnmpMessageQueue queue = new SnmpMessageQueue();
    queue.addMessage(new SnmpMessage(event, event.getSubject(), event.getMessage()));
    SnmpNotifierConfigurationExecutionOptions options = new SnmpNotifierConfigurationExecutionOptions();
    options.setCommunity(community);
    options.setOid(oid);
    options.setVersion(version);
    options.setHost(hostName);
    options.setPort(port);
    SnmpNotificationRunnable notifierRun = null;
    try {
        TransportMapping transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        CommunityTarget cTarget = new CommunityTarget();
        cTarget.setCommunity(new OctetString(options.getCommunity()));
        int snmpVersion = SnmpNotifierService.decideOnSnmpVersion(options.getVersion());
        cTarget.setVersion(snmpVersion);
        cTarget.setAddress(new UdpAddress(options.getHost() + SnmpNotifierService.ADDRESS_SEPARATOR + options.getPort()));
        notifierRun = new SnmpNotificationRunnable(queue, options, snmp, cTarget, snmpVersion);
    } catch (IOException e) {
        Logger.getLogger(TestSnmpNotifier.class.getCanonicalName()).log(Level.SEVERE, "Error occurred while creating UDP transport", e);
        actionReport.setMessage("Error occurred while creating UDP transport");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } catch (InvalidSnmpVersion invalidSnmpVersion) {
        Logger.getLogger(TestSnmpNotifier.class.getCanonicalName()).log(Level.SEVERE, "Error occurred while configuring SNMP version: " + invalidSnmpVersion.getMessage());
        actionReport.setMessage("Error occurred while configuring SNMP version: " + invalidSnmpVersion.getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
    // set up logger to store result
    Logger logger = Logger.getLogger(SnmpNotificationRunnable.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler(10);
    bqh.setLevel(Level.FINE);
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.FINE);
    logger.addHandler(bqh);
    // send message, this occurs in its own thread
    Thread notifierThread = new Thread(notifierRun, "test-snmp-notifier-thread");
    notifierThread.start();
    try {
        notifierThread.join();
    } catch (InterruptedException ex) {
        Logger.getLogger(TestSnmpNotifier.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        logger.setLevel(oldLevel);
    }
    LogRecord message = bqh.poll();
    bqh.clear();
    if (message == null) {
        // something's gone wrong
        Logger.getLogger(TestSnmpNotifier.class.getName()).log(Level.SEVERE, "Failed to send SNMP message");
        actionReport.setMessage("Failed to send SNMP message");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } else {
        actionReport.setMessage(message.getMessage());
        if (message.getLevel() == Level.FINE) {
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
}
Also used : OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Config(com.sun.enterprise.config.serverbeans.Config) TransportMapping(org.snmp4j.TransportMapping) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) RestEndpoint(org.glassfish.api.admin.RestEndpoint) InvalidSnmpVersion(fish.payara.notification.snmp.exception.InvalidSnmpVersion) BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) LogRecord(java.util.logging.LogRecord) Snmp(org.snmp4j.Snmp) Level(java.util.logging.Level) CommunityTarget(org.snmp4j.CommunityTarget)

Example 27 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class TestXmppNotifier method execute.

@Override
public void execute(AdminCommandContext context) {
    ActionReport actionReport = context.getActionReport();
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config named: " + target);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    XmppNotifierConfiguration xmppConfig = config.getExtensionByType(XmppNotifierConfiguration.class);
    if (hostName == null) {
        hostName = xmppConfig.getHost();
    }
    if (port == null) {
        port = Integer.parseInt(xmppConfig.getPort());
    }
    if (serviceName == null) {
        serviceName = xmppConfig.getServiceName();
    }
    if (username == null) {
        username = xmppConfig.getUsername();
    }
    if (password == null) {
        password = xmppConfig.getPassword();
    }
    if (securityDisabled == null) {
        securityDisabled = Boolean.valueOf(xmppConfig.getSecurityDisabled());
    }
    if (roomId == null) {
        roomId = xmppConfig.getRoomId();
    }
    // prepare xmpp message
    XmppNotificationEvent event = factory.buildNotificationEvent(SUBJECT, MESSAGE);
    event.setEventType(SUBJECT);
    XmppMessageQueue queue = new XmppMessageQueue();
    queue.addMessage(new XmppMessage(event, event.getSubject(), event.getMessage()));
    XmppNotifierConfigurationExecutionOptions options = new XmppNotifierConfigurationExecutionOptions();
    options.setHost(hostName);
    options.setPort(port);
    options.setServiceName(serviceName);
    if (!Strings.isNullOrEmpty(username)) {
        options.setUsername(username);
    }
    if (!Strings.isNullOrEmpty(password)) {
        options.setPassword(password);
    }
    options.setSecurityDisabled(securityDisabled);
    options.setRoomId(roomId);
    XMPPTCPConnection connection = null;
    try {
        // Create connection
        XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder().setSecurityMode(options.getSecurityDisabled() ? ConnectionConfiguration.SecurityMode.disabled : ConnectionConfiguration.SecurityMode.required).setServiceName(options.getServiceName()).setHost(options.getHost()).setPort(options.getPort()).build();
        connection = new XMPPTCPConnection(configuration);
        connection.connect();
        if (options.getUsername() != null && options.getPassword() != null) {
            connection.login(options.getUsername(), options.getPassword());
        } else {
            connection.login();
        }
    } catch (SmackException | IOException | XMPPException ex) {
        actionReport.setMessage(ex.getMessage());
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        queue.resetQueue();
        return;
    }
    XmppNotificationRunnable notifierRun = new XmppNotificationRunnable(queue, options, connection);
    // set up logger to store result
    Logger logger = Logger.getLogger(XmppNotificationRunnable.class.getCanonicalName());
    BlockingQueueHandler bqh = new BlockingQueueHandler();
    bqh.setLevel(Level.FINE);
    Level oldLevel = logger.getLevel();
    logger.setLevel(Level.FINE);
    logger.addHandler(bqh);
    // send message, this occurs in its own thread
    Thread notifierThread = new Thread(notifierRun, "test-xmpp-notifier-thread");
    notifierThread.start();
    try {
        notifierThread.join();
    } catch (InterruptedException ex) {
        Logger.getLogger(TestXmppNotifier.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        connection.disconnect();
        logger.setLevel(oldLevel);
    }
    LogRecord message = bqh.poll();
    bqh.clear();
    logger.removeHandler(bqh);
    if (message == null) {
        // something's gone wrong
        Logger.getGlobal().log(Level.SEVERE, "Failed to send XMPP message");
        actionReport.setMessage("Failed to send XMPP message");
        actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
    } else {
        actionReport.setMessage(message.getMessage());
        if (message.getLevel() == Level.FINE) {
            actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        } else {
            actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
        }
    }
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) Config(com.sun.enterprise.config.serverbeans.Config) SmackException(org.jivesoftware.smack.SmackException) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) IOException(java.io.IOException) ActionReport(org.glassfish.api.ActionReport) Logger(java.util.logging.Logger) BlockingQueueHandler(fish.payara.nucleus.notification.BlockingQueueHandler) LogRecord(java.util.logging.LogRecord) Level(java.util.logging.Level) XMPPException(org.jivesoftware.smack.XMPPException)

Example 28 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class IIOPUtils method postConstruct.

// private GlassFishORBManager gfORBMgr;
public void postConstruct() {
    processType = processEnv.getProcessType();
    if (processEnv.getProcessType().isServer()) {
        Config c = services.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
        iiopService = c.getExtensionByType(IiopService.class);
        final Collection<ThreadPool> threadPool = c.getThreadPools().getThreadPool();
        final Collection<NetworkListener> listeners = allByContract(NetworkListener.class);
        final Set<String> names = new TreeSet<String>();
        threadPools = new ArrayList<ThreadPool>();
        for (NetworkListener listener : listeners) {
            names.add(listener.getThreadPool());
        }
        for (ThreadPool pool : threadPool) {
            if (!names.contains(pool.getName())) {
                threadPools.add(pool);
            }
        }
        serverRefs = allByContract(ServerRef.class);
    }
    IIOPUtils.initMe(this);
}
Also used : Config(com.sun.enterprise.config.serverbeans.Config) IiopService(org.glassfish.orb.admin.config.IiopService) TreeSet(java.util.TreeSet) ThreadPool(org.glassfish.grizzly.config.dom.ThreadPool) ServerRef(com.sun.enterprise.config.serverbeans.ServerRef) NetworkListener(org.glassfish.grizzly.config.dom.NetworkListener)

Example 29 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class DeleteIiopListener method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the parameter names and the values the parameter values
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final Target targetUtil = services.getService(Target.class);
    final Config config = targetUtil.getConfig(target);
    ActionReport report = context.getActionReport();
    IiopService iiopService = config.getExtensionByType(IiopService.class);
    if (!isIIOPListenerExists(iiopService)) {
        report.setMessage(localStrings.getLocalString("delete.iiop.listener" + ".notexists", "IIOP Listener {0} does not exist.", listener_id));
        report.setActionExitCode(ExitCode.FAILURE);
        return;
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<IiopService>() {

            @Override
            public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
                List<IiopListener> listenerList = param.getIiopListener();
                for (IiopListener listener : listenerList) {
                    String currListenerId = listener.getId();
                    if (currListenerId != null && currListenerId.equals(listener_id)) {
                        listenerList.remove(listener);
                        break;
                    }
                }
                return listenerList;
            }
        }, iiopService);
        report.setActionExitCode(ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        String actual = e.getMessage();
        report.setMessage(localStrings.getLocalString("delete.iiop.listener.fail", "failed", listener_id, actual));
        report.setActionExitCode(ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) IiopListener(org.glassfish.orb.admin.config.IiopListener) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) Config(com.sun.enterprise.config.serverbeans.Config) IiopService(org.glassfish.orb.admin.config.IiopService) List(java.util.List) ActionReport(org.glassfish.api.ActionReport)

Example 30 with Config

use of com.sun.enterprise.config.serverbeans.Config in project Payara by payara.

the class JdbcRecoveryResourceHandler method loadXAResourcesAndItsConnections.

/**
 * {@inheritDoc}
 */
@Override
public void loadXAResourcesAndItsConnections(List xaresList, List connList) {
    // Done so as to initialize connectors-runtime before loading jdbc-resources. need a better way ?
    ConnectorRuntime crt = connectorRuntimeProvider.get();
    Collection<JdbcResource> jdbcResources = getAllJdbcResources();
    if (jdbcResources == null || jdbcResources.size() == 0) {
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest("loadXAResourcesAndItsConnections : no resources");
        }
        return;
    }
    List<JdbcConnectionPool> jdbcPools = new ArrayList<JdbcConnectionPool>();
    for (Resource resource : jdbcResources) {
        JdbcResource jdbcResource = (JdbcResource) resource;
        if (getResourcesUtil().isEnabled(jdbcResource)) {
            ResourceInfo resourceInfo = ConnectorsUtil.getResourceInfo(jdbcResource);
            JdbcConnectionPool pool = JdbcResourcesUtil.createInstance().getJdbcConnectionPoolOfResource(resourceInfo);
            if (pool != null && "javax.sql.XADataSource".equals(pool.getResType())) {
                jdbcPools.add(pool);
            }
            if (_logger.isLoggable(Level.FINE)) {
                _logger.fine("JdbcRecoveryResourceHandler:: loadXAResourcesAndItsConnections :: " + "adding : " + (jdbcResource.getPoolName()));
            }
        }
    }
    loadAllJdbcResources();
    // Read from the transaction-service , if the replacement of
    // Vendor XAResource class with our version required.
    // If yes, put the mapping in the xaresourcewrappers properties.
    Properties XAResourceWrappers = new Properties();
    XAResourceWrappers.put("oracle.jdbc.xa.client.OracleXADataSource", "com.sun.enterprise.transaction.jts.recovery.OracleXAResource");
    Config c = habitat.getService(Config.class, ServerEnvironment.DEFAULT_INSTANCE_NAME);
    txService = c.getExtensionByType(TransactionService.class);
    List<Property> properties = txService.getProperty();
    if (properties != null) {
        for (Property property : properties) {
            String name = property.getName();
            String value = property.getValue();
            if (name.equals("oracle-xa-recovery-workaround")) {
                if ("false".equals(value)) {
                    XAResourceWrappers.remove("oracle.jdbc.xa.client.OracleXADataSource");
                }
            } else if (name.equals("sybase-xa-recovery-workaround")) {
                if (value.equals("true")) {
                    XAResourceWrappers.put("com.sybase.jdbc2.jdbc.SybXADataSource", "com.sun.enterprise.transaction.jts.recovery.SybaseXAResource");
                }
            }
        }
    }
    for (JdbcConnectionPool jdbcConnectionPool : jdbcPools) {
        if (jdbcConnectionPool.getResType() == null || jdbcConnectionPool.getName() == null || !jdbcConnectionPool.getResType().equals("javax.sql.XADataSource")) {
            if (_logger.isLoggable(Level.FINEST)) {
                _logger.finest("skipping pool : " + jdbcConnectionPool.getName());
            }
            continue;
        }
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.finest(" using pool : " + jdbcConnectionPool.getName());
        }
        PoolInfo poolInfo = ConnectorsUtil.getPoolInfo(jdbcConnectionPool);
        try {
            String[] dbUserPassword = getdbUserPasswordOfJdbcConnectionPool(jdbcConnectionPool);
            String dbUser = dbUserPassword[0];
            String dbPassword = dbUserPassword[1];
            if (dbPassword == null) {
                dbPassword = "";
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, "datasource.xadatasource_nullpassword_error", poolInfo);
                }
            }
            if (dbUser == null) {
                dbUser = "";
                if (_logger.isLoggable(Level.FINEST)) {
                    _logger.log(Level.FINEST, "datasource.xadatasource_nulluser_error", poolInfo);
                }
            }
            ManagedConnectionFactory fac = crt.obtainManagedConnectionFactory(poolInfo);
            Subject subject = new Subject();
            PasswordCredential pc = new PasswordCredential(dbUser, dbPassword.toCharArray());
            pc.setManagedConnectionFactory(fac);
            Principal prin = new ResourcePrincipal(dbUser, dbPassword);
            subject.getPrincipals().add(prin);
            subject.getPrivateCredentials().add(pc);
            ManagedConnection mc = fac.createManagedConnection(subject, null);
            connList.add(mc);
            try {
                XAResource xares = mc.getXAResource();
                if (xares != null) {
                    // See if a wrapper class for the vendor XADataSource is
                    // specified if yes, replace the XAResouce class of database
                    // vendor with our own version
                    String datasourceClassname = jdbcConnectionPool.getDatasourceClassname();
                    String wrapperclass = (String) XAResourceWrappers.get(datasourceClassname);
                    if (wrapperclass != null) {
                        // need to load wrapper class provided by "transactions" module.
                        // Using connector-class-loader so as to get access to "transaction" module.
                        XAResourceWrapper xaresWrapper = null;
                        xaresWrapper = (XAResourceWrapper) crt.getConnectorClassLoader().loadClass(wrapperclass).newInstance();
                        xaresWrapper.init(mc, subject);
                        if (_logger.isLoggable(Level.FINEST)) {
                            _logger.finest("adding resource " + poolInfo + " -- " + xaresWrapper);
                        }
                        xaresList.add(xaresWrapper);
                    } else {
                        if (_logger.isLoggable(Level.FINEST)) {
                            _logger.finest("adding resource " + poolInfo + " -- " + xares);
                        }
                        xaresList.add(xares);
                    }
                }
            } catch (ResourceException ex) {
                _logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
                }
            // ignored. Not at XA_TRANSACTION level
            }
        } catch (Exception ex) {
            _logger.log(Level.WARNING, "datasource.xadatasource_error", poolInfo);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "datasource.xadatasource_error_excp", ex);
            }
        }
    }
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) PasswordCredential(javax.resource.spi.security.PasswordCredential) Properties(java.util.Properties) XAResourceWrapper(com.sun.enterprise.transaction.api.XAResourceWrapper) ManagedConnection(javax.resource.spi.ManagedConnection) ResourceException(javax.resource.ResourceException) Property(org.jvnet.hk2.config.types.Property) ResourceInfo(org.glassfish.resourcebase.resources.api.ResourceInfo) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) TransactionService(com.sun.enterprise.transaction.config.TransactionService) XAResource(javax.transaction.xa.XAResource) Resource(com.sun.enterprise.config.serverbeans.Resource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Subject(javax.security.auth.Subject) ResourceException(javax.resource.ResourceException) NamingException(javax.naming.NamingException) ManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory) XAResource(javax.transaction.xa.XAResource) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ResourcePrincipal(com.sun.enterprise.deployment.ResourcePrincipal) Principal(java.security.Principal) ConnectorRuntime(com.sun.appserv.connectors.internal.api.ConnectorRuntime)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)152 ActionReport (org.glassfish.api.ActionReport)73 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)50 PropertyVetoException (java.beans.PropertyVetoException)34 Target (org.glassfish.internal.api.Target)31 CommandTarget (org.glassfish.config.support.CommandTarget)30 Properties (java.util.Properties)28 NetworkConfig (org.glassfish.grizzly.config.dom.NetworkConfig)23 Protocol (org.glassfish.grizzly.config.dom.Protocol)20 HashMap (java.util.HashMap)17 Server (com.sun.enterprise.config.serverbeans.Server)15 NetworkListener (org.glassfish.grizzly.config.dom.NetworkListener)15 Logger (java.util.logging.Logger)14 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)13 Protocols (org.glassfish.grizzly.config.dom.Protocols)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 BlockingQueueHandler (fish.payara.nucleus.notification.BlockingQueueHandler)10 Level (java.util.logging.Level)10 LogRecord (java.util.logging.LogRecord)10