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));
}
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);
}
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);
}
}
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());
}
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);
}
Aggregations