Search in sources :

Example 1 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testProgramList.

/**
 * Tests for program list calls
 */
@Test
public void testProgramList() throws Exception {
    // test initial state
    testListInitialState(TEST_NAMESPACE2, ProgramType.MAPREDUCE);
    testListInitialState(TEST_NAMESPACE1, ProgramType.WORKFLOW);
    testListInitialState(TEST_NAMESPACE2, ProgramType.SPARK);
    testListInitialState(TEST_NAMESPACE1, ProgramType.SERVICE);
    // deploy AllProgramsApp in namespace1 and verify
    deploy(AllProgramsApp.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    // deploy AppWithServices in namespace2 and verify
    deploy(AppWithServices.class, 200, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
    ApplicationSpecification allProgramSpec = Specifications.from(new AllProgramsApp());
    // verify list by namespace
    for (io.cdap.cdap.api.app.ProgramType type : io.cdap.cdap.api.app.ProgramType.values()) {
        Set<String> programsByType = allProgramSpec.getProgramsByType(type);
        verifyProgramList(TEST_NAMESPACE1, ProgramType.valueOf(type.name()), programsByType.size());
    }
    verifyProgramList(TEST_NAMESPACE2, ProgramType.SERVICE, 1);
    // verify list by app
    for (io.cdap.cdap.api.app.ProgramType type : io.cdap.cdap.api.app.ProgramType.values()) {
        Set<String> programsByType = allProgramSpec.getProgramsByType(type);
        verifyProgramList(TEST_NAMESPACE1, AllProgramsApp.NAME, ProgramType.valueOf(type.name()), programsByType.size());
    }
    verifyProgramList(TEST_NAMESPACE2, AppWithServices.NAME, ProgramType.SERVICE, 1);
    // verify invalid namespace
    Assert.assertEquals(404, getAppFDetailResponseCode(TEST_NAMESPACE1, AppWithServices.SERVICE_NAME));
    // verify invalid app
    Assert.assertEquals(404, getAppFDetailResponseCode(TEST_NAMESPACE1, "random"));
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Test(org.junit.Test)

Example 2 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.

the class ApplicationVerificationTest method testGoodApplication.

/**
 * Good test
 */
@Test
public void testGoodApplication() {
    ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp());
    ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create();
    ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
    ApplicationVerification app = new ApplicationVerification();
    VerifyResult result = app.verify(new ApplicationId("test", newSpec.getName()), newSpec);
    Assert.assertSame(result.getMessage(), result.getStatus(), VerifyResult.Status.SUCCESS);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationSpecificationAdapter(io.cdap.cdap.internal.app.ApplicationSpecificationAdapter) AllProgramsApp(io.cdap.cdap.AllProgramsApp) VerifyResult(io.cdap.cdap.app.verification.VerifyResult) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 3 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.

the class PreferencesHttpHandlerInternalTest method testApplication.

@Test
public void testApplication() throws Exception {
    String appName = AllProgramsApp.NAME;
    String namespace1 = TEST_NAMESPACE1;
    String uriInstance = getPreferenceURI();
    String uriNamespace1 = getPreferenceURI(namespace1);
    String uriApp = getPreferenceURI(namespace1, appName);
    PreferencesDetail detail;
    Map<String, String> combinedProperties = Maps.newHashMap();
    // Application not created yet. Get preferences should succeed and get back one with empty properties.
    detail = getPreferencesInternal(getPreferenceURI(namespace1, "some_non_existing_app"), false, HttpResponseStatus.OK);
    Assert.assertTrue(detail.getProperties().isEmpty());
    Assert.assertFalse(detail.getResolved());
    Assert.assertEquals(0, detail.getSeqId());
    // Create the app.
    addApplication(namespace1, new AllProgramsApp());
    Map<String, String> propMap = Maps.newHashMap();
    Assert.assertEquals(propMap, getPreferences(uriApp, false, 200));
    Assert.assertEquals(propMap, getPreferences(uriApp, true, 200));
    getPreferences(getPreferenceURI(namespace1, "InvalidAppName"), false, 404);
    // Application created but no preferences created yet. API call still succeeds but result is empty.
    detail = getPreferencesInternal(uriApp, false, HttpResponseStatus.OK);
    Assert.assertEquals(Collections.emptyMap(), detail.getProperties());
    // For entity without any references, seqId is set to default 0, otherwise it should be always > 0.
    Assert.assertEquals(0, detail.getSeqId());
    // Set the preference
    Map<String, String> instanceProperties = ImmutableMap.of("key0", "instance-val0", "instance-key1", "instance-val1");
    Map<String, String> namespace1Properties = ImmutableMap.of("key0", "namespace-val0", "namespace1-key1", "namespace1-val1");
    Map<String, String> appProperties = ImmutableMap.of("key0", "app-val0", "app-key1", "app-val1");
    setPreferences(uriInstance, instanceProperties, 200);
    setPreferences(uriNamespace1, namespace1Properties, 200);
    setPreferences(uriApp, appProperties, 200);
    // Get and verify preferences on the application
    detail = getPreferencesInternal(uriApp, false, HttpResponseStatus.OK);
    Assert.assertEquals(appProperties, detail.getProperties());
    Assert.assertTrue(detail.getSeqId() > 0);
    Assert.assertFalse(detail.getResolved());
    // Get and verify resolved preferences on the application
    detail = getPreferencesInternal(uriApp, true, HttpResponseStatus.OK);
    combinedProperties.clear();
    combinedProperties.putAll(instanceProperties);
    combinedProperties.putAll(namespace1Properties);
    combinedProperties.putAll(appProperties);
    Assert.assertEquals(combinedProperties, detail.getProperties());
    Assert.assertTrue(detail.getSeqId() > 0);
    Assert.assertTrue(detail.getResolved());
    // Delete preferences on the application and verify resolved
    deletePreferences(uriApp, 200);
    detail = getPreferencesInternal(uriApp, true, HttpResponseStatus.OK);
    combinedProperties.clear();
    combinedProperties.putAll(instanceProperties);
    combinedProperties.putAll(namespace1Properties);
    Assert.assertEquals(combinedProperties, detail.getProperties());
    Assert.assertTrue(detail.getSeqId() > 0);
    Assert.assertTrue(detail.getResolved());
    // Delete preferences on the namespace and verify.
    deletePreferences(uriNamespace1, 200);
    detail = getPreferencesInternal(uriApp, true, HttpResponseStatus.OK);
    combinedProperties.clear();
    combinedProperties.putAll(instanceProperties);
    Assert.assertEquals(combinedProperties, detail.getProperties());
    Assert.assertTrue(detail.getSeqId() > 0);
    Assert.assertTrue(detail.getResolved());
    // Delete preferences on the instance and verify.
    deletePreferences(uriInstance, 200);
    detail = getPreferencesInternal(uriApp, true, HttpResponseStatus.OK);
    combinedProperties.clear();
    Assert.assertEquals(combinedProperties, detail.getProperties());
    Assert.assertTrue(detail.getSeqId() > 0);
    Assert.assertTrue(detail.getResolved());
}
Also used : PreferencesDetail(io.cdap.cdap.proto.PreferencesDetail) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Test(org.junit.Test)

Example 4 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.

the class PreferencesHttpHandlerInternalTest method testProgram.

@Test
public void testProgram() throws Exception {
    String uriInstance = getPreferenceURI();
    String namespace2 = TEST_NAMESPACE2;
    String appName = AllProgramsApp.NAME;
    String uriNamespace2Service = getPreferenceURI(namespace2, appName, "services", AllProgramsApp.NoOpService.NAME);
    PreferencesDetail detail;
    Map<String, String> programProperties = Maps.newHashMap();
    // Create application.
    addApplication(namespace2, new AllProgramsApp());
    // Get preferences on invalid program type
    getPreferencesInternal(getPreferenceURI(namespace2, appName, "invalidType", "somename"), false, HttpResponseStatus.BAD_REQUEST);
    // Get preferences on non-existing program id. Should succeed and get back a PreferencesDetail with empty properites
    detail = getPreferencesInternal(getPreferenceURI(namespace2, appName, "services", "somename"), false, HttpResponseStatus.OK);
    Assert.assertTrue(detail.getProperties().isEmpty());
    Assert.assertFalse(detail.getResolved());
    Assert.assertEquals(0, detail.getSeqId());
    // Set preferences on the program
    programProperties.clear();
    programProperties.put("key0", "program-val0");
    programProperties.put("program-key1", "program-val1");
    setPreferences(uriNamespace2Service, programProperties, 200);
    // Get and verify preferences
    detail = getPreferencesInternal(uriNamespace2Service, false, HttpResponseStatus.OK);
    Assert.assertEquals(programProperties, detail.getProperties());
    Assert.assertTrue(detail.getSeqId() > 0);
    Assert.assertFalse(detail.getResolved());
    // Set preferences on the instance and verify.
    Map<String, String> instanceProperties = ImmutableMap.of("key0", "instance-key0", "instance-key1", "instance-val1");
    setPreferences(uriInstance, instanceProperties, 200);
    // Get resolved preferences on the program
    detail = getPreferencesInternal(uriNamespace2Service, true, HttpResponseStatus.OK);
    Map<String, String> combinedProperties = Maps.newHashMap();
    combinedProperties.putAll(instanceProperties);
    combinedProperties.putAll(programProperties);
    Assert.assertEquals(combinedProperties, detail.getProperties());
    Assert.assertTrue(detail.getSeqId() > 0);
    Assert.assertTrue(detail.getResolved());
    // Delete preferences on the program
    deletePreferences(uriNamespace2Service, 200);
    detail = getPreferencesInternal(uriNamespace2Service, true, HttpResponseStatus.OK);
    Assert.assertEquals(instanceProperties, detail.getProperties());
    Assert.assertTrue(detail.getSeqId() > 0);
    Assert.assertTrue(detail.getResolved());
    // Delete preferences on the instance
    deletePreferences(uriInstance, 200);
    detail = getPreferencesInternal(uriNamespace2Service, true, HttpResponseStatus.OK);
    Assert.assertEquals(Collections.emptyMap(), detail.getProperties());
    Assert.assertTrue(detail.getSeqId() > 0);
    Assert.assertTrue(detail.getResolved());
}
Also used : PreferencesDetail(io.cdap.cdap.proto.PreferencesDetail) AllProgramsApp(io.cdap.cdap.AllProgramsApp) Test(org.junit.Test)

Example 5 with AllProgramsApp

use of io.cdap.cdap.AllProgramsApp in project cdap by caskdata.

the class DefaultStoreTest method testProgramRunCount.

@Test
public void testProgramRunCount() {
    ApplicationSpecification spec = Specifications.from(new AllProgramsApp());
    ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName());
    ArtifactId testArtifact = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
    ProgramId workflowId = appId.workflow(AllProgramsApp.NoOpWorkflow.NAME);
    ProgramId serviceId = appId.service(AllProgramsApp.NoOpService.NAME);
    ProgramId nonExistingAppProgramId = NamespaceId.DEFAULT.app("nonExisting").workflow("test");
    ProgramId nonExistingProgramId = appId.workflow("nonExisting");
    // add the application
    store.addApplication(appId, spec);
    // add some run records to workflow and service
    for (int i = 0; i < 5; i++) {
        setStart(workflowId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
        setStart(serviceId.run(RunIds.generate()), Collections.emptyMap(), Collections.emptyMap(), testArtifact);
    }
    List<RunCountResult> result = store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId, nonExistingAppProgramId, nonExistingProgramId));
    // compare the result
    Assert.assertEquals(4, result.size());
    for (RunCountResult runCountResult : result) {
        ProgramId programId = runCountResult.getProgramId();
        Long count = runCountResult.getCount();
        if (programId.equals(nonExistingAppProgramId) || programId.equals(nonExistingProgramId)) {
            Assert.assertNull(count);
            Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
        } else {
            Assert.assertNotNull(count);
            Assert.assertEquals(5L, count.longValue());
        }
    }
    // remove the app should remove all run count
    store.removeApplication(appId);
    for (RunCountResult runCountResult : store.getProgramRunCounts(ImmutableList.of(workflowId, serviceId))) {
        Assert.assertNull(runCountResult.getCount());
        Assert.assertTrue(runCountResult.getException() instanceof NotFoundException);
    }
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) RunCountResult(io.cdap.cdap.proto.RunCountResult) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) NotFoundException(io.cdap.cdap.common.NotFoundException) AllProgramsApp(io.cdap.cdap.AllProgramsApp) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Aggregations

AllProgramsApp (io.cdap.cdap.AllProgramsApp)35 Test (org.junit.Test)33 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)27 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)24 ProgramId (io.cdap.cdap.proto.id.ProgramId)14 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)9 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 JsonObject (com.google.gson.JsonObject)5 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)5 File (java.io.File)5 Set (java.util.Set)5 ProgramType (io.cdap.cdap.api.app.ProgramType)4 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)4 Specifications (io.cdap.cdap.internal.app.deploy.Specifications)4 ProgramType (io.cdap.cdap.proto.ProgramType)4 Arrays (java.util.Arrays)4 LinkedHashMap (java.util.LinkedHashMap)4 ImmutableMap (com.google.common.collect.ImmutableMap)3