Search in sources :

Example 1 with AppRequest

use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.

the class AppScheduleUpdateTest method testUpdateSchedulesFlag.

@Test
public void testUpdateSchedulesFlag() throws Exception {
    // deploy an app with schedule
    AppWithSchedule.AppConfig config = new AppWithSchedule.AppConfig(true, true, true);
    Id.Artifact artifactId = Id.Artifact.from(TEST_NAMESPACE_META2.getNamespaceId().toId(), AppWithSchedule.NAME, VERSION1);
    addAppArtifact(artifactId, AppWithSchedule.class);
    AppRequest<? extends Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config);
    ApplicationId defaultAppId = TEST_NAMESPACE_META2.getNamespaceId().app(AppWithSchedule.NAME);
    Assert.assertEquals(200, deploy(defaultAppId, request).getStatusLine().getStatusCode());
    List<ScheduleDetail> actualSchSpecs = listSchedules(TEST_NAMESPACE_META2.getNamespaceId().getNamespace(), defaultAppId.getApplication(), defaultAppId.getVersion());
    // none of the schedules will be added - by default we have set update schedules to be false as system property.
    Assert.assertEquals(0, actualSchSpecs.size());
    request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config, null, null, true);
    Assert.assertEquals(200, deploy(defaultAppId, request).getStatusLine().getStatusCode());
    actualSchSpecs = listSchedules(TEST_NAMESPACE_META2.getNamespaceId().getNamespace(), defaultAppId.getApplication(), defaultAppId.getVersion());
    // both the schedules will be added as now,
    // we have provided update schedules property to be true manually in appRequest
    Assert.assertEquals(2, actualSchSpecs.size());
    config = new AppWithSchedule.AppConfig(true, true, false);
    request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config);
    Assert.assertEquals(200, deploy(defaultAppId, request).getStatusLine().getStatusCode());
    actualSchSpecs = listSchedules(TEST_NAMESPACE_META2.getNamespaceId().getNamespace(), defaultAppId.getApplication(), defaultAppId.getVersion());
    // no changes will be made, as default behavior is dont update schedules, so both the schedules should be there
    Assert.assertEquals(2, actualSchSpecs.size());
    config = new AppWithSchedule.AppConfig(false, false, false);
    request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config);
    Assert.assertEquals(200, deploy(defaultAppId, request).getStatusLine().getStatusCode());
    actualSchSpecs = listSchedules(TEST_NAMESPACE_META2.getNamespaceId().getNamespace(), defaultAppId.getApplication(), defaultAppId.getVersion());
    // workflow is deleted, so the schedules will be deleted now
    Assert.assertEquals(0, actualSchSpecs.size());
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Id(co.cask.cdap.proto.Id) ScheduleDetail(co.cask.cdap.proto.ScheduleDetail) AppWithSchedule(co.cask.cdap.AppWithSchedule) ApplicationId(co.cask.cdap.proto.id.ApplicationId) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 2 with AppRequest

use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testListAndGet.

@Test
public void testListAndGet() throws Exception {
    final String appName = "AppWithDatasetName";
    Id.Namespace ns2 = Id.Namespace.from(TEST_NAMESPACE2);
    Id.Artifact ns2ArtifactId = Id.Artifact.from(ns2, "bloatedListAndGet", "1.0.0-SNAPSHOT");
    //deploy without name to testnamespace1
    HttpResponse response = deploy(BloatedWordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    //deploy with name to testnamespace2
    response = addAppArtifact(ns2ArtifactId, BloatedWordCountApp.class);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Id.Application appId = Id.Application.from(ns2, appName);
    response = deploy(appId, new AppRequest<Config>(ArtifactSummary.from(ns2ArtifactId.toArtifactId())));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertNotNull(response.getEntity());
    // deploy with name and version to testnamespace2
    ApplicationId app1 = new ApplicationId(TEST_NAMESPACE2, appName, VERSION1);
    response = deploy(app1, new AppRequest<Config>(ArtifactSummary.from(ns2ArtifactId.toArtifactId())));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertNotNull(response.getEntity());
    //verify testnamespace1 has 1 app
    List<JsonObject> apps = getAppList(TEST_NAMESPACE1);
    Assert.assertEquals(1, apps.size());
    //verify testnamespace2 has 2 app
    apps = getAppList(TEST_NAMESPACE2);
    Assert.assertEquals(2, apps.size());
    //get and verify app details in testnamespace1
    JsonObject result = getAppDetails(TEST_NAMESPACE1, "WordCountApp");
    Assert.assertEquals("WordCountApp", result.get("name").getAsString());
    Assert.assertEquals("Application for counting words", result.get("description").getAsString());
    JsonArray streams = result.get("streams").getAsJsonArray();
    Assert.assertEquals(1, streams.size());
    JsonObject stream = streams.get(0).getAsJsonObject();
    Assert.assertEquals("text", stream.get("name").getAsString());
    JsonArray datasets = result.get("datasets").getAsJsonArray();
    Assert.assertEquals(1, datasets.size());
    JsonObject dataset = datasets.get(0).getAsJsonObject();
    Assert.assertEquals("mydataset", dataset.get("name").getAsString());
    JsonArray programs = result.get("programs").getAsJsonArray();
    Assert.assertEquals(6, programs.size());
    JsonObject[] progs = new JsonObject[programs.size()];
    for (int i = 0; i < programs.size(); i++) {
        progs[i] = programs.get(i).getAsJsonObject();
    }
    // sort the programs by name to make this test deterministic
    Arrays.sort(progs, new Comparator<JsonObject>() {

        @Override
        public int compare(JsonObject o1, JsonObject o2) {
            return o1.get("name").getAsString().compareTo(o2.get("name").getAsString());
        }
    });
    int i = 0;
    Assert.assertEquals("Worker", progs[i].get("type").getAsString());
    Assert.assertEquals("LazyGuy", progs[i].get("name").getAsString());
    Assert.assertEquals("nothing to describe", progs[i].get("description").getAsString());
    i++;
    Assert.assertEquals("Workflow", progs[i].get("type").getAsString());
    Assert.assertEquals("SingleStep", progs[i].get("name").getAsString());
    Assert.assertEquals("", progs[i].get("description").getAsString());
    i++;
    Assert.assertEquals("Spark", progs[i].get("type").getAsString());
    Assert.assertEquals("SparklingNothing", progs[i].get("name").getAsString());
    Assert.assertEquals("Spark program that does nothing", progs[i].get("description").getAsString());
    i++;
    Assert.assertEquals("Mapreduce", progs[i].get("type").getAsString());
    Assert.assertEquals("VoidMapReduceJob", progs[i].get("name").getAsString());
    Assert.assertTrue(progs[i].get("description").getAsString().startsWith("Mapreduce that does nothing"));
    i++;
    Assert.assertEquals("Flow", progs[i].get("type").getAsString());
    Assert.assertEquals("WordCountFlow", progs[i].get("name").getAsString());
    Assert.assertEquals("Flow for counting words", progs[i].get("description").getAsString());
    i++;
    Assert.assertEquals("Service", progs[i].get("type").getAsString());
    Assert.assertEquals("WordFrequencyService", progs[i].get("name").getAsString());
    Assert.assertEquals("", progs[i].get("description").getAsString());
    //get and verify app details in testnamespace2
    result = getAppDetails(TEST_NAMESPACE2, appName);
    Assert.assertEquals(appName, result.get("name").getAsString());
    //get and verify app details in testnamespace2
    result = getAppDetails(TEST_NAMESPACE2, appName, VERSION1);
    Assert.assertEquals(appName, result.get("name").getAsString());
    //delete app in testnamespace1
    response = doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    //delete app in testnamespace2
    response = doDelete(getVersionedAPIPath("apps/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    deleteArtifact(ns2ArtifactId, 200);
    //verify testnamespace2 has 0 app
    apps = getAppList(TEST_NAMESPACE2);
    Assert.assertEquals(0, apps.size());
}
Also used : HttpResponse(org.apache.http.HttpResponse) JsonObject(com.google.gson.JsonObject) AppRequest(co.cask.cdap.proto.artifact.AppRequest) JsonArray(com.google.gson.JsonArray) BloatedWordCountApp(co.cask.cdap.BloatedWordCountApp) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 3 with AppRequest

use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testAppWithConfig.

@Test
public void testAppWithConfig() throws Exception {
    Id.Application appId = Id.Application.from(Id.Namespace.DEFAULT, "ConfigApp");
    Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "appWithConfig", "1.0.0-SNAPSHOT");
    HttpResponse response = addAppArtifact(artifactId, ConfigTestApp.class);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    ConfigTestApp.ConfigClass config = new ConfigTestApp.ConfigClass("abc", "def");
    response = deploy(appId, new AppRequest<>(ArtifactSummary.from(artifactId.toArtifactId()), config));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    JsonObject appDetails = getAppDetails(Id.Namespace.DEFAULT.getId(), "ConfigApp");
    Assert.assertEquals(GSON.toJson(config), appDetails.get("configuration").getAsString());
    deleteApp(appId, 200);
    deleteArtifact(artifactId, 200);
}
Also used : HttpResponse(org.apache.http.HttpResponse) JsonObject(com.google.gson.JsonObject) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ConfigTestApp(co.cask.cdap.ConfigTestApp) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 4 with AppRequest

use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.

the class AppLifecycleHttpHandlerTest method testDelete.

/**
   * Tests deleting applications with versioned and non-versioned API.
   */
@Test
public void testDelete() throws Exception {
    // Delete an non-existing app
    HttpResponse response = doDelete(getVersionedAPIPath("apps/XYZ", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(404, response.getStatusLine().getStatusCode());
    // Start a fow for the App
    deploy(WordCountApp.class, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1);
    Id.Program program = Id.Program.from(TEST_NAMESPACE1, "WordCountApp", ProgramType.FLOW, "WordCountFlow");
    startProgram(program);
    waitState(program, "RUNNING");
    // Try to delete an App while its flow is running
    response = doDelete(getVersionedAPIPath("apps/WordCountApp", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(409, response.getStatusLine().getStatusCode());
    Assert.assertEquals("'" + program.getApplication() + "' could not be deleted. Reason: The following programs are still running: " + program.getId(), readResponse(response));
    stopProgram(program);
    waitState(program, "STOPPED");
    startProgram(program);
    waitState(program, "RUNNING");
    // Try to delete all Apps while flow is running
    response = doDelete(getVersionedAPIPath("apps", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(409, response.getStatusLine().getStatusCode());
    Assert.assertEquals("'" + program.getNamespace() + "' could not be deleted. Reason: The following programs are still running: " + program.getApplicationId() + ": " + program.getId(), readResponse(response));
    stopProgram(program);
    waitState(program, "STOPPED");
    // Delete the app in the wrong namespace
    response = doDelete(getVersionedAPIPath("apps/WordCountApp", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
    Assert.assertEquals(404, response.getStatusLine().getStatusCode());
    // Delete an non-existing app with version
    response = doDelete(getVersionedAPIPath("apps/XYZ/versions/" + VERSION1, Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(404, response.getStatusLine().getStatusCode());
    // Deploy an app with version
    Id.Artifact wordCountArtifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "wordcountapp", VERSION1);
    addAppArtifact(wordCountArtifactId, WordCountApp.class);
    AppRequest<? extends Config> wordCountRequest = new AppRequest<>(new ArtifactSummary(wordCountArtifactId.getName(), wordCountArtifactId.getVersion().getVersion()));
    ApplicationId wordCountApp1 = NamespaceId.DEFAULT.app("WordCountApp", VERSION1);
    Assert.assertEquals(200, deploy(wordCountApp1, wordCountRequest).getStatusLine().getStatusCode());
    // Start a flow for the App
    ProgramId program1 = wordCountApp1.program(ProgramType.FLOW, "WordCountFlow");
    startProgram(program1, 200);
    waitState(program1, "RUNNING");
    // Try to delete an App while its flow is running
    response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", wordCountApp1.getApplication(), wordCountApp1.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, wordCountApp1.getNamespace()));
    Assert.assertEquals(409, response.getStatusLine().getStatusCode());
    Assert.assertEquals("'" + program1.getParent() + "' could not be deleted. Reason: The following programs" + " are still running: " + program1.getProgram(), readResponse(response));
    stopProgram(program1, null, 200, null);
    waitState(program1, "STOPPED");
    // Delete the app with version in the wrong namespace
    response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", wordCountApp1.getApplication(), wordCountApp1.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE2));
    Assert.assertEquals(404, response.getStatusLine().getStatusCode());
    //Delete the app with version after stopping the flow
    response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", wordCountApp1.getApplication(), wordCountApp1.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, wordCountApp1.getNamespace()));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    response = doDelete(getVersionedAPIPath(String.format("apps/%s/versions/%s", wordCountApp1.getApplication(), wordCountApp1.getVersion()), Constants.Gateway.API_VERSION_3_TOKEN, wordCountApp1.getNamespace()));
    Assert.assertEquals(404, response.getStatusLine().getStatusCode());
    //Delete the App after stopping the flow
    response = doDelete(getVersionedAPIPath("apps/WordCountApp/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    response = doDelete(getVersionedAPIPath("apps/WordCountApp/", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(404, response.getStatusLine().getStatusCode());
    // deleting the app should not delete the artifact
    response = doGet(getVersionedAPIPath("artifacts/WordCountApp", Constants.Gateway.API_VERSION_3_TOKEN, TEST_NAMESPACE1));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    List<ArtifactSummary> summaries = readResponse(response, new TypeToken<List<ArtifactSummary>>() {
    }.getType());
    Assert.assertFalse(summaries.isEmpty());
    // cleanup
    deleteNamespace(NamespaceId.DEFAULT.getNamespace());
}
Also used : ArtifactSummary(co.cask.cdap.api.artifact.ArtifactSummary) TypeToken(com.google.gson.reflect.TypeToken) HttpResponse(org.apache.http.HttpResponse) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Id(co.cask.cdap.proto.Id) ProgramId(co.cask.cdap.proto.id.ProgramId) ArtifactId(co.cask.cdap.proto.id.ArtifactId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) AppRequest(co.cask.cdap.proto.artifact.AppRequest) Test(org.junit.Test)

Example 5 with AppRequest

use of co.cask.cdap.proto.artifact.AppRequest in project cdap by caskdata.

the class DataPipelineTest method testPipelineWithAllActions.

@Test
public void testPipelineWithAllActions() throws Exception {
    String actionTable = "actionTable";
    String action1RowKey = "action1.row";
    String action1ColumnKey = "action1.column";
    String action1Value = "action1.value";
    String action2RowKey = "action2.row";
    String action2ColumnKey = "action2.column";
    String action2Value = "action2.value";
    String action3RowKey = "action3.row";
    String action3ColumnKey = "action3.column";
    String action3Value = "action3.value";
    ETLBatchConfig etlConfig = ETLBatchConfig.builder("* * * * *").addStage(new ETLStage("action1", MockAction.getPlugin(actionTable, action1RowKey, action1ColumnKey, action1Value))).addStage(new ETLStage("action2", MockAction.getPlugin(actionTable, action2RowKey, action2ColumnKey, action2Value))).addStage(new ETLStage("action3", MockAction.getPlugin(actionTable, action3RowKey, action3ColumnKey, action3Value))).addConnection("action1", "action2").addConnection("action1", "action3").setEngine(Engine.MAPREDUCE).build();
    AppRequest<ETLBatchConfig> appRequest = new AppRequest<>(APP_ARTIFACT, etlConfig);
    ApplicationId appId = NamespaceId.DEFAULT.app("MyActionOnlyApp");
    ApplicationManager appManager = deployApplication(appId.toId(), appRequest);
    WorkflowManager workflowManager = appManager.getWorkflowManager(SmartWorkflow.NAME);
    workflowManager.start();
    workflowManager.waitForRun(ProgramRunStatus.COMPLETED, 5, TimeUnit.MINUTES);
    DataSetManager<Table> actionTableDS = getDataset(actionTable);
    Assert.assertEquals(action1Value, MockAction.readOutput(actionTableDS, action1RowKey, action1ColumnKey));
    Assert.assertEquals(action2Value, MockAction.readOutput(actionTableDS, action2RowKey, action2ColumnKey));
    Assert.assertEquals(action3Value, MockAction.readOutput(actionTableDS, action3RowKey, action3ColumnKey));
    List<RunRecord> history = workflowManager.getHistory(ProgramRunStatus.COMPLETED);
    Assert.assertEquals(1, history.size());
    String runId = history.get(0).getPid();
    WorkflowTokenDetail tokenDetail = workflowManager.getToken(runId, WorkflowToken.Scope.USER, action1RowKey + action1ColumnKey);
    validateToken(tokenDetail, action1RowKey + action1ColumnKey, action1Value);
    tokenDetail = workflowManager.getToken(runId, WorkflowToken.Scope.USER, action2RowKey + action2ColumnKey);
    validateToken(tokenDetail, action2RowKey + action2ColumnKey, action2Value);
    tokenDetail = workflowManager.getToken(runId, WorkflowToken.Scope.USER, action3RowKey + action3ColumnKey);
    validateToken(tokenDetail, action3RowKey + action3ColumnKey, action3Value);
}
Also used : ApplicationManager(co.cask.cdap.test.ApplicationManager) KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) Table(co.cask.cdap.api.dataset.table.Table) WorkflowManager(co.cask.cdap.test.WorkflowManager) AppRequest(co.cask.cdap.proto.artifact.AppRequest) ETLBatchConfig(co.cask.cdap.etl.proto.v2.ETLBatchConfig) RunRecord(co.cask.cdap.proto.RunRecord) ETLStage(co.cask.cdap.etl.proto.v2.ETLStage) ApplicationId(co.cask.cdap.proto.id.ApplicationId) WorkflowTokenDetail(co.cask.cdap.proto.WorkflowTokenDetail) Test(org.junit.Test)

Aggregations

AppRequest (co.cask.cdap.proto.artifact.AppRequest)73 ApplicationId (co.cask.cdap.proto.id.ApplicationId)68 Test (org.junit.Test)46 ApplicationManager (co.cask.cdap.test.ApplicationManager)44 ETLStage (co.cask.cdap.etl.proto.v2.ETLStage)39 StructuredRecord (co.cask.cdap.api.data.format.StructuredRecord)31 Schema (co.cask.cdap.api.data.schema.Schema)29 Table (co.cask.cdap.api.dataset.table.Table)29 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)28 ETLBatchConfig (co.cask.cdap.etl.proto.v2.ETLBatchConfig)27 WorkflowManager (co.cask.cdap.test.WorkflowManager)27 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)21 ArtifactId (co.cask.cdap.proto.id.ArtifactId)16 Id (co.cask.cdap.proto.Id)14 NamespaceId (co.cask.cdap.proto.id.NamespaceId)13 ProgramId (co.cask.cdap.proto.id.ProgramId)13 HashSet (java.util.HashSet)13 TimeoutException (java.util.concurrent.TimeoutException)11 ArrayList (java.util.ArrayList)9 DataStreamsConfig (co.cask.cdap.etl.proto.v2.DataStreamsConfig)8