use of co.cask.cdap.common.ProgramNotFoundException in project cdap by caskdata.
the class ProgramClient method getProgramLogs.
/**
* Gets the logs of a program.
*
* @param program the program
* @param start start time of the time range of desired logs
* @param stop end time of the time range of desired logs
* @return the logs of the program
* @throws IOException if a network error occurred
* @throws NotFoundException if the application or program could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public String getProgramLogs(ProgramId program, long start, long stop) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
String path = String.format("apps/%s/%s/%s/logs?start=%d&stop=%d&escape=false", program.getApplication(), program.getType().getCategoryName(), program.getProgram(), start, stop);
URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ProgramNotFoundException(program);
}
return new String(response.getResponseBody(), Charsets.UTF_8);
}
use of co.cask.cdap.common.ProgramNotFoundException in project cdap by caskdata.
the class ProgramClient method getRuntimeArgs.
/**
* Gets the runtime args of a program.
*
* @param program the program
* @return runtime args of the program
* @throws IOException if a network error occurred
* @throws ProgramNotFoundException if the application or program could not be found
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public Map<String, String> getRuntimeArgs(ProgramId program) throws IOException, UnauthenticatedException, ProgramNotFoundException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s/%s/%s/runtimeargs", program.getApplication(), program.getVersion(), program.getType().getCategoryName(), program.getProgram());
URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), path);
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ProgramNotFoundException(program);
}
return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() {
}).getResponseObject();
}
use of co.cask.cdap.common.ProgramNotFoundException in project cdap by caskdata.
the class PreferencesClient method deleteProgramPreferences.
/**
* Deletes Preferences at the Program Level.
*
* @param program Program Id
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ProgramNotFoundException if the requested program is not found
*/
public void deleteProgramPreferences(ProgramId program) throws IOException, UnauthenticatedException, ProgramNotFoundException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), String.format("/apps/%s/%s/%s/preferences", program.getApplication(), program.getType().getCategoryName(), program.getProgram()));
HttpResponse response = restClient.execute(HttpMethod.DELETE, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ProgramNotFoundException(program);
}
}
use of co.cask.cdap.common.ProgramNotFoundException in project cdap by caskdata.
the class PreferencesClient method setProgramPreferences.
/**
* Sets Preferences at the Program Level.
*
* @param program Program 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 ProgramNotFoundException if the requested program is not found
*/
public void setProgramPreferences(ProgramId program, Map<String, String> preferences) throws IOException, UnauthenticatedException, ProgramNotFoundException, UnauthorizedException {
URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), String.format("/apps/%s/%s/%s/preferences", program.getApplication(), program.getType().getCategoryName(), program.getProgram()));
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 ProgramNotFoundException(program);
}
}
use of co.cask.cdap.common.ProgramNotFoundException in project cdap by caskdata.
the class ScheduleTaskRunner method execute.
/**
* Executes a program without blocking until its completion.
*
* @return a {@link ListenableFuture} object that completes when the program completes
*/
public ListenableFuture<?> execute(final ProgramId id, Map<String, String> sysArgs, Map<String, String> userArgs) throws Exception {
ProgramRuntimeService.RuntimeInfo runtimeInfo;
String originalUserId = SecurityRequestContext.getUserId();
try {
// if the program has a namespace user configured then set that user in the security request context.
// See: CDAP-7396
String nsPrincipal = namespaceQueryAdmin.get(id.getNamespaceId()).getConfig().getPrincipal();
if (nsPrincipal != null && SecurityUtil.isKerberosEnabled(cConf)) {
SecurityRequestContext.setUserId(new KerberosName(nsPrincipal).getServiceName());
}
runtimeInfo = lifecycleService.startInternal(id, sysArgs, userArgs, false);
} catch (ProgramNotFoundException | ApplicationNotFoundException e) {
throw new TaskExecutionException(String.format(UserMessages.getMessage(UserErrors.PROGRAM_NOT_FOUND), id), e, false);
} finally {
SecurityRequestContext.setUserId(originalUserId);
}
final ProgramController controller = runtimeInfo.getController();
final CountDownLatch latch = new CountDownLatch(1);
controller.addListener(new AbstractListener() {
@Override
public void init(ProgramController.State state, @Nullable Throwable cause) {
if (state == ProgramController.State.COMPLETED) {
completed();
}
if (state == ProgramController.State.ERROR) {
error(controller.getFailureCause());
}
}
@Override
public void killed() {
latch.countDown();
}
@Override
public void completed() {
latch.countDown();
}
@Override
public void error(Throwable cause) {
latch.countDown();
}
}, Threads.SAME_THREAD_EXECUTOR);
return executorService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
latch.await();
return null;
}
});
}
Aggregations