use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testDeployAppWithDisabledProfileInSchedule.
@Test
public void testDeployAppWithDisabledProfileInSchedule() throws Exception {
// put my profile and disable it
ProfileId profileId = new NamespaceId(TEST_NAMESPACE1).profile("MyProfile");
Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
putProfile(profileId, profile, 200);
disableProfile(profileId, 200);
// deploy an app with schedule with some disabled profile in the schedule property
AppWithSchedule.AppConfig config = new AppWithSchedule.AppConfig(true, true, true, ImmutableMap.of(SystemArguments.PROFILE_NAME, "USER:MyProfile"));
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.fromEntityId(TEST_NAMESPACE_META1.getNamespaceId()), AppWithSchedule.NAME, VERSION1);
addAppArtifact(artifactId, AppWithSchedule.class);
AppRequest<? extends Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config, null, null, true);
// deploy should fail with a 409
ApplicationId defaultAppId = TEST_NAMESPACE_META1.getNamespaceId().app(AppWithSchedule.NAME);
Assert.assertEquals(409, deploy(defaultAppId, request).getResponseCode());
// enable
enableProfile(profileId, 200);
Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
// disable again so that we can delete it at namespace deletion
disableProfile(profileId, 200);
// clean up
deleteApp(defaultAppId, 200);
deleteArtifact(artifactId, 200);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class ProfileHttpHandler method getProfiles.
/**
* List the profiles in the given namespace. By default the results will not contain profiles in system scope.
*/
@GET
@Path("/namespaces/{namespace-id}/profiles")
public void getProfiles(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @QueryParam("includeSystem") @DefaultValue("false") String includeSystem) throws Exception {
NamespaceId namespace = getValidatedNamespace(namespaceId);
accessEnforcer.enforceOnParent(EntityType.PROFILE, namespace, authenticationContext.getPrincipal(), StandardPermission.LIST);
boolean include = Boolean.valueOf(includeSystem);
if (include) {
accessEnforcer.enforceOnParent(EntityType.PROFILE, NamespaceId.SYSTEM, authenticationContext.getPrincipal(), StandardPermission.LIST);
}
List<Profile> profiles = verifyCpuLabelsProfiles(profileService.getProfiles(namespace, include), namespace);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(profiles));
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class ProfileHttpHandler method getSystemProfiles.
@GET
@Path("/profiles")
public void getSystemProfiles(HttpRequest request, HttpResponder responder) throws Exception {
NamespaceId namespaceId = NamespaceId.SYSTEM;
accessEnforcer.enforceOnParent(EntityType.PROFILE, namespaceId, authenticationContext.getPrincipal(), StandardPermission.LIST);
List<Profile> profiles = verifyCpuLabelsProfiles(profileService.getProfiles(namespaceId, true), NamespaceId.SYSTEM);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(profiles));
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
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 cdapio.
the class ProfileService method deleteProfile.
/**
* Deletes the profile from the profile store. Native profile cannot be deleted.
* Other profile deletion must satisfy the following:
* 1. Profile must exist and must be DISABLED
* 2. Profile must not be assigned to any entities. Profiles can be assigned to an entity by setting a preference
* or a schedule property.
* 3. There must be no active program runs using this profile
*
* @param profileId the id of the profile to delete
* @throws NotFoundException if the profile is not found
* @throws ProfileConflictException if the profile is enabled
* @throws MethodNotAllowedException if trying to delete the Native profile
*/
public void deleteProfile(ProfileId profileId) throws MethodNotAllowedException, NotFoundException, ProfileConflictException {
if (profileId.equals(ProfileId.NATIVE)) {
throw new MethodNotAllowedException(String.format("Profile Native %s cannot be deleted.", profileId.getScopedName()));
}
TransactionRunners.run(transactionRunner, context -> {
ProfileStore profileStore = ProfileStore.get(context);
Profile profile = profileStore.getProfile(profileId);
AppMetadataStore appMetadataStore = AppMetadataStore.create(context);
deleteProfile(profileStore, appMetadataStore, profileId, profile);
}, NotFoundException.class, ProfileConflictException.class);
deleteMetrics(profileId);
}
Aggregations