Search in sources :

Example 6 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class GraphDbStructureGuide method showStructure.

private void showStructure(Statement statement, DbStructureVisitor visitor) {
    ReadOperations read = statement.readOperations();
    try {
        showTokens(visitor, read);
        showSchema(visitor, read);
        showStatistics(visitor, read);
    } catch (KernelException e) {
        throw new IllegalStateException("Kernel exception when traversing database schema structure and statistics.  This is not expected to happen.", e);
    }
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException)

Example 7 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class RemoveOrphanConstraintIndexesOnStartup method perform.

public void perform() {
    try (KernelTransaction transaction = kernel.newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
        Statement statement = transaction.acquireStatement()) {
        for (NewIndexDescriptor index : loop(statement.readOperations().uniqueIndexesGetAll())) {
            if (statement.readOperations().indexGetOwningUniquenessConstraintId(index) == null) {
                log.info("Removing orphan constraint index: " + index);
                statement.schemaWriteOperations().uniqueIndexDrop(index);
            }
        }
        transaction.success();
    } catch (KernelException e) {
        log.error("Failed to execute orphan index checking transaction.", e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) KernelException(org.neo4j.kernel.api.exceptions.KernelException)

Example 8 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class DataSourceModule method setupProcedures.

private Procedures setupProcedures(PlatformModule platform, EditionModule editionModule) {
    File pluginDir = platform.config.get(GraphDatabaseSettings.plugin_dir);
    Log internalLog = platform.logging.getInternalLog(Procedures.class);
    Procedures procedures = new Procedures(new SpecialBuiltInProcedures(Version.getNeo4jVersion(), platform.databaseInfo.edition.toString()), pluginDir, internalLog, new ProcedureConfig(platform.config));
    platform.life.add(procedures);
    platform.dependencies.satisfyDependency(procedures);
    procedures.registerType(Node.class, new SimpleConverter(NTNode, Node.class));
    procedures.registerType(Relationship.class, new SimpleConverter(NTRelationship, Relationship.class));
    procedures.registerType(Path.class, new SimpleConverter(NTPath, Path.class));
    procedures.registerType(Geometry.class, new SimpleConverter(NTGeometry, Geometry.class));
    procedures.registerType(Point.class, new SimpleConverter(NTPoint, Point.class));
    // Register injected public API components
    Log proceduresLog = platform.logging.getUserLog(Procedures.class);
    procedures.registerComponent(Log.class, (ctx) -> proceduresLog, true);
    Guard guard = platform.dependencies.resolveDependency(Guard.class);
    procedures.registerComponent(ProcedureTransaction.class, new ProcedureTransactionProvider(), true);
    procedures.registerComponent(TerminationGuard.class, new TerminationGuardProvider(guard), true);
    // Below components are not public API, but are made available for internal
    // procedures to call, and to provide temporary workarounds for the following
    // patterns:
    //  - Batch-transaction imports (GDAPI, needs to be real and passed to background processing threads)
    //  - Group-transaction writes (same pattern as above, but rather than splitting large transactions,
    //                              combine lots of small ones)
    //  - Bleeding-edge performance (KernelTransaction, to bypass overhead of working with Core API)
    procedures.registerComponent(DependencyResolver.class, (ctx) -> platform.dependencies, false);
    procedures.registerComponent(KernelTransaction.class, (ctx) -> ctx.get(KERNEL_TRANSACTION), false);
    procedures.registerComponent(GraphDatabaseAPI.class, (ctx) -> platform.graphDatabaseFacade, false);
    // Security procedures
    procedures.registerComponent(SecurityContext.class, ctx -> ctx.get(SECURITY_CONTEXT), true);
    // Edition procedures
    try {
        editionModule.registerProcedures(procedures);
    } catch (KernelException e) {
        internalLog.error("Failed to register built-in edition procedures at start up: " + e.getMessage());
    }
    return procedures;
}
Also used : NTPath(org.neo4j.kernel.api.proc.Neo4jTypes.NTPath) Path(org.neo4j.graphdb.Path) Log(org.neo4j.logging.Log) SimpleConverter(org.neo4j.kernel.impl.proc.TypeMappers.SimpleConverter) NTNode(org.neo4j.kernel.api.proc.Neo4jTypes.NTNode) Node(org.neo4j.graphdb.Node) SpecialBuiltInProcedures(org.neo4j.kernel.builtinprocs.SpecialBuiltInProcedures) Procedures(org.neo4j.kernel.impl.proc.Procedures) NTPoint(org.neo4j.kernel.api.proc.Neo4jTypes.NTPoint) Point(org.neo4j.graphdb.spatial.Point) TerminationGuardProvider(org.neo4j.kernel.impl.proc.TerminationGuardProvider) NTGeometry(org.neo4j.kernel.api.proc.Neo4jTypes.NTGeometry) Geometry(org.neo4j.graphdb.spatial.Geometry) NTRelationship(org.neo4j.kernel.api.proc.Neo4jTypes.NTRelationship) Relationship(org.neo4j.graphdb.Relationship) AvailabilityGuard(org.neo4j.kernel.AvailabilityGuard) SchemaWriteGuard(org.neo4j.kernel.impl.api.SchemaWriteGuard) Guard(org.neo4j.kernel.guard.Guard) TerminationGuard(org.neo4j.procedure.TerminationGuard) TimeoutGuard(org.neo4j.kernel.guard.TimeoutGuard) ProcedureTransactionProvider(org.neo4j.kernel.impl.proc.ProcedureTransactionProvider) KernelException(org.neo4j.kernel.api.exceptions.KernelException) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) File(java.io.File) ProcedureConfig(org.neo4j.kernel.impl.proc.ProcedureConfig) SpecialBuiltInProcedures(org.neo4j.kernel.builtinprocs.SpecialBuiltInProcedures)

Example 9 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class ProcedureJarLoader method loadProceduresFromDir.

public Callables loadProceduresFromDir(File root) throws IOException, KernelException {
    if (!root.exists()) {
        return Callables.empty();
    }
    Callables out = new Callables();
    List<URL> list = Stream.of(root.listFiles((dir, name) -> name.endsWith(".jar"))).map(this::toURL).collect(toList());
    URL[] jarFiles = list.toArray(new URL[list.size()]);
    URLClassLoader loader = new URLClassLoader(jarFiles, this.getClass().getClassLoader());
    for (URL jarFile : jarFiles) {
        loadProcedures(jarFile, loader, out);
    }
    return out;
}
Also used : CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) ZipInputStream(java.util.zip.ZipInputStream) Log(org.neo4j.logging.Log) RawIterator(org.neo4j.collection.RawIterator) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) IOException(java.io.IOException) File(java.io.File) KernelException(org.neo4j.kernel.api.exceptions.KernelException) ArrayList(java.util.ArrayList) URLClassLoader(java.net.URLClassLoader) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Optional(java.util.Optional) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) ZipEntry(java.util.zip.ZipEntry) PrefetchingRawIterator(org.neo4j.collection.PrefetchingRawIterator) URLClassLoader(java.net.URLClassLoader) URL(java.net.URL)

Example 10 with KernelException

use of org.neo4j.kernel.api.exceptions.KernelException in project neo4j by neo4j.

the class ReflectiveProcedureCompiler method compileAggregationFunction.

List<CallableUserAggregationFunction> compileAggregationFunction(Class<?> fcnDefinition) throws KernelException {
    try {
        List<Method> methods = Arrays.stream(fcnDefinition.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(UserAggregationFunction.class)).collect(Collectors.toList());
        if (methods.isEmpty()) {
            return emptyList();
        }
        MethodHandle constructor = constructor(fcnDefinition);
        ArrayList<CallableUserAggregationFunction> out = new ArrayList<>(methods.size());
        for (Method method : methods) {
            String valueName = method.getAnnotation(UserAggregationFunction.class).value();
            String definedName = method.getAnnotation(UserAggregationFunction.class).name();
            QualifiedName funcName = extractName(fcnDefinition, method, valueName, definedName);
            if (config.isWhitelisted(funcName.toString())) {
                out.add(compileAggregationFunction(fcnDefinition, constructor, method, funcName));
            } else {
                log.warn(String.format("The function '%s' is not on the whitelist and won't be loaded.", funcName.toString()));
            }
        }
        out.sort(Comparator.comparing(a -> a.signature().name().toString()));
        return out;
    } catch (KernelException e) {
        throw e;
    } catch (Exception e) {
        throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, e, "Failed to compile function defined in `%s`: %s", fcnDefinition.getSimpleName(), e.getMessage());
    }
}
Also used : FailedLoadProcedure(org.neo4j.kernel.api.proc.FailedLoadProcedure) Mode(org.neo4j.procedure.Mode) MethodHandle(java.lang.invoke.MethodHandle) Arrays(java.util.Arrays) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) Log(org.neo4j.logging.Log) RawIterator(org.neo4j.collection.RawIterator) CallableProcedure(org.neo4j.kernel.api.proc.CallableProcedure) UserAggregationResult(org.neo4j.procedure.UserAggregationResult) Status(org.neo4j.kernel.api.exceptions.Status) UserAggregationUpdate(org.neo4j.procedure.UserAggregationUpdate) FailedLoadFunction(org.neo4j.kernel.api.proc.FailedLoadFunction) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Iterators.asRawIterator(org.neo4j.helpers.collection.Iterators.asRawIterator) FailedLoadAggregatedFunction(org.neo4j.kernel.api.proc.FailedLoadAggregatedFunction) ProcedureSignature(org.neo4j.kernel.api.proc.ProcedureSignature) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) Procedure(org.neo4j.procedure.Procedure) Method(java.lang.reflect.Method) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) CallableUserFunction(org.neo4j.kernel.api.proc.CallableUserFunction) Iterator(java.util.Iterator) UserFunctionSignature(org.neo4j.kernel.api.proc.UserFunctionSignature) Collections.emptyList(java.util.Collections.emptyList) MethodHandles(java.lang.invoke.MethodHandles) Description(org.neo4j.procedure.Description) Collections.emptyIterator(java.util.Collections.emptyIterator) Collectors(java.util.stream.Collectors) KernelException(org.neo4j.kernel.api.exceptions.KernelException) FieldSignature(org.neo4j.kernel.api.proc.FieldSignature) UserFunction(org.neo4j.procedure.UserFunction) List(java.util.List) Stream(java.util.stream.Stream) UserAggregationFunction(org.neo4j.procedure.UserAggregationFunction) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) PerformsWrites(org.neo4j.procedure.PerformsWrites) Comparator(java.util.Comparator) Context(org.neo4j.kernel.api.proc.Context) OutputMapper(org.neo4j.kernel.impl.proc.OutputMappers.OutputMapper) QualifiedName(org.neo4j.kernel.api.proc.QualifiedName) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) UserAggregationFunction(org.neo4j.procedure.UserAggregationFunction) CallableUserAggregationFunction(org.neo4j.kernel.api.proc.CallableUserAggregationFunction) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) MethodHandle(java.lang.invoke.MethodHandle)

Aggregations

KernelException (org.neo4j.kernel.api.exceptions.KernelException)13 ArrayList (java.util.ArrayList)5 Log (org.neo4j.logging.Log)5 List (java.util.List)4 Optional (java.util.Optional)4 Stream (java.util.stream.Stream)4 RawIterator (org.neo4j.collection.RawIterator)4 Status (org.neo4j.kernel.api.exceptions.Status)4 CallableProcedure (org.neo4j.kernel.api.proc.CallableProcedure)4 CallableUserAggregationFunction (org.neo4j.kernel.api.proc.CallableUserAggregationFunction)4 CallableUserFunction (org.neo4j.kernel.api.proc.CallableUserFunction)4 MethodHandle (java.lang.invoke.MethodHandle)3 MethodHandles (java.lang.invoke.MethodHandles)3 Method (java.lang.reflect.Method)3 Modifier (java.lang.reflect.Modifier)3 Arrays (java.util.Arrays)3 Collections.emptyIterator (java.util.Collections.emptyIterator)3 Collections.emptyList (java.util.Collections.emptyList)3 Comparator (java.util.Comparator)3 Iterator (java.util.Iterator)3