- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.6k
 
[grid] Add Node session-history endpoint and write to local file for other utility to consume #15879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            VietND96
  wants to merge
  7
  commits into
  trunk
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
node-status-to-file
  
      
      
   
  
    
  
  
  
 
  
      
    base: trunk
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    [grid] Add Node session-history endpoint and write to local file for other utility to consume #15879
Changes from 2 commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      830b966
              
                [grid] Add Node session-history endpoint and write to local file for …
              
              
                VietND96 9436e06
              
                Fix tests
              
              
                VietND96 471f17f
              
                Suggestion: Add missing write permission
              
              
                VietND96 b182d49
              
                Suggestion: Use static empty list
              
              
                VietND96 b9c2a15
              
                Run format
              
              
                VietND96 0b19339
              
                Run format
              
              
                VietND96 93f6f3e
              
                Merge branch 'trunk' into node-status-to-file
              
              
                VietND96 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            66 changes: 66 additions & 0 deletions
          
          66 
        
  java/src/org/openqa/selenium/grid/data/SessionHistoryEntry.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Licensed to the Software Freedom Conservancy (SFC) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The SFC licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| 
     | 
||
| package org.openqa.selenium.grid.data; | ||
| 
     | 
||
| import java.time.Instant; | ||
| import java.util.Objects; | ||
| import org.openqa.selenium.internal.Require; | ||
| import org.openqa.selenium.remote.SessionId; | ||
| 
     | 
||
| public class SessionHistoryEntry { | ||
| private final SessionId sessionId; | ||
| private final Instant startTime; | ||
| private Instant stopTime; | ||
| 
     | 
||
| public SessionHistoryEntry(SessionId sessionId, Instant startTime, Instant stopTime) { | ||
| this.sessionId = Require.nonNull("Session ID", sessionId); | ||
| this.startTime = Require.nonNull("Start time", startTime); | ||
| this.stopTime = stopTime; // Can be null for ongoing sessions | ||
| } | ||
| 
     | 
||
| public SessionId getSessionId() { | ||
| return sessionId; | ||
| } | ||
| 
     | 
||
| public Instant getStartTime() { | ||
| return startTime; | ||
| } | ||
| 
     | 
||
| public Instant getStopTime() { | ||
| return stopTime; | ||
| } | ||
| 
     | 
||
| public void setStopTime(Instant stopTime) { | ||
| this.stopTime = stopTime; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (!(o instanceof SessionHistoryEntry)) return false; | ||
| SessionHistoryEntry that = (SessionHistoryEntry) o; | ||
| return Objects.equals(sessionId, that.sessionId) | ||
| && Objects.equals(startTime, that.startTime) | ||
| && Objects.equals(stopTime, that.stopTime); | ||
| } | ||
| 
     | 
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(sessionId, startTime, stopTime); | ||
| } | ||
| } | 
        
          
          
            40 changes: 40 additions & 0 deletions
          
          40 
        
  java/src/org/openqa/selenium/grid/data/SessionStartedEvent.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Licensed to the Software Freedom Conservancy (SFC) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The SFC licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| 
     | 
||
| package org.openqa.selenium.grid.data; | ||
| 
     | 
||
| import java.util.function.Consumer; | ||
| import org.openqa.selenium.events.Event; | ||
| import org.openqa.selenium.events.EventListener; | ||
| import org.openqa.selenium.events.EventName; | ||
| import org.openqa.selenium.internal.Require; | ||
| import org.openqa.selenium.remote.SessionId; | ||
| 
     | 
||
| public class SessionStartedEvent extends Event { | ||
| 
     | 
||
| private static final EventName SESSION_STARTED = new EventName("session-started"); | ||
| 
     | 
||
| public SessionStartedEvent(SessionId id) { | ||
| super(SESSION_STARTED, id); | ||
| } | ||
| 
     | 
||
| public static EventListener<SessionId> listener(Consumer<SessionId> handler) { | ||
| Require.nonNull("Handler", handler); | ||
| 
     | 
||
| return new EventListener<>(SESSION_STARTED, SessionId.class, handler); | ||
| } | ||
| } | 
        
          
          
            45 changes: 45 additions & 0 deletions
          
          45 
        
  java/src/org/openqa/selenium/grid/node/GetNodeSessionHistory.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Licensed to the Software Freedom Conservancy (SFC) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The SFC licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| 
     | 
||
| package org.openqa.selenium.grid.node; | ||
| 
     | 
||
| import static org.openqa.selenium.remote.http.Contents.asJson; | ||
| 
     | 
||
| import com.google.common.collect.ImmutableMap; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.List; | ||
| import org.openqa.selenium.grid.data.SessionHistoryEntry; | ||
| import org.openqa.selenium.internal.Require; | ||
| import org.openqa.selenium.remote.http.HttpHandler; | ||
| import org.openqa.selenium.remote.http.HttpRequest; | ||
| import org.openqa.selenium.remote.http.HttpResponse; | ||
| 
     | 
||
| class GetNodeSessionHistory implements HttpHandler { | ||
| 
     | 
||
| private final Node node; | ||
| 
     | 
||
| GetNodeSessionHistory(Node node) { | ||
| this.node = Require.nonNull("Node", node); | ||
| } | ||
| 
     | 
||
| @Override | ||
| public HttpResponse execute(HttpRequest req) throws UncheckedIOException { | ||
| List<SessionHistoryEntry> sessionHistory = node.getSessionHistory(); | ||
| 
     | 
||
| return new HttpResponse().setContent(asJson(ImmutableMap.of("value", sessionHistory))); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.