use of io.cdap.cdap.internal.app.runtime.artifact.AuthorizationArtifactRepository in project cdap by caskdata.
the class ConfiguratorTest method testAppWithConfig.
@Test
public void testAppWithConfig() throws Exception {
LocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, ConfigTestApp.class);
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, ConfigTestApp.class.getSimpleName(), "1.0.0");
CConfiguration cConf = CConfiguration.create();
ArtifactRepository baseArtifactRepo = new DefaultArtifactRepository(conf, null, null, null, new DummyProgramRunnerFactory(), new DefaultImpersonator(cConf, null));
ArtifactRepository artifactRepo = new AuthorizationArtifactRepository(baseArtifactRepo, authEnforcer, authenticationContext);
PluginFinder pluginFinder = new LocalPluginFinder(artifactRepo);
ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("myTable");
AppDeploymentInfo appDeploymentInfo = new AppDeploymentInfo(artifactId.toEntityId(), appJar, NamespaceId.DEFAULT, new ApplicationClass(ConfigTestApp.class.getName(), "", null), null, null, new Gson().toJson(config));
// Create a configurator that is testable. Provide it an application.
Configurator configurator = new InMemoryConfigurator(conf, pluginFinder, new DefaultImpersonator(cConf, null), artifactRepo, null, appDeploymentInfo);
ListenableFuture<ConfigResponse> result = configurator.config();
ConfigResponse response = result.get(10, TimeUnit.SECONDS);
Assert.assertNotNull(response);
AppSpecInfo appSpecInfo = response.getAppSpecInfo();
if (appSpecInfo == null) {
throw new IllegalStateException("Failed to deploy application");
}
ApplicationSpecification specification = appSpecInfo.getAppSpec();
Assert.assertNotNull(specification);
Assert.assertEquals(1, specification.getDatasets().size());
Assert.assertTrue(specification.getDatasets().containsKey("myTable"));
// Create a deployment info without the app configuration
appDeploymentInfo = new AppDeploymentInfo(artifactId.toEntityId(), appJar, NamespaceId.DEFAULT, new ApplicationClass(ConfigTestApp.class.getName(), "", null), null, null, null);
Configurator configuratorWithoutConfig = new InMemoryConfigurator(conf, pluginFinder, new DefaultImpersonator(cConf, null), artifactRepo, null, appDeploymentInfo);
result = configuratorWithoutConfig.config();
response = result.get(10, TimeUnit.SECONDS);
Assert.assertNotNull(response);
appSpecInfo = response.getAppSpecInfo();
if (appSpecInfo == null) {
throw new IllegalStateException("Failed to deploy application");
}
specification = appSpecInfo.getAppSpec();
Assert.assertNotNull(specification);
Assert.assertEquals(1, specification.getDatasets().size());
Assert.assertTrue(specification.getDatasets().containsKey(ConfigTestApp.DEFAULT_TABLE));
Assert.assertNotNull(specification.getProgramSchedules().get(ConfigTestApp.SCHEDULE_NAME));
ProgramStatusTrigger trigger = (ProgramStatusTrigger) specification.getProgramSchedules().get(ConfigTestApp.SCHEDULE_NAME).getTrigger();
Assert.assertEquals(trigger.getProgramId().getProgram(), ConfigTestApp.WORKFLOW_NAME);
}
use of io.cdap.cdap.internal.app.runtime.artifact.AuthorizationArtifactRepository in project cdap by caskdata.
the class ConfiguratorTest method testInMemoryConfigurator.
@Test
public void testInMemoryConfigurator() throws Exception {
LocationFactory locationFactory = new LocalLocationFactory(TMP_FOLDER.newFolder());
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, AllProgramsApp.class);
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, AllProgramsApp.class.getSimpleName(), "1.0.0");
CConfiguration cConf = CConfiguration.create();
ArtifactRepository baseArtifactRepo = new DefaultArtifactRepository(conf, null, null, null, new DummyProgramRunnerFactory(), new DefaultImpersonator(cConf, null));
ArtifactRepository artifactRepo = new AuthorizationArtifactRepository(baseArtifactRepo, authEnforcer, authenticationContext);
PluginFinder pluginFinder = new LocalPluginFinder(artifactRepo);
AppDeploymentInfo appDeploymentInfo = new AppDeploymentInfo(artifactId.toEntityId(), appJar, NamespaceId.DEFAULT, new ApplicationClass(AllProgramsApp.class.getName(), "", null), null, null, null);
// Create a configurator that is testable. Provide it a application.
Configurator configurator = new InMemoryConfigurator(conf, pluginFinder, new DefaultImpersonator(cConf, null), artifactRepo, null, appDeploymentInfo);
// Extract response from the configurator.
ListenableFuture<ConfigResponse> result = configurator.config();
ConfigResponse response = result.get(10, TimeUnit.SECONDS);
Assert.assertNotNull(response);
AppSpecInfo appSpecInfo = response.getAppSpecInfo();
if (appSpecInfo == null) {
throw new IllegalStateException("Failed to deploy application");
}
ApplicationSpecification specification = appSpecInfo.getAppSpec();
Assert.assertNotNull(specification);
// Simple checks.
Assert.assertEquals(AllProgramsApp.NAME, specification.getName());
ApplicationSpecification expectedSpec = Specifications.from(new AllProgramsApp());
for (ProgramType programType : ProgramType.values()) {
Assert.assertEquals(expectedSpec.getProgramsByType(programType), specification.getProgramsByType(programType));
}
Assert.assertEquals(expectedSpec.getDatasets(), specification.getDatasets());
}
Aggregations