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