Isolate gerrit:server rule in gerrit/server package
Move c.g.g.rules and c.g.g.audit packages to c.g.g.server package to reflect the real dependencies on server package for these clases. This allows us to move server code related BUILD rules from general package c.g.g to c.g.g.server package. With this small refactoring we can achieve our goal having the BUILD files as close to the sources as possible. Moreover, this non-intrusive change (no core plugins were affected) significantly simplifies the whole build structure as this allows us to eliminate BUILD rule in general c.g.g package. Before this change a developer must study build files to actually understand what parts of codes are controlled by c.g.g/BUILD build file. With this change, it is obvious, because all BUILD files are located as close as possible to the sources they control. This changes also leaves place for improvement. At the moment, the sources can be isolated from the giant java/com/google/gerrit/server rules, the packages can be moved outside of c.g.g.server package and de-coupled from java/com/google/gerrit/server rules, as it was already done with receive, index, metrics and lifecycle packages. These future and further decomposition of java/com/google/gerrit/server rule is beyond of the scope of this change. Change-Id: Iac35422bd9d6ad933c2dded2293c679cdd2aead5
This commit is contained in:
committed by
Dave Borowitz
parent
376a7bbb64
commit
590071e7ff
107
java/com/google/gerrit/server/audit/AuditEvent.java
Normal file
107
java/com/google/gerrit/server/audit/AuditEvent.java
Normal file
@@ -0,0 +1,107 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed 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 com.google.gerrit.server.audit;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
|
||||
public class AuditEvent {
|
||||
|
||||
public static final String UNKNOWN_SESSION_ID = "000000000000000000000000000";
|
||||
protected static final ImmutableListMultimap<String, ?> EMPTY_PARAMS = ImmutableListMultimap.of();
|
||||
|
||||
public final String sessionId;
|
||||
public final CurrentUser who;
|
||||
public final long when;
|
||||
public final String what;
|
||||
public final ListMultimap<String, ?> params;
|
||||
public final Object result;
|
||||
public final long timeAtStart;
|
||||
public final long elapsed;
|
||||
public final UUID uuid;
|
||||
|
||||
@AutoValue
|
||||
public abstract static class UUID {
|
||||
private static UUID create() {
|
||||
return new AutoValue_AuditEvent_UUID(
|
||||
String.format("audit:%s", java.util.UUID.randomUUID().toString()));
|
||||
}
|
||||
|
||||
public abstract String uuid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new audit event with results
|
||||
*
|
||||
* @param sessionId session id the event belongs to
|
||||
* @param who principal that has generated the event
|
||||
* @param what object of the event
|
||||
* @param when time-stamp of when the event started
|
||||
* @param params parameters of the event
|
||||
* @param result result of the event
|
||||
*/
|
||||
public AuditEvent(
|
||||
String sessionId,
|
||||
CurrentUser who,
|
||||
String what,
|
||||
long when,
|
||||
ListMultimap<String, ?> params,
|
||||
Object result) {
|
||||
Preconditions.checkNotNull(what, "what is a mandatory not null param !");
|
||||
|
||||
this.sessionId = MoreObjects.firstNonNull(sessionId, UNKNOWN_SESSION_ID);
|
||||
this.who = who;
|
||||
this.what = what;
|
||||
this.when = when;
|
||||
this.timeAtStart = this.when;
|
||||
this.params = MoreObjects.firstNonNull(params, EMPTY_PARAMS);
|
||||
this.uuid = UUID.create();
|
||||
this.result = result;
|
||||
this.elapsed = TimeUtil.nowMs() - timeAtStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return uuid.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AuditEvent other = (AuditEvent) obj;
|
||||
return this.uuid.equals(other.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"AuditEvent UUID:%s, SID:%s, TS:%d, who:%s, what:%s",
|
||||
uuid.uuid(), sessionId, when, who, what);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user