use of com.sun.enterprise.config.serverbeans.JavaConfig 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
}
use of com.sun.enterprise.config.serverbeans.JavaConfig in project Payara by payara.
the class V2ToV3ConfigUpgrade method postConstruct.
@Override
public void postConstruct() {
// the 'prevent' defense
if (configs == null || configs.getConfig() == null || configs.getConfig().isEmpty()) {
return;
}
try {
for (Config c : configs.getConfig()) {
JavaConfig jc = c.getJavaConfig();
if (jc == null) {
continue;
}
// fix issues where each new config gets 2x, 3x, 4x the data
newJvmOptions.clear();
oldJvmOptions = Collections.unmodifiableList(jc.getJvmOptions());
doAdditions("server-config".equals(c.getName()));
doRemovals();
ConfigSupport.apply(new JavaConfigChanger(), jc);
}
} catch (Exception e) {
getLogger().log(Level.SEVERE, JVM_OPTION_UPGRADE_FAILURE, e);
throw new RuntimeException(e);
}
}
use of com.sun.enterprise.config.serverbeans.JavaConfig in project Payara by payara.
the class CreateProfiler method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the paramter names and the values the parameter values
*
* @param context information
*/
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
if (javaConfig.getProfiler() != null) {
System.out.println("profiler exists. Please delete it first");
report.setMessage(localStrings.getLocalString("create.profiler.alreadyExists", "profiler exists. Please delete it first"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
ConfigSupport.apply(new SingleConfigCode<JavaConfig>() {
public Object run(JavaConfig param) throws PropertyVetoException, TransactionFailure {
Profiler newProfiler = param.createChild(Profiler.class);
newProfiler.setName(name);
newProfiler.setClasspath(classpath);
newProfiler.setEnabled(enabled.toString());
newProfiler.setNativeLibraryPath(nativeLibraryPath);
if (properties != null) {
for (Map.Entry e : properties.entrySet()) {
Property prop = newProfiler.createChild(Property.class);
prop.setName((String) e.getKey());
prop.setValue((String) e.getValue());
newProfiler.getProperty().add(prop);
}
}
param.setProfiler(newProfiler);
return newProfiler;
}
}, javaConfig);
} catch (TransactionFailure e) {
report.setMessage(localStrings.getLocalString("create.profiler.fail", "{0} create failed ", name));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
use of com.sun.enterprise.config.serverbeans.JavaConfig in project Payara by payara.
the class CombinedJavaConfigSystemPropertyListener method changed.
/* force serial behavior; don't allow more than one thread to make a mess here */
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
// ignore a REMOVE and an ADD of the same value
final UnprocessedChangeEvents unp = ConfigSupport.sortAndDispatch(events, new Changed() {
@Override
public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tc, T t) {
NotProcessed result = null;
if (tc == Profiler.class) {
result = new NotProcessed("Creation or changes to a profiler require restart");
} else if (tc == Property.class && t.getParent().getClass() == JavaConfig.class) {
result = new NotProcessed("Addition of properties to JavaConfig requires restart");
} else if (tc == JavaConfig.class && t instanceof JavaConfig) {
final JavaConfig njc = (JavaConfig) t;
logFine(type, njc);
// we must *always* check the jvm options, no way to know except by comparing,
// plus we should send an appropriate message back for each removed/added item
final List<String> curProps = new ArrayList<String>(njc.getJvmOptions());
final boolean jvmOptionsWereChanged = !oldProps.equals(curProps);
final List<String> reasons = handle(oldProps, curProps);
oldProps = curProps;
// something in the JavaConfig itself changed
// to do this well, we ought to keep a list of attributes, so we can make a good message
// saying exactly which attribute what changed
final Map<String, String> curAttrs = collectAttrs(njc);
reasons.addAll(handleAttrs(oldAttrs, curAttrs));
oldAttrs = curAttrs;
result = reasons.isEmpty() ? null : new NotProcessed(CombinedJavaConfigSystemPropertyListener.toString(reasons));
} else if (tc == SystemProperty.class && t instanceof SystemProperty) {
final SystemProperty sp = (SystemProperty) t;
// check to see if this system property is for this instance
ConfigBeanProxy proxy = sp.getParent();
ConfigView p = ConfigSupport.getImpl(proxy);
if (p == ConfigSupport.getImpl(server) || p == ConfigSupport.getImpl(config) || (cluster != null && p == ConfigSupport.getImpl(cluster)) || p == ConfigSupport.getImpl(domain)) {
// check to see if this system property is referenced by any of the options
String pname = sp.getName();
if (referencesProperty(pname, oldProps) || referencesProperty(pname, oldAttrs.values())) {
result = new NotProcessed("The system-property, " + pname + ", that is referenced by the Java configuration, was modified");
}
}
if (type == TYPE.ADD || type == TYPE.CHANGE) {
// create-system-properties
if (proxy instanceof Domain) {
return addToDomain(sp);
} else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
return addToConfig(sp);
} else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
return addToCluster(sp);
} else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
return addToServer(sp);
}
} else if (type == TYPE.REMOVE) {
if (proxy instanceof Domain) {
return removeFromDomain(sp);
} else if (proxy instanceof Config && p == ConfigSupport.getImpl(config)) {
return removeFromConfig(sp);
} else if (cluster != null && proxy instanceof Cluster && p == ConfigSupport.getImpl(cluster)) {
return removeFromCluster(sp);
} else if (proxy instanceof Server && p == ConfigSupport.getImpl(server)) {
return removeFromServer(sp);
}
}
} else {
// ignore other changes that are reported
}
return result;
}
}, logger);
return unp;
}
use of com.sun.enterprise.config.serverbeans.JavaConfig in project Payara by payara.
the class TranslatedValuesTest method testJavaRoot.
@Test
public void testJavaRoot() {
if (System.getProperty("user.home").contains(File.separator)) {
JavaConfig config = getHabitat().getService(JavaConfig.class);
String javaRoot = config.getJavaHome();
assertTrue(javaRoot.indexOf(File.separatorChar) != -1);
}
assertTrue(true);
}
Aggregations