Skip to content

Commit

Permalink
Changing from lamda to a NO OP guice module
Browse files Browse the repository at this point in the history
  • Loading branch information
sahusanket committed Oct 28, 2024
1 parent 0202ea0 commit e766975
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.cdap.cdap.app.runtime.spark.distributed.SparkTwillRunnable;
import io.cdap.cdap.common.app.RunIds;
import io.cdap.cdap.common.conf.CConfiguration;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.test.MockTwillContext;
import io.cdap.cdap.internal.app.runtime.BasicArguments;
import io.cdap.cdap.internal.app.runtime.ProgramOptionConstants;
Expand Down Expand Up @@ -102,7 +103,7 @@ protected ServiceAnnouncer getServiceAnnouncer() {
}
}.createModule(CConfiguration.create(), new Configuration(),
createProgramOptions(programRunId), programRunId);
Injector injector = Guice.createInjector(module, getAuditLogNoOpModule());
Injector injector = Guice.createInjector(module, new NoOpAuditLogModule());
injector.getInstance(ServiceProgramRunner.class);
injector.getInstance(ProgramStateWriter.class);
}
Expand Down Expand Up @@ -156,7 +157,7 @@ protected ServiceAnnouncer getServiceAnnouncer() {



Injector injector = Guice.createInjector(module,getAuditLogNoOpModule());
Injector injector = Guice.createInjector(module,new NoOpAuditLogModule());
injector.getInstance(SparkProgramRunner.class);
injector.getInstance(ProgramStateWriter.class);

Expand All @@ -182,13 +183,4 @@ private ProgramOptions createProgramOptions(ProgramRunId programRunId) {

return new SimpleProgramOptions(programRunId.getParent(), new BasicArguments(systemArgs), new BasicArguments());
}

private Module getAuditLogNoOpModule(){
return new AbstractModule() {
@Override
protected void configure() {
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.cdap.cdap.common.guice.DFSLocationModule;
import io.cdap.cdap.common.guice.IOModule;
import io.cdap.cdap.common.guice.KafkaClientModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.guice.SupplierProviderBridge;
import io.cdap.cdap.common.guice.ZkClientModule;
import io.cdap.cdap.common.guice.ZkDiscoveryModule;
Expand Down Expand Up @@ -148,11 +149,11 @@ protected void configure() {
bind(UsageWriter.class).to(MessagingUsageWriter.class);
// Overrides the metadata store to be no-op (programs never access it directly)
bind(MetadataStorage.class).to(NoopMetadataStorage.class);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}));

bind(RuntimeMonitorType.class).toInstance(runtimeMonitorType);
modules.add(new NoOpAuditLogModule());
}

private List<Module> getCoreModules() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import io.cdap.cdap.common.conf.CConfiguration;
import io.cdap.cdap.common.conf.Constants;
import io.cdap.cdap.common.discovery.ResolvingDiscoverable;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.io.Locations;
import io.cdap.cdap.common.lang.jar.BundleJarUtil;
import io.cdap.cdap.common.lang.jar.ClassLoaderFolder;
Expand Down Expand Up @@ -483,11 +484,11 @@ protected void configure() {
bind(ArtifactRepositoryReader.class).to(RemoteArtifactRepositoryReader.class)
.in(Scopes.SINGLETON);
bind(ArtifactRepository.class).to(RemoteArtifactRepository.class);

bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
});

modules.add(new NoOpAuditLogModule());

return modules;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.cdap.cdap.common.guice.ConfigModule;
import io.cdap.cdap.common.guice.InMemoryDiscoveryModule;
import io.cdap.cdap.common.guice.LocalLocationModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.http.DefaultHttpRequestConfig;
import io.cdap.cdap.common.internal.remote.InternalAuthenticator;
import io.cdap.cdap.common.internal.remote.NoOpInternalAuthenticator;
Expand Down Expand Up @@ -86,6 +87,7 @@ public void beforeTest() throws Exception {
new ConfigModule(cConf),
new LocalLocationModule(),
new InMemoryDiscoveryModule(),
new NoOpAuditLogModule(),
new AbstractModule() {
@Override
protected void configure() {
Expand All @@ -94,7 +96,6 @@ protected void configure() {
bind(InternalAuthenticator.class).to(
NoOpInternalAuthenticator.class);
bind(RemoteAuthenticator.class).to(NoOpRemoteAuthenticator.class);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.cdap.cdap.common.guice.ConfigModule;
import io.cdap.cdap.common.guice.InMemoryDiscoveryModule;
import io.cdap.cdap.common.guice.LocalLocationModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.guice.RemoteAuthenticatorModules;
import io.cdap.cdap.common.metrics.NoOpMetricsCollectionService;
import io.cdap.cdap.messaging.DefaultTopicMetadata;
Expand Down Expand Up @@ -133,13 +134,7 @@ protected void bindLogProcessor() {
});
}
},
new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
new NoOpAuditLogModule()
);

messagingService = injector.getInstance(MessagingService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import io.cdap.cdap.common.guice.ConfigModule;
import io.cdap.cdap.common.guice.IOModule;
import io.cdap.cdap.common.guice.LocalLocationModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.guice.RemoteAuthenticatorModules;
import io.cdap.cdap.common.io.DatumReader;
import io.cdap.cdap.common.io.DatumWriter;
Expand Down Expand Up @@ -189,9 +190,9 @@ protected void configure() {
NoOpMetricsCollectionService.class);
bind(DiscoveryService.class).toInstance(discoveryService);
bind(DiscoveryServiceClient.class).toInstance(discoveryService);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
},
new NoOpAuditLogModule()
);

messagingService = injector.getInstance(MessagingService.class);
Expand Down Expand Up @@ -224,6 +225,7 @@ protected void configure() {
new AuthorizationEnforcementModule().getNoOpModules(),
new AuthenticationContextModules().getNoOpModule(),
new IOModule(),
new NoOpAuditLogModule(),
new AbstractModule() {
@Override
protected void configure() {
Expand All @@ -234,7 +236,6 @@ protected void configure() {
bind(DiscoveryService.class).toInstance(discoveryService);
bind(DiscoveryServiceClient.class).toInstance(discoveryService);
bind(ProgramRunId.class).toInstance(PROGRAM_RUN_ID);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.cdap.cdap.common.guice.ConfigModule;
import io.cdap.cdap.common.guice.InMemoryDiscoveryModule;
import io.cdap.cdap.common.guice.LocalLocationModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.http.DefaultHttpRequestConfig;
import io.cdap.cdap.common.internal.remote.NoOpRemoteAuthenticator;
import io.cdap.cdap.common.internal.remote.RemoteClient;
Expand Down Expand Up @@ -134,9 +135,9 @@ protected void bindLogProcessor() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
},
new NoOpAuditLogModule()
);

messagingService = injector.getInstance(MessagingService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import io.cdap.cdap.common.discovery.EndpointStrategy;
import io.cdap.cdap.common.discovery.RandomEndpointStrategy;
import io.cdap.cdap.common.discovery.URIScheme;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.id.Id;
import io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator;
import io.cdap.cdap.common.internal.remote.RemoteClientFactory;
Expand Down Expand Up @@ -246,7 +247,7 @@ protected void configure() {
// needed because we set Kerberos to true in DefaultNamespaceAdminTest
bind(UGIProvider.class).to(CurrentUGIProvider.class);
bind(MetadataSubscriberService.class).in(Scopes.SINGLETON);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
install(new NoOpAuditLogModule());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.cdap.cdap.common.guice.ConfigModule;
import io.cdap.cdap.common.guice.IOModule;
import io.cdap.cdap.common.guice.InMemoryDiscoveryModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.guice.NonCustomLocationUnitTestModule;
import io.cdap.cdap.common.guice.RemoteAuthenticatorModules;
import io.cdap.cdap.common.twill.NoopTwillRunnerService;
Expand Down Expand Up @@ -109,8 +110,8 @@ protected void configure() {
install(new MetadataReaderWriterModules().getInMemoryModules());
install(new MessagingServerRuntimeModule().getInMemoryModules());
install(new MockProvisionerModule());
install(new NoOpAuditLogModule());
// Needed by MonitorHandlerModuler
bind(TwillRunner.class).to(NoopTwillRunnerService.class);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.cdap.cdap.common.guice.ConfigModule;
import io.cdap.cdap.common.guice.InMemoryDiscoveryModule;
import io.cdap.cdap.common.guice.LocalLocationModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.metrics.NoOpMetricsCollectionService;
import io.cdap.cdap.data.runtime.StorageModule;
import io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule;
Expand Down Expand Up @@ -67,13 +68,13 @@ public void testGuiceInjector() throws Exception {
new ProvisionerModule(),
new AuthorizationEnforcementModule().getNoOpModules(),
new MessagingServerRuntimeModule().getInMemoryModules(),
new NoOpAuditLogModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
bind(SecureStore.class).toInstance(FakeSecureStore.builder().build());
bind(ProgramStateWriter.class).to(NoOpProgramStateWriter.class);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import io.cdap.cdap.common.guice.ConfigModule;
import io.cdap.cdap.common.guice.InMemoryDiscoveryModule;
import io.cdap.cdap.common.guice.LocalLocationModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.metrics.NoOpMetricsCollectionService;
import io.cdap.cdap.data.runtime.StorageModule;
import io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule;
Expand Down Expand Up @@ -124,11 +125,11 @@ public static void setUp() throws IOException, TopicAlreadyExistsException, Peer
new SystemDatasetRuntimeModule().getInMemoryModules(),
new TransactionModules().getInMemoryModules(),
new StorageModule(),
new NoOpAuditLogModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class).in(Scopes.SINGLETON);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
});
// Define all StructuredTable before starting any services that need StructuredTable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.cdap.cdap.common.guice;

import com.google.inject.AbstractModule;
import io.cdap.cdap.api.auditlogging.AuditLogWriter;

/**
* A NO OPERATION guice module for {@link AuditLogWriter}.
* This is to be used in modules where AUDIT LOGGING is not expected, but it is a part of common netty layer binding,
* So it needs to be included.
*/
public class NoOpAuditLogModule extends AbstractModule {
@Override
protected void configure() {
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.cdap.cdap.common.guice.DFSLocationModule;
import io.cdap.cdap.common.guice.IOModule;
import io.cdap.cdap.common.guice.KafkaClientModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.guice.RemoteAuthenticatorModules;
import io.cdap.cdap.common.guice.ZkClientModule;
import io.cdap.cdap.common.guice.ZkDiscoveryModule;
Expand Down Expand Up @@ -125,6 +126,7 @@ static Injector createInjector(CConfiguration cConf, Configuration hConf, String
new SecureStoreClientModule(),
new AuthorizationEnforcementModule().getDistributedModules(),
new AuthenticationContextModules().getMasterModule(),
new NoOpAuditLogModule(),
new AbstractModule() {
@Override
protected void configure() {
Expand All @@ -135,7 +137,6 @@ protected void configure() {
// TODO (CDAP-14677): find a better way to inject metadata publisher
bind(MetadataPublisher.class).to(MessagingMetadataPublisher.class);
bind(MetadataServiceClient.class).to(DefaultMetadataServiceClient.class);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.cdap.cdap.common.guice.DFSLocationModule;
import io.cdap.cdap.common.guice.IOModule;
import io.cdap.cdap.common.guice.KafkaClientModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.guice.RemoteAuthenticatorModules;
import io.cdap.cdap.common.guice.ZkClientModule;
import io.cdap.cdap.common.guice.ZkDiscoveryModule;
Expand Down Expand Up @@ -119,12 +120,12 @@ static Injector createGuiceInjector(CConfiguration cConf, Configuration hConf,
new AuthorizationEnforcementModule().getDistributedModules(),
new AuthenticationContextModules().getMasterModule(),
new MessagingClientModule(),
new NoOpAuditLogModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
bind(UGIProvider.class).to(RemoteUGIProvider.class).in(Scopes.SINGLETON);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.cdap.cdap.common.guice.DFSLocationModule;
import io.cdap.cdap.common.guice.IOModule;
import io.cdap.cdap.common.guice.KafkaClientModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.guice.RemoteAuthenticatorModules;
import io.cdap.cdap.common.guice.ZkClientModule;
import io.cdap.cdap.common.guice.ZkDiscoveryModule;
Expand Down Expand Up @@ -136,11 +137,11 @@ static Injector createGuiceInjector(CConfiguration cConf, Configuration hConf, S
new AuthorizationEnforcementModule().getDistributedModules(),
new AuthenticationContextModules().getMasterModule(),
new MetricsWriterModule(),
new NoOpAuditLogModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.cdap.cdap.common.guice.DFSLocationModule;
import io.cdap.cdap.common.guice.IOModule;
import io.cdap.cdap.common.guice.KafkaClientModule;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.common.guice.RemoteAuthenticatorModules;
import io.cdap.cdap.common.guice.ZkClientModule;
import io.cdap.cdap.common.guice.ZkDiscoveryModule;
Expand Down Expand Up @@ -127,12 +128,12 @@ static Injector createGuiceInjector(CConfiguration cConf, Configuration hConf,
new AuditModule(),
new AuthorizationEnforcementModule().getDistributedModules(),
new AuthenticationContextModules().getMasterModule(),
new NoOpAuditLogModule(),
new AbstractModule() {
@Override
protected void configure() {
bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
bind(UGIProvider.class).to(RemoteUGIProvider.class).in(Scopes.SINGLETON);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.cdap.cdap.api.auditlogging.AuditLogWriter;
import io.cdap.cdap.api.data.DatasetContext;
import io.cdap.cdap.common.conf.Constants;
import io.cdap.cdap.common.guice.NoOpAuditLogModule;
import io.cdap.cdap.security.spi.authorization.AuthorizationContext;
import io.cdap.cdap.security.spi.authorization.PermissionManager;

Expand All @@ -43,7 +44,7 @@ protected void configure() {
expose(PermissionManager.class);
bind(RoleController.class).to(DelegatingRoleController.class).in(Scopes.SINGLETON);;
expose(RoleController.class);
bind(AuditLogWriter.class).toInstance(auditLogContexts -> {});
install(new NoOpAuditLogModule());
expose(AuditLogWriter.class);
}
}
Loading

0 comments on commit e766975

Please sign in to comment.