Search in sources :

Example 1 with QualifiedName

use of org.neo4j.internal.kernel.api.procs.QualifiedName in project neo4j by neo4j.

the class SingleInstanceRoutingProcedureInstallerTest method shouldRegisterRoutingProcedures.

@Test
void shouldRegisterRoutingProcedures() throws Exception {
    DatabaseManager<?> databaseManager = mock(DatabaseManager.class);
    ConnectorPortRegister portRegister = mock(ConnectorPortRegister.class);
    ClientRoutingDomainChecker clientRoutingDomainChecker = mock(ClientRoutingDomainChecker.class);
    Config config = Config.defaults();
    LogProvider logProvider = nullLogProvider();
    SingleInstanceRoutingProcedureInstaller installer = new SingleInstanceRoutingProcedureInstaller(databaseManager, clientRoutingDomainChecker, portRegister, config, logProvider);
    GlobalProcedures procedures = spy(new GlobalProceduresRegistry());
    installer.install(procedures);
    verify(procedures, times(2)).register(any(GetRoutingTableProcedure.class));
    Set<QualifiedName> expectedNames = newSetWith(new QualifiedName(new String[] { "dbms", "routing" }, "getRoutingTable"), new QualifiedName(new String[] { "dbms", "cluster", "routing" }, "getRoutingTable"));
    Set<QualifiedName> actualNames = procedures.getAllProcedures().stream().map(ProcedureSignature::name).collect(toSet());
    assertEquals(expectedNames, actualNames);
}
Also used : ConnectorPortRegister(org.neo4j.configuration.connectors.ConnectorPortRegister) NullLogProvider.nullLogProvider(org.neo4j.logging.NullLogProvider.nullLogProvider) LogProvider(org.neo4j.logging.LogProvider) GlobalProceduresRegistry(org.neo4j.procedure.impl.GlobalProceduresRegistry) Config(org.neo4j.configuration.Config) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) GlobalProcedures(org.neo4j.kernel.api.procedure.GlobalProcedures) Test(org.junit.jupiter.api.Test)

Example 2 with QualifiedName

use of org.neo4j.internal.kernel.api.procs.QualifiedName in project neo4j by neo4j.

the class BuiltInDbmsProceduresIT method listAllCapabilitiesShouldNotReturnBlocked.

@Test
void listAllCapabilitiesShouldNotReturnBlocked() throws KernelException {
    // set blocked capabilities
    Config config = dependencyResolver.resolveDependency(Config.class);
    config.set(CapabilitiesSettings.dbms_capabilities_blocked, List.of("my.custom.**"));
    QualifiedName procedureName = procedureName("dbms", "listAllCapabilities");
    int procedureId = procs().procedureGet(procedureName).id();
    RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
    List<AnyValue[]> capabilities = asList(callResult);
    List<String> capabilityNames = capabilities.stream().map(c -> ((TextValue) c[0]).stringValue()).collect(Collectors.toList());
    assertThat(capabilityNames).containsExactlyInAnyOrder(DBMSCapabilities.dbms_instance_version.name().fullName(), DBMSCapabilities.dbms_instance_kernel_version.name().fullName(), DBMSCapabilities.dbms_instance_edition.name().fullName(), DBMSCapabilities.dbms_instance_operational_mode.name().fullName(), TestCapabilities.my_dynamic_capability.name().fullName(), TestCapabilities.my_internal_capability.name().fullName());
}
Also used : AnyValue(org.neo4j.values.AnyValue) Arrays(java.util.Arrays) Label(org.neo4j.graphdb.Label) RawIterator(org.neo4j.collection.RawIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Public(org.neo4j.annotations.Public) Values(org.neo4j.values.storable.Values) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CapabilitiesRegistry(org.neo4j.capabilities.CapabilitiesRegistry) Capability(org.neo4j.capabilities.Capability) CapabilitiesSettings(org.neo4j.capabilities.CapabilitiesSettings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FALSE(org.neo4j.configuration.SettingValueParsers.FALSE) CapabilityProviderContext(org.neo4j.capabilities.CapabilityProviderContext) INTEGER(org.neo4j.capabilities.Type.INTEGER) DOUBLE(org.neo4j.capabilities.Type.DOUBLE) CapabilityProvider(org.neo4j.capabilities.CapabilityProvider) Name(org.neo4j.capabilities.Name) DBMSCapabilities(org.neo4j.capabilities.DBMSCapabilities) BooleanValue(org.neo4j.values.storable.BooleanValue) BOOLEAN(org.neo4j.capabilities.Type.BOOLEAN) TextValue(org.neo4j.values.storable.TextValue) Label.label(org.neo4j.graphdb.Label.label) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Collectors(java.util.stream.Collectors) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) Description(org.neo4j.configuration.Description) KernelException(org.neo4j.exceptions.KernelException) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CapabilityDeclaration(org.neo4j.capabilities.CapabilityDeclaration) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest) Config(org.neo4j.configuration.Config) TextValue(org.neo4j.values.storable.TextValue) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 3 with QualifiedName

use of org.neo4j.internal.kernel.api.procs.QualifiedName in project neo4j by neo4j.

the class BuiltInDbmsProceduresIT method listAllCapabilities.

@Test
void listAllCapabilities() throws KernelException {
    QualifiedName procedureName = procedureName("dbms", "listAllCapabilities");
    int procedureId = procs().procedureGet(procedureName).id();
    RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, new AnyValue[] {}, ProcedureCallContext.EMPTY);
    List<AnyValue[]> capabilities = asList(callResult);
    List<String> capabilityNames = capabilities.stream().map(c -> ((TextValue) c[0]).stringValue()).collect(Collectors.toList());
    assertThat(capabilityNames).containsExactlyInAnyOrder(DBMSCapabilities.dbms_instance_version.name().fullName(), DBMSCapabilities.dbms_instance_kernel_version.name().fullName(), DBMSCapabilities.dbms_instance_edition.name().fullName(), DBMSCapabilities.dbms_instance_operational_mode.name().fullName(), TestCapabilities.my_custom_capability.name().fullName(), TestCapabilities.my_internal_capability.name().fullName(), TestCapabilities.my_dynamic_capability.name().fullName());
}
Also used : AnyValue(org.neo4j.values.AnyValue) Arrays(java.util.Arrays) Label(org.neo4j.graphdb.Label) RawIterator(org.neo4j.collection.RawIterator) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) Iterators.asList(org.neo4j.internal.helpers.collection.Iterators.asList) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Config(org.neo4j.configuration.Config) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ProcedureSignature.procedureName(org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName) Public(org.neo4j.annotations.Public) Values(org.neo4j.values.storable.Values) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) CapabilitiesRegistry(org.neo4j.capabilities.CapabilitiesRegistry) Capability(org.neo4j.capabilities.Capability) CapabilitiesSettings(org.neo4j.capabilities.CapabilitiesSettings) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FALSE(org.neo4j.configuration.SettingValueParsers.FALSE) CapabilityProviderContext(org.neo4j.capabilities.CapabilityProviderContext) INTEGER(org.neo4j.capabilities.Type.INTEGER) DOUBLE(org.neo4j.capabilities.Type.DOUBLE) CapabilityProvider(org.neo4j.capabilities.CapabilityProvider) Name(org.neo4j.capabilities.Name) DBMSCapabilities(org.neo4j.capabilities.DBMSCapabilities) BooleanValue(org.neo4j.values.storable.BooleanValue) BOOLEAN(org.neo4j.capabilities.Type.BOOLEAN) TextValue(org.neo4j.values.storable.TextValue) Label.label(org.neo4j.graphdb.Label.label) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Collectors(java.util.stream.Collectors) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) List(java.util.List) ProcedureCallContext(org.neo4j.internal.kernel.api.procs.ProcedureCallContext) ArrayUtils.toArray(org.apache.commons.lang3.ArrayUtils.toArray) Description(org.neo4j.configuration.Description) KernelException(org.neo4j.exceptions.KernelException) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CapabilityDeclaration(org.neo4j.capabilities.CapabilityDeclaration) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest) TextValue(org.neo4j.values.storable.TextValue) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 4 with QualifiedName

use of org.neo4j.internal.kernel.api.procs.QualifiedName in project neo4j by neo4j.

the class BuiltInDbmsProceduresIT method callListConfig.

private List<AnyValue[]> callListConfig(String searchString) throws KernelException {
    QualifiedName procedureName = procedureName("dbms", "listConfig");
    int procedureId = procs().procedureGet(procedureName).id();
    RawIterator<AnyValue[], ProcedureException> callResult = procs().procedureCallDbms(procedureId, toArray(stringValue(searchString)), ProcedureCallContext.EMPTY);
    return asList(callResult);
}
Also used : QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException)

Example 5 with QualifiedName

use of org.neo4j.internal.kernel.api.procs.QualifiedName in project neo4j by neo4j.

the class ProcedureCompiler method compileProcedure.

List<CallableProcedure> compileProcedure(Class<?> procDefinition, String warning, boolean fullAccess) throws KernelException {
    try {
        List<Method> procedureMethods = Arrays.stream(procDefinition.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(Procedure.class)).collect(Collectors.toList());
        if (procedureMethods.isEmpty()) {
            return emptyList();
        }
        assertValidConstructor(procDefinition);
        List<CallableProcedure> out = new ArrayList<>(procedureMethods.size());
        for (Method method : procedureMethods) {
            String valueName = method.getAnnotation(Procedure.class).value();
            String definedName = method.getAnnotation(Procedure.class).name();
            QualifiedName procName = extractName(procDefinition, method, valueName, definedName);
            if (fullAccess || config.isWhitelisted(procName.toString())) {
                out.add(compileProcedure(procDefinition, method, warning, fullAccess, procName));
            } else {
                log.warn(String.format("The procedure '%s' is not on the allowlist and won't be loaded.", procName.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 procedure defined in `%s`: %s", procDefinition.getSimpleName(), e.getMessage());
    }
}
Also used : Mode(org.neo4j.procedure.Mode) Arrays(java.util.Arrays) Log(org.neo4j.logging.Log) UserAggregationResult(org.neo4j.procedure.UserAggregationResult) CallableUserAggregationFunction(org.neo4j.kernel.api.procedure.CallableUserAggregationFunction) Status(org.neo4j.kernel.api.exceptions.Status) UserAggregationUpdate(org.neo4j.procedure.UserAggregationUpdate) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) Constructor(java.lang.reflect.Constructor) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) UserFunctionSignature(org.neo4j.internal.kernel.api.procs.UserFunctionSignature) Procedure(org.neo4j.procedure.Procedure) Method(java.lang.reflect.Method) GraphDatabaseSettings.procedure_unrestricted(org.neo4j.configuration.GraphDatabaseSettings.procedure_unrestricted) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) Collections.emptyList(java.util.Collections.emptyList) CallableUserFunction(org.neo4j.kernel.api.procedure.CallableUserFunction) FailedLoadFunction(org.neo4j.kernel.api.procedure.FailedLoadFunction) Description(org.neo4j.procedure.Description) Collectors(java.util.stream.Collectors) FieldSignature(org.neo4j.internal.kernel.api.procs.FieldSignature) Internal(org.neo4j.procedure.Internal) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) FailedLoadProcedure(org.neo4j.kernel.api.procedure.FailedLoadProcedure) UserFunction(org.neo4j.procedure.UserFunction) List(java.util.List) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) KernelException(org.neo4j.exceptions.KernelException) Modifier.isPublic(java.lang.reflect.Modifier.isPublic) UserAggregationFunction(org.neo4j.procedure.UserAggregationFunction) FailedLoadAggregatedFunction(org.neo4j.kernel.api.procedure.FailedLoadAggregatedFunction) ProcedureSignature(org.neo4j.internal.kernel.api.procs.ProcedureSignature) Comparator(java.util.Comparator) Admin(org.neo4j.procedure.Admin) QualifiedName(org.neo4j.internal.kernel.api.procs.QualifiedName) ArrayList(java.util.ArrayList) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) SystemProcedure(org.neo4j.kernel.api.procedure.SystemProcedure) Procedure(org.neo4j.procedure.Procedure) FailedLoadProcedure(org.neo4j.kernel.api.procedure.FailedLoadProcedure) CallableProcedure(org.neo4j.kernel.api.procedure.CallableProcedure) Method(java.lang.reflect.Method) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) KernelException(org.neo4j.exceptions.KernelException) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) ComponentInjectionException(org.neo4j.kernel.api.exceptions.ComponentInjectionException) KernelException(org.neo4j.exceptions.KernelException)

Aggregations

QualifiedName (org.neo4j.internal.kernel.api.procs.QualifiedName)23 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)14 Test (org.junit.jupiter.api.Test)13 Arrays (java.util.Arrays)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 KernelException (org.neo4j.exceptions.KernelException)7 ProcedureSignature (org.neo4j.internal.kernel.api.procs.ProcedureSignature)6 Config (org.neo4j.configuration.Config)5 ArrayUtils.toArray (org.apache.commons.lang3.ArrayUtils.toArray)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 UserFunctionSignature (org.neo4j.internal.kernel.api.procs.UserFunctionSignature)4 CallableProcedure (org.neo4j.kernel.api.procedure.CallableProcedure)4 CallableUserAggregationFunction (org.neo4j.kernel.api.procedure.CallableUserAggregationFunction)4 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)4 Constructor (java.lang.reflect.Constructor)3 Method (java.lang.reflect.Method)3 Modifier.isPublic (java.lang.reflect.Modifier.isPublic)3 ArrayList (java.util.ArrayList)3 Collections.emptyList (java.util.Collections.emptyList)3