Search in sources :

Example 6 with PreferencesDetail

use of io.cdap.cdap.proto.PreferencesDetail in project cdap by caskdata.

the class PreferencesHttpHandlerInternal method getProgramPreferences.

/**
 * Get program level preferences
 *
 * Note that if the given program doesn't exist, the return {@link PreferencesDetail} will be empty
 * (i.e. {@link PreferencesDetail#properties} will be an empty map). In the case of requesting resolved preferences,
 * the returned {@link PreferencesDetail} will include preferences from ancestor (i.e. preferences at application,
 * namespace and instance level)
 *
 * @param request {@link HttpRequest}
 * @param responder the responder used for sending response back to client
 * @param namespace the namespace of the application
 * @param appId the application to get preferences for
 * @param programType the type of the program
 * @param programId id of the program to get preferences for
 * @param resolved whether to return resolved preferences or not
 * @throws Exception
 */
@Path("/namespaces/{namespace-id}/apps/{application-id}/{program-type}/{program-id}/preferences")
@GET
public void getProgramPreferences(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @PathParam("application-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId, @QueryParam("resolved") boolean resolved) throws Exception {
    ProgramId program = new ProgramId(namespace, appId, getProgramType(programType), programId);
    // No need to check if program exists. PreferencesService returns an empty PreferencesDetail when that happens.
    PreferencesDetail detail;
    if (resolved) {
        detail = preferencesService.getResolvedPreferences(program);
    } else {
        detail = preferencesService.getPreferences(program);
    }
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(detail, PreferencesDetail.class));
}
Also used : PreferencesDetail(io.cdap.cdap.proto.PreferencesDetail) ProgramId(io.cdap.cdap.proto.id.ProgramId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 7 with PreferencesDetail

use of io.cdap.cdap.proto.PreferencesDetail in project cdap by caskdata.

the class PreferencesHttpHandlerInternal method getNamespacePreferences.

/**
 * Get namespace level preferences.
 *
 * Note that if the given namespace doesn't exist, the return {@link PreferencesDetail} will be empty
 * (i.e. {@link PreferencesDetail#properties} will be an empty map). In the case of requesting resolved preferences,
 * the returned {@link PreferencesDetail} will include preferences from ancestor (i.e. preferences at instance level)
 *
 * @param request {@link HttpRequest}
 * @param responder the responder used for sending response back to client
 * @param namespace the namespace to get preferences for
 * @param resolved whether to return resolved preferences or not
 */
@Path("/namespaces/{namespace-id}/preferences")
@GET
public void getNamespacePreferences(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @QueryParam("resolved") boolean resolved) {
    NamespaceId namespaceId = new NamespaceId(namespace);
    // No need to check if namespace exists. PreferencesService returns an empty PreferencesDetail when that happens.
    PreferencesDetail detail;
    if (resolved) {
        detail = preferencesService.getResolvedPreferences(namespaceId);
    } else {
        detail = preferencesService.getPreferences(namespaceId);
    }
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(detail, PreferencesDetail.class));
}
Also used : PreferencesDetail(io.cdap.cdap.proto.PreferencesDetail) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 8 with PreferencesDetail

use of io.cdap.cdap.proto.PreferencesDetail in project cdap by cdapio.

the class PreferencesServiceTest method testCleanSlate.

// Testing PreferencesStore
@Test
public void testCleanSlate() throws Exception {
    Map<String, String> emptyMap = ImmutableMap.of();
    PreferencesService store = getInjector().getInstance(PreferencesService.class);
    Assert.assertEquals(emptyMap, store.getProperties());
    Assert.assertEquals(emptyMap, store.getProperties(new NamespaceId("somenamespace")));
    Assert.assertEquals(emptyMap, store.getProperties(NamespaceId.DEFAULT));
    Assert.assertEquals(emptyMap, store.getResolvedProperties());
    Assert.assertEquals(emptyMap, store.getResolvedProperties(new ProgramId("a", "b", ProgramType.WORKFLOW, "d")));
    // should not throw any exception if try to delete properties without storing anything
    store.deleteProperties();
    store.deleteProperties(NamespaceId.DEFAULT);
    store.deleteProperties(new ProgramId("a", "x", ProgramType.WORKFLOW, "z"));
    // Get instance level PreferencesDetail. None has been set, so seqId should be 0 and it should monotonically
    // increasing as preferences are mutated (i.e. set or deleted) for the entity.
    PreferencesDetail detail = store.getPreferences();
    Assert.assertEquals(emptyMap, detail.getProperties());
    Assert.assertEquals(0, detail.getSeqId());
}
Also used : PreferencesDetail(io.cdap.cdap.proto.PreferencesDetail) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ProgramId(io.cdap.cdap.proto.id.ProgramId) Test(org.junit.Test)

Example 9 with PreferencesDetail

use of io.cdap.cdap.proto.PreferencesDetail in project cdap by cdapio.

the class PreferencesHttpHandlerInternal method getInstancePreferences.

/**
 * Get instance level preferences
 *
 * @param request {@link HttpRequest}
 * @param responder the responder used for sending response back to client
 */
@Path("/preferences")
@GET
public void getInstancePreferences(HttpRequest request, HttpResponder responder) {
    PreferencesDetail detail = preferencesService.getPreferences();
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(detail, PreferencesDetail.class));
}
Also used : PreferencesDetail(io.cdap.cdap.proto.PreferencesDetail) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 10 with PreferencesDetail

use of io.cdap.cdap.proto.PreferencesDetail in project cdap by cdapio.

the class PreferencesHttpHandlerInternal method getNamespacePreferences.

/**
 * Get namespace level preferences.
 *
 * Note that if the given namespace doesn't exist, the return {@link PreferencesDetail} will be empty
 * (i.e. {@link PreferencesDetail#properties} will be an empty map). In the case of requesting resolved preferences,
 * the returned {@link PreferencesDetail} will include preferences from ancestor (i.e. preferences at instance level)
 *
 * @param request {@link HttpRequest}
 * @param responder the responder used for sending response back to client
 * @param namespace the namespace to get preferences for
 * @param resolved whether to return resolved preferences or not
 */
@Path("/namespaces/{namespace-id}/preferences")
@GET
public void getNamespacePreferences(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace, @QueryParam("resolved") boolean resolved) {
    NamespaceId namespaceId = new NamespaceId(namespace);
    // No need to check if namespace exists. PreferencesService returns an empty PreferencesDetail when that happens.
    PreferencesDetail detail;
    if (resolved) {
        detail = preferencesService.getResolvedPreferences(namespaceId);
    } else {
        detail = preferencesService.getPreferences(namespaceId);
    }
    responder.sendJson(HttpResponseStatus.OK, GSON.toJson(detail, PreferencesDetail.class));
}
Also used : PreferencesDetail(io.cdap.cdap.proto.PreferencesDetail) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

PreferencesDetail (io.cdap.cdap.proto.PreferencesDetail)28 Test (org.junit.Test)12 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)8 ProgramId (io.cdap.cdap.proto.id.ProgramId)8 GET (javax.ws.rs.GET)8 Path (javax.ws.rs.Path)8 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)6 HashMap (java.util.HashMap)6 AllProgramsApp (io.cdap.cdap.AllProgramsApp)4 InstanceId (io.cdap.cdap.proto.id.InstanceId)4 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)2 PreviewMessage (io.cdap.cdap.app.preview.PreviewMessage)2 PreviewRequest (io.cdap.cdap.app.preview.PreviewRequest)2 PreviewStatus (io.cdap.cdap.app.preview.PreviewStatus)2 ProgramController (io.cdap.cdap.app.runtime.ProgramController)2 NamespaceAlreadyExistsException (io.cdap.cdap.common.NamespaceAlreadyExistsException)2 PreferencesService (io.cdap.cdap.config.PreferencesService)2 AbstractListener (io.cdap.cdap.internal.app.runtime.AbstractListener)2 BasicThrowable (io.cdap.cdap.proto.BasicThrowable)2 NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)2