Search in sources :

Example 41 with ProfileId

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);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 42 with ProfileId

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);
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 43 with ProfileId

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;
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ArrayList(java.util.ArrayList) Profile(io.cdap.cdap.proto.profile.Profile)

Example 44 with ProfileId

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)));
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 45 with 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;
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) ProgramRunCluster(io.cdap.cdap.proto.ProgramRunCluster) Nullable(javax.annotation.Nullable)

Aggregations

ProfileId (io.cdap.cdap.proto.id.ProfileId)112 Test (org.junit.Test)68 Profile (io.cdap.cdap.proto.profile.Profile)50 ProgramId (io.cdap.cdap.proto.id.ProgramId)26 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)26 Path (javax.ws.rs.Path)22 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)16 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)14 HashMap (java.util.HashMap)14 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)12 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)12 MetricStore (io.cdap.cdap.api.metrics.MetricStore)10 NotFoundException (io.cdap.cdap.common.NotFoundException)10 ProgramSchedule (io.cdap.cdap.internal.app.runtime.schedule.ProgramSchedule)10 ProfileService (io.cdap.cdap.internal.profile.ProfileService)10 ArrayList (java.util.ArrayList)10 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)8 ScheduleId (io.cdap.cdap.proto.id.ScheduleId)8 POST (javax.ws.rs.POST)8 Store (io.cdap.cdap.app.store.Store)6