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());
}
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());
}
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);
}
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());
}
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);
}
Aggregations