public void setWorkerInstances(String namespaceId, String appId, String workerId, int instances) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/worker/%s/instances", getNamespacePath(namespaceId), appId, workerId); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, uri); JsonObject json = new JsonObject(); json.addProperty("instances", instances); request.content().writeCharSequence(json.toString(), StandardCharsets.UTF_8); HttpUtil.setContentLength(request, request.content().readableBytes()); programLifecycleHttpHandler.setWorkerInstances(request, responder, namespaceId, appId, workerId); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Set worker instances failed"); }
public void deleteAllApplications(NamespaceId namespaceId) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.DELETE, String.format("%s/apps", getNamespacePath(namespaceId.getNamespace())) ); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.deleteAllApps(request, mockResponder, namespaceId.getNamespace()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Deleting all apps failed"); }
public void setServiceInstances(String namespaceId, String applicationId, String serviceName, int instances) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/services/%s/instances", getNamespacePath(namespaceId), applicationId, serviceName); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, uri); JsonObject json = new JsonObject(); json.addProperty("instances", instances); request.content().writeCharSequence(json.toString(), StandardCharsets.UTF_8); HttpUtil.setContentLength(request, request.content().readableBytes()); programLifecycleHttpHandler.setServiceInstances(request, responder, namespaceId, applicationId, serviceName); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Set service instances failed"); }
public void resume(String namespaceId, String appId, String schedName) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/schedules/%s/resume", getNamespacePath(namespaceId), appId, schedName); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri); HttpUtil.setContentLength(request, request.content().readableBytes()); programLifecycleHttpHandler.performAction(request, responder, namespaceId, appId, "schedules", schedName, "resume"); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Resume workflow schedules failed"); }
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"); }
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"); }
public void suspend(String namespaceId, String appId, String scheduleName) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/schedules/%s/suspend", getNamespacePath(namespaceId), appId, scheduleName); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri); HttpUtil.setContentLength(request, request.content().readableBytes()); programLifecycleHttpHandler.performAction(request, responder, namespaceId, appId, "schedules", scheduleName, "suspend"); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Suspend workflow schedules failed"); }
public Instances getWorkerInstances(String namespaceId, String appId, String workerId) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/worker/%s/instances", getNamespacePath(namespaceId), appId, workerId); HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri); programLifecycleHttpHandler.getWorkerInstances(request, responder, namespaceId, appId, workerId); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Get worker instances failed"); return responder.decodeResponseContent(Instances.class); }
public ServiceInstances getServiceInstances(String namespaceId, String applicationId, String serviceName) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/services/%s/instances", getNamespacePath(namespaceId), applicationId, serviceName); HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri); programLifecycleHttpHandler.getServiceInstances(request, responder, namespaceId, applicationId, serviceName); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Get service instances failed"); return responder.decodeResponseContent(ServiceInstances.class); }
public void deleteApplication(ApplicationId appId) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.DELETE, String.format("%s/apps/%s/versions/%s", getNamespacePath(appId.getNamespace()), appId.getApplication(), appId.getVersion())); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.deleteApp(request, mockResponder, appId.getNamespace(), appId.getApplication()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Deleting app failed"); }
public Collection<String> listAppVersions(ApplicationId appId) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s/versions", getNamespacePath(appId.getNamespace()), appId.getApplication()) ); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.listAppVersions(request, mockResponder, appId.getNamespace(), appId.getApplication()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Failed to list application versions"); return mockResponder.decodeResponseContent(new TypeToken<Collection<String>>() { }.getType(), GSON); }
public List<PluginInstanceDetail> getPlugins(ApplicationId application) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s", getNamespacePath(application.getNamespace()), application.getApplication()) ); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.getPluginsInfo(request, mockResponder, application.getNamespace(), application.getApplication()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Getting app info failed"); return mockResponder.decodeResponseContent(new TypeToken<List<PluginInstanceDetail>>() { }.getType(), GSON); }
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"); }
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"); }
public ApplicationDetail getInfo(ApplicationId appId) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s", getNamespacePath(appId.getNamespace()), appId.getApplication()) ); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.getAppInfo(request, mockResponder, appId.getNamespace(), appId.getApplication()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Getting app info failed"); return mockResponder.decodeResponseContent(new TypeToken<ApplicationDetail>() { }.getType(), GSON); }
private List<RunRecord> doGetHistory(String namespace, String application, String applicationVersion, String programName, String categoryName, ProgramRunStatus status) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/versions/%s/%s/runs?status=" + status.name(), getNamespacePath(namespace), application, applicationVersion, categoryName, programName); HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri); programLifecycleHttpHandler.programHistory(request, responder, namespace, application, applicationVersion, categoryName, programName, status.name(), null, null, 100); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Getting workflow history failed"); return responder.decodeResponseContent(RUN_RECORDS_TYPE); }
public ApplicationDetail getVersionedInfo(ApplicationId appId) throws Exception { HttpRequest request = new DefaultHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.GET, String.format("%s/apps/%s/versions/%s", getNamespacePath(appId.getNamespace()), appId.getApplication(), appId.getVersion()) ); request.headers().set(Constants.Gateway.API_KEY, "api-key-example"); MockResponder mockResponder = new MockResponder(); appLifecycleHttpHandler.getAppVersionInfo(request, mockResponder, appId.getNamespace(), appId.getApplication(), appId.getVersion()); verifyResponse(HttpResponseStatus.OK, mockResponder.getStatus(), "Getting app version info failed"); return mockResponder.decodeResponseContent(new TypeToken<ApplicationDetail>() { }.getType(), GSON); }
public void addSchedule(ApplicationId application, ScheduleDetail scheduleDetail) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/versions/%s/schedules/%s", getNamespacePath(application.getNamespace()), application.getApplication(), application.getVersion(), scheduleDetail.getName()); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, uri); request.content().writeCharSequence(GSON.toJson(scheduleDetail), StandardCharsets.UTF_8); HttpUtil.setContentLength(request, request.content().readableBytes()); programLifecycleHttpHandler.addSchedule(request, responder, application.getNamespace(), application.getApplication(), application.getVersion(), scheduleDetail.getName()); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Add schedule failed"); }
public void enableSchedule(ScheduleId scheduleId) throws Exception { MockResponder responder = new MockResponder(); String uri = String.format("%s/apps/%s/versions/%s/program-type/schedules/program-id/%s/action/enable", getNamespacePath(scheduleId.getNamespace()), scheduleId.getVersion(), scheduleId.getApplication(), scheduleId.getSchedule()); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri); HttpUtil.setContentLength(request, 0); programLifecycleHttpHandler.performAction(request, responder, scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), "schedules", scheduleId.getSchedule(), "enable"); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Enable schedule failed"); }
public void deleteSchedule(ScheduleId scheduleId) throws Exception { MockResponder responder = new MockResponder(); ApplicationId application = scheduleId.getParent(); String uri = String.format("%s/apps/%s/versions/%s/schedules/%s", getNamespacePath(application.getNamespace()), application.getApplication(), application.getVersion(), scheduleId.getSchedule()); HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, uri); programLifecycleHttpHandler.deleteSchedule(request, responder, application.getNamespace(), application.getApplication(), application.getVersion(), scheduleId.getSchedule()); verifyResponse(HttpResponseStatus.OK, responder.getStatus(), "Delete schedule failed"); } }