use of io.cdap.cdap.api.app.ProgramType in project cdap by caskdata.
the class RemoteConfiguratorTest method testRemoteConfigurator.
@Test
public void testRemoteConfigurator() throws Exception {
LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFolder());
Location appJar = AppJarHelper.createDeploymentJar(locationFactory, AllProgramsApp.class);
ArtifactId artifactId = NamespaceId.DEFAULT.artifact(AllProgramsApp.class.getSimpleName(), "1.0.0");
artifacts.put(artifactId, new ArtifactDetail(new ArtifactDescriptor(artifactId.getNamespace(), artifactId.toApiArtifactId(), appJar), new ArtifactMeta(ArtifactClasses.builder().build())));
AppDeploymentInfo info = new AppDeploymentInfo(artifactId, appJar, NamespaceId.DEFAULT, new ApplicationClass(AllProgramsApp.class.getName(), "", null), null, null, null);
Configurator configurator = new RemoteConfigurator(cConf, metricsCollectionService, info, remoteClientFactory);
// 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());
}
use of io.cdap.cdap.api.app.ProgramType in project cdap by caskdata.
the class ApplicationSpecificationAdapterTest method testGetProgramIds.
@Test
public void testGetProgramIds() throws IOException {
ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
Set<ProgramId> expectedIds = new HashSet<>();
for (ProgramType programType : ProgramType.values()) {
appSpec.getProgramsByType(programType).stream().map(name -> appId.program(io.cdap.cdap.proto.ProgramType.valueOf(programType.name()), name)).forEach(expectedIds::add);
}
String json = ApplicationSpecificationAdapter.create().toJson(appSpec);
try (JsonReader reader = new JsonReader(new StringReader(json))) {
Set<ProgramId> programIds = ApplicationSpecificationAdapter.getProgramIds(appId, reader);
Assert.assertEquals(expectedIds, programIds);
}
}
use of io.cdap.cdap.api.app.ProgramType 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());
}
use of io.cdap.cdap.api.app.ProgramType in project cdap by caskdata.
the class AuditPublishTest method testPublish.
@Test
public void testPublish() throws Exception {
String appName = AllProgramsApp.NAME;
ApplicationId appId = NamespaceId.DEFAULT.app(appName);
ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
// Define expected values
Set<EntityId> expectedMetadataChangeEntities = new HashSet<>();
// Metadata change on the artifact and app
expectedMetadataChangeEntities.add(NamespaceId.DEFAULT.artifact(AllProgramsApp.class.getSimpleName(), "1"));
expectedMetadataChangeEntities.add(appId);
// All programs would have metadata change
for (ProgramType programType : ProgramType.values()) {
for (String programName : spec.getProgramsByType(programType)) {
io.cdap.cdap.proto.ProgramType internalProgramType = io.cdap.cdap.proto.ProgramType.valueOf(programType.name());
expectedMetadataChangeEntities.add(appId.program(internalProgramType, programName));
}
}
// All dataset would have metadata change as well as creation
Set<EntityId> expectedCreateEntities = new HashSet<>();
for (String dataset : spec.getDatasets().keySet()) {
expectedCreateEntities.add(NamespaceId.DEFAULT.dataset(dataset));
}
expectedMetadataChangeEntities.addAll(expectedCreateEntities);
// TODO (CDAP-14733): Scheduler doesn't publish CREATE audit events. Once it does, we must expect them here, too.
for (String schedule : spec.getProgramSchedules().keySet()) {
expectedMetadataChangeEntities.add(appId.schedule(schedule));
}
Multimap<AuditType, EntityId> expectedAuditEntities = HashMultimap.create();
expectedAuditEntities.putAll(AuditType.METADATA_CHANGE, expectedMetadataChangeEntities);
expectedAuditEntities.putAll(AuditType.CREATE, expectedCreateEntities);
// Deploy application
AppFabricTestHelper.deployApplication(Id.Namespace.DEFAULT, AllProgramsApp.class, null, cConf);
// Verify audit messages
Tasks.waitFor(expectedAuditEntities, () -> {
List<AuditMessage> publishedMessages = fetchAuditMessages();
Multimap<AuditType, EntityId> actualAuditEntities = HashMultimap.create();
for (AuditMessage message : publishedMessages) {
EntityId entityId = EntityId.fromMetadataEntity(message.getEntity());
if (entityId instanceof NamespacedEntityId) {
if (((NamespacedEntityId) entityId).getNamespace().equals(NamespaceId.SYSTEM.getNamespace())) {
// Ignore system audit messages
continue;
}
}
if (entityId.getEntityType() == EntityType.ARTIFACT && entityId instanceof ArtifactId) {
ArtifactId artifactId = (ArtifactId) entityId;
// Version is dynamic for deploys in test cases
entityId = Ids.namespace(artifactId.getNamespace()).artifact(artifactId.getArtifact(), "1");
}
actualAuditEntities.put(message.getType(), entityId);
}
return actualAuditEntities;
}, 5, TimeUnit.SECONDS);
}
Aggregations