/** * Creates a {@link ProgramId} with no program name. This allows matching * for all datasets associated with an Application as opposed to a single program. */ public static ProgramId getProgramId(ApplicationId applicationId) { // Use empty programId to denote applicationId return new ProgramId(applicationId, ProgramType.WORKER, ""); }
public static ProgramId getId(String name) { int firstIndex = name.indexOf('.'); int secondIndex = name.indexOf('.', firstIndex + 1); int thirdIndex = name.indexOf('.', secondIndex + 1); String programType = name.substring(0, firstIndex); String namespaceId = name.substring(firstIndex + 1, secondIndex); String appId = name.substring(secondIndex + 1, thirdIndex); String programName = name.substring(thirdIndex + 1); return new ProgramId(namespaceId, appId, programType, programName); }
@GET @Path("/apps/{app-id}/{program-category}/{program-id}/live-info") @SuppressWarnings("unused") public void liveInfo(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-category") String programCategory, @PathParam("program-id") String programId) throws BadRequestException { ProgramType type = getProgramType(programCategory); ProgramId program = new ProgramId(namespaceId, appId, type, programId); getLiveInfo(responder, program, runtimeService); }
@GET @Path("/apps/{app-id}/{program-category}/{program-id}/live-info") @SuppressWarnings("unused") public void liveInfo(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-category") String programCategory, @PathParam("program-id") String programId) throws BadRequestException { ProgramType type = getProgramType(programCategory); ProgramId program = new ProgramId(namespaceId, appId, type, programId); getLiveInfo(responder, program, runtimeService); }
@DELETE @Path("/routeconfig") public void deleteRouteConfig(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("service-id") String serviceId) throws Exception { ProgramId programId = new ProgramId(namespaceId, appId, ProgramType.SERVICE, serviceId); routeStore.delete(programId); responder.sendStatus(HttpResponseStatus.OK); } }
@GET @Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/datasets") public void getProgramDatasetUsage(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId) { ProgramType type = ProgramType.valueOfCategoryName(programType); final ProgramId id = new ProgramId(namespaceId, appId, type, programId); Set<DatasetId> ids = registry.getDatasets(id); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids)); }
@GET @Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/streams") public void getProgramStreamUsage(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId) { ProgramType type = ProgramType.valueOfCategoryName(programType); final ProgramId id = new ProgramId(namespaceId, appId, type, programId); Set<StreamId> ids = registry.getStreams(id); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids)); }
@GET @Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/datasets") public void getProgramDatasetUsage(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId) { ProgramType type = ProgramType.valueOfCategoryName(programType); final ProgramId id = new ProgramId(namespaceId, appId, type, programId); Set<DatasetId> ids = registry.getDatasets(id); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ids)); }
private ProgramId deserializeProgramId(JsonObject id) { ApplicationId app = deserializeApplicationId(id); ProgramType programType = ProgramType.valueOf(id.get("type").getAsString().toUpperCase()); String programId = id.get("program").getAsString(); return new ProgramId(app.getNamespace(), app.getApplication(), programType, programId); }
private ProgramId deserializeProgramId(JsonObject id) { ApplicationId app = deserializeApplicationId(id); ProgramType programType = ProgramType.valueOf(id.get("type").getAsString().toUpperCase()); String programId = id.get("program").getAsString(); return new ProgramId(app.getNamespace(), app.getApplication(), programType, programId); }
@Override public Trigger onProgramStatus(String application, ProgramType programType, String program, ProgramStatus... programStatuses) { return new ProgramStatusTrigger(new ProgramId(namespaceId.getNamespace(), application, co.cask.cdap.proto.ProgramType.valueOf(programType.name()), program), programStatuses); }
@Override public Trigger onProgramStatus(String application, ProgramType programType, String program, ProgramStatus... programStatuses) { return new ProgramStatusTrigger(new ProgramId(namespaceId.getNamespace(), application, co.cask.cdap.proto.ProgramType.valueOf(programType.name()), program), programStatuses); }
@Override public ProgramId getElement(MDSKey.Splitter splitter) { return new ProgramId(splitter.getString(), splitter.getString(), ProgramType.valueOfCategoryName(splitter.getString()), splitter.getString()); } }
@Override public ProgramId getElement(MDSKey.Splitter splitter) { return new ProgramId(splitter.getString(), splitter.getString(), ProgramType.valueOfCategoryName(splitter.getString()), splitter.getString()); } }
private NamespacedEntityId toEntityId(MDSKey.Splitter splitter, char marker) { switch (marker) { case DATASET_MARKER: return new DatasetId(splitter.getString(), splitter.getString()); case PROGRAM_MARKER: return new ProgramId(splitter.getString(), splitter.getString(), ProgramType.valueOfCategoryName(splitter.getString()), splitter.getString()); default: throw new IllegalStateException("Invalid row with marker " + marker); } }
@SuppressWarnings("unused") public static ProgramId fromIdParts(Iterable<String> idString) { Iterator<String> iterator = idString.iterator(); return new ProgramId( new ApplicationId(next(iterator, "namespace"), next(iterator, "application"), next(iterator, "version")), ProgramType.valueOfPrettyName(next(iterator, "type")), nextAndEnd(iterator, "program")); }
@SuppressWarnings("unused") public static ProgramId fromIdParts(Iterable<String> idString) { Iterator<String> iterator = idString.iterator(); return new ProgramId( new ApplicationId(next(iterator, "namespace"), next(iterator, "application"), next(iterator, "version")), ProgramType.valueOfPrettyName(next(iterator, "type")), nextAndEnd(iterator, "program")); }
@Override public ProgramId getParent() { return new ProgramId(new ApplicationId(getNamespace(), getApplication(), getVersion()), ProgramType.FLOW, getFlow()); }
@Test public void testStopBeforeStart() throws RuntimeException { ProgramId programId = new ProgramId("account1", "invalidApp", ProgramType.MAPREDUCE, "InvalidMR"); long now = System.currentTimeMillis(); String pid = RunIds.generate().getId(); store.setStop(programId.run(pid), now, ProgramController.State.ERROR.getRunStatus(), ByteBuffer.allocate(0).array()); Assert.assertNull(store.getRun(programId.run(pid))); }
@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")); }