use of org.neo4j.kernel.api.procedure.SystemProcedure in project neo4j by neo4j.
the class AuthProcedures method listUsers.
@SystemProcedure
@Deprecated
@Description("List all native users.")
@Procedure(name = "dbms.security.listUsers", mode = READ, deprecatedBy = "Administration command: SHOW USERS")
public Stream<UserResult> listUsers() throws ProcedureException {
var query = "SHOW USERS";
List<UserResult> result = new ArrayList<>();
try {
Result execute = transaction.execute(query);
execute.accept(row -> {
var username = row.getString("user");
var changeRequired = row.getBoolean("passwordChangeRequired");
result.add(new UserResult(username, changeRequired));
return true;
});
} catch (Exception e) {
translateException(e, "dbms.security.listUsers");
}
if (result.isEmpty()) {
return showCurrentUser();
}
return result.stream();
}
use of org.neo4j.kernel.api.procedure.SystemProcedure in project neo4j by neo4j.
the class BuiltInProcedures method indexDetails.
@Deprecated(since = "4.2.0", forRemoval = true)
@SystemProcedure
@Description("Detailed description of specific index.")
@Procedure(name = "db.indexDetails", mode = READ, deprecatedBy = "SHOW INDEXES YIELD * command")
public Stream<IndexDetailResult> indexDetails(@Name("indexName") String indexName) throws ProcedureException {
if (callContext.isSystemDatabase()) {
return Stream.empty();
}
TokenRead tokenRead = kernelTransaction.tokenRead();
IndexingService indexingService = resolver.resolveDependency(IndexingService.class);
SchemaReadCore schemaRead = kernelTransaction.schemaRead().snapshot();
List<IndexDescriptor> indexes = asList(schemaRead.indexesGetAll());
IndexDescriptor index = null;
for (IndexDescriptor candidate : indexes) {
if (candidate.getName().equals(indexName)) {
index = candidate;
break;
}
}
if (index == null) {
throw new ProcedureException(Status.Schema.IndexNotFound, "Could not find index with name \"" + indexName + "\"");
}
final IndexDetailResult indexDetailResult = asIndexDetails(tokenRead, schemaRead, index);
return Stream.of(indexDetailResult);
}
use of org.neo4j.kernel.api.procedure.SystemProcedure in project neo4j by neo4j.
the class BuiltInDbmsProcedures method listClientConfig.
@Internal
@SystemProcedure
@Description("Return config settings interesting to clients (e.g. Neo4j Browser)")
@Procedure(name = "dbms.clientConfig", mode = DBMS)
public Stream<ConfigResult> listClientConfig() {
List<ConfigResult> results = new ArrayList<>();
Set<String> browserSettings = Stream.of("browser.allow_outgoing_connections", "browser.credential_timeout", "browser.retain_connection_credentials", "browser.retain_editor_history", "dbms.security.auth_enabled", "browser.remote_content_hostname_whitelist", "browser.post_connect_cmd", "dbms.default_database").collect(Collectors.toCollection(HashSet::new));
Config config = graph.getDependencyResolver().resolveDependency(Config.class);
config.getValues().forEach((setting, value) -> {
if (browserSettings.contains(setting.name().toLowerCase())) {
results.add(new ConfigResult(setting, value));
}
});
return results.stream().sorted(Comparator.comparing(c -> c.name));
}
use of org.neo4j.kernel.api.procedure.SystemProcedure in project neo4j by neo4j.
the class BuiltInDbmsProcedures method killQueries.
@SystemProcedure
@Description("Kill all transactions executing a query with any of the given query ids.")
@Procedure(name = "dbms.killQueries", mode = DBMS)
public Stream<QueryTerminationResult> killQueries(@Name("ids") List<String> idTexts) throws InvalidArgumentsException {
DatabaseManager<DatabaseContext> databaseManager = getDatabaseManager();
DatabaseIdRepository databaseIdRepository = databaseManager.databaseIdRepository();
Map<Long, QueryId> queryIds = new HashMap<>(idTexts.size());
for (String idText : idTexts) {
QueryId id = QueryId.parse(idText);
queryIds.put(id.internalId(), id);
}
List<QueryTerminationResult> result = new ArrayList<>(queryIds.size());
for (FabricTransaction tx : getFabricTransactions()) {
for (ExecutingQuery query : getActiveFabricQueries(tx)) {
QueryId givenQueryId = queryIds.remove(query.internalQueryId());
if (givenQueryId != null) {
result.add(killFabricQueryTransaction(givenQueryId, tx, query));
}
}
}
for (Map.Entry<NamedDatabaseId, DatabaseContext> databaseEntry : databaseManager.registeredDatabases().entrySet()) {
NamedDatabaseId databaseId = databaseEntry.getKey();
DatabaseContext databaseContext = databaseEntry.getValue();
if (databaseContext.database().isStarted()) {
for (KernelTransactionHandle tx : getExecutingTransactions(databaseContext)) {
if (tx.executingQuery().isPresent()) {
QueryId givenQueryId = queryIds.remove(tx.executingQuery().get().internalQueryId());
if (givenQueryId != null) {
result.add(killQueryTransaction(givenQueryId, tx, databaseId));
}
}
}
}
}
// Add error about the rest
for (QueryId queryId : queryIds.values()) {
result.add(new QueryFailedTerminationResult(queryId, "n/a", "No Query found with this id"));
}
return result.stream();
}
use of org.neo4j.kernel.api.procedure.SystemProcedure in project neo4j by neo4j.
the class BuiltInDbmsProcedures method upgrade.
@Admin
@SystemProcedure
@Description("Upgrade the system database schema if it is not the current schema.")
@Procedure(name = "dbms.upgrade", mode = WRITE)
public Stream<SystemGraphComponentUpgradeResult> upgrade() throws ProcedureException {
if (!callContext.isSystemDatabase()) {
throw new ProcedureException(ProcedureCallFailed, "This is an administration command and it should be executed against the system database: dbms.upgrade");
}
SystemGraphComponents versions = systemGraphComponents;
SystemGraphComponent.Status status = versions.detect(transaction);
// New components are not currently initialised in cluster deployment when new binaries are booted on top of an existing database.
// This is a known shortcoming of the lifecycle and a state transfer from UNINITIALIZED to CURRENT must be supported
// as a workaround until it is fixed.
var upgradableStatuses = List.of(REQUIRES_UPGRADE, UNINITIALIZED);
if (upgradableStatuses.contains(status)) {
ArrayList<String> failed = new ArrayList<>();
versions.forEach(component -> {
SystemGraphComponent.Status initialStatus = component.detect(transaction);
if (upgradableStatuses.contains(initialStatus)) {
try {
component.upgradeToCurrent(graph);
} catch (Exception e) {
failed.add(String.format("[%s] %s", component.componentName(), e.getMessage()));
}
}
});
String upgradeResult = failed.isEmpty() ? "Success" : "Failed: " + String.join(", ", failed);
return Stream.of(new SystemGraphComponentUpgradeResult(versions.detect(transaction).name(), upgradeResult));
} else {
return Stream.of(new SystemGraphComponentUpgradeResult(status.name(), status.resolution()));
}
}
Aggregations