Search in sources :

Example 96 with Property

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

the class CreateIiopListener 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);
    final ActionReport report = context.getActionReport();
    IiopService iiopService = config.getExtensionByType(IiopService.class);
    // check port uniqueness, only for same address
    for (IiopListener listener : iiopService.getIiopListener()) {
        if (listener.getId().equals(listener_id)) {
            String ls = localStrings.getLocalString("create.iiop.listener.duplicate", "IIOP Listener named {0} already exists.", listener_id);
            report.setMessage(ls);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
        if (listener.getAddress().trim().equals(listeneraddress) && listener.getPort().trim().equals((iiopport))) {
            String def = "Port [{0}] is already taken by another listener: " + "[{1}] for address [{2}], choose another port.";
            String ls = localStrings.getLocalString("create.iiop.listener.port.occupied", def, iiopport, listener.getId(), listeneraddress);
            report.setMessage(ls);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    try {
        ConfigSupport.apply(new SingleConfigCode<IiopService>() {

            @Override
            public Object run(IiopService param) throws PropertyVetoException, TransactionFailure {
                IiopListener newListener = param.createChild(IiopListener.class);
                newListener.setId(listener_id);
                newListener.setAddress(listeneraddress);
                newListener.setPort(iiopport);
                newListener.setSecurityEnabled(securityenabled.toString());
                newListener.setEnabled(enabled.toString());
                newListener.setLazyInit(Boolean.toString(lazyInit));
                // add properties
                if (properties != null) {
                    for (java.util.Map.Entry entry : properties.entrySet()) {
                        Property property = newListener.createChild(Property.class);
                        property.setName((String) entry.getKey());
                        property.setValue((String) entry.getValue());
                        newListener.getProperty().add(property);
                    }
                }
                param.getIiopListener().add(newListener);
                return newListener;
            }
        }, iiopService);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (TransactionFailure e) {
        String actual = e.getMessage();
        String def = "Creation of: " + listener_id + "failed because of: " + actual;
        String msg = localStrings.getLocalString("create.iiop.listener.fail", def, listener_id, actual);
        report.setMessage(msg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : IiopListener(org.glassfish.orb.admin.config.IiopListener) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Config(com.sun.enterprise.config.serverbeans.Config) ActionReport(org.glassfish.api.ActionReport) PropertyVetoException(java.beans.PropertyVetoException) Target(org.glassfish.internal.api.Target) CommandTarget(org.glassfish.config.support.CommandTarget) IiopService(org.glassfish.orb.admin.config.IiopService) Property(org.jvnet.hk2.config.types.Property)

Example 97 with Property

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

the class RestMonitoringService method changed.

@Override
public UnprocessedChangeEvents changed(PropertyChangeEvent[] propertyChangeEvents) {
    List<UnprocessedChangeEvent> unprocessedChanges = new ArrayList<>();
    boolean dynamicStart = false;
    for (PropertyChangeEvent propertyChangeEvent : propertyChangeEvents) {
        // Check that the property change event is for us.
        if (propertyChangeEvent.getSource().toString().equals("GlassFishConfigBean." + RestMonitoringConfiguration.class.getName()) && isCurrentInstanceMatchTarget(propertyChangeEvent)) {
            // Check if the property has actually changed
            if (!propertyChangeEvent.getOldValue().equals(propertyChangeEvent.getNewValue())) {
                // If the application hasn't attempted to start yet
                if (!startAttempted) {
                    // property, we don't need to compare it to the current value - it can only be true
                    if (propertyChangeEvent.getPropertyName().equals("enabled")) {
                        // Flag that we want to dynamically start Rest Monitoring
                        dynamicStart = true;
                    } else if (propertyChangeEvent.getPropertyName().equals("context-root")) {
                        // If we haven't attempted to start the app yet, grab the new context root
                        Config serverConfig = domain.getServerNamed(serverEnv.getInstanceName()).getConfig();
                        RestMonitoringEndpointDecider endpointDecider = new RestMonitoringEndpointDecider(serverConfig, restMonitoringConfiguration);
                        contextRoot = endpointDecider.getContextRoot();
                    }
                } else if (!propertyChangeEvent.getPropertyName().equals("security-enabled")) {
                    // If a startup has been attempted and the changed property isn't securityEnabled, throw an
                    // unprocessed change event as we need to restart
                    unprocessedChanges.add(new UnprocessedChangeEvent(propertyChangeEvent, "Rest monitoring redeployment required"));
                }
            }
        }
    }
    // This should only be true if rest monitoring was not enabled at startup, and we've just enabled the service
    if (dynamicStart) {
        loadApplication(true);
    }
    // If we need to restart, throw an unprocessed change event
    if (unprocessedChanges.isEmpty()) {
        return null;
    } else {
        return new UnprocessedChangeEvents(unprocessedChanges);
    }
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) Config(com.sun.enterprise.config.serverbeans.Config) ArrayList(java.util.ArrayList) RestMonitoringConfiguration(fish.payara.appserver.monitoring.rest.service.configuration.RestMonitoringConfiguration) RestMonitoringEndpointDecider(fish.payara.appserver.monitoring.rest.service.adapter.RestMonitoringEndpointDecider)

Example 98 with Property

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

the class ActiveJmsResourceAdapter method setValuesFromConfiguration.

private void setValuesFromConfiguration(String cfName, EjbMessageBeanDescriptor descriptor_) throws ConnectorRuntimeException {
    // todo: need to enable
    List<Property> ep = null;
    try {
        /*Resources rbeans = getAllResources();//ServerBeansFactory.getDomainBean(ctx).getResources();
            ConnectorResource res = (ConnectorResource)
                             rbeans.getResourceByName(ConnectorResource.class, cfName);*/
        String appName = descriptor_.getApplication().getAppName();
        String moduleName = ConnectorsUtil.getModuleName(descriptor_);
        ConnectorResource res = (ConnectorResource) ResourcesUtil.createInstance().getResource(cfName, appName, moduleName, ConnectorResource.class);
        if (res == null) {
            String msg = sm.getString("ajra.mdb_cf_not_created", cfName);
            throw new ConnectorRuntimeException(msg);
        }
        ConnectorConnectionPool ccp = (ConnectorConnectionPool) ResourcesUtil.createInstance().getResource(res.getPoolName(), appName, moduleName, ConnectorConnectionPool.class);
        // rbeans.getResourceByName(ConnectorConnectionPool.class, res.getPoolName());
        ep = ccp.getProperty();
    } catch (Exception ce) {
        String msg = sm.getString("ajra.mdb_cf_not_created", cfName);
        ConnectorRuntimeException cre = new ConnectorRuntimeException(msg);
        cre.initCause(ce);
        throw cre;
    }
    if (ep == null) {
        String msg = sm.getString("ajra.cannot_find_phy_dest");
        throw new ConnectorRuntimeException(msg);
    }
    for (int i = 0; i < ep.size(); i++) {
        Property prop = ep.get(i);
        String name = prop.getName();
        if (name.equals(MCFADDRESSLIST)) {
            name = ADDRESSLIST;
        }
        String val = prop.getValue();
        if (val == null || val.equals("")) {
            continue;
        }
        descriptor_.putRuntimeActivationConfigProperty(new EnvironmentProperty(name, val, null));
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) Property(org.jvnet.hk2.config.types.Property) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty) ConnectorResource(org.glassfish.connectors.config.ConnectorResource) MultiException(org.glassfish.hk2.api.MultiException) PrivilegedActionException(java.security.PrivilegedActionException) ExecutionException(java.util.concurrent.ExecutionException) ResourceAdapterInternalException(javax.resource.spi.ResourceAdapterInternalException) URISyntaxException(java.net.URISyntaxException) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)

Example 99 with Property

use of org.jvnet.hk2.config.ConfigModel.Property 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;
        // 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 100 with Property

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

the class ActiveJmsResourceAdapter method getBrokerInstanceName.

/**
 * Computes the instance name for the MQ broker.
 */
private static String getBrokerInstanceName(String asDomain, String asInstance, JmsService js) {
    List jmsProperties = js.getProperty();
    String instanceName = null;
    String suffix = null;
    if (jmsProperties != null) {
        for (int ii = 0; ii < jmsProperties.size(); ii++) {
            Property p = (Property) jmsProperties.get(ii);
            String name = p.getName();
            if (name.equals("instance-name"))
                instanceName = p.getValue();
            if (name.equals("instance-name-suffix"))
                suffix = p.getValue();
            if (name.equals("append-version") && Boolean.valueOf(p.getValue()).booleanValue()) {
                suffix = Version.getMajorVersion() + "_" + Version.getMinorVersion();
            }
        }
    }
    if (instanceName != null)
        return instanceName;
    if (asInstance.equals(DEFAULT_SERVER)) {
        instanceName = DEFAULT_MQ_INSTANCE;
    } else {
        instanceName = asDomain + "_" + asInstance;
    }
    if (suffix != null)
        instanceName = instanceName + "_" + suffix;
    return instanceName;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Property(org.jvnet.hk2.config.types.Property) EnvironmentProperty(com.sun.enterprise.deployment.EnvironmentProperty) ConnectorConfigProperty(com.sun.enterprise.deployment.ConnectorConfigProperty)

Aggregations

Property (org.jvnet.hk2.config.types.Property)149 PropertyVetoException (java.beans.PropertyVetoException)30 HashMap (java.util.HashMap)27 Properties (java.util.Properties)22 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)22 ArrayList (java.util.ArrayList)18 ActionReport (org.glassfish.api.ActionReport)17 Map (java.util.Map)15 File (java.io.File)13 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)12 Config (com.sun.enterprise.config.serverbeans.Config)11 List (java.util.List)11 AuthRealm (com.sun.enterprise.config.serverbeans.AuthRealm)10 HttpService (com.sun.enterprise.config.serverbeans.HttpService)9 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)9 Server (com.sun.enterprise.config.serverbeans.Server)8 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)8 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)8 Application (com.sun.enterprise.config.serverbeans.Application)7 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)7