use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class AppMetadataStore method addWorkflowNodeState.
private void addWorkflowNodeState(ProgramRunId programRunId, Map<String, String> systemArgs, ProgramRunStatus status, @Nullable BasicThrowable failureCause, byte[] sourceId) throws IOException {
String workflowNodeId = systemArgs.get(ProgramOptionConstants.WORKFLOW_NODE_ID);
String workflowName = systemArgs.get(ProgramOptionConstants.WORKFLOW_NAME);
String workflowRun = systemArgs.get(ProgramOptionConstants.WORKFLOW_RUN_ID);
ApplicationId appId = programRunId.getParent().getParent();
ProgramRunId workflowRunId = appId.workflow(workflowName).run(workflowRun);
// Get the run record of the Workflow which started this program
List<Field<?>> runRecordFields = getProgramRunInvertedTimeKey(TYPE_RUN_RECORD_ACTIVE, workflowRunId, RunIds.getTime(workflowRun, TimeUnit.SECONDS));
RunRecordDetail record = getRunRecordsTable().read(runRecordFields).map(AppMetadataStore::deserializeRunRecordMeta).orElse(null);
// If the workflow is gone, just ignore the update
if (record == null) {
return;
}
List<Field<?>> primaryKeys = getWorkflowPrimaryKeys(workflowRunId, workflowNodeId);
WorkflowNodeStateDetail nodeState = getWorkflowNodeStateTable().read(primaryKeys).map(r -> r.getString(StoreDefinition.AppMetadataStore.NODE_STATE_DATA)).map(f -> GSON.fromJson(f, WorkflowNodeStateDetail.class)).orElse(null);
// - the program runId is the same as the existing workflow state
if (status == ProgramRunStatus.STARTING || nodeState == null || programRunId.getRun().equals(nodeState.getRunId())) {
WorkflowNodeStateDetail nodeStateDetail = new WorkflowNodeStateDetail(workflowNodeId, ProgramRunStatus.toNodeStatus(status), programRunId.getRun(), failureCause);
writeToStructuredTableWithPrimaryKeys(primaryKeys, nodeStateDetail, getWorkflowNodeStateTable(), StoreDefinition.AppMetadataStore.NODE_STATE_DATA);
// Update the parent Workflow run record by adding node id and program run id in the properties
Map<String, String> properties = new HashMap<>(record.getProperties());
properties.put(workflowNodeId, programRunId.getRun());
writeToRunRecordTableWithPrimaryKeys(runRecordFields, RunRecordDetail.builder(record).setProperties(properties).setSourceId(sourceId).build());
}
}
use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class AppMetadataStore method getCompletedRuns.
private Map<ProgramRunId, RunRecordDetail> getCompletedRuns(Set<ProgramRunId> programRunIds) throws IOException {
List<List<Field<?>>> allKeys = new ArrayList<>();
for (ProgramRunId programRunId : programRunIds) {
List<Field<?>> keys = getRunRecordProgramPrefix(TYPE_RUN_RECORD_COMPLETED, programRunId.getParent());
// Get start time from RunId
long programStartSecs = RunIds.getTime(RunIds.fromString(programRunId.getRun()), TimeUnit.SECONDS);
keys.add(Fields.longField(StoreDefinition.AppMetadataStore.RUN_START_TIME, getInvertedTsKeyPart(programStartSecs)));
keys.add(Fields.stringField(StoreDefinition.AppMetadataStore.RUN_FIELD, programRunId.getRun()));
allKeys.add(keys);
}
return getRunRecordsTable().multiRead(allKeys).stream().map(AppMetadataStore::deserializeRunRecordMeta).collect(Collectors.toMap(RunRecordDetail::getProgramRunId, r -> r, (r1, r2) -> {
throw new IllegalStateException("Duplicate run record for " + r1.getProgramRunId());
}, LinkedHashMap::new));
}
use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class ProfileStore method saveProfile.
/**
* Save the profile to the profile store. By default the profile status will be enabled.
*
* @param profileId the id of the profile to save
* @param profile the information of the profile
*/
public void saveProfile(ProfileId profileId, Profile profile) throws IOException {
Collection<Field<?>> fields = getProfileKeys(profileId);
Profile oldProfile = getProfileInternal(fields);
Profile newProfile = new Profile(profile.getName(), profile.getLabel(), profile.getDescription(), profile.getScope(), oldProfile == null ? ProfileStatus.ENABLED : oldProfile.getStatus(), profile.getProvisioner(), oldProfile == null ? profile.getCreatedTsSeconds() : oldProfile.getCreatedTsSeconds());
fields.add(Fields.stringField(StoreDefinition.ProfileStore.PROFILE_DATA_FIELD, GSON.toJson(newProfile)));
profileTable.upsert(fields);
}
use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class ProfileStore method deleteProfile.
/**
* Deletes the profile from the profile store
*
* @param profileId the id of the profile to delete
* @throws NotFoundException if the profile is not found
* @throws ProfileConflictException if the profile is enabled
*/
public void deleteProfile(ProfileId profileId) throws NotFoundException, ProfileConflictException, IOException {
Collection<Field<?>> fields = getProfileKeys(profileId);
Profile value = getProfileInternal(fields);
if (value == null) {
throw new NotFoundException(profileId);
}
if (value.getStatus() == ProfileStatus.ENABLED) {
throw new ProfileConflictException(String.format("Profile %s in namespace %s is currently enabled. A profile can " + "only be deleted if it is disabled", profileId.getProfile(), profileId.getNamespace()), profileId);
}
profileTable.delete(getProfileKeys(profileId));
}
use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class ProfileStore method removeProfileAssignment.
/**
* Remove an assignment from the profile.
*
* @param profileId the profile id
* @param entityId the entity to remove from the assignment
* @throws NotFoundException if the profile is not found
*/
public void removeProfileAssignment(ProfileId profileId, EntityId entityId) throws NotFoundException, IOException {
Collection<Field<?>> keys = getProfileKeys(profileId);
Profile profile = getProfileInternal(keys);
if (profile == null) {
throw new NotFoundException(profileId);
}
addEntityIdKey(keys, entityId);
profileEntityTable.delete(keys);
}
Aggregations