use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class RemoteRuntimeStoreHandler method setSuspend.
@POST
@Path("/setSuspend")
public void setSuspend(HttpRequest request, HttpResponder responder) throws Exception {
Iterator<MethodArgument> arguments = parseArguments(request);
ProgramId program = deserializeNext(arguments);
String pid = deserializeNext(arguments);
store.setSuspend(program, pid);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class RemoteRuntimeStoreHandler method setResume.
@POST
@Path("/setResume")
public void setResume(HttpRequest request, HttpResponder responder) throws Exception {
Iterator<MethodArgument> arguments = parseArguments(request);
ProgramId program = deserializeNext(arguments);
String pid = deserializeNext(arguments);
store.setResume(program, pid);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class RemoteUsageRegistryHandler method registerDataset.
@POST
@Path("/registerDataset")
public void registerDataset(HttpRequest request, HttpResponder responder) throws Exception {
Iterator<MethodArgument> arguments = parseArguments(request);
ProgramId programId = deserializeNext(arguments);
DatasetId datasetInstance = deserializeNext(arguments);
usageRegistry.register(programId, datasetInstance);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class ProgramLifecycleService method validateAndCorrectRunningRunRecords.
/**
* Fix all the possible inconsistent states for RunRecords that shows it is in RUNNING state but actually not
* via check to {@link ProgramRuntimeService} for a type of CDAP program.
*
* @param programType The type of program the run records need to validate and update.
* @param processedInvalidRunRecordIds the {@link Set} of processed invalid run record ids.
*/
@VisibleForTesting
void validateAndCorrectRunningRunRecords(final ProgramType programType, final Set<String> processedInvalidRunRecordIds) {
final Map<RunId, RuntimeInfo> runIdToRuntimeInfo = runtimeService.list(programType);
LOG.trace("Start getting run records not actually running ...");
Collection<RunRecordMeta> notActuallyRunning = store.getRuns(ProgramRunStatus.RUNNING, new com.google.common.base.Predicate<RunRecordMeta>() {
@Override
public boolean apply(RunRecordMeta input) {
String runId = input.getPid();
// Check if it is not actually running.
return !runIdToRuntimeInfo.containsKey(RunIds.fromString(runId));
}
}).values();
LOG.trace("End getting {} run records not actually running.", notActuallyRunning.size());
final Map<String, ProgramId> runIdToProgramId = new HashMap<>();
LOG.trace("Start getting invalid run records ...");
Collection<RunRecordMeta> invalidRunRecords = Collections2.filter(notActuallyRunning, new com.google.common.base.Predicate<RunRecordMeta>() {
@Override
public boolean apply(RunRecordMeta input) {
String runId = input.getPid();
// check for program Id for the run record, if null then it is invalid program type.
ProgramId targetProgramId = retrieveProgramIdForRunRecord(programType, runId);
// Check if run id is for the right program type
if (targetProgramId != null) {
runIdToProgramId.put(runId, targetProgramId);
return true;
} else {
return false;
}
}
});
// don't correct run records for programs running inside a workflow
// for instance, a MapReduce running in a Workflow will not be contained in the runtime info in this class
invalidRunRecords = Collections2.filter(invalidRunRecords, new com.google.common.base.Predicate<RunRecordMeta>() {
@Override
public boolean apply(RunRecordMeta invalidRunRecordMeta) {
boolean shouldCorrect = shouldCorrectForWorkflowChildren(invalidRunRecordMeta, processedInvalidRunRecordIds);
if (!shouldCorrect) {
LOG.trace("Will not correct invalid run record {} since it's parent workflow still running.", invalidRunRecordMeta);
return false;
}
return true;
}
});
LOG.trace("End getting invalid run records.");
if (!invalidRunRecords.isEmpty()) {
LOG.warn("Found {} RunRecords with RUNNING status and the program not actually running for program type {}", invalidRunRecords.size(), programType.getPrettyName());
} else {
LOG.trace("No RunRecords found with RUNNING status and the program not actually running for program type {}", programType.getPrettyName());
}
// Now lets correct the invalid RunRecords
for (RunRecordMeta invalidRunRecordMeta : invalidRunRecords) {
String runId = invalidRunRecordMeta.getPid();
ProgramId targetProgramId = runIdToProgramId.get(runId);
boolean updated = store.compareAndSetStatus(targetProgramId, runId, ProgramController.State.ALIVE.getRunStatus(), ProgramController.State.ERROR.getRunStatus());
if (updated) {
LOG.warn("Fixed RunRecord {} for program {} with RUNNING status because the program was not " + "actually running", runId, targetProgramId);
processedInvalidRunRecordIds.add(runId);
}
}
}
use of co.cask.cdap.proto.id.ProgramId in project cdap by caskdata.
the class ProgramLifecycleService method retrieveProgramIdForRunRecord.
/**
* Helper method to get {@link ProgramId} for a RunRecord for type of program
*
* @param programType Type of program to search
* @param runId The target id of the {@link RunRecord} to find
* @return the program id of the run record or {@code null} if does not exist.
*/
@Nullable
private ProgramId retrieveProgramIdForRunRecord(ProgramType programType, String runId) {
// Get list of namespaces (borrow logic from AbstractAppFabricHttpHandler#listPrograms)
List<NamespaceMeta> namespaceMetas = nsStore.list();
// For each, get all programs under it
ProgramId targetProgramId = null;
for (NamespaceMeta nm : namespaceMetas) {
NamespaceId namespace = Ids.namespace(nm.getName());
Collection<ApplicationSpecification> appSpecs = store.getAllApplications(namespace);
// For each application get the programs checked against run records
for (ApplicationSpecification appSpec : appSpecs) {
switch(programType) {
case FLOW:
for (String programName : appSpec.getFlows().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case MAPREDUCE:
for (String programName : appSpec.getMapReduce().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case SPARK:
for (String programName : appSpec.getSpark().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case SERVICE:
for (String programName : appSpec.getServices().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case WORKER:
for (String programName : appSpec.getWorkers().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case WORKFLOW:
for (String programName : appSpec.getWorkflows().keySet()) {
ProgramId programId = validateProgramForRunRecord(nm.getName(), appSpec.getName(), appSpec.getAppVersion(), programType, programName, runId);
if (programId != null) {
targetProgramId = programId;
break;
}
}
break;
case CUSTOM_ACTION:
case WEBAPP:
// no-op
break;
default:
LOG.debug("Unknown program type: " + programType.name());
break;
}
if (targetProgramId != null) {
break;
}
}
if (targetProgramId != null) {
break;
}
}
return targetProgramId;
}
Aggregations