[GLASSFISH-19448] Cannot get the logs details to be displayed in the admin console logviewer Created: 15/Dec/12  Updated: 04/Jan/13  Resolved: 04/Jan/13

Status: Resolved
Project: glassfish
Component/s: logging
Affects Version/s: 4.0_b67_ms7
Fix Version/s: 4.0_b71

Type: Bug Priority: Critical
Reporter: Anissa Lam Assignee: sandeep.shrivastava
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by GLASSFISH-19447 Cannot get the list of log file names Closed

 Description   

The admin console uses the following REST endpoint to get the list of logs to be displayed in the log viewer.

http://localhost:4848/management/domain/view-log/details.json

However, this is now returning FAILURE as the status.
Debugging the code shows that the following lines is throwing the exception.

private String getWithType(
            String logFileName,
            long startIndex,
            boolean searchForward,
            int maximumNumberOfResults,
            long fromTime,
            long toTime,
            String logLevel, boolean onlyLevel, String anySearch, List<String> listOfModules,
            String instanceName,
            String type) throws IOException {
        if (habitat.getService(LogManager.class) == null) {
            //the logger service is not install, so we cannot rely on it.
            //return an error
            throw new IOException("The GlassFish LogManager Service is not available. Not installed?");
        }

The REST endpoint should return something like this:

{"records": [{"recordNumber":337,"loggedDateTimeInMS":1355531068978,"loggedLevel":"WARNING","productName":"glassfish3.1.2","loggerName":"org.apache.catalina.connector.Request","nameValuePairs":"_ThreadID=51;_ThreadName=Thread-2;","messageID":"PWC4011","Message":" Unable to set request character encoding to UTF-8 from context , because request parameters have already been read, or ServletRequest.getReader() has already been called"},{"recordNumber":336,"loggedDateTimeInMS":1355531051885,"loggedLevel":"WARNING","productName":"glassfish3.1.2","loggerName":"org.apache.catalina.connector.Request","nameValuePairs":"_ThreadID=80;_ThreadName=Thread-2;","messageID":"PWC4011","Message":" Unable to set request character encoding to UTF-8 from context , because request parameters have already been read, or ServletRequest.getReader() has already been called"}

Since we still need to support the old format, so the current resource to get the logs have to work like before.



 Comments   
Comment by sandeep.shrivastava [ 24/Dec/12 ]

There seems to be some issue with HK2 ServiceLocator in not being able to find the service. I created the following asadmin command to isolate the issue.

When the jar containing the asadmin command is dropped into the modules dir, the following is the trace of the execution. While the normal @Inject works OK the ServiceLocator injected using the @Context is not working as expected.

[sanshriv@adc6260176 glassfish3]$ bin/asadmin log-manager --help
NAME
log-manager

SYNOPSIS
Usage: log-manager [--usehabitat=false]

OPTIONS
--usehabitat

Command log-manager executed successfully.

[sanshriv@adc6260176 glassfish3]$ bin/asadmin log-manager
Logging props file=/scratch/sanshriv/software/oracle-glassfish/glassfish3/glassfish/domains/domain1/config/logging.properties
Log files=[server.log_2012-12-18T12-13-48, server.log]
Command log-manager executed successfully.

[sanshriv@adc6260176 glassfish3]$ bin/asadmin log-manager --useHabitat true
remote failure: java.lang.NullPointerException
Command log-manager failed.

The command source code used is reproduced below.

/*

  • Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
    */

package com.oracle.diagnostics.logging.commands;

import java.io.File;
import java.util.logging.Logger;

import javax.inject.Inject;
import javax.ws.rs.core.Context;

import org.glassfish.api.ActionReport;
import org.glassfish.api.Param;
import org.glassfish.api.admin.AdminCommand;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.ExecuteOn;
import org.glassfish.api.admin.FailurePolicy;
import org.glassfish.api.admin.RestEndpoint;
import org.glassfish.api.admin.RestEndpoints;
import org.glassfish.api.admin.RuntimeType;
import org.glassfish.api.admin.ServerEnvironment;
import org.glassfish.config.support.CommandTarget;
import org.glassfish.config.support.TargetType;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.hk2.api.ServiceLocator;
import org.jvnet.hk2.annotations.Service;

import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.server.logging.logviewer.backend.LogFilter;

@ExecuteOn(value =

{RuntimeType.INSTANCE}

, ifOffline = FailurePolicy.Error, ifNeverStarted = FailurePolicy.Error)
@Service(name = "log-manager")
@TargetType(

{CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER, CommandTarget.CLUSTERED_INSTANCE}

)
@PerLookup
@RestEndpoints(

{ @RestEndpoint(configBean=Domain.class, opType=RestEndpoint.OpType.POST, path="log-manager", description="Log Manager") }

)
public class LogManager implements AdminCommand {

private static Logger LOGGER = Logger.getLogger(LogManager.class.getName());

@Inject
ServerEnvironment env;

@Inject
Domain domain;

@Inject
org.glassfish.internal.api.LogManager logManager;

@Inject
LogFilter logFilter;

@Context
protected ServiceLocator habitat;

@Param(optional=true, defaultValue="false")
boolean useHabitat;

public void execute(AdminCommandContext context) {

final ActionReport report = context.getActionReport();

String instanceName = env.getInstanceName();
LOGGER.info("Running command log-manager on instance " + instanceName);

if (useHabitat)

{ logManager = habitat.getService(org.glassfish.internal.api.LogManager.class); }

File logFile;
try

{ logFile = logManager.getLoggingFile(); report.addSubActionsReport().appendMessage( "Logging props file="+logFile.getAbsolutePath()); report.addSubActionsReport().appendMessage( "Log files="+logFilter.getInstanceLogFileNames(instanceName)); report.setActionExitCode(ActionReport.ExitCode.SUCCESS); }

catch (Exception e)

{ report.setFailureCause(e); report.setActionExitCode(ActionReport.ExitCode.FAILURE); return; }

}

}

Comment by sandeep.shrivastava [ 24/Dec/12 ]

John,

Could you take a look at the ServiceLocator issue we are running into?

Another way to reproduce the issue is to invoke the logviwer in the console.

http://localhost:4848/common/logViewer/logViewer.jsf?instanceName=server&loglevel=INFO&viewResults=true

Thanks

Sandeep

Comment by jwells [ 02/Jan/13 ]

Where can I find this "LogManager.java" file? It does not appear to be in either open or closed workspace.

I can find a LogManager.java, but it is an interface in the org.glassfish.internal.api package and does not
seem to be related. Is this code you haven't checked in yet? In which case, could I get the LogManager.java
you are talking about?

Also, if normal @Inject works is there a reason you can't just use that rather than @Context habitat?

These are the sort of questions I have about this use case...

Comment by sandeep.shrivastava [ 02/Jan/13 ]

The org.glassfish.internal.api.LogManager interface is implemented by the com.sun.enterprise.server.logging.LogManagerService class in main/nucleus/core/logging module in the open source.

It is referred by the all/main/nucleus/admin/rest/rest-service module which is part of the Admin Console.

The classes in question are the org.glassfish.admin.rest.resources.custom.LogNamesResource and org.glassfish.admin.rest.resources.custom.StructuredLogViewerResource

This it where it is failing:

if (habitat.getService(LogManager.class) == null)

{ //the logger service is not install, so we cannot rely on it. //return an error throw new IOException("The GlassFish LogManager Service is not available. Not installed?"); }

It is not able to find the service either using @Inject or the habitat.

You can exercise this by launching the Admin console, selecting the server(Admin Server) node from the left navtree and clicking "View Log Files".

Comment by jwells [ 02/Jan/13 ]

Ah, the fact that you are using a Rest resource is the reason for this issue! The issue is that you are getting the Jersey service locator (which does not have the GlassFish services in it) and thus that ServiceLocator cannot see the GlassFish services.

If you need access to the the GlassFish services (which you do) you will need to use:

org.glassfish.internal.api.Globals.getDefaultBaseServiceLocator(), which will return the GlassFish ServiceLocator, which has the LogManager in it.

Note that this "Globals" class is going to be scrutinized the in following months for a better mechanism for applications (such as the console) to get the GlassFish ServiceLocator but that for now using Globals is the best mechanism.

Comment by jwells [ 02/Jan/13 ]

I realized I should re-open this an assign it back since I haven't actually fixed it lol!

Comment by sandeep.shrivastava [ 04/Jan/13 ]

This should be fixed with revision 57956.

Generated at Mon May 04 13:22:18 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.