use of org.apache.pulsar.functions.proto.Request in project incubator-pulsar by apache.
the class FunctionMetaDataManager method updateFunction.
/**
* Sends an update request to the FMT (Function Metadata Topic)
* @param functionMetaData The function metadata that needs to be updated
* @return a completable future of when the update has been applied
*/
public synchronized CompletableFuture<RequestResult> updateFunction(FunctionMetaData functionMetaData) {
long version = 0;
String tenant = functionMetaData.getFunctionConfig().getTenant();
if (!this.functionMetaDataMap.containsKey(tenant)) {
this.functionMetaDataMap.put(tenant, new ConcurrentHashMap<>());
}
Map<String, Map<String, FunctionMetaData>> namespaces = this.functionMetaDataMap.get(tenant);
String namespace = functionMetaData.getFunctionConfig().getNamespace();
if (!namespaces.containsKey(namespace)) {
namespaces.put(namespace, new ConcurrentHashMap<>());
}
Map<String, FunctionMetaData> functionMetaDatas = namespaces.get(namespace);
String functionName = functionMetaData.getFunctionConfig().getName();
if (functionMetaDatas.containsKey(functionName)) {
version = functionMetaDatas.get(functionName).getVersion() + 1;
}
FunctionMetaData newFunctionMetaData = functionMetaData.toBuilder().setVersion(version).build();
Request.ServiceRequest updateRequest = ServiceRequestUtils.getUpdateRequest(this.workerConfig.getWorkerId(), newFunctionMetaData);
return submit(updateRequest);
}
use of org.apache.pulsar.functions.proto.Request in project incubator-pulsar by apache.
the class FunctionMetaDataManager method deregisterFunction.
/**
* Sends a deregister request to the FMT (Function Metadata Topic) for a function
* @param tenant the tenant the function that needs to be deregistered belongs to
* @param namespace the namespace the function that needs to be deregistered belongs to
* @param functionName the name of the function
* @return a completable future of when the deregister has been applied
*/
public synchronized CompletableFuture<RequestResult> deregisterFunction(String tenant, String namespace, String functionName) {
FunctionMetaData functionMetaData = this.functionMetaDataMap.get(tenant).get(namespace).get(functionName);
FunctionMetaData newFunctionMetaData = functionMetaData.toBuilder().setVersion(functionMetaData.getVersion() + 1).build();
Request.ServiceRequest deregisterRequest = ServiceRequestUtils.getDeregisterRequest(this.workerConfig.getWorkerId(), newFunctionMetaData);
return submit(deregisterRequest);
}
Aggregations