forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding Intercept Interface * adding intercept classes * addressing comments * updating impl * adding * improving * adding implementation * fixes * improving impl * removing impl Refactor intercept interface (#12) * refactoring intercept interface * cleaning up * fix bug
- Loading branch information
Showing
39 changed files
with
1,804 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...r-common/src/main/java/org/apache/pulsar/broker/intercept/FunctionsInterceptProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.apache.pulsar.broker.intercept; | ||
|
||
import org.apache.pulsar.common.functions.FunctionConfig; | ||
import org.apache.pulsar.common.io.SinkConfig; | ||
import org.apache.pulsar.common.io.SourceConfig; | ||
|
||
public interface FunctionsInterceptProvider { | ||
/** | ||
* Intercept call for create function | ||
* | ||
* @param functionConfig function config of the function to be created | ||
* @param clientRole the role used to create function | ||
*/ | ||
default void createFunction(FunctionConfig functionConfig, String clientRole) throws InterceptException {} | ||
|
||
/** | ||
* Intercept call for update function | ||
* @param functionConfig function config of the function to be updated | ||
* @param existingFunctionConfig | ||
* @param clientRole the role used to update function | ||
*/ | ||
default void updateFunction(FunctionConfig functionConfig, FunctionConfig existingFunctionConfig, String clientRole) throws InterceptException {} | ||
} |
34 changes: 34 additions & 0 deletions
34
...er-common/src/main/java/org/apache/pulsar/broker/intercept/FunctionsInterceptService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.apache.pulsar.broker.intercept; | ||
|
||
import org.apache.pulsar.common.functions.FunctionConfig; | ||
|
||
public class FunctionsInterceptService { | ||
|
||
private final FunctionsInterceptProvider provider; | ||
|
||
public FunctionsInterceptService(FunctionsInterceptProvider functionsInterceptProvider) { | ||
this.provider = functionsInterceptProvider; | ||
} | ||
|
||
/** | ||
* Intercept call for create function | ||
* | ||
* @param functionConfig function config of the function to be created | ||
* @param clientRole the role used to create function | ||
*/ | ||
public void createFunction(FunctionConfig functionConfig, String clientRole) throws InterceptException { | ||
provider.createFunction(functionConfig, clientRole); | ||
} | ||
|
||
/** | ||
* Intercept call for update source | ||
* | ||
* @param updates updates to this function's function config | ||
* @param existingFunctionConfig the existing function config | ||
* @param clientRole the role used to update function | ||
*/ | ||
public void updateFunction(FunctionConfig updates, FunctionConfig existingFunctionConfig, String clientRole) throws InterceptException { | ||
provider.updateFunction(updates, existingFunctionConfig, clientRole); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...ar-broker-common/src/main/java/org/apache/pulsar/broker/intercept/InterceptException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.intercept; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.Optional; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class InterceptException extends Exception { | ||
|
||
private Optional<Integer> errorCode = Optional.empty(); | ||
|
||
public InterceptException(Integer errorCode, String errorMessage) { | ||
super(errorMessage); | ||
this.errorCode = Optional.of(errorCode); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/intercept/InterceptProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.intercept; | ||
|
||
import org.apache.pulsar.broker.ServiceConfiguration; | ||
import org.apache.pulsar.client.admin.PulsarAdmin; | ||
|
||
/** | ||
* This class provides a mechanism to intercept various API calls | ||
*/ | ||
public interface InterceptProvider { | ||
|
||
default TenantsInterceptProvider getTenantInterceptProvider() { | ||
return new TenantsInterceptProvider() {}; | ||
} | ||
|
||
default NamespacesInterceptProvider getNamespaceInterceptProvider() { | ||
return new NamespacesInterceptProvider() {}; | ||
} | ||
|
||
default TopicsInterceptProvider getTopicInterceptProvider() { | ||
return new TopicsInterceptProvider() {}; | ||
} | ||
|
||
default FunctionsInterceptProvider getFunctionsInterceptProvider() { | ||
return new FunctionsInterceptProvider() {}; | ||
} | ||
|
||
default SourcesInterceptProvider getSourcesInterceptProvider() { | ||
return new SourcesInterceptProvider() {}; | ||
} | ||
|
||
default SinksInterceptProvider getSinksInterceptProvider() { | ||
return new SinksInterceptProvider() {}; | ||
} | ||
|
||
/** | ||
* Perform initialization for the intercept provider | ||
* | ||
* @param conf broker config object | ||
*/ | ||
default void initialize(ServiceConfiguration conf, PulsarAdmin pulsarAdmin) throws InterceptException {} | ||
} |
95 changes: 95 additions & 0 deletions
95
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/intercept/InterceptService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.intercept; | ||
|
||
import com.google.common.annotations.Beta; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.pulsar.broker.PulsarServerException; | ||
import org.apache.pulsar.broker.ServiceConfiguration; | ||
import org.apache.pulsar.client.admin.PulsarAdmin; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
/** | ||
* Service that manages intercepting API calls to a pulsar cluster | ||
*/ | ||
@Beta | ||
public class InterceptService { | ||
private static final Logger log = LoggerFactory.getLogger(InterceptService.class); | ||
|
||
private InterceptProvider provider; | ||
private final ServiceConfiguration conf; | ||
private final TenantsInterceptService tenantInterceptService; | ||
private final NamespacesInterceptService namespaceInterceptService; | ||
private final TopicInterceptService topicInterceptService; | ||
private final FunctionsInterceptService functionInterceptService; | ||
private final SinksInterceptService sinkInterceptService; | ||
private final SourcesInterceptService sourceInterceptService; | ||
|
||
public InterceptService(ServiceConfiguration conf, PulsarAdmin pulsarAdmin) | ||
throws PulsarServerException { | ||
this.conf = conf; | ||
|
||
try { | ||
final String providerClassname = conf.getInterceptProvider(); | ||
if (StringUtils.isNotBlank(providerClassname)) { | ||
provider = (InterceptProvider) Class.forName(providerClassname).newInstance(); | ||
provider.initialize(conf, pulsarAdmin); | ||
log.info("Interceptor {} has been loaded.", providerClassname); | ||
} else { | ||
provider = new InterceptProvider() {}; | ||
} | ||
|
||
tenantInterceptService = new TenantsInterceptService(provider.getTenantInterceptProvider()); | ||
namespaceInterceptService = new NamespacesInterceptService(provider.getNamespaceInterceptProvider()); | ||
topicInterceptService = new TopicInterceptService(provider.getTopicInterceptProvider()); | ||
functionInterceptService = new FunctionsInterceptService(provider.getFunctionsInterceptProvider()); | ||
sourceInterceptService = new SourcesInterceptService(provider.getSourcesInterceptProvider()); | ||
sinkInterceptService = new SinksInterceptService(provider.getSinksInterceptProvider()); | ||
|
||
} catch (Throwable e) { | ||
throw new PulsarServerException("Failed to load an intercept provider.", e); | ||
} | ||
} | ||
|
||
public TenantsInterceptService tenants() { | ||
return tenantInterceptService; | ||
} | ||
|
||
public NamespacesInterceptService namespaces() { | ||
return namespaceInterceptService; | ||
} | ||
|
||
public TopicInterceptService topics() { | ||
return topicInterceptService; | ||
} | ||
|
||
public FunctionsInterceptService functions() { | ||
return functionInterceptService; | ||
} | ||
|
||
public SourcesInterceptService sources() { | ||
return sourceInterceptService; | ||
} | ||
|
||
public SinksInterceptService sinks() { | ||
return sinkInterceptService; | ||
} | ||
} |
Oops, something went wrong.