Search in sources :

Example 11 with Profile

use of io.cdap.cdap.proto.profile.Profile 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));
}
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 12 with Profile

use of io.cdap.cdap.proto.profile.Profile 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);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) TableNotFoundException(io.cdap.cdap.spi.data.TableNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) Profile(io.cdap.cdap.proto.profile.Profile)

Example 13 with Profile

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

the class ProfileService method deleteAllProfiles.

/**
 * Delete all profiles in a given namespace. Deleting all profiles in SYSTEM namespace is not allowed.
 *
 * @param namespaceId the id of the namespace
 */
public void deleteAllProfiles(NamespaceId namespaceId) throws MethodNotAllowedException, NotFoundException, ProfileConflictException {
    if (namespaceId.equals(NamespaceId.SYSTEM)) {
        throw new MethodNotAllowedException("Deleting all system profiles is not allowed.");
    }
    List<ProfileId> deleted = new ArrayList<>();
    TransactionRunners.run(transactionRunner, context -> {
        ProfileStore profileStore = ProfileStore.get(context);
        AppMetadataStore appMetadataStore = AppMetadataStore.create(context);
        List<Profile> profiles = profileStore.getProfiles(namespaceId, false);
        for (Profile profile : profiles) {
            ProfileId profileId = namespaceId.profile(profile.getName());
            deleteProfile(profileStore, appMetadataStore, profileId, profile);
            deleted.add(profileId);
        }
    }, ProfileConflictException.class, NotFoundException.class);
    // delete the metrics
    for (ProfileId profileId : deleted) {
        deleteMetrics(profileId);
    }
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) MethodNotAllowedException(io.cdap.cdap.common.MethodNotAllowedException) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) ArrayList(java.util.ArrayList) ProfileStore(io.cdap.cdap.internal.app.store.profile.ProfileStore) Profile(io.cdap.cdap.proto.profile.Profile)

Example 14 with Profile

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

the class ProfileService method getProfile.

/**
 * Get the profile information about the given profile with property overrides. If a non-editable property is
 * in the overrides, it will be ignored, but a message will be logged.
 *
 * @param profileId the id of the profile to look up
 * @param overrides overrides to the profile properties
 * @return the profile information about the given profile
 * @throws NotFoundException if the profile is not found
 */
public Profile getProfile(ProfileId profileId, Map<String, String> overrides) throws NotFoundException {
    Profile storedProfile = getProfile(profileId);
    List<ProvisionerPropertyValue> properties = new ArrayList<>();
    Set<String> remainingOverrides = new HashSet<>(overrides.keySet());
    // add all  properties from the stored profile
    for (ProvisionerPropertyValue storedProperty : storedProfile.getProvisioner().getProperties()) {
        String propertyName = storedProperty.getName();
        String storedVal = storedProperty.getValue();
        if (!storedProperty.isEditable()) {
            if (overrides.containsKey(propertyName)) {
                LOG.info("Profile property {} cannot be edited. The original value will be used.", propertyName);
            }
            properties.add(storedProperty);
        } else {
            String val = overrides.getOrDefault(propertyName, storedVal);
            properties.add(new ProvisionerPropertyValue(propertyName, val, true));
        }
        remainingOverrides.remove(propertyName);
    }
    // add all remaining overrides
    for (String propertyName : remainingOverrides) {
        properties.add(new ProvisionerPropertyValue(propertyName, overrides.get(propertyName), true));
    }
    ProvisionerInfo provisionerInfo = new ProvisionerInfo(storedProfile.getProvisioner().getName(), properties);
    return new Profile(storedProfile.getName(), storedProfile.getLabel(), storedProfile.getDescription(), storedProfile.getScope(), storedProfile.getStatus(), provisionerInfo, storedProfile.getCreatedTsSeconds());
}
Also used : ProvisionerPropertyValue(io.cdap.cdap.proto.provisioner.ProvisionerPropertyValue) ProvisionerInfo(io.cdap.cdap.proto.provisioner.ProvisionerInfo) ArrayList(java.util.ArrayList) Profile(io.cdap.cdap.proto.profile.Profile) HashSet(java.util.HashSet)

Example 15 with Profile

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

the class ProvisioningServiceTest method createTaskInfo.

private TaskFields createTaskInfo(ProvisionerInfo provisionerInfo) {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").workflow("wf").run(RunIds.generate());
    Map<String, String> systemArgs = new HashMap<>();
    Map<String, String> userArgs = new HashMap<>();
    Profile profile = new Profile(ProfileId.NATIVE.getProfile(), "label", "desc", provisionerInfo);
    SystemArguments.addProfileArgs(systemArgs, profile);
    systemArgs.put(Constants.APP_CDAP_VERSION, APP_CDAP_VERSION);
    ProgramOptions programOptions = new SimpleProgramOptions(programRunId.getParent(), new BasicArguments(systemArgs), new BasicArguments(userArgs));
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
    ApplicationSpecification appSpec = new DefaultApplicationSpecification("name", "1.0.0", APP_CDAP_VERSION, "desc", null, artifactId, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
    ProgramDescriptor programDescriptor = new ProgramDescriptor(programRunId.getParent(), appSpec);
    return new TaskFields(programDescriptor, programOptions, programRunId);
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HashMap(java.util.HashMap) Profile(io.cdap.cdap.proto.profile.Profile) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor)

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