@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception { NamespaceId namespace = args.appId.getParent(); printStream.print("Stopping programs...\n"); programClient.stop(namespace, args.programs); printStream.print("Starting programs...\n"); List<BatchProgramStart> startList = new ArrayList<>(args.programs.size()); for (BatchProgram program : args.programs) { startList.add(new BatchProgramStart(program)); } programClient.start(namespace, startList); }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception { NamespaceId namespace = args.appId.getParent(); printStream.print("Stopping programs...\n"); programClient.stop(namespace, args.programs); printStream.print("Starting programs...\n"); List<BatchProgramStart> startList = new ArrayList<>(args.programs.size()); for (BatchProgram program : args.programs) { startList.add(new BatchProgramStart(program)); } programClient.start(namespace, startList); }
/** * Sets Preferences at the Application Level. * * @param application Application Id * @param preferences map of key-value pairs * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server * @throws NotFoundException if the requested application or namespace is not found */ public void setApplicationPreferences(ApplicationId application, Map<String, String> preferences) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(application.getParent(), String.format("/apps/%s/preferences", application.getApplication())); HttpResponse response = restClient.execute(HttpMethod.PUT, url, GSON.toJson(preferences), null, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NotFoundException(application); } }
/** * Deletes Preferences at the Application Level. * * @param application Application Id * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server * @throws NotFoundException if the request application or namespace is not found */ public void deleteApplicationPreferences(ApplicationId application) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(application.getParent(), String.format("/apps/%s/preferences", application.getApplication())); HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NotFoundException(application); } }
/** * Checks if an application exists. * * @param app the application to check * @return true if the application exists * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public boolean exists(ApplicationId app) throws IOException, UnauthenticatedException, UnauthorizedException { HttpResponse response = restClient.execute( HttpMethod.GET, config.resolveNamespacedURLV3(app.getParent(), "apps/" + app.getApplication()), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); return response.getResponseCode() != HttpURLConnection.HTTP_NOT_FOUND; }
/** * 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); } }
public String getStatus(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException { String path = String.format("apps/%s/versions/%s/schedules/%s/status", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule()); URL url = config.resolveNamespacedURLV3(scheduleId.getParent().getParent(), path); HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) { throw new NotFoundException(scheduleId); } Map<String, String> responseObject = ObjectResponse.<Map<String, String>>fromJsonBody(response, MAP_STRING_STRING_TYPE, GSON).getResponseObject(); return responseObject.get("status"); }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception { List<BatchProgramResult> results = programClient.stop(args.appId.getParent(), args.programs); Table table = Table.builder() .setHeader("name", "type", "error") .setRows(results, new RowMaker<BatchProgramResult>() { @Override public List<?> makeRow(BatchProgramResult result) { return Lists.newArrayList( result.getProgramId(), result.getProgramType(), result.getError()); } }).build(); cliConfig.getTableRenderer().render(cliConfig, printStream, table); }
/** * Receives an input containing application specification and location * and verifies both. * * @param input An instance of {@link ApplicationDeployable} */ @Override public void process(ApplicationDeployable input) throws Exception { // create stream instances ApplicationSpecification specification = input.getSpecification(); NamespaceId namespaceId = input.getApplicationId().getParent(); KerberosPrincipalId ownerPrincipal = input.getOwnerPrincipal(); // get the authorizing user String authorizingUser = AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, input.getApplicationId(), ownerPrincipal); streamCreator.createStreams(namespaceId, specification.getStreams().values(), ownerPrincipal, authorizingUser); // Emit the input to next stage. emit(input); } }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception { List<BatchProgramResult> results = programClient.stop(args.appId.getParent(), args.programs); Table table = Table.builder() .setHeader("name", "type", "error") .setRows(results, new RowMaker<BatchProgramResult>() { @Override public List<?> makeRow(BatchProgramResult result) { return Lists.newArrayList( result.getProgramId(), result.getProgramType(), result.getError()); } }).build(); cliConfig.getTableRenderer().render(cliConfig, printStream, table); }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgramStart> args) throws Exception { List<BatchProgramResult> results = programClient.start(args.appId.getParent(), args.programs); Table table = Table.builder() .setHeader("name", "type", "error") .setRows(results, new RowMaker<BatchProgramResult>() { @Override public List<?> makeRow(BatchProgramResult result) { return Lists.newArrayList( result.getProgramId(), result.getProgramType(), result.getError()); } }).build(); cliConfig.getTableRenderer().render(cliConfig, printStream, table); }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception { List<BatchProgramStatus> results = programClient.getStatus(args.appId.getParent(), args.programs); Table table = Table.builder() .setHeader("name", "type", "status", "error") .setRows(results, new RowMaker<BatchProgramStatus>() { @Override public List<?> makeRow(BatchProgramStatus result) { return Lists.newArrayList( result.getProgramId(), result.getProgramType(), result.getStatus(), result.getError()); } }).build(); cliConfig.getTableRenderer().render(cliConfig, printStream, table); }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgramStart> args) throws Exception { List<BatchProgramResult> results = programClient.start(args.appId.getParent(), args.programs); Table table = Table.builder() .setHeader("name", "type", "error") .setRows(results, new RowMaker<BatchProgramResult>() { @Override public List<?> makeRow(BatchProgramResult result) { return Lists.newArrayList( result.getProgramId(), result.getProgramType(), result.getError()); } }).build(); cliConfig.getTableRenderer().render(cliConfig, printStream, table); }
@Override protected void runBatchCommand(PrintStream printStream, Args<BatchProgram> args) throws Exception { List<BatchProgramStatus> results = programClient.getStatus(args.appId.getParent(), args.programs); Table table = Table.builder() .setHeader("name", "type", "status", "error") .setRows(results, new RowMaker<BatchProgramStatus>() { @Override public List<?> makeRow(BatchProgramStatus result) { return Lists.newArrayList( result.getProgramId(), result.getProgramType(), result.getStatus(), result.getError()); } }).build(); cliConfig.getTableRenderer().render(cliConfig, printStream, table); }
/** * 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(); }
/** * Receives an input containing application specification and location * and verifies both. * * @param input An instance of {@link ApplicationDeployable} */ @Override public void process(ApplicationDeployable input) throws Exception { // create dataset instances ApplicationSpecification specification = input.getSpecification(); NamespaceId namespaceId = input.getApplicationId().getParent(); KerberosPrincipalId ownerPrincipal = input.getOwnerPrincipal(); // get the authorizing user String authorizingUser = AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, input.getApplicationId(), ownerPrincipal); datasetInstanceCreator.createInstances(namespaceId, specification.getDatasets(), ownerPrincipal, authorizingUser); // Emit the input to next stage. emit(input); } }
/** * Receives an input containing application specification and location * and verifies both. * * @param input An instance of {@link ApplicationDeployable} */ @Override public void process(ApplicationDeployable input) throws Exception { // create dataset instances ApplicationSpecification specification = input.getSpecification(); NamespaceId namespaceId = input.getApplicationId().getParent(); KerberosPrincipalId ownerPrincipal = input.getOwnerPrincipal(); // get the authorizing user String authorizingUser = AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, input.getApplicationId(), ownerPrincipal); datasetInstanceCreator.createInstances(namespaceId, specification.getDatasets(), ownerPrincipal, authorizingUser); // Emit the input to next stage. emit(input); } }
/** * 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(); }
/** * Deploys dataset modules specified in the given application spec. * * @param input An instance of {@link ApplicationDeployable} */ @Override public void process(ApplicationDeployable input) throws Exception { KerberosPrincipalId ownerPrincipal = input.getOwnerPrincipal(); // get the authorizing user String authorizingUser = AuthorizationUtil.getAppAuthorizingUser(ownerAdmin, authenticationContext, input.getApplicationId(), ownerPrincipal); ClassLoader classLoader = getContext().getProperty(LocalApplicationManager.ARTIFACT_CLASSLOADER_KEY); datasetModulesDeployer.deployModules(input.getApplicationId().getParent(), input.getSpecification().getDatasetModules(), input.getArtifactLocation(), classLoader, authorizingUser); // Emit the input to next stage. emit(input); } }