Search in sources :

Example 1 with FunctionAuthProvider

use of org.apache.pulsar.functions.auth.FunctionAuthProvider in project incubator-pulsar by apache.

the class FunctionActionerTest method testFunctionAuthDisabled.

@Test
public void testFunctionAuthDisabled() throws Exception {
    WorkerConfig workerConfig = new WorkerConfig();
    workerConfig.setWorkerId("worker-1");
    workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
    workerConfig.setFunctionRuntimeFactoryConfigs(ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("test"), Map.class));
    workerConfig.setPulsarServiceUrl("pulsar://localhost:6650");
    workerConfig.setStateStorageServiceUrl("foo");
    workerConfig.setFunctionAssignmentTopicName("assignments");
    String downloadDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
    workerConfig.setDownloadDirectory(downloadDir);
    RuntimeFactory factory = mock(RuntimeFactory.class);
    Runtime runtime = mock(Runtime.class);
    doReturn(runtime).when(factory).createContainer(any(), any(), any(), any());
    doNothing().when(runtime).start();
    Namespace dlogNamespace = mock(Namespace.class);
    final String exceptionMsg = "dl namespace not-found";
    doThrow(new IllegalArgumentException(exceptionMsg)).when(dlogNamespace).openLog(any());
    @SuppressWarnings("resource") FunctionActioner actioner = new FunctionActioner(workerConfig, factory, dlogNamespace, new ConnectorsManager(workerConfig), new FunctionsManager(workerConfig), mock(PulsarAdmin.class));
    String pkgPathLocation = "http://invalid/my-file.jar";
    Function.FunctionMetaData functionMeta = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("func-1")).setPackageLocation(PackageLocationMetaData.newBuilder().setPackagePath(pkgPathLocation).build()).build();
    Function.Instance instance = Function.Instance.newBuilder().setFunctionMetaData(functionMeta).build();
    RuntimeSpawner runtimeSpawner = spy(actioner.getRuntimeSpawner(instance, "foo"));
    assertNull(runtimeSpawner.getInstanceConfig().getFunctionAuthenticationSpec());
    FunctionRuntimeInfo functionRuntimeInfo = mock(FunctionRuntimeInfo.class);
    RuntimeFactory runtimeFactory = mock(RuntimeFactory.class);
    Optional<FunctionAuthProvider> functionAuthProvider = Optional.of(mock(FunctionAuthProvider.class));
    doReturn(functionAuthProvider).when(runtimeFactory).getAuthProvider();
    doReturn(runtimeFactory).when(runtimeSpawner).getRuntimeFactory();
    doReturn(instance).when(functionRuntimeInfo).getFunctionInstance();
    doReturn(runtimeSpawner).when(functionRuntimeInfo).getRuntimeSpawner();
    actioner.terminateFunction(functionRuntimeInfo);
    // make sure cache
    verify(functionAuthProvider.get(), times(0)).cleanUpAuthData(any(), any());
}
Also used : ThreadRuntimeFactoryConfig(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactoryConfig) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) RuntimeFactory(org.apache.pulsar.functions.runtime.RuntimeFactory) Namespace(org.apache.distributedlog.api.namespace.Namespace) FunctionAuthProvider(org.apache.pulsar.functions.auth.FunctionAuthProvider) Function(org.apache.pulsar.functions.proto.Function) Runtime(org.apache.pulsar.functions.runtime.Runtime) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) Map(java.util.Map) RuntimeSpawner(org.apache.pulsar.functions.runtime.RuntimeSpawner) Test(org.testng.annotations.Test)

Example 2 with FunctionAuthProvider

use of org.apache.pulsar.functions.auth.FunctionAuthProvider in project pulsar by yahoo.

the class FunctionActionerTest method testFunctionAuthDisabled.

@Test
public void testFunctionAuthDisabled() throws Exception {
    WorkerConfig workerConfig = new WorkerConfig();
    workerConfig.setWorkerId("worker-1");
    workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
    workerConfig.setFunctionRuntimeFactoryConfigs(ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("test"), Map.class));
    workerConfig.setPulsarServiceUrl("pulsar://localhost:6650");
    workerConfig.setStateStorageServiceUrl("foo");
    workerConfig.setFunctionAssignmentTopicName("assignments");
    String downloadDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
    workerConfig.setDownloadDirectory(downloadDir);
    RuntimeFactory factory = mock(RuntimeFactory.class);
    Runtime runtime = mock(Runtime.class);
    doReturn(runtime).when(factory).createContainer(any(), any(), any(), any());
    doNothing().when(runtime).start();
    Namespace dlogNamespace = mock(Namespace.class);
    final String exceptionMsg = "dl namespace not-found";
    doThrow(new IllegalArgumentException(exceptionMsg)).when(dlogNamespace).openLog(any());
    @SuppressWarnings("resource") FunctionActioner actioner = new FunctionActioner(workerConfig, factory, dlogNamespace, new ConnectorsManager(workerConfig), new FunctionsManager(workerConfig), mock(PulsarAdmin.class));
    String pkgPathLocation = "http://invalid/my-file.jar";
    Function.FunctionMetaData functionMeta = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("func-1")).setPackageLocation(PackageLocationMetaData.newBuilder().setPackagePath(pkgPathLocation).build()).build();
    Function.Instance instance = Function.Instance.newBuilder().setFunctionMetaData(functionMeta).build();
    RuntimeSpawner runtimeSpawner = spy(actioner.getRuntimeSpawner(instance, "foo"));
    assertNull(runtimeSpawner.getInstanceConfig().getFunctionAuthenticationSpec());
    FunctionRuntimeInfo functionRuntimeInfo = mock(FunctionRuntimeInfo.class);
    RuntimeFactory runtimeFactory = mock(RuntimeFactory.class);
    Optional<FunctionAuthProvider> functionAuthProvider = Optional.of(mock(FunctionAuthProvider.class));
    doReturn(functionAuthProvider).when(runtimeFactory).getAuthProvider();
    doReturn(runtimeFactory).when(runtimeSpawner).getRuntimeFactory();
    doReturn(instance).when(functionRuntimeInfo).getFunctionInstance();
    doReturn(runtimeSpawner).when(functionRuntimeInfo).getRuntimeSpawner();
    actioner.terminateFunction(functionRuntimeInfo);
    // make sure cache
    verify(functionAuthProvider.get(), times(0)).cleanUpAuthData(any(), any());
}
Also used : ThreadRuntimeFactoryConfig(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactoryConfig) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) RuntimeFactory(org.apache.pulsar.functions.runtime.RuntimeFactory) Namespace(org.apache.distributedlog.api.namespace.Namespace) FunctionAuthProvider(org.apache.pulsar.functions.auth.FunctionAuthProvider) Function(org.apache.pulsar.functions.proto.Function) Runtime(org.apache.pulsar.functions.runtime.Runtime) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) Map(java.util.Map) RuntimeSpawner(org.apache.pulsar.functions.runtime.RuntimeSpawner) Test(org.testng.annotations.Test)

Example 3 with FunctionAuthProvider

use of org.apache.pulsar.functions.auth.FunctionAuthProvider in project pulsar by apache.

the class FunctionActionerTest method testFunctionAuthDisabled.

@Test
public void testFunctionAuthDisabled() throws Exception {
    WorkerConfig workerConfig = new WorkerConfig();
    workerConfig.setWorkerId("worker-1");
    workerConfig.setFunctionRuntimeFactoryClassName(ThreadRuntimeFactory.class.getName());
    workerConfig.setFunctionRuntimeFactoryConfigs(ObjectMapperFactory.getThreadLocal().convertValue(new ThreadRuntimeFactoryConfig().setThreadGroupName("test"), Map.class));
    workerConfig.setPulsarServiceUrl("pulsar://localhost:6650");
    workerConfig.setStateStorageServiceUrl("foo");
    workerConfig.setFunctionAssignmentTopicName("assignments");
    String downloadDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
    workerConfig.setDownloadDirectory(downloadDir);
    RuntimeFactory factory = mock(RuntimeFactory.class);
    Runtime runtime = mock(Runtime.class);
    doReturn(runtime).when(factory).createContainer(any(), any(), any(), any());
    doNothing().when(runtime).start();
    Namespace dlogNamespace = mock(Namespace.class);
    final String exceptionMsg = "dl namespace not-found";
    doThrow(new IllegalArgumentException(exceptionMsg)).when(dlogNamespace).openLog(any());
    @SuppressWarnings("resource") FunctionActioner actioner = new FunctionActioner(workerConfig, factory, dlogNamespace, new ConnectorsManager(workerConfig), new FunctionsManager(workerConfig), mock(PulsarAdmin.class));
    String pkgPathLocation = "http://invalid/my-file.jar";
    Function.FunctionMetaData functionMeta = Function.FunctionMetaData.newBuilder().setFunctionDetails(Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-namespace").setName("func-1")).setPackageLocation(PackageLocationMetaData.newBuilder().setPackagePath(pkgPathLocation).build()).build();
    Function.Instance instance = Function.Instance.newBuilder().setFunctionMetaData(functionMeta).build();
    RuntimeSpawner runtimeSpawner = spy(actioner.getRuntimeSpawner(instance, "foo"));
    assertNull(runtimeSpawner.getInstanceConfig().getFunctionAuthenticationSpec());
    FunctionRuntimeInfo functionRuntimeInfo = mock(FunctionRuntimeInfo.class);
    RuntimeFactory runtimeFactory = mock(RuntimeFactory.class);
    Optional<FunctionAuthProvider> functionAuthProvider = Optional.of(mock(FunctionAuthProvider.class));
    doReturn(functionAuthProvider).when(runtimeFactory).getAuthProvider();
    doReturn(runtimeFactory).when(runtimeSpawner).getRuntimeFactory();
    doReturn(instance).when(functionRuntimeInfo).getFunctionInstance();
    doReturn(runtimeSpawner).when(functionRuntimeInfo).getRuntimeSpawner();
    actioner.terminateFunction(functionRuntimeInfo);
    // make sure cache
    verify(functionAuthProvider.get(), times(0)).cleanUpAuthData(any(), any());
}
Also used : ThreadRuntimeFactoryConfig(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactoryConfig) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) RuntimeFactory(org.apache.pulsar.functions.runtime.RuntimeFactory) Namespace(org.apache.distributedlog.api.namespace.Namespace) FunctionAuthProvider(org.apache.pulsar.functions.auth.FunctionAuthProvider) Function(org.apache.pulsar.functions.proto.Function) Runtime(org.apache.pulsar.functions.runtime.Runtime) ThreadRuntimeFactory(org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory) Map(java.util.Map) RuntimeSpawner(org.apache.pulsar.functions.runtime.RuntimeSpawner) Test(org.testng.annotations.Test)

Aggregations

Map (java.util.Map)3 Namespace (org.apache.distributedlog.api.namespace.Namespace)3 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)3 FunctionAuthProvider (org.apache.pulsar.functions.auth.FunctionAuthProvider)3 Function (org.apache.pulsar.functions.proto.Function)3 Runtime (org.apache.pulsar.functions.runtime.Runtime)3 RuntimeFactory (org.apache.pulsar.functions.runtime.RuntimeFactory)3 RuntimeSpawner (org.apache.pulsar.functions.runtime.RuntimeSpawner)3 ThreadRuntimeFactory (org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory)3 ThreadRuntimeFactoryConfig (org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactoryConfig)3 Test (org.testng.annotations.Test)3