Search in sources :

Example 1 with ProgramNotFoundException

use of io.cdap.cdap.common.ProgramNotFoundException in project cdap by caskdata.

the class ProgramExistenceVerifier method ensureExists.

@Override
public void ensureExists(ProgramId programId) throws ApplicationNotFoundException, ProgramNotFoundException {
    ApplicationId appId = programId.getParent();
    ApplicationSpecification appSpec = store.getApplication(appId);
    if (appSpec == null) {
        throw new ApplicationNotFoundException(appId);
    }
    ProgramType programType = programId.getType();
    Set<String> programNames = null;
    if (programType == ProgramType.MAPREDUCE && appSpec.getMapReduce() != null) {
        programNames = appSpec.getMapReduce().keySet();
    } else if (programType == ProgramType.WORKFLOW && appSpec.getWorkflows() != null) {
        programNames = appSpec.getWorkflows().keySet();
    } else if (programType == ProgramType.SERVICE && appSpec.getServices() != null) {
        programNames = appSpec.getServices().keySet();
    } else if (programType == ProgramType.SPARK && appSpec.getSpark() != null) {
        programNames = appSpec.getSpark().keySet();
    } else if (programType == ProgramType.WORKER && appSpec.getWorkers() != null) {
        programNames = appSpec.getWorkers().keySet();
    }
    if (programNames != null) {
        if (programNames.contains(programId.getProgram())) {
            // is valid.
            return;
        }
    }
    throw new ProgramNotFoundException(programId);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) ProgramType(io.cdap.cdap.proto.ProgramType) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException)

Example 2 with ProgramNotFoundException

use of io.cdap.cdap.common.ProgramNotFoundException in project cdap by caskdata.

the class ProgramClient method getStatus.

/**
 * Gets the status of a program
 * @param programId the program
 * @return the status of the program (e.g. STOPPED, STARTING, RUNNING)
 * @throws IOException if a network error occurred
 * @throws ProgramNotFoundException if the program with the specified name could not be found
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public String getStatus(ProgramId programId) throws IOException, ProgramNotFoundException, UnauthenticatedException, UnauthorizedException {
    String path = String.format("apps/%s/versions/%s/%s/%s/status", programId.getApplication(), programId.getVersion(), programId.getType().getCategoryName(), programId.getProgram());
    URL url = config.resolveNamespacedURLV3(programId.getNamespaceId(), path);
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
        throw new ProgramNotFoundException(programId);
    }
    Map<String, String> responseObject = ObjectResponse.<Map<String, String>>fromJsonBody(response, MAP_STRING_STRING_TYPE, GSON).getResponseObject();
    return responseObject.get("status");
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) URL(java.net.URL)

Example 3 with ProgramNotFoundException

use of io.cdap.cdap.common.ProgramNotFoundException in project cdap by caskdata.

the class ProgramClient method setRuntimeArgs.

/**
 * Sets the runtime args of a program.
 *
 * @param program the program
 * @param runtimeArgs 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 void setRuntimeArgs(ProgramId program, Map<String, String> runtimeArgs) 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);
    HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(runtimeArgs)).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ProgramNotFoundException(program);
    }
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) URL(java.net.URL)

Example 4 with ProgramNotFoundException

use of io.cdap.cdap.common.ProgramNotFoundException in project cdap by caskdata.

the class ProgramClient method getLiveInfo.

/**
 * Gets the live information of a program. In distributed CDAP,
 * this will contain IDs of the YARN applications that are running the program.
 *
 * @param program the program
 * @return {@link ProgramLiveInfo} of the program
 * @throws IOException if a network error occurred
 * @throws ProgramNotFoundException if the program with the specified name could not be found
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 */
public DistributedProgramLiveInfo getLiveInfo(ProgramId program) throws IOException, ProgramNotFoundException, UnauthenticatedException, UnauthorizedException {
    String path = String.format("apps/%s/%s/%s/live-info", program.getApplication(), 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, DistributedProgramLiveInfo.class).getResponseObject();
}
Also used : DistributedProgramLiveInfo(io.cdap.cdap.proto.DistributedProgramLiveInfo) HttpResponse(io.cdap.common.http.HttpResponse) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) URL(java.net.URL)

Example 5 with ProgramNotFoundException

use of io.cdap.cdap.common.ProgramNotFoundException in project cdap by caskdata.

the class ProgramClient method start.

/**
 * Starts a program using specified runtime arguments.
 *
 * @param program the program to start
 * @param debug true to start in debug mode
 * @param runtimeArgs runtime arguments to pass to the program
 * @throws IOException
 * @throws ProgramNotFoundException
 * @throws UnauthenticatedException
 * @throws UnauthorizedException
 */
public void start(ProgramId program, boolean debug, @Nullable Map<String, String> runtimeArgs) throws IOException, ProgramNotFoundException, UnauthenticatedException, UnauthorizedException {
    String action = debug ? "debug" : "start";
    String path = String.format("apps/%s/versions/%s/%s/%s/%s", program.getApplication(), program.getVersion(), program.getType().getCategoryName(), program.getProgram(), action);
    URL url = config.resolveNamespacedURLV3(program.getNamespaceId(), path);
    // Required to add body even if runtimeArgs is null to avoid 411 error for Http POST
    HttpRequest.Builder request = HttpRequest.post(url).withBody(GSON.toJson(runtimeArgs));
    ;
    HttpResponse response = restClient.execute(request.build(), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ProgramNotFoundException(program);
    }
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) HttpResponse(io.cdap.common.http.HttpResponse) ProgramNotFoundException(io.cdap.cdap.common.ProgramNotFoundException) URL(java.net.URL)

Aggregations

ProgramNotFoundException (io.cdap.cdap.common.ProgramNotFoundException)17 HttpResponse (io.cdap.common.http.HttpResponse)11 URL (java.net.URL)10 NotFoundException (io.cdap.cdap.common.NotFoundException)5 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)5 ProgramId (io.cdap.cdap.proto.id.ProgramId)5 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)4 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)4 HttpRequest (io.cdap.common.http.HttpRequest)4 WorkflowSpecification (io.cdap.cdap.api.workflow.WorkflowSpecification)3 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)3 List (java.util.List)3 TypeToken (com.google.common.reflect.TypeToken)2 Inject (com.google.inject.Inject)2 InstanceNotFoundException (io.cdap.cdap.api.dataset.InstanceNotFoundException)2 ScheduleNotFoundException (io.cdap.cdap.internal.app.runtime.schedule.ScheduleNotFoundException)2 ProgramType (io.cdap.cdap.proto.ProgramType)2 WorkflowNodeStateDetail (io.cdap.cdap.proto.WorkflowNodeStateDetail)2 IOException (java.io.IOException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1