Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce SystemInformation service, hook into UDC.
UDC has a complex dependency hierarchy, and because of that it uses reflection to extract information from system components. This introduces a "SystemInformation" service where components publish metadata and UDC can access it without reflection. Also minor improvements to UDC resilience - only store up to 10 latest client names and urlencode query parameters in UDC ping payload.
- Loading branch information
Showing
29 changed files
with
895 additions
and
687 deletions.
There are no files selected for viewing
This file contains 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 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
61 changes: 61 additions & 0 deletions
61
community/kernel/src/main/java/org/neo4j/udc/UsageData.java
This file contains 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,61 @@ | ||
/* | ||
* Copyright (c) 2002-2015 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.udc; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* An in-memory storage location for usage metadata. | ||
* Any component is allowed to publish it's usage date here, and it can be any object, | ||
* including mutable classes. It is up to the usage data publishing code to choose which items from this repository | ||
* to publish. | ||
* | ||
* This service is meant as a diagnostic and informational tool, notably used by UDC. | ||
*/ | ||
public class UsageData | ||
{ | ||
private final ConcurrentHashMap<UsageDataKey, Object> store = new ConcurrentHashMap<>(); | ||
|
||
public <T> void set( UsageDataKey<T> key, T value ) | ||
{ | ||
store.put( key, value ); | ||
} | ||
|
||
public <T> T get( UsageDataKey<T> key ) | ||
{ | ||
Object o = store.get( key ); | ||
if( o == null ) | ||
{ | ||
// When items are missing, if there is a default value, we do a get-or-create style operation | ||
// This allows outside actors to get-or-create rich objects and know they will get the same object out | ||
// that other threads would use, which is helpful when we store mutable objects | ||
T value = key.generateDefaultValue(); | ||
if(value == null) | ||
{ | ||
return null; | ||
} | ||
|
||
store.putIfAbsent( key, value ); | ||
return get( key ); | ||
} | ||
return (T) o; | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
community/kernel/src/main/java/org/neo4j/udc/UsageDataKey.java
This file contains 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,87 @@ | ||
/* | ||
* Copyright (c) 2002-2015 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.udc; | ||
|
||
import org.neo4j.function.Supplier; | ||
|
||
import static org.neo4j.function.Suppliers.singleton; | ||
|
||
/** | ||
* A lookup key to publish or retrieve data in {@link UsageData}. | ||
* @param <Type> | ||
*/ | ||
public class UsageDataKey<Type> | ||
{ | ||
private final String name; | ||
|
||
/** When key is requested and no value exists, a default value is generated and inserted using this */ | ||
private final Supplier<Type> defaultVal; | ||
|
||
public static <T> UsageDataKey<T> key(String name) | ||
{ | ||
return key(name, null); | ||
} | ||
|
||
public static <T> UsageDataKey<T> key(String name, T defaultVal) | ||
{ | ||
return new UsageDataKey<>( name, singleton(defaultVal) ); | ||
} | ||
|
||
public static <T> UsageDataKey<T> key(String name, Supplier<T> defaultVal) | ||
{ | ||
return new UsageDataKey<>( name, defaultVal ); | ||
} | ||
|
||
public UsageDataKey( String name, Supplier<Type> defaultValue ) | ||
{ | ||
this.name = name; | ||
this.defaultVal = defaultValue; | ||
} | ||
|
||
String name() | ||
{ | ||
return name; | ||
} | ||
|
||
Type generateDefaultValue() | ||
{ | ||
return defaultVal == null ? null : defaultVal.get(); | ||
} | ||
|
||
@Override | ||
public boolean equals( Object o ) | ||
{ | ||
if ( this == o ) | ||
{ return true; } | ||
if ( o == null || getClass() != o.getClass() ) | ||
{ return false; } | ||
|
||
UsageDataKey<?> key = (UsageDataKey<?>) o; | ||
|
||
return name.equals( key.name ); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() | ||
{ | ||
return name.hashCode(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
community/kernel/src/main/java/org/neo4j/udc/UsageDataKeys.java
This file contains 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,75 @@ | ||
/* | ||
* Copyright (c) 2002-2015 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.udc; | ||
|
||
import org.neo4j.concurrent.RecentK; | ||
import org.neo4j.function.Supplier; | ||
|
||
import static org.neo4j.udc.UsageDataKey.key; | ||
|
||
/** | ||
* Inventory of common keys. This list is not exhaustive, and all items listed may not be available. | ||
* Still, this serves as a useful starting point for what you can expect to find, and new items added are | ||
* encouraged to have their keys listed here. | ||
*/ | ||
public class UsageDataKeys | ||
{ | ||
/** Edition of Neo4j running, eg 'community' or 'enterprise' */ | ||
public static final UsageDataKey<Edition> edition = key( "neo4j.edition", Edition.unknown ); | ||
|
||
/** Version of Neo4j running, eg. 1.2.3-RC1 */ | ||
public static final UsageDataKey<String> version = key( "neo4j.version", "N/A" ); | ||
|
||
/** Revision of Neo4j running, a link back to source control revision ids. */ | ||
public static final UsageDataKey<String> revision = key( "neo4j.revision", "N/A" ); | ||
|
||
/** Operational mode of the database */ | ||
public static final UsageDataKey<OperationalMode> operationalMode = key( "neo4j.opMode", OperationalMode.unknown ); | ||
|
||
/** Self-reported names of clients connecting to us. */ | ||
public static final UsageDataKey<RecentK<String>> clientNames = key( "neo4j.clientNames", new Supplier<RecentK<String>>() | ||
{ | ||
@Override | ||
public RecentK<String> get() | ||
{ | ||
return new RecentK<>( 10 ); | ||
} | ||
} ); | ||
|
||
/** Cluster server ID */ | ||
public static final UsageDataKey<String> serverId = key( "neo4j.serverId" ); | ||
|
||
public enum OperationalMode | ||
{ | ||
// Note, these are sent verbatum via UDC if UDC is enabled | ||
unknown, | ||
single, | ||
ha | ||
} | ||
|
||
public enum Edition | ||
{ | ||
// Note, these are sent verbatum via UDC if UDC is enabled | ||
unknown, | ||
community, | ||
advanced, | ||
enterprise | ||
} | ||
} |
This file contains 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 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.