Search in sources :

Example 1 with WorkflowAppWithFork

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();
}
Also used : Manifest(java.util.jar.Manifest) JsonObject(com.google.gson.JsonObject) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) Arrays(java.util.Arrays) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) CapabilityAppWithWorkflow(io.cdap.cdap.CapabilityAppWithWorkflow) AppJarHelper(io.cdap.cdap.common.test.AppJarHelper) AppFabricTestHelper(io.cdap.cdap.internal.AppFabricTestHelper) Gson(com.google.gson.Gson) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) After(org.junit.After) Map(java.util.Map) AfterClass(org.junit.AfterClass) ApplicationLifecycleService(io.cdap.cdap.internal.app.services.ApplicationLifecycleService) UUID(java.util.UUID) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) Collectors(java.util.stream.Collectors) Id(io.cdap.cdap.common.id.Id) List(java.util.List) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Constants(io.cdap.cdap.common.conf.Constants) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) PluginJarHelper(io.cdap.cdap.common.test.PluginJarHelper) BeforeClass(org.junit.BeforeClass) Location(org.apache.twill.filesystem.Location) ManifestFields(io.cdap.cdap.app.program.ManifestFields) AppFabricTestBase(io.cdap.cdap.internal.app.services.http.AppFabricTestBase) HashMap(java.util.HashMap) CapabilitySleepingWorkflowApp(io.cdap.cdap.CapabilitySleepingWorkflowApp) ApplicationWithPrograms(io.cdap.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) Requirements(io.cdap.cdap.api.annotation.Requirements) ProgramType(io.cdap.cdap.proto.ProgramType) Files(com.google.common.io.Files) Locations(io.cdap.cdap.common.io.Locations) ProgramLifecycleService(io.cdap.cdap.internal.app.services.ProgramLifecycleService) CapabilitySleepingWorkflowPluginApp(io.cdap.cdap.CapabilitySleepingWorkflowPluginApp) ProgramId(io.cdap.cdap.proto.id.ProgramId) FileWriter(java.io.FileWriter) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) Test(org.junit.Test) IOException(java.io.IOException) LocationFactory(org.apache.twill.filesystem.LocationFactory) File(java.io.File) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) WorkflowAppWithFork(io.cdap.cdap.WorkflowAppWithFork) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) FileReader(java.io.FileReader) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Assert(org.junit.Assert) Collections(java.util.Collections) WorkflowAppWithFork(io.cdap.cdap.WorkflowAppWithFork) Requirements(io.cdap.cdap.api.annotation.Requirements) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Id(io.cdap.cdap.common.id.Id) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) CapabilityAppWithWorkflow(io.cdap.cdap.CapabilityAppWithWorkflow) File(java.io.File) Test(org.junit.Test)

Example 2 with WorkflowAppWithFork

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);
    }
}
Also used : WorkflowAppWithFork(io.cdap.cdap.WorkflowAppWithFork) ArrayList(java.util.ArrayList) Requirements(io.cdap.cdap.api.annotation.Requirements) ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) CapabilityAppWithWorkflow(io.cdap.cdap.CapabilityAppWithWorkflow) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with WorkflowAppWithFork

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());
}
Also used : DefaultPartitionTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultPartitionTriggerInfo) WorkflowAppWithFork(io.cdap.cdap.WorkflowAppWithFork) DefaultTimeTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo) TriggerInfo(io.cdap.cdap.api.schedule.TriggerInfo) DefaultProgramStatusTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultProgramStatusTriggerInfo) DefaultPartitionTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultPartitionTriggerInfo) DefaultTimeTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo) TriggeringScheduleInfo(io.cdap.cdap.api.schedule.TriggeringScheduleInfo) BasicWorkflowToken(io.cdap.cdap.internal.app.runtime.workflow.BasicWorkflowToken) DefaultProgramStatusTriggerInfo(io.cdap.cdap.internal.app.runtime.schedule.trigger.DefaultProgramStatusTriggerInfo) Test(org.junit.Test)

Aggregations

WorkflowAppWithFork (io.cdap.cdap.WorkflowAppWithFork)3 Test (org.junit.Test)3 CapabilityAppWithWorkflow (io.cdap.cdap.CapabilityAppWithWorkflow)2 Requirements (io.cdap.cdap.api.annotation.Requirements)2 ApplicationDetail (io.cdap.cdap.proto.ApplicationDetail)2 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)2 Files (com.google.common.io.Files)1 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 AllProgramsApp (io.cdap.cdap.AllProgramsApp)1 CapabilitySleepingWorkflowApp (io.cdap.cdap.CapabilitySleepingWorkflowApp)1 CapabilitySleepingWorkflowPluginApp (io.cdap.cdap.CapabilitySleepingWorkflowPluginApp)1 ArtifactScope (io.cdap.cdap.api.artifact.ArtifactScope)1 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)1 TriggerInfo (io.cdap.cdap.api.schedule.TriggerInfo)1 TriggeringScheduleInfo (io.cdap.cdap.api.schedule.TriggeringScheduleInfo)1 ManifestFields (io.cdap.cdap.app.program.ManifestFields)1 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 Constants (io.cdap.cdap.common.conf.Constants)1