Search in sources :

Example 16 with FunctionDetails

use of org.apache.pulsar.functions.proto.Function.FunctionDetails in project pulsar by apache.

the class KubernetesRuntimeTest method verifyCreateJobNameWithCollisionalAndInvalidMarksFunctionName.

private void verifyCreateJobNameWithCollisionalAndInvalidMarksFunctionName() throws Exception {
    final FunctionDetails functionDetail1 = createFunctionDetails("test_function*name");
    final FunctionDetails functionDetail2 = createFunctionDetails("test+function*name");
    final String jobName1 = KubernetesRuntime.createJobName(functionDetail1, null);
    final String jobName2 = KubernetesRuntime.createJobName(functionDetail2, null);
    assertNotEquals(jobName1, jobName2);
    KubernetesRuntime.doChecks(functionDetail1, null);
    KubernetesRuntime.doChecks(functionDetail2, null);
}
Also used : FunctionDetails(org.apache.pulsar.functions.proto.Function.FunctionDetails)

Example 17 with FunctionDetails

use of org.apache.pulsar.functions.proto.Function.FunctionDetails in project pulsar by apache.

the class FunctionApiV2ResourceTest method testGetFunctionSuccess.

@Test
public void testGetFunctionSuccess() throws IOException {
    mockInstanceUtils();
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
    SinkSpec sinkSpec = SinkSpec.newBuilder().setTopic(outputTopic).setSerDeClassName(outputSerdeClassName).build();
    FunctionDetails functionDetails = FunctionDetails.newBuilder().setClassName(className).setSink(sinkSpec).setName(function).setNamespace(namespace).setProcessingGuarantees(ProcessingGuarantees.ATMOST_ONCE).setTenant(tenant).setParallelism(parallelism).setSource(SourceSpec.newBuilder().setSubscriptionType(subscriptionType).putAllTopicsToSerDeClassName(topicsToSerDeClassName)).build();
    FunctionMetaData metaData = FunctionMetaData.newBuilder().setCreateTime(System.currentTimeMillis()).setFunctionDetails(functionDetails).setPackageLocation(PackageLocationMetaData.newBuilder().setPackagePath("/path/to/package")).setVersion(1234).build();
    when(mockedManager.getFunctionMetaData(eq(tenant), eq(namespace), eq(function))).thenReturn(metaData);
    FunctionDetails actual = getDefaultFunctionInfo();
    assertEquals(functionDetails, actual);
}
Also used : FunctionMetaData(org.apache.pulsar.functions.proto.Function.FunctionMetaData) FunctionDetails(org.apache.pulsar.functions.proto.Function.FunctionDetails) SinkSpec(org.apache.pulsar.functions.proto.Function.SinkSpec) Test(org.testng.annotations.Test)

Example 18 with FunctionDetails

use of org.apache.pulsar.functions.proto.Function.FunctionDetails in project pulsar by apache.

the class SourceApiV3ResourceTest method testGetSourceSuccess.

@Test
public void testGetSourceSuccess() {
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(source))).thenReturn(true);
    SourceSpec sourceSpec = SourceSpec.newBuilder().setBuiltin("jdbc").build();
    SinkSpec sinkSpec = SinkSpec.newBuilder().setTopic(outputTopic).setSerDeClassName(outputSerdeClassName).build();
    FunctionDetails functionDetails = FunctionDetails.newBuilder().setClassName(IdentityFunction.class.getName()).setSink(sinkSpec).setName(source).setNamespace(namespace).setProcessingGuarantees(ProcessingGuarantees.ATLEAST_ONCE).setRuntime(FunctionDetails.Runtime.JAVA).setAutoAck(true).setTenant(tenant).setParallelism(parallelism).setSource(sourceSpec).build();
    FunctionMetaData metaData = FunctionMetaData.newBuilder().setCreateTime(System.currentTimeMillis()).setFunctionDetails(functionDetails).setPackageLocation(PackageLocationMetaData.newBuilder().setPackagePath("/path/to/package")).setVersion(1234).build();
    when(mockedManager.getFunctionMetaData(eq(tenant), eq(namespace), eq(source))).thenReturn(metaData);
    SourceConfig config = getDefaultSourceInfo();
    assertEquals(SourceConfigUtils.convertFromDetails(functionDetails), config);
}
Also used : FunctionMetaData(org.apache.pulsar.functions.proto.Function.FunctionMetaData) FunctionDetails(org.apache.pulsar.functions.proto.Function.FunctionDetails) SourceSpec(org.apache.pulsar.functions.proto.Function.SourceSpec) IdentityFunction(org.apache.pulsar.functions.api.utils.IdentityFunction) SourceConfig(org.apache.pulsar.common.io.SourceConfig) SinkSpec(org.apache.pulsar.functions.proto.Function.SinkSpec) Test(org.testng.annotations.Test)

Example 19 with FunctionDetails

use of org.apache.pulsar.functions.proto.Function.FunctionDetails in project pulsar by apache.

the class SinkApiV3ResourceTest method testGetSinkSuccess.

@Test
public void testGetSinkSuccess() {
    when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(sink))).thenReturn(true);
    Function.SourceSpec sourceSpec = Function.SourceSpec.newBuilder().setSubscriptionType(Function.SubscriptionType.SHARED).setSubscriptionName(subscriptionName).putInputSpecs("input", Function.ConsumerSpec.newBuilder().setSerdeClassName(DEFAULT_SERDE).setIsRegexPattern(false).build()).build();
    Function.SinkSpec sinkSpec = Function.SinkSpec.newBuilder().setBuiltin("jdbc").build();
    FunctionDetails functionDetails = FunctionDetails.newBuilder().setClassName(IdentityFunction.class.getName()).setSink(sinkSpec).setName(sink).setNamespace(namespace).setProcessingGuarantees(ATLEAST_ONCE).setTenant(tenant).setParallelism(parallelism).setRuntime(FunctionDetails.Runtime.JAVA).setSource(sourceSpec).build();
    FunctionMetaData metaData = FunctionMetaData.newBuilder().setCreateTime(System.currentTimeMillis()).setFunctionDetails(functionDetails).setPackageLocation(Function.PackageLocationMetaData.newBuilder().setPackagePath("/path/to/package")).setVersion(1234).build();
    when(mockedManager.getFunctionMetaData(eq(tenant), eq(namespace), eq(sink))).thenReturn(metaData);
    getDefaultSinkInfo();
    assertNotNull(getDefaultSinkInfo().getInputs());
    assertEquals(getDefaultSinkInfo().getInputs(), Collections.singleton("input"));
    assertEquals(SinkConfigUtils.convertFromDetails(functionDetails), getDefaultSinkInfo());
}
Also used : FunctionMetaData(org.apache.pulsar.functions.proto.Function.FunctionMetaData) Function(org.apache.pulsar.functions.proto.Function) IdentityFunction(org.apache.pulsar.functions.api.utils.IdentityFunction) FunctionDetails(org.apache.pulsar.functions.proto.Function.FunctionDetails) Test(org.testng.annotations.Test)

Example 20 with FunctionDetails

use of org.apache.pulsar.functions.proto.Function.FunctionDetails in project pulsar by yahoo.

the class FunctionActioner method stopFunction.

public void stopFunction(FunctionRuntimeInfo functionRuntimeInfo) {
    Function.Instance instance = functionRuntimeInfo.getFunctionInstance();
    FunctionMetaData functionMetaData = instance.getFunctionMetaData();
    FunctionDetails details = functionMetaData.getFunctionDetails();
    log.info("{}/{}/{}-{} Stopping function...", details.getTenant(), details.getNamespace(), details.getName(), instance.getInstanceId());
    if (functionRuntimeInfo.getRuntimeSpawner() != null) {
        functionRuntimeInfo.getRuntimeSpawner().close();
        functionRuntimeInfo.setRuntimeSpawner(null);
    }
    cleanupFunctionFiles(functionRuntimeInfo);
}
Also used : FunctionMetaData(org.apache.pulsar.functions.proto.Function.FunctionMetaData) Function(org.apache.pulsar.functions.proto.Function) FunctionDetails(org.apache.pulsar.functions.proto.Function.FunctionDetails)

Aggregations

FunctionDetails (org.apache.pulsar.functions.proto.Function.FunctionDetails)111 Test (org.testng.annotations.Test)42 IdentityFunction (org.apache.pulsar.functions.api.utils.IdentityFunction)27 Function (org.apache.pulsar.functions.proto.Function)27 HashMap (java.util.HashMap)21 FunctionConfig (org.apache.pulsar.common.functions.FunctionConfig)21 Gson (com.google.gson.Gson)18 FunctionMetaData (org.apache.pulsar.functions.proto.Function.FunctionMetaData)18 ConsumerConfig (org.apache.pulsar.common.functions.ConsumerConfig)15 File (java.io.File)12 ProducerConfig (org.apache.pulsar.common.functions.ProducerConfig)12 Resources (org.apache.pulsar.common.functions.Resources)12 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)9 IOException (java.io.IOException)9 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)9 SinkSpec (org.apache.pulsar.functions.proto.Function.SinkSpec)9 URL (java.net.URL)6 Map (java.util.Map)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 FileNotFoundException (java.io.FileNotFoundException)5