Skip to content

Commit

Permalink
Merge pull request eclipse-ee4j#23889 from dmatej/nucleus-tests-6.x
Browse files Browse the repository at this point in the history
eclipse-ee4j#23507 Nucleus tests transformed to Admin tests
  • Loading branch information
arjantijms authored Apr 4, 2022
2 parents 00492b4 + 5662e66 commit 2be7140
Show file tree
Hide file tree
Showing 160 changed files with 7,535 additions and 6,963 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -138,7 +139,7 @@ public static void getPhysicalDestination(HandlerContext handlerCtx) {
Map valueMap = new HashMap();
try {
String objectName = getJmsDestinationObjectName(SUBTYPE_CONFIG, name, type);
AttributeList attributes = (AttributeList) JMXUtil.getMBeanServer().getAttributes(new ObjectName(objectName), ATTRS_CONFIG);
AttributeList attributes = JMXUtil.getMBeanServer().getAttributes(new ObjectName(objectName), ATTRS_CONFIG);
for (Attribute attribute : attributes.asList()) {
valueMap.put(attribute.getName(), (attribute.getValue() != null) ? attribute.getValue().toString() : null);
}
Expand Down Expand Up @@ -168,7 +169,7 @@ public static void getPhysicalDestinationStats(HandlerContext handlerCtx) {
insureJmsBrokerIsRunning();

String objectName = getJmsDestinationObjectName(SUBTYPE_MONITOR, name, type);
AttributeList attributes = (AttributeList) getMBeanServerConnection(target).getAttributes(new ObjectName(objectName), ATTRS_MONITOR);
AttributeList attributes = getMBeanServerConnection(target).getAttributes(new ObjectName(objectName), ATTRS_MONITOR);
ResourceBundle bundle = GuiUtil.getBundle("org.glassfish.jms.admingui.Strings");
statsList.add(createRow("Name", name, ""));
statsList.add(createRow("Type", type.substring(0, 1).toUpperCase(GuiUtil.guiLocale) + type.substring(1), ""));
Expand Down Expand Up @@ -208,12 +209,12 @@ public static void getPhysicalDestinations(HandlerContext handlerCtx) {
List<Map> selectedList = (List) handlerCtx.getInputValue("selectedRows");
boolean hasOrig = (selectedList == null || selectedList.size() == 0) ? false : true;

for (int i = 0; i < objectNames.length; i++) {
for (ObjectName objectName : objectNames) {
// getAttributes for the given objectName...
HashMap oneRow = new HashMap();
oneRow.put("name", objectNames[i].getKeyProperty(PROP_NAME).replaceAll("\"", ""));
oneRow.put("type", "t".equals(objectNames[i].getKeyProperty(PROP_DEST_TYPE)) ? "topic" : "queue");
oneRow.put("selected", (hasOrig) ? isSelected(objectNames[i].getKeyProperty(PROP_NAME), selectedList) : false);
oneRow.put("name", objectName.getKeyProperty(PROP_NAME).replaceAll("\"", ""));
oneRow.put("type", "t".equals(objectName.getKeyProperty(PROP_DEST_TYPE)) ? "topic" : "queue");
oneRow.put("selected", (hasOrig) ? isSelected(objectName.getKeyProperty(PROP_NAME), selectedList) : false);
result.add(oneRow);
}

Expand Down Expand Up @@ -287,7 +288,7 @@ public static void updatePhysicalDestination(HandlerContext handlerCtx) {
public static void deleteJMSDest(HandlerContext handlerCtx) {
// String configName = ((String) handlerCtx.getInputValue("targetName"));
List obj = (List) handlerCtx.getInputValue("selectedRows");
List<Map> selectedRows = (List) obj;
List<Map> selectedRows = obj;
try {
for (Map oneRow : selectedRows) {
String name = (String) oneRow.get("name");
Expand Down Expand Up @@ -403,7 +404,7 @@ protected static void buildAttributeList(AttributeList list, Map attrMap, String
list.add(new Attribute(ATTR_MAX_NUM_MSGS, Long.parseLong((String) attrMap.get(ATTR_MAX_NUM_MSGS))));
list.add(new Attribute(ATTR_MAX_BYTES_PER_MSG, Long.parseLong((String) attrMap.get(ATTR_MAX_BYTES_PER_MSG))));
list.add(new Attribute(ATTR_MAX_TOTAL_MSG_BYTES, Long.parseLong((String) attrMap.get(ATTR_MAX_TOTAL_MSG_BYTES))));
list.add(new Attribute(ATTR_LIMIT_BEHAVIOR, (String) attrMap.get(ATTR_LIMIT_BEHAVIOR)));
list.add(new Attribute(ATTR_LIMIT_BEHAVIOR, attrMap.get(ATTR_LIMIT_BEHAVIOR)));
list.add(new Attribute(ATTR_MAX_NUM_PRODUCERS, Integer.parseInt((String) attrMap.get(ATTR_MAX_NUM_PRODUCERS))));
if ("queue".equals(type)) {
list.add(new Attribute(ATTR_MAX_NUM_ACTIVE_CONSUMERS, Integer.parseInt((String) attrMap.get(ATTR_MAX_NUM_ACTIVE_CONSUMERS))));
Expand All @@ -413,7 +414,7 @@ protected static void buildAttributeList(AttributeList list, Map attrMap, String
list.add(new Attribute(ATTR_CONSUMER_FLOW_LIMIT, Long.parseLong((String) attrMap.get(ATTR_CONSUMER_FLOW_LIMIT))));
list.add(new Attribute(ATTR_USE_DMQ, Boolean.valueOf((String) attrMap.get(ATTR_USE_DMQ))));
list.add(new Attribute(ATTR_VALIDATE_XML_SCHEMA_ENABLED, Boolean.valueOf((String) attrMap.get(ATTR_VALIDATE_XML_SCHEMA_ENABLED))));
list.add(new Attribute(ATTR_XML_SCHEMA_URI_LIST, (String) attrMap.get(ATTR_XML_SCHEMA_URI_LIST)));
list.add(new Attribute(ATTR_XML_SCHEMA_URI_LIST, attrMap.get(ATTR_XML_SCHEMA_URI_LIST)));
}

protected static void insureJmsBrokerIsRunning() throws ConnectorRuntimeException {
Expand Down Expand Up @@ -444,14 +445,15 @@ private static MBeanServerConnection getMBeanServerConnection(String target) thr
}

PhysicalDestinations pd = new PhysicalDestinations();
MQJMXConnectorInfo mqInfo = pd.getConnectorInfo(target, configRef, habitat, domain);

return mqInfo.getMQMBeanServerConnection();
try (MQJMXConnectorInfo mqInfo = pd.createConnectorInfo(target, configRef, habitat, domain)) {
// fyi, the connection is just a description, not closeable.
return mqInfo.getMQMBeanServerConnection();
}
}

private static class PhysicalDestinations extends JMSDestination {
public MQJMXConnectorInfo getConnectorInfo(String target, String configName, ServiceLocator habitat, Domain domain) throws Exception {
return getMQJMXConnectorInfo(target, domain.getConfigNamed(configName), habitat.<ServerContext>getService(ServerContext.class),
public MQJMXConnectorInfo createConnectorInfo(String target, String configName, ServiceLocator habitat, Domain domain) throws Exception {
return createMQJMXConnectorInfo(target, domain.getConfigNamed(configName), habitat.<ServerContext>getService(ServerContext.class),
domain, habitat.<ConnectorRuntime>getService(ConnectorRuntime.class));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -236,7 +237,7 @@ public static AppClientContainer.Builder newBuilder(

private URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();

private Collection<EntityManagerFactory> emfs = null;
private final Collection<EntityManagerFactory> emfs = null;

// private boolean isJWS = false;

Expand Down Expand Up @@ -354,7 +355,7 @@ private void completePreparation(final Instrumentation inst) throws
* Allow pre-destroy handling to work on the main class during clean-up.
*/
cleanup.setInjectionManager(injectionManager,
clientMainClassSetting.clientMainClass);
ClientMainClassSetting.clientMainClass);

/*
* If this app client contains persistence unit refs, then initialize
Expand Down Expand Up @@ -459,9 +460,10 @@ public Map<Thread, StackTraceElement[]> run() {

private void cleanupWhenSafe() {
if (isEDTRunning()) {
final AtomicReference<Thread> edt = new AtomicReference<Thread>();
final AtomicReference<Thread> edt = new AtomicReference<>();
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
edt.set(Thread.currentThread());
}
Expand Down Expand Up @@ -498,7 +500,7 @@ private Method getMainMethod() throws NoSuchMethodException,
// String[] as the only argument
Method result = null;

result = clientMainClassSetting.getClientMainClass(
result = ClientMainClassSetting.getClientMainClass(
classLoader,
injectionManager,
invocationManager,
Expand Down Expand Up @@ -729,34 +731,34 @@ void setClassLoader(ACCClassLoader classLoader) {
*/
public interface Builder {

public AppClientContainer newContainer(URI archiveURI) throws Exception, UserError;
AppClientContainer newContainer(URI archiveURI) throws Exception, UserError;

public AppClientContainer newContainer(URI archiveURI,
AppClientContainer newContainer(URI archiveURI,
CallbackHandler callbackHandler,
String mainClassName,
String appName) throws Exception, UserError;

public AppClientContainer newContainer(URI archiveURI,
AppClientContainer newContainer(URI archiveURI,
CallbackHandler callbackHandler,
String mainClassName,
String appName,
boolean isTextAuth) throws Exception, UserError;



public AppClientContainer newContainer(Class mainClass) throws Exception, UserError;
AppClientContainer newContainer(Class mainClass) throws Exception, UserError;

public TargetServer[] getTargetServers();
TargetServer[] getTargetServers();

/**
* Adds an optional {@link MessageSecurityConfig} setting.
*
* @param msConfig the new MessageSecurityConfig
* @return the <code>Builder</code> instance
*/
public Builder addMessageSecurityConfig(final MessageSecurityConfig msConfig);
Builder addMessageSecurityConfig(final MessageSecurityConfig msConfig);

public List<MessageSecurityConfig> getMessageSecurityConfig();
List<MessageSecurityConfig> getMessageSecurityConfig();

/**
* Sets the optional authentication realm for the ACC.
Expand All @@ -767,9 +769,9 @@ public AppClientContainer newContainer(URI archiveURI,
* @param className name of the class which implements the realm
* @return the <code>Builder</code> instance
*/
public Builder authRealm(final String className);
Builder authRealm(final String className);

public AuthRealm getAuthRealm();
AuthRealm getAuthRealm();

// /**
// * Sets the callback handler the ACC will use when authentication is
Expand Down Expand Up @@ -802,9 +804,9 @@ public AppClientContainer newContainer(URI archiveURI,
* @param password password valid in the default realm on the server for the username
* @return the <code>Builder</code> instance
*/
public Builder clientCredentials(final String user, final char[] password);
Builder clientCredentials(final String user, final char[] password);

public ClientCredential getClientCredential();
ClientCredential getClientCredential();

/**
* Sets the optional client credentials and server-side realm to be used during
Expand All @@ -819,15 +821,15 @@ public AppClientContainer newContainer(URI archiveURI,
* @param realmName name of the realm on the server within which the credentials are valid
* @return the <code>Builder</code> instance
*/
public Builder clientCredentials(final String user, final char[] password, final String realm);
Builder clientCredentials(final String user, final char[] password, final String realm);

/**
* Sets the container-level Properties.
*
* @param containerProperties
* @return
*/
public Builder containerProperties(final Properties containerProperties);
Builder containerProperties(final Properties containerProperties);

/**
* Sets the container-level properties.
Expand All @@ -838,23 +840,23 @@ public AppClientContainer newContainer(URI archiveURI,
* @param containerProperties Property objects to use in setting the properties
* @return
*/
public Builder containerProperties(final List<Property> containerProperties);
Builder containerProperties(final List<Property> containerProperties);

/**
* Returns the container-level Properties.
* @return container-level properties
*/
public Properties getContainerProperties();
Properties getContainerProperties();

/**
* Sets the logger which the ACC should use as it runs.
*
* @param logger
* @return
*/
public Builder logger(final Logger logger);
Builder logger(final Logger logger);

public Logger getLogger();
Logger getLogger();

/**
* Sets whether the ACC should send the password to the server during
Expand All @@ -863,9 +865,9 @@ public AppClientContainer newContainer(URI archiveURI,
* @param sendPassword
* @return
*/
public Builder sendPassword(final boolean sendPassword);
Builder sendPassword(final boolean sendPassword);

public boolean getSendPassword();
boolean getSendPassword();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -17,23 +18,26 @@
package org.glassfish.ha.commands;

import com.sun.enterprise.config.serverbeans.Domain;
import java.util.*;

import jakarta.validation.constraints.Pattern;

import java.util.ArrayList;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
import org.glassfish.api.Param;
import org.glassfish.api.admin.AdminCommand;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.CommandLock;

import org.jvnet.hk2.annotations.Service;
import org.glassfish.hk2.api.PerLookup;

import jakarta.validation.constraints.Pattern;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.glassfish.api.admin.*;
import org.glassfish.api.admin.RestEndpoint;
import org.glassfish.api.admin.RestEndpoints;
import org.glassfish.ha.store.spi.BackingStoreFactoryRegistry;
import org.glassfish.hk2.api.PerLookup;
import org.jvnet.hk2.annotations.Service;

/**
* The list-persistence-types command lists different kinds of persistence options for session data
Expand All @@ -51,10 +55,12 @@
})
public class ListPersistenceTypesCommand implements AdminCommand {

@Param(name="type", optional=false, primary=false)
private static final String CONTAINER_TYPES = "(ejb|web)";

@Param(name = "type", optional = false, primary = false)
@I18n("list.persistence.types.container")
@Pattern(regexp = "(ejb|web)")
private String containerType = "";
@Pattern(regexp = CONTAINER_TYPES, message = "Valid values: " + CONTAINER_TYPES)
private final String containerType = "";

private Logger logger;
private static final String EOL = "\n";
Expand Down Expand Up @@ -89,7 +95,7 @@ public void execute(AdminCommandContext context) {
output = output.substring(0, output.length()-1);
}
Properties extraProperties = new Properties();
extraProperties.put("types", new ArrayList<String>(allPersistenceTypes));
extraProperties.put("types", new ArrayList<>(allPersistenceTypes));

report.setExtraProperties(extraProperties);
report.setMessage(output);
Expand Down
Loading

0 comments on commit 2be7140

Please sign in to comment.