Search in sources :

Example 6 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class GetMonitoringConfiguration method execute.

/**
 * Method that is invoked when the asadmin command is performed.
 *  Pretty prints the Monitoring Service Configuration values.
 * @param context
 */
@Override
public void execute(AdminCommandContext context) {
    Config config = targetUtil.getConfig(target);
    if (config == null) {
        context.getActionReport().setMessage("No such config name: " + targetUtil);
        context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    ActionReport actionReport = context.getActionReport();
    ActionReport notifiersReport = actionReport.addSubActionsReport();
    ActionReport attributeReport = actionReport.addSubActionsReport();
    ColumnFormatter attributeColumnFormatter = new ColumnFormatter(ATTRIBUTE_HEADERS);
    ColumnFormatter notifiersColumnFormatter = new ColumnFormatter(NOTIFIER_HEADERS);
    MonitoringServiceConfiguration monitoringConfig = config.getExtensionByType(MonitoringServiceConfiguration.class);
    List<ServiceHandle<BaseNotifierService>> allNotifierServiceHandles = habitat.getAllServiceHandles(BaseNotifierService.class);
    actionReport.appendMessage("Monitoring Service Configuration is enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getEnabled())) + "\n");
    actionReport.appendMessage("Monitoring Service Configuration has AMX enabled? " + prettyBool(Boolean.valueOf(monitoringConfig.getAmx())) + "\n");
    actionReport.appendMessage("Monitoring Service Configuration log frequency? " + monitoringConfig.getLogFrequency() + " " + monitoringConfig.getLogFrequencyUnit());
    actionReport.appendMessage(StringUtils.EOL);
    Map<String, Object> map = new HashMap<>();
    Properties extraProps = new Properties();
    map.put("enabled", monitoringConfig.getEnabled());
    map.put("amx", monitoringConfig.getAmx());
    map.put("logfrequency", monitoringConfig.getLogFrequency());
    map.put("logfrequencyunit", monitoringConfig.getLogFrequencyUnit());
    extraProps.put("jmxmonitoringConfiguration", map);
    List<Map<String, String>> monitoredAttributes = new ArrayList<>();
    for (MonitoredAttribute monitoredBean : monitoringConfig.getMonitoredAttributes()) {
        Object[] values = new Object[3];
        values[0] = monitoredBean.getObjectName();
        values[1] = monitoredBean.getAttributeName();
        values[2] = monitoredBean.getDescription();
        Map<String, String> monitoredAttribute = new HashMap<>();
        monitoredAttribute.put(monitoredBean.getObjectName(), monitoredBean.getAttributeName());
        monitoredAttributes.add(monitoredAttribute);
        attributeColumnFormatter.addRow(values);
    }
    // Cannot change key in line below - required for admingui propertyDescTable.inc
    extraProps.put("monitored-beans", monitoredAttributes);
    actionReport.setExtraProperties(extraProps);
    if (!monitoringConfig.getNotifierList().isEmpty()) {
        List<Class<Notifier>> notifierClassList = Lists.transform(monitoringConfig.getNotifierList(), new Function<Notifier, Class<Notifier>>() {

            @Override
            public Class<Notifier> apply(Notifier input) {
                return resolveNotifierClass(input);
            }
        });
        Properties notifierProps = new Properties();
        for (ServiceHandle<BaseNotifierService> serviceHandle : allNotifierServiceHandles) {
            Notifier notifier = monitoringConfig.getNotifierByType(serviceHandle.getService().getNotifierType());
            if (notifier != null) {
                ConfigView view = ConfigSupport.getImpl(notifier);
                NotifierConfigurationType annotation = view.getProxyType().getAnnotation(NotifierConfigurationType.class);
                if (notifierClassList.contains(view.<Notifier>getProxyType())) {
                    Object[] values = new Object[2];
                    values[0] = annotation.type();
                    values[1] = notifier.getEnabled();
                    notifiersColumnFormatter.addRow(values);
                    Map<String, Object> mapNotifiers = new HashMap<>(2);
                    mapNotifiers.put("notifierName", values[0]);
                    mapNotifiers.put("notifierEnabled", values[1]);
                    notifierProps.put("notifierList" + annotation.type(), mapNotifiers);
                }
            }
            actionReport.getExtraProperties().putAll(notifierProps);
        }
    }
    notifiersReport.setMessage(notifiersColumnFormatter.toString());
    notifiersReport.appendMessage(StringUtils.EOL);
    attributeReport.setMessage(attributeColumnFormatter.toString());
    attributeReport.appendMessage(StringUtils.EOL);
    actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : MonitoredAttribute(fish.payara.jmx.monitoring.configuration.MonitoredAttribute) HashMap(java.util.HashMap) ConfigView(org.jvnet.hk2.config.ConfigView) Config(com.sun.enterprise.config.serverbeans.Config) MonitoringServiceConfiguration(fish.payara.jmx.monitoring.configuration.MonitoringServiceConfiguration) ArrayList(java.util.ArrayList) ActionReport(org.glassfish.api.ActionReport) Properties(java.util.Properties) ColumnFormatter(com.sun.enterprise.util.ColumnFormatter) Notifier(fish.payara.nucleus.notification.configuration.Notifier) NotifierConfigurationType(fish.payara.nucleus.notification.configuration.NotifierConfigurationType) BaseNotifierService(fish.payara.nucleus.notification.service.BaseNotifierService) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class ConsoleClassLoader method findModuleClassLoader.

/**
 *	<p> This method find the <code>ClassLoader</code> associated with the
 *	    named module.</p>
 */
public static ClassLoader findModuleClassLoader(String moduleName) {
    // System.out.println("Find module ClassLoader: " + moduleName);
    // Get the ServletContext
    ServletContext servletCtx = (ServletContext) (FacesContext.getCurrentInstance().getExternalContext()).getContext();
    // Get the Habitat from the ServletContext
    ServiceLocator habitat = (ServiceLocator) servletCtx.getAttribute(HABITAT_ATTRIBUTE);
    // correct ClassLoader for the requested module (or null)
    return habitat.<ConsolePluginService>getService(ConsolePluginService.class).getModuleClassLoader(moduleName);
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ConsolePluginService(org.glassfish.admingui.plugin.ConsolePluginService) ServletContext(javax.servlet.ServletContext)

Example 8 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class DOLUtils method getModuleType.

/**
 * Utility method to retrieve a {@link ArchiveType} from a stringified module type.
 * Since {@link ArchiveType} is an extensible abstraction and implementations are plugged in via HK2 service
 * registry, this method returns null if HK2 service registry is not setup.
 *
 * If null is passed to this method, it returns null instead of returning an arbitrary ArchiveType or throwing
 * an exception.
 *
 * @param moduleType String equivalent of the module type being looked up. null is allowed.
 * @return the corresponding ArchiveType, null if no such module type exists or HK2 Service registry is not set up
 */
public static ArchiveType getModuleType(String moduleType) {
    if (moduleType == null) {
        return null;
    }
    final ServiceLocator services = Globals.getDefaultHabitat();
    ArchiveType result = null;
    // This method is called without HK2 being setup when dol unit tests are run, so protect against NPE.
    if (services != null) {
        result = services.getService(ArchiveType.class, moduleType);
    }
    return result;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ArchiveType(org.glassfish.api.deployment.archive.ArchiveType)

Example 9 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class CompositeUtil method createConstructor.

/**
 * This method creates the default constructor for the class. Default values are set for any @Attribute defined with
 * a defaultValue.
 */
private void createConstructor(ClassWriter cw, String className, Map<String, Map<String, Object>> properties) {
    MethodVisitor method = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    method.visitCode();
    method.visitVarInsn(ALOAD, 0);
    method.visitMethodInsn(INVOKESPECIAL, "org/glassfish/admin/rest/composite/RestModelImpl", "<init>", "()V");
    for (Map.Entry<String, Map<String, Object>> property : properties.entrySet()) {
        String fieldName = property.getKey();
        String defaultValue = (String) property.getValue().get("defaultValue");
        if (defaultValue != null && !defaultValue.isEmpty()) {
            setDefaultValue(method, className, fieldName, (Class<?>) property.getValue().get("type"), defaultValue);
        }
    }
    method.visitInsn(RETURN);
    method.visitMaxs(1, 1);
    method.visitEnd();
}
Also used : JsonString(javax.json.JsonString) Map(java.util.Map) ParameterMap(org.glassfish.api.admin.ParameterMap) HashMap(java.util.HashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MethodVisitor(org.glassfish.hk2.external.org.objectweb.asm.MethodVisitor)

Example 10 with Method

use of org.glassfish.hk2.external.org.objectweb.asm.commons.Method in project Payara by payara.

the class CompositeUtil method getModel.

/**
 * This method will return a generated concrete class that implements the interface requested, as well as any
 * interfaces intended to extend the base model interface.  Model extensions must be annotated with
 *
 * @param modelIface   The base interface for the desired data model
 * @return An instance of a concrete class implementing the requested interfaces
 * @throws Exception
 * @RestModelExtension, and must be compiled with rest-annotation-processor library on the compile classpath
 * for metadata generation.
 */
public synchronized <T> T getModel(Class<T> modelIface) {
    String className = modelIface.getName() + "Impl";
    if (!generatedClasses.containsKey(className)) {
        Map<String, Map<String, Object>> properties = new HashMap<String, Map<String, Object>>();
        Set<Class<?>> interfaces = getModelExtensions(modelIface);
        interfaces.add(modelIface);
        for (Class<?> iface : interfaces) {
            analyzeInterface(iface, properties);
        }
        ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        visitClass(classWriter, className, interfaces, properties);
        for (Map.Entry<String, Map<String, Object>> entry : properties.entrySet()) {
            String name = entry.getKey();
            final Map<String, Object> property = entry.getValue();
            Class<?> type = (Class<?>) property.get("type");
            createField(classWriter, name, type);
            createGettersAndSetters(classWriter, modelIface, className, name, property);
        }
        createConstructor(classWriter, className, properties);
        classWriter.visitEnd();
        Class<?> newClass;
        try {
            newClass = defineClass(modelIface, className, classWriter.toByteArray());
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        generatedClasses.put(className, newClass);
    }
    try {
        return (T) generatedClasses.get(className).newInstance();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : HashMap(java.util.HashMap) JsonString(javax.json.JsonString) ClassWriter(org.glassfish.hk2.external.org.objectweb.asm.ClassWriter) JsonException(javax.json.JsonException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) JsonObject(javax.json.JsonObject) Map(java.util.Map) ParameterMap(org.glassfish.api.admin.ParameterMap) HashMap(java.util.HashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Aggregations

MultiException (org.glassfish.hk2.api.MultiException)18 Method (java.lang.reflect.Method)16 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)12 GeneratorAdapter (org.glassfish.hk2.external.org.objectweb.asm.commons.GeneratorAdapter)8 Method (org.glassfish.hk2.external.org.objectweb.asm.commons.Method)8 PrivilegedActionException (java.security.PrivilegedActionException)7 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)6 URISyntaxException (java.net.URISyntaxException)6 ExecutionException (java.util.concurrent.ExecutionException)6 ResourceAdapterInternalException (javax.resource.spi.ResourceAdapterInternalException)6 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)6 File (java.io.File)5 HashMap (java.util.HashMap)5 ConfigModel (org.jvnet.hk2.config.ConfigModel)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Attribute (org.jvnet.hk2.config.Attribute)4 PropertyVetoException (java.beans.PropertyVetoException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashSet (java.util.HashSet)3