use of io.cdap.cdap.WorkflowAppWithFork in project cdap by caskdata.
the class CapabilityManagementServiceTest method testApplicationDeployment.
@Test
public void testApplicationDeployment() throws Exception {
String externalConfigPath = tmpFolder.newFolder("capability-config-app").getAbsolutePath();
cConfiguration.set(Constants.Capability.CONFIG_DIR, externalConfigPath);
capabilityManagementService.runTask();
String testVersion = "1.0.0";
// Deploy application with capability
Class<CapabilityAppWithWorkflow> appWithWorkflowClass = CapabilityAppWithWorkflow.class;
Requirements declaredAnnotation = appWithWorkflowClass.getDeclaredAnnotation(Requirements.class);
// verify this app has capabilities
Assert.assertTrue(declaredAnnotation.capabilities().length > 0);
try {
capabilityStatusStore.checkAllEnabled(Arrays.asList(declaredAnnotation.capabilities()));
Assert.fail("expecting exception");
} catch (CapabilityNotAvailableException ex) {
}
String appNameWithCapability = appWithWorkflowClass.getSimpleName() + UUID.randomUUID();
deployTestArtifact(Id.Namespace.DEFAULT.getId(), appNameWithCapability, testVersion, appWithWorkflowClass);
try {
// deploy app
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, appNameWithCapability, testVersion);
applicationLifecycleService.deployApp(NamespaceId.DEFAULT, appNameWithCapability, testVersion, artifactId, null, programId -> {
});
Assert.fail("Expecting exception");
} catch (CapabilityNotAvailableException ex) {
// expected
}
// Deploy application without capability
Class<WorkflowAppWithFork> appNoCapabilityClass = WorkflowAppWithFork.class;
Requirements declaredAnnotation1 = appNoCapabilityClass.getDeclaredAnnotation(Requirements.class);
// verify this app has no capabilities
Assert.assertNull(declaredAnnotation1);
String appNameWithOutCapability = appWithWorkflowClass.getSimpleName() + UUID.randomUUID();
deployArtifactAndApp(appNoCapabilityClass, appNameWithOutCapability, testVersion);
// enable the capabilities
List<CapabilityConfig> capabilityConfigs = Arrays.stream(declaredAnnotation.capabilities()).map(capability -> new CapabilityConfig("Test capability", CapabilityStatus.ENABLED, capability, Collections.emptyList(), Collections.emptyList(), Collections.emptyList())).collect(Collectors.toList());
for (CapabilityConfig capabilityConfig : capabilityConfigs) {
writeConfigAsFile(externalConfigPath, capabilityConfig.getCapability(), capabilityConfig);
}
capabilityManagementService.runTask();
// deployment should go through now
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, appNameWithCapability, testVersion);
applicationLifecycleService.deployApp(NamespaceId.DEFAULT, appNameWithCapability, testVersion, artifactId, null, programId -> {
});
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithCapability, testVersion));
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithOutCapability, testVersion));
artifactRepository.deleteArtifact(Id.Artifact.from(new Id.Namespace(NamespaceId.DEFAULT.getNamespace()), appNameWithCapability, testVersion));
artifactRepository.deleteArtifact(Id.Artifact.from(new Id.Namespace(NamespaceId.DEFAULT.getNamespace()), appNameWithOutCapability, testVersion));
for (CapabilityConfig capabilityConfig : capabilityConfigs) {
new File(externalConfigPath, capabilityConfig.getCapability()).delete();
}
capabilityManagementService.runTask();
}
use of io.cdap.cdap.WorkflowAppWithFork in project cdap by caskdata.
the class CapabilityApplierTest method testGetAppsWithCapability.
@Test
public void testGetAppsWithCapability() throws Exception {
// Deploy application with capability
Class<CapabilityAppWithWorkflow> appWithWorkflowClass = CapabilityAppWithWorkflow.class;
Requirements declaredAnnotation = appWithWorkflowClass.getDeclaredAnnotation(Requirements.class);
// verify this app has capabilities
Assert.assertTrue(declaredAnnotation.capabilities().length > 0);
String appNameWithCapabilities = appWithWorkflowClass.getSimpleName() + UUID.randomUUID();
for (String capability : declaredAnnotation.capabilities()) {
CapabilityConfig capabilityConfig = new CapabilityConfig("Enable", CapabilityStatus.ENABLED, capability, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
capabilityWriter.addOrUpdateCapability(capability, CapabilityStatus.ENABLED, capabilityConfig);
}
deployArtifactAndApp(appWithWorkflowClass, appNameWithCapabilities);
// Deploy application without capability
Class<WorkflowAppWithFork> appNoCapabilityClass = WorkflowAppWithFork.class;
Requirements declaredAnnotation1 = appNoCapabilityClass.getDeclaredAnnotation(Requirements.class);
// verify this app has no capabilities
Assert.assertNull(declaredAnnotation1);
String appNameWithoutCapability = appNoCapabilityClass.getSimpleName() + UUID.randomUUID();
deployArtifactAndApp(appNoCapabilityClass, appNameWithoutCapability);
// verify that list applications return the application tagged with capability only
for (String capability : declaredAnnotation.capabilities()) {
EntityResult<ApplicationId> appsForCapability = capabilityApplier.getApplications(NamespaceId.DEFAULT, capability, null, 0, 10);
Set<ApplicationId> applicationIds = new HashSet<>(appsForCapability.getEntities());
List<ApplicationDetail> appsReturned = new ArrayList<>(applicationLifecycleService.getAppDetails(applicationIds).values());
appsReturned.forEach(applicationDetail -> Assert.assertEquals(appNameWithCapabilities, applicationDetail.getArtifact().getName()));
}
// delete the app and verify nothing is returned.
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithCapabilities, TEST_VERSION));
for (String capability : declaredAnnotation.capabilities()) {
Set<ApplicationId> applicationIds = new HashSet<>(capabilityApplier.getApplications(NamespaceId.DEFAULT, capability, null, 0, 10).getEntities());
List<ApplicationDetail> appsReturned = new ArrayList<>(applicationLifecycleService.getAppDetails(applicationIds).values());
Assert.assertTrue(appsReturned.isEmpty());
}
applicationLifecycleService.removeApplication(NamespaceId.DEFAULT.app(appNameWithoutCapability, TEST_VERSION));
artifactRepository.deleteArtifact(Id.Artifact.from(new Id.Namespace(NamespaceId.DEFAULT.getNamespace()), appNameWithoutCapability, TEST_VERSION));
for (String capability : declaredAnnotation.capabilities()) {
capabilityWriter.deleteCapability(capability);
}
}
use of io.cdap.cdap.WorkflowAppWithFork in project cdap by caskdata.
the class TriggeringScheduleInfoAdapterTest method testSerDeserScheduleInfo.
@Test
public void testSerDeserScheduleInfo() {
BasicWorkflowToken token = new BasicWorkflowToken(1);
token.setCurrentNode("node");
token.put("tokenKey", "tokenVal");
List<TriggerInfo> triggerInfos = ImmutableList.of(new DefaultProgramStatusTriggerInfo("ns", Specifications.from(new WorkflowAppWithFork()).getName(), ProgramType.WORKFLOW, WorkflowAppWithFork.WorkflowWithFork.class.getSimpleName(), RunIds.generate(), ProgramStatus.COMPLETED, token, Collections.emptyMap()), new DefaultPartitionTriggerInfo("ns", "ds", 10, 11), new DefaultTimeTriggerInfo("1 * * * *", 0L));
TriggeringScheduleInfo scheduleInfo = new DefaultTriggeringScheduleInfo("schedule", "description", triggerInfos, ImmutableMap.of("key", "value"));
String scheduleInfoJson = GSON.toJson(scheduleInfo);
TriggeringScheduleInfo deserializedScheduleInfo = GSON.fromJson(scheduleInfoJson, TriggeringScheduleInfo.class);
Assert.assertEquals(scheduleInfoJson, GSON.toJson(deserializedScheduleInfo));
DefaultProgramStatusTriggerInfo expectedProgramStatusTriggerInfo = (DefaultProgramStatusTriggerInfo) triggerInfos.get(0);
DefaultProgramStatusTriggerInfo deserializedProgramStatusTriggerInfo = (DefaultProgramStatusTriggerInfo) deserializedScheduleInfo.getTriggerInfos().get(0);
Assert.assertEquals(expectedProgramStatusTriggerInfo.getApplicationName(), deserializedProgramStatusTriggerInfo.getApplicationName());
Assert.assertEquals(expectedProgramStatusTriggerInfo.getWorkflowToken().getAll(), deserializedProgramStatusTriggerInfo.getWorkflowToken().getAll());
}
Aggregations