use of org.apache.pulsar.functions.proto.Function.SinkSpec in project pulsar by apache.
the class FunctionActioner method getBuiltinArchive.
private File getBuiltinArchive(FunctionDetails.Builder functionDetails) throws IOException, ClassNotFoundException {
if (functionDetails.hasSource()) {
SourceSpec sourceSpec = functionDetails.getSource();
if (!StringUtils.isEmpty(sourceSpec.getBuiltin())) {
Connector connector = connectorsManager.getConnector(sourceSpec.getBuiltin());
File archive = connector.getArchivePath().toFile();
String sourceClass = connector.getConnectorDefinition().getSourceClass();
SourceSpec.Builder builder = SourceSpec.newBuilder(functionDetails.getSource());
builder.setClassName(sourceClass);
functionDetails.setSource(builder);
fillSourceTypeClass(functionDetails, connector.getClassLoader(), sourceClass);
return archive;
}
}
if (functionDetails.hasSink()) {
SinkSpec sinkSpec = functionDetails.getSink();
if (!StringUtils.isEmpty(sinkSpec.getBuiltin())) {
Connector connector = connectorsManager.getConnector(sinkSpec.getBuiltin());
File archive = connector.getArchivePath().toFile();
String sinkClass = connector.getConnectorDefinition().getSinkClass();
SinkSpec.Builder builder = SinkSpec.newBuilder(functionDetails.getSink());
builder.setClassName(sinkClass);
functionDetails.setSink(builder);
fillSinkTypeClass(functionDetails, connector.getClassLoader(), sinkClass);
return archive;
}
}
if (!StringUtils.isEmpty(functionDetails.getBuiltin())) {
return functionsManager.getFunctionArchive(functionDetails.getBuiltin()).toFile();
}
throw new IOException("Could not find built in archive definition");
}
use of org.apache.pulsar.functions.proto.Function.SinkSpec 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.SinkSpec 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.SinkSpec in project pulsar by yahoo.
the class FunctionActioner method getBuiltinArchive.
private File getBuiltinArchive(FunctionDetails.Builder functionDetails) throws IOException, ClassNotFoundException {
if (functionDetails.hasSource()) {
SourceSpec sourceSpec = functionDetails.getSource();
if (!StringUtils.isEmpty(sourceSpec.getBuiltin())) {
Connector connector = connectorsManager.getConnector(sourceSpec.getBuiltin());
File archive = connector.getArchivePath().toFile();
String sourceClass = connector.getConnectorDefinition().getSourceClass();
SourceSpec.Builder builder = SourceSpec.newBuilder(functionDetails.getSource());
builder.setClassName(sourceClass);
functionDetails.setSource(builder);
fillSourceTypeClass(functionDetails, connector.getClassLoader(), sourceClass);
return archive;
}
}
if (functionDetails.hasSink()) {
SinkSpec sinkSpec = functionDetails.getSink();
if (!StringUtils.isEmpty(sinkSpec.getBuiltin())) {
Connector connector = connectorsManager.getConnector(sinkSpec.getBuiltin());
File archive = connector.getArchivePath().toFile();
String sinkClass = connector.getConnectorDefinition().getSinkClass();
SinkSpec.Builder builder = SinkSpec.newBuilder(functionDetails.getSink());
builder.setClassName(sinkClass);
functionDetails.setSink(builder);
fillSinkTypeClass(functionDetails, connector.getClassLoader(), sinkClass);
return archive;
}
}
if (!StringUtils.isEmpty(functionDetails.getBuiltin())) {
return functionsManager.getFunctionArchive(functionDetails.getBuiltin()).toFile();
}
throw new IOException("Could not find built in archive definition");
}
use of org.apache.pulsar.functions.proto.Function.SinkSpec in project pulsar by yahoo.
the class FunctionActioner method fillSourceTypeClass.
private void fillSourceTypeClass(FunctionDetails.Builder functionDetails, ClassLoader narClassLoader, String className) throws ClassNotFoundException {
String typeArg = getSourceType(className, narClassLoader).getName();
SourceSpec.Builder sourceBuilder = SourceSpec.newBuilder(functionDetails.getSource());
sourceBuilder.setTypeClassName(typeArg);
functionDetails.setSource(sourceBuilder);
SinkSpec sinkSpec = functionDetails.getSink();
if (null == sinkSpec || StringUtils.isEmpty(sinkSpec.getTypeClassName())) {
SinkSpec.Builder sinkBuilder = SinkSpec.newBuilder(sinkSpec);
sinkBuilder.setTypeClassName(typeArg);
functionDetails.setSink(sinkBuilder);
}
}
Aggregations