Search in sources :

Example 51 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class ProfileStore method addProfileAssignment.

/**
 * Add an assignment to the profile. Assignment can only be added if the profile is ENABLED
 *
 * @param profileId the profile id
 * @param entityId the entity to add to the assgiment
 */
public void addProfileAssignment(ProfileId profileId, EntityId entityId) throws ProfileConflictException, NotFoundException, IOException {
    Collection<Field<?>> fields = getProfileKeys(profileId);
    Profile profile = getProfileInternal(fields);
    if (profile == null) {
        throw new NotFoundException(profileId);
    }
    if (profile.getStatus() == ProfileStatus.DISABLED) {
        throw new ProfileConflictException(String.format("Profile %s is DISABLED. No entity can be assigned to it.", profileId.getProfile()), profileId);
    }
    addEntityIdKey(fields, entityId);
    fields.add(Fields.stringField(StoreDefinition.ProfileStore.ENTITY_DATA_FIELD, GSON.toJson(entityId)));
    profileEntityTable.upsert(fields);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) TableNotFoundException(io.cdap.cdap.spi.data.TableNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) Profile(io.cdap.cdap.proto.profile.Profile)

Example 52 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class ProfileStore method changeProfileStatus.

private void changeProfileStatus(ProfileId profileId, ProfileStatus expectedStatus) throws NotFoundException, ProfileConflictException, IOException {
    Collection<Field<?>> fields = getProfileKeys(profileId);
    Profile oldProfile = getProfileInternal(fields);
    if (oldProfile == null) {
        throw new NotFoundException(profileId);
    }
    if (oldProfile.getStatus() == expectedStatus) {
        throw new ProfileConflictException(String.format("Profile %s already %s", profileId.getProfile(), expectedStatus.toString()), profileId);
    }
    Profile newProfile = new Profile(oldProfile.getName(), oldProfile.getLabel(), oldProfile.getDescription(), oldProfile.getScope(), expectedStatus, oldProfile.getProvisioner(), oldProfile.getCreatedTsSeconds());
    fields.add(Fields.stringField(StoreDefinition.ProfileStore.PROFILE_DATA_FIELD, GSON.toJson(newProfile)));
    profileTable.upsert(fields);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) TableNotFoundException(io.cdap.cdap.spi.data.TableNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProfileConflictException(io.cdap.cdap.common.ProfileConflictException) Profile(io.cdap.cdap.proto.profile.Profile)

Example 53 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

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 54 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class ProfileHttpHandler method writeProfile.

private void writeProfile(ProfileId profileId, FullHttpRequest request) throws BadRequestException, IOException, MethodNotAllowedException {
    ProfileCreateRequest profileCreateRequest;
    try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) {
        profileCreateRequest = GSON.fromJson(reader, ProfileCreateRequest.class);
        validateProvisionerProperties(profileCreateRequest);
    } catch (JsonSyntaxException e) {
        throw new BadRequestException("Unable to parse request body. Please make sure it is valid JSON", e);
    }
    String totalProcessingCpusLabel = getTotalProcessingCpusLabel(profileCreateRequest.getProvisioner());
    profileCreateRequest.getProvisioner().setTotalProcessingCpusLabel(totalProcessingCpusLabel);
    Profile profile = new Profile(profileId.getProfile(), profileCreateRequest.getLabel(), profileCreateRequest.getDescription(), profileId.getScope(), profileCreateRequest.getProvisioner());
    profileService.saveProfile(profileId, profile);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) ProfileCreateRequest(io.cdap.cdap.proto.profile.ProfileCreateRequest) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BadRequestException(io.cdap.cdap.common.BadRequestException) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) Profile(io.cdap.cdap.proto.profile.Profile)

Example 55 with Profile

use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.

the class AppFabricTestBase method getProfile.

protected Optional<Profile> getProfile(ProfileId profileId, int expectedCode) throws Exception {
    HttpResponse response = doGet(String.format("/v3/namespaces/%s/profiles/%s", profileId.getNamespace(), profileId.getProfile()));
    assertResponseCode(expectedCode, response);
    if (expectedCode == HttpResponseStatus.OK.code()) {
        return Optional.of(GSON.fromJson(response.getResponseBodyAsString(), Profile.class));
    }
    return Optional.empty();
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) Profile(io.cdap.cdap.proto.profile.Profile)

Aggregations

Profile (io.cdap.cdap.proto.profile.Profile)86 ProfileId (io.cdap.cdap.proto.id.ProfileId)50 Test (org.junit.Test)48 ProvisionerInfo (io.cdap.cdap.proto.provisioner.ProvisionerInfo)32 NotFoundException (io.cdap.cdap.common.NotFoundException)16 ProfileConflictException (io.cdap.cdap.common.ProfileConflictException)14 ProgramId (io.cdap.cdap.proto.id.ProgramId)14 Field (io.cdap.cdap.spi.data.table.field.Field)14 ArrayList (java.util.ArrayList)14 ProvisionerPropertyValue (io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue)10 TableNotFoundException (io.cdap.cdap.spi.data.TableNotFoundException)10 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)8 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)8 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)6 Store (io.cdap.cdap.app.store.Store)6 DefaultStore (io.cdap.cdap.internal.app.store.DefaultStore)6 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)6 Injector (com.google.inject.Injector)4