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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations