use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class ProfileServiceTest method testProfileService.
@Test
public void testProfileService() throws Exception {
// get non-existing profile
try {
profileService.getProfile(NamespaceId.DEFAULT.profile("nonExisting"));
Assert.fail();
} catch (NotFoundException e) {
// expected
}
// delete non-existing profile
try {
profileService.deleteProfile(NamespaceId.DEFAULT.profile("nonExisting"));
Assert.fail();
} catch (NotFoundException e) {
// expected
}
ProfileId profileId = NamespaceId.DEFAULT.profile("MyProfile");
Profile expected = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES));
// add a profile
profileService.saveProfile(profileId, expected);
// get the profile
Assert.assertEquals(expected, profileService.getProfile(profileId));
// add a profile which already exists, should succeed and the profile property should be updated
expected = new Profile("MyProfile", "label", "my 2nd profile for updating", new ProvisionerInfo("anotherProvisioner", Collections.emptyList()));
profileService.saveProfile(profileId, expected);
Assert.assertEquals(expected, profileService.getProfile(profileId));
// add another profile to default namespace
ProfileId profileId2 = NamespaceId.DEFAULT.profile("MyProfile2");
Profile profile2 = new Profile("MyProfile2", "label", "my 2nd profile for testing", new ProvisionerInfo("anotherProvisioner", PROPERTY_SUMMARIES));
profileService.saveProfile(profileId2, profile2);
// add default profile
profileService.saveProfile(ProfileId.NATIVE, Profile.NATIVE);
// get all profiles
List<Profile> profiles = ImmutableList.of(expected, profile2, Profile.NATIVE);
Assert.assertEquals(profiles, profileService.getProfiles(NamespaceId.DEFAULT, true));
// by default the profile status should be enabled
Assert.assertEquals(ProfileStatus.ENABLED, profileService.getProfile(profileId).getStatus());
Assert.assertEquals(ProfileStatus.ENABLED, profileService.getProfile(profileId2).getStatus());
// by default the profile will be enabled, so enable it will throw a ProfileConflictException
try {
profileService.enableProfile(profileId);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
// disable the profile should success
profileService.disableProfile(profileId);
// check the profile status to the disabled
Assert.assertEquals(ProfileStatus.DISABLED, profileService.getProfile(profileId).getStatus());
// disable again should throw ProfileConflictException
try {
profileService.disableProfile(profileId);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
// enable should work this time
profileService.enableProfile(profileId);
Assert.assertEquals(ProfileStatus.ENABLED, profileService.getProfile(profileId).getStatus());
// delete the second profile should fail since it is enabled
try {
profileService.deleteProfile(profileId2);
Assert.fail();
} catch (ProfileConflictException e) {
// expected
}
profileService.disableProfile(profileId2);
profileService.deleteProfile(profileId2);
Assert.assertEquals(ImmutableList.of(expected), profileService.getProfiles(NamespaceId.DEFAULT, false));
// add one and delete all profiles
profileService.saveProfile(profileId2, profile2);
profileService.disableProfile(profileId);
profileService.disableProfile(profileId2);
profileService.deleteAllProfiles(NamespaceId.DEFAULT);
Assert.assertEquals(Collections.EMPTY_LIST, profileService.getProfiles(NamespaceId.DEFAULT, false));
// try to enable and disable an non-existing profile should throw NotFoundException
try {
profileService.enableProfile(profileId);
Assert.fail();
} catch (NotFoundException e) {
// expected
}
try {
profileService.disableProfile(profileId);
Assert.fail();
} catch (NotFoundException e) {
// expected
}
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class ProfileServiceTest method testProfileOverrides.
@Test
public void testProfileOverrides() throws Exception {
List<ProvisionerPropertyValue> provisionerProperties = new ArrayList<>();
provisionerProperties.add(new ProvisionerPropertyValue("editable1", "val", true));
provisionerProperties.add(new ProvisionerPropertyValue("editable2", "val", true));
provisionerProperties.add(new ProvisionerPropertyValue("final", "finalval", false));
ProvisionerInfo provisionerInfo = new ProvisionerInfo("provisioner", provisionerProperties);
Profile profile = new Profile("name", "label", "desc", provisionerInfo);
ProfileId profileId = NamespaceId.DEFAULT.profile("p");
profileService.saveProfile(profileId, profile);
try {
Map<String, String> args = new HashMap<>();
args.put("editable1", "newval");
args.put("final", "shouldnotwork");
args.put("newarg", "val");
// resolved properties should include all the stored properties,
// with 'final' not overridden and 'editable1' overridden.
List<ProvisionerPropertyValue> expectedProperties = new ArrayList<>();
expectedProperties.add(new ProvisionerPropertyValue("editable1", "newval", true));
expectedProperties.add(new ProvisionerPropertyValue("editable2", "val", true));
expectedProperties.add(new ProvisionerPropertyValue("final", "finalval", false));
expectedProperties.add(new ProvisionerPropertyValue("newarg", "val", true));
provisionerInfo = new ProvisionerInfo(provisionerInfo.getName(), expectedProperties);
Profile expected = new Profile(profile.getName(), "label", profile.getDescription(), provisionerInfo);
Profile actual = profileService.getProfile(profileId, args);
Assert.assertEquals(expected, actual);
} finally {
profileService.disableProfile(profileId);
profileService.deleteProfile(profileId);
}
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class ProfileServiceTest method testProfileMetricsDeletion.
@Test
public void testProfileMetricsDeletion() throws Exception {
ProfileId myProfile = NamespaceId.DEFAULT.profile("MyProfile");
Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
ProgramRunId runId = NamespaceId.DEFAULT.app("myApp").workflow("myProgram").run(RunIds.generate());
// create and disable the profile
profileService.saveProfile(myProfile, profile);
profileService.disableProfile(myProfile);
// emit some metrics
MetricsCollectionService metricService = getInjector().getInstance(MetricsCollectionService.class);
MetricsContext metricsContext = metricService.getContext(getMetricsTags(runId, myProfile));
metricsContext.increment(Constants.Metrics.Program.PROGRAM_NODE_MINUTES, 30L);
MetricStore metricStore = getInjector().getInstance(MetricStore.class);
Tasks.waitFor(30L, () -> getMetric(metricStore, runId, myProfile, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
// delete and verify the metrics are gone
profileService.deleteProfile(myProfile);
Tasks.waitFor(0L, () -> getMetric(metricStore, runId, myProfile, "system." + Constants.Metrics.Program.PROGRAM_NODE_MINUTES), 10, TimeUnit.SECONDS);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class ProfileServiceTest method testProfileCreationTime.
@Test
public void testProfileCreationTime() throws Exception {
ProfileId myProfile = NamespaceId.DEFAULT.profile("MyProfile");
long creationTime = TimeUnit.SECONDS.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), ProfileStatus.ENABLED, Profile.NATIVE.getProvisioner(), creationTime);
profileService.saveProfile(myProfile, profile);
Assert.assertEquals(creationTime, profileService.getProfile(myProfile).getCreatedTsSeconds());
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
the class ProfileServiceTest method testProfileCreationDisabled.
@Test(expected = MethodNotAllowedException.class)
public void testProfileCreationDisabled() throws Exception {
CConfiguration cConfWithProfileCreationDisabled = CConfiguration.copy(cConf);
cConfWithProfileCreationDisabled.setBoolean(Constants.Profile.UPDATE_ALLOWED, false);
ProfileService service = new ProfileService(cConfWithProfileCreationDisabled, getInjector().getInstance(MetricsSystemClient.class), getInjector().getInstance(TransactionRunner.class));
ProfileId profileId = NamespaceId.DEFAULT.profile("MyProfile");
Profile profile = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES));
// Add a profile
service.saveProfile(profileId, profile);
}
Aggregations