@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; }
/** * 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); } }
/** * 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)); }
/** * Lists all applications currently deployed, optionally filtering to only include applications that use one of * the specified artifact names and the specified artifact version. * * @param namespace the namespace to list application versions from * @param appName the application name to list versions for * @return list of {@link String} application versions. * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public List<String> listAppVersions(NamespaceId namespace, String appName) throws IOException, UnauthenticatedException, UnauthorizedException, ApplicationNotFoundException { String path = String.format("apps/%s/versions", appName); URL url = config.resolveNamespacedURLV3(namespace, path); HttpRequest request = HttpRequest.get(url).build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new ApplicationNotFoundException(namespace.app(appName)); } return ObjectResponse.fromJsonBody(response, new TypeToken<List<String>>() { }).getResponseObject(); }
/** * Get details about the specified application. * * @param appId the id of the application to get * @return details about the specified application * @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 ApplicationDetail get(ApplicationId appId) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException { String path = String.format("apps/%s/versions/%s", appId.getApplication(), appId.getVersion()); HttpResponse response = restClient.execute(HttpMethod.GET, config.resolveNamespacedURLV3(appId.getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new ApplicationNotFoundException(appId); } return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject(); }
/** * Enable a schedule in an application. * * @param scheduleId the id of the schedule to be enabled */ public void enableSchedule(ScheduleId scheduleId) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException, BadRequestException { String path = String.format("apps/%s/versions/%s/program-type/schedules/program-id/%s/action/enable", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); HttpResponse response = restClient.execute(HttpMethod.PUT, config.resolveNamespacedURLV3(scheduleId.getParent().getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST); int responseCode = response.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) { throw new ApplicationNotFoundException(scheduleId.getParent()); } else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) { throw new BadRequestException(String.format("Bad Request. Reason: %s", response.getResponseBodyAsString())); } } }
/** * Get plugins in the specified application. * * @param appId the id of the application to get * @return list of plugins in the application * @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 List<PluginInstanceDetail> getPlugins(ApplicationId appId) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException { HttpResponse response = restClient.execute(HttpMethod.GET, config.resolveNamespacedURLV3( appId.getParent(), "apps/" + appId.getApplication() + "/plugins"), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new ApplicationNotFoundException(appId); } return ObjectResponse.fromJsonBody(response, new TypeToken<List<PluginInstanceDetail>>() { }).getResponseObject(); }
/** * Lists all programs belonging to an application. * * @param app the application * @return List of all {@link ProgramRecord}s * @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 List<ProgramRecord> listPrograms(ApplicationId app) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException { String path = String.format("apps/%s/versions/%s", app.getApplication(), app.getVersion()); URL url = config.resolveNamespacedURLV3(app.getParent(), path); HttpRequest request = HttpRequest.get(url).build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new ApplicationNotFoundException(app); } return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject().getPrograms(); }
@Override public ProgramDescriptor loadProgram(ProgramId id) throws IOException, ApplicationNotFoundException, ProgramNotFoundException { ApplicationMeta appMeta = Transactionals.execute(transactional, context -> { return getAppMetadataStore(context).getApplication(id.getNamespace(), id.getApplication(), id.getVersion()); }); if (appMeta == null) { throw new ApplicationNotFoundException(id.getParent()); } if (!programExists(id, appMeta.getSpec())) { throw new ProgramNotFoundException(id); } return new ProgramDescriptor(id, appMeta.getSpec()); }
@Override public ProgramDescriptor loadProgram(ProgramId id) throws IOException, ApplicationNotFoundException, ProgramNotFoundException { ApplicationMeta appMeta = Transactionals.execute(transactional, context -> { return getAppMetadataStore(context).getApplication(id.getNamespace(), id.getApplication(), id.getVersion()); }); if (appMeta == null) { throw new ApplicationNotFoundException(id.getParent()); } if (!programExists(id, appMeta.getSpec())) { throw new ProgramNotFoundException(id); } return new ProgramDescriptor(id, appMeta.getSpec()); }