Search in sources :

Example 1 with AppWithServices

use of co.cask.cdap.AppWithServices in project cdap by caskdata.

the class DefaultStoreTest method testServiceInstances.

@Test
public void testServiceInstances() throws Exception {
    ApplicationSpecification appSpec = Specifications.from(new AppWithServices());
    ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
    store.addApplication(appId, appSpec);
    // Test setting of service instances
    ProgramId programId = appId.program(ProgramType.SERVICE, "NoOpService");
    int count = store.getServiceInstances(programId);
    Assert.assertEquals(1, count);
    store.setServiceInstances(programId, 10);
    count = store.getServiceInstances(programId);
    Assert.assertEquals(10, count);
    ApplicationSpecification newSpec = store.getApplication(appId);
    Assert.assertNotNull(newSpec);
    Map<String, ServiceSpecification> services = newSpec.getServices();
    Assert.assertEquals(1, services.size());
    ServiceSpecification serviceSpec = services.get("NoOpService");
    Assert.assertEquals(10, serviceSpec.getInstances());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ServiceSpecification(co.cask.cdap.api.service.ServiceSpecification) AppWithServices(co.cask.cdap.AppWithServices) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 2 with AppWithServices

use of co.cask.cdap.AppWithServices in project cdap by caskdata.

the class DefaultStoreTest method testServiceDeletion.

@Test
public void testServiceDeletion() throws Exception {
    // Store the application specification
    AbstractApplication app = new AppWithServices();
    ApplicationSpecification appSpec = Specifications.from(app);
    ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
    store.addApplication(appId, appSpec);
    AbstractApplication newApp = new AppWithNoServices();
    // get the delete program specs after deploying AppWithNoServices
    List<ProgramSpecification> programSpecs = store.getDeletedProgramSpecifications(appId, Specifications.from(newApp));
    // verify the result.
    Assert.assertEquals(1, programSpecs.size());
    Assert.assertEquals("NoOpService", programSpecs.get(0).getName());
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ProgramSpecification(co.cask.cdap.api.ProgramSpecification) AppWithServices(co.cask.cdap.AppWithServices) AbstractApplication(co.cask.cdap.api.app.AbstractApplication) AppWithNoServices(co.cask.cdap.AppWithNoServices) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 3 with AppWithServices

use of co.cask.cdap.AppWithServices in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testProgramSpecification.

/**
 * Program specification tests through appfabric apis.
 */
@Test
public void testProgramSpecification() throws Exception {
    // deploy WordCountApp in namespace1 and verify
    HttpResponse response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // deploy AppWithServices in namespace2 and verify
    response = deploy(AppWithServices.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // deploy AppWithWorkflow in namespace2 and verify
    response = deploy(AppWithWorkflow.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // deploy AppWithWorker in namespace1 and verify
    response = deploy(AppWithWorker.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // verify program specification
    verifyProgramSpecification(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW.getCategoryName(), WORDCOUNT_FLOW_NAME);
    verifyProgramSpecification(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.MAPREDUCE.getCategoryName(), WORDCOUNT_MAPREDUCE_NAME);
    verifyProgramSpecification(TEST_NAMESPACE2, APP_WITH_SERVICES_APP_ID, ProgramType.SERVICE.getCategoryName(), APP_WITH_SERVICES_SERVICE_NAME);
    verifyProgramSpecification(TEST_NAMESPACE2, APP_WITH_WORKFLOW_APP_ID, ProgramType.WORKFLOW.getCategoryName(), APP_WITH_WORKFLOW_WORKFLOW_NAME);
    verifyProgramSpecification(TEST_NAMESPACE1, AppWithWorker.NAME, ProgramType.WORKER.getCategoryName(), AppWithWorker.WORKER);
    // verify invalid namespace
    Assert.assertEquals(404, getProgramSpecificationResponseCode(TEST_NAMESPACE1, APP_WITH_SERVICES_APP_ID, ProgramType.SERVICE.getCategoryName(), APP_WITH_SERVICES_SERVICE_NAME));
    // verify invalid app
    Assert.assertEquals(404, getProgramSpecificationResponseCode(TEST_NAMESPACE2, APP_WITH_SERVICES_APP_ID, ProgramType.WORKFLOW.getCategoryName(), APP_WITH_WORKFLOW_WORKFLOW_NAME));
    // verify invalid program type
    Assert.assertEquals(405, getProgramSpecificationResponseCode(TEST_NAMESPACE2, APP_WITH_SERVICES_APP_ID, "random", APP_WITH_WORKFLOW_WORKFLOW_NAME));
    // verify invalid program type
    Assert.assertEquals(404, getProgramSpecificationResponseCode(TEST_NAMESPACE2, AppWithWorker.NAME, ProgramType.WORKER.getCategoryName(), AppWithWorker.WORKER));
}
Also used : AppWithServices(co.cask.cdap.AppWithServices) HttpResponse(org.apache.http.HttpResponse) AppWithWorker(co.cask.cdap.AppWithWorker) AppWithWorkflow(co.cask.cdap.AppWithWorkflow) Test(org.junit.Test)

Example 4 with AppWithServices

use of co.cask.cdap.AppWithServices 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_NAMESPACE1, ProgramType.FLOW);
    testListInitialState(TEST_NAMESPACE2, ProgramType.MAPREDUCE);
    testListInitialState(TEST_NAMESPACE1, ProgramType.WORKFLOW);
    testListInitialState(TEST_NAMESPACE2, ProgramType.SPARK);
    testListInitialState(TEST_NAMESPACE1, ProgramType.SERVICE);
    // deploy WordCountApp in namespace1 and verify
    HttpResponse response = deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // deploy AppWithServices in namespace2 and verify
    response = deploy(AppWithServices.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    // verify list by namespace
    verifyProgramList(TEST_NAMESPACE1, ProgramType.FLOW, 1);
    verifyProgramList(TEST_NAMESPACE1, ProgramType.MAPREDUCE, 1);
    verifyProgramList(TEST_NAMESPACE2, ProgramType.SERVICE, 1);
    // verify list by app
    verifyProgramList(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.FLOW, 1);
    verifyProgramList(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.MAPREDUCE, 1);
    verifyProgramList(TEST_NAMESPACE1, WORDCOUNT_APP_NAME, ProgramType.WORKFLOW, 0);
    verifyProgramList(TEST_NAMESPACE2, APP_WITH_SERVICES_APP_ID, ProgramType.SERVICE, 1);
    // verify invalid namespace
    Assert.assertEquals(404, getAppFDetailResponseCode(TEST_NAMESPACE1, APP_WITH_SERVICES_APP_ID, ProgramType.SERVICE.getCategoryName()));
    // verify invalid app
    Assert.assertEquals(404, getAppFDetailResponseCode(TEST_NAMESPACE1, "random", ProgramType.FLOW.getCategoryName()));
}
Also used : AppWithServices(co.cask.cdap.AppWithServices) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

AppWithServices (co.cask.cdap.AppWithServices)4 Test (org.junit.Test)4 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)2 ApplicationId (co.cask.cdap.proto.id.ApplicationId)2 HttpResponse (org.apache.http.HttpResponse)2 AppWithNoServices (co.cask.cdap.AppWithNoServices)1 AppWithWorker (co.cask.cdap.AppWithWorker)1 AppWithWorkflow (co.cask.cdap.AppWithWorkflow)1 ProgramSpecification (co.cask.cdap.api.ProgramSpecification)1 AbstractApplication (co.cask.cdap.api.app.AbstractApplication)1 ServiceSpecification (co.cask.cdap.api.service.ServiceSpecification)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1