use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class ProfileHttpHandlerTest method testEnableDisableProfile.
@Test
public void testEnableDisableProfile() throws Exception {
Profile expected = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo(MockProvisioner.NAME, PROPERTY_SUMMARIES));
ProfileId profileId = NamespaceId.DEFAULT.profile(expected.getName());
// enable and disable a non-existing profile should give a 404
enableProfile(profileId, HttpURLConnection.HTTP_NOT_FOUND);
disableProfile(profileId, HttpURLConnection.HTTP_NOT_FOUND);
// put the profile
putProfile(profileId, expected, HttpURLConnection.HTTP_OK);
// by default the status should be enabled
Assert.assertEquals(ProfileStatus.ENABLED, getProfileStatus(profileId, HttpURLConnection.HTTP_OK).get());
// enable it again should give a 409
enableProfile(profileId, HttpURLConnection.HTTP_CONFLICT);
// disable should work
disableProfile(profileId, HttpURLConnection.HTTP_OK);
Assert.assertEquals(ProfileStatus.DISABLED, getProfileStatus(profileId, HttpURLConnection.HTTP_OK).get());
// disable again should give a 409
disableProfile(profileId, HttpURLConnection.HTTP_CONFLICT);
// enable should work
enableProfile(profileId, HttpURLConnection.HTTP_OK);
Assert.assertEquals(ProfileStatus.ENABLED, getProfileStatus(profileId, HttpURLConnection.HTTP_OK).get());
// now delete should not work since we have the profile enabled
deleteProfile(profileId, HttpURLConnection.HTTP_CONFLICT);
// disable and delete
disableProfile(profileId, HttpURLConnection.HTTP_OK);
deleteProfile(profileId, HttpURLConnection.HTTP_OK);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class AppFabricTestBase method getSystemProfile.
protected Optional<Profile> getSystemProfile(String profileName, int expectedCode) throws Exception {
HttpResponse response = doGet(String.format("/v3/profiles/%s", profileName));
assertResponseCode(expectedCode, response);
if (expectedCode == HttpResponseStatus.OK.code()) {
return Optional.of(GSON.fromJson(response.getResponseBodyAsString(), Profile.class));
}
return Optional.empty();
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class CoreSchedulerServiceTest method testAddScheduleWithDisabledProfile.
@Test
public void testAddScheduleWithDisabledProfile() throws Exception {
// put my profile and by default it is enabled
ProfileId profileId = NS_ID.profile("MyProfile");
Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
putProfile(profileId, profile, 200);
// add a schedule, it should succeed since the profile is enabled.
ProgramSchedule tsched1 = new ProgramSchedule("tsched1", "one time schedule", PROG1_ID, ImmutableMap.of("prop1", "nn", SystemArguments.PROFILE_NAME, "USER:MyProfile"), new TimeTrigger("* * ? * 1"), ImmutableList.<Constraint>of());
scheduler.addSchedule(tsched1);
Assert.assertEquals(Collections.singletonList(tsched1), scheduler.listSchedules(PROG1_ID));
// now disable the profile
disableProfile(profileId, 200);
// delete it
scheduler.deleteSchedule(TSCHED1_ID);
Assert.assertEquals(Collections.emptyList(), scheduler.listSchedules(PROG1_ID));
// add it again should also fail since the profile is disabled
try {
scheduler.addSchedule(tsched1);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
// clean up
deleteProfile(profileId, 200);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class MetadataSubscriberServiceTest method testProfileMetadataWithNoProfilePreferences.
@Test
public void testProfileMetadataWithNoProfilePreferences() throws Exception {
Injector injector = getInjector();
// add a new profile in default namespace
ProfileService profileService = injector.getInstance(ProfileService.class);
ProfileId myProfile = new ProfileId(NamespaceId.DEFAULT.getNamespace(), "MyProfile");
Profile profile1 = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
profileService.saveProfile(myProfile, profile1);
// add a app with workflow to app meta store
ApplicationSpecification appSpec = Specifications.from(new AppWithWorkflow());
ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName());
ProgramId workflowId = appId.workflow("SampleWorkflow");
// get the metadata - should be empty since we haven't deployed the app
MetadataStorage mds = injector.getInstance(MetadataStorage.class);
Assert.assertEquals(Collections.emptyMap(), mds.read(new Read(workflowId.toMetadataEntity())).getProperties());
Store store = injector.getInstance(DefaultStore.class);
store.addApplication(appId, appSpec);
// set default namespace to use the profile, since now MetadataSubscriberService is not started,
// it should not affect the mds
PreferencesService preferencesService = injector.getInstance(PreferencesService.class);
preferencesService.setProperties(NamespaceId.DEFAULT, Collections.singletonMap(SystemArguments.PROFILE_NAME, "USER:MyProfile"));
try {
// Verify the workflow profile metadata is updated to my profile
Tasks.waitFor(myProfile.getScopedName(), () -> getProfileProperty(mds, workflowId), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
// Set the property without profile is a replacement of the preference, so it is same as deletion of the profile
preferencesService.setProperties(NamespaceId.DEFAULT, Collections.emptyMap());
// Verify the workflow profile metadata is updated to default profile
Tasks.waitFor(ProfileId.NATIVE.getScopedName(), () -> getProfileProperty(mds, workflowId), 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
} finally {
// stop and clean up the store
preferencesService.deleteProperties(NamespaceId.DEFAULT);
store.removeAll(NamespaceId.DEFAULT);
profileService.disableProfile(myProfile);
profileService.deleteProfile(myProfile);
mds.apply(new MetadataMutation.Drop(workflowId.toMetadataEntity()), MutationOptions.DEFAULT);
}
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class SystemProfileCreatorTest method testExistingIsUnmodified.
@Test
public void testExistingIsUnmodified() throws Exception {
// write a profile
ProfileId profileId = NamespaceId.SYSTEM.profile("p1");
List<ProvisionerPropertyValue> properties = new ArrayList<>();
properties.add(new ProvisionerPropertyValue("name1", "val1", true));
properties.add(new ProvisionerPropertyValue("name2", "val2", true));
ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, properties);
Profile profile = new Profile(profileId.getProfile(), "profile label", "profile description", EntityScope.SYSTEM, provisionerInfo);
profileService.saveProfile(profileId, profile);
// run the bootstrap step and make sure it succeeded
SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments(profile.getName(), "different label", "different desciption", profile.getProvisioner());
BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject());
BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED);
Assert.assertEquals(expected, result);
// check that it didn't overwrite the existing profile
Assert.assertEquals(profile, profileService.getProfile(profileId));
}
Aggregations