glassfish
  1. glassfish
  2. GLASSFISH-19448

Cannot get the logs details to be displayed in the admin console logviewer

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 4.0_b67_ms7
    • Fix Version/s: 4.0_b71
    • Component/s: logging
    • Labels:
      None

      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.

        Issue Links

          Activity

          Anissa Lam created issue -
          rajendra_inamdar made changes -
          Field Original Value New Value
          Assignee rajendra_inamdar [ rajendra_inamdar ] sandeep.shrivastava [ sandeep.shrivastava ]
          Hide
          sandeep.shrivastava added a comment -

          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; }

          }

          }

          Show
          sandeep.shrivastava added a comment - 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; } } }
          Hide
          sandeep.shrivastava added a comment -

          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

          Show
          sandeep.shrivastava added a comment - 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
          sandeep.shrivastava made changes -
          Assignee sandeep.shrivastava [ sandeep.shrivastava ] jwells [ jwells ]
          Hide
          jwells added a comment -

          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...

          Show
          jwells added a comment - 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...
          jwells made changes -
          Assignee jwells [ jwells ] sandeep.shrivastava [ sandeep.shrivastava ]
          Hide
          sandeep.shrivastava added a comment -

          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".

          Show
          sandeep.shrivastava added a comment - 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".
          Anissa Lam made changes -
          Link This issue is duplicated by GLASSFISH-19447 [ GLASSFISH-19447 ]
          jwells made changes -
          Assignee sandeep.shrivastava [ sandeep.shrivastava ] jwells [ jwells ]
          Hide
          jwells added a comment -

          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.

          Show
          jwells added a comment - 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.
          jwells made changes -
          Status Open [ 1 ] Closed [ 6 ]
          Resolution Works as designed [ 7 ]
          Hide
          jwells added a comment -

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

          Show
          jwells added a comment - I realized I should re-open this an assign it back since I haven't actually fixed it lol!
          jwells made changes -
          Resolution Works as designed [ 7 ]
          Status Closed [ 6 ] Reopened [ 4 ]
          Assignee jwells [ jwells ] sandeep.shrivastava [ sandeep.shrivastava ]
          Hide
          sandeep.shrivastava added a comment -

          This should be fixed with revision 57956.

          Show
          sandeep.shrivastava added a comment - This should be fixed with revision 57956.
          sandeep.shrivastava made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Fix Version/s 4.0_b71 [ 16100 ]
          Resolution Fixed [ 1 ]

            People

            • Assignee:
              sandeep.shrivastava
              Reporter:
              Anissa Lam
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: