Search in sources :

Example 71 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class MetadataHttpHandler method getAppTags.

@GET
@Path("/namespaces/{namespace-id}/apps/{app-id}/metadata/tags")
public void getAppTags(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @QueryParam("scope") String scope) throws NotFoundException, BadRequestException {
    ApplicationId app = new ApplicationId(namespaceId, appId);
    responder.sendJson(HttpResponseStatus.OK, getTags(app, scope));
}
Also used : ApplicationId(co.cask.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 72 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class MetadataHttpHandler method removeAppProperty.

@DELETE
@Path("/namespaces/{namespace-id}/apps/{app-id}/metadata/properties/{property}")
public void removeAppProperty(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("property") String property) throws NotFoundException {
    ApplicationId app = new ApplicationId(namespaceId, appId);
    metadataAdmin.removeProperties(app, property);
    responder.sendString(HttpResponseStatus.OK, String.format("Metadata property %s for app %s deleted successfully.", property, app));
}
Also used : ApplicationId(co.cask.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 73 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId in project cdap by caskdata.

the class AbstractVerifierTest method testId.

/**
   * Checking if name is an id or no.
   */
@Test
public void testId() throws Exception {
    AbstractVerifier<String> v = new AbstractVerifier<String>() {

        @Override
        protected String getName(String input) {
            return input;
        }
    };
    ApplicationId appId = new ApplicationId("test", "some");
    Assert.assertTrue(v.verify(appId, "foo").isSuccess());
    Assert.assertTrue(v.verify(appId, "mydataset").isSuccess());
    Assert.assertFalse(v.verify(appId, "foo name").isSuccess());
    Assert.assertTrue(v.verify(appId, "foo-name").isSuccess());
    Assert.assertTrue(v.verify(appId, "foo_name").isSuccess());
    Assert.assertTrue(v.verify(appId, "foo1234").isSuccess());
    Assert.assertFalse(v.verify(appId, "foo^ name").isSuccess());
    Assert.assertFalse(v.verify(appId, "foo^name").isSuccess());
    Assert.assertFalse(v.verify(appId, "foo/name").isSuccess());
    Assert.assertFalse(v.verify(appId, "foo$name").isSuccess());
}
Also used : ApplicationId(co.cask.cdap.proto.id.ApplicationId) Test(org.junit.Test)

Example 74 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId 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 75 with ApplicationId

use of co.cask.cdap.proto.id.ApplicationId 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)

Aggregations

ApplicationId (co.cask.cdap.proto.id.ApplicationId)234 Test (org.junit.Test)123 ProgramId (co.cask.cdap.proto.id.ProgramId)73 AppRequest (co.cask.cdap.proto.artifact.AppRequest)64 ApplicationManager (co.cask.cdap.test.ApplicationManager)49 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)45 ETLStage (co.cask.cdap.etl.proto.v2.ETLStage)44 NamespaceId (co.cask.cdap.proto.id.NamespaceId)43 Table (co.cask.cdap.api.dataset.table.Table)37 StructuredRecord (co.cask.cdap.api.data.format.StructuredRecord)36 Schema (co.cask.cdap.api.data.schema.Schema)34 ETLBatchConfig (co.cask.cdap.etl.proto.v2.ETLBatchConfig)32 WorkflowManager (co.cask.cdap.test.WorkflowManager)31 Path (javax.ws.rs.Path)31 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)29 StreamId (co.cask.cdap.proto.id.StreamId)28 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)26 ArrayList (java.util.ArrayList)25 HashSet (java.util.HashSet)24 NotFoundException (co.cask.cdap.common.NotFoundException)23