private boolean isUserServiceType(String uriPart) { for (ProgramType type : ServiceDiscoverable.getUserServiceTypes()) { if (type.getCategoryName().equals(uriPart)) { return true; } } return false; }
@Override public List<?> makeRow(ProgramRecord object) { return Lists.newArrayList(object.getType().getCategoryName(), object.getApp(), object.getName(), object.getDescription()); } }).build();
public void stopProgram(String namespaceId, String appId, String appVersion, String programId, ProgramType type) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/versions/%s/%s/%s/stop", getNamespacePath(namespaceId), appId, appVersion, type.getCategoryName(), programId); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri); HttpUtil.setContentLength(request, request.content().readableBytes()); programLifecycleHttpHandler.performAction(request, responder, namespaceId, appId, appVersion, type.getCategoryName(), programId, "stop"); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Stop " + type + " failed"); }
protected void stopProgram(Id.Program program, String runId, int expectedStatusCode, String expectedMessage) throws Exception { String path; if (runId == null) { path = String.format("apps/%s/%s/%s/stop", program.getApplicationId(), program.getType().getCategoryName(), program.getId()); } else { path = String.format("apps/%s/%s/%s/runs/%s/stop", program.getApplicationId(), program.getType().getCategoryName(), program.getId(), runId); } stopProgram(path, program.getNamespaceId(), expectedStatusCode, expectedMessage); }
private void verifyProgramList(String namespace, ProgramType programType, int expected) throws Exception { HttpResponse response = requestProgramList(namespace, programType.getCategoryName()); Assert.assertEquals(200, response.getResponseCode()); List<Map<String, String>> programs = GSON.fromJson(response.getResponseBodyAsString(), LIST_MAP_STRING_STRING_TYPE); Assert.assertEquals(expected, programs.size()); }
public void stopProgram(String namespaceId, String appId, String programId, ProgramType type) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/%s/%s/stop", getNamespacePath(namespaceId), appId, type.getCategoryName(), programId); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri); HttpUtil.setContentLength(request, request.content().readableBytes()); programLifecycleHttpHandler.performAction(request, responder, namespaceId, appId, type.getCategoryName(), programId, "stop"); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Stop " + type + " failed"); }
@Override public MDSKey getKey(ProgramId programId) { MDSKey.Builder keyBuilder = new MDSKey.Builder() .add(programId.getNamespace()) .add(programId.getApplication()); // If programId is empty, this is actually applicationId if (!programId.getEntityName().isEmpty()) { keyBuilder.add(programId.getType().getCategoryName()); keyBuilder.add(programId.getEntityName()); } return keyBuilder.build(); }
@Override public MDSKey getKey(ProgramId programId) { MDSKey.Builder keyBuilder = new MDSKey.Builder() .add(programId.getNamespace()) .add(programId.getApplication()); // If programId is empty, this is actually applicationId if (!programId.getEntityName().isEmpty()) { keyBuilder.add(programId.getType().getCategoryName()); keyBuilder.add(programId.getEntityName()); } return keyBuilder.build(); }
/** * Tries to start the given program with the given runtime arguments and expect the call completed with the status. */ protected void startProgram(Id.Program program, Map<String, String> args, int expectedStatusCode) throws Exception { String path = String.format("apps/%s/%s/%s/start", program.getApplicationId(), program.getType().getCategoryName(), program.getId()); startProgram(path, program.getNamespaceId(), args, expectedStatusCode); }
protected void stopProgram(ProgramId program, @Nullable String runId, int expectedStatusCode, String expectedMessage) throws Exception { String path; if (runId == null) { path = String.format("apps/%s/versions/%s/%s/%s/stop", program.getApplication(), program.getVersion(), program.getType().getCategoryName(), program.getProgram()); } else { // TODO: HTTP endpoint for stopping a program run of an app version not implemented path = null; } stopProgram(path, program.getNamespace(), expectedStatusCode, expectedMessage); }
public String getStatus(String namespaceId, String appId, String appVersion, String programId, ProgramType type) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/versions/%s/%s/%s/status", getNamespacePath(namespaceId), appId, appVersion, type, programId); HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri); programLifecycleHttpHandler.getStatus(request, responder, namespaceId, appId, appVersion, type.getCategoryName(), programId); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Get status " + type + " failed"); Map<String, String> json = responder.decodeResponseContent(MAP_TYPE); return json.get("status"); }
/** * Tries to start the given program with the given runtime arguments and expect the call completed with the status. */ protected void debugProgram(Id.Program program, int expectedStatusCode) throws Exception { String path = String.format("apps/%s/%s/%s/debug", program.getApplicationId(), program.getType().getCategoryName(), program.getId()); HttpResponse response = doPost(getVersionedAPIPath(path, program.getNamespaceId()), GSON.toJson(ImmutableMap.<String, String>of())); Assert.assertEquals(expectedStatusCode, response.getResponseCode()); }
public String getStatus(String namespaceId, String appId, String programId, ProgramType type) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/%s/%s/status", getNamespacePath(namespaceId), appId, type, programId); HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri); programLifecycleHttpHandler.getStatus(request, responder, namespaceId, appId, type.getCategoryName(), programId); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Get status " + type + " failed"); Map<String, String> json = responder.decodeResponseContent(MAP_TYPE); return json.get("status"); }
/** * Tries to start the given program with the given runtime arguments and expect the call completed with the status. */ protected void startProgram(ProgramId program, Map<String, String> args, int expectedStatusCode) throws Exception { String path = String.format("apps/%s/versions/%s/%s/%s/start", program.getApplication(), program.getVersion(), program.getType().getCategoryName(), program.getProgram()); startProgram(path, program.getNamespace(), args, expectedStatusCode); }
private HttpResponse programStatus(Id.Program program) throws Exception { String path = String.format("apps/%s/%s/%s/status", program.getApplicationId(), program.getType().getCategoryName(), program.getId()); return doGet(getVersionedAPIPath(path, program.getNamespaceId())); }
public List<RunRecord> getHistory(Id.Program programId, ProgramRunStatus status) throws Exception { String namespace = programId.getNamespaceId(); String application = programId.getApplicationId(); String programName = programId.getId(); String categoryName = programId.getType().getCategoryName(); return doGetHistory(namespace, application, ApplicationId.DEFAULT_VERSION, programName, categoryName, status); }
protected List<RunRecord> getProgramRuns(Id.Program program, ProgramRunStatus status) throws Exception { String path = String.format("apps/%s/%s/%s/runs?status=%s", program.getApplicationId(), program.getType().getCategoryName(), program.getId(), status.name()); HttpResponse response = doGet(getVersionedAPIPath(path, program.getNamespaceId())); Assert.assertEquals(200, response.getResponseCode()); return GSON.fromJson(response.getResponseBodyAsString(), LIST_RUNRECORD_TYPE); }
private void testListInitialState(String namespace, ProgramType programType) throws Exception { HttpResponse response = doGet(getVersionedAPIPath(programType.getCategoryName(), Constants.Gateway.API_VERSION_3_TOKEN, namespace)); Assert.assertEquals(200, response.getResponseCode()); Assert.assertEquals(EMPTY_ARRAY_JSON, response.getResponseBodyAsString()); }
public List<RunRecord> getHistory(ProgramId programId, ProgramRunStatus status) throws Exception { String namespace = programId.getNamespace(); String application = programId.getApplication(); String applicationVersion = programId.getVersion(); String programName = programId.getProgram(); String categoryName = programId.getType().getCategoryName(); return doGetHistory(namespace, application, applicationVersion, programName, categoryName, status); }
private void testVersionedProgramRuntimeArgs(ProgramId programId) throws Exception { String versionedRuntimeArgsUrl = getVersionedAPIPath("apps/" + programId.getApplication() + "/versions/" + programId.getVersion() + "/" + programId.getType().getCategoryName() + "/" + programId.getProgram() + "/runtimeargs", Constants.Gateway.API_VERSION_3_TOKEN, programId.getNamespace()); verifyRuntimeArgs(versionedRuntimeArgsUrl); }