use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class ProfileHttpHandler method disableProfile.
/**
* Disable the profile, so that no new program runs can use it,
* and no new schedules/programs can be assigned to it.
*/
@POST
@Path("/namespaces/{namespace-id}/profiles/{profile-name}/disable")
public void disableProfile(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("profile-name") String profileName) throws Exception {
ProfileId profileId = getValidatedProfile(namespaceId, profileName);
accessEnforcer.enforce(profileId, authenticationContext.getPrincipal(), StandardPermission.UPDATE);
profileService.disableProfile(profileId);
responder.sendStatus(HttpResponseStatus.OK);
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class ProfileHttpHandler method enableSystemProfile.
@POST
@Path("/profiles/{profile-name}/enable")
public void enableSystemProfile(HttpRequest request, HttpResponder responder, @PathParam("profile-name") String profileName) throws Exception {
ProfileId profileId = getValidatedProfile(NamespaceId.SYSTEM, profileName);
accessEnforcer.enforce(profileId, authenticationContext.getPrincipal(), StandardPermission.UPDATE);
profileService.enableProfile(profileId);
responder.sendStatus(HttpResponseStatus.OK);
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class ProfileHttpHandler method verifyCpuLabelsProfiles.
private List<Profile> verifyCpuLabelsProfiles(List<Profile> profileList, NamespaceId namespaceId) throws BadRequestException, MethodNotAllowedException {
List<Profile> verifiedProfiles = new ArrayList<>();
for (Profile profile : profileList) {
ProfileId profileId = getValidatedProfile(namespaceId, profile.getName());
verifiedProfiles.add(verifyCpuLabelsProfile(profile, profileId));
}
return verifiedProfiles;
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class ProfileHttpHandler method getSystemProfile.
@GET
@Path("/profiles/{profile-name}")
public void getSystemProfile(HttpRequest request, HttpResponder responder, @PathParam("profile-name") String profileName) throws Exception {
ProfileId profileId = getValidatedProfile(NamespaceId.SYSTEM, profileName);
accessEnforcer.enforce(profileId, authenticationContext.getPrincipal(), StandardPermission.GET);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(verifyCpuLabelsProfile(profileService.getProfile(profileId), profileId)));
}
use of io.cdap.cdap.proto.id.ProfileId in project cdap by cdapio.
the class AppMetadataStore method recordProgramProvisioning.
/**
* Record that the program run is provisioning compute resources for the run. If the current status has
* a higher source id, this call will be ignored.
*
* @param programRunId program run
* @param runtimeArgs runtime arguments
* @param systemArgs system arguments
* @param sourceId unique id representing the source of program run status, such as the message id of the program
* run status notification in TMS. The source id must increase as the recording time of the program
* run status increases, so that the attempt to persist program run status older than the existing
* program run status will be ignored
* @param artifactId artifact id of the program's application -
* its null only for older messages that were not processed before upgrading to 5.0
* @return {@link ProgramRunClusterStatus#PROVISIONING} if it is successfully persisted, {@code null} otherwise.
*/
@Nullable
public RunRecordDetail recordProgramProvisioning(ProgramRunId programRunId, Map<String, String> runtimeArgs, Map<String, String> systemArgs, byte[] sourceId, @Nullable ArtifactId artifactId) throws IOException {
long startTs = RunIds.getTime(programRunId.getRun(), TimeUnit.SECONDS);
if (startTs == -1L) {
LOG.error("Ignoring unexpected request to record provisioning state for program run {} that does not have " + "a timestamp in the run id.", programRunId);
return null;
}
RunRecordDetail existing = getRun(programRunId);
// for some reason, there is an existing run record.
if (existing != null) {
LOG.error("Ignoring unexpected request to record provisioning state for program run {} that has an existing " + "run record in run state {} and cluster state {}.", programRunId, existing.getStatus(), existing.getCluster().getStatus());
return null;
}
Optional<ProfileId> profileId = SystemArguments.getProfileIdFromArgs(programRunId.getNamespaceId(), systemArgs);
if (!profileId.isPresent()) {
LOG.error("Ignoring unexpected request to record provisioning state for program run {} that does not have " + "a profile assigned to it.", programRunId);
return null;
}
ProgramRunCluster cluster = new ProgramRunCluster(ProgramRunClusterStatus.PROVISIONING, null, null);
RunRecordDetail meta = RunRecordDetail.builder().setProgramRunId(programRunId).setStartTime(startTs).setStatus(ProgramRunStatus.PENDING).setProperties(getRecordProperties(systemArgs, runtimeArgs)).setSystemArgs(systemArgs).setCluster(cluster).setProfileId(profileId.get()).setPeerName(systemArgs.get(ProgramOptionConstants.PEER_NAME)).setSourceId(sourceId).setArtifactId(artifactId).setPrincipal(systemArgs.get(ProgramOptionConstants.PRINCIPAL)).build();
writeNewRunRecord(meta, TYPE_RUN_RECORD_ACTIVE);
LOG.trace("Recorded {} for program {}", ProgramRunClusterStatus.PROVISIONING, programRunId);
return meta;
}
Aggregations