@Override public void ensureExists(ApplicationId appId) throws ApplicationNotFoundException { if (store.getApplication(appId) == null) { throw new ApplicationNotFoundException(appId); } } }
@Override public void ensureExists(ApplicationId appId) throws ApplicationNotFoundException { if (store.getApplication(appId) == null) { throw new ApplicationNotFoundException(appId); } } }
/** * Returns the list of versions of the application. */ @GET @Path("/apps/{app-id}/versions") public void listAppVersions(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") final String namespaceId, @PathParam("app-id") final String appId) throws Exception { ApplicationId applicationId = validateApplicationId(namespaceId, appId); Collection<String> versions = applicationLifecycleService.getAppVersions(namespaceId, appId); if (versions.isEmpty()) { throw new ApplicationNotFoundException(applicationId); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(versions)); }
/** * Returns the list of versions of the application. */ @GET @Path("/apps/{app-id}/versions") public void listAppVersions(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") final String namespaceId, @PathParam("app-id") final String appId) throws Exception { ApplicationId applicationId = validateApplicationId(namespaceId, appId); Collection<String> versions = applicationLifecycleService.getAppVersions(namespaceId, appId); if (versions.isEmpty()) { throw new ApplicationNotFoundException(applicationId); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(versions)); }
/** * Get detail about the plugin in the specified application * * @param appId the id of the application * @return list of plugins in the application * @throws ApplicationNotFoundException if the specified application does not exist */ public List<PluginInstanceDetail> getPlugins(ApplicationId appId) throws ApplicationNotFoundException { ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId); } List<PluginInstanceDetail> pluginInstanceDetails = new ArrayList<>(); for (Map.Entry<String, Plugin> entry : appSpec.getPlugins().entrySet()) { pluginInstanceDetails.add(new PluginInstanceDetail(entry.getKey(), entry.getValue())); } return pluginInstanceDetails; }
/** * Get detail about the plugin in the specified application * * @param appId the id of the application * @return list of plugins in the application * @throws ApplicationNotFoundException if the specified application does not exist */ public List<PluginInstanceDetail> getPlugins(ApplicationId appId) throws ApplicationNotFoundException { ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId); } List<PluginInstanceDetail> pluginInstanceDetails = new ArrayList<>(); for (Map.Entry<String, Plugin> entry : appSpec.getPlugins().entrySet()) { pluginInstanceDetails.add(new PluginInstanceDetail(entry.getKey(), entry.getValue())); } return pluginInstanceDetails; }
@Override public List<ProgramHistory> getRuns(Collection<ProgramId> programs, ProgramRunStatus status, long startTime, long endTime, int limit, Predicate<RunRecordMeta> filter) { return Transactionals.execute(transactional, context -> { List<ProgramHistory> result = new ArrayList<>(programs.size()); AppMetadataStore appMetadataStore = getAppMetadataStore(context); Collection<ApplicationId> appIds = programs.stream().map(ProgramId::getParent).collect(Collectors.toList()); Map<ApplicationId, ApplicationMeta> apps = appMetadataStore.getApplicationsForAppIds(appIds); for (ProgramId program : programs) { ApplicationMeta appMeta = apps.get(program.getParent()); if (appMeta == null) { result.add(new ProgramHistory(program, Collections.emptyList(), new ApplicationNotFoundException(program.getParent()))); continue; } ApplicationSpecification appSpec = appMeta.getSpec(); ProgramSpecification programSpec = getExistingAppProgramSpecification(appSpec, program); if (programSpec == null) { result.add(new ProgramHistory(program, Collections.emptyList(), new ProgramNotFoundException(program))); continue; } List<RunRecord> runs = appMetadataStore.getRuns(program, status, startTime, endTime, limit, filter).values() .stream() .map(record -> RunRecord.builder(record).build()).collect(Collectors.toList()); result.add(new ProgramHistory(program, runs, null)); } return result; }); }
@Override public List<ProgramHistory> getRuns(Collection<ProgramId> programs, ProgramRunStatus status, long startTime, long endTime, int limit, Predicate<RunRecordMeta> filter) { return Transactionals.execute(transactional, context -> { List<ProgramHistory> result = new ArrayList<>(programs.size()); AppMetadataStore appMetadataStore = getAppMetadataStore(context); Collection<ApplicationId> appIds = programs.stream().map(ProgramId::getParent).collect(Collectors.toList()); Map<ApplicationId, ApplicationMeta> apps = appMetadataStore.getApplicationsForAppIds(appIds); for (ProgramId program : programs) { ApplicationMeta appMeta = apps.get(program.getParent()); if (appMeta == null) { result.add(new ProgramHistory(program, Collections.emptyList(), new ApplicationNotFoundException(program.getParent()))); continue; } ApplicationSpecification appSpec = appMeta.getSpec(); ProgramSpecification programSpec = getExistingAppProgramSpecification(appSpec, program); if (programSpec == null) { result.add(new ProgramHistory(program, Collections.emptyList(), new ProgramNotFoundException(program))); continue; } List<RunRecord> runs = appMetadataStore.getRuns(program, status, startTime, endTime, limit, filter).values() .stream() .map(record -> RunRecord.builder(record).build()).collect(Collectors.toList()); result.add(new ProgramHistory(program, runs, null)); } return result; }); }
@GET @Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/nodes/state") public void getWorkflowNodeStates(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String applicationId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId) throws NotFoundException { ApplicationId appId = Ids.namespace(namespaceId).app(applicationId); ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId); } ProgramId workflowProgramId = appId.workflow(workflowId); WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowProgramId.getProgram()); if (workflowSpec == null) { throw new ProgramNotFoundException(workflowProgramId); } ProgramRunId workflowRunId = workflowProgramId.run(runId); if (store.getRun(workflowRunId) == null) { throw new NotFoundException(workflowRunId); } List<WorkflowNodeStateDetail> nodeStateDetails = store.getWorkflowNodeStates(workflowRunId); Map<String, WorkflowNodeStateDetail> nodeStates = new HashMap<>(); for (WorkflowNodeStateDetail nodeStateDetail : nodeStateDetails) { nodeStates.put(nodeStateDetail.getNodeId(), nodeStateDetail); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(nodeStates, STRING_TO_NODESTATEDETAIL_MAP_TYPE)); }
throw new ApplicationNotFoundException(programId.getParent()); } else if (!store.programExists(programId)) { throw new ProgramNotFoundException(programId);
@GET @Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/nodes/state") public void getWorkflowNodeStates(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String applicationId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId) throws NotFoundException { ApplicationId appId = Ids.namespace(namespaceId).app(applicationId); ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId); } ProgramId workflowProgramId = appId.workflow(workflowId); WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowProgramId.getProgram()); if (workflowSpec == null) { throw new ProgramNotFoundException(workflowProgramId); } ProgramRunId workflowRunId = workflowProgramId.run(runId); if (store.getRun(workflowRunId) == null) { throw new NotFoundException(workflowRunId); } List<WorkflowNodeStateDetail> nodeStateDetails = store.getWorkflowNodeStates(workflowRunId); Map<String, WorkflowNodeStateDetail> nodeStates = new HashMap<>(); for (WorkflowNodeStateDetail nodeStateDetail : nodeStateDetails) { nodeStates.put(nodeStateDetail.getNodeId(), nodeStateDetail); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(nodeStates, STRING_TO_NODESTATEDETAIL_MAP_TYPE)); }
throw new ApplicationNotFoundException(programId.getParent()); } else if (!store.programExists(programId)) { throw new ProgramNotFoundException(programId);
/** * Add a schedule to an application. * * @param app the application * @param scheduleDetail the schedule to be added */ public void addSchedule(ApplicationId app, ScheduleDetail scheduleDetail) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException, BadRequestException { String path = String.format("apps/%s/versions/%s/schedules/%s", app.getApplication(), app.getVersion(), scheduleDetail.getName()); HttpResponse response = restClient.execute(HttpMethod.PUT, config.resolveNamespacedURLV3(app.getParent(), path), GSON.toJson(scheduleDetail), ImmutableMap.<String, String>of(), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST); int responseCode = response.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) { throw new ApplicationNotFoundException(app); } else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException(String.format("Bad Request. Reason: %s", response.getResponseBodyAsString())); } }
/** * Deletes an application. * * @param app the application to delete * @throws ApplicationNotFoundException if the application with the given ID was not found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public void delete(ApplicationId app) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException { String path = String.format("apps/%s/versions/%s", app.getApplication(), app.getVersion()); HttpResponse response = restClient.execute(HttpMethod.DELETE, config.resolveNamespacedURLV3(app.getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new ApplicationNotFoundException(app); } }
private void getScheduledRuntime(HttpResponder responder, String namespaceId, String appName, String workflowName, boolean previousRuntimeRequested) throws SchedulerException, NotFoundException { try { ApplicationId appId = new ApplicationId(namespaceId, appName); WorkflowId workflowId = new WorkflowId(appId, workflowName); ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId); } if (appSpec.getWorkflows().get(workflowName) == null) { throw new ProgramNotFoundException(workflowId); } List<ScheduledRuntime> runtimes; if (previousRuntimeRequested) { runtimes = timeScheduler.previousScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW); } else { runtimes = timeScheduler.nextScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runtimes)); } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } }
ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId);
/** * Get detail about the specified application * * @param appId the id of the application to get * @return detail about the specified application * @throws ApplicationNotFoundException if the specified application does not exist */ public ApplicationDetail getAppDetail(ApplicationId appId) throws Exception { // TODO: CDAP-12473: filter based on the entity visibility in the app detail // user needs to pass the visibility check to get the app detail AuthorizationUtil.ensureAccess(appId, authorizationEnforcer, authenticationContext.getPrincipal()); ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId); } String ownerPrincipal = ownerAdmin.getOwnerPrincipal(appId); return filterApplicationDetail(appId, ApplicationDetail.fromSpec(appSpec, ownerPrincipal)); }
private void getScheduledRuntime(HttpResponder responder, String namespaceId, String appName, String workflowName, boolean previousRuntimeRequested) throws SchedulerException, NotFoundException { try { ApplicationId appId = new ApplicationId(namespaceId, appName); WorkflowId workflowId = new WorkflowId(appId, workflowName); ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId); } if (appSpec.getWorkflows().get(workflowName) == null) { throw new ProgramNotFoundException(workflowId); } List<ScheduledRuntime> runtimes; if (previousRuntimeRequested) { runtimes = timeScheduler.previousScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW); } else { runtimes = timeScheduler.nextScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW); } responder.sendJson(HttpResponseStatus.OK, GSON.toJson(runtimes)); } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } }
ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId);
/** * Get detail about the specified application * * @param appId the id of the application to get * @return detail about the specified application * @throws ApplicationNotFoundException if the specified application does not exist */ public ApplicationDetail getAppDetail(ApplicationId appId) throws Exception { // TODO: CDAP-12473: filter based on the entity visibility in the app detail // user needs to pass the visibility check to get the app detail AuthorizationUtil.ensureAccess(appId, authorizationEnforcer, authenticationContext.getPrincipal()); ApplicationSpecification appSpec = store.getApplication(appId); if (appSpec == null) { throw new ApplicationNotFoundException(appId); } String ownerPrincipal = ownerAdmin.getOwnerPrincipal(appId); return filterApplicationDetail(appId, ApplicationDetail.fromSpec(appSpec, ownerPrincipal)); }